1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICK3DPARTICLE_H |
5 | #define QQUICK3DPARTICLE_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 | |
21 | #include <QtQuick3DParticles/private/qquick3dparticlesystem_p.h> |
22 | #include <QtQuick3DParticles/private/qquick3dparticledata_p.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class QQuick3DParticleSpriteSequence; |
27 | |
28 | class Q_QUICK3DPARTICLES_EXPORT QQuick3DParticle : public QQuick3DObject |
29 | { |
30 | Q_OBJECT |
31 | Q_PROPERTY(int maxAmount READ maxAmount WRITE setMaxAmount NOTIFY maxAmountChanged) |
32 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged RESET resetColor) |
33 | Q_PROPERTY(QVector4D colorVariation READ colorVariation WRITE setColorVariation NOTIFY colorVariationChanged) |
34 | Q_PROPERTY(bool unifiedColorVariation READ unifiedColorVariation WRITE setUnifiedColorVariation NOTIFY unifiedColorVariationChanged) |
35 | Q_PROPERTY(FadeType fadeInEffect READ fadeInEffect WRITE setFadeInEffect NOTIFY fadeInEffectChanged) |
36 | Q_PROPERTY(FadeType fadeOutEffect READ fadeOutEffect WRITE setFadeOutEffect NOTIFY fadeOutEffectChanged) |
37 | Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration NOTIFY fadeInDurationChanged) |
38 | Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration NOTIFY fadeOutDurationChanged) |
39 | Q_PROPERTY(AlignMode alignMode READ alignMode WRITE setAlignMode NOTIFY alignModeChanged) |
40 | Q_PROPERTY(QVector3D alignTargetPosition READ alignTargetPosition WRITE setAlignTargetPosition NOTIFY alignTargetPositionChanged) |
41 | Q_PROPERTY(bool hasTransparency READ hasTransparency WRITE setHasTransparency NOTIFY hasTransparencyChanged) |
42 | Q_PROPERTY(SortMode sortMode READ sortMode WRITE setSortMode NOTIFY sortModeChanged) |
43 | |
44 | QML_NAMED_ELEMENT(Particle3D) |
45 | QML_UNCREATABLE("Particle3D is abstract" ) |
46 | QML_ADDED_IN_VERSION(6, 2) |
47 | |
48 | public: |
49 | QQuick3DParticle(QQuick3DObject *parent = nullptr); |
50 | ~QQuick3DParticle() override; |
51 | |
52 | enum FadeType |
53 | { |
54 | FadeNone, |
55 | FadeOpacity, |
56 | FadeScale |
57 | }; |
58 | Q_ENUM(FadeType) |
59 | |
60 | enum AlignMode |
61 | { |
62 | AlignNone, |
63 | AlignTowardsTarget, |
64 | AlignTowardsStartVelocity |
65 | }; |
66 | Q_ENUM(AlignMode) |
67 | |
68 | enum SortMode |
69 | { |
70 | SortNone, |
71 | SortNewest, |
72 | SortOldest, |
73 | SortDistance, |
74 | }; |
75 | Q_ENUM(SortMode) |
76 | |
77 | QQuick3DParticleSystem *system() const; |
78 | int maxAmount() const; |
79 | QColor color() const; |
80 | QVector4D colorVariation() const; |
81 | bool unifiedColorVariation() const; |
82 | FadeType fadeInEffect() const; |
83 | FadeType fadeOutEffect() const; |
84 | int fadeInDuration() const; |
85 | int fadeOutDuration() const; |
86 | AlignMode alignMode() const; |
87 | QVector3D alignTargetPosition() const; |
88 | bool hasTransparency() const; |
89 | SortMode sortMode() const; |
90 | |
91 | float opacity() const; |
92 | void resetColor(); |
93 | |
94 | public Q_SLOTS: |
95 | void setSystem(QQuick3DParticleSystem *system); |
96 | void setMaxAmount(int maxAmount); |
97 | void setColor(QColor color); |
98 | void setColorVariation(QVector4D colorVariation); |
99 | void setUnifiedColorVariation(bool unified); |
100 | void setFadeInEffect(QQuick3DParticle::FadeType fadeInEffect); |
101 | void setFadeOutEffect(QQuick3DParticle::FadeType fadeOutEffect); |
102 | void setFadeInDuration(int fadeInDuration); |
103 | void setFadeOutDuration(int fadeOutDuration); |
104 | void setAlignMode(QQuick3DParticle::AlignMode alignMode); |
105 | void setAlignTargetPosition(const QVector3D &alignPosition); |
106 | void setHasTransparency(bool transparency); |
107 | void setSortMode(QQuick3DParticle::SortMode sortMode); |
108 | |
109 | Q_SIGNALS: |
110 | void systemChanged(); |
111 | void maxAmountChanged(); |
112 | void colorChanged(); |
113 | void colorVariationChanged(); |
114 | void unifiedColorVariationChanged(); |
115 | void fadeInEffectChanged(); |
116 | void fadeOutEffectChanged(); |
117 | void fadeInDurationChanged(); |
118 | void fadeOutDurationChanged(); |
119 | void alignModeChanged(); |
120 | void alignTargetPositionChanged(); |
121 | void hasTransparencyChanged(); |
122 | void sortModeChanged(); |
123 | |
124 | protected: |
125 | // From QQmlParserStatus |
126 | void componentComplete() override; |
127 | QQuick3DParticle(QQuick3DObjectPrivate &dd, QQuick3DNode *parent = nullptr); |
128 | |
129 | virtual void reset(); |
130 | virtual void doSetMaxAmount(int amount); |
131 | |
132 | void updateBurstIndex(int amount); |
133 | // This will return the next available index |
134 | virtual int nextCurrentIndex(const QQuick3DParticleEmitter *emitter); |
135 | QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override |
136 | { |
137 | return node; |
138 | } |
139 | |
140 | QList<QQuick3DParticleData> m_particleData; |
141 | QQuick3DParticleSpriteSequence *m_spriteSequence = nullptr; |
142 | |
143 | int m_maxAmount = 100; |
144 | int m_currentIndex = -1; |
145 | int m_lastBurstIndex = 0; |
146 | AlignMode m_alignMode = AlignNone; |
147 | QVector3D m_alignTarget; |
148 | virtual void setDepthBias(float bias) |
149 | { |
150 | m_depthBias = bias; |
151 | } |
152 | float depthBias() const |
153 | { |
154 | return m_depthBias; |
155 | } |
156 | |
157 | private: |
158 | friend class QQuick3DParticleSystem; |
159 | friend class QQuick3DParticleEmitter; |
160 | friend class QQuick3DParticleSpriteSequence; |
161 | |
162 | QQuick3DParticleSystem *m_system = nullptr; |
163 | |
164 | QColor m_color; |
165 | QVector4D m_colorVariation; |
166 | bool m_unifiedColorVariation = false; |
167 | FadeType m_fadeInEffect = FadeOpacity; |
168 | FadeType m_fadeOutEffect = FadeOpacity; |
169 | int m_fadeInDuration = 250; |
170 | int m_fadeOutDuration = 250; |
171 | float m_depthBias = 0.0f; |
172 | bool m_hasTransparency = true; |
173 | SortMode m_sortMode = SortNone; |
174 | }; |
175 | |
176 | QT_END_NAMESPACE |
177 | |
178 | #endif |
179 | |