Jump to content
  • Advertisement
Sign in to follow this  
chillypacman

get an array of vertices from x file

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

There isn't anything built into DirectX that does this so I'm trying to do it with what I have available to me in directx. Though I just can't figure it out. How can I create an array of the vertices in an x file? I'm trying to create an array like: int vertex[3] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; out of an ID3DXMesh. It shoul dbe possible, especialy since ID3DXMesh has the drawsubset() function, so obviously the vertex array is there somewhere...

Share this post


Link to post
Share on other sites
Advertisement
Do you want the indices or the vertices? Your subject title and code fragment conflict...

If you're wanting a performant way of doing this, interpret the vertex declaration and then use ID3DXMesh::LockVertexBuffer() to grab the data.

Otherwise, a much simpler way is to just use ID3DXMesh::CloneMeshFVF(D3DFVF_XYZ)( and then memcpy_s() the entire contents of the VB to a float[] array.

If you just want the indices, then ::LockIndexBuffer() is all that you need. Simple [smile]

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Do you want the indices or the vertices? Your subject title and code fragment conflict...

If you're wanting a performant way of doing this, interpret the vertex declaration and then use ID3DXMesh::LockVertexBuffer() to grab the data.

Otherwise, a much simpler way is to just use ID3DXMesh::CloneMeshFVF(D3DFVF_XYZ)( and then memcpy_s() the entire contents of the VB to a float[] array.

If you just want the indices, then ::LockIndexBuffer() is all that you need. Simple [smile]

hth
Jack


Clearly I have no clue what I want.

I got to this situation from wanting to implement something not too different to the following:

	// Plane geometry
const int indexes[6] = {2, 1, 0, 3, 2, 0};
const dVector3 triVert[4] = {
{ 10.0, 0.0, 10.0},
{-10.0, 0.0, 10.0},
{-10.0, 0.0, -10.0},
{ 10.0, 0.0, -10.0}
};

triMesh = dGeomTriMeshDataCreate();
dGeomTriMeshDataBuildSimple(triMesh, (dReal*)triVert, 4, indexes, 6);
plane = dCreateTriMesh(space, triMesh, NULL, NULL, NULL);
dGeomSetData(plane, "Plane");
dGeomSetPosition(plane, 0, -10.0, 0);




with triVert being the array.

So I'll try the ID3DXMesh::CloneMeshFVF and if it doesn't work (because I"m an idiot) then I'll come back here and complain that it isn't working :p

[Edited by - chillypacman on May 26, 2007 7:35:15 AM]

Share this post


Link to post
Share on other sites
The XFileData objects will allow you to enumerate the contents of an .X file without actually loading it into a D3DXMesh, if you'd like to do things that way, also.

Share this post


Link to post
Share on other sites
Ok, still not working... I've created a class that is supposed to do everything I want and create the object I want but everytime I try to initialize it, it just closes the application window:


int* indexes;
float *vert;

dGeomID object;
dTriMeshDataID triMesh;
dVector3 triVert;

LPDIRECT3DVERTEXBUFFER9* VB;
LPDIRECT3DINDEXBUFFER9 *IB;
...
TriMesh::TriMesh(ID3DXMesh* _model, IDirect3DDevice9* Device, dSpaceID* _space)
{
model = _model;
space = _space;

model->CloneMeshFVF(NULL, D3DFVF_XYZ, Device, &modelClone);

VB = 0;
modelClone->GetVertexBuffer(VB);

IB = 0;
modelClone->GetIndexBuffer(IB);

indexes = 0;
memcpy_s(indexes, sizeof(indexes), indexes, (3 * model->GetNumFaces()) * sizeof (IB));

vert = 0;
memcpy_s(triVert, sizeof(triVert), VB, model->GetNumVertices() * sizeof (VB));

triMesh = dGeomTriMeshDataCreate();
dGeomTriMeshDataBuildSimple(triMesh, (dReal*)triVert, modelClone->GetNumVertices(), indexes, modelClone->GetNumFaces() * 3);

object = dCreateTriMesh(*space, triMesh, NULL, NULL, NULL);
}





My problem is probably with the memcpy_s() thing though I'm not sure...

[Edited by - chillypacman on May 26, 2007 8:44:59 AM]

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!