Hi!
I'm programming a visual editor where the user can modify btConvexHullShapes, in a way similar to a modeling program.
As the user adjusts the shape, I'd like (in my code) to simply clear all the points of the btConvexHullShape and re-add the updated points.
At present, I didn't find any member functions on class btConvexHullShape for clearing the points, or even removing them.
It seems like the expected approach is to create a new btConvexHullShape, add the new points, then delete the old btConvexHullShape.
For performance reasons (e.g., avoiding unnecessary calls to new and delete), I'd prefer to update the btConvexHullShape in place.
E.g., call pMyShape->clearAllPoints(), then add the new points.
By the way, if btConvexHullShape::m_unscaledPoints was a protected member (instead of private), I could create a derived class
(e.g., class MyConvexHullShape : public btConvexHullShape) and simply implement clearAllPoints() in the derived class.
Unfortunately, m_unscaledPoints is private, so that's not an option.
Any suggestions are appreciated. Thanks!
Jim
Updating a btConvexHullShape in place
- Erwin Coumans
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
- Contact:
Re: Updating a btConvexHullShape in place
You could derive a class from the btConvexHullShape and update the points
(or add a 'setPoint' method)
Just make sure to re-calculate the local AABB (it is cached/computed once) and the global AABB.
You can make it protected and create a patch. By the way, I am considering to store the points as structure of arrays (instead of an array of vertices) to make it easier to vectorize the 'getSupportVector' in SIMD/SSEx.
Hope this helps,
Erwin
(or add a 'setPoint' method)
Just make sure to re-calculate the local AABB (it is cached/computed once) and the global AABB.
You can make it protected and create a patch. By the way, I am considering to store the points as structure of arrays (instead of an array of vertices) to make it easier to vectorize the 'getSupportVector' in SIMD/SSEx.
Hope this helps,
Erwin
Re: Updating a btConvexHullShape in place
Hi Erwin,
Thanks for the reply!
For the moment, I simply added this member function to my local version of btConvexHullShape.
It seems to work fine for my current purposes.
Ideally, my local source would be in sync with the official version of Bullet. But this is my first modification to Bullet, so I'm tempted to live with the minor inconsistency, for the moment. If I need to make a second change to Bullet, that might be the right time for me take the plunge are start submitting patches.
Jim
Thanks for the reply!
For the moment, I simply added this member function to my local version of btConvexHullShape.
Code: Select all
void clearPoints(bool recalculateLocalAabb)
{
m_unscaledPoints.resize(0);
if (recalculateLocalAabb)
recalcLocalAabb();
}
Ideally, my local source would be in sync with the official version of Bullet. But this is my first modification to Bullet, so I'm tempted to live with the minor inconsistency, for the moment. If I need to make a second change to Bullet, that might be the right time for me take the plunge are start submitting patches.
Jim