summaryrefslogtreecommitdiffstats
path: root/src/plugins/sceneparsers/gltf/gltfimporter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/sceneparsers/gltf/gltfimporter.cpp')
-rw-r--r--src/plugins/sceneparsers/gltf/gltfimporter.cpp47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/plugins/sceneparsers/gltf/gltfimporter.cpp b/src/plugins/sceneparsers/gltf/gltfimporter.cpp
index c026594bf..a94a4f307 100644
--- a/src/plugins/sceneparsers/gltf/gltfimporter.cpp
+++ b/src/plugins/sceneparsers/gltf/gltfimporter.cpp
@@ -255,7 +255,7 @@ Qt3DRender::QFilterKey *buildFilterKey(const QString &key, const QJsonValue &val
namespace Qt3DRender {
-Q_LOGGING_CATEGORY(GLTFImporterLog, "Qt3D.GLTFImport")
+Q_LOGGING_CATEGORY(GLTFImporterLog, "Qt3D.GLTFImport", QtWarningMsg)
GLTFImporter::GLTFImporter() : QSceneImporter(),
@@ -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)
@@ -1072,7 +1087,7 @@ void GLTFImporter::cleanup()
m_shaderPaths.clear();
delete_if_without_parent(m_programs);
m_programs.clear();
- for (auto params : m_techniqueParameters.values())
+ for (auto params : qAsConst(m_techniqueParameters))
delete_if_without_parent(params);
m_techniqueParameters.clear();
delete_if_without_parent(m_techniques);
@@ -1546,7 +1561,7 @@ void GLTFImporter::processJSONExtensions(const QString &id, const QJsonObject &j
// level GLTF item.
if (id == KEY_COMMON_MAT) {
const auto lights = jsonObject.value(KEY_LIGHTS).toObject();
- for (auto lightKey : lights.keys()) {
+ for (const auto &lightKey : lights.keys()) {
const auto light = lights.value(lightKey).toObject();
auto lightType = light.value(KEY_TYPE).toString();
const auto lightValues = light.value(lightType).toObject();