AnimationMixer是场景中特定对象的动画播放器。当场景中的多个对象独立动画时,可以为每个对象使用一个AnimationMixer。
let animations = gltf.animations;
self.mixer = new THREE.AnimationMixer(self.model);
let idleAction = self.mixer.clipAction(animations[0]);//通过动画数据创建播放器
let runAction = self.mixer.clipAction(animations[1]);
let walkAction = self.mixer.clipAction(animations[3]);
self.actions = [idleAction, walkAction, runAction];
self.actions[1].play();//直接调用播放器的播放事件让动画播放
// self.actions[1].setDuration(5).play();//单位是秒
self.animate();
在循环渲染中更新混合器。
animate() {
requestAnimationFrame(this.animate);
let mixerUpdateDelta = this.clock.getDelta();
if (this.mixer) this.mixer.update(mixerUpdateDelta);
this.renderer.render(this.scene, this.camera);
}