10#include <QtCore/qdir.h>
11#include <QtQml/qqmlfile.h>
12#include <QtQuick3D/private/qquick3dobject_p.h>
13#include <QtQuick3D/private/qquick3dmodel_p.h>
14#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
20
21
22
23
24
25
26
27
28
29
30
31
33QQuick3DParticleShape::QQuick3DParticleShape(QObject *parent)
34 : QQuick3DParticleAbstractShape(parent)
39
40
41
42
43
44
45bool QQuick3DParticleShape::fill()
const
50void QQuick3DParticleShape::setFill(
bool fill)
60
61
62
63
64
65
68
69
70
71
72
73
74
75
76
77
78
80QQuick3DParticleShape::ShapeType QQuick3DParticleShape::type()
const
86
87
88
89
90
91
92QVector3D QQuick3DParticleShape::extents()
const
97void QQuick3DParticleShape::setType(QQuick3DParticleShape::ShapeType type)
103 Q_EMIT typeChanged();
106void QQuick3DParticleShape::setExtents(QVector3D extents)
108 if (m_extents == extents)
112 Q_EMIT extentsChanged();
115QVector3D QQuick3DParticleShape::getPosition(
int particleIndex)
117 if (!parentNode() || !m_system)
119 if (m_cachedIndex == particleIndex)
120 return m_cachedPosition;
123 case QQuick3DParticleShape::ShapeType::Cube:
124 m_cachedPosition = randomPositionCube(particleIndex);
126 case QQuick3DParticleShape::ShapeType::Sphere:
127 m_cachedPosition = randomPositionSphere(particleIndex);
129 case QQuick3DParticleShape::ShapeType::Cylinder:
130 m_cachedPosition = randomPositionCylinder(particleIndex);
133 m_cachedIndex = particleIndex;
134 return m_cachedPosition;
137QVector3D QQuick3DParticleShape::getSurfaceNormal(
int particleIndex)
142 auto rand = m_system->rand();
145 case QQuick3DParticleShape::ShapeType::Cube: {
146 int side =
int(rand->get(particleIndex, QPRand::Shape4) * 6);
160 mat.rotate(m_parentNode->rotation());
161 n = mat.mapVector(n);
163 case QQuick3DParticleShape::ShapeType::Sphere:
164 if (particleIndex != m_cachedIndex)
165 getPosition(particleIndex);
166 n = m_cachedPosition.normalized();
168 case QQuick3DParticleShape::ShapeType::Cylinder:
169 QVector3D scale = m_parentNode->scale();
170 float theta = rand->get(particleIndex, QPRand::Shape3) *
float(
M_PI) * 2.0f;
171 float x =
QPCOS(theta);
172 float z =
QPSIN(theta);
175 QVector3D normal(x, 0.0, z);
177 mat.rotate(m_parentNode->rotation());
178 n = mat.mapVector(normal.normalized());
184QVector3D QQuick3DParticleShape::randomPositionCube(
int particleIndex)
const
186 auto rand = m_system->rand();
187 QVector3D s = m_parentNode->scale() * m_extents;
188 float x = s.x() - (rand->get(particleIndex, QPRand::Shape1) * s.x() * 2.0f);
189 float y = s.y() - (rand->get(particleIndex, QPRand::Shape2) * s.y() * 2.0f);
190 float z = s.z() - (rand->get(particleIndex, QPRand::Shape3) * s.z() * 2.0f);
193 int side =
int(rand->get(particleIndex, QPRand::Shape4) * 6);
208 mat.rotate(m_parentNode->rotation());
209 return mat.mapVector(QVector3D(x, y, z));
212QVector3D QQuick3DParticleShape::randomPositionSphere(
int particleIndex)
const
214 auto rand = m_system->rand();
215 QVector3D scale = m_parentNode->scale() * m_extents;
216 float theta = rand->get(particleIndex, QPRand::Shape1) *
float(
M_PI) * 2.0f;
217 float v = rand->get(particleIndex, QPRand::Shape2);
218 float phi = acos((2.0f * v) - 1.0f);
219 float r = m_fill ? pow(rand->get(particleIndex, QPRand::Shape3), 1.0f / 3.0f) : 1.0f;
222 float z = r *
QPCOS(phi);
223 QVector3D pos(x, y, z);
226 mat.rotate(m_parentNode->rotation());
227 return mat.mapVector(pos);
230QVector3D QQuick3DParticleShape::randomPositionCylinder(
int particleIndex)
const
232 auto rand = m_system->rand();
233 QVector3D scale = m_parentNode->scale() * m_extents;
234 float y = scale.y() - (rand->get(particleIndex, QPRand::Shape1) * scale.y() * 2.0f);
237 r = sqrt(rand->get(particleIndex, QPRand::Shape2));
238 float theta = rand->get(particleIndex, QPRand::Shape3) *
float(
M_PI) * 2.0f;
239 float x = r *
QPCOS(theta);
240 float z = r *
QPSIN(theta);
243 QVector3D pos(x, y, z);
245 mat.rotate(m_parentNode->rotation());
246 return mat.mapVector(pos);