diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-02-13 14:11:08 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-02-13 14:58:06 +0000 |
commit | 209efae5307bf6cf519848205dbbe637c62c4ae2 (patch) | |
tree | 4ddf105cfe9a59391a058665d4b670079e69f02d | |
parent | 664b73dd36de6205cc84a219f936dd744a2dc184 (diff) |
Make scene parsers operate on URLs instead of raw filenames
This way they are compatible with how mesh and texture source URLs
are handled.
Change-Id: Ifeee504fd3f5957d23f5cade92a73663488bdaf9
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | examples/assimp/main.qml | 2 | ||||
-rw-r--r-- | examples/cpp_example/main.cpp | 2 | ||||
-rw-r--r-- | src/plugins/sceneparsers/assimp/assimpparser.cpp | 7 | ||||
-rw-r--r-- | src/plugins/sceneparsers/assimp/assimpparser_p.h | 4 | ||||
-rw-r--r-- | src/render/backend/jobs/loadscenejob.cpp | 6 | ||||
-rw-r--r-- | src/render/backend/jobs/loadscenejob_p.h | 5 | ||||
-rw-r--r-- | src/render/backend/renderscene.cpp | 4 | ||||
-rw-r--r-- | src/render/backend/renderscene_p.h | 5 | ||||
-rw-r--r-- | src/render/backend/scenemanager.cpp | 6 | ||||
-rw-r--r-- | src/render/backend/scenemanager_p.h | 8 | ||||
-rw-r--r-- | src/render/frontend/qabstractsceneloader.cpp | 6 | ||||
-rw-r--r-- | src/render/frontend/qabstractsceneloader.h | 9 | ||||
-rw-r--r-- | src/render/frontend/qabstractsceneloader_p.h | 2 | ||||
-rw-r--r-- | src/render/io/abstractsceneparser_p.h | 5 | ||||
-rw-r--r-- | src/render/io/gltfparser.cpp | 7 | ||||
-rw-r--r-- | src/render/io/gltfparser_p.h | 4 |
16 files changed, 46 insertions, 36 deletions
diff --git a/examples/assimp/main.qml b/examples/assimp/main.qml index 8de03a948..fa3d557a7 100644 --- a/examples/assimp/main.qml +++ b/examples/assimp/main.qml @@ -81,7 +81,7 @@ Entity SceneLoader { id: scene - source: ":/assets/test_scene.dae" + source: "assets/test_scene.dae" }] } } diff --git a/examples/cpp_example/main.cpp b/examples/cpp_example/main.cpp index cff6ad1f0..df20ba030 100644 --- a/examples/cpp_example/main.cpp +++ b/examples/cpp_example/main.cpp @@ -123,7 +123,7 @@ int main(int ac, char **av) sceneTransform->addTransform(sceneTranslateTransform); sceneEntity->addComponent(sceneTransform); // scene->setSource(":/assets/gltf/wine/wine.json"); - scene->setSource(":/assets/test_scene.dae"); + scene->setSource(QUrl("qrc:/assets/test_scene.dae")); sceneEntity->addComponent(scene); // Camera diff --git a/src/plugins/sceneparsers/assimp/assimpparser.cpp b/src/plugins/sceneparsers/assimp/assimpparser.cpp index 781899611..054c3ab79 100644 --- a/src/plugins/sceneparsers/assimp/assimpparser.cpp +++ b/src/plugins/sceneparsers/assimp/assimpparser.cpp @@ -52,6 +52,7 @@ #include <QColor> #include <qmath.h> #include <Qt3DRenderer/private/renderlogging_p.h> +#include <Qt3DCore/private/qurlhelper_p.h> QT_BEGIN_NAMESPACE @@ -273,8 +274,9 @@ QMatrix4x4 AssimpParser::aiMatrix4x4ToQMatrix4x4(const aiMatrix4x4 &matrix) * Sets the \a path used by the parser to load the asset file. * If the file is valid, this will trigger the parsing of the file. */ -void AssimpParser::setFilePath(const QString& path) +void AssimpParser::setSource(const QUrl &source) { + const QString path = QUrlHelper::urlToLocalFileOrQrc(source); QFileInfo file(path); m_sceneDir = file.absoluteDir(); if (!file.exists()) { @@ -288,8 +290,9 @@ void AssimpParser::setFilePath(const QString& path) * Returns true if the extension of \a path is supported by * the assimp parser. */ -bool AssimpParser::isPathExtensionSupported(const QString &path) +bool AssimpParser::isExtensionSupported(const QUrl &source) { + const QString path = QUrlHelper::urlToLocalFileOrQrc(source); return AssimpParser::isAssimpPath(path); } diff --git a/src/plugins/sceneparsers/assimp/assimpparser_p.h b/src/plugins/sceneparsers/assimp/assimpparser_p.h index cb446e426..31bfb7bc1 100644 --- a/src/plugins/sceneparsers/assimp/assimpparser_p.h +++ b/src/plugins/sceneparsers/assimp/assimpparser_p.h @@ -78,8 +78,8 @@ public: static bool isAssimpPath(const QString& path); // SceneParserInterface interface - void setFilePath(const QString& path) Q_DECL_OVERRIDE; - bool isPathExtensionSupported(const QString &path) Q_DECL_OVERRIDE; + void setSource(const QUrl& source) Q_DECL_OVERRIDE; + bool isExtensionSupported(const QUrl &source) Q_DECL_OVERRIDE; QEntity *scene(QString id = QString()) Q_DECL_OVERRIDE; QEntity *node(QString id) Q_DECL_OVERRIDE; diff --git a/src/render/backend/jobs/loadscenejob.cpp b/src/render/backend/jobs/loadscenejob.cpp index 00a94cdac..169804e19 100644 --- a/src/render/backend/jobs/loadscenejob.cpp +++ b/src/render/backend/jobs/loadscenejob.cpp @@ -46,7 +46,7 @@ namespace Qt3D { namespace Render { -LoadSceneJob::LoadSceneJob(const QString &source, const QNodeId &m_sceneComponent) +LoadSceneJob::LoadSceneJob(const QUrl &source, const QNodeId &m_sceneComponent) : QAspectJob() , m_renderer(Q_NULLPTR) , m_source(source) @@ -59,8 +59,8 @@ void LoadSceneJob::run() QEntity *sceneTree = m_renderer->sceneManager()->sceneTreeFromSource(m_source); if (sceneTree == Q_NULLPTR) { Q_FOREACH (AbstractSceneParser *parser, m_renderer->sceneParsers()) { - if (parser->isPathExtensionSupported(m_source)) { - parser->setFilePath(m_source); + if (parser->isExtensionSupported(m_source)) { + parser->setSource(m_source); sceneTree = parser->scene(); m_renderer->sceneManager()->addLoadedSceneTree(m_source, sceneTree); } diff --git a/src/render/backend/jobs/loadscenejob_p.h b/src/render/backend/jobs/loadscenejob_p.h index 68df20c03..1497f7c9f 100644 --- a/src/render/backend/jobs/loadscenejob_p.h +++ b/src/render/backend/jobs/loadscenejob_p.h @@ -40,6 +40,7 @@ #include <Qt3DCore/qaspectjob.h> #include <Qt3DCore/qnodeid.h> #include <QSharedPointer> +#include <QUrl> QT_BEGIN_NAMESPACE @@ -52,7 +53,7 @@ class Renderer; class LoadSceneJob : public Qt3D::QAspectJob { public: - explicit LoadSceneJob(const QString &source, const QNodeId &sceneComponent); + explicit LoadSceneJob(const QUrl &source, const QNodeId &sceneComponent); void setRenderer(Renderer *renderer) { m_renderer = renderer; } protected: @@ -60,7 +61,7 @@ protected: private: Renderer *m_renderer; - QString m_source; + QUrl m_source; QNodeId m_sceneComponent; }; diff --git a/src/render/backend/renderscene.cpp b/src/render/backend/renderscene.cpp index 00a2e466e..b9769f32b 100644 --- a/src/render/backend/renderscene.cpp +++ b/src/render/backend/renderscene.cpp @@ -66,12 +66,12 @@ void RenderScene::sceneChangeEvent(const QSceneChangePtr &e) { QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e); if (propertyChange->propertyName() == QByteArrayLiteral("source")) { - m_source = propertyChange->value().toString(); + m_source = propertyChange->value().toUrl(); m_sceneManager->addSceneData(m_source, peerUuid()); } } -QString RenderScene::source() const +QUrl RenderScene::source() const { return m_source; } diff --git a/src/render/backend/renderscene_p.h b/src/render/backend/renderscene_p.h index 71ba98d7b..4f7d12c06 100644 --- a/src/render/backend/renderscene_p.h +++ b/src/render/backend/renderscene_p.h @@ -39,6 +39,7 @@ #include <QtGlobal> #include <Qt3DCore/qbackendnode.h> +#include <QUrl> QT_BEGIN_NAMESPACE @@ -59,13 +60,13 @@ public: // QObserverInterface interface void sceneChangeEvent(const QSceneChangePtr &e) Q_DECL_OVERRIDE; - QString source() const; + QUrl source() const; void setSceneSubtree(QEntity *subTree); void setSceneManager(SceneManager *manager); private: SceneManager *m_sceneManager; - QString m_source; + QUrl m_source; }; class RenderSceneFunctor : public QBackendNodeFunctor diff --git a/src/render/backend/scenemanager.cpp b/src/render/backend/scenemanager.cpp index 21bb1432a..32611c4d0 100644 --- a/src/render/backend/scenemanager.cpp +++ b/src/render/backend/scenemanager.cpp @@ -50,7 +50,7 @@ SceneManager::SceneManager() : QResourceManager<RenderScene, { } -void SceneManager::addSceneData(const QString &source, const QNodeId &sceneUuid) +void SceneManager::addSceneData(const QUrl &source, const QNodeId &sceneUuid) { m_pendingJobs.append(LoadSceneJobPtr(new LoadSceneJob(source, sceneUuid))); } @@ -62,13 +62,13 @@ QVector<LoadSceneJobPtr> SceneManager::pendingSceneLoaderJobs() return copy; } -void SceneManager::addLoadedSceneTree(const QString &source, QEntity *tree) +void SceneManager::addLoadedSceneTree(const QUrl &source, QEntity *tree) { SceneManager::Locker lock(this); m_loadedSceneTrees.insert(source, tree); } -QEntity *SceneManager::sceneTreeFromSource(const QString &source) +QEntity *SceneManager::sceneTreeFromSource(const QUrl &source) { SceneManager::Locker lock(this); return m_loadedSceneTrees.value(source); diff --git a/src/render/backend/scenemanager_p.h b/src/render/backend/scenemanager_p.h index d45ed17bc..61b0c02a9 100644 --- a/src/render/backend/scenemanager_p.h +++ b/src/render/backend/scenemanager_p.h @@ -59,14 +59,14 @@ class SceneManager : public QResourceManager<RenderScene, public: SceneManager(); - void addSceneData(const QString &source, const QNodeId &sceneUuid); + void addSceneData(const QUrl &source, const QNodeId &sceneUuid); QVector<LoadSceneJobPtr> pendingSceneLoaderJobs(); - void addLoadedSceneTree(const QString &source, QEntity *tree); - QEntity *sceneTreeFromSource(const QString &source); + void addLoadedSceneTree(const QUrl &source, QEntity *tree); + QEntity *sceneTreeFromSource(const QUrl &source); private: - QHash<QString, QEntity *> m_loadedSceneTrees; + QHash<QUrl, QEntity *> m_loadedSceneTrees; QVector<LoadSceneJobPtr> m_pendingJobs; }; diff --git a/src/render/frontend/qabstractsceneloader.cpp b/src/render/frontend/qabstractsceneloader.cpp index 0b7c1b0a6..9e0b06aec 100644 --- a/src/render/frontend/qabstractsceneloader.cpp +++ b/src/render/frontend/qabstractsceneloader.cpp @@ -70,18 +70,18 @@ void QAbstractSceneLoader::copy(const QNode *ref) d_func()->m_source = s->d_func()->m_source; } -QString QAbstractSceneLoader::source() const +QUrl QAbstractSceneLoader::source() const { Q_D(const QAbstractSceneLoader); return d->m_source; } -void QAbstractSceneLoader::setSource(QString arg) +void QAbstractSceneLoader::setSource(const QUrl &arg) { Q_D(QAbstractSceneLoader); if (d->m_source != arg) { d->m_source = arg; - emit sourceChanged(arg); + emit sourceChanged(); } } diff --git a/src/render/frontend/qabstractsceneloader.h b/src/render/frontend/qabstractsceneloader.h index e96b75638..d5e08aa35 100644 --- a/src/render/frontend/qabstractsceneloader.h +++ b/src/render/frontend/qabstractsceneloader.h @@ -40,6 +40,7 @@ #include <Qt3DCore/qcomponent.h> #include <Qt3DCore/qscenechange.h> #include <Qt3DRenderer/qt3drenderer_global.h> +#include <QUrl> QT_BEGIN_NAMESPACE @@ -53,7 +54,7 @@ class QT3DRENDERERSHARED_EXPORT QAbstractSceneLoader : public QComponent { Q_OBJECT Q_ENUMS(Status) - Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) public: explicit QAbstractSceneLoader(QNode *parent = 0); @@ -64,8 +65,8 @@ public: Error }; - QString source() const; - void setSource(QString arg); + QUrl source() const; + void setSource(const QUrl &arg); Status status() const; void setStatus(Status status); @@ -73,7 +74,7 @@ public: virtual void sceneChangeEvent(const QSceneChangePtr &change) = 0; Q_SIGNALS: - void sourceChanged(QString arg); + void sourceChanged(); void statusChanged(); protected: diff --git a/src/render/frontend/qabstractsceneloader_p.h b/src/render/frontend/qabstractsceneloader_p.h index dfe3b515e..b9586fcf7 100644 --- a/src/render/frontend/qabstractsceneloader_p.h +++ b/src/render/frontend/qabstractsceneloader_p.h @@ -57,7 +57,7 @@ public: Q_DECLARE_PUBLIC(QAbstractSceneLoader) - QString m_source; + QUrl m_source; QAbstractSceneLoader::Status m_status; }; diff --git a/src/render/io/abstractsceneparser_p.h b/src/render/io/abstractsceneparser_p.h index 3d4d5442c..c6aef1729 100644 --- a/src/render/io/abstractsceneparser_p.h +++ b/src/render/io/abstractsceneparser_p.h @@ -40,6 +40,7 @@ #include <QObject> #include <QStringList> #include <QLoggingCategory> +#include <QUrl> #include <Qt3DRenderer/qt3drenderer_global.h> QT_BEGIN_NAMESPACE @@ -69,8 +70,8 @@ public: AbstractSceneParser(); virtual ~AbstractSceneParser(); - virtual void setFilePath(const QString &path) = 0; - virtual bool isPathExtensionSupported(const QString &path) = 0; + virtual void setSource(const QUrl &source) = 0; + virtual bool isExtensionSupported(const QUrl &source) = 0; virtual QEntity *scene(QString id = QString()) = 0; virtual QEntity *node(QString id) = 0; diff --git a/src/render/io/gltfparser.cpp b/src/render/io/gltfparser.cpp index 459655771..c11e4d8f6 100644 --- a/src/render/io/gltfparser.cpp +++ b/src/render/io/gltfparser.cpp @@ -50,6 +50,7 @@ #include <Qt3DCore/qtransform.h> #include <Qt3DCore/qmatrixtransform.h> #include <Qt3DCore/qcameralens.h> +#include <Qt3DCore/private/qurlhelper_p.h> #include <qtexture.h> #include <qparameter.h> @@ -285,8 +286,9 @@ bool GLTFParser::setJSON( QJsonDocument json ) * Sets the \a path used by the parser to load the scene file. * If the file is valid, parsing is automatically triggered. */ -void GLTFParser::setFilePath(const QString &path) +void GLTFParser::setSource(const QUrl &source) { + const QString path = QUrlHelper::urlToLocalFileOrQrc(source); QFileInfo finfo(path); if (!finfo.exists()) { qWarning() << "missing file:" << path; @@ -307,8 +309,9 @@ void GLTFParser::setFilePath(const QString &path) * Returns true if the extension of \a path is supported by the * GLTF parser. */ -bool GLTFParser::isPathExtensionSupported(const QString &path) +bool GLTFParser::isExtensionSupported(const QUrl &source) { + const QString path = QUrlHelper::urlToLocalFileOrQrc(source); return GLTFParser::isGLTFPath(path); } diff --git a/src/render/io/gltfparser_p.h b/src/render/io/gltfparser_p.h index 9e021f78a..a72e03793 100644 --- a/src/render/io/gltfparser_p.h +++ b/src/render/io/gltfparser_p.h @@ -75,8 +75,8 @@ public: bool setJSON( QJsonDocument json ); // SceneParserInterface interface - void setFilePath(const QString &path) Q_DECL_OVERRIDE; - bool isPathExtensionSupported(const QString &path) Q_DECL_OVERRIDE; + void setSource(const QUrl &source) Q_DECL_OVERRIDE; + bool isExtensionSupported(const QUrl &source) Q_DECL_OVERRIDE; /** * @brief instantiate Create Nodes based on glTf JSON document |