ParticleSystem

This represents a particle system in Babylon. Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust. Particles can take different shapes while emitted like box, sphere, cone or you can write your custom function.

example

https://doc.babylonjs.com/babylon101/particles

Hierarchy

Implements

Index

Constructors

Properties

Methods

Constructors

constructor

  • new ParticleSystem(name: string, capacity: number, scene: Scene, customEffect?: Nullable<Effect>, isAnimationSheetEnabled?: boolean, epsilon?: number): ParticleSystem
  • Instantiates a particle system. Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.

    Parameters

    • name: string

      The name of the particle system

    • capacity: number

      The max number of particles alive at the same time

    • scene: Scene

      The scene the particle system belongs to

    • Optional customEffect: Nullable<Effect>

      a custom effect used to change the way particles are rendered by default

    • Optional isAnimationSheetEnabled: boolean

      Must be true if using a spritesheet to animate the particles texture

    • Optional epsilon: number

      Offset used to render the particles

    Returns ParticleSystem

Properties

activeSubSystems

activeSubSystems: Array<ParticleSystem>

The current active Sub-systems, this property is used by the root particle system only.

animations

animations: Animation[]

List of animations used by the particle system.

billboardMode

billboardMode: number

Gets or sets the billboard mode to use when isBillboardBased = true. Only BABYLON.AbstractMesh.BILLBOARDMODE_ALL and AbstractMesh.BILLBOARDMODE_Y are supported so far

blendMode

blendMode: number

Blend mode use to render the particle, it can be either ParticleSystem.BLENDMODE_ONEONE or ParticleSystem.BLENDMODE_STANDARD.

color1

color1: Color4

Random color of each particle after it has been emitted, between color1 and color2 vectors

color2

color2: Color4

Random color of each particle after it has been emitted, between color1 and color2 vectors

colorDead

colorDead: Color4

Color the particle will have at the end of its lifetime

customShader

customShader: any

This can help using your own shader to render the particle system. The according effect will be created

direction1

direction1: Vector3

Random direction of each particle after it has been emitted, between direction1 and direction2 vectors. This only works when particleEmitterTyps is a BoxParticleEmitter

direction2

direction2: Vector3

Random direction of each particle after it has been emitted, between direction1 and direction2 vectors. This only works when particleEmitterTyps is a BoxParticleEmitter

disposeOnStop

disposeOnStop: boolean

Specifies whether the particle system will be disposed once it reaches the end of the animation.

emitRate

emitRate: number

The maximum number of particles to emit per frame

emitter

The emitter represents the Mesh or position we are attaching the particle system to.

endSpriteCellID

endSpriteCellID: number

If using a spritesheet (isAnimationSheetEnabled) defines the last sprite cell to display

forceDepthWrite

forceDepthWrite: boolean

Forces the particle to write their depth information to the depth buffer. This can help preventing other draw calls to override the particles.

gravity

gravity: Vector3

You can use gravity if you want to give an orientation to your particles.

id

id: string

The id of the Particle system.

imageProcessingConfiguration

imageProcessingConfiguration: ImageProcessingConfiguration

Sets the Default image processing configuration used either in the this material.

If sets to null, the scene one is in use.

isAnimationSheetEnabled

isAnimationSheetEnabled: boolean

Gets or sets whether an animation sprite sheet is enabled or not on the particle system

isBillboardBased

isBillboardBased: boolean

Gets or sets a boolean indicating if the particles must be rendered as billboard or aligned with the direction

layerMask

layerMask: number

The layer mask we are rendering the particles through.

limitVelocityDamping

limitVelocityDamping: number

Gets or sets a value indicating the damping to apply if the limit velocity factor is reached

manualEmitCount

manualEmitCount: number

If you want to launch only a few particles at once, that can be done, as well.

maxAngularSpeed

maxAngularSpeed: number

Maximum angular speed of emitting particles (Z-axis rotation for each particle).

maxEmitBox

maxEmitBox: Vector3

