From 94f4803d527922c2cdf8ebdb0af6cc244934e68a Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Fri, 4 May 2018 17:28:18 -0700 Subject: [PATCH] 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; }