如何让多个对象播放相同的动画THRE.js



我正在向场景中添加一组鸟,但其中只有一只正在播放我加载的动画。我在文档中读到,您可以使用THREE.AnimationObjectGroup,但我无法使其工作。我在这个循环中加载对象和动画。


for (var numberOfBirds = 0; numberOfBirds < 20; numberOfBirds++) {
loader.load("./assets/bird.gltf", function (gltf) {
//Loading in and positioning model
var bird = gltf.scene;
bird.scale.set(10, 10, 10);
bird.position.set(Math.random() * 500, Math.random() * 500, Math.random() * 500);
var flock = new THREE.AnimationObjectGroup;
flock.add(bird);
console.log(flock);
//Playing Animation
mixer = new THREE.AnimationMixer(flock);
console.log(gltf.animations);
mixer.clipAction(gltf.animations[0]).play();
scene.add(bird);

});
}

THREjs仍然是新手,但可能会退出您的'var flock=new THREE.AnimationObjectGroup;'从for循环调用"//播放动画"块。

创建组-->将20只鸟添加到组(用于循环(->为小组播放动画。

不确定是否需要场景。也加(鸟(。我认为你可以在循环后添加场景。

@mumbu22说了什么,此外,请确保在更新/渲染循环中更新混合器

if (this.mixer) {
this.deltaSeconds = timestamp - this.start;
this.mixer.update( this.deltaSeconds );
this.start = timestamp; 
}

最新更新