【发布时间】:2021-12-26 16:08:13
【问题描述】:
我正在尝试将MeshStandardMaterial 应用于 GLTF 导入模型的网格。用于测试的 GLTF 模型是一个从 Blender 导出的简单立方体。
成功加载我所做的 GLTF 模型后:
this.material = new THREE.MeshStandardMaterial({
map: this.texture,
})
this.cubePost2Model = this.resources.items.cubePost2.scene
this.cubePost2Model.traverse((child) =>
{
if(child instanceof THREE.Mesh)
{
child.castShadow = true
child.material = this.material // This line throw the error
console.log(child) // Returns succesfully one mesh
}
})
this.scene.add(this.cubePost2Model)
在前面的代码中,这一行:child.material = this.material 在控制台中抛出错误:
Uncaught TypeError: Cannot read properties of undefined (reading 'visible')
【问题讨论】: