Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Loading .X File Terrain into Bullet Physics


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   -  Reputation: 673

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.


Sponsor:

#2 Medo3337   Members   -  Reputation: 673

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.



PARTNERS