From ce1809e50da6e49e5d57e0ae7961496f0af83506 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 24 Jan 2023 12:01:51 +0300 Subject: [PATCH] Support material names & emission in gltf parser --- libs/gfx/include/psemek/gfx/gltf_parser.hpp | 2 ++ libs/gfx/source/gltf_parser.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/libs/gfx/include/psemek/gfx/gltf_parser.hpp b/libs/gfx/include/psemek/gfx/gltf_parser.hpp index 66c6e882..477c6d10 100644 --- a/libs/gfx/include/psemek/gfx/gltf_parser.hpp +++ b/libs/gfx/include/psemek/gfx/gltf_parser.hpp @@ -34,8 +34,10 @@ namespace psemek::gfx struct material { + std::string name; std::optional albedo; std::optional texture; + std::optional emission; }; struct texture diff --git a/libs/gfx/source/gltf_parser.cpp b/libs/gfx/source/gltf_parser.cpp index 649daba8..e41568f8 100644 --- a/libs/gfx/source/gltf_parser.cpp +++ b/libs/gfx/source/gltf_parser.cpp @@ -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())