Support material names & emission in gltf parser

This commit is contained in:
Nikita Lisitsa 2023-01-24 12:01:51 +03:00
parent 5ce8647b3d
commit ce1809e50d
2 changed files with 12 additions and 0 deletions

View file

@ -34,8 +34,10 @@ namespace psemek::gfx
struct material
{
std::string name;
std::optional<color_4f> albedo;
std::optional<std::size_t> texture;
std::optional<color_3f> emission;
};
struct texture

View file

@ -102,6 +102,8 @@ namespace psemek::gfx
{
auto & target = result.materials.emplace_back();
target.name = material["name"].GetString();
auto const & pbr = material["pbrMetallicRoughness"];
if (pbr.HasMember("baseColorFactor"))
@ -116,6 +118,14 @@ namespace psemek::gfx
{
target.texture = document["textures"].GetArray()[pbr["baseColorTexture"]["index"].GetUint64()]["source"].GetInt64();
}
if (material.HasMember("emissiveFactor"))
{
auto const & emission = material["emissiveFactor"].GetArray();
gfx::color_3f & target_emission = target.emission.emplace();
for (std::size_t i = 0; i < 3; ++i)
target_emission[i] = emission[i].GetFloat();
}
}
for (auto const & image : document["images"].GetArray())