threejs mixer 不使用 'setTime' 更新



>我有一个 threejs 动画混音器设置如下:

this.mixer = new THREE.AnimationMixer(this.object);
this.mixer.timeScale = 2; //play twice as fast
this.mixer.addEventListener('finished', this.handlePullAnimFinished);
this.pullAnim = this.mixer.clipAction(this.animations[0]);
this.pullAnim.clampWhenFinished = true;
this.pullAnim.setLoop(THREE.LoopOnce);
this.pullAnim.enable = true;

但是如果我尝试做类似this.mixer.setTime(0.5)的事情,可以选择地this.mixer.update()什么也没发生

如何以编程方式将混音器设置为动画中的特定点(而不是自动播放(?

我已经在这里看到了有关设置动画以自动播放的文档(并成功地使其工作(

乍一看,你的错误是.update()没有任何论据。

根据文档,混音器希望更新方法在每帧上以秒为单位接收更改。

根据此演示,您可以执行以下操作:

var clock = new THREE.Clock();
function animate() {
var dt = clock.getDelta();
mixer.update( dt );
renderer.render( scene, camera );
requestAnimationFrame( animate );
}

你可以试试这个:

// r3f version
useEffect(()=>{
action.play()
}, [])
useFrame(()=>{
mixer.setTime(.3)
})
// vanilla version
actions['EmptyAction.001'].play()
let time = .3
animate(){
mixer.setTime(time)
requestAnimationFrame(animate)
}
animate()

最新更新