Search code examples
three.jsblendergltf

Three.js mixer.time = n doesn't play on the n'th blender frame, nor does mixer.time=n/1000


In blender, my animation has a total length of 250ms.

enter image description here

But when I play my running animation to

mixer.time = 100/1000;

It only plays part of the animation.

    mixer = new THREE.AnimationMixer(cube);
      gltf.animations.forEach((clip) => {
      mixer.clipAction(clip).play();
             });
       });

...
     function seekAnimationTime(animMixer, timeInSeconds){
    animMixer.time=0;
    for(var i=0;i<animMixer._actions.length;i++){
      animMixer._actions[i].time=0;
    }
    animMixer.update(timeInSeconds)
  }

How to I make the animation run to a certain "frame" or time in blender units?

Any help appreciated.


Solution

  • using

    var duration = 0;
    ...
      mixer = new THREE.AnimationMixer(cube);
          gltf.animations.forEach((clip) => {
            duration = clip.duration;
          mixer.clipAction(clip).play();
                 });
    ...
    if(mixer!=null){
        var tar = 50; // percentage you want to play to
        var mul = duration*(tar/100)
            seekAnimationTime(mixer,elapsed*mul);//elapsed is a time scale running from 0 to 1
        }