Skeletal Animation + Babylon Animation

I’m working on setting up a two-part animation similar to this playground, where I have skeletal animation as well as rotational animation on a specific part of the model in Babylon. But, somewhere, I’m setting stuff up wrong.

My skeleton hierarchy (the image below) is probably different from the Dude’s,
image
but I don’t think that’s an issue since I was still able to locate the bone I want to rotate through scene.getBoneByName()

But when I try applying the logic below to the bones in my PG that are being logged, nothing seems to happen.

var scaleMatrix2 = BABYLON.Matrix.Compose(new BABYLON.Vector3(10,10,10), BABYLON.Quaternion.Identity(), BABYLON.Vector3.Zero());

            console.log(skeleton.bones)

            var initMat = skeleton.bones[0].getLocalMatrix().clone();

            var m = skeleton.bones[0].getLocalMatrix();

            m.multiplyToRef(scaleMatrix2, m);

            animation.start(true);

            var angle = 0;

            scene.registerBeforeRender(function () {

                var mat = skeleton.bones[0].getLocalMatrix().copyFrom(initMat);

                mat.multiplyToRef(BABYLON.Matrix.RotationZ(angle), mat);

                angle += 0.1;

                skeleton.bones[0].markAsDirty();

            })

I’ve tried, rotate, rotation, and setRotation as well in different formats (potentially all wrong as well) and haven’t had any success.

Any advice on this would be greatly appreciated.

Unfortunately I can’t provide a PG link (I’ve never saved one) due to the proprietary nature of the content I’m working with. :frowning:

1 Like

I enabled Debug on the bone I was trying to rotate and I saw it rotating in the PG however, it kept snapping back to 0 if I tried to change it’s rotation in the Inspector . Is the animation from the animation groups overriding it?

In addition, it’s pivot was off. In Maya, it had one pivot, in Babylon, it seemed to have the pivot of the top joint in the rig. Then when I played an animation from one of my animation groups, the pivot changed.

Unfortunately we will need a repro. I have no clue what can be wrong without seeing a repro :frowning:

It could come from a lot of reasons. For instance if you are loading a glTF file the bones are actually controlled by transformNode

1 Like

I created a proxy rig and saved a PG using that:

https://www.babylonjs-playground.com/#FWQMXF

The goal is to spin the top bar while the two boxes on the side continue their bounce animation.

As you are loading a gltf/glb file, the transformations of the skeleton are not to be read on the bones but on the linked transform nodes instead.

You should use bone.getTransformNode() to get the transform node on which to apply your transformations:

https://playground.babylonjs.com/#FWQMXF#2

5 Likes

This has been the single most useful comment I have come across! I have been searching the forums trying to figure out how to get playground examples working with glb files. Most examples are either .babylon files + skeletons or .glb files + animationGroups. There is very little information on how to use skeletons with glb files.