From 54c3b04fce5c8feb87e06d6037a4199bacda289d Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Fri, 2 Feb 2018 11:12:06 -0800 Subject: [PATCH] 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. --- src/glTF/NodeData.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/glTF/NodeData.cpp b/src/glTF/NodeData.cpp index 5e9cfb4..e582126 100644 --- a/src/glTF/NodeData.cpp +++ b/src/glTF/NodeData.cpp @@ -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 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; }