mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-12 02:49:02 +08:00
Fixes morph targets parsing
This commit is contained in:
parent
4ebd5a9f82
commit
2682c6fb4b
@ -475,7 +475,6 @@ typedef struct {
|
||||
std::string name;
|
||||
std::vector<Primitive> primitives;
|
||||
std::vector<double> weights; // weights to be applied to the Morph Targets
|
||||
std::vector<std::map<std::string, int> >targets;
|
||||
ParameterMap extensions;
|
||||
Value extras;
|
||||
} Mesh;
|
||||
@ -500,7 +499,6 @@ class Node {
|
||||
std::vector<double> scale; // length must be 0 or 3
|
||||
std::vector<double> translation; // length must be 0 or 3
|
||||
std::vector<double> matrix; // length must be 0 or 16
|
||||
std::vector<double> weights; // The weights of the instantiated Morph Target
|
||||
|
||||
Value extras;
|
||||
};
|
||||
@ -1714,6 +1712,25 @@ static bool ParsePrimitive(Primitive *primitive, std::string *err,
|
||||
return false;
|
||||
}
|
||||
|
||||
// Look for morph targets
|
||||
picojson::object::const_iterator targetsObject = o.find("targets");
|
||||
if ((targetsObject != o.end()) && (targetsObject->second).is<picojson::array>()) {
|
||||
const picojson::array &targetArray =
|
||||
(targetsObject->second).get<picojson::array>();
|
||||
for (size_t i = 0; i < targetArray.size(); i++) {
|
||||
std::map<std::string, int> targetAttribues;
|
||||
|
||||
const picojson::object &dict = targetArray[i].get<picojson::object>();
|
||||
picojson::object::const_iterator dictIt(dict.begin());
|
||||
picojson::object::const_iterator dictItEnd(dict.end());
|
||||
|
||||
for (; dictIt != dictItEnd; ++dictIt) {
|
||||
targetAttribues[dictIt->first] = static_cast<int>(dictIt->second.get<double>());
|
||||
}
|
||||
primitive->targets.push_back(targetAttribues);
|
||||
}
|
||||
}
|
||||
|
||||
ParseExtrasProperty(&(primitive->extras), o);
|
||||
|
||||
return true;
|
||||
@ -1737,25 +1754,6 @@ static bool ParseMesh(Mesh *mesh, std::string *err, const picojson::object &o) {
|
||||
}
|
||||
}
|
||||
|
||||
// Look for morph targets
|
||||
picojson::object::const_iterator targetsObject = o.find("targets");
|
||||
if ((targetsObject != o.end()) && (targetsObject->second).is<picojson::array>()) {
|
||||
const picojson::array &targetArray =
|
||||
(targetsObject->second).get<picojson::array>();
|
||||
for (size_t i = 0; i < targetArray.size(); i++) {
|
||||
std::map<std::string, int> targetAttribues;
|
||||
|
||||
const picojson::object &dict = targetArray[i].get<picojson::object>();
|
||||
picojson::object::const_iterator dictIt(dict.begin());
|
||||
picojson::object::const_iterator dictItEnd(dict.end());
|
||||
|
||||
for (; dictIt != dictItEnd; ++dictIt) {
|
||||
targetAttribues[dictIt->first] = static_cast<int>(dictIt->second.get<double>());
|
||||
}
|
||||
mesh->targets.push_back(targetAttribues);
|
||||
}
|
||||
}
|
||||
|
||||
// Should probably check if has targets and if dimensions fit
|
||||
ParseNumberArrayProperty(&mesh->weights, err, o, "weights", false);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user