1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
5#ifndef QQUICK3DRESOURCELOADER_H
6#define QQUICK3DRESOURCELOADER_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick3D/private/qquick3dnode_p.h>
20#include <QtQuick3D/private/qquick3dgeometry_p.h>
21#include <QtQuick3D/private/qquick3dtexture_p.h>
22#include <QtQml/QQmlListProperty>
23
24QT_BEGIN_NAMESPACE
25
26class Q_QUICK3D_EXPORT QQuick3DResourceLoader : public QQuick3DObject
27{
28 Q_OBJECT
29 Q_PROPERTY(QList<QUrl> meshSources READ meshSources WRITE setMeshSources NOTIFY meshSourcesChanged)
30 Q_PROPERTY(QQmlListProperty<QQuick3DTexture> textures READ textures)
31 Q_PROPERTY(QQmlListProperty<QQuick3DGeometry> geometries READ geometries)
32 QML_NAMED_ELEMENT(ResourceLoader)
33 QML_ADDED_IN_VERSION(6, 3)
34public:
35 QQuick3DResourceLoader(QQuick3DObject *parent = nullptr);
36
37 const QList<QUrl> &meshSources() const;
38 void setMeshSources(const QList<QUrl> &newMeshSources);
39 QQmlListProperty<QQuick3DGeometry> geometries();
40 QQmlListProperty<QQuick3DTexture> textures();
41Q_SIGNALS:
42 void meshSourcesChanged();
43
44private Q_SLOTS:
45 void onGeometryDestroyed(QObject *object);
46 void onTextureDestroyed(QObject *object);
47protected:
48 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
49 void markAllDirty() override;
50 void itemChange(ItemChange change, const ItemChangeData &value) override;
51
52private:
53 static void qmlAppendGeometry(QQmlListProperty<QQuick3DGeometry> *list, QQuick3DGeometry *geometry);
54 static QQuick3DGeometry *qmlGeometryAt(QQmlListProperty<QQuick3DGeometry> *list, qsizetype index);
55 static qsizetype qmlGeometriesCount(QQmlListProperty<QQuick3DGeometry> *list);
56 static void qmlClearGeometries(QQmlListProperty<QQuick3DGeometry> *list);
57
58 static void qmlAppendTexture(QQmlListProperty<QQuick3DTexture> *list, QQuick3DTexture *texture);
59 static QQuick3DTexture *qmlTextureAt(QQmlListProperty<QQuick3DTexture> *list, qsizetype index);
60 static qsizetype qmlTexturesCount(QQmlListProperty<QQuick3DTexture> *list);
61 static void qmlClearTextures(QQmlListProperty<QQuick3DTexture> *list);
62
63 enum ResourceLoaderDirtyType {
64 MeshesDirty = 0x00000001,
65 TexturesDirty = 0x00000002,
66 GeometriesDirty = 0x00000004
67 };
68
69
70 quint32 m_dirtyAttributes = 0xffffffff; // all dirty by default
71 void markDirty(ResourceLoaderDirtyType type);
72 void updateSceneManager(QQuick3DSceneManager *sceneManager);
73
74 QList<QUrl> m_meshSources;
75 QList<QQuick3DGeometry *> m_geometries;
76 QList<QQuick3DTexture *> m_textures;
77};
78
79QT_END_NAMESPACE
80
81#endif // QQUICK3DRESOURCELOADER_H
82

source code of qtquick3d/src/quick3d/qquick3dresourceloader_p.h