首页 > 解决方案 > GLTF 3D 模型在应该动画的时候没有动画

问题描述

所以目标很简单,我想为 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 模型显示但没有动画。在 devTools 中没有错误/警告。

遵循官方文档并且不起作用,这很奇怪,但我确定我错过了一些东西......

标签: javascriptthree.js3daugmented-realitygltf

解决方案


我尝试了相同的代码并遇到了同样的问题。我的是 getDelta() 返回 0,所以动画没有前进。为了检查动画是否正常工作,我只是在animation.update() 中手动输入了一个值,即animation.update(0.01)。


推荐阅读