【问题标题】:play animation once instead of looping three.js播放一次动画而不是循环three.js
【发布时间】:2016-03-01 18:16:00
【问题描述】:

我已将搅拌机 JSON 动画导出到 THREE.js, 一切正常,但我只想播放一次动画并停止而不是循环播放动画。

【问题讨论】:

    标签: html animation three.js blender


    【解决方案1】:

    老问题,但如果有人需要,解决方案是设置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();
    })
    

    我指的是 ThreeJS r84

    【讨论】:

    • 我发现我需要在play之后做一个reset,所以animation.play().reset();
    【解决方案2】:

    Animation 对象的loop 属性设置为false。

    此处的文档:http://threejs.org/docs/#Reference/Extras.Animation/Animation

    【讨论】:

      猜你喜欢
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 2021-03-16
      • 1970-01-01
      相关资源
      最近更新 更多