Skip to content

Commit b274b34

Browse files
committed
tiny_gltf.h - register MSFT_lod with the model's used extensions
1 parent b132612 commit b274b34

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tiny_gltf.h

+26
Original file line numberDiff line numberDiff line change
@@ -8334,6 +8334,32 @@ static void SerializeGltfModel(const Model *model, detail::json &o) {
83348334
}
83358335
}
83368336

8337+
// MSFT_lod
8338+
8339+
// Look if there is a node that employs MSFT_lod
8340+
auto msft_lod_nodes_it = std::find_if(
8341+
model->nodes.begin(), model->nodes.end(),
8342+
[](const Node& node) { return !node.lods.empty(); });
8343+
8344+
// Look if there is a material that employs MSFT_lod
8345+
auto msft_lod_materials_it = std::find_if(
8346+
model->materials.begin(), model->materials.end(),
8347+
[](const Material& material) {return !material.lods.empty(); });
8348+
8349+
// If either a node or a material employ MSFT_lod, then we need
8350+
// to add MSFT_lod to the list of used extensions.
8351+
if (msft_lod_nodes_it != model->nodes.end() || msft_lod_materials_it != model->materials.end()) {
8352+
// First check if MSFT_lod is already registered as used extension
8353+
auto has_msft_lod = std::find_if(
8354+
extensionsUsed.begin(), extensionsUsed.end(),
8355+
[](const std::string &s) { return (s.compare("MSFT_lod") == 0); });
8356+
8357+
// If MSFT_lod is not registered yet, add it
8358+
if (has_msft_lod == extensionsUsed.end()) {
8359+
extensionsUsed.push_back("MSFT_lod");
8360+
}
8361+
}
8362+
83378363
// Extensions used
83388364
if (extensionsUsed.size()) {
83398365
SerializeStringArrayProperty("extensionsUsed", extensionsUsed, o);

0 commit comments

Comments
 (0)