Maximum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so. This only works when particleEmitterTyps is a BoxParticleEmitter

maxEmitPower

maxEmitPower: number

Maximum power of emitting particles.

maxInitialRotation

maxInitialRotation: number

Gets or sets the maximal initial rotation in radians.

maxLifeTime

maxLifeTime: number

Maximum life time of emitting particles.

maxScaleX

maxScaleX: number

Maximum scale of emitting particles on X axis.

maxScaleY

maxScaleY: number

Maximum scale of emitting particles on Y axis.

maxSize

maxSize: number

Maximum Size of emitting particles.

minAngularSpeed

minAngularSpeed: number

Minimum angular speed of emitting particles (Z-axis rotation for each particle).

minEmitBox

minEmitBox: Vector3

Minimum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so. This only works when particleEmitterTyps is a BoxParticleEmitter

minEmitPower

minEmitPower: number

Minimum power of emitting particles.

minInitialRotation

minInitialRotation: number

Gets or sets the minimal initial rotation in radians.

minLifeTime

minLifeTime: number

Minimum life time of emitting particles.

minScaleX

minScaleX: number

Minimum scale of emitting particles on X axis.

minScaleY

minScaleY: number

Minimum scale of emitting particles on Y axis.

minSize

minSize: number

Minimum Size of emitting particles.

name

name: string

The friendly name of the Particle system.

noiseStrength

noiseStrength: Vector3

Gets or sets the strength to apply to the noise value (default is (10, 10, 10))

noiseTexture

noiseTexture: Nullable<BaseTexture>

Gets or sets a texture used to add random noise to particle positions

onAnimationEnd

onAnimationEnd: Nullable<function>

Callback triggered when the particle animation is ending.

onDispose

onDispose: function

Sets a callback that will be triggered when the system is disposed

Type declaration

    • (): void
    • Returns void

onDisposeObservable

onDisposeObservable: Observable<ParticleSystem>

An event triggered when the system is disposed

particleEmitterType

particleEmitterType: IParticleEmitterType

The particle emitter type defines the emitter used by the particle system. It can be for example box, sphere, or cone...

particleTexture

particleTexture: Nullable<Texture>

The texture used to render each particle. (this can be a spritesheet)

particles

particles: Particle[]

Gets the current list of active particles

preWarmCycles

preWarmCycles: number

Gets or sets a value indicating how many cycles (or frames) must be executed before first rendering (this value has to be set before starting the system). Default is 0

preWarmStepOffset

preWarmStepOffset: number

Gets or sets a value indicating the time step multiplier to use in pre-warm mode (default is 1)

preventAutoStart

preventAutoStart: boolean

By default particle system starts as soon as they are created. This prevents the automatic start to happen and let you decide when to start emitting particles.

recycleParticle

recycleParticle: function

"Recycles" one of the particle by copying it back to the "stock" of particles and removing it from the active list. Its lifetime will start back at 0.

Type declaration

renderingGroupId

renderingGroupId: number

The rendering group used by the Particle system to chose when to render.

spriteCellChangeSpeed

spriteCellChangeSpeed: number

If using a spritesheet (isAnimationSheetEnabled) defines the speed of the sprite loop (default is 1 meaning the animation will play once during the entire particle lifetime)

spriteCellHeight

spriteCellHeight: number

If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell height to use

spriteCellWidth

spriteCellWidth: number

If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell width to use

startDirectionFunction

startDirectionFunction: function

This function can be defined to specify initial direction for every new particle. It by default use the emitterType defined function

Type declaration

startPositionFunction

startPositionFunction: function

This function can be defined to specify initial position for every new particle. It by default use the emitterType defined function

Type declaration

startSpriteCellID

startSpriteCellID: number

If using a spritesheet (isAnimationSheetEnabled) defines the first sprite cell to display

subEmitters

subEmitters: ParticleSystem[]

this is the Sub-emitters templates that will be used to generate particle system when the particle dies, this property is used by the root particle system only.

