I see that terrain scene node generated via heightmap differs from other nodes because indices are empty. I try to get all triangles used in terrain to pass them into bullet mesh shape, but I can't find any proper way to do it. I'll be grateful if somoene tell me how to generate triangles for terrain scene node. Here is fragment of code I wrote, but it doesn't work. Second loop never runs, because indice count is zero.
Code: Select all
btCollisionShape * createShape(const irr::scene::ISceneNode * pNode)
{
scene::ITerrainSceneNode* pTerrain = (scene::ITerrainSceneNode*) pNode;
scene::IMesh* mesh = pTerrain->getMesh();
btTriangleMesh* btMesh = new btTriangleMesh();
for (int bIndex = 0; bIndex < mesh->getMeshBufferCount(); ++bIndex)
{
// Extracting all meshes from TerrainNode
scene::IMeshBuffer* irrMesh = mesh->getMeshBuffer(bIndex);
auto mb_vertices = (video::S3DVertex2TCoords*) irrMesh->getVertices();
// now irrMesh->getIndexCount() returns 0
// mb_vertices is filled properly, but nothing is known about triangles
// nullptr
u16* indices = (u16*) irrMesh->getIndices();
for (int i = 0; i < irrMesh->getIndexCount(); i += 3)
{
s32 index = indices[i];
btMesh->addTriangle(bulletVector(mb_vertices[index].Pos), bulletVector(mb_vertices[index + 1].Pos), bulletVector(mb_vertices[index + 2].Pos));
}
}
pShape = new btBvhTriangleMeshShape(btMesh, true);
}
}