• 9
• 16
• 15
• 12
• 9

Retrieve vertex data from a mesh

This topic is 4264 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm having trouble figuring out exactly how to manipulate vertex data from a mesh. I have the ID3DXMesh* loaded in aomesh->mesh. I have the following code written.
// calc stride of vertex
int numBytePerVertex = aomesh->mesh->GetNumBytesPerVertex();

// get vertex buffer description
D3DVERTEXBUFFER_DESC desc;
IDirect3DVertexBuffer9* p_vb;
aomesh->mesh->GetVertexBuffer(&p_vb);
p_vb->GetDesc(&desc);

// lock vertex buffer
BYTE* v = 0;

// code to retrieve position and normal data not yet written
.
.
//

// unlock vertex buffer
aomesh->mesh->UnlockVertexBuffer();


Is this the proper way to get the stride of each vertex? Once you have a FVF description, stored in desc.FVF, how do you tell the byte offset from the beginning of the vertex data where a particular data is, such as position, normal, or color data?

Share on other sites
That is pretty much the only way of generalising the process. If you know that the incoming format is you can optimize accordingly - You might want to look into using ID3DXMesh::CloneMesh() to help out.

I would recommend using the vertex declaration rather than FVF's; given that FVF's are a subset of declarations you shouldn't have any problems (however, some vertex formats cannot be represented by FVF's). The various fields in D3DVERTEXELEMENT9 will reveal the appropriate offsets/lengths etc...

hth
Jack