GLTFLoader: Unable to run animations

I have a glb created in Blender. I am importing it to my scene just fine. I can see the animations and they play when running on the gltf viewere . I can see them in my console…

The problem is I cannot get the animation to play. I have been reading this discourse for days and cannot figure what I’m doing wrong here…I’m just trying to pose this figure. Some guidance would be appreciated.

Thanks!

        loader.load('/public/makeavatar/base/avatar.glb', function ( gltf ) {,,,,,
              let avatar = gltf.scene
              avatar.animations = gltf.animations; 
              scene.add(avatar);

              function setPose (avatar, getPose){
                console.log (avatar.animations);
                var i = 0
                avatar.animations.forEach((clip) => {
                    if (clip.name == getPose){
                         var mixer = new AnimationMixer( avatar );
                         console.log(i + " " +clip.name)
                         var action = mixer.clipAction(clip);
                         action.clampWhenFinished = true;
                         action.play();
                         console.log(action);
                    }
                    i = i + 1
                });
            }

setPose (avatar, “Standing”);

You have to update the instance of AnimationMixer in your animation loop. This can’t work if you create a local variable in the setPose() function.

Thanks! I had it outside but moved it in to see if it made a difference… moving it out has nil effect. Do I need to set a frame or something?

Check out how the mixer is managed in this example:

https://threejs.org/examples/webgl_animation_skinning_morph

You essentially have to do the same in your app.

Thank you sir!