btGhostObject always active and always recalculating AABB

cgripeos
Posts: 20
Joined: Mon Sep 24, 2007 5:45 am

btGhostObject always active and always recalculating AABB

Post by cgripeos »

Hi everybody,

I have an issue that I've worked around but I don't feel good about my solution.

I noticed that in our scenes we have a lot of Ghosts and spend up to 3ms updating them.


The Ghosts have setCollisionFlags set to btCollisionObject::CF_NO_CONTACT_RESPONSE.

The DyanmicsWorld has mDynamicsWorld->setForceUpdateAllAabbs(false) so that aabbs of CollisionObjects should not be calculated if the CollisionObjects are not active.


Looking at the Bullet profiler, almost all the time is spend in updating the Ghost AABBs in btCollisionWorld::updateAabbs().

After some investigation I noticed that, even though the Ghosts never move, they are always active and that means that their aabbs get recalculated every frame.

To get around this, I changed the code in btCollisionWorld::updateAabbs() from

Code: Select all

//only update aabb of active objects
if (m_forceUpdateAllAabbs || colObj->isActive()))
{
   updateSingleAabb(colObj);
}
to skip Ghosts ...

Code: Select all

//only update aabb of active objects
if (m_forceUpdateAllAabbs || (colObj->isActive() && (colObj->getInternalType() != btCollisionObject::CO_GHOST_OBJECT)))
{
   updateSingleAabb(colObj);
}
... and then I changed my code so that every time I do change a Ghost's world transform I manually do btCollisionWorld::updateSingleAabb() on it.

This was all so that the aabb of a Ghost is not recalculated unless its transform changes.

Is this the right way to solve this problem?
Are there better, less hacky solutions that I am not thinking of?

Thanks in advance for any help,

cg
cgripeos
Posts: 20
Joined: Mon Sep 24, 2007 5:45 am

Re: btGhostObject always active and always recalculating AAB

Post by cgripeos »

I haven't gotten any replies yet.

I just wanted to add that with the above fix, we shaved off 3ms from Bullet's update call.

This performance problem (I would think) is very common in games that use btGhostObjects as "game triggers".

Again, any ideas as to how to solve this problem differently/more-cleanly would be greatly appreciated.

Thanks again,
cg
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: btGhostObject always active and always recalculating AAB

Post by Erwin Coumans »

Yes, if your ghosts AABB updates takes too much time, that is a good solution.

We could add some lazy-evaluation/flags that detect change of transform, to avoid AABB recalculation,
but we lack the time/resources to do so.