GLTF 3D 模型在应该动画的时候没有动画
GLTF 3D model isn't animated when it should be
所以目标很简单,我想制作一个 3D 模型的动画,导入为 .gltf 文件(它只有 1 个动画)。
我一直在遵循文档步骤:
https://threejs.org/docs/#manual/en/introduction/Animation-system
还有一些来自实习生的其他例子,它们看起来都差不多,只有少数地方有所修改,但想法每次都是一样的。
我的代码(注释的是失败的尝试):
let loader = new THREE.GLTFLoader();
loader.load('scene.gltf', function ( gltf ) {
GLTF = gltf;
let xMesh = gltf.scene.children[0];
scene.add(xMesh);//arWorldRoot.add(xMesh);
animation = new THREE.AnimationMixer(xMesh);
animation.clipAction(gltf.animations[0]).setDuration(8).play();
//scene.add( gltf.scene );
//animation = new THREE.AnimationMixer(gltf.scene);
//animation.clipAction(gltf.animations[0]).play();
//gltf.animations.forEach(( clip ) => {
//animation.clipAction(clip).play();
//});
//render();
}, undefined, function ( error ) {
console.error( error );
} );
....
....
....
function render() {
requestAnimationFrame(render);
var delta = new THREE.Clock().getDelta();
if (animation != null) {
animation.update(delta);
};
renderer.render(scene, camera);
}
我从所有这些尝试中得到的输出是显示了 3D 模型,但没有显示 animated.IndevTools 没有错误/警告。
按照官方文档进行操作很奇怪而且不起作用,但我确定我遗漏了一些东西...
我尝试了相同的代码,但遇到了同样的问题。我的是 getDelta() 返回 0,所以动画没有向前移动。为了检查动画是否正常工作,我只是在 animation.update() 中手动输入了一个值,即 animation.update(0.01).
所以目标很简单,我想制作一个 3D 模型的动画,导入为 .gltf 文件(它只有 1 个动画)。
我一直在遵循文档步骤:
https://threejs.org/docs/#manual/en/introduction/Animation-system
还有一些来自实习生的其他例子,它们看起来都差不多,只有少数地方有所修改,但想法每次都是一样的。
我的代码(注释的是失败的尝试):
let loader = new THREE.GLTFLoader();
loader.load('scene.gltf', function ( gltf ) {
GLTF = gltf;
let xMesh = gltf.scene.children[0];
scene.add(xMesh);//arWorldRoot.add(xMesh);
animation = new THREE.AnimationMixer(xMesh);
animation.clipAction(gltf.animations[0]).setDuration(8).play();
//scene.add( gltf.scene );
//animation = new THREE.AnimationMixer(gltf.scene);
//animation.clipAction(gltf.animations[0]).play();
//gltf.animations.forEach(( clip ) => {
//animation.clipAction(clip).play();
//});
//render();
}, undefined, function ( error ) {
console.error( error );
} );
....
....
....
function render() {
requestAnimationFrame(render);
var delta = new THREE.Clock().getDelta();
if (animation != null) {
animation.update(delta);
};
renderer.render(scene, camera);
}
我从所有这些尝试中得到的输出是显示了 3D 模型,但没有显示 animated.IndevTools 没有错误/警告。
按照官方文档进行操作很奇怪而且不起作用,但我确定我遗漏了一些东西...
我尝试了相同的代码,但遇到了同样的问题。我的是 getDelta() 返回 0,所以动画没有向前移动。为了检查动画是否正常工作,我只是在 animation.update() 中手动输入了一个值,即 animation.update(0.01).