API

Interface IParticleSystem

Interface representing a particle system in Babylon.js. This groups the common functionalities that needs to be implemented in order to create a particle system. A particle system represents a way to manage particles from their emission to their animation and rendering.

interface IParticleSystem {
    animations: Animation[];
    beginAnimationFrom: number;
    beginAnimationLoop: boolean;
    beginAnimationOnStart: boolean;
    beginAnimationTo: number;
    billboardMode: number;
    blendMode: number;
    color1: Color4;
    color2: Color4;
    colorDead: Color4;
    defaultProjectionMatrix: Matrix;
    disposeOnStop: boolean;
    doNotSerialize?: boolean;
    emitRate: number;
    emitter: Nullable<AbstractMesh | Vector3>;
    endSpriteCellID: number;
    gravity: Vector3;
    id: string;
    indexBuffer: Nullable<DataBuffer>;
    isAnimationSheetEnabled: boolean;
    isBillboardBased: boolean;
    isLocal: boolean;
    isNodeGenerated: boolean;
    layerMask: number;
    limitVelocityDamping: number;
    manualEmitCount: number;
    maxAngularSpeed: number;
    maxEmitPower: number;
    maxInitialRotation: number;
    maxLifeTime: number;
    maxScaleX: number;
    maxScaleY: number;
    maxSize: number;
    minAngularSpeed: number;
    minEmitPower: number;
    minInitialRotation: number;
    minLifeTime: number;
    minScaleX: number;
    minScaleY: number;
    minSize: number;
    name: string;
    noiseStrength: Vector3;
    noiseTexture: Nullable<BaseTexture>;
    onBeforeDrawParticlesObservable: Observable<Nullable<Effect>>;
    onDisposeObservable: Observable<IParticleSystem>;
    onStartedObservable: Observable<IParticleSystem>;
    onStoppedObservable: Observable<IParticleSystem>;
    particleEmitterType: Nullable<IParticleEmitterType>;
    particleTexture: Nullable<BaseTexture>;
    preWarmCycles: number;
    preWarmStepOffset: number;
    renderingGroupId: number;
    snippetId: string;
    spriteCellChangeSpeed: number;
    spriteCellHeight: number;
    spriteCellLoop: boolean;
    spriteCellWidth: number;
    spriteRandomStartCell: boolean;
    startDelay: number;
    startSpriteCellID: number;
    targetStopDuration: number;
    translationPivot: Vector2;
    uniqueId: number;
    updateInAnimate: boolean;
    updateSpeed: number;
    useLogarithmicDepth: boolean;
    useRampGradients: boolean;
    vertexBuffers: Immutable<{ [key: string]: VertexBuffer }>;
    vertexShaderName: string;
    addAlphaRemapGradient(
        gradient: number,
        min: number,
        max: number,
    ): IParticleSystem;
    addAngularSpeedGradient(
        gradient: number,
        factor: number,
        factor2?: number,
    ): IParticleSystem;
    addColorGradient(
        gradient: number,
        color1: Color4,
        color2?: Color4,
    ): IParticleSystem;
    addColorRemapGradient(
        gradient: number,
        min: number,
        max: number,
    ): IParticleSystem;
    addDragGradient(
        gradient: number,
        factor: number,
        factor2?: number,
    ): IParticleSystem;
    addEmitRateGradient(
        gradient: number,
        factor: number,
        factor2?: number,
    ): IParticleSystem;
    addLifeTimeGradient(
        gradient: number,
        factor: number,
        factor2?: number,
    ): IParticleSystem;
    addLimitVelocityGradient(
        gradient: number,
        factor: number,
        factor2?: number,
    ): IParticleSystem;
    addRampGradient(gradient: number, color: Color3): IParticleSystem;
    addSizeGradient(
        gradient: number,
        factor: number,
        factor2?: number,
    ): IParticleSystem;
    addStartSizeGradient(
        gradient: number,
        factor: number,
        factor2?: number,
    ): IParticleSystem;
    addVelocityGradient(
        gradient: number,
        factor: number,
        factor2?: number,
    ): IParticleSystem;
    animate(): void;
    clone(name: string, newEmitter: any): Nullable<IParticleSystem>;
    createBoxEmitter(
        direction1: Vector3,
        direction2: Vector3,
        minEmitBox: Vector3,
        maxEmitBox: Vector3,
    ): BoxParticleEmitter;
    createConeEmitter(radius: number, angle: number): ConeParticleEmitter;
    createCylinderEmitter(
        radius: number,
        height: number,
        radiusRange: number,
        directionRandomizer: number,
    ): CylinderParticleEmitter;
    createDirectedConeEmitter(
        radius: number,
        angle: number,
        direction1: Vector3,
        direction2: Vector3,
    ): ConeDirectedParticleEmitter;
    createDirectedCylinderEmitter(
        radius: number,
        height: number,
        radiusRange: number,
        direction1: Vector3,
        direction2: Vector3,
    ): CylinderDirectedParticleEmitter;
    createDirectedSphereEmitter(
        radius: number,
        direction1: Vector3,
        direction2: Vector3,
    ): SphereDirectedParticleEmitter;
    createHemisphericEmitter(
        radius: number,
        radiusRange: number,
    ): HemisphericParticleEmitter;
    createMeshEmitter(mesh: Nullable<AbstractMesh>): MeshParticleEmitter;
    createPointEmitter(
        direction1: Vector3,
        direction2: Vector3,
    ): PointParticleEmitter;
    createSphereEmitter(
        radius: number,
        radiusRange: number,
    ): SphereParticleEmitter;
    dispose(
        disposeTexture?: boolean,
        disposeAttachedSubEmitters?: boolean,
        disposeEndSubEmitters?: boolean,
    ): void;
    fillDefines(
        defines: string[],
        blendMode: number,
        fillImageProcessing?: boolean,
    ): void;
    fillUniformsAttributesAndSamplerNames(
        uniforms: string[],
        attributes: string[],
        samplers: string[],
    ): void;
    forceRefreshGradients(): void;
    getActiveCount(): number;
    getAlphaRemapGradients(): Nullable<FactorGradient[]>;
    getAngularSpeedGradients(): Nullable<FactorGradient[]>;
    getCapacity(): number;
    getClassName(): string;
    getColorGradients(): Nullable<ColorGradient[]>;
    getColorGradients(): Nullable<ColorGradient[]>;
    getColorRemapGradients(): Nullable<FactorGradient[]>;
    getCustomEffect(blendMode: number): Nullable<Effect>;
    getDragGradients(): Nullable<FactorGradient[]>;
    getEmitRateGradients(): Nullable<FactorGradient[]>;
    getLifeTimeGradients(): Nullable<FactorGradient[]>;
    getLimitVelocityGradients(): Nullable<FactorGradient[]>;
    getRampGradients(): Nullable<Color3Gradient[]>;
    getScene(): Nullable<Scene>;
    getSizeGradients(): Nullable<FactorGradient[]>;
    getStartSizeGradients(): Nullable<FactorGradient[]>;
    getVelocityGradients(): Nullable<FactorGradient[]>;
    isReady(): boolean;
    isStarted(): boolean;
    isStopping(): boolean;
    rebuild(): void;
    removeAngularSpeedGradient(gradient: number): IParticleSystem;
    removeColorGradient(gradient: number): IParticleSystem;
    removeDragGradient(gradient: number): IParticleSystem;
    removeEmitRateGradient(gradient: number): IParticleSystem;
    removeLifeTimeGradient(gradient: number): IParticleSystem;
    removeLimitVelocityGradient(gradient: number): IParticleSystem;
    removeSizeGradient(gradient: number): IParticleSystem;
    removeStartSizeGradient(gradient: number): IParticleSystem;
    removeVelocityGradient(gradient: number): IParticleSystem;
    render(): number;
    reset(): void;
    serialize(serializeTexture: boolean): any;
    setCustomEffect(effect: Nullable<Effect>, blendMode: number): void;
    start(delay?: number): void;
    stop(): void;
}

