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 | QT_BEGIN_NAMESPACE |
29 | |
30 | class QQmlInstanceModel; |
31 | class QQmlChangeSet; |
32 | class QQuick3DParticleInstanceTable; |
33 | |
34 | class Q_QUICK3DPARTICLES_EXPORT QQuick3DParticleModelParticle : public QQuick3DParticle |
35 | { |
36 | Q_OBJECT |
37 | Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) |
38 | Q_PROPERTY(QQuick3DInstancing *instanceTable READ instanceTable NOTIFY instanceTableChanged) |
39 | |
40 | QML_NAMED_ELEMENT(ModelParticle3D) |
41 | Q_CLASSINFO("DefaultProperty" , "delegate" ) |
42 | QML_ADDED_IN_VERSION(6, 2) |
43 | |
44 | public: |
45 | QQuick3DParticleModelParticle(QQuick3DNode *parent = nullptr); |
46 | |
47 | QQmlComponent *delegate() const; |
48 | QQuick3DInstancing *instanceTable() const; |
49 | |
50 | public Q_SLOTS: |
51 | void setDelegate(QQmlComponent *delegate); |
52 | |
53 | Q_SIGNALS: |
54 | void delegateChanged(); |
55 | void instanceTableChanged(); |
56 | |
57 | protected: |
58 | void componentComplete() override; |
59 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
60 | |
61 | void setDepthBias(float bias) override |
62 | { |
63 | QQuick3DParticle::setDepthBias(bias); |
64 | if (m_node) |
65 | updateDepthBias(bias); |
66 | } |
67 | private: |
68 | void regenerate(); |
69 | void handleMaxAmountChanged(int amount); |
70 | void handleSortModeChanged(QQuick3DParticle::SortMode mode); |
71 | |
72 | friend class QQuick3DParticleSystem; |
73 | friend class QQuick3DParticleEmitter; |
74 | |
75 | void clearInstanceTable(); |
76 | void addInstance(const QVector3D &position, const QVector3D &scale, |
77 | const QVector3D &eulerRotation, const QColor &color, |
78 | float age); |
79 | void commitInstance(); |
80 | void updateDepthBias(float bias); |
81 | |
82 | QPointer<QQmlComponent> m_delegate; |
83 | QPointer<QQuick3DNode> m_node; |
84 | QQuick3DParticleInstanceTable *m_instanceTable = nullptr; |
85 | |
86 | QVector3D m_initialScale; |
87 | float m_initialOpacity = 1.0f; |
88 | bool m_explicitColor; |
89 | }; |
90 | |
91 | QT_END_NAMESPACE |
92 | |
93 | #endif // QQUICK3DPARTICLEMODELPARTICLE_H |
94 | |