Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMedo3337

Posted 11 November 2012 - 09:36 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);

#2Medo3337

Posted 11 November 2012 - 06:53 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);

#1Medo3337

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.

How do I change the following line to make it load the terrain from .x file?
btCollisionShape *terrain = new btBvhTriangleMeshShape();

PARTNERS