Implemented by

Index
animations: Animation[]

List of animations used by the particle system.

beginAnimationFrom: number

Gets or sets the frame to start the animation from when beginAnimationOnStart is true

beginAnimationLoop: boolean

Gets or sets a boolean indicating if animations must loop when beginAnimationOnStart is true

beginAnimationOnStart: boolean

Gets or sets a boolean indicating that hosted animations (in the system.animations array) must be started when system.start() is called

beginAnimationTo: number

Gets or sets the frame to end the animation on when beginAnimationOnStart is true

billboardMode: number

Gets or sets the billboard mode to use when isBillboardBased = true. Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED

blendMode: number

Blend mode use to render the particle. It can be any of the ParticleSystem.BLENDMODE_* constants

color1: Color4

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

color2: Color4

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

colorDead: Color4

Color the particle will have at the end of its lifetime.

defaultProjectionMatrix: Matrix

Gets or sets a matrix to use to compute projection

disposeOnStop: boolean

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

doNotSerialize?: boolean

Specifies if the particle system should be serialized

emitRate: number

The maximum number of particles to emit per frame until we reach the activeParticleCount value

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

endSpriteCellID: number

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

gravity: Vector3

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

id: string

The id of the Particle system.

indexBuffer: Nullable<DataBuffer>

Gets the index buffer used by the particle system (or null if no index buffer is used)

