0

Is it possible to say by eye, what is wrong with the following mesh:

enter image description here

I am sure, that triangle structure is good initially:

enter image description here

But error is probably on the stage of preparing mesh for jME3.

Probably I flip some triangles, because it looks reverse from behind:

enter image description here

How to control triangle orientation?

I form list of vertex index in straight way

List<Mesh.Triangle> triangles = mesh.calculateTriangles2();
    indexes = new int[triangles.size()*3];
    int ii;
    for(int i=0; i<triangles.size(); ++i) {
        ii = 0;
        for(Mesh.Node node : triangles.get(i)) {
            indexes[i*3+ii] = nodesMap.get(node);
            ii++;
        }
    }

which leads the order of vertices in triangles are random. What defines orientation?

Dims
  • 47,675
  • 117
  • 331
  • 600
  • 2
    I think you might be calculating the normals incorrectly, assuming you are doing so manually. If you use the vector product on two edges you may get a normal vector that points either up or down, depending on which edges you choose. – Bartvbl Jun 17 '14 at 11:39
  • 1
    either bad normals or bad winding – ratchet freak Jun 17 '14 at 11:42
  • 2
    The winding @ratchetfreak mentioned is that OpenGL by default considers counter-clockwise vertex order as a definition of the front face of a polygon. If you accidentally draw the vertices in clockwise order, they will face the other direction. – Bartvbl Jun 17 '14 at 11:49
  • 1
    Do a glPolygonMode(GL_LINE) and check if the triangles are drawn properly. If so do disable face culling. This should solve your issue I think. – mrVoid Jun 17 '14 at 12:43
  • Are you trying to draw this as a triangle strip by chance? That is what the end result looks like to me. Without seeing the actual drawing code, that is just a guess, however. – Andon M. Coleman Jun 18 '14 at 00:50

0 Answers0