Retrieve vertex data from a mesh

Started by
0 comments, last by jollyjeffers 17 years, 8 months ago
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;
aomesh->mesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&v);

// 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?
Advertisement
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

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

This topic is closed to new replies.

Advertisement