Archived

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

How do i extract/change vertex information in meshes?

This topic is 5093 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 can load and display meshes pretty easily now, but i want to be able to dynamically change the position and the brightness of each vertex in the model. Does anyone have any information on how this is done?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
check out the ID3DXMesh reference in the SDK

there are methods like GetVertexBuffer() and GetIndexBuffer()

Share this post


Link to post
Share on other sites
It's LockVertexBuffer and LockIndexBuffer :-) Just make sure you unlock them (UnlockVertexBuffer/UnlockIndexBuffer) when you're done.

The way you call them would be something like
CUSTOMVERTEX* pVertices; //CUSTOMVERTEX is your own FVF struct
pMesh->LockVertexBuffer(0, (void**)&pVertices);
//pVertices now holds a pointer to all the vertices in pMesh
for(int i=0;iGetNumVertices();i++) //Loop through each vertex
{
pVertices[i+0].position += D3DXVECTOR3(rand()/32768.0f - 0.5f, rand()/32768.0f - 0.5f, rand()/32768.0f - 0.5f);
//Add a random vector with components between -0.5 and 0.5 to each vertex
}
pMesh->UnlockVertexBuffer();

Obviously this will just randomly move and deform the mesh. You get the idea though (I hope). LockVertexBuffer just loads the vertices into the pVertices argument and allows for read/write access to the buffer. Again, make sure you unlock or your app won't be happy.

Edit: changed the i to i+0 because it was giving me italics

[edited by - ms291052 on January 6, 2004 7:44:48 PM]

Share this post


Link to post
Share on other sites