PDA

View Full Version : Getting an array of the vertices and indices from an ID3DXMesh?


chillypacman
05-31-2007, 07:51 AM
Hi all :)

I'm trying to create a method that will take out the vertices and indices of an ID3DXMesh and put them in an array so that I can use it to create a trimesh in ode.

Basically I want to do this:

dGeomID plane;
dTriMeshDataID triMesh;
...
// Plane geometry
const int indexes[6] = {2, 1, 0, 3, 2, 0};// <--- THIS
const dVector3 triVert[4] = { //<------- AND THIS
{ 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);

Heres what I have so far and it doesn't work:

int* indexes;
float* vert;

LPDIRECT3DVERTEXBUFFER9 VB;
LPDIRECT3DINDEXBUFFER9 IB;
dVector3 triVert;

model->GetVertexBuffer(&VB);
model->GetIndexBuffer(&IB);

memcpy_s(indexes, sizeof(IB), IB, sizeof(IB));
memcpy_s(vert, sizeof(VB), VB, sizeof(VB));


If anyone could shed osme light on this it would be GREATLY appreciated :)

Oybl
05-31-2007, 01:56 PM
You have to lock the buffers first, then you get a pointer to actual data