Arun Kumar
Arun Kumar

Reputation: 81

play animation once instead of looping three.js

I have exported blender JSON animation into THREE.js, everything works fine, but I want to play the animation only once and stop instead of looping the animation.

Upvotes: 8

Views: 14483

Answers (3)

Sjoerd Spoelstra
Sjoerd Spoelstra

Reputation: 1

Make sure you type LoopOnce NOT loopOnce (as I did). Took me hours to spot that one (no error message).

Upvotes: 0

a.barbieri
a.barbieri

Reputation: 2596

Old question, but in case anyone needs it the solution is to set animation.setLoop(THREE.LoopOnce)

let objLoader = new THREE.ObjectLoader();

objLoader.load('./your.json', function(obj)
{
  scene.add(obj);

  let animationMixer = new THREE.AnimationMixer(obj);
  let animation = animationMixer.clipAction(obj.animations[0]);
  animation.setLoop(THREE.LoopOnce);
  animation.clampWhenFinished = true;
  animation.enable = true;

  animation.play();
})

I'm referring to ThreeJS r84.

Upvotes: 16

Tennyson H
Tennyson H

Reputation: 1716

Set the loop property on the Animation object to false.

documentation here: http://threejs.org/docs/#Reference/Extras.Animation/Animation

Upvotes: 1

Related Questions