Jump to content

Image of the Day

Setting up a playground for our bad boys... #maya #gameart #screenshotsaturday #gamedev https://t.co/V5mfxWkzHg
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

Loading .X File Terrain into Bullet Physics

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 Medo3337   Members   

891
Like
0Likes
Like

Posted 11 November 2012 - 06:17 PM

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

Edited by Medo3337, 11 November 2012 - 09:36 PM.


#2 Medo3337   Members   

891
Like
0Likes
Like

Posted 11 November 2012 - 09:37 PM

I found the solution here:
http://code.google.com/p/labtd/source/browse/trunk/Source/labtd/World/CollisionShapeLibrary.cpp

This question is now resolved.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.