1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICK3DPARTICLEMODELPARTICLE_H |
5 | #define QQUICK3DPARTICLEMODELPARTICLE_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 <QColor> |
19 | #include <QVector4D> |
20 | #include <QtQuick3D/private/qquick3dnode_p.h> |
21 | #include <QtQuick3D/private/qquick3dmodel_p.h> |
22 | #include <QtQuick3D/qquick3dinstancing.h> |
23 | |
24 | #include <QtQuick3DParticles/private/qquick3dparticle_p.h> |
25 | #include <QtQuick3DParticles/private/qquick3dparticlesystem_p.h> |
26 | #include <QtQuick3DParticles/private/qquick3dparticledata_p.h> |
27 | |
28 | #include <QtCore/qpointer.h> |
29 | |
30 | QT_BEGIN_NAMESPACE |
31 | |
32 | class QQmlInstanceModel; |
33 | class QQmlChangeSet; |
34 | class QQuick3DParticleInstanceTable; |
35 | |
36 | class Q_QUICK3DPARTICLES_EXPORT QQuick3DParticleModelParticle : public QQuick3DParticle |
37 | { |
38 | Q_OBJECT |
39 | Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) |
40 | Q_PROPERTY(QQuick3DInstancing *instanceTable READ instanceTable NOTIFY instanceTableChanged) |
41 | |
42 | QML_NAMED_ELEMENT(ModelParticle3D) |
43 | Q_CLASSINFO("DefaultProperty" , "delegate" ) |
44 | QML_ADDED_IN_VERSION(6, 2) |
45 | |
46 | public: |
47 | QQuick3DParticleModelParticle(QQuick3DNode *parent = nullptr); |
48 | |
49 | QQmlComponent *delegate() const; |
50 | QQuick3DInstancing *instanceTable() const; |
51 | |
52 | public Q_SLOTS: |
53 | void setDelegate(QQmlComponent *delegate); |
54 | |
55 | Q_SIGNALS: |
56 | void delegateChanged(); |
57 | void instanceTableChanged(); |
58 | |
59 | protected: |
60 | void componentComplete() override; |
61 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
62 | |
63 | void setDepthBias(float bias) override |
64 | { |
65 | QQuick3DParticle::setDepthBias(bias); |
66 | if (m_node) |
67 | updateDepthBias(bias); |
68 | } |
69 | private: |
70 | void regenerate(); |
71 | void handleMaxAmountChanged(int amount); |
72 | void handleSortModeChanged(QQuick3DParticle::SortMode mode); |
73 | |
74 | friend class QQuick3DParticleSystem; |
75 | friend class QQuick3DParticleEmitter; |
76 | |
77 | void clearInstanceTable(); |
78 | void addInstance(const QVector3D &position, const QVector3D &scale, |
79 | const QVector3D &eulerRotation, const QColor &color, |
80 | float age); |
81 | void commitInstance(); |
82 | void updateDepthBias(float bias); |
83 | |
84 | QPointer<QQmlComponent> m_delegate; |
85 | QPointer<QQuick3DNode> m_node; |
86 | QQuick3DParticleInstanceTable *m_instanceTable = nullptr; |
87 | |
88 | QVector3D m_initialScale; |
89 | }; |
90 | |
91 | QT_END_NAMESPACE |
92 | |
93 | #endif // QQUICK3DPARTICLEMODELPARTICLE_H |
94 | |