Generating a useful mesh from a poorly defined one

Started by
2 comments, last by DXnut 17 years, 9 months ago
I have a list of triangles, each defined with arbitrary CW/CCW ordering and with no surface or vertex normals assigned. I want to turn this into a fully lit, back-face culled surface (just using materials, no texturing), but I'm not sure where to start... Is there a specific algorithm/procedure I should be following? What are the options? If I throw everything into a D3DXMesh, can it compute outward facing normals and reorder vertices for me?
Dave.
Advertisement
D3DX can probably do a fair bit of the work for you, but probably not all.

In particular you'll probably have to re-order the vertices so they are consistently CW or CCW wound. If you've got a CW/CCW attribute for each face it shouldn't be too hard to sort this out. Dont worry about duplicating data (or creating an optimal list) as you can use ID3DXMesh::OptimizeInPlace() to refine whatever you pass to D3DX.

Have a look at the Mesh Functions list - that should give you a good idea of what D3DX can perform for you.

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Ah great, thanks for the reply.

Can anyone tell me how I would go about reordering vertices to be in CW/CCW order? What do I test for to see which way its currently going?
Dave.
Quote:Original post by DangerDave
Ah great, thanks for the reply.

Can anyone tell me how I would go about reordering vertices to be in CW/CCW order? What do I test for to see which way its currently going?


You can create 2 vectors from the 3 vertices and then get cross product vector. The direction of the cross product vector will tell you how to order the vertices.
--------------------------Most of what I know came from Frank D. Luna's DirectX books

This topic is closed to new replies.

Advertisement