8#include <QtCore/qdir.h>
9#include <QtQml/qqmlfile.h>
10#include <QtQuick3D/private/qquick3dobject_p.h>
11#include <QtQuick3D/private/qquick3dmodel_p.h>
12#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
18
19
20
21
22
23
24
25
26
27
28
29
31QQuick3DParticleShape::QQuick3DParticleShape(QObject *parent)
32 : QQuick3DParticleAbstractShape(parent)
37
38
39
40
41
42
43bool QQuick3DParticleShape::fill()
const
48void QQuick3DParticleShape::setFill(
bool fill)
58
59
60
61
62
63
66
67
68
69
70
71
72
73
74
75
76
78QQuick3DParticleShape::ShapeType QQuick3DParticleShape::type()
const
84
85
86
87
88
89
90QVector3D QQuick3DParticleShape::extents()
const
95void QQuick3DParticleShape::setType(QQuick3DParticleShape::ShapeType type)
101 Q_EMIT typeChanged();
104void QQuick3DParticleShape::setExtents(QVector3D extents)
106 if (m_extents == extents)
110 Q_EMIT extentsChanged();
113QVector3D QQuick3DParticleShape::getPosition(
int particleIndex)
115 if (!parentNode() || !m_system)
117 if (m_cachedIndex == particleIndex)
118 return m_cachedPosition;
121 case QQuick3DParticleShape::ShapeType::Cube:
122 m_cachedPosition = randomPositionCube(particleIndex);
124 case QQuick3DParticleShape::ShapeType::Sphere:
125 m_cachedPosition = randomPositionSphere(particleIndex);
127 case QQuick3DParticleShape::ShapeType::Cylinder:
128 m_cachedPosition = randomPositionCylinder(particleIndex);
131 m_cachedIndex = particleIndex;
132 return m_cachedPosition;
135QVector3D QQuick3DParticleShape::getSurfaceNormal(
int particleIndex)
140 auto rand = m_system->rand();
143 case QQuick3DParticleShape::ShapeType::Cube: {
144 int side =
int(rand->get(particleIndex, QPRand::Shape4) * 6);
158 mat.rotate(m_parentNode->rotation());
159 n = mat.mapVector(n);
161 case QQuick3DParticleShape::ShapeType::Sphere:
162 if (particleIndex != m_cachedIndex)
163 getPosition(particleIndex);
164 n = m_cachedPosition.normalized();
166 case QQuick3DParticleShape::ShapeType::Cylinder:
167 QVector3D scale = m_parentNode->scale();
168 float theta = rand->get(particleIndex, QPRand::Shape3) *
float(
M_PI) * 2.0f;
169 float x =
QPCOS(theta);
170 float z =
QPSIN(theta);
173 QVector3D normal(x, 0.0, z);
175 mat.rotate(m_parentNode->rotation());
176 n = mat.mapVector(normal.normalized());
182QVector3D QQuick3DParticleShape::randomPositionCube(
int particleIndex)
const
184 auto rand = m_system->rand();
185 QVector3D s = m_parentNode->scale() * m_extents;
186 float x = s.x() - (rand->get(particleIndex, QPRand::Shape1) * s.x() * 2.0f);
187 float y = s.y() - (rand->get(particleIndex, QPRand::Shape2) * s.y() * 2.0f);
188 float z = s.z() - (rand->get(particleIndex, QPRand::Shape3) * s.z() * 2.0f);
191 int side =
int(rand->get(particleIndex, QPRand::Shape4) * 6);
206 mat.rotate(m_parentNode->rotation());
207 return mat.mapVector(QVector3D(x, y, z));
210QVector3D QQuick3DParticleShape::randomPositionSphere(
int particleIndex)
const
212 auto rand = m_system->rand();
213 QVector3D scale = m_parentNode->scale() * m_extents;
214 float theta = rand->get(particleIndex, QPRand::Shape1) *
float(
M_PI) * 2.0f;
215 float v = rand->get(particleIndex, QPRand::Shape2);
216 float phi = acos((2.0f * v) - 1.0f);
217 float r = m_fill ? pow(rand->get(particleIndex, QPRand::Shape3), 1.0f / 3.0f) : 1.0f;
220 float z = r *
QPCOS(phi);
221 QVector3D pos(x, y, z);
224 mat.rotate(m_parentNode->rotation());
225 return mat.mapVector(pos);
228QVector3D QQuick3DParticleShape::randomPositionCylinder(
int particleIndex)
const
230 auto rand = m_system->rand();
231 QVector3D scale = m_parentNode->scale() * m_extents;
232 float y = scale.y() - (rand->get(particleIndex, QPRand::Shape1) * scale.y() * 2.0f);
235 r = sqrt(rand->get(particleIndex, QPRand::Shape2));
236 float theta = rand->get(particleIndex, QPRand::Shape3) *
float(
M_PI) * 2.0f;
237 float x = r *
QPCOS(theta);
238 float z = r *
QPSIN(theta);
241 QVector3D pos(x, y, z);
243 mat.rotate(m_parentNode->rotation());
244 return mat.mapVector(pos);