Determining vertex winding order

Started by
12 comments, last by JohnnyCode 10 years, 2 months ago

The usual way to find the winding is to calculate the normal using the cross product of the first two edges and compare that with the face normal vector. Depending on if they point in the same direction, you can figure out what the winding order is.

Yes, without explicit normal info, the winding consistancy is just interpretation open.

Consider a mesh consisting of two planes, not connected, with one plane facing opposite than the other. Will you consider the winding broken? Or will you consider it a correct mesh?

Advertisement


Consider a mesh consisting of two planes, not connected, with one plane facing opposite than the other. Will you consider the winding broken? Or will you consider it a correct mesh?

Strictly speaking, if you don't specify normal vectors, then there is no way to tell if they are facing opposite directions :) However, the test that the OP is doing would tell you if the windings were opposite of one another in that test case...


Just for the record, your last two quotations are wrong. tonemgub said that, not me.

Yup -but I was talking only about the 2d case, where the winding is relative to the 2d plane, so the normal.z value can be easily interpreted as winding.

Because in OP code snippet, it seems that only 2d values are used in the area calculationL p0x and p0y - there's no p0z.

And in that case, there is no need to use the area at all. He can just use the z value from the normal, assuming that the normal is computed using the dot product, and that the order of vertices used in the vector-subtraction operations to get the two vectors that are passed to the dot product is always the same, for each triangle.

I'm getting opposite winding for opposite sides of a cube. This can't be right as the cube renders just fine

Cube is an enclosed mesh, and as for enclosed meshes, it makes sance to detect winding consistancy. If winding would be inconsistant, you would not have an enclosed mesh, but a spike-open edge mesh. Your algorithm returns different results becouse it projects the cube. You should go the way that Alvaro suggested, that would perfectly work for enclosed meshes.

You can determine if two polygons that share an edge have the same winding or not, just by checking that the common edge is mentioned in reverse order.

it does not matter then wheather you start with an hypothetical inverse triangle or correct one, since you check consistancy. This would be a robust function that would return surface validity, wheather it was a cube, or inverted cube-room. But for open meshes without normal info, it is pointless to check on winding.

This topic is closed to new replies.

Advertisement