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.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"))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue