Cope with degenerate node T/R/S.

It's technically valid for e.g. scale to have a zero dimension, which in
turn wreaks havoc on the rotation quaternion we get from the FBX SDK.

The simplest solution is to just leave any T/R/S vector out of the glTF
if it has any NaN component.
This commit is contained in:
Par Winzell 2018-02-02 11:12:06 -08:00
parent a3989249f3
commit 54c3b04fce
1 changed files with 11 additions and 5 deletions

View File

@ -52,12 +52,18 @@ void NodeData::SetCamera(uint32_t cameraIndex)
json NodeData::serialize() const
{
json result = {
{ "name", name },
{ "translation", toStdVec(translation) },
{ "rotation", toStdVec(rotation) },
{ "scale", toStdVec(scale) }
json result = { { "name", name } };
// if any of the T/R/S have NaN components, just leave them out of the glTF
auto maybeAdd = [&](std::string key, std::vector<float> vec) {
if (std::none_of(vec.begin(), vec.end(), [&](float n) { return isnan(n); })) {
result[key] = vec;
}
};
maybeAdd("translation", toStdVec(translation));
maybeAdd("rotation", toStdVec(rotation));
maybeAdd("scale", toStdVec(scale));
if (!children.empty()) {
result["children"] = children;
}