Sign in to follow this  

Retrieve vertex data from a mesh

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

If you intended to correct an error in the post then please contact us.

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;
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?

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

hth
Jack

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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