isAnimationSheetEnabled: boolean

Gets or sets a boolean indicating if a spritesheet is used to animate the particles texture

isBillboardBased: boolean

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

isLocal: boolean

Specifies if the particles are updated in emitter local space or world space

isNodeGenerated: boolean

Returns true if the particle system was generated by a node particle system set

layerMask: number

The layer mask we are rendering the particles through.

limitVelocityDamping: number

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

manualEmitCount: number

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

maxAngularSpeed: number

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

maxEmitPower: number

Maximum power of emitting particles.

maxInitialRotation: number

Gets or sets the maximal initial rotation in radians.

maxLifeTime: number

Maximum life time of emitting particles.

maxScaleX: number

Maximum scale of emitting particles on X axis.

maxScaleY: number

Maximum scale of emitting particles on Y axis.

maxSize: number

Maximum Size of emitting particles.

minAngularSpeed: number

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

minEmitPower: number

Minimum power of emitting particles.

minInitialRotation: number

Gets or sets the minimal initial rotation in radians.

minLifeTime: number

Minimum life time of emitting particles.

minScaleX: number

Minimum scale of emitting particles on X axis.

minScaleY: number

Minimum scale of emitting particles on Y axis.

minSize: number

Minimum Size of emitting particles.

name: string

The name of the Particle system.

noiseStrength: Vector3

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

noiseTexture: Nullable<BaseTexture>

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

onBeforeDrawParticlesObservable: Observable<Nullable<Effect>>

Observable that will be called just before the particles are drawn

onDisposeObservable: Observable<IParticleSystem>

An event triggered when the system is disposed

onStartedObservable: Observable<IParticleSystem>

An event triggered when the system is started

onStoppedObservable: Observable<IParticleSystem>

An event triggered when the system is stopped

particleEmitterType: Nullable<IParticleEmitterType>

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

particleTexture: Nullable<BaseTexture>

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

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: number

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

renderingGroupId: number

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

snippetId: string

Snippet ID if the particle system was created from the snippet server

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: number

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

spriteCellLoop: boolean

If using a spritesheet (isAnimationSheetEnabled), defines whether the sprite animation is looping

spriteCellWidth: number

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

spriteRandomStartCell: boolean

