-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db202f3
commit a776b00
Showing
10 changed files
with
144 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export module vk_gltf_viewer:gltf.MaterialVariantsMapping; | ||
|
||
import std; | ||
export import fastgltf; | ||
import :helpers.ranges; | ||
|
||
namespace vk_gltf_viewer::gltf { | ||
/** | ||
* @brief Associative data structure of mappings for KHR_materials_variants. | ||
* | ||
* KHR_materials_variants extension defines the material variants for each primitive. For each variant index, you can call `at` to get the list of primitives and their material indices that use the corresponding material variant. | ||
*/ | ||
class MaterialVariantsMapping { | ||
public: | ||
struct VariantPrimitive { | ||
fastgltf::Primitive *pPrimitive; | ||
std::uint32_t materialIndex; | ||
}; | ||
|
||
explicit MaterialVariantsMapping(fastgltf::Asset &asset [[clang::lifetimebound]]) noexcept { | ||
for (fastgltf::Primitive &primitive : asset.meshes | std::views::transform(&fastgltf::Mesh::primitives) | std::views::join) { | ||
for (const auto &[materialVariantIndex, mapping] : primitive.mappings | ranges::views::enumerate) { | ||
if (mapping) { | ||
data[materialVariantIndex].emplace_back(&primitive, *mapping); | ||
} | ||
} | ||
} | ||
} | ||
|
||
[[nodiscard]] std::span<const VariantPrimitive> at(std::size_t materialVariantIndex) const { | ||
return data.at(materialVariantIndex); | ||
} | ||
|
||
private: | ||
std::unordered_map<std::size_t, std::vector<VariantPrimitive>> data; | ||
}; | ||
} |