Sign in to follow this  

Loading .X File Terrain into Bullet Physics

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

I'm looking to load the terrain that I have created in 3Ds Max into Bullet physics, I am using C++ and DirectX.

I have tried the following, it's not working as expected:
[CODE]DWORD numVertices = mesh->GetNumVertices();
DWORD numFaces = mesh->GetNumFaces();
VertexNormal *v = 0;
mesh->LockVertexBuffer(0, (void**)&v);
// Extract vertices
TriMeshData *pData = new TriMeshData();
pData->vertices = new btScalar[numVertices * 3];
for(DWORD i = 0; i < numVertices; i++)
{
pData->vertices[i*3+0] = v[i].position.x;
pData->vertices[i*3+1] = v[i].position.y;
pData->vertices[i*3+2] = v[i].position.z;
}
mesh->UnlockVertexBuffer();
// Extract indices
pData->indices = new int[numFaces * 3];
WORD* ind = 0;
mesh->LockIndexBuffer(0,(void**)&ind);

//memcpy( &indices, &ind, sizeof(ind));
for(DWORD i = 0; i < numFaces; i++)
{
pData->indices[i*3+0] = ind[i*3+0];
pData->indices[i*3+1] = ind[i*3+1];
pData->indices[i*3+2] = ind[i*3+2];
}
mesh->UnlockIndexBuffer();
int indexStride = 3 * sizeof(int);
int vertStride = sizeof(btVector3);
pData->indexVertexArrays = new btTriangleIndexVertexArray(numFaces, pData->indices, indexStride,
numVertices, (btScalar*) &pData->vertices[0], sizeof(btScalar) * 3);
bool useQuantizedAabbCompression = true;
btBvhTriangleMeshShape *groundShape = new btBvhTriangleMeshShape(pData->indexVertexArrays, true);
[/CODE] Edited by Medo3337

Share this post


Link to post
Share on other sites
I found the solution here:
http://code.google.com/p/labtd/source/browse/trunk/Source/labtd/World/CollisionShapeLibrary.cpp

This question is now resolved.

Share this post


Link to post
Share on other sites
Sign in to follow this