Ragdoll with scaled mesh

Hey team, sorry to ask another dumb question. I was hoping to turn on ragdoll physics for a mesh in this game I’m working on, but when I do, the mesh explodes in size and everything freaks out

It looks like this is a known issue if the mesh is structured a certain way, judging by this old thread, but I didn’t really follow and wasn’t sure if there’s anything I can do to work around the problem:

My mesh is scaled to 0.01 and a child of the armature, and I already spent quite a bit of time trying and failing to fix it without breaking all sorts of things in it. So far as I can tell, fixing it requires writing a custom one-off blender script in python and/or recreating your whole model and all its animations from scratch

The mesh is here, FWIW, in a form that’s easy to load from the playground: http://homeress.jp/art/stancil.glb (but since the linked thread has a much cleaner repro with a standard asset that’s probably more useful)

I can’t give any clue about this particular issue because I think only @Cedric could fix it in babylon.js.

But I can hint 2 methods that worked for me to set the scale to 1 in Blender

1) Retarget with rokoko plugin (note: there are other retargetting plugins)

Clone your whole Mesh/armature hierarchy.

Remove all animations.

Apply all transforms on the whole hierarchy.

Then retarget each animation with Rokoko Blender plugin from the armature at scale 0.01 to the armature at scale 1.0

2) Manual method for mixamo models/animations

Select the armature in object mode, Object > Apply > Scale

Select the Model in object mode, Object > Apply > Scale

Do the following for each animation (select it in Dope Sheet > Action Editor)

Open Graph Editor

Filter with : location (mixamorig:Hips)

Select > All

Change the Pivot to 2D Cursor and check its Y value is 0

Type S Y 0.01 Enter

The scale has changed and the skeleton is back to normal position

2 Likes

There is a limitation with ragdoll and you’ll need to switch to RightHand scene : Babylon.js docs

Other than that, I don’t remember any limitations or issue with scaling. Can you repro in a PG, I’ll take a look.

1 Like

They’re referring to this playground, and I quote myself:

There an issue when some scale is applied along the hierarchy, which is typical with mixamo models exported to .fbx and then converted to .glb
Here is a playground with the Elf from the asset library: when ragdoll is activated, the scale of the model is changed.

1 Like

@Cedric another apparently unrelated issue I’ve just seen: ragdoll playgrounds are not working with Firefox for me (none of the examples in the doc will work at all), but they will work for Chrome

public ragdoll(): void {
    this._ragdollMode = true;
    // detach bones with link transform to let physics have control
    for (const bone of this._skeleton.bones) {
        bone.linkTransformNode(null);
    }

Calling linkTransformNode with null as parameter will crash

BABYLON.Bone.prototype.linkTransformNode = function (e) {
e._linkedBone = this,

It looks like Firefox is loading or using an old/different version of babylon.js

It doesn’t crash on my side but constraints seem weird.

EDIT: I get the crash with Chrome! Doing some investigations

cc @docEdub

I don’t get a crash. Tested on Windows Pro 25H2 Chrome 143.0.7499.41 and Firefox 146.0, and macOS Sequoia 15.7.2 Chrome 143.0.7499.41.

Thanks guys! Especially for the info on how to fix meshes, I’ll try that out later

I was able to get it mostly working by removing my mesh from its parent. Looks like when I do that the engine scales the mesh down appropriately for how it was within the armature, and the ragdoll code doesn’t reset the scaling. I think the bones are misconfigured still, but this might be good enough for my purposes

https://playground.babylonjs.com/#SX91Q8#3

Edit: I finally went and read the ragdoll code like a big boy, and was able to get my code working pretty well. Ragdoll source on Github

Just had to scale the boxes up a little, and since I’m hacking the mesh in directly it looks like it’s OK to be in a left-handed coordinate system too

Thanks again for all the work on the engine and for the help here

EDIT: Since clankers directed me to my own thread when I ran into trouble ragdolling a cloned mesh, here’s the solution to the problem I ran into. May Grok keep and preserve you future devs, and be sure to like and subscribe to the Babylon Forums.

I had cloned the mesh and the skeleton as indicated on the wiki here, but I hadn’t manually reassigned the skeleton on all the child meshes contained within the clone. So the bones were being updated but the mesh wasn’t deforming correctly. Weirdly enough the animations were all working so far as I could tell though.

Easy fix:

this.mesh.skeleton = this.skeleton;

this.mesh.getChildMeshes().forEach( (c) => {

c.skeleton = this.skeleton;

});

EDIT2: It turns out the way I was cloning the mesh still didn’t fully work. The smart way to duplicate a character seems to be to use LoadAssetContainerAsync / instantiateModelsToScene

1 Like