Determing facet winding

We normally use clockwise windings for our facet models. However, we have some models that have a mixture of CW and CCW facets so that the backward facets appear dark when displayed in OpenGL.

I was trying to find a way to determine which facets are backwards so that I can fix them in the models. My first idea was to simply do a cross product of all of the facets and check the direction of the normal. If it is negative then I reverse the facet direction. But then I realized that CW facets on the opposite size of the model will always come back negative, since they actually face away from the user. The only other idea I can come up with to to manually render the model from six sides to determines which facets should point towards the user. But even this could cause problems, like how much resolution do I need and what if a facet is perpendicular.

Before I go too far down this road I was wondering if you have any suggestions. Maybe there is a simple solution that I’m not thinking about.

Thank you,

Jim

I think MeshLab may be able to make winding order consistent.

Fixing flipped faces only works consistently with closed meshes. So, all faces of a closed mesh will either point inside or out. You could simply pick a random face, and flip all surrounding faces to match it. And expand your search from there.

I don’t know how this process works exactly, but it might have something to do with building a half-edge data structure, and traversing it.

For example, if you take one face, and say it’s vertex ordering is CCW, then each of its edges have a certain direction.
Then traverse the adjacent faces from each of those edges, maintaining that edge direction. If the adjacent face happens
to be going in the opposite direction (compared to the edge), reverse it.

Here’s another method. Only works for convex meshes. Won’t work for meshes shaped like a torus.

For each face, draw a line from the geometric center of the mesh through the center of the face.
Take the dot product of the line and face normal. If negative, then the face is flipped.

For a manifold surface, each edge will be shared by at most two faces (for a non-manifold surface, there’s no such thing as consistent winding).

If the winding is consistent, then whenever two faces share an edge, the order of the vertices in one face will be the reverse of that in the other face. If the order is the same in both faces, then the winding is inconsistent.

E.g. two triangles ABC and CBD sharing the edge BC have a consistent winding, as the shared edge is BC in one but CB in the other. OTOH, triangles ABC and BCD have inconsistent winding as the shared edge is BC in both.

Yes, a manifold mesh is what I meant. The forum won’t let me edit my previous post to make the typo correction.