From 7d9bcafda8649dee657a727bc2f5d1a4c6beb609 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 10 Aug 2020 17:00:19 -0700 Subject: [PATCH] when using stablePDPlugin, approximate inertia by box for unsupported shapes. --- .../plugins/stablePDPlugin/BulletConversion.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/SharedMemory/plugins/stablePDPlugin/BulletConversion.cpp b/examples/SharedMemory/plugins/stablePDPlugin/BulletConversion.cpp index 224afaf9a..cb6bacd33 100644 --- a/examples/SharedMemory/plugins/stablePDPlugin/BulletConversion.cpp +++ b/examples/SharedMemory/plugins/stablePDPlugin/BulletConversion.cpp @@ -93,6 +93,7 @@ bool btExtractJointBodyFromTempLinks(btAlignedObjectArray& links, Eige collisionShape = compound->getChildShape(0); } } + switch (collisionShape->getShapeType()) { case BOX_SHAPE_PROXYTYPE: @@ -102,6 +103,7 @@ bool btExtractJointBodyFromTempLinks(btAlignedObjectArray& links, Eige param0 = box->getHalfExtentsWithMargin()[0] * 2; param1 = box->getHalfExtentsWithMargin()[1] * 2; param2 = box->getHalfExtentsWithMargin()[2] * 2; + break; } case SPHERE_SHAPE_PROXYTYPE: @@ -124,7 +126,20 @@ bool btExtractJointBodyFromTempLinks(btAlignedObjectArray& links, Eige } default: { - btAssert(0); + //approximate by its box + btTransform identity; + identity.setIdentity(); + btVector3 aabbMin, aabbMax; + collisionShape->getAabb(identity, aabbMin, aabbMax); + btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5); + btScalar margin = collisionShape->getMargin(); + btScalar lx = btScalar(2.) * (halfExtents.x() + margin); + btScalar ly = btScalar(2.) * (halfExtents.y() + margin); + btScalar lz = btScalar(2.) * (halfExtents.z() + margin); + param0 = lx; + param1 = ly; + param2 = lz; + shapeType = cShape::eShapeBox; } } }