Sign in to follow this  

Retrieve vertex data from a mesh

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
IDirect3DVertexBuffer9* p_vb;

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

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 this post

Link to post
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...


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this