如何为GLTF模型添加光泽度/镜面纹理?

时间:2018-08-14 18:19:35

标签: javascript json three.js textures gltf

问题:

我有一个模型的镜面/光泽度纹理图像,而该模型尚未被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"} 

1 个答案:

答案 0 :(得分:1)

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

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

我建议您看一下规范以获得更多信息:

您还可能会发现,在Substance Painter或Blender之类的工具中,可以导入和导出glTF的操作更容易。