play animation once instead of looping three.js

2019-07-17 05:43发布

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.

2条回答
迷人小祖宗
2楼-- · 2019-07-17 06:00

Set the loop property on the Animation object to false.

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

查看更多
做个烂人
3楼-- · 2019-07-17 06:15

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 )

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

  animation.play()
})

I'm referring to ThreeJS r84.

查看更多
登录 后发表回答