1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICK3DPARTICLELINEPARTICLE_H
5#define QQUICK3DPARTICLELINEPARTICLE_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 <QtQuick3DParticles/private/qquick3dparticlespriteparticle_p.h>
19
20QT_BEGIN_NAMESPACE
21
22class Q_QUICK3DPARTICLES_EXPORT QQuick3DParticleLineParticle : public QQuick3DParticleSpriteParticle
23{
24 Q_OBJECT
25 Q_PROPERTY(int segmentCount READ segmentCount WRITE setSegmentCount NOTIFY segmentCountChanged)
26 Q_PROPERTY(float alphaFade READ alphaFade WRITE setAlphaFade NOTIFY alphaFadeChanged)
27 Q_PROPERTY(float scaleMultiplier READ scaleMultiplier WRITE setScaleMultiplier NOTIFY scaleMultiplierChanged)
28 Q_PROPERTY(float texcoordMultiplier READ texcoordMultiplier WRITE setTexcoordMultiplier NOTIFY texcoordMultiplierChanged)
29 Q_PROPERTY(float length READ length WRITE setLength NOTIFY lengthChanged)
30 Q_PROPERTY(float lengthVariation READ lengthVariation WRITE setLengthVariation NOTIFY lengthVariationChanged)
31 Q_PROPERTY(float lengthDeltaMin READ lengthDeltaMin WRITE setLengthDeltaMin NOTIFY lengthDeltaMinChanged)
32 Q_PROPERTY(int eolFadeOutDuration READ eolFadeOutDuration WRITE setEolFadeOutDuration NOTIFY eolFadeOutDurationChanged)
33 Q_PROPERTY(TexcoordMode texcoordMode READ texcoordMode WRITE setTexcoordMode NOTIFY texcoordModeChanged)
34
35 QML_NAMED_ELEMENT(LineParticle3D)
36 QML_ADDED_IN_VERSION(6, 4)
37
38public:
39 enum TexcoordMode
40 {
41 Absolute,
42 Relative,
43 Fill,
44 };
45 Q_ENUM(TexcoordMode)
46
47 QQuick3DParticleLineParticle(QQuick3DNode *parent = nullptr);
48 ~QQuick3DParticleLineParticle() override;
49
50 int segmentCount() const;
51 float alphaFade() const;
52 float scaleMultiplier() const;
53 float texcoordMultiplier() const;
54 float length() const;
55 float lengthVariation() const;
56 float lengthDeltaMin() const;
57 int eolFadeOutDuration() const;
58 TexcoordMode texcoordMode() const;
59
60public Q_SLOTS:
61 void setSegmentCount(int count);
62 void setAlphaFade(float fade);
63 void setScaleMultiplier(float multiplier);
64 void setTexcoordMultiplier(float multiplier);
65 void setLength(float length);
66 void setLengthVariation(float length);
67 void setLengthDeltaMin(float min);
68 void setEolFadeOutDuration(int duration);
69 void setTexcoordMode(QQuick3DParticleLineParticle::TexcoordMode mode);
70
71Q_SIGNALS:
72 void segmentCountChanged();
73 void alphaFadeChanged();
74 void scaleMultiplierChanged();
75 void texcoordMultiplierChanged();
76 void lengthChanged();
77 void lengthVariationChanged();
78 void lengthDeltaMinChanged();
79 void eolFadeOutDurationChanged();
80 void texcoordModeChanged();
81
82private:
83
84 struct LineDataHeader
85 {
86 int emitterIndex = -1;
87 int pointCount = 0;
88 int currentIndex = 0;
89 float length = 0.0f;
90 };
91 struct LineData
92 {
93 QVector3D position;
94 QVector3D normal;
95 QVector4D color;
96 QVector3D tangent;
97 QVector3D binormal;
98 float size = 0.0f;
99 float length = 0.0f;
100 };
101 struct FadeOutLineData
102 {
103 int emitterIndex;
104 SpriteParticleData endPoint;
105 LineDataHeader header;
106 QVector<LineData> lineData;
107 float beginTime;
108 float endTime;
109 float timeFactor;
110 };
111
112 friend class QQuick3DParticleSystem;
113
114 class LineParticleUpdateNode : public ParticleUpdateNode
115 {
116 public:
117 LineParticleUpdateNode(QQuick3DNode *parent = nullptr)
118 : ParticleUpdateNode(parent)
119 {
120 }
121 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
122 };
123
124 void updateLineBuffer(LineParticleUpdateNode *updateNode, QSSGRenderGraphObject *node);
125 QSSGRenderGraphObject *updateLineNode(QSSGRenderGraphObject *node);
126 void handleSegmentCountChanged();
127 void updateLineSegment(int particleIndex);
128 void clearSegment(int particleIndex);
129 void handleMaxAmountChanged(int amount) override;
130 void handleSystemChanged(QQuick3DParticleSystem *system) override;
131 void reset() override;
132 void commitParticles(float time) override;
133 int nextCurrentIndex(const QQuick3DParticleEmitter *emitter) override;
134 void saveLineSegment(int particleIndex, float time);
135 void setParticleData(int particleIndex,
136 const QVector3D &position,
137 const QVector3D &rotation,
138 const QVector4D &color,
139 float size, float age,
140 float animationFrame) override;
141 void resetParticleData(int particleIndex) override;
142
143 QVector<LineDataHeader> m_lineHeaderData;
144 QVector<LineData> m_lineData;
145 QVector<FadeOutLineData> m_fadeOutData;
146
147 float m_alphaFade = 0.0f;
148 float m_scaleMultiplier = 1.0f;
149 float m_texcoordMultiplier = 1.0f;
150 float m_lengthDeltaMin = 10.0f;
151 float m_length = -1.0f;
152 float m_lengthVariation = 0.0f;
153 int m_segmentCount = 1;
154 int m_eolFadeOutDuration = 0;
155 TexcoordMode m_texcoordMode = TexcoordMode::Absolute;
156};
157
158QT_END_NAMESPACE
159
160#endif
161

source code of qtquick3d/src/quick3dparticles/qquick3dparticlelineparticle_p.h