favreau / bullet

Automatically exported from code.google.com/p/bullet
0 stars 0 forks source link

[Performance] btCompoundShape::setLocalScaling does a lot of unnecessary recalculateLocalAabb #487

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Bullet trunk:

void    btCompoundShape::updateChildTransform(int childIndex, const 
btTransform& newChildTransform)
{
        ...
        recalculateLocalAabb();
}

...

void btCompoundShape::setLocalScaling(const btVector3& scaling)
{

        for(int i = 0; i < m_children.size(); i++)
        {
                ...
                updateChildTransform(i, childTrans);
                recalculateLocalAabb();
        }
        m_localScaling = scaling;
}

Note that there's one recalculateLocalAabb at the end of updateChildTransform, 
and then another one right after the call to updateChildTransform in 
setLocalScaling. The second is obviously superfluous, but, without knowing this 
code in and out, it also seems that only a single call to recalculateLocalAabb 
is needed at the end of setLocalScaling. This change makes the creation time of 
a 5000 shape compound shape go from several seconds to ~0. Resulting code:

void    btCompoundShape::updateChildTransform(int childIndex, const 
btTransform& newChildTransform, bool shouldRecalculateLocalAabb = true)
{
        ...
        if(shouldRecalculateLocalAabb)
                recalculateLocalAabb();
}

...

void btCompoundShape::setLocalScaling(const btVector3& scaling)
{

        for(int i = 0; i < m_children.size(); i++)
        {
                ...
                updateChildTransform(i, childTrans, false);
        }
        m_localScaling = scaling;
        recalculateLocalAabb();
}

Original issue reported on code.google.com by mirza.ga...@gmail.com on 3 Mar 2011 at 6:11

GoogleCodeExporter commented 9 years ago
Good point, I applied the patch in latest trunk:
http://code.google.com/p/bullet/source/detail?r=2322

Thanks for the feedback!
Erwin

Original comment by erwin.coumans on 4 Mar 2011 at 8:17