mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-12 06:29:00 +08:00
Supports glTF morph (glTF 2.0, not tested)
This commit is contained in:
parent
8cb98950ff
commit
38a6a7565c
@ -447,6 +447,9 @@ struct Primitive {
|
||||
// when rendering.
|
||||
int indices; // The index of the accessor that contains the indices.
|
||||
int mode; // one of TINYGLTF_MODE_***
|
||||
std::vector<std::map<std::string, int> > targets; // array of morph targets,
|
||||
//where each target is a dict with attribues in ["POSITION, "NORMAL", "TANGENT"] pointing
|
||||
// to their corresponding accessors
|
||||
Value extras;
|
||||
|
||||
Primitive()
|
||||
@ -459,6 +462,8 @@ struct Primitive {
|
||||
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;
|
||||
@ -483,7 +488,7 @@ 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<std::string> meshes;
|
||||
std::vector<double> weights; // The weights of the instantiated Morph Target
|
||||
|
||||
Value extras;
|
||||
};
|
||||
@ -1766,6 +1771,28 @@ 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);
|
||||
|
||||
ParseExtrasProperty(&(mesh->extras), o);
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user