This topic is now archived and is closed to further replies.


Finding Mesh Faces

Recommended Posts

Given the number of face of a mesh (LPD3DXMESH) is there any way to generate the three vertices of that triangle? There probably is some way with the adjacency buffer, but I can''t seem to find it. Any help would be appreciated. Thanks.

Share this post

Link to post
Share on other sites
You can use the index buffer of the ID3DXMesh interface to find all the vertices of a particular face (triangle). The index buffer is stored as a triangle list.

Here''s some code to show you how to do it:

const D3DXVECTOR3 &v0 = pVertices[pIndices[faceNum*3]].position;
const D3DXVECTOR3 &v1 = pVertices[pIndices[faceNum*3 + 1]].position;
const D3DXVECTOR3 &v2 = pVertices[pIndices[faceNum*3 + 2]].position;

This assumes that "pVertices" is a pointer to your vertex type. To get a pointer to the vertices of your mesh, you need to call ID3DXMesh::LockVertexBuffer(), preferably using the D3DLOCK_READONLY flag so that it goes a little faster. "pIndices" is a pointer to your index buffer. You get this by calling ID3DXMesh::LockIndexBuffer.

Hope this helps,

Share this post

Link to post
Share on other sites