This topic is 4638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

hi guys can anyone tell me how to read the vertexs positions of a mesh ???

Share on other sites
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 on other sites

"then memcpy out the vertices into an array"

how do i do this ???

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.

ace

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 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 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]

Share on other sites

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 on other sites

offffff it is really hard to translate from C++ to C# .
can anybody convert the above code to c# plz

Share on other sites
No one said it would be easy man, feel free to step up and help yourself.

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

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631759
• Total Posts
3002138
×