Fix gltf parser in case a material doesn't have 'pbrMetallicRoughness' field
This commit is contained in:
parent
ff7eb827fe
commit
156a58a59a
1 changed files with 29 additions and 25 deletions
|
|
@ -228,39 +228,43 @@ namespace psemek::gfx
|
||||||
|
|
||||||
target.name = material["name"].GetString();
|
target.name = material["name"].GetString();
|
||||||
|
|
||||||
|
target.two_sided = false;
|
||||||
if (material.HasMember("doubleSided"))
|
if (material.HasMember("doubleSided"))
|
||||||
target.two_sided = material["doubleSided"].GetBool();
|
target.two_sided = material["doubleSided"].GetBool();
|
||||||
else
|
|
||||||
target.two_sided = false;
|
|
||||||
|
|
||||||
auto const & pbr = material["pbrMetallicRoughness"];
|
// Material can omit pbrMetallicRoughness entry if
|
||||||
|
// all the values are defaulted
|
||||||
if (pbr.HasMember("baseColorFactor"))
|
if (material.HasMember("pbrMetallicRoughness"))
|
||||||
{
|
{
|
||||||
auto const & color = pbr["baseColorFactor"].GetArray();
|
auto const & pbr = material["pbrMetallicRoughness"];
|
||||||
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("baseColorTexture"))
|
if (pbr.HasMember("baseColorFactor"))
|
||||||
{
|
{
|
||||||
target.texture = document["textures"].GetArray()[pbr["baseColorTexture"]["index"].GetUint64()]["source"].GetInt64();
|
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"))
|
if (pbr.HasMember("baseColorTexture"))
|
||||||
{
|
{
|
||||||
target.metallic = pbr["metallicFactor"].GetFloat();
|
target.texture = document["textures"].GetArray()[pbr["baseColorTexture"]["index"].GetUint64()]["source"].GetInt64();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pbr.HasMember("roughnessFactor"))
|
if (pbr.HasMember("metallicFactor"))
|
||||||
{
|
{
|
||||||
target.roughness = pbr["roughnessFactor"].GetFloat();
|
target.metallic = pbr["metallicFactor"].GetFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pbr.HasMember("metallicRoughnessTexture"))
|
if (pbr.HasMember("roughnessFactor"))
|
||||||
{
|
{
|
||||||
target.material_texture = document["textures"].GetArray()[pbr["metallicRoughnessTexture"]["index"].GetUint64()]["source"].GetInt64();
|
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"))
|
if (material.HasMember("emissiveFactor"))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue