Triangle strips with jmonkey

Hi,



i am totally new to jmonkey.

I have to use it for some kind of “universitary” project.

There, we have utilize triangle strips.

So i tried the following code:





Mesh mesh = new Mesh();



Vector3f [] vertices = new Vector3f[4];



// Erstes Viereck, erste Reihe

vertices[3] = new Vector3f(0,1,0);

vertices[1] = new Vector3f(1,1,0);

vertices[2] = new Vector3f(0,0,0);

vertices[0] = new Vector3f(1,0,0);



mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));



geo = new Geometry(“OurMesh”, mesh);

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat1.setColor(“Color”, ColorRGBA.Green);

mat1.getAdditionalRenderState().setWireframe(true);

geo.setMaterial(mat1);



mesh.setMode(Mesh.Mode.TriangleStrip);

mesh.updateBound();

mesh.setStatic();



Geometry lines = new Geometry(“OurMesh”, mesh);

lines.setMaterial(mat1);



rootNode.attachChild(lines);





and now, i tried to change the vertices from this:



Vector3f [] vertices = new Vector3f[4];



// Erstes Viereck, erste Reihe

vertices[3] = new Vector3f(0,1,0);

vertices[1] = new Vector3f(1,1,0);

vertices[2] = new Vector3f(0,0,0);

vertices[0] = new Vector3f(1,0,0);





to this:





Vector3f [] vertices = new Vector3f[4];



// Erstes Viereck, erste Reihe

vertices[0] = new Vector3f(0,1,0);

vertices[1] = new Vector3f(1,1,0);

vertices[2] = new Vector3f(0,0,0);

vertices[3] = new Vector3f(1,0,0);





After that, i can’t see anything and i don’t understand why.



Can anybody explain this behavior to me and tell me, what i’m doing wrong?



Thanks in advance,



Jonas

Triangle strips have a winding order. As you create them they will automatically alternate their normal face direction. You just have to look at the other side and you will see them.

If your shape is not just a rectangle, then you will have to introduce degenerate polygons (polygons with zero area or containing collinear points). This is easy by just duplicating the last point. It will fix the winding order too.

Some good pictures on winding order here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205124%28v=vs.85%29.aspx

Thank you very much for the information.

I really thought, i was kind of stupid.

After rotating my object, it became visible.

Now i understand a little bit more of jmonkey.



Best wishes,



jonas

Technically this is more of an OpenGL thing, but yes I have been there too and wondered where my mesh disappeared to when really I was just looking at the back of it :slight_smile:

Good luck