StaticMeshShapeConverter and Ogre::ManualObject

dangerdaveCS

01-03-2010 14:52:58

I have one bug/efficiency report/fix and one feature request for you all:

I'm trying to make some dynamic terrain by defining the geometry using Ogre::ManualObject, then turning that into a btBvhTriangleMeshShape (using StaticMeshToShapeConverter -> TriangleMeshCollisionShape).

Problem:
I cannot pass the ManualObject to StaticMeshToShapeConverter directly, even though it derives from Ogre::Renderable. I get strange runtime errors, seemingly caused by the NULL return from getRenderOperation() when called on a ManualObject.

In order to convert the mesh to a collision object I have to first run convertToMesh() on the ManualObject, then attach the newly created Ogre::MeshPtr to an Entity, then pass the Entity on to StaticMeshToShapeConverter. The problem with this is that the entire mesh data is needlessly copied when creating the Ogre::MeshPtr.

Fix:
In order to fix this I added the following constructor to StaticMeshToShapeConverter:

StaticMeshToShapeConverter::StaticMeshToShapeConverter(Ogre::ManualObject *rend, const Ogre::Matrix4 &transform)
{
for (int i = 0; i != rend->getNumSections(); ++i)
{
RenderOperation* op = rend->getSection(i)->getRenderOperation();
VertexIndexToShape::addStaticVertexData(op->vertexData);
if(op->useIndexes)
VertexIndexToShape::addIndexData(op->indexData);
}
}


The only difference between the above constructor and the original "StaticMeshToShapeConverter(Renderable *rend", is the loop through sections.

Request
Even with this slight optimization there is still one extra copy of the mesh data that is not necessary. Currently the mesh data is copied from ManualObject -> StaticMeshToShapeConverter -> btBvhTriangleMeshShape . The middle step is not really necessary. It would be brilliant if OgreBullet could skip its internal storage and just do a direct translation from ManualObject -> btBvhTriangleMeshShape. Then it would be much more suitable for future dynamic terrain algorithms.