Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse Keyframe animation in Three.js

Tags:

three.js

Really I would like to reverse a keyframe animation using THREE.KeyFrameAnimation.update with a negative number, appreciate this isn't supported natively, has anyone got any advice?

like image 832
Greg Findon Avatar asked Feb 02 '26 17:02

Greg Findon


1 Answers

I actually found a solution to this for when you only want to play it once. I posted the full class here:

  • https://gist.github.com/rtpHarry/2d41811d04825935039dfc075116d0ad

The important bit is:

  // will force the mixer to play in reverse no matter what
  playClipReverseByIndex_Forced(index) {
    this.action = this.mixer.clipAction(this.animations[index]);

    if(this.action.time === 0) {
        this.action.time = this.action.getClip().duration;
    }

    this.action.paused = false;
    this.action.setLoop(THREE.LoopOnce);      
    this.action.timeScale = -1;
    this.action.play();
  }
like image 90
rtpHarry Avatar answered Feb 05 '26 14:02

rtpHarry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!