Skip to content

Commit

Permalink
Cope with degenerate node T/R/S.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Par Winzell committed Feb 2, 2018
1 parent a398924 commit 54c3b04
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/glTF/NodeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 54c3b04

Please sign in to comment.