class ParticleScene

Keeps track of all active ParticleSystems in a particular scene and performs per-frame updates.

Public

Constructors

ParticleScene

ParticleScene()

Default constructor.

Call SetOwner() after construction.

Methods

~ParticleScene

~ParticleScene() noexcept

SetOwner

void SetOwner(const SPtr<SceneInstance> &scene)

Set the owning scene instance.

Must be called after construction.

Update

Advances the simulation for all particle systems using the current frame time delta.

Outputs a set of data that can be used for rendering

& updating every active particle system.

Play

void Play(ecs::ParticleSimulation &simulation, const ParticleSystemSettings &settings)

Starts or resumes the particle system.

New particles will be emitted and existing particles will be evolved.

Pause

void Pause(ecs::ParticleSimulation &simulation)

Pauses the particle system.

New particles will stop being emitted and existing particle state will be frozen.

Stop

void Stop(ecs::ParticleSimulation &simulation)

Stops the particle system and resets it to initial state, clearing all particles.

CalculateBounds

AABox CalculateBounds(const ecs::ParticleSimulation &simulation) const

Calculate current particle bounds.

AllocateId

u32 AllocateId()

Allocates a unique particle system ID.

Used by the ParticleSystem component and ECS-only users.

staticCreate

static SPtr<ParticleScene> Create()

Creates a new empty particle scene.

Private

Methods

PreSimulate

void PreSimulate(const ParticleSystemState &state, u32 startIndex, u32 count, bool spacing, float spacingOffset)

Decrements particle lifetime, kills expired particles and executes evolvers that need to run before the simulation.

state
State describing the current state of the simulation.
startIndex
Index of the first particle to update.
count
Number of particles to update, starting from .
spacing
When false all particles will use the same time-step. If true the time-step will be divided by so particles are uniformly distributed over the time-step.
spacingOffset
Extra offset that controls the starting position of the first particle when calculating spacing. Should be in range [0, 1). 0 = beginning of the current time step, 1 = start of next particle.

Simulate

void Simulate(const ParticleSystemState &state, u32 startIndex, u32 count, bool spacing, float spacingOffset)

Simulates particle properties, advancing the simulation.

state
State describing the current state of the simulation.
startIndex
Index of the first particle to update.
count
Number of particles to update, starting from .
spacing
When false all particles will use the same time-step. If true the time-step will be divided by so particles are uniformly distributed over the time-step.
spacingOffset
Extra offset that controls the starting position of the first particle when calculating spacing. Should be in range [0, 1). 0 = beginning of the current time step, 1 = start of next particle.

PostSimulate

void PostSimulate(const ParticleSystemState &state, u32 startIndex, u32 count, bool spacing, float spacingOffset)

Executes evolvers that need to run after the simulation.

state
State describing the current state of the simulation.
startIndex
Index of the first particle to update.
count
Number of particles to update, starting from .
spacing
When false all particles will use the same time-step. If true the time-step will be divided by so particles are uniformly distributed over the time-step.
spacingOffset
Extra offset that controls the starting position of the first particle when calculating spacing. Should be in range [0, 1). 0 = beginning of the current time step, 1 = start of next particle.

AdvanceSimulation

void AdvanceSimulation(ecs::ParticleSimulation &simulation, const ecs::ParticleSystem &config, const ecs::WorldTransform &transform, float timeDelta, const EvaluatedAnimationData *animData)

Advances the simulation for a single particle system by the given time delta.

Handles emitting, evolving, and integrating all particles.

SortParticles

void SortParticles(const ParticleSet &set, ParticleSortMode sortMode, const Vector3 &viewPoint, u32 *indices)

Sorts the particles in the provided the .

Sorted particle indices are placed in the

array which is expected to be pre-allocated with enough space to hold an index for each particle in a set. is used as a reference point when using the Distance sort mode.

Fields

mOwner

WeakSPtr<SceneInstance> mOwner

m

Members * m

mNextId

u32 mNextId

mPaused

bool mPaused

mSimulationData

EvaluatedParticleData[2] mSimulationData

mReadBufferIdx

u32 mReadBufferIdx

mWriteBufferIdx

u32 mWriteBufferIdx

mMutex

Mutex mMutex

mSwapBuffers

bool mSwapBuffers