Convex Decomposition Explodes?

Post Reply
Posts: 1
Joined: Fri Jul 20, 2012 7:11 pm

Convex Decomposition Explodes?

Post by danwexler » Fri Jul 20, 2012 8:11 pm

I'm using the HCAD code to create btConvexHullShapes and associated btRigidBodys, but the resulting system explodes violently!

Specifically, I take a convex object (rubber duck) about 10 units wide and decompose it using HCAD into clusters. For each cluster, I compute the centroid and recenter the points in the original mesh associated with that cluster (using HCAD::GetPartition) so that the centroid becomes the origin. Then I create a btConvexHullShape for each cluster, also adjusting the points returned by HCAD::GetCH so the centroid is the origin (e.g. P - centroid). I set the btConvexHullShape::SetMargin to 0.01f and the startTransform for the MotionState using setOrigin(centroid) to move the cluster back to its original position. I create a btRigidBody using btPolyhedralConvexShape::calculateLocalInertia for the MoI with a mass of 10, friction of 0.99 and restitution of zero and btRigidBody::setContactProcessingThreshold of BT_LARGE_FLOAT.

This is all based on the ConvexDecomposition demo code. My hulls look great. The hulls start in the correct position, but immediately explode VIOLENTLY in all directions! I have not applied any external forces. I assume this is likely due to the "approximate" part of the decomposition resulting in overlapping objects?

My goal is to have a stable shape made up of individual convex parts, which will later be exploded by applying external forces. My plan was to use the btTypedConstraint::setBreakingThreshold to create breakable joints between the hulls, but I haven't started created constraints yet because the model is unstable. I don't expect the model to retain its original shape after converting it to separate rigid body hulls, but I didn't expect it to explode -- perhaps instead it would just crumble like a broken porcelain duck.

How can I make the original set of rigid bodies for each hull stable? I feel like I'm missing something silly -- perhaps a bad margin/padding value? Or should I place the hulls in a btCompoundShape and wait for an impulse larger than some threshold before separating them into individual rigid bodies. Or should I create p2p breakable constraints and just set the threshold high enough to prevent the initial explosion? Or should I "shrink" each hull slightly towards its centroid to prevent intersection? What's the best way to check for or prevent hull-hull intersections?

Code excerpt, images and video reference:

Code fragment:
Original mesh, partitioned:
Hulls with HCAD::SetNVerticesPerCH to 100 (no lighting normals):
Video of undesired explosion (apologies for wartermark):

Post Reply