summaryrefslogtreecommitdiffstats
path: root/src/plugins/sceneparsers/gltf/gltfimporter.cpp
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2017-04-10 16:26:57 +0100
committerMike Krus <mike.krus@kdab.com>2017-05-21 11:40:00 +0000
commitb3302278a1e6094b17d4c7bd353e7717ee050bb5 (patch)
tree80f7c626805f42561e6ea17db87aafa960592031 /src/plugins/sceneparsers/gltf/gltfimporter.cpp
parent9f8fc3717508a6b8045f65e6c820692fb67dc450 (diff)
Add support to load data from memory for scene loaders
Change-Id: I666897ae54441a226fa6f8a7f8cdfc1a576f3494 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/plugins/sceneparsers/gltf/gltfimporter.cpp')
-rw-r--r--src/plugins/sceneparsers/gltf/gltfimporter.cpp41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/plugins/sceneparsers/gltf/gltfimporter.cpp b/src/plugins/sceneparsers/gltf/gltfimporter.cpp
index 78e230969..a94a4f307 100644
--- a/src/plugins/sceneparsers/gltf/gltfimporter.cpp
+++ b/src/plugins/sceneparsers/gltf/gltfimporter.cpp
@@ -314,13 +314,30 @@ void GLTFImporter::setSource(const QUrl &source)
}
/*!
- * Returns true if the extension of \a path is supported by the
+ * Sets the \a path used by the parser to load the scene file.
+ * If the file is valid, parsing is automatically triggered.
+ */
+void GLTFImporter::setData(const QByteArray& data, const QString &basePath)
+{
+ QJsonDocument sceneDocument = QJsonDocument::fromBinaryData(data);
+ if (sceneDocument.isNull())
+ sceneDocument = QJsonDocument::fromJson(data);
+
+ if (Q_UNLIKELY(!setJSON(sceneDocument))) {
+ qCWarning(GLTFImporterLog, "not a JSON document");
+ return;
+ }
+
+ setBasePath(basePath);
+}
+
+/*!
+ * Returns true if the extensions are supported by the
* GLTF parser.
*/
-bool GLTFImporter::isFileTypeSupported(const QUrl &source) const
+bool GLTFImporter::areFileTypesSupported(const QStringList &extensions) const
{
- const QString path = QUrlHelper::urlToLocalFileOrQrc(source);
- return GLTFImporter::isGLTFPath(path);
+ return GLTFImporter::isGLTFSupported(extensions);
}
Qt3DCore::QEntity* GLTFImporter::node(const QString &id)
@@ -570,16 +587,14 @@ GLTFImporter::AccessorData::AccessorData(const QJsonObject &json)
stride = byteStride.toInt();
}
-bool GLTFImporter::isGLTFPath(const QString& path)
+bool GLTFImporter::isGLTFSupported(const QStringList &extensions)
{
- QFileInfo finfo(path);
- if (!finfo.exists())
- return false;
-
- // might need to detect other things in the future, but would
- // prefer to avoid doing a full parse.
- QString suffix = finfo.suffix().toLower();
- return suffix == QLatin1String("json") || suffix == QLatin1String("gltf") || suffix == QLatin1String("qgltf");
+ for (auto suffix: qAsConst(extensions)) {
+ suffix = suffix.toLower();
+ if (suffix == QLatin1String("json") || suffix == QLatin1String("gltf") || suffix == QLatin1String("qgltf"))
+ return true;
+ }
+ return false;
}
void GLTFImporter::renameFromJson(const QJsonObject &json, QObject * const object)