I have a custom animation system
If you wrote your own animation system, you’re doubtless aware such systems juggle dozens of coordinate transforms and their inverses:
- model to world,
- bone bind to parent (for each bone),
- bone bind to model (for each bone), and
- bone local to-bind (for each bone).
I want to spawn a ragdoll matching its final pose.
Converting a character pose to a physics ragdoll requires fluency in combining transforms. The complexity is magnified when coordinate transforms are expressed in diverse ways:
- matrices,
- quaternions,
- Euler angles (6 orderings), and
- Tait-Bryan angles (6 orderings).
JMonkeyEngine has 2 built-in animation systems, one dating from 2012 and another from 2019. If you used either of those systems, then the DynamicAnimControl
class (found in both the jme3-jbullet and Minie libraries) would handle the coordinate transforms for you. There’s even a graphical tool (named DacWizard) to generate and tune Minie ragdolls for any animated model.
Since you’re re-inventing the wheel instead, DynamicAnimControl
and DacWizard won’t benefit you directly. However, they’re 100% open source, so perhaps you can benefit from studying the source code.
One trick for troubleshooting ragdoll physics is to start with very simple animated models. Humanoid models involve dozens of bones; their complexity makes them almost impossible to debug. For testing and troubleshooting, start with models having 1-3 bones.
I take each bone’s finalTransform (using joml.Matrix4f) and apply it to JBullet’s BoxShape, but the collision shapes appear in the wrong place.
Is finalTransform
defined relative to physics-space coordinates? If not, then it can’t be applied directly to a collision object.
Should I use BoxShape, CapsuleShape, or something else for ragdoll bones?
The best shape depends on the bone you’re trying to simulate. For torsos, I tend to use convex-hull shapes or multi-sphere shapes. For limbs, I generally use convex-hull shapes or capsule shapes.
- Living creatures do not have sharp corners. Therefore, I would only consider box shapes for particularly blocky robots.
- Convex-hull shapes can match meshes more closely, but they consume more CPU during simulation.
- Multi-sphere shapes aren’t available in JBullet because it’s based on a 2010 snapshot of Bullet that pre-dates multi-sphere shapes. For this reason alone, I recommend switching from JBullet to Libbulletjme.
I’m struggling with ConeTwistConstraint and Point2PointConstraint.
DynamicAnimControl
uses generic 6-dof constraints exclusively, so I don’t have any advice specific to cone-twist/p2p constraints. When tuning ragdolls, I often start by giving each rotational degree of freedom (DOF) a range of +/- one radian (about 57 degrees of arc) and then reduce the ranges from there.
Are there working examples for this?
All my ragdoll examples use JMonkeyEngine, DynamicAnimControl
, and 6-dof constraints. A good starting point might be the TestDac
demo app in the MinieExamples project: (see An overview of the demo applications :: The Minie project), which generates and simulates ragdolls for 8 different animated models.
Sorry I’m not good at troubleshooting unfamiliar/undocumented code simply by reading it.