Instanced Geometry - make updating bounding box optional?

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 605
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
x 16
Contact:

Instanced Geometry - make updating bounding box optional?

Post by AshMcConnell »

Hi Folks,

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();
  }
}
Of course as time goes on I will probably not show suspension on cars further away (I haven't quite got that far yet), but I think this would be useful for people who want to batch together quite a few moving objects of the same texture.

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
Post Reply