Add debug code to dump before/after FBXNode to file

Also fix trailing comma issue in json since gvim complains
bitterly.
This commit is contained in:
Simon Walton 2018-05-04 17:28:18 -07:00
parent e22bc7eff2
commit 94f4803d52
2 changed files with 46 additions and 6 deletions

View file

@ -33,6 +33,10 @@
#include "FBXBaker.h" #include "FBXBaker.h"
#ifdef HIFI_DUMP_FBX
#include "FBXToJSON.h"
#endif
void FBXBaker::bake() { void FBXBaker::bake() {
qDebug() << "FBXBaker" << _modelURL << "bake starting"; qDebug() << "FBXBaker" << _modelURL << "bake starting";
@ -194,6 +198,21 @@ void FBXBaker::importScene() {
qCDebug(model_baking) << "Parsing" << _modelURL; qCDebug(model_baking) << "Parsing" << _modelURL;
_rootNode = reader._rootNode = reader.parseFBX(&fbxFile); _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()); _geometry = reader.extractFBXGeometry({}, _modelURL.toString());
_textureContentMap = reader._textureContent; _textureContentMap = reader._textureContent;
} }
@ -374,5 +393,19 @@ void FBXBaker::exportScene() {
_outputFiles.push_back(_bakedModelFilePath); _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; qCDebug(model_baking) << "Exported" << _modelURL << "with re-written paths to" << _bakedModelFilePath;
} }

View file

@ -15,12 +15,15 @@
template<typename T> template<typename T>
inline FBXToJSON& FBXToJSON::operator<<(QVector<T>& arrayProp) { inline FBXToJSON& FBXToJSON::operator<<(QVector<T>& arrayProp) {
*this << "["; *this << "[";
char comma = ' ';
for (auto& prop : arrayProp) { for (auto& prop : arrayProp) {
*(std::ostringstream*)this << prop << ", "; *(std::ostringstream*)this << comma << prop;
comma = ',';
} }
*this << "] "; *this << "] ";
if (arrayProp.size() > 4) { if (arrayProp.size() > 4) {
*this << "# " << arrayProp.size() << " items"; *this << "// " << arrayProp.size() << " items";
} }
*this << '\n'; *this << '\n';
@ -34,10 +37,12 @@ FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) {
if (nodeName.empty()) nodeName = "nodename"; if (nodeName.empty()) nodeName = "nodename";
*this << string(_indentLevel * 4, ' ') << '"' << nodeName << "\": {\n"; *this << string(_indentLevel * 4, ' ') << '"' << nodeName << "\": {\n";
++_indentLevel; ++_indentLevel;
int p = 0; int p = 0;
char* eol = "";
for (auto& prop : fbxNode.properties) { for (auto& prop : fbxNode.properties) {
*this << string(_indentLevel * 4, ' ') << "\"p" << p++ << "\": "; *this << eol << string(_indentLevel * 4, ' ') << "\"p" << p++ << "\": ";
switch (prop.userType()) { switch (prop.userType()) {
case QMetaType::Short: case QMetaType::Short:
case QMetaType::Bool: case QMetaType::Bool:
@ -69,14 +74,16 @@ FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) {
} }
break; break;
} }
*this << ",\n"; eol = ",\n";
} }
for (auto child : fbxNode.children) { for (auto& child : fbxNode.children) {
*this << eol;
*this << child; *this << child;
eol = ",\n";
} }
*this << string(_indentLevel * 4, ' ') << "},\n"; *this << "\n" << string(_indentLevel * 4, ' ') << "}";
--_indentLevel; --_indentLevel;
return *this; return *this;
} }