diff --git a/libs/gfx/source/gltf_parser.cpp b/libs/gfx/source/gltf_parser.cpp index 7130c844..7bf16c4b 100644 --- a/libs/gfx/source/gltf_parser.cpp +++ b/libs/gfx/source/gltf_parser.cpp @@ -228,39 +228,43 @@ namespace psemek::gfx target.name = material["name"].GetString(); + target.two_sided = false; if (material.HasMember("doubleSided")) target.two_sided = material["doubleSided"].GetBool(); - else - target.two_sided = false; - auto const & pbr = material["pbrMetallicRoughness"]; - - if (pbr.HasMember("baseColorFactor")) + // Material can omit pbrMetallicRoughness entry if + // all the values are defaulted + if (material.HasMember("pbrMetallicRoughness")) { - auto const & color = pbr["baseColorFactor"].GetArray(); - gfx::color_4f & target_color = target.albedo.emplace(); - for (std::size_t i = 0; i < 4; ++i) - target_color[i] = color[i].GetFloat(); - } + auto const & pbr = material["pbrMetallicRoughness"]; - if (pbr.HasMember("baseColorTexture")) - { - target.texture = document["textures"].GetArray()[pbr["baseColorTexture"]["index"].GetUint64()]["source"].GetInt64(); - } + if (pbr.HasMember("baseColorFactor")) + { + auto const & color = pbr["baseColorFactor"].GetArray(); + gfx::color_4f & target_color = target.albedo.emplace(); + for (std::size_t i = 0; i < 4; ++i) + target_color[i] = color[i].GetFloat(); + } - if (pbr.HasMember("metallicFactor")) - { - target.metallic = pbr["metallicFactor"].GetFloat(); - } + if (pbr.HasMember("baseColorTexture")) + { + target.texture = document["textures"].GetArray()[pbr["baseColorTexture"]["index"].GetUint64()]["source"].GetInt64(); + } - if (pbr.HasMember("roughnessFactor")) - { - target.roughness = pbr["roughnessFactor"].GetFloat(); - } + if (pbr.HasMember("metallicFactor")) + { + target.metallic = pbr["metallicFactor"].GetFloat(); + } - if (pbr.HasMember("metallicRoughnessTexture")) - { - target.material_texture = document["textures"].GetArray()[pbr["metallicRoughnessTexture"]["index"].GetUint64()]["source"].GetInt64(); + if (pbr.HasMember("roughnessFactor")) + { + target.roughness = pbr["roughnessFactor"].GetFloat(); + } + + if (pbr.HasMember("metallicRoughnessTexture")) + { + target.material_texture = document["textures"].GetArray()[pbr["metallicRoughnessTexture"]["index"].GetUint64()]["source"].GetInt64(); + } } if (material.HasMember("emissiveFactor"))