Jump to content

animationGroup weight and blending are not working for certain gltf file


shen
 Share

Recommended Posts

First, animationGroup.setWeightForAllAnimatables works for the UFO file https://www.babylonjs-playground.com/#PSR2ZX#17, but not https://www.babylonjs-playground.com/#PSR2ZX#18. Is it because of the skeleton animation? 

        /**
         * Start all animations on given targets
         * @param loop defines if animations must loop
         * @param speedRatio defines the ratio to apply to animation speed (1 by default)
         * @param from defines the from key (optional)
         * @param to defines the to key (optional)
         * @returns the current animation group
         */
        public start(loop = false, speedRatio = 1, from?: number, to?: number): AnimationGroup {
            if (this._isStarted || this._targetedAnimations.length === 0) {
                return this;
            }

            for (const targetedAnimation of this._targetedAnimations) {
                this._animatables.push(this._scene.beginDirectAnimation(targetedAnimation.target, [targetedAnimation.animation], from !== undefined ? from : this._from, to !== undefined ? to : this._to, loop, speedRatio, () => {
                    this.onAnimationEndObservable.notifyObservers(targetedAnimation);
                }));
            }

            this._speedRatio = speedRatio;

            this._isStarted = true;

            return this;
        }

In AnimationGroup, beginDirectAnimation was used. Will beginWeightedAnimation make weight and blending working?

Second (I guess is't a different issue), 

    scene.animationPropertiesOverride = new BABYLON.AnimationPropertiesOverride();
    scene.animationPropertiesOverride.enableBlending = true;
    scene.animationPropertiesOverride.blendingSpeed = 0.02;

That works with https://www.babylonjs-playground.com/#BCU1XR, but not with scene.animationGroups._targetedAnimations.animation.enableBlending (in both https://www.babylonjs-playground.com/#PSR2ZX#17 and https://www.babylonjs-playground.com/#PSR2ZX#18). The value of enableBlending is always undefined. 

BTW, Weight -1 means stop while 0 also means stop too. That's confusing. 

Link to comment
Share on other sites

Ok that's a lot of questions:

setWeightForAllAnimatables: what do you want to achieve here? Did you read this: http://doc.babylonjs.com/babylon101/animations#animation-weights. If you set everyone to 0 then there is no animation as they all will be multiplied by 0

scene.animationGroups._targetedAnimations: you should not use a _function as they are internal to the engine. What do you want to achieve here?

Link to comment
Share on other sites

 

57 minutes ago, Deltakosh said:

setWeightForAllAnimatables: what do you want to achieve here?

As I understand, if two 2 animationGroups with weight say 0.5 are playing together, they can blend like https://www.babylonjs-playground.com/#BCU1XR. In the playground, weight of different animationGroup can be controlled by the sliders, and the blending in UFO case seems working but not in the ybot case. 

I updated the demo here https://www.babylonjs-playground.com/#PSR2ZX#31, and let it start with default weight. You can only the third animation run although all three animationGroups are playing. If you use the slider set weight between 0 and 1, the animation will just stop playing. 

Forget about what I said "-1 and 0 are confusing". It's off topic. 

57 minutes ago, Deltakosh said:

scene.animationGroups._targetedAnimations: you should not use a _function as they are internal to the engine. What do you want to achieve here?

In animationGroups.start 

public play(loop?: boolean)

            for (const targetedAnimation of this._targetedAnimations) {
                this._animatables.push(this._scene.beginDirectAnimation(targetedAnimation.target, [targetedAnimation.animation], from !== undefined ? from : this._from, to !== undefined ? to : this._to, loop, speedRatio, () => {
                    this.onAnimationEndObservable.notifyObservers(targetedAnimation);
                }));
            }

I found that animations pushed in _animatables didn't have value on enableBlending. So I just wonder is it the cause of the blend problem. 

Link to comment
Share on other sites

It's generated from ybot.fbx (I guess the same as dummy3.babylon) with https://github.com/Kupoman/blendergltf following https://www.donmccurdy.com/2017/11/06/creating-animated-gltf-characters-with-mixamo-and-blender/. The animation blending is working with three.js (you can try to open it with https://gltf-viewer.donmccurdy.com/). 

I guess that 400 animations are targeting different bones. How many animations are there normally in a group?  

Link to comment
Share on other sites

The animation works for Babylon.js as well but I don't think there is 400 bones in this scene. This looks suspicious 

 

Furthermore when the code for blending works with dummy3 and not your exported files. Can you try to use your mesh in this demo: https://www.babylonjs-playground.com/#PSR2ZX#10

Just to make sure we are good even with 400 animations. Blending is enabled by default in this demo so it will help to understand

Link to comment
Share on other sites

Ok so it is working which means that even if the mesh is not optimal it does not have errors :)

Also this demo demonstrates that blending between animations works 

 

Now let's go back to animation weights: I finally understood why it was not working :). You must export for model with bones animation and not direct TRS animation for every single mesh (Does it make sense?)

 

 

Link to comment
Share on other sites

If it's model's problem, why weights are working in three.js https://jsfiddle.net/shenzhuxi/hvvz9bc8/

I just checked out the latest Babylon.js code, and now seems it's working ... some kind ... in a hilarious way https://www.babylonjs-playground.com/#PSR2ZX#18

In the model https://gist.github.com/shenzhuxi/cf7ad7ce73ca6228a99a0a64a7eb6ab8/raw/d919fd82a5768a236b55fb0011603ca7b46ded5d/ybot.gltf, the animations of Alpha_Surface are working, but the animations of Alpha_Joints (the balls) are not. 

Link to comment
Share on other sites

Unfortunately this is almost impossible to debug as there are too much animations and furthermore you are doing skining without bones.

I highly recommend to first fix the model and export it with skeleton animations (if you re using Blender perhaps using the babylon exporter should be a better option)

Link to comment
Share on other sites

OK I'm back with good news!

I found a bug in my quaternion computation so now this works:

https://www.babylonjs-playground.com/#PSR2ZX#31

This one as well: https://www.babylonjs-playground.com/#PSR2ZX#34

Please note that you should not try to get more than two quaternions blended because there is no simple math way to compute a correct result. This means you should not have more than two group running together and you should try to keep the weight sum == 1

 

I'm sorry about the inconvenience and I want to apologize because I realized really lately that you had 2 bones plus an animated mesh hierarchy.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...