1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICK3DPARTICLEAFFECTOR_H |
5 | #define QQUICK3DPARTICLEAFFECTOR_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 <QObject> |
19 | #include <QList> |
20 | #include <QQmlListProperty> |
21 | #include <QtQuick3D/private/qquick3dnode_p.h> |
22 | #include <QtQuick3DParticles/private/qquick3dparticledata_p.h> |
23 | #include <QtQuick3DParticles/private/qquick3dparticlesystem_p.h> |
24 | #include <QtQuick3DParticles/private/qquick3dparticleemitter_p.h> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class Q_QUICK3DPARTICLES_EXPORT QQuick3DParticleAffector : public QQuick3DNode |
29 | { |
30 | Q_OBJECT |
31 | Q_PROPERTY(QQuick3DParticleSystem *system READ system WRITE setSystem NOTIFY systemChanged) |
32 | Q_PROPERTY(QQmlListProperty<QQuick3DParticle> particles READ particles) |
33 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) |
34 | QML_NAMED_ELEMENT(Affector3D) |
35 | QML_UNCREATABLE("Affector3D is abstract" ) |
36 | QML_ADDED_IN_VERSION(6, 2) |
37 | |
38 | public: |
39 | QQuick3DParticleAffector(QQuick3DNode *parent = nullptr); |
40 | ~QQuick3DParticleAffector() override; |
41 | |
42 | QQuick3DParticleSystem *system() const; |
43 | bool enabled() const; |
44 | |
45 | // Particles list handling |
46 | QQmlListProperty<QQuick3DParticle> particles(); |
47 | void appendParticle(QQuick3DParticle *); |
48 | qsizetype particleCount() const; |
49 | QQuick3DParticle *particle(qsizetype) const; |
50 | void clearParticles(); |
51 | void replaceParticle(qsizetype, QQuick3DParticle *); |
52 | void removeLastParticle(); |
53 | |
54 | public Q_SLOTS: |
55 | void setSystem(QQuick3DParticleSystem *system); |
56 | void setEnabled(bool enabled); |
57 | |
58 | Q_SIGNALS: |
59 | void update(); |
60 | void systemChanged(); |
61 | void enabledChanged(); |
62 | |
63 | protected: |
64 | QList<QQuick3DParticle *> m_particles; |
65 | QQuick3DNode *m_systemSharedParent = nullptr; |
66 | |
67 | private: |
68 | friend class QQuick3DParticleSystem; |
69 | // From QQmlParserStatus |
70 | void componentComplete() override; |
71 | |
72 | // Called once per frame for all the enabled affectors. |
73 | virtual void prepareToAffect(); |
74 | // Called for each living particle attached to the attractor. |
75 | virtual void affectParticle(const QQuick3DParticleData &sd, QQuick3DParticleDataCurrent *d, float time) = 0; |
76 | |
77 | static void appendParticle(QQmlListProperty<QQuick3DParticle> *, QQuick3DParticle *); |
78 | static qsizetype particleCount(QQmlListProperty<QQuick3DParticle> *); |
79 | static QQuick3DParticle *particle(QQmlListProperty<QQuick3DParticle> *, qsizetype); |
80 | static void clearParticles(QQmlListProperty<QQuick3DParticle> *); |
81 | static void replaceParticle(QQmlListProperty<QQuick3DParticle> *, qsizetype, QQuick3DParticle *); |
82 | static void removeLastParticle(QQmlListProperty<QQuick3DParticle> *); |
83 | |
84 | QQuick3DParticleSystem *m_system = nullptr; |
85 | bool m_enabled = true; |
86 | QMap<QQuick3DParticle *, QMetaObject::Connection> m_connections; |
87 | }; |
88 | |
89 | QT_END_NAMESPACE |
90 | |
91 | #endif // QQUICK3DPARTICLEAFFECTOR_H |
92 | |