Updating a btConvexHullShape in place

Post Reply
Jim Gray
Posts: 2
Joined: Tue Oct 07, 2014 3:29 pm

Updating a btConvexHullShape in place

Post by Jim Gray »

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! :D
Jim
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Updating a btConvexHullShape in place

Post by Erwin Coumans »

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
Jim Gray
Posts: 2
Joined: Tue Oct 07, 2014 3:29 pm

Re: Updating a btConvexHullShape in place

Post by Jim Gray »

Hi Erwin,

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();
	}
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
Post Reply