Fixing winding order in meshes
Posted 28 January 2012 - 12:28 PM
So when I render them half the triangles disappear.
I have tried writing some code that calculates a face normal for each triangle and compares it to the vertex normals, if the angle between the face normal and the vertex normals is greater than 90 degrees, I flip the winding order.
This seems to work for objects that are supplied with vertex normals, but some of the objects I want to use don't have vertex normals.
I am struggling to come up with an alternative technique for this case.
The best I can come up with at the moment is to calculate the centre of the object, throw a ray through each vertex and compare the direction of this ray with the face normal, but that only works for some objects.
Out of ideas, anyone got anything?
Posted 28 January 2012 - 01:33 PM
Pick triangle with right winding order, mark it as processed. For each its edge find adjacent unprocessed triangles. If such triangle sweeps edge points in the same order as in the processed area than flip winding order. Mark corrected adjacent triangles as processed and repeat algorithm for the new edges of processed area. When you couldn't find adjacent triangles at all, you'll have fully processed connected piece of mesh. Pick another triangle and move to next piece. If you pick triangle with wrong winding order than whole piece will be backfaced, you can correct this later.
Posted 28 January 2012 - 04:44 PM
If you do pick a starting triangle with the wrong winding order, then it's possible that the entire object will end up with the wrong winding order.
It's worth thinking about though, the idea of using connections may be something I can work with.......
Posted 28 January 2012 - 07:18 PM
Posted 28 January 2012 - 09:45 PM
True, but it doesn't solve my problem, I need it to be a "human interaction free" solution
I think I'm going to put it in my toolbox though, I'll try and find time to do it tomorrow and let you know how well it works
Posted 28 January 2012 - 11:02 PM
Posted 29 January 2012 - 02:03 AM
Posted 29 January 2012 - 10:22 AM
Render the object into a depth buffer, I don't care about anything else, with culling off. Then using the depth buffer as a test parse the object again.
If the polygon is the "front" polygon, and it's surface normal is pointing away from the camera, then flip it's winding.
Repeat this for all six major axes.
I'm not at all sure if this will work with all objects though, the case I think may fail is an object with engines.
I did a quick check on one mesh and there are a lot of cases when three polygons share an edge. It's probably where the artist added a subdivided basic shape to the mesh.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users