| 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 | |
| 23 | #include <QtCore/qpointer.h> |
| 24 | #include <QtCore/qlist.h> |
| 25 | #if QT_CONFIG(mimetype) |
| 26 | #include <QtCore/qmimetype.h> |
| 27 | #endif |
| 28 | |
| 29 | QT_BEGIN_NAMESPACE |
| 30 | |
| 31 | class Q_QUICK3DASSETUTILS_EXPORT QQuick3DRuntimeLoader : public QQuick3DNode |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | |
| 35 | QML_NAMED_ELEMENT(RuntimeLoader) |
| 36 | QML_ADDED_IN_VERSION(6, 2) |
| 37 | |
| 38 | Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) |
| 39 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
| 40 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) |
| 41 | Q_PROPERTY(QQuick3DBounds3 bounds READ bounds NOTIFY boundsChanged) |
| 42 | Q_PROPERTY(QQuick3DInstancing *instancing READ instancing WRITE setInstancing NOTIFY instancingChanged) |
| 43 | Q_PROPERTY(QStringList supportedExtensions READ supportedExtensions CONSTANT REVISION(6, 7)) |
| 44 | #if QT_CONFIG(mimetype) |
| 45 | Q_PROPERTY(QList<QMimeType> supportedMimeTypes READ supportedMimeTypes CONSTANT REVISION(6, 7)) |
| 46 | #endif |
| 47 | |
| 48 | public: |
| 49 | explicit QQuick3DRuntimeLoader(QQuick3DNode *parent = nullptr); |
| 50 | |
| 51 | QUrl source() const; |
| 52 | void setSource(const QUrl &newSource); |
| 53 | void componentComplete() override; |
| 54 | Q_REVISION(6, 7) static QStringList supportedExtensions(); |
| 55 | #if QT_CONFIG(mimetype) |
| 56 | Q_REVISION(6, 7) static QList<QMimeType> supportedMimeTypes(); |
| 57 | #endif |
| 58 | |
| 59 | enum class Status { Empty, Success, Error }; |
| 60 | Q_ENUM(Status) |
| 61 | Status status() const; |
| 62 | QString errorString() const; |
| 63 | const QQuick3DBounds3 &bounds() const; |
| 64 | |
| 65 | QQuick3DInstancing *instancing() const; |
| 66 | void setInstancing(QQuick3DInstancing *newInstancing); |
| 67 | |
| 68 | Q_SIGNALS: |
| 69 | void sourceChanged(); |
| 70 | void statusChanged(); |
| 71 | void errorStringChanged(); |
| 72 | void boundsChanged(); |
| 73 | void instancingChanged(); |
| 74 | |
| 75 | protected: |
| 76 | QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override; |
| 77 | |
| 78 | private: |
| 79 | void calculateBounds(); |
| 80 | void loadSource(); |
| 81 | void updateModels(); |
| 82 | |
| 83 | QPointer<QQuick3DNode> m_root; |
| 84 | QPointer<QQuick3DNode> m_imported; |
| 85 | QString m_assetId; // Used to release runtime assets in the buffer manager. |
| 86 | QUrl m_source; |
| 87 | Status m_status = Status::Empty; |
| 88 | QString m_errorString; |
| 89 | bool m_boundsDirty = false; |
| 90 | QQuick3DBounds3 m_bounds; |
| 91 | QQuick3DInstancing *m_instancing = nullptr; |
| 92 | bool m_instancingChanged = false; |
| 93 | }; |
| 94 | |
| 95 | QT_END_NAMESPACE |
| 96 | |
| 97 | #endif // QQUICK3DRUNTIMELOADER_H |
| 98 |
