mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 00:36:00 +08:00
tiny_gltf.h - parse node and material lods
This commit is contained in:
parent
4fea26f6c8
commit
a42263bdba
38
tiny_gltf.h
38
tiny_gltf.h
@ -764,6 +764,7 @@ struct Material {
|
||||
std::string alphaMode{"OPAQUE"}; // default "OPAQUE"
|
||||
double alphaCutoff{0.5}; // default 0.5
|
||||
bool doubleSided{false}; // default false
|
||||
std::vector<int> lods; // level of detail materials (MSFT_lod)
|
||||
|
||||
PbrMetallicRoughness pbrMetallicRoughness;
|
||||
|
||||
@ -1018,6 +1019,7 @@ class Node {
|
||||
int mesh{-1};
|
||||
int light{-1}; // light source index (KHR_lights_punctual)
|
||||
int emitter{-1}; // audio emitter index (KHR_audio)
|
||||
std::vector<int> lods; // level of detail nodes (MSFT_lod)
|
||||
std::vector<int> children;
|
||||
std::vector<double> rotation; // length must be 0 or 4
|
||||
std::vector<double> scale; // length must be 0 or 3
|
||||
@ -5165,6 +5167,24 @@ static bool ParseNode(Node *node, std::string *err, const detail::json &o,
|
||||
}
|
||||
node->emitter = emitter;
|
||||
|
||||
node->lods.clear();
|
||||
if (node->extensions.count("MSFT_lod") != 0) {
|
||||
auto const &msft_lod_ext = node->extensions["MSFT_lod"];
|
||||
if (msft_lod_ext.Has("ids")) {
|
||||
auto idsArr = msft_lod_ext.Get("ids");
|
||||
for (size_t i = 0; i < idsArr.ArrayLen(); ++i) {
|
||||
node->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
|
||||
}
|
||||
} else {
|
||||
if (err) {
|
||||
*err +=
|
||||
"Node has extension MSFT_lod, but does not reference "
|
||||
"other nodes via their ids.\n";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -5364,6 +5384,24 @@ static bool ParseMaterial(Material *material, std::string *err, std::string *war
|
||||
ParseExtrasAndExtensions(material, err, o,
|
||||
store_original_json_for_extras_and_extensions);
|
||||
|
||||
material->lods.clear();
|
||||
if (material->extensions.count("MSFT_lod") != 0) {
|
||||
auto const &msft_lod_ext = material->extensions["MSFT_lod"];
|
||||
if (msft_lod_ext.Has("ids")) {
|
||||
auto idsArr = msft_lod_ext.Get("ids");
|
||||
for (size_t i = 0; i < idsArr.ArrayLen(); ++i) {
|
||||
material->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
|
||||
}
|
||||
} else {
|
||||
if (err) {
|
||||
*err +=
|
||||
"Material has extension MSFT_lod, but does not reference "
|
||||
"other materials via their ids.\n";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user