diff --git a/tiny_gltf_loader.h b/tiny_gltf_loader.h index 7c9bd4e..3c00572 100644 --- a/tiny_gltf_loader.h +++ b/tiny_gltf_loader.h @@ -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 > 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 primitives; + std::vector weights; // weights to be applied to the Morph Targets + std::vector >targets; ParameterMap extensions; Value extras; } Mesh; @@ -483,7 +488,7 @@ class Node { std::vector scale; // length must be 0 or 3 std::vector translation; // length must be 0 or 3 std::vector matrix; // length must be 0 or 16 - std::vector meshes; + std::vector 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()) { + const picojson::array &targetArray = + (targetsObject->second).get(); + for (size_t i = 0; i < targetArray.size(); i++) { + std::map targetAttribues; + + const picojson::object &dict = targetArray[i].get(); + picojson::object::const_iterator dictIt(dict.begin()); + picojson::object::const_iterator dictItEnd(dict.end()); + + for (; dictIt != dictItEnd; ++dictIt) { + targetAttribues[dictIt->first] = static_cast(dictIt->second.get()); + } + 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;