Sign in to follow this  
jad_salloum

reading vertexs from mesh

Recommended Posts

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[i].x=(*(*float)&*p); //Get the X
p+=4;
vlist[i].y=(*(*float)&*p); //Get the Y
p+=4;
vlist[i].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

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