Page 1 of 1

Control BoundingBoxes on Entity-Level.

Posted: Wed Nov 26, 2008 12:51 pm
by lithander
On a Mesh level a BoundingBox can be customized and set using _setBounds(). On an Entity level getBoundingBox() returns it's Meshes bounding box unaffected by the current AnimationState. Thus the meshes bounding box needs to be big enough to encompass the mesh in _all_ possible animation states.

In our use-case this results in way too large bounding boxes preventing effective culling for rendering and hit test purposes. The caused performance hit is a lot bigger then what it would cost to maintaining a BoundingBox per entity that takes the current animationState into account. As far as I can see ogre seems to be missing an interface for the programmer to control the results of Entity::getBoundinBox, though.

I'd suggest to extend the MovableObject::Listener interface to return a custom boundingBox just like you can use it to return a custom LightList allready. Or a _setBounds() method on an movableObject/entity level.

Or is there another way to do it that I'm not seeing?

Posted: Wed Nov 26, 2008 1:41 pm
by jacmoe
Get the geometry data from the mesh each frame and make/update your own boundingbox.
You can optimise by checking if the mesh animates, so that the boundingbox is only updated if something has changed since the last update.
That works splendidly. :wink:

Posted: Wed Nov 26, 2008 2:25 pm
by lithander
jacmoe wrote:Get the geometry data from the mesh each frame and make/update your own boundingbox.
Yeah, calculating a fitting bounding box is easy enough. But how can I make Ogre use my bounding box instead of it's own?

Posted: Wed Nov 26, 2008 2:45 pm
by jacmoe
You can probably override this:

Code: Select all

virtual const AxisAlignedBox& Ogre::MovableObject::getWorldBoundingBox(bool derive = false);

Posted: Wed Nov 26, 2008 7:40 pm
by syedhs
Well Jacmoe then a new class need to be created which is a little overkill for this purpose. And I am not sure about how function like SceneManager::createEntity (and others) are going to be affected.

Re: Control BoundingBoxes on Entity-Level.

Posted: Wed Dec 24, 2008 12:40 pm
by Red5_StandingBy
Hi,

Here is how we have overcome this issue.

When we export the skeletal animation of our character, we keep the translational change of the root bone at zero and write those values to a separate animation curve file.
(only translation, rotation of the root bone should by untouched)
We then run the skeletal animation and translational path animation in sync. So the character animates in place and is at the same time translated to the correct point in world space. The bounding box does not need to be updated since the animation of the character now includes only body motion of arms, legs etc., which are insignificant and do not invalidate the original bounding box of the model.

Re: Control BoundingBoxes on Entity-Level.

Posted: Wed Dec 24, 2008 1:04 pm
by madmarx
Same here than Red5_StandingBy's solution.

Re: Control BoundingBoxes on Entity-Level.

Posted: Mon Sep 14, 2009 8:38 pm
by koirat
My model is ok when running or walking, the problem is when i play death animation and then i have got a Fallen Pose. Since now character is aligned paralelle to the ground it's bounding box should be different.(it's not and my model is blinking when going out off FOV) I's there an easy way to update it's BB ? Ogre is doing it somehow at start can i just somehow repeat the process for current model state.

Re: Control BoundingBoxes on Entity-Level.

Posted: Mon Sep 14, 2009 9:28 pm
by madmarx
I don't know :
>>Ogre is doing it somehow at start
Not exactly, a boundingbox is stored within the mesh during the conversion to binary mesh. This bounding box is aggregated within the one of the parent node, using its actual rotation/scale/position.

I think you could try to alter the bounding box using : Ogre::Mesh::_setBounds ( const AxisAlignedBox & bounds, bool pad = true )
I have never done it myself though.

Re: Control BoundingBoxes on Entity-Level.

Posted: Tue Sep 15, 2009 12:56 am
by robtherich
madmarx wrote:I think you could try to alter the bounding box using : Ogre::Mesh::_setBounds ( const AxisAlignedBox & bounds, bool pad = true )
I have never done it myself though.
This works.

Re: Control BoundingBoxes on Entity-Level.

Posted: Tue Sep 15, 2009 8:48 am
by koirat
Thanks guys.
I will try it.

Re: Control BoundingBoxes on Entity-Level.

Posted: Tue Sep 15, 2009 8:52 pm
by Praetor
If you come up with an elegant solution then patches are welcome. The separate animations for translations and everything else seems less elegant but quite workable.

Re: Control BoundingBoxes on Entity-Level.

Posted: Sat Sep 19, 2009 10:10 pm
by oddrose
Not sure if it counts as elegant, but I'm implementing what has been on the roadmap for a while i.e. dynamic bounds for meshes. The implementation I'm doing is updating the bounds when the animation is updated and checks that the bounds are outside the bones+a padding "factor" that's defined in the mesh-file. Since I'm not involved in any exporter work I'll have to collaborate with someone on this I guess. The padding is going to be calculated as a maximum value of the distance from bones to the vertices attached to them. (In the 3d app).

Here's the implementation in more detail:
http://www.ogre3d.org/forums/viewtopic.php?f=4&t=52560

I think I'll manage to submit a patch in 1 to 2 weeks. (Busy with school=) )