gltf材质覆盖停止动画混合器

时间:2018-07-16 10:15:03

标签: aframe webvr gltf

我非常担心gltf模型的问题。如果尝试覆盖gltf的材质,动画将停止。我认为这与覆盖的更新功能和动画混合器的滴答功能发生碰撞有关,但是我还没有设法自己解决它。

我希望有人能指出我为什么会这样。 这是一个实时示例:http://motiondolphins.com/app_onlyFefo/index.html

在此先感谢您。这是代码本身。带注释的部分是材料的替代。如果我取消注释,则将加载新材质,但动画将停止:

        AFRAME.registerComponent("fefo", {
            init: function() {

                var texture = new THREE.TextureLoader().load( 'models/static.png' );
                texture.wrapS = THREE.RepeatWrapping;
                texture.wrapT = THREE.RepeatWrapping;
                texture.repeat.set( 20, 20 );


                this.material  = new THREE.MeshToonMaterial({
                    bumpMap:texture,
                    bumpScale:0.03,

                    color : 0xffffff
            });

            this.el.addEventListener('model-loaded', () => this.update());


            var el = this.el;
            setTimeout(()=>{
                var model = el.getObject3D('mesh')       
                this.mixer = new THREE.AnimationMixer(model);
                var clips = model.animations || (model.geometry || {}).animations || 
                [];
                console.log(this.mixer)
                console.log(el)
                console.log(clips[0])
                const action = this.mixer.clipAction(clips[0], model);
                action.setDuration(10).setLoop(THREE.LoopRepeat).play();
                console.log(action)
            }, 3000)
            },

            /////////////////HERE I TRY TO OVERRIDE THE MATERIAL, BUT IF I DO, ANIMATION STOPS

            update: function () {

            //      object = this.el.getObject3D('mesh');

            //     if (!object) return;
            //     object.traverse((node) => {

            //     if (node.isMesh) node.material = this.material;
            // }); 

        },
            tick: function (t, dt) {

                if (this.mixer && !isNaN(dt)) this.mixer.update(dt / 1000);

            }
        })

1 个答案:

答案 0 :(得分:1)

请务必记住,Three.js中的Material实际上代表WebGL shader program,而不仅仅是对象的视觉“外观”。 MeshToonMaterial扩展了MeshPhongMaterial,并继承了与动画有关的一些属性,需要保留这些属性才能使动画起作用:

newMaterial.skinning = oldMaterial.skinning;
newMaterial.morphTargets = oldMaterial.morphTargets;
newMaterial.morphNormals = oldMaterial.morphNormals;

在这种情况下,我认为重要的只是.skinning属性,因为模型使用骨架。