I have continued my attempts to integrate Bullet in a nice and friendly way, here is an attempt at loading in a basic .x mesh and parsing it to Bullet format.
Code:
void LoadXFile( char* MeshFilename, ID3DXMesh* &Mesh )
{
//Zero Mesh and create buffer
Mesh = 0;
ID3DXBuffer* MeshBuffer = 0;
//Load and optimize the mesh
D3DXLoadMeshFromX( MeshFilename, D3DXMESH_MANAGED, D3DDevice, &MeshBuffer, 0, 0, 0, &Mesh);
Mesh->OptimizeInplace( D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_COMPACT | D3DXMESHOPT_VERTEXCACHE, (DWORD*)MeshBuffer->GetBufferPointer(), 0, 0, 0);
//Release and zero the buffer
MeshBuffer->Release(); MeshBuffer = NULL;
btBvhTriangleMeshShape* btTriMeshShape;
btTriangleIndexVertexArray* mIndexVertexArray;
DWORD *pIndexBuffer;
DWORD *pVertexBuffer;
//Find a working example of a working locked vertex buffer then continue trying to adapt this parsing code!
Mesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&pVertexBuffer);
Mesh->LockIndexBuffer(D3DLOCK_READONLY, (void**)&pIndexBuffer);
mIndexVertexArray = new btTriangleIndexVertexArray(Mesh->GetNumFaces(),
(int*) &pIndexBuffer,
Mesh->GetNumBytesPerVertex() * 3,
Mesh->GetNumVertices,
(btScalar*) &pVertexBuffer,
Mesh->GetNumBytesPerVertex());
Mesh->UnlockIndexBuffer();
Mesh->UnlockVertexBuffer();
btVector3 aabbMin(-10000,-10000,-10000), aabbMax(10000,10000,10000);
bool useQuantizedAabbCompression = true;
btTriMeshShape = new btBvhTriangleMeshShape(mIndexVertexArray, true);
}
This will crash on the last line because the "btTriangleIndexVertexArray" setup does not appear to work with this configuration, my mesh is a simple cube with the normals facing inward. I am desperate for an implementation of mesh loading that uses blender, 3DS Max 2010 or works by parsing in another mesh, I am completely unable to use the SDK until I fix this.
I am using Bullet 2.77 my demo folder includes a benchmark folder that uses btTriangleIndexVertexArray however I cannot seem to find how anything interacts with the various arrays such as LandscapeVtx in order to load in data.
I am currently taking a step back to a more desperate approach using the following code just to load in something I can interact with.
btTriangleMesh* trimesh = new btTriangleMesh();
for ( i=0;i<numTriangles;i++)
{
trimesh->addTriangle(triangles[i].vertex0,triangles[i].vertex1,triangles[i].vertex2);
}
btCollisionShape* shape = 0;
//static, non-moving world environment geometry
bool useQuantization = true;
shape = new btBvhTriangleMeshShape(trimesh,useQuantization);