mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-12 06:29:00 +08:00
Fixes morph targets parsing
This commit is contained in:
parent
4ebd5a9f82
commit
2682c6fb4b
@ -403,7 +403,7 @@ struct BufferView{
|
|||||||
BufferView()
|
BufferView()
|
||||||
: byteOffset(0)
|
: byteOffset(0)
|
||||||
, byteStride(4)
|
, byteStride(4)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -474,8 +474,7 @@ struct Primitive {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<Primitive> primitives;
|
std::vector<Primitive> primitives;
|
||||||
std::vector<double> weights; // weights to be applied to the Morph Targets
|
std::vector<double> weights; // weights to be applied to the Morph Targets
|
||||||
std::vector<std::map<std::string, int> >targets;
|
|
||||||
ParameterMap extensions;
|
ParameterMap extensions;
|
||||||
Value extras;
|
Value extras;
|
||||||
} Mesh;
|
} Mesh;
|
||||||
@ -500,7 +499,6 @@ class Node {
|
|||||||
std::vector<double> scale; // length must be 0 or 3
|
std::vector<double> scale; // length must be 0 or 3
|
||||||
std::vector<double> translation; // 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> matrix; // length must be 0 or 16
|
||||||
std::vector<double> weights; // The weights of the instantiated Morph Target
|
|
||||||
|
|
||||||
Value extras;
|
Value extras;
|
||||||
};
|
};
|
||||||
@ -1714,6 +1712,25 @@ static bool ParsePrimitive(Primitive *primitive, std::string *err,
|
|||||||
return false;
|
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);
|
ParseExtrasProperty(&(primitive->extras), o);
|
||||||
|
|
||||||
return true;
|
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
|
// Should probably check if has targets and if dimensions fit
|
||||||
ParseNumberArrayProperty(&mesh->weights, err, o, "weights", false);
|
ParseNumberArrayProperty(&mesh->weights, err, o, "weights", false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user