Code: Select all
btBulletWorldImporter import(0);
if (import.loadFile(qPrintable(filePath)))
{
if (import.getNumCollisionShapes() == 1)
{
shape = import.getCollisionShapeByIndex(0);
}
}
'import.getNumBvhs()' also returned 1, so the bvh was properly saved in the file.
However, the loading code took basically as much time as recreating the shape every time, which I found suspicious. It was indeed going through btBvhTriangleMeshShape::buildOptimizedBvh(), which I was not expecting.
Then I found this in btBulletWorldImporter.cpp:
Code: Select all
btTriangleMeshShapeData* trimesh = (btTriangleMeshShapeData*)shapeData;
btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&trimesh->m_meshInterface);
btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
if (!meshInterface->getNumSubParts())
{
return 0;
}
btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
meshInterface->setScaling(scaling);
btOptimizedBvh* bvh = 0;
#if 0
if (trimesh->m_quantizedFloatBvh)
{
btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh);
if (bvhPtr && *bvhPtr)
{
bvh = *bvhPtr;
} else
{
bvh = createOptimizedBvh();
bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
}
}
if (trimesh->m_quantizedDoubleBvh)
{
btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedDoubleBvh);
if (bvhPtr && *bvhPtr)
{
bvh = *bvhPtr;
} else
{
bvh = createOptimizedBvh();
bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh);
}
}
#endif
btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface,bvh);
My question is: Why was that #if block there in the first place? I can't find the repository history for that file for my version... Will I have any negative side effects from reactivating that code block?
I'm using bullet 2.80 (r2531).
The demo code in ConcavePhysicsDemo.cpp to load a serialized shape doesn't really make sense when bvh's are serialized either:
Code: Select all
btBulletWorldImporter import(0);//don't store info into the world
if (import.loadFile("myShape.bullet"))
{
int numBvh = import.getNumBvhs();
if (numBvh)
{
btOptimizedBvh* bvh = import.getBvhByIndex(0);
btVector3 aabbMin(-1000,-1000,-1000),aabbMax(1000,1000,1000);
trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax,false);
trimeshShape->setOptimizedBvh(bvh);
//trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression,aabbMin,aabbMax);
//trimeshShape->setOptimizedBvh(bvh);
}
int numShape = import.getNumCollisionShapes();
if (numShape)
{
trimeshShape = (btBvhTriangleMeshShape*)import.getCollisionShapeByIndex(0);
//if you know the name, you can also try to get the shape by name:
const char* meshName = import.getNameForPointer(trimeshShape);
if (meshName)
trimeshShape = (btBvhTriangleMeshShape*)import.getCollisionShapeByName(meshName);
}
}