Modify FBX reader to allow for multiple empty node

Some baked files can have spurious empty nodes in
them; this was causing chunks of the FBX file to be
missed. Also more tweaks for FBX to JSON conversion.
https://highfidelity.manuscript.com/f/cases/14329/
This commit is contained in:
Simon Walton 2018-05-07 18:18:16 -07:00
parent 94f4803d52
commit 37ead11cf9
3 changed files with 34 additions and 10 deletions

View file

@ -214,10 +214,7 @@ FBXNode parseBinaryFBXNode(QDataStream& in, int& position, bool has64BitPosition
while (endOffset > position) {
FBXNode child = parseBinaryFBXNode(in, position, has64BitPositions);
if (child.name.isNull()) {
return node;
} else {
if (!child.name.isNull()) {
node.children.append(child);
}
}

View file

@ -2,7 +2,7 @@
// FBXToJSON.cpp
// libraries/fbx/src
//
// Created by Simon Walton on 5/4/2013.
// Created by Simon Walton on 5/4/2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
@ -12,6 +12,8 @@
#include "FBXToJSON.h"
#include "FBX.h"
using std::string;
template<typename T>
inline FBXToJSON& FBXToJSON::operator<<(QVector<T>& arrayProp) {
*this << "[";
@ -31,10 +33,12 @@ inline FBXToJSON& FBXToJSON::operator<<(QVector<T>& arrayProp) {
}
FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) {
using std::string;
string nodeName(fbxNode.name);
if (nodeName.empty()) nodeName = "nodename";
if (nodeName.empty()) {
nodeName = "node";
} else {
nodeName = stringEscape(nodeName);
}
*this << string(_indentLevel * 4, ' ') << '"' << nodeName << "\": {\n";
@ -55,7 +59,7 @@ FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) {
case QMetaType::QString:
case QMetaType::QByteArray:
*this << '"' << prop.toString().toStdString() << '"';
*this << '"' << stringEscape(prop.toByteArray().toStdString()) << '"';
break;
default:
@ -87,3 +91,24 @@ FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) {
--_indentLevel;
return *this;
}
string FBXToJSON::stringEscape(const string& in) {
string out;
out.reserve(in.length());
for (unsigned char inChar: in) {
if (inChar == '"') {
out.append(R"(\")");
}
else if (inChar == '\\') {
out.append(R"(\\)");
}
else if (inChar < 0x20 || inChar == 0x7f) {
char h[5];
sprintf(h, "\\x%02x", inChar);
out.append(h);
}
else out.append(1, inChar);
}
return out;
}

View file

@ -2,7 +2,7 @@
// FBXToJSON.h
// libraries/fbx/src
//
// Created by Simon Walton on 5/4/2013.
// Created by Simon Walton on 5/4/2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
@ -13,6 +13,7 @@
#define hifi_FBXToJSON_h
#include <sstream>
#include <string>
// Forward declarations.
class FBXNode;
@ -24,6 +25,7 @@ public:
private:
template<typename T> FBXToJSON& operator<<(QVector<T>& arrayProp);
static std::string stringEscape(const std::string& in);
int _indentLevel { 0 };
};