• Advertisement
Sign in to follow this  

reading vertexs from mesh

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

Advertisement
LPD3DXMESH has a GetVertexBuffer() method, use this to extract teh VB, then memcpy out the vertices into an array. You can manipulate them from there.

ace

Share this post


Link to post
Share on other sites
You should know the number of vertices in the vertex buffer that resides in the LPD3DXMESH object. If you know the type of the vert stored in there then you can create an array of that type. Then lock the vertex buffer, memcpy() from the vertex buffer to the array and then unlock the buffer again.

Google and the SDK has loads of information on this.

ace

Share this post


Link to post
Share on other sites
I'm a bit of a noob at this, and the sticking point of the process for me is getting the vertex type.

When I load a mesh with D3DXLoadMeshFromX, I don't specify a vertex format anywhere, so what type does it get? I can't find anything in the docs.

The only way I can see to do it is to use GetFVF but this is a bit annoying because I would have to manually add up the size of each of the vertex's elements to get the offset to the data I want and the sizeof the whole struct.

Please tell me there's another way...


- Mijin -

Share this post


Link to post
Share on other sites
if you want to copy Just the Vertices Only and do not give care about anything else you can do this without caring about the FVF size. Here it is

struct Vertex{
float x,y,z;
Vertex(float xx,float yy,float zz):x(xx),y(yy),z(zz){}
};

void ExtractMeshVertex(Vertex* vlist,LPD3DXMESH mesh)
{
int numVertex=mesh->GetNumVertices();
BYTE* p;
vlist=new Vertex[numVertex];
DWORD size=D3DXGetFVFVertexSize(mesh->GetFVF());
mesh->LockVertexBuffer(D3DLOCK_READONLY,(LPVOID*)&p);
for(int i=0;i<numVertex;i++){
vlist.x=(*(*float)&*p); //Get the X
p+=4;
vlist.y=(*(*float)&*p); //Get the Y
p+=4;
vlist.z=(*(*float)&*p); //Get the Z
p-=8;
p+=size;
}
mesh->UnlockVertexBuffer();
return;
}

PS: Now you will have all vertices inside the vlist.



[Edited by - BornToCode on November 6, 2005 4:18:18 PM]

Share this post


Link to post
Share on other sites
Wow quick reply

Thanks, I'm glad I was barking up the right tree i.e. there was no super-convenient way I'd missed (although I had overlooked D3DXGetFVFVertexSize).

Actually I need the verts + normals, but it's a straightforward extension to your code to jump over the xyz portion based on which xyz flag has been set.

- Mijin -

Share this post


Link to post
Share on other sites

i am trying to do this but i have a lack of resources so i would appreciate any kind of help and if u can lead me to some sites that could help and mean while try converting it :)

Share this post


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

  • Advertisement