From a17359d2df824bc4c5fcebad2b74acb5bad4934c Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Thu, 3 May 2018 17:26:25 -0700 Subject: [PATCH 1/9] Ensure a minimum of one joint-verts sets to prevent crash A baked FBX that has no joints will cause a crash without this. --- libraries/fbx/src/FBXReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 86422ef70c..860d3ae5f4 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -1602,7 +1602,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS // NOTE: shapeVertices are in joint-frame std::vector shapeVertices; - shapeVertices.resize(geometry.joints.size()); + shapeVertices.resize(std::max(1, geometry.joints.size()) ); // find our special joints geometry.leftEyeJointIndex = modelIDs.indexOf(jointEyeLeftID); From e22bc7eff234734c47944bc8032be39981388933 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Fri, 4 May 2018 14:10:22 -0700 Subject: [PATCH 2/9] Add FBXNode to JSON stream class --- libraries/fbx/src/FBXToJSON.cpp | 82 +++++++++++++++++++++++++++++++++ libraries/fbx/src/FBXToJSON.h | 30 ++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 libraries/fbx/src/FBXToJSON.cpp create mode 100644 libraries/fbx/src/FBXToJSON.h diff --git a/libraries/fbx/src/FBXToJSON.cpp b/libraries/fbx/src/FBXToJSON.cpp new file mode 100644 index 0000000000..1620fcca46 --- /dev/null +++ b/libraries/fbx/src/FBXToJSON.cpp @@ -0,0 +1,82 @@ +// +// FBXToJSON.cpp +// libraries/fbx/src +// +// Created by Simon Walton on 5/4/2013. +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "FBXToJSON.h" +#include "FBX.h" + +template +inline FBXToJSON& FBXToJSON::operator<<(QVector& arrayProp) { + *this << "["; + for (auto& prop : arrayProp) { + *(std::ostringstream*)this << prop << ", "; + } + *this << "] "; + if (arrayProp.size() > 4) { + *this << "# " << arrayProp.size() << " items"; + } + *this << '\n'; + + return *this; +} + +FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) { + using std::string; + + string nodeName(fbxNode.name); + if (nodeName.empty()) nodeName = "nodename"; + + *this << string(_indentLevel * 4, ' ') << '"' << nodeName << "\": {\n"; + ++_indentLevel; + int p = 0; + for (auto& prop : fbxNode.properties) { + *this << string(_indentLevel * 4, ' ') << "\"p" << p++ << "\": "; + switch (prop.userType()) { + case QMetaType::Short: + case QMetaType::Bool: + case QMetaType::Int: + case QMetaType::LongLong: + case QMetaType::Double: + case QMetaType::Float: + *this << prop.toString().toStdString(); + break; + + case QMetaType::QString: + case QMetaType::QByteArray: + *this << '"' << prop.toString().toStdString() << '"'; + break; + + default: + if (prop.canConvert>()) { + *this << prop.value>(); + } else if (prop.canConvert>()) { + *this << prop.value>(); + } else if (prop.canConvert>()) { + *this << prop.value>(); + } else if (prop.canConvert>()) { + *this << prop.value>(); + } else if (prop.canConvert>()) { + *this << prop.value>(); + } else { + *this << ""; + } + break; + } + *this << ",\n"; + } + + for (auto child : fbxNode.children) { + *this << child; + } + + *this << string(_indentLevel * 4, ' ') << "},\n"; + --_indentLevel; + return *this; +} diff --git a/libraries/fbx/src/FBXToJSON.h b/libraries/fbx/src/FBXToJSON.h new file mode 100644 index 0000000000..0961144e9f --- /dev/null +++ b/libraries/fbx/src/FBXToJSON.h @@ -0,0 +1,30 @@ +// +// FBXToJSON.h +// libraries/fbx/src +// +// Created by Simon Walton on 5/4/2013. +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_FBXToJSON_h +#define hifi_FBXToJSON_h + +#include + +// Forward declarations. +class FBXNode; +template class QVector; + +class FBXToJSON : public std::ostringstream { +public: + FBXToJSON& operator<<(const FBXNode& fbxNode); + +private: + template FBXToJSON& operator<<(QVector& arrayProp); + int _indentLevel { 0 }; +}; + +#endif // hifi_FBXToJSON_h From 94f4803d527922c2cdf8ebdb0af6cc244934e68a Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Fri, 4 May 2018 17:28:18 -0700 Subject: [PATCH 3/9] Add debug code to dump before/after FBXNode to file Also fix trailing comma issue in json since gvim complains bitterly. --- libraries/baking/src/FBXBaker.cpp | 33 +++++++++++++++++++++++++++++++ libraries/fbx/src/FBXToJSON.cpp | 19 ++++++++++++------ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index 0407c8508c..0cd0c0addb 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -33,6 +33,10 @@ #include "FBXBaker.h" +#ifdef HIFI_DUMP_FBX +#include "FBXToJSON.h" +#endif + void FBXBaker::bake() { qDebug() << "FBXBaker" << _modelURL << "bake starting"; @@ -194,6 +198,21 @@ void FBXBaker::importScene() { qCDebug(model_baking) << "Parsing" << _modelURL; _rootNode = reader._rootNode = reader.parseFBX(&fbxFile); + +#ifdef HIFI_DUMP_FBX + { + FBXToJSON fbxToJSON; + fbxToJSON << _rootNode; + QFileInfo modelFile(_originalModelFilePath); + QString outFilename(_bakedOutputDir + "/" + modelFile.completeBaseName() + "_FBX.json"); + QFile jsonFile(outFilename); + if (jsonFile.open(QIODevice::WriteOnly)) { + jsonFile.write(fbxToJSON.str().c_str(), fbxToJSON.str().length()); + jsonFile.close(); + } + } +#endif + _geometry = reader.extractFBXGeometry({}, _modelURL.toString()); _textureContentMap = reader._textureContent; } @@ -374,5 +393,19 @@ void FBXBaker::exportScene() { _outputFiles.push_back(_bakedModelFilePath); +#ifdef HIFI_DUMP_FBX + { + FBXToJSON fbxToJSON; + fbxToJSON << _rootNode; + QFileInfo modelFile(_bakedModelFilePath); + QString outFilename(modelFile.dir().absolutePath() + "/" + modelFile.completeBaseName() + "_FBX.json"); + QFile jsonFile(outFilename); + if (jsonFile.open(QIODevice::WriteOnly)) { + jsonFile.write(fbxToJSON.str().c_str(), fbxToJSON.str().length()); + jsonFile.close(); + } + } +#endif + qCDebug(model_baking) << "Exported" << _modelURL << "with re-written paths to" << _bakedModelFilePath; } diff --git a/libraries/fbx/src/FBXToJSON.cpp b/libraries/fbx/src/FBXToJSON.cpp index 1620fcca46..40178c7120 100644 --- a/libraries/fbx/src/FBXToJSON.cpp +++ b/libraries/fbx/src/FBXToJSON.cpp @@ -15,12 +15,15 @@ template inline FBXToJSON& FBXToJSON::operator<<(QVector& arrayProp) { *this << "["; + char comma = ' '; for (auto& prop : arrayProp) { - *(std::ostringstream*)this << prop << ", "; + *(std::ostringstream*)this << comma << prop; + comma = ','; } *this << "] "; + if (arrayProp.size() > 4) { - *this << "# " << arrayProp.size() << " items"; + *this << "// " << arrayProp.size() << " items"; } *this << '\n'; @@ -34,10 +37,12 @@ FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) { if (nodeName.empty()) nodeName = "nodename"; *this << string(_indentLevel * 4, ' ') << '"' << nodeName << "\": {\n"; + ++_indentLevel; int p = 0; + char* eol = ""; for (auto& prop : fbxNode.properties) { - *this << string(_indentLevel * 4, ' ') << "\"p" << p++ << "\": "; + *this << eol << string(_indentLevel * 4, ' ') << "\"p" << p++ << "\": "; switch (prop.userType()) { case QMetaType::Short: case QMetaType::Bool: @@ -69,14 +74,16 @@ FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) { } break; } - *this << ",\n"; + eol = ",\n"; } - for (auto child : fbxNode.children) { + for (auto& child : fbxNode.children) { + *this << eol; *this << child; + eol = ",\n"; } - *this << string(_indentLevel * 4, ' ') << "},\n"; + *this << "\n" << string(_indentLevel * 4, ' ') << "}"; --_indentLevel; return *this; } From 37ead11cf97d503dad9be54ffedb62f0221d517b Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Mon, 7 May 2018 18:18:16 -0700 Subject: [PATCH 4/9] 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/ --- libraries/fbx/src/FBXReader_Node.cpp | 5 +--- libraries/fbx/src/FBXToJSON.cpp | 35 ++++++++++++++++++++++++---- libraries/fbx/src/FBXToJSON.h | 4 +++- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/libraries/fbx/src/FBXReader_Node.cpp b/libraries/fbx/src/FBXReader_Node.cpp index c4454421b6..9375dc7b56 100644 --- a/libraries/fbx/src/FBXReader_Node.cpp +++ b/libraries/fbx/src/FBXReader_Node.cpp @@ -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); } } diff --git a/libraries/fbx/src/FBXToJSON.cpp b/libraries/fbx/src/FBXToJSON.cpp index 40178c7120..2994de0f02 100644 --- a/libraries/fbx/src/FBXToJSON.cpp +++ b/libraries/fbx/src/FBXToJSON.cpp @@ -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 inline FBXToJSON& FBXToJSON::operator<<(QVector& arrayProp) { *this << "["; @@ -31,10 +33,12 @@ inline FBXToJSON& FBXToJSON::operator<<(QVector& 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; +} diff --git a/libraries/fbx/src/FBXToJSON.h b/libraries/fbx/src/FBXToJSON.h index 0961144e9f..85feac6bff 100644 --- a/libraries/fbx/src/FBXToJSON.h +++ b/libraries/fbx/src/FBXToJSON.h @@ -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 +#include // Forward declarations. class FBXNode; @@ -24,6 +25,7 @@ public: private: template FBXToJSON& operator<<(QVector& arrayProp); + static std::string stringEscape(const std::string& in); int _indentLevel { 0 }; }; From 82e43aea113116ca917294d9cda360e16d5456ab Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Tue, 8 May 2018 13:59:38 -0700 Subject: [PATCH 5/9] Baking - if mesh extraction or compression fails don't change node Needed to prevent a null (would-be Draco mesh) node being added. --- libraries/baking/src/FBXBaker.cpp | 59 ++++++++++++++++--------------- libraries/fbx/src/FBXWriter.cpp | 3 +- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index 0cd0c0addb..0aa0414518 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -257,39 +257,40 @@ void FBXBaker::rewriteAndBakeSceneModels() { } else if (hasWarnings()) { continue; } - } - - objectChild.children.push_back(dracoMeshNode); + } else { + objectChild.children.push_back(dracoMeshNode); - static const std::vector nodeNamesToDelete { - // Node data that is packed into the draco mesh - "Vertices", - "PolygonVertexIndex", - "LayerElementNormal", - "LayerElementColor", - "LayerElementUV", - "LayerElementMaterial", - "LayerElementTexture", + static const std::vector nodeNamesToDelete { + // Node data that is packed into the draco mesh + "Vertices", + "PolygonVertexIndex", + "LayerElementNormal", + "LayerElementColor", + "LayerElementUV", + "LayerElementMaterial", + "LayerElementTexture", - // Node data that we don't support - "Edges", - "LayerElementTangent", - "LayerElementBinormal", - "LayerElementSmoothing" - }; - auto& children = objectChild.children; - auto it = children.begin(); - while (it != children.end()) { - auto begin = nodeNamesToDelete.begin(); - auto end = nodeNamesToDelete.end(); - if (find(begin, end, it->name) != end) { - it = children.erase(it); - } else { - ++it; + // Node data that we don't support + "Edges", + "LayerElementTangent", + "LayerElementBinormal", + "LayerElementSmoothing" + }; + auto& children = objectChild.children; + auto it = children.begin(); + while (it != children.end()) { + auto begin = nodeNamesToDelete.begin(); + auto end = nodeNamesToDelete.end(); + if (find(begin, end, it->name) != end) { + it = children.erase(it); + } else { + ++it; + } } } - } - } + } // Geometry Object + + } // foreach root child } } } diff --git a/libraries/fbx/src/FBXWriter.cpp b/libraries/fbx/src/FBXWriter.cpp index 511f253193..9cdc552af1 100644 --- a/libraries/fbx/src/FBXWriter.cpp +++ b/libraries/fbx/src/FBXWriter.cpp @@ -62,8 +62,7 @@ QByteArray FBXWriter::encodeFBX(const FBXNode& root) { out.setVersion(QDataStream::Qt_4_5); out.writeRawData(FBX_BINARY_PROLOG, FBX_BINARY_PROLOG.size()); - auto bytes = QByteArray(FBX_HEADER_BYTES_BEFORE_VERSION - FBX_BINARY_PROLOG.size(), '\0'); - out.writeRawData(bytes, bytes.size()); + out.writeRawData("\0\x1a", 3); // Blender needs this header component. #ifdef USE_FBX_2016_FORMAT out << FBX_VERSION_2016; From 8716e9591ea1fb42ce6961dd0c0f65d37ad7956f Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Tue, 8 May 2018 16:12:01 -0700 Subject: [PATCH 6/9] Fixes for gcc compilation Maybe even clang also. --- libraries/fbx/src/FBXToJSON.cpp | 4 ++-- libraries/fbx/src/FBXToJSON.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/fbx/src/FBXToJSON.cpp b/libraries/fbx/src/FBXToJSON.cpp index 2994de0f02..195b7f5f90 100644 --- a/libraries/fbx/src/FBXToJSON.cpp +++ b/libraries/fbx/src/FBXToJSON.cpp @@ -15,7 +15,7 @@ using std::string; template -inline FBXToJSON& FBXToJSON::operator<<(QVector& arrayProp) { +inline FBXToJSON& FBXToJSON::operator<<(const QVector& arrayProp) { *this << "["; char comma = ' '; for (auto& prop : arrayProp) { @@ -44,7 +44,7 @@ FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) { ++_indentLevel; int p = 0; - char* eol = ""; + const char* eol = ""; for (auto& prop : fbxNode.properties) { *this << eol << string(_indentLevel * 4, ' ') << "\"p" << p++ << "\": "; switch (prop.userType()) { diff --git a/libraries/fbx/src/FBXToJSON.h b/libraries/fbx/src/FBXToJSON.h index 85feac6bff..e6b8efe51d 100644 --- a/libraries/fbx/src/FBXToJSON.h +++ b/libraries/fbx/src/FBXToJSON.h @@ -24,7 +24,7 @@ public: FBXToJSON& operator<<(const FBXNode& fbxNode); private: - template FBXToJSON& operator<<(QVector& arrayProp); + template FBXToJSON& operator<<(const QVector& arrayProp); static std::string stringEscape(const std::string& in); int _indentLevel { 0 }; }; From df6609c1f56bfb45fcc889bc0ecf082865e3590a Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Tue, 8 May 2018 16:26:19 -0700 Subject: [PATCH 7/9] Remove debugging #define --- libraries/baking/src/FBXBaker.cpp | 1 - libraries/baking/src/ModelBaker.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index c5aa5166ed..c6bfa045b9 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -33,7 +33,6 @@ #include "ModelBakingLoggingCategory.h" #include "TextureBaker.h" -#define HIFI_DUMP_FBX #ifdef HIFI_DUMP_FBX #include "FBXToJSON.h" #endif diff --git a/libraries/baking/src/ModelBaker.cpp b/libraries/baking/src/ModelBaker.cpp index 697b937a3b..75e10c54ab 100644 --- a/libraries/baking/src/ModelBaker.cpp +++ b/libraries/baking/src/ModelBaker.cpp @@ -24,7 +24,6 @@ #include #include -#define HIFI_DUMP_FBX #ifdef HIFI_DUMP_FBX #include "FBXToJSON.h" #endif From 7f2a90cdb9395b399eb3c4409d5e067add1e5860 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Fri, 18 May 2018 11:20:45 -0700 Subject: [PATCH 8/9] Address couple of reviewer issues --- libraries/baking/src/FBXBaker.cpp | 40 ------------------------------- libraries/fbx/src/FBX.h | 3 ++- libraries/fbx/src/FBXWriter.cpp | 1 - 3 files changed, 2 insertions(+), 42 deletions(-) diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index c6bfa045b9..b90082d969 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -365,43 +365,3 @@ void FBXBaker::rewriteAndBakeSceneTextures() { } } } - -#if 0 -void FBXBaker::exportScene() { - // save the relative path to this FBX inside our passed output folder - auto fileName = _modelURL.fileName(); - auto baseName = fileName.left(fileName.lastIndexOf('.')); - auto bakedFilename = baseName + BAKED_FBX_EXTENSION; - - _bakedModelFilePath = _bakedOutputDir + "/" + bakedFilename; - - auto fbxData = FBXWriter::encodeFBX(_rootNode); - - QFile bakedFile(_bakedModelFilePath); - - if (!bakedFile.open(QIODevice::WriteOnly)) { - handleError("Error opening " + _bakedModelFilePath + " for writing"); - return; - } - - bakedFile.write(fbxData); - - _outputFiles.push_back(_bakedModelFilePath); - -#ifdef HIFI_DUMP_FBX - { - FBXToJSON fbxToJSON; - fbxToJSON << _rootNode; - QFileInfo modelFile(_bakedModelFilePath); - QString outFilename(modelFile.dir().absolutePath() + "/" + modelFile.completeBaseName() + "_FBX.json"); - QFile jsonFile(outFilename); - if (jsonFile.open(QIODevice::WriteOnly)) { - jsonFile.write(fbxToJSON.str().c_str(), fbxToJSON.str().length()); - jsonFile.close(); - } - } -#endif - - qCDebug(model_baking) << "Exported" << _modelURL << "with re-written paths to" << _bakedModelFilePath; -} -#endif diff --git a/libraries/fbx/src/FBX.h b/libraries/fbx/src/FBX.h index ce3fc52c3a..b3b2b29c74 100644 --- a/libraries/fbx/src/FBX.h +++ b/libraries/fbx/src/FBX.h @@ -28,8 +28,9 @@ #include #include -static const QByteArray FBX_BINARY_PROLOG = "Kaydara FBX Binary "; +// See comment in FBXReader::parseFBX(). static const int FBX_HEADER_BYTES_BEFORE_VERSION = 23; +static const QByteArray FBX_BINARY_PROLOG("Kaydara FBX Binary \0\x1a\0", FBX_HEADER_BYTES_BEFORE_VERSION); static const quint32 FBX_VERSION_2015 = 7400; static const quint32 FBX_VERSION_2016 = 7500; diff --git a/libraries/fbx/src/FBXWriter.cpp b/libraries/fbx/src/FBXWriter.cpp index 7b1a4a6642..8a668e7ce9 100644 --- a/libraries/fbx/src/FBXWriter.cpp +++ b/libraries/fbx/src/FBXWriter.cpp @@ -62,7 +62,6 @@ QByteArray FBXWriter::encodeFBX(const FBXNode& root) { out.setVersion(QDataStream::Qt_4_5); out.writeRawData(FBX_BINARY_PROLOG, FBX_BINARY_PROLOG.size()); - out.writeRawData("\0\x1a", 3); // Blender needs this header component. #ifdef USE_FBX_2016_FORMAT out << FBX_VERSION_2016; From c205a856a71376b91a555b59d3a4c1f39db3de9f Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Mon, 21 May 2018 13:29:08 -0700 Subject: [PATCH 9/9] Split canned FBX header in two; only check first part on read --- libraries/fbx/src/FBX.h | 3 ++- libraries/fbx/src/FBXWriter.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/fbx/src/FBX.h b/libraries/fbx/src/FBX.h index b3b2b29c74..239908f86c 100644 --- a/libraries/fbx/src/FBX.h +++ b/libraries/fbx/src/FBX.h @@ -30,7 +30,8 @@ // See comment in FBXReader::parseFBX(). static const int FBX_HEADER_BYTES_BEFORE_VERSION = 23; -static const QByteArray FBX_BINARY_PROLOG("Kaydara FBX Binary \0\x1a\0", FBX_HEADER_BYTES_BEFORE_VERSION); +static const QByteArray FBX_BINARY_PROLOG("Kaydara FBX Binary "); +static const QByteArray FBX_BINARY_PROLOG2("\0\x1a\0", 3); static const quint32 FBX_VERSION_2015 = 7400; static const quint32 FBX_VERSION_2016 = 7500; diff --git a/libraries/fbx/src/FBXWriter.cpp b/libraries/fbx/src/FBXWriter.cpp index 8a668e7ce9..4504898e32 100644 --- a/libraries/fbx/src/FBXWriter.cpp +++ b/libraries/fbx/src/FBXWriter.cpp @@ -62,6 +62,7 @@ QByteArray FBXWriter::encodeFBX(const FBXNode& root) { out.setVersion(QDataStream::Qt_4_5); out.writeRawData(FBX_BINARY_PROLOG, FBX_BINARY_PROLOG.size()); + out.writeRawData(FBX_BINARY_PROLOG2, FBX_BINARY_PROLOG2.size()); #ifdef USE_FBX_2016_FORMAT out << FBX_VERSION_2016;