我已经阅读了FBX Loader示例,并制作了动画。 但是,显然,FBX模型默认情况下使用PhongMaterials导入模型。 问题是我需要它成为BasicMaterial(与“ unlit”(统一)相同)。当我尝试创建一个新的THREE.MeshBasicMaterial并使用copy()函数将数据从Phong材质传递到所需材质时,我会遇到类似此屏幕截图的错误。
https://www.r-bloggers.com/r-na-vs-null/
如果我只是创建一个新的MeshBasicMaterial,将其颜色设置为与“ Phong材质”相同,则不会出现任何错误,但是动画将不再播放。
这里是我的代码:
function load_init( object ) {
mixer = new THREE.AnimationMixer( object );
object.traverse( function ( child ) {
if ( child.isMesh ) {
const oldMat = child.material;
var newMat = new THREE.MeshBasicMaterial();
if(oldMat.length == undefined)//only one material in the mesh
{
console.log(newMat.copy(oldMat));//it copies succesfuly
//child.material = newMat; // gives errors
child.material = new THREE.MeshBasicMaterial( {
color: oldMat.color,
} );//materials are changed, but the animation wont play
//anymore
}
else//multiple materials
{
for(var i = 0; i < oldMat.length; i++)
{
console.log(newMat.copy(oldMat[i]));//it copies succesfuly
//child.material[i] = newMat; // gives errors
child.material[i] = new THREE.MeshBasicMaterial( {
color: oldMat[i].color,
} );//materials are changed, but the animation wont play
//anymore
}
}
}
} );
var action = mixer.clipAction( object.animations[ 0 ] );
action.play();
scene.add( object );
}