Jump to content
  • Advertisement
Sign in to follow this  

Getting vertices out of x file

This topic is 3880 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

Hi, I am trying to get the vertex information out of a X file using DirectX. This is the code I have currently :-
LPD3DXMESH tempMesh;
	m_pMesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_XYZ, RendererMgr::GetInstance().GetDevice(), &tempMesh); 
	DWORD fvf = tempMesh->GetFVF();

	// get the vertices
	D3DXVECTOR3 *vertices;

	tempMesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID *)&vertices);

But this seems to give me wrong results. Could someone please tell me what I am doing wrong here. Thanks

Share this post

Link to post
Share on other sites
Why do you think you're getting the wrong results?

Not knowing what you're comparing the vertices to, you might try locking the index buffer and accessing the vertices as indexed.

Share this post

Link to post
Share on other sites
Here is a snippet, that you can extract all vertices.

//Get the number of vertices in the mesh
int numVertices = mesh->GetNumVertices();
//The size of the FVF
DWORD stride = D3DXGetFVFVertexSize(mesh->GetFVF());
//Pointer to the current position in the mesh vertex buffer
BYTE *ptr = NULL;
//Lock the vertex buffer
mesh->LockVertexBuffer(0, (void**)&ptr);
//vector to hold the positions of the vertices in the mesh
//For all of the vertices put them in the vector
for(int i = 0; i < numVertices; i ++)
//pos = the position of a vertex
D3DXVECTOR3 *pos = (D3DXVECTOR3*)ptr;
//put it in the vector
positions.push_back(D3DXVECTOR3(pos->x, pos->y, pos->z));
//Increase the pointer in the vertex buffer by the size of the FVF
ptr += stride;

Hope it helps. :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!