如何解决如何获得多个对象来播放相同的动画THREE.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);
});
}
解决方法
对THREEjs还是一个新手,但也许会拉出“ var flock = new THREE.AnimationObjectGroup;”从您的for循环中,然后在for循环之外调用“ //播放动画”块。
创建组->将20只小鸟添加到组(用于循环)->为组播放动画。
不确定是否需要scene.add(bird)。我认为您可以在循环后执行scene.add(flock)。
,@ mumbu22所说的话,另外还要确保在更新/渲染循环中更新混音器
if (this.mixer) {
this.deltaSeconds = timestamp - this.start;
this.mixer.update( this.deltaSeconds );
this.start = timestamp;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。