class ParticleSystem

Controls spawning, evolution and rendering of particles.

Particles can be 2D or 3D, with a variety of rendering options. Particle system should be used for rendering objects that cannot properly be represented using static or animated meshes, like liquids, smoke or flames.

The particle system requires you to specify at least one ParticleEmitter, which controls how are new particles generated. You will also want to specify one or more ParticleEvolvers, which change particle properties over time.

Public

Constructors

ParticleSystem

ParticleSystem(const HSceneObject &parent)

Methods

~ParticleSystem

virtual ~ParticleSystem() noexcept = default

SetSettings

void SetSettings(const ParticleSystemSettings &settings)

Determines general purpose settings that apply to the particle system.

SetGpuSimulationSettings

void SetGpuSimulationSettings(const ParticleGpuSimulationSettings &settings)

Determines settings that control particle GPU simulation.

SetEmitters

void SetEmitters(const Vector<SPtr<ParticleEmitter>> &emitters)

Set of objects that determine initial position, normal and other properties of newly spawned particles.

Each particle system must have at least one emitter.

GetEmitters

const Vector<SPtr<ParticleEmitter>> &GetEmitters() const

SetEvolvers

void SetEvolvers(const Vector<SPtr<ParticleEvolver>> &evolvers)

Set of objects that determine how particle properties change during their lifetime.

Evolvers only affect CPU simulated particles.

GetEvolvers

const Vector<SPtr<ParticleEvolver>> &GetEvolvers() const

SetLayer

void SetLayer(u64 layer)

Determines the layer bitfield that controls whether a system is considered visible in a specific camera.

Layer must match camera layer in order for the camera to render the component.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

GetSettings

const SettingsType &GetSettings() const

Determines general purpose settings that apply to the particle system.

GetGpuSimulationSettings

const GpuSimSettingsType &GetGpuSimulationSettings() const

Determines settings that control particle GPU simulation.

GetLayer

u64 GetLayer() const

Determines the layer bitfield that controls whether a system is considered visible in a specific camera.

Layer must match camera layer in order for the camera to render the component.

Internal

Methods

GetId

u32 GetId() const

Returns an ID that uniquely identifies the particle system.

Can be used for locating evaluated particle system render data in the structure output by the ParticlesManager.

TogglePreviewMode

bool TogglePreviewMode(bool enabled)

Enables or disables preview mode.

Preview mode allows the particle system to play while the game is not running, primarily for preview purposes in the editor. Returns true if the preview mode was enabled, false if it was disabled or enabling preview failed.

Simulate

void Simulate(float timeDelta, const EvaluatedAnimationData *animData)

Updates the particle simulation by advancing it by .

New state will be updated in the internal ParticleSet.

CalculateBounds

AABox CalculateBounds() const

Calculates the bounds of all the particles in the system.

Should be called after a call to SimulateInternal() to get up-to-date bounds. The bounds are in the simulation space of the particle system.

staticAdvanceTime

static float AdvanceTime(float time, float timeDelta, float duration, bool loop, float &outTimeStep)

Advances the particle system time according to the current time, time delta and the provided settings.

time
Current time to use as a base.
timeDelta
Amount of time to advance the time by.
duration
Maximum time allowed by the particle system.
loop
Determines what happens when the time exceeds . If true the time will wrap around to 0 and start over, if false the time will be clamped to .
outTimeStep
Actual time-step the simulation was advanced by. This is normally equal to but might be a different value if time was clamped.

Returns: New time value.

Protected

Constructors

ParticleSystem

ParticleSystem()

Methods

Initialize

void Initialize() override

Construct any resources the component needs before use.

Called when the parent scene object is initialized. A non-initialized component shouldn't be used in a live scene (i.e. it should not receive any of the component logic updates or events).

OnCreated

void OnCreated() override

Called once when the component has been created.

Called regardless of the state the component is in.

OnDestroyed

void OnDestroyed() override

Called once just before the component is destroyed.

Called regardless of the state the component is in.

OnDisabled

void OnDisabled() override

Called every time a component is placed into the Stopped state.

This includes component destruction if component wasn't already in Stopped state during destruction. When called during destruction it is called before OnDestroyed.

OnEnabled

void OnEnabled() override

Called every time a component leaves the Stopped state, if the component is enabled.

This includes component creation if requirements for leaving the Stopped state are met. When called during creation it is called after OnBeginPlay.

OnSceneChanged

void OnSceneChanged(SceneInstance *oldScene, ecs::Entity oldEntity) override

Called when the parent SceneObject's ECS entity is migrated to a new registry (e.g. when moving between scenes).

The old scene and entity are provided so that components can access sub-systems (renderer, physics, etc.) and read any data stored only in ECS fragments.

OnTransformChanged

void OnTransformChanged(TransformChangedFlags flags) override

Called when the component's parent scene object has changed.

Not called if the component is in Stopped state. Also only called if necessary notify flags are set via SetNotifyFlagsInternal().

Play

void Play()

Starts the particle system.

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

Pause

void Pause()

Pauses the particle system.

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

Stop

void Stop()

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

GetCoreDependencies

void GetCoreDependencies(Vector<CoreObject *> &dependencies) override

Populates the provided array with all core objects that this core object depends upon.

Dependencies are required for syncing to the render thread, so the system can be aware to update the dependant objects if a dependency is marked as dirty (for example updating a camera's viewport should also trigger an update on camera so it has a chance to potentially update its data).

Fields

mPreviewMode

bool mPreviewMode

Private

Methods

GetParticleSystemData

const TParticleSystemData<false> &GetParticleSystemData() const

Returns a reference to the particle system data for the CRTP getter interface.

GetFragment

ecs::ParticleSystem &GetFragment()

Returns a mutable reference to the particle system ECS fragment.

GetFragment

const ecs::ParticleSystem &GetFragment() const

Returns a const reference to the particle system ECS fragment.

GetSimulationFragment

ecs::ParticleSimulation &GetSimulationFragment()

Returns a mutable reference to the particle simulation ECS fragment.

GetSimulationFragment

const ecs::ParticleSimulation &GetSimulationFragment() const

Returns a const reference to the particle simulation ECS fragment.

MarkRenderProxyDataDirty

void MarkRenderProxyDataDirty(ComponentDirtyFlag flag = ComponentDirtyFlag::Everything)

Marks the render proxy data as dirty.

This causes the SyncToRenderProxy() method to trigger the next time objects are synced to the render thread.

flags
Flags in case you want to signal that only part of the internal data is dirty. SyncToRenderProxy() will be called regardless and it's up to the implementation to read the flags value if needed.