【问题标题】:How can I add a glossiness / specular texture to a GLTF model?如何向 GLTF 模型添加光泽度/镜面反射纹理?
【发布时间】:2019-01-21 16:11:42
【问题描述】:

问题:

我有一个尚未被 GLTF 模型使用的模型的镜面反射/光泽度纹理图像。

如何在模型中使用/添加纹理,使其在应有的位置具有反射/光泽?

我不知道要在 .gltf 文件中进行哪些更改才能使用纹理。

编辑:添加了更多的 GLTF 行,以便更好地了解情况。


GLTF JSON:

"images": [
    {
        "name": "...",
        "uri": "..."
    },
    {
        "name": "...",
        "uri": "..."
    },
    {
        "name": "...",
        "uri": "..."
    },
    {
        "name": "...",
        "uri": "..."
    },
    {
        "name": "...",
        "uri": "..."
    }
],
"samplers": [
    {}
],
"textures": [
    {
        "name": "T_N",
        "sampler": 0,
        "source": 0
    },
    {
        "name": "Map #9",
        "sampler": 0,
        "source": 1
    },
    {
        "name": "T_D",
        "sampler": 0,
        "source": 2
    },
    {
        "name": "Map #6",
        "sampler": 0,
        "source": 3
    },
    {
        "name": "Specular",
        "sampler": 0,
        "source": 4
    }
],

"materials": [
    {
        "name": "Head",
        "alphaMode": "OPAQUE",
        "extras": {
            "fromFBX": {
                "shadingModel": "<unknown>",
                "isTruePBR": false
            }
        },
        "normalTexture": {
            "index": 0,
            "texCoord": 0
        },
        "emissiveTexture": {
            "index": 1,
            "texCoord": 0
        },
        "pbrMetallicRoughness": {
            "baseColorTexture": {
                "index": 2,
                "texCoord": 0
            },
            "baseColorFactor": [
                1.0,
                1.0,
                1.0,
                1.0
            ],
            "metallicFactor": 0.800000002980232,
            "roughnessFactor": 0.600000011920929
        }
    },
    {
        "name": "Body",
        "alphaMode": "BLEND",
        "extras": {
            "fromFBX": {
                "shadingModel": "<unknown>",
                "isTruePBR": true
            }
        },
        "pbrMetallicRoughness": {
            "baseColorTexture": {
                "index": 3,
                "texCoord": 0
            },
            "baseColorFactor": [
                1.0,
                1.0,
                1.0,
                1.0
            ],
            "metallicFactor": 0.80000002980232,
            "roughnessFactor": 0.600000011920929
        },
        "extensions": {
            "KHR_materials_pbrSpecularGlossiness": {
                "specularGlossinessTexture": {
                    "index": 4
                }
            }
        }
    }
],
"meshes": [
    {
        "name": "Head",
        "primitives": [
            {
                "material": 0,
                "mode": 4,
                "attributes": {
                    "COLOR_0": 3,
                    "NORMAL": 2,
                    "POSITION": 1,
                    "TEXCOORD_0": 4
                },
                "indices": 0,
                "extensions": {
                    "KHR_draco_mesh_compression": {
                        "bufferView": 0,
                        "attributes": {
                            "COLOR_0": 2,
                            "NORMAL": 1,
                            "POSITION": 0,
                            "TEXCOORD_0": 3
                        }
                    }
                }
            }
        ]
    },
    {
        "name": "Body",
        "primitives": [
            {
                "material": 1,
                "mode": 4,
                "attributes": {
                    "COLOR_0": 8,
                    "NORMAL": 7,
                    "POSITION": 6,
                    "TEXCOORD_0": 9
                },
                "indices": 5,
                "extensions": {
                    "KHR_draco_mesh_compression": {
                        "bufferView": 1,
                        "attributes": {
                            "COLOR_0": 2,
                            "NORMAL": 1,
                            "POSITION": 0,
                            "TEXCOORD_0": 3
                        }
                    }
                }
            }
        ]
    }
],

错误:

这是我在尝试加载模型时使用上述修改后的 GLTF 时遇到的错误:

{"message":"Cannot read property 'getMaterialType' of undefined","name":"TypeError"} 

【问题讨论】:

    标签: javascript json three.js textures gltf


    【解决方案1】:

    glTF-Sample-Models 存储库中有一些很好的示例。这是使用两种不同 PBR 工作流程的相同模型:

    您上面的示例 JSON 使用的是金属/粗糙,因此您必须通过将金属和粗糙度因子替换为等效的规格/光泽属性来将其“转换”为规格/光泽。

    我建议查看规范以获取更多信息:

    您可能还会发现在 Substance Painter 或 Blender 等工具中更容易做到这一点,它们可以导入和导出 glTF。

    【讨论】:

    • 我打赌以下错误:{"message":"Cannot read property 'getMaterialType' of undefined","name":"TypeError"} 添加字段后:github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/…
    • 在问题中更新了我当前的 GLTF 文件,其中包含更改和更多行。
    • 您知道导致错误的原因吗?
    • 我认为您需要使用 Google Drive 或 Dropbox 或其他工具发布整个 glTF 文件。 glTF“验证”工具也可以提供帮助。
    • 我验证了文件,现在我得到了与这里完全相同的错误:stackoverflow.com/questions/51839039/… 我不知道是什么原因造成的......
    猜你喜欢
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 2017-07-29
    • 2021-11-24
    • 2020-03-11
    • 2019-08-23
    • 2018-05-10
    • 1970-01-01
    相关资源
    最近更新 更多