1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICK3DRUNTIMELOADER_H
5#define QQUICK3DRUNTIMELOADER_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 purely as an
12// implementation detail. 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 <QtQuick3D/private/qquick3dmodel_p.h>
19#include <QtQuick3D/private/qquick3dinstancing_p.h>
20
21#include "qtquick3dassetutilsglobal_p.h"
22
23QT_BEGIN_NAMESPACE
24
25class Q_QUICK3DASSETUTILS_EXPORT QQuick3DRuntimeLoader : public QQuick3DNode
26{
27 Q_OBJECT
28
29 QML_NAMED_ELEMENT(RuntimeLoader)
30 QML_ADDED_IN_VERSION(6, 2)
31
32 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
33 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
34 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
35 Q_PROPERTY(QQuick3DBounds3 bounds READ bounds NOTIFY boundsChanged)
36 Q_PROPERTY(QQuick3DInstancing *instancing READ instancing WRITE setInstancing NOTIFY instancingChanged)
37
38public:
39 explicit QQuick3DRuntimeLoader(QQuick3DNode *parent = nullptr);
40
41 QUrl source() const;
42 void setSource(const QUrl &newSource);
43 void componentComplete() override;
44
45 enum class Status { Empty, Success, Error };
46 Q_ENUM(Status)
47 Status status() const;
48 QString errorString() const;
49 const QQuick3DBounds3 &bounds() const;
50
51 QQuick3DInstancing *instancing() const;
52 void setInstancing(QQuick3DInstancing *newInstancing);
53
54Q_SIGNALS:
55 void sourceChanged();
56 void statusChanged();
57 void errorStringChanged();
58 void boundsChanged();
59 void instancingChanged();
60
61protected:
62 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
63
64private:
65 void calculateBounds();
66 void loadSource();
67 void updateModels();
68
69 QPointer<QQuick3DNode> m_root;
70 QPointer<QQuick3DNode> m_imported;
71 QString m_assetId; // Used to release runtime assets in the buffer manager.
72 QUrl m_source;
73 Status m_status = Status::Empty;
74 QString m_errorString;
75 bool m_boundsDirty = false;
76 QQuick3DBounds3 m_bounds;
77 QQuick3DInstancing *m_instancing = nullptr;
78 bool m_instancingChanged = false;
79};
80
81QT_END_NAMESPACE
82
83#endif // QQUICK3DRUNTIMELOADER_H
84

source code of qtquick3d/src/assetutils/qquick3druntimeloader_p.h