targetStopDuration

targetStopDuration: number

The amount of time the particle system is running (depends of the overall update speed).

textureMask

textureMask: Color4

An optional mask to filter some colors out of the texture, or filter a part of the alpha channel

translationPivot

translationPivot: Vector2

Gets or sets a Vector2 used to move the pivot (by default (0,0))

updateFunction

updateFunction: function

This function can be defined to provide custom update for active particles. This function will be called instead of regular update (age, position, color, etc.). Do not forget that this function will be called on every frame so try to keep it simple and fast :)

Type declaration

updateSpeed

updateSpeed: number

The overall motion speed (0.01 is default update speed, faster updates = faster animation)

Static BLENDMODE_ADD

BLENDMODE_ADD: number

Add current color and particle color multiplied by particle’s alpha.

Static BLENDMODE_ONEONE

BLENDMODE_ONEONE: number

Source color is added to the destination color without alpha affecting the result.

Static BLENDMODE_STANDARD

BLENDMODE_STANDARD: number

Blend current color and particle color using particle’s alpha.

Methods

addAngularSpeedGradient

  • addAngularSpeedGradient(gradient: number, factor: number, factor2?: number): IParticleSystem
  • Adds a new angular speed gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • factor: number

      defines the angular speed to affect to the specified gradient

    • Optional factor2: number

      defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from

    Returns IParticleSystem

    the current particle system

addColorGradient

  • Adds a new color gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • color: Color4

      defines the color to affect to the specified gradient

    • Optional color2: Color4

      defines an additional color used to define a range ([color, color2]) with main color to pick the final color from

    Returns IParticleSystem

addLifeTimeGradient

  • addLifeTimeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem
  • Adds a new life time gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • factor: number

      defines the life time factor to affect to the specified gradient

    • Optional factor2: number

      defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from

    Returns IParticleSystem

    the current particle system

addLimitVelocityGradient

  • addLimitVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem
  • Adds a new limit velocity gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • factor: number

      defines the limit velocity value to affect to the specified gradient

    • Optional factor2: number

      defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from

    Returns IParticleSystem

    the current particle system

addSizeGradient

  • addSizeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem
  • Adds a new size gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • factor: number

      defines the size factor to affect to the specified gradient

    • Optional factor2: number

      defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from

    Returns IParticleSystem

    the current particle system

addVelocityGradient

  • addVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem
  • Adds a new velocity gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • factor: number

      defines the velocity to affect to the specified gradient

    • Optional factor2: number

      defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from

    Returns IParticleSystem

    the current particle system

animate

  • animate(preWarmOnly?: boolean): void
  • Animates the particle system for the current frame by emitting new particles and or animating the living ones.

    Parameters

    • Optional preWarmOnly: boolean

      will prevent the system from updating the vertex buffer (default is false)

    Returns void

clone

  • Clones the particle system.

    Parameters

    • name: string

      The name of the cloned object

    • newEmitter: any

      The new emitter to use

    Returns ParticleSystem

    the cloned particle system

createBoxEmitter

  • Creates a Box Emitter for the particle system. (emits between direction1 and direction2 from withing the box defined by minEmitBox and maxEmitBox)

    Parameters

    • direction1: Vector3

      Particles are emitted between the direction1 and direction2 from within the box

    • direction2: Vector3

      Particles are emitted between the direction1 and direction2 from within the box

    • minEmitBox: Vector3

      Particles are emitted from the box between minEmitBox and maxEmitBox

    • maxEmitBox: Vector3

      Particles are emitted from the box between minEmitBox and maxEmitBox

    Returns BoxParticleEmitter

    the emitter

createConeEmitter

  • Creates a Cone Emitter for the particle system (emits from the cone to the particle position)

    Parameters

    • Optional radius: number

      The radius of the cone to emit from

    • Optional angle: number

      The base angle of the cone

    Returns ConeParticleEmitter

    the emitter

