mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:21:16 +02:00
Add FBXNode to JSON stream class
This commit is contained in:
parent
a17359d2df
commit
e22bc7eff2
2 changed files with 112 additions and 0 deletions
82
libraries/fbx/src/FBXToJSON.cpp
Normal file
82
libraries/fbx/src/FBXToJSON.cpp
Normal file
|
@ -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<typename T>
|
||||||
|
inline FBXToJSON& FBXToJSON::operator<<(QVector<T>& 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<QVector<float>>()) {
|
||||||
|
*this << prop.value<QVector<float>>();
|
||||||
|
} else if (prop.canConvert<QVector<double>>()) {
|
||||||
|
*this << prop.value<QVector<double>>();
|
||||||
|
} else if (prop.canConvert<QVector<bool>>()) {
|
||||||
|
*this << prop.value<QVector<bool>>();
|
||||||
|
} else if (prop.canConvert<QVector<qint32>>()) {
|
||||||
|
*this << prop.value<QVector<qint32>>();
|
||||||
|
} else if (prop.canConvert<QVector<qint64>>()) {
|
||||||
|
*this << prop.value<QVector<qint64>>();
|
||||||
|
} else {
|
||||||
|
*this << "<unimplemented value>";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*this << ",\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto child : fbxNode.children) {
|
||||||
|
*this << child;
|
||||||
|
}
|
||||||
|
|
||||||
|
*this << string(_indentLevel * 4, ' ') << "},\n";
|
||||||
|
--_indentLevel;
|
||||||
|
return *this;
|
||||||
|
}
|
30
libraries/fbx/src/FBXToJSON.h
Normal file
30
libraries/fbx/src/FBXToJSON.h
Normal file
|
@ -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 <sstream>
|
||||||
|
|
||||||
|
// Forward declarations.
|
||||||
|
class FBXNode;
|
||||||
|
template<typename T> class QVector;
|
||||||
|
|
||||||
|
class FBXToJSON : public std::ostringstream {
|
||||||
|
public:
|
||||||
|
FBXToJSON& operator<<(const FBXNode& fbxNode);
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename T> FBXToJSON& operator<<(QVector<T>& arrayProp);
|
||||||
|
int _indentLevel { 0 };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_FBXToJSON_h
|
Loading…
Reference in a new issue