Archived

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

Pirosan

How do i extract/change vertex information in meshes?

Recommended Posts

Pirosan    124
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   
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
ms291052    223
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