【问题标题】:Console error when applying material to mesh将材料应用于网格时出现控制台错误
【发布时间】: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')

【问题讨论】:

    标签: three.js mesh


    【解决方案1】:

    projectObject() 中发生错误时,这意味着您将undefined 分配给child.material。所以看起来this.material 没有指向预期的物质对象。

    【讨论】:

    • 感谢您的回答。这个问题是错误的,因为我提取了部分代码来简化它。对于那个很抱歉。最后,问题是我在几何之后构建了材质。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    • 2020-08-17
    • 2021-12-14
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多