play animation once instead of looping three.js

久未见 提交于 2020-01-24 12:43:06

问题


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.


回答1:


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.




回答2:


Set the loop property on the Animation object to false.

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



来源:https://stackoverflow.com/questions/33959167/play-animation-once-instead-of-looping-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!