reading vertexs from mesh

Started by
8 comments, last by jad_salloum 18 years, 5 months ago
hi guys can anyone tell me how to read the vertexs positions of a mesh ???
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


"then memcpy out the vertices into an array"

how do i do this ???
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
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 -
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 Xp+=4;vlist.y=(*(*float)&*p); //Get the Yp+=4;vlist.z=(*(*float)&*p); //Get the Zp-=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]
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 -

offffff it is really hard to translate from C++ to C# .
can anybody convert the above code to c# plz
No one said it would be easy man, feel free to step up and help yourself.
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein

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 :)

This topic is closed to new replies.

Advertisement