I have been experimenting with Instanced Geometry for my suspension arms recently. I managed to get it working (although there seems to be a bug or limitation that means that you cannot attach it to a node other than the root node).
I did some profiling after adding the instanced geometry and found that InstancedGeometry::BatchInstance::updateBoundingBox was taking up 33% of the CPU time for OgreMain.dll. I realised that this was because I was setting the position of the suspension arms each frame and with 20 cars it was recalculating the bounding box 480 times per frame, rather than the 20 times that are needed.
I added a parameter to setPosition and setPositionOrientation (defaulted to true) to allow the user to decide whether to recalc the bounding box. After I set ALL positions of the 24 suspension arms I then call BatchInstance::updateBoundingBox() manually. This brought the %time down to a reasonable 4%.
Code: Select all
void InstancedGeometry::InstancedObject::setPositionAndOrientation(Vector3 p, const Quaternion& q, bool calcBoundingBox)
{
mPosition = p;
mOrientation = q;
needUpdate();
if (calcBoundingBox){
BatchInstance* parentBatchInstance=(*(mGeometryBucketList.begin()))->getParent()->getParent()->getParent();
parentBatchInstance->updateBoundingBox();
}
}
I am not sure how to submit a patch (if people think it is useful), let me know and i'll go the official route if there is one.
All the best,
Ash