summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-10-28 13:01:16 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-03-23 15:13:49 +0100
commitf18a602a33c12318e815350afaa3205cd1fa5fa6 (patch)
tree7c3317f1bd12ba67d59ae96bebf8d14af5314513 /tools
parent21cd6cb494c7a7b75081cc87ab14c8a6326eeb78 (diff)
qgltf: Use CBOR as binary format
[ChangeLog][qgltf][Important Behavior Changes] The -b option to qgltf now generates CBOR data instead of binary JSON. Therefore, gltf files generated with Qt 6.0 and the -b option to qgltf are not compatible with Qt 5.14 or earlier. Change-Id: I1641afa4ee3635e86885f85e79558ab42c31a196 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qgltf/qgltf.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/tools/qgltf/qgltf.cpp b/tools/qgltf/qgltf.cpp
index 71cdb6b5e..20073677b 100644
--- a/tools/qgltf/qgltf.cpp
+++ b/tools/qgltf/qgltf.cpp
@@ -43,6 +43,7 @@
#include <qjsondocument.h>
#include <qjsonobject.h>
#include <qjsonarray.h>
+#include <qcborvalue.h>
#include <qmath.h>
#define GLT_UNSIGNED_SHORT 0x1403
@@ -216,6 +217,9 @@ static inline QVector<float> ai2qt(const aiMatrix4x4 &matrix)
struct Options {
QString outDir;
+#if QT_CONFIG(cborstreamwriter)
+ bool genBin;
+#endif
bool compact;
bool compress;
bool genTangents;
@@ -1302,7 +1306,6 @@ private:
ProgramInfo *chooseProgram(uint materialIndex);
QJsonObject m_obj;
- QJsonDocument m_doc;
QVector<ProgramInfo> m_progs;
struct TechniqueInfo {
@@ -2445,23 +2448,34 @@ void GltfExporter::save(const QString &inputFilename)
exportTechniques(m_obj, basename);
- m_doc.setObject(m_obj);
-
QString gltfName = opts.outDir + basename + QStringLiteral(".qgltf");
f.setFileName(gltfName);
+#if QT_CONFIG(cborstreamwriter)
+ if (opts.showLog)
+ qDebug().noquote() << (opts.genBin ? "Writing (CBOR)" : "Writing") << gltfName;
+
+ const QIODevice::OpenMode openMode = opts.genBin
+ ? (QIODevice::WriteOnly | QIODevice::Truncate)
+ : (QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
+ const QByteArray data = opts.genBin
+ ? QCborValue::fromJsonValue(m_obj).toCbor()
+ : QJsonDocument(m_obj).toJson(opts.compact ? QJsonDocument::Compact
+ : QJsonDocument::Indented);
+#else
if (opts.showLog)
qDebug().noquote() << "Writing" << gltfName;
const QIODevice::OpenMode openMode
= QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text;
- const QByteArray json
- = m_doc.toJson(opts.compact ? QJsonDocument::Compact : QJsonDocument::Indented);
+ const QByteArray data
+ = QJsonDocument(m_obj).toJson(opts.compact ? QJsonDocument::Compact
+ : QJsonDocument::Indented);
+#endif
if (f.open(openMode)) {
m_files.insert(QFileInfo(f.fileName()).fileName());
- QByteArray json = m_doc.toJson(opts.compact ? QJsonDocument::Compact : QJsonDocument::Indented);
- f.write(json);
+ f.write(data);
f.close();
}
@@ -2505,8 +2519,8 @@ int main(int argc, char **argv)
cmdLine.setApplicationDescription(QString::fromUtf8(description));
QCommandLineOption outDirOpt(QStringLiteral("d"), QStringLiteral("Place all output data into <dir>"), QStringLiteral("dir"));
cmdLine.addOption(outDirOpt);
-#ifndef QT_BOOTSTRAPPED
- QCommandLineOption binOpt(QStringLiteral("b"), QStringLiteral("Store binary JSON data in the .qgltf file"));
+#if QT_CONFIG(cborstreamwriter)
+ QCommandLineOption binOpt(QStringLiteral("b"), QStringLiteral("Store CBOR data in the .qgltf file"));
cmdLine.addOption(binOpt);
#endif
QCommandLineOption compactOpt(QStringLiteral("m"), QStringLiteral("Store compact JSON in the .qgltf file"));
@@ -2531,6 +2545,9 @@ int main(int argc, char **argv)
cmdLine.addOption(silentOpt);
cmdLine.process(app);
opts.outDir = cmdLine.value(outDirOpt);
+#if QT_CONFIG(cborstreamwriter)
+ opts.genBin = cmdLine.isSet(binOpt);
+#endif
opts.compact = cmdLine.isSet(compactOpt);
opts.compress = cmdLine.isSet(compOpt);
opts.genTangents = cmdLine.isSet(tangentOpt);