1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DRENDER_RENDER_LOADSCENEJOB_H
5#define QT3DRENDER_RENDER_LOADSCENEJOB_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <Qt3DCore/qaspectjob.h>
19#include <Qt3DCore/qentity.h>
20#include <Qt3DCore/private/qaspectjob_p.h>
21#include <Qt3DCore/qnodeid.h>
22#include <Qt3DRender/qsceneloader.h>
23#include <QSharedPointer>
24#include <QUrl>
25#include <functional>
26#include <Qt3DRender/private/qt3drender_global_p.h>
27
28QT_BEGIN_NAMESPACE
29
30namespace Qt3DRender {
31
32class QSceneImporter;
33
34namespace Render {
35
36class Scene;
37class NodeManagers;
38
39class LoadSceneJob;
40
41class Q_AUTOTEST_EXPORT LoadSceneJobPrivate : public Qt3DCore::QAspectJobPrivate
42{
43public:
44 explicit LoadSceneJobPrivate(LoadSceneJob *q): q_ptr(q) {}
45 ~LoadSceneJobPrivate() override {}
46
47 void postFrame(Qt3DCore::QAspectManager *manager) override;
48
49 std::unique_ptr<Qt3DCore::QEntity> m_sceneSubtree;
50 QSceneLoader::Status m_status = QSceneLoader::None;
51
52 Q_DECLARE_PUBLIC(LoadSceneJob)
53private:
54 LoadSceneJob *q_ptr;
55};
56
57class Q_3DRENDERSHARED_PRIVATE_EXPORT LoadSceneJob : public Qt3DCore::QAspectJob
58{
59public:
60 explicit LoadSceneJob(const QUrl &source, Qt3DCore::QNodeId sceneComponent);
61 void setData(const QByteArray &data);
62 void setNodeManagers(NodeManagers *managers) { m_managers = managers; }
63 void setSceneImporters(const QList<QSceneImporter *> sceneImporters) { m_sceneImporters = sceneImporters; }
64
65 NodeManagers *nodeManagers() const;
66 QList<QSceneImporter *> sceneImporters() const;
67 QUrl source() const;
68 Qt3DCore::QNodeId sceneComponentId() const;
69
70 void run() override;
71
72private:
73 QUrl m_source;
74 QByteArray m_data;
75 Qt3DCore::QNodeId m_sceneComponent;
76 NodeManagers *m_managers;
77 QList<QSceneImporter *> m_sceneImporters;
78
79 Qt3DCore::QEntity *tryLoadScene(QSceneLoader::Status &finalStatus,
80 const QStringList &extensions,
81 const std::function<void (QSceneImporter *)> &importerSetupFunc);
82 Q_DECLARE_PRIVATE(LoadSceneJob)
83};
84
85typedef QSharedPointer<LoadSceneJob> LoadSceneJobPtr;
86
87} // namespace Render
88
89} // namespace Qt3DRender
90
91QT_END_NAMESPACE
92
93#endif // LOADSCENEJOB_H
94

source code of qt3d/src/render/jobs/loadscenejob_p.h