This allows the system to random pick the start cell ID between startSpriteCellID and endSpriteCellID

startDelay: number

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

startSpriteCellID: number

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

targetStopDuration: number

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

translationPivot: Vector2

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

uniqueId: number

Gets or sets the unique id of the particle system.

updateInAnimate: boolean

Indicates that the update of particles is done in the animate function (and not in render)

updateSpeed: number

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

useLogarithmicDepth: boolean

Gets or sets a boolean enabling the use of logarithmic depth buffers, which is good for wide depth buffers.

useRampGradients: boolean

Gets or sets a boolean indicating that ramp gradients must be used

vertexBuffers: Immutable<{ [key: string]: VertexBuffer }>

Gets the vertex buffers used by the particle system

vertexShaderName: string

Gets the name of the particle vertex shader

  • Adds a new alpha remap gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • min: number

      defines the alpha remap minimal range

    • max: number

      defines the alpha remap maximal range

    Returns IParticleSystem

    the current particle system

  • 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

    • Optionalfactor2: 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

  • Adds a new color remap gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • min: number

      defines the color remap minimal range

    • max: number

      defines the color remap maximal range

    Returns IParticleSystem

    the current particle system

  • Adds a new drag gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • factor: number

      defines the drag to affect to the specified gradient

    • Optionalfactor2: 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

  • Adds a new emit rate gradient (please note that this will only work if you set the targetStopDuration property)

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • factor: number

      defines the emit rate to affect to the specified gradient

    • Optionalfactor2: 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

  • 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

    • Optionalfactor2: 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

  • Adds a new limit velocity gradient

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • factor: number

      defines the limit velocity to affect to the specified gradient

    • Optionalfactor2: 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

  • 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

    • Optionalfactor2: 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

  • Adds a new start size gradient (please note that this will only work if you set the targetStopDuration property)

    Parameters

    • gradient: number

      defines the gradient to use (between 0 and 1)

    • factor: number

      defines the start size to affect to the specified gradient

    • Optionalfactor2: 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

  • 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

    • Optionalfactor2: 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

  • 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

  • Creates a Cylinder Emitter for the particle system (emits from the cylinder to the particle position)

    Parameters

    • radius: number

      The radius of the emission cylinder

    • height: number

      The height of the emission cylinder

    • radiusRange: number

      The range of emission [0-1] 0 Surface only, 1 Entire Radius

    • directionRandomizer: number

      How much to randomize the particle direction [0-1]

    Returns CylinderParticleEmitter

    the emitter

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

    Parameters

    • radius: number

      The radius of the cylinder to emit from

    • height: number

      The height of the emission cylinder

    • radiusRange: number

      the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)

    • direction1: Vector3

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

    • direction2: Vector3

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

    Returns CylinderDirectedParticleEmitter

    the emitter

  • Dispose the particle system and frees its associated resources.

    Parameters

    • OptionaldisposeTexture: boolean

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

    • OptionaldisposeAttachedSubEmitters: boolean

      defines if the attached sub-emitters must be disposed as well (false by default)

    • OptionaldisposeEndSubEmitters: boolean

      defines if the end type sub-emitters must be disposed as well (false by default)

    Returns void

  • Fill the defines array according to the current settings of the particle system

    Parameters

    • defines: string[]

      Array to be updated

    • blendMode: number

      blend mode to take into account when updating the array

    • OptionalfillImageProcessing: boolean

      fills the image processing defines

    Returns void

  • Fill the uniforms, attributes and samplers arrays according to the current settings of the particle system

    Parameters

    • uniforms: string[]

      Uniforms array to fill

    • attributes: string[]

      Attributes array to fill

    • samplers: string[]

      Samplers array to fill

    Returns void

  • Serializes the particle system to a JSON object

    Parameters

    • serializeTexture: boolean

      defines if the texture must be serialized as well

    Returns any

    the JSON object