Loading...
Searching...
No Matches
VolumeParticleEmitter2.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_VOLUME_PARTICLE_EMITTER2_HPP
12#define CUBBYFLOW_VOLUME_PARTICLE_EMITTER2_HPP
13
17
18#include <random>
19
20namespace CubbyFlow
21{
28{
29 public:
30 class Builder;
31
53 double spacing, const Vector2D& initialVel = Vector2D(),
54 const Vector2D& linearVel = Vector2D(), double angularVel = 0.0,
55 size_t maxNumberOfParticles = std::numeric_limits<size_t>::max(),
56 double jitter = 0.0, bool isOneShot = true,
57 bool allowOverlapping = false, uint32_t seed = 0);
58
68
71
74
77
80
82 [[nodiscard]] double GetJitter() const;
83
85 void SetJitter(double newJitter);
86
88 [[nodiscard]] bool GetIsOneShot() const;
89
100
103
114
117
120
122 [[nodiscard]] double GetSpacing() const;
123
125 void SetSpacing(double newSpacing);
126
129
132
135
138
140 [[nodiscard]] double GetAngularVelocity() const;
141
144
147
148 private:
155 void OnUpdate(double currentTimeInSeconds,
156 double timeIntervalInSeconds) override;
157
158 void Emit(const ParticleSystemData2Ptr& particles,
160
161 [[nodiscard]] double Random();
162
163 [[nodiscard]] Vector2D VelocityAt(const Vector2D& point) const;
164
165 std::mt19937 m_rng;
166
167 ImplicitSurface2Ptr m_implicitSurface;
168 BoundingBox2D m_maxRegion;
169 double m_spacing;
170 Vector2D m_initialVel;
171 Vector2D m_linearVel;
172 double m_angularVel = 0.0;
173 PointGenerator2Ptr m_pointsGen;
174
175 size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
176 size_t m_numberOfEmittedParticles = 0;
177
178 double m_jitter = 0.0;
179 bool m_isOneShot = true;
180 bool m_allowOverlapping = false;
181};
182
184using VolumeParticleEmitter2Ptr = std::shared_ptr<VolumeParticleEmitter2>;
185
190{
191 public:
195
198
201
204
207
210
213
216 size_t maxNumberOfParticles);
217
220
223
226
229
232
235
236 private:
237 ImplicitSurface2Ptr m_implicitSurface;
238 BoundingBox2D m_maxRegion;
239 double m_spacing = 0.1;
240 Vector2D m_initialVel;
241 Vector2D m_linearVel;
242 double m_angularVel = 0.0;
243 size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
244 double m_jitter = 0.0;
245 uint32_t m_seed = 0;
246 bool m_isBoundSet = false;
247 bool m_isOneShot = true;
248 bool m_allowOverlapping = false;
249};
250} // namespace CubbyFlow
251
252#endif
N-D axis-aligned bounding box class.
Definition BoundingBox.hpp:47
Definition Matrix.hpp:30
Abstract base class for 2-D particle emitter.
Definition ParticleEmitter2.hpp:22
Front-end to create VolumeParticleEmitter2 objects step by step.
Definition VolumeParticleEmitter2.hpp:190
Builder & WithMaxNumberOfParticles(size_t maxNumberOfParticles)
Returns builder with max number of particles.
Builder & WithInitialVelocity(const Vector2D &initialVel)
Returns builder with initial velocity.
Builder & WithAngularVelocity(double angularVel)
Returns builder with angular velocity.
Builder & WithLinearVelocity(const Vector2D &linearVel)
Returns builder with linear velocity.
Builder & WithJitter(double jitter)
Returns builder with jitter amount.
VolumeParticleEmitter2Ptr MakeShared() const
Builds shared pointer of VolumeParticleEmitter2 instance.
Builder & WithImplicitSurface(const ImplicitSurface2Ptr &implicitSurface)
Returns builder with implicit surface defining volume shape.
Builder & WithSpacing(double spacing)
Returns builder with spacing.
Builder & WithAllowOverlapping(bool allowOverlapping)
Returns builder with overlapping flag.
Builder & WithMaxRegion(const BoundingBox2D &maxRegion)
Returns builder with max region.
Builder & WithSurface(const Surface2Ptr &surface)
Returns builder with surface defining volume shape.
Builder & WithRandomSeed(uint32_t seed)
Returns builder with random seed.
Builder & WithIsOneShot(bool isOneShot)
Returns builder with one-shot flag.
VolumeParticleEmitter2 Build() const
Builds VolumeParticleEmitter2.
2-D volumetric particle emitter.
Definition VolumeParticleEmitter2.hpp:28
void SetMaxRegion(const BoundingBox2D &newMaxRegion)
Sets the max particle generator region.
void SetSpacing(double newSpacing)
Sets the spacing between particles.
void SetAllowOverlapping(bool newValue)
Sets the flag to true if particles can overlap each other.
void SetIsOneShot(bool newValue)
Sets the flag to true if particles are emitted just once.
size_t GetMaxNumberOfParticles() const
Returns max number of particles to be emitted.
double GetJitter() const
Returns jitter amount.
void SetJitter(double newJitter)
Sets jitter amount between 0 and 1.
static Builder GetBuilder()
Returns builder fox VolumeParticleEmitter2.
Vector2D GetInitialVelocity() const
Sets the initial velocity of the particles.
void SetLinearVelocity(const Vector2D &newLinearVel)
Sets the linear velocity of the emitter.
void SetInitialVelocity(const Vector2D &newInitialVel)
Returns the initial velocity of the particles.
const ImplicitSurface2Ptr & GetSurface() const
Returns source surface.
void SetAngularVelocity(double newAngularVel)
Sets the linear velocity of the emitter.
double GetSpacing() const
Returns the spacing between particles.
bool GetAllowOverlapping() const
Returns true if particles can be overlapped.
void SetPointGenerator(const PointGenerator2Ptr &newPointsGen)
Sets the point generator.
bool GetIsOneShot() const
Returns true if particles should be emitted just once.
void SetMaxNumberOfParticles(size_t newMaxNumberOfParticles)
Sets the max number of particles to be emitted.
Vector2D GetLinearVelocity() const
Returns the linear velocity of the emitter.
VolumeParticleEmitter2(ImplicitSurface2Ptr implicitSurface, BoundingBox2D maxRegion, double spacing, const Vector2D &initialVel=Vector2D(), const Vector2D &linearVel=Vector2D(), double angularVel=0.0, size_t maxNumberOfParticles=std::numeric_limits< size_t >::max(), double jitter=0.0, bool isOneShot=true, bool allowOverlapping=false, uint32_t seed=0)
void SetSurface(const ImplicitSurface2Ptr &newSurface)
Sets the source surface.
const BoundingBox2D & GetMaxRegion() const
Returns max particle generator region.
double GetAngularVelocity() const
Returns the angular velocity of the emitter.
Definition pybind11Utils.hpp:21
Vector2< double > Vector2D
Definition Matrix.hpp:774
std::shared_ptr< PointGenerator2 > PointGenerator2Ptr
Shared pointer for the PointGenerator2 type.
Definition PointGenerator2.hpp:71
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition Surface.hpp:144
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition ParticleSystemData.hpp:281
std::shared_ptr< VolumeParticleEmitter2 > VolumeParticleEmitter2Ptr
Shared pointer for the VolumeParticleEmitter2 type.
Definition VolumeParticleEmitter2.hpp:184
std::shared_ptr< ImplicitSurface2 > ImplicitSurface2Ptr
Shared pointer type for the ImplicitSurface2.
Definition ImplicitSurface.hpp:67