Rotation property animation for a GLB Model doesn't work

The Animation works perfectly for mesh created using MeshBuilder.CreateBox. but
the rotation animations just don’t work for the GLB mesh.

var animationTurnRight = new BABYLON.Animation(“MyAnimationMove”, “rotation.y”, frameRate,
BABYLON.Animation.ANIMATIONTYPE_FLOAT,
BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
var turnRightKeys = [
{
frame: 0,
value: 0
},
{
frame: 4*frameRate,
value: 0.5
},
];
scene.beginDirectAnimation(anim_model, [animationTurnRight], 0, 5 * frameRate, false,1);

Hey!
are you sure you are animating the right model? gltf models offer more than one mesh in the hierarchy

you can use scene.debugLayer.show() to see how it looks like

Sorry to pick up this ages old Thread, but the problem seems to fit:

We have a custom setup, but maybe someone has any idea:
If I change the targetProperty to “scaling.x” or “postion.x” this works flawlessly, using any rotation component will play an Animation in the Inspector, but rotation values will not change in the Inspector, nor will the model animate.
Using scaling and position I see the values change in the Inspector and the animation.

Any ideas?

here is my function:

createRotationAnimation(name, targetMesh, startValue, endValue){
        console.log("Creating Animation.")
        const frameRate = 30
        const rotationAnimation = new Animation(name, "rotation.y", frameRate, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CYCLE);
        const keyFrames = [];

        keyFrames.push({
            frame: 0,
            value: startValue,
        });

        keyFrames.push({
            frame: frameRate * 3,
            value: Math.PI * 2,
        });

        rotationAnimation.setKeys(keyFrames);
        const object = this.scene.getMeshByID(targetMesh);
        object.animations = []
        object.animations.push(rotationAnimation);
        this.scene.beginAnimation(object, 0, 90, true);
        console.log(endValue)

    }

gltf models are using rotationQuaternions and not rotation by default. So you either need to animate the quaternion or you need to setup the mesh.rotationQuaternion to null before playing with the euler rotation.

3 Likes

Wow! That was quick! I’ll look into it!
Thanks!

I’ve spent two days trying to figure out why my rotation animations don’t work. I finally found this thread, which then allowed to find this sentence in the docs

  1. Some software saves all meshes with a rotationQuaternion set and you cannot then use the rotation methods unless you first add
    myMesh.rotationQuaternion = null; //Any version of Babylon.js

That is just so random.

Guys… surely we can do better at surfacing user usage errors. May I suggest throwing an error when attempting to use Euler angle rotations while a quaternion vector is set on the mesh/model?

Or… even better, just provide methods on all rotatable objects that can take Euler angles but do them using quaternions under the hood. Meaning, all rotations are always done as quaternion computations, but a user can get and set the rotation values as Euler angles with new API methods.

1 Like

Adding @PirateJC for the doc

@arcman7, first and foremost, welcome to the Babylon family! It’s great to have you here.

Secondly, great suggestion. Sorry this was hard one to figure out. I’ve run into similar frustration in the past myself trying to navigate the difference between rotationQuaternion and Euler angles.

One thing we could do is add some more examples in the docs, but it doesn’t sound like you’re suggesting a doc update here, but rather better error handling OR perhaps some new methods that are a bit intelligent under the hood, allowing the developers to not have to worry about mentally managing this difference themselves?

I like this last idea a lot. @sebavan - Not sure how technically possible this would be but it’s definitely worth exploring and talking about.

Let me know if there’s a specific doc update that we think would be helpful in the meantime.

Cheers!

2 Likes

Hi PirateJC, thanks for the warm welcome :smile: Overall I do appreciate Babylon JS, I’ve gotta say my tiny project is coming along thanks to this library. There have been a number obstacles I’ve encountered throughout my adoption period however, and I’d be happy to elaborate on what those have been for me personally in another thread (where ever appropriate).

I am suggesting either throwing an error when the operation the user is attempting to do is blocked by the existence of the rotationQuaternion property or a bigger change that accomplishes:

OR perhaps some new methods that are a bit intelligent under the hood, allowing the developers to not have to worry about mentally managing this difference themselves?

I figure since I’m going to be using this library so much I’d be happy to try making a pull request for the smaller change of throwing an error, just to start with, but I’d definitely need someone to pair up with to get my dev environment set up and to show me where to even make those changes.

3 Likes

Awesome! We are always THRILLED to have people contribute to Babylon!

Here’s a good doc to review to get started contributing:

If you get stuck along the way, feel free to use the forum for help. You’ll hopefully discover that this is a VERY friendly and helpful community of people. :slight_smile:

Looking forward to seeing your first PR!

1 Like

Cool, I’ll start here and take a look. Btw, do you guys have a discord channel?

Nope. It’s something we’ve thought about but the forum and twitter are our main touchpoints.

Also YouTube, but that’s mostly outbound comms.

@arcman7 hi, just checking in! Were you able to set up the environment to contribute, are you having any difficulties? :grinning_face_with_smiling_eyes:

Hi @carolhmj I’ll have to try setting up the environment again sometime in the near future. If I have any problems I will let you know. Thanks for asking!

1 Like