From 2682c6fb4b1b089afc902ee0af74a95727dababd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Chatelain?= Date: Wed, 14 Jun 2017 09:46:57 +0000 Subject: [PATCH] Fixes morph targets parsing --- tiny_gltf_loader.h | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/tiny_gltf_loader.h b/tiny_gltf_loader.h index 90e02f3..651e9d7 100644 --- a/tiny_gltf_loader.h +++ b/tiny_gltf_loader.h @@ -403,7 +403,7 @@ struct BufferView{ BufferView() : byteOffset(0) , byteStride(4) - {} + {} }; @@ -474,8 +474,7 @@ struct Primitive { typedef struct { std::string name; std::vector primitives; - std::vector weights; // weights to be applied to the Morph Targets - std::vector >targets; + std::vector weights; // weights to be applied to the Morph Targets ParameterMap extensions; Value extras; } Mesh; @@ -500,7 +499,6 @@ 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 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()) { + 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()); + } + 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()) { - 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);