createDirectedSphereEmitter

  • Creates a Directed Sphere Emitter for the particle system (emits between direction1 and direction2)

    Parameters

    • Optional radius: number

      The radius of the sphere to emit from

    • Optional direction1: Vector3

      Particles are emitted between the direction1 and direction2 from within the sphere

    • Optional direction2: Vector3

      Particles are emitted between the direction1 and direction2 from within the sphere

    Returns SphereDirectedParticleEmitter

    the emitter

createHemisphericEmitter

  • Creates a Hemisphere Emitter for the particle system (emits along the hemisphere radius)

    Parameters

    • Optional radius: number

      The radius of the hemisphere to emit from

    • Optional radiusRange: number

      The range of the hemisphere to emit from [0-1] 0 Surface Only, 1 Entire Radius

    Returns HemisphericParticleEmitter

    the emitter

createPointEmitter

  • Creates a Point Emitter for the particle system (emits directly from the emitter position)

    Parameters

    • direction1: Vector3

      Particles are emitted between the direction1 and direction2 from within the box

    • direction2: Vector3

      Particles are emitted between the direction1 and direction2 from within the box

    Returns PointParticleEmitter

    the emitter

createSphereEmitter

  • Creates a Sphere Emitter for the particle system (emits along the sphere radius)

    Parameters

    • Optional radius: number

      The radius of the sphere to emit from

    • Optional radiusRange: number

      The range of the sphere to emit from [0-1] 0 Surface Only, 1 Entire Radius

    Returns SphereParticleEmitter

    the emitter

dispose

  • dispose(disposeTexture?: boolean): void
  • Disposes the particle system and free the associated resources

    Parameters

    • Optional disposeTexture: boolean

      defines if the particule texture must be disposed as well (true by default)

    Returns void

getAngularSpeedGradients

getCapacity

  • getCapacity(): number
  • Gets the maximum number of particles active at the same time.

    Returns number

    The max number of active particles.

getClassName

  • getClassName(): string
  • Returns the string "ParticleSystem"

    Returns string

    a string containing the class name

getColorGradients

getLifeTimeGradients

getLimitVelocityGradients

getScene

  • Get hosting scene

    Returns Scene

    the scene

getSizeGradients

getVelocityGradients

isAlive

  • isAlive(): boolean
  • Gets whether there are still active particles in the system.

    Returns boolean

    True if it is alive, otherwise false.

isReady

  • isReady(): boolean
  • Is this system ready to be used/rendered

    Returns boolean

    true if the system is ready

isStarted

  • isStarted(): boolean
  • Gets whether the system has been started.

    Returns boolean

    True if it has been started, otherwise false.

rebuild

  • rebuild(): void

removeAngularSpeedGradient

removeColorGradient

removeLifeTimeGradient

  • Remove a specific life time gradient

    Parameters

    • gradient: number

      defines the gradient to remove

    Returns IParticleSystem

    the current particle system

removeLimitVelocityGradient

removeSizeGradient

removeVelocityGradient

render

  • render(): number
  • Renders the particle system in its current state.

    Returns number

    the current number of particles

reset

  • reset(): void

serialize

  • serialize(): any
  • Serializes the particle system to a JSON object.

    Returns any

    the JSON object

start

  • start(delay?: number): void
  • Starts the particle system and begins to emit

    Parameters

    • Optional delay: number

      defines the delay in milliseconds before starting the system (0 by default)

    Returns void

stop

  • stop(stopSubEmitters?: boolean): void
  • Stops the particle system.

    Parameters

    • Optional stopSubEmitters: boolean

      if true it will stop the current system and all created sub-Systems if false it will stop the current root system only, this param is used by the root particle system only. the default value is true.

    Returns void

Static Parse

  • Parses a JSON object to create a particle system.

    Parameters

    • parsedParticleSystem: any

      The JSON object to parse

    • scene: Scene

      The scene to create the particle system in

    • rootUrl: string

      The root url to use to load external dependencies like texture

    Returns ParticleSystem

    the Parsed particle system

Generated using TypeDoc