javascript - How to get multiple objects to play the same animation THREE.js
问题描述
I am adding a group of birds to a scene but only one of them is playing the animation that I loaded I've read in the documentation that you can use THREE.AnimationObjectGroup but I cant get it to work. I load the objects and animation in this loop.
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);
});
}
解决方案
Still new to THREEjs but maybe pull out your 'var flock = new THREE.AnimationObjectGroup;' from your for loop and call your '//play animation' block outside of the for loop.
create group --> add 20 birds to group (for loop) --> play animation for group.
Not sure if you need scene.add(bird) either. I think you can just scene.add(flock) after the loop.
推荐阅读
- android - 从我自己的应用程序在 Android 手机上启动团队会议
- linux - Sendmail bash 脚本读取文本文件并添加超链接
- node.js - http-proxy-middleware express 的并行连接性能问题
- chisel - Chisel Bootcamp 2.5 练习,用于转换为基于 tilelink 的 for 和 tester。详细说明但给出 TLMonitor 断言错误
- android-studio - 在 Android Studio 4.0 中找不到“提取字符串资源”选项
- r - 将交互式 Python Bokeh 图转移到 Shiny
- python - Pygame:如何旋转表面区域而不使图像闪烁两次?
- syntax - 为什么 Deno 会标记使用 nodejs 不会发生的语法错误?
- node.js - 机器人:在 20 秒内更改在频道中交谈的权限,创建倒计时并在此过程中删除这些消息
- java - eclipse macosc cocoa 64bit 与 mac64 bit.dmg 安装程序之间的区别