Sign in to follow this  
Medo Mex

Loading .X File Terrain into Bullet Physics

Recommended Posts

Medo Mex    891
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this