there is enough context there... he is setting a btTriangleMesh equal to a irr::scene::CDynamicMeshBuffer which are not compatible and do not represent the same data.
Instead you need to learn what a btTriangleMesh requires, vertex array, index array, number of vertices, number of indices, and build that using the data in the mesh buffer.
Code: Select all
//used to get a bullet triangle mesh from an irrlicht mesh
btTriangleMesh *getTriangleMesh(IMesh* const mesh, const vector3df scale=vector3df(1,1,1))
{
btVector3 vertices[3];
u32 i, j, k;
s32 index, numVertices;
u16* mb_indices;
btTriangleMesh *pTriMesh = new btTriangleMesh();
for(i = 0; i < mesh->getMeshBufferCount(); i++)
{
irr::scene::IMeshBuffer* mb=mesh->getMeshBuffer(i);
//////////////////////////////////////////////////////////////////////////
// Extract vertex data //
// Because the vertices are stored as structs with no common base class,//
// We need to handle each type separately //
//////////////////////////////////////////////////////////////////////////
if(mb->getVertexType() == irr::video::EVT_STANDARD)
{
irr::video::S3DVertex* mb_vertices=(irr::video::S3DVertex*)mb->getVertices();
mb_indices = mb->getIndices();
numVertices = mb->getVertexCount();
for(j=0;j<mb->getIndexCount();j+=3)
{ //get index into vertex list
for (k=0;k<3;k++)
{
//three verts per triangle
index = mb_indices[j+k];
if (index > numVertices) continue;
//convert to btVector3
vertices[k] = btVector3(mb_vertices[index].Pos.X * scale.X, mb_vertices[index].Pos.Y * scale.Y,mb_vertices[index].Pos.Z * scale.Z); // 1100
}
pTriMesh->addTriangle(vertices[0], vertices[1], vertices[2]);
}
}
else
if(mb->getVertexType()==irr::video::EVT_2TCOORDS)
{
// Same but for S3DVertex2TCoords data
irr::video::S3DVertex2TCoords* mb_vertices=(irr::video::S3DVertex2TCoords*)mb->getVertices();
u16* mb_indices = mb->getIndices();
s32 numVertices = mb->getVertexCount();
for(j=0;j<mb->getIndexCount();j+=3)
{ //index into irrlicht data
for (k=0;k<3;k++)
{
s32 index = mb_indices[j+k];
if (index > numVertices) continue;
vertices[k] = btVector3(mb_vertices[index].Pos.X * scale.X, mb_vertices[index].Pos.Y * scale.Y, mb_vertices[index].Pos.Z * scale.Z);
}
pTriMesh->addTriangle(vertices[0], vertices[1], vertices[2]);
}
}
// Does not handle the EVT_TANGENTS type
}
if(pTriMesh)
{
return pTriMesh;
}
return 0;
}
I borrowed this from one of the bullet wrappers for irrlicht. This is an example (working one) on how to convert an irrlicht mesh into a bullet mesh. Having no direct conversion or overloads to simply do an = operation you need to program things like this to convert everything back and forth. Integrating a physics engine with irrlicht will not be as easy as you may have thought so you may want to look into one of the wrappers that already exist and are pretty much fully functional.