Used to simulate particles and produce renderable particle mesh on either CPU or GPU. GPU simulation is generally much faster than its CPU counterpart, because it avoids slow CPU-GPU synchronization and takes advantage of many GPU cores. However, it requires client to support reasonable uniform count, reading from multiple textures in vertex shader and OES_texture_float extension, including rendering into float textures. Most mobile devices fail to satisfy these requirements, so it's not recommended to simulate thousands of particles on them. GPU version also can't sort particles, so enabling sorting forces CPU mode too. Particle rotation is specified by a single angle parameter: default billboard particles rotate around camera facing axis, while mesh particles rotate around 2 different view-independent axes. Most of the simulation parameters are specified with Curve or CurveSet. Curves are interpolated based on each particle's lifetime, therefore parameters are able to change over time. Most of the curve parameters can also be specified by 2 minimum/maximum curves, this way each particle will pick a random value in-between.
entity: Entity
The Entity that this Component is attached to.
Component.entity
system: ComponentSystem
The ComponentSystem used to create this Component.
Component.system
get alignToMotion(): boolean
Gets whether particles are oriented in their direction of motion or not.
boolean
set alignToMotion(arg: boolean): void
Sets whether particles are oriented in their direction of motion or not.
boolean
void
get alphaGraph(): Curve
Gets the alpha graph.
set alphaGraph(arg: Curve): void
Sets the alpha graph.
void
get alphaGraph2(): Curve
Gets the second alpha graph.
set alphaGraph2(arg: Curve): void
Sets the second alpha graph. If not null, particles pick random values between alphaGraph
and alphaGraph2.
void
get animIndex(): number
Gets the index of the animation to play.
number
set animIndex(arg: number): void
Sets the index of the animation to play. When animNumAnimations is greater than 1, the
sprite sheet animation index determines which animation the particle system should play.
number
void
get animLoop(): boolean
Gets whether the sprite sheet animation plays once or loops continuously.
boolean
set animLoop(arg: boolean): void
Sets whether the sprite sheet animation plays once or loops continuously.
boolean
void
get animNumAnimations(): number
Gets the number of sprite sheet animations contained within the current sprite sheet.
number
set animNumAnimations(arg: number): void
Sets the number of sprite sheet animations contained within the current sprite sheet. The
number of animations multiplied by number of frames should be a value less than animTilesX
multiplied by animTilesY.
number
void
get animNumFrames(): number
Gets the number of sprite sheet frames in the current sprite sheet animation.
number
set animNumFrames(arg: number): void
Sets the number of sprite sheet frames in the current sprite sheet animation. The number of
animations multiplied by number of frames should be a value less than animTilesX
multiplied by animTilesY.
number
void
get animSpeed(): number
Gets the sprite sheet animation speed.
number
set animSpeed(arg: number): void
Sets the sprite sheet animation speed. 1 = particle lifetime, 2 = double the particle lifetime, etc.
number
void
get animStartFrame(): number
Gets the sprite sheet frame that the animation should begin playing from.
number
set animStartFrame(arg: number): void
Sets the sprite sheet frame that the animation should begin playing from. Indexed from the start of the current animation.
number
void
get animTilesX(): number
Gets the number of horizontal tiles in the sprite sheet.
number
set animTilesX(arg: number): void
Sets the number of horizontal tiles in the sprite sheet.
number
void
get animTilesY(): number
Gets the number of vertical tiles in the sprite sheet.
number
set animTilesY(arg: number): void
Sets the number of vertical tiles in the sprite sheet.
number
void
get autoPlay(): boolean
Gets whether the particle system plays automatically on creation.
boolean
set autoPlay(arg: boolean): void
Sets whether the particle system plays automatically on creation. If set to false, it is necessary to call ParticleSystemComponent#play for the particle system to play. Defaults to true.
boolean
void
get blendType(): number
Gets how particles are blended when being written to the currently active render target.
number
set blendType(arg: number): void
Sets how particles are blended when being written to the currently active render target. Can be:
number
void
get colorGraph(): CurveSet
Gets the color graph.
set colorGraph(arg: CurveSet): void
Sets the color graph.
void
get colorGraph2(): CurveSet
Gets the second color graph.
set colorGraph2(arg: CurveSet): void
Sets the second color graph. If not null, particles pick random values between colorGraph
and colorGraph2.
void
get colorMap(): Texture
Gets the color map texture to apply to all particles in the system.
set colorMap(arg: Texture): void
Sets the color map texture to apply to all particles in the system. If no texture is assigned, a default spot texture is used.
void
get colorMapAsset(): Asset
Gets the Asset used to set the colorMap.
set colorMapAsset(arg: Asset): void
Sets the Asset used to set the colorMap.
void
get depthSoftening(): number
Gets whether depth softening is enabled.
number
set depthSoftening(arg: number): void
Sets whether depth softening is enabled. Controls fading of particles near their intersections with scene geometry. This effect, when it's non-zero, requires scene depth map to be rendered. Multiple depth-dependent effects can share the same map, but if you only use it for particles, bear in mind that it can double engine draw calls.
number
void
get depthWrite(): boolean
Gets whether depth writes is enabled.
boolean
set depthWrite(arg: boolean): void
Sets whether depth writes is enabled. If enabled, the particles will write to the depth buffer. If disabled, the depth buffer is left unchanged and particles will be guaranteed to overwrite one another in the order in which they are rendered.
boolean
void
get drawOrder(): number
Gets the draw order of the component.
number
set drawOrder(drawOrder: number): void
Sets the draw order of the component. A higher value means that the component will be rendered on top of other components in the same layer. This is not used unless the layer's sort order is set to SORTMODE_MANUAL.
number
void
get emitterExtents(): Vec3
Gets the extents of a local space bounding box within which particles are spawned at random positions.
set emitterExtents(arg: Vec3): void
Sets the extents of a local space bounding box within which particles are spawned at random
positions. This only applies to particle system with the shape EMITTERSHAPE_BOX.
void
get emitterExtentsInner(): Vec3
Gets the exception of extents of a local space bounding box within which particles are not spawned.
set emitterExtentsInner(arg: Vec3): void
Sets the exception of extents of a local space bounding box within which particles are not
spawned. It is aligned to the center of emitterExtents. This only applies to particle system
with the shape EMITTERSHAPE_BOX.
void
get emitterRadius(): number
Gets the radius within which particles are spawned at random positions.
number
set emitterRadius(arg: number): void
Sets the radius within which particles are spawned at random positions. This only applies to
particle system with the shape EMITTERSHAPE_SPHERE.
number
void
get emitterRadiusInner(): number
Gets the inner radius within which particles are not spawned.
number
set emitterRadiusInner(arg: number): void
Sets the inner radius within which particles are not spawned. This only applies to particle
system with the shape EMITTERSHAPE_SPHERE.
number
void
get emitterShape(): number
Gets the shape of the emitter.
number
set emitterShape(arg: number): void
Sets the shape of the emitter. Defines the bounds inside which particles are spawned. Also affects the direction of initial velocity.
number
void
get enabled(): boolean
Gets the enabled state of the component.
boolean
set enabled(arg: boolean): void
Sets the enabled state of the component.
boolean
void
Component.enabled
get halfLambert(): boolean
Gets whether Half Lambert lighting is enabled.
boolean
set halfLambert(arg: boolean): void
Sets whether Half Lambert lighting is enabled. Enabling Half Lambert lighting avoids particles looking too flat in shadowed areas. It is a completely non-physical lighting model but can give more pleasing visual results.
boolean
void
get initialVelocity(): number
Gets the magnitude of the initial emitter velocity.
number
set initialVelocity(arg: number): void
Sets the magnitude of the initial emitter velocity. Direction is given by emitter shape.
number
void
get intensity(): number
Gets the color multiplier.
number
set intensity(arg: number): void
Sets the color multiplier.
number
void
get layers(): number[]
Gets the array of layer IDs (Layer#id) to which this particle system belongs.
number
set layers(arg: number[]): void
Sets the array of layer IDs (Layer#id) to which this particle system should belong. Don't push/pop/splice or modify this array. If you want to change it, set a new one instead.
number
void
get lifetime(): number
Gets the length of time in seconds between a particle's birth and its death.
number
set lifetime(arg: number): void
Sets the length of time in seconds between a particle's birth and its death.
number
void
get lighting(): boolean
Gets whether particles will be lit by ambient and directional lights.
boolean
set lighting(arg: boolean): void
Sets whether particles will be lit by ambient and directional lights.
boolean
void
get localSpace(): boolean
Gets whether particles move with respect to the emitter's transform rather then world space.
boolean
set localSpace(arg: boolean): void
Sets whether particles move with respect to the emitter's transform rather then world space.
boolean
void
get localVelocityGraph(): CurveSet
Gets the local space velocity graph.
set localVelocityGraph(arg: CurveSet): void
Sets the local space velocity graph.
void
get localVelocityGraph2(): CurveSet
Gets the second velocity graph.
set localVelocityGraph2(arg: CurveSet): void
Sets the second velocity graph. If not null, particles pick random values between localVelocityGraph and localVelocityGraph2.
void
get loop(): boolean
Gets whether the particle system loops.
boolean
set loop(arg: boolean): void
Sets whether the particle system loops.
boolean
void
get mesh(): Mesh
Gets the polygonal mesh to be used as a particle.
set mesh(arg: Mesh): void
Sets the polygonal mesh to be used as a particle. Only first vertex/index buffer is used. Vertex buffer must contain local position at first 3 floats of each vertex.
void
get meshAsset(): Asset
Gets the Asset used to set the mesh.
set meshAsset(arg: Asset): void
Sets the Asset used to set the mesh.
void
get noFog(): boolean
Gets whether fogging is ignored.
boolean
set noFog(arg: boolean): void
Sets whether fogging is ignored.
boolean
void
get normalMap(): Texture
Gets the normal map texture to apply to all particles in the system.
set normalMap(arg: Texture): void
Sets the normal map texture to apply to all particles in the system. If no texture is assigned, an approximate spherical normal is calculated for each vertex.
void
get normalMapAsset(): Asset
Gets the Asset used to set the normalMap.
set normalMapAsset(arg: Asset): void
Sets the Asset used to set the normalMap.
void
get numParticles(): number
Gets the maximum number of simulated particles.
number
set numParticles(arg: number): void
Sets the maximum number of simulated particles.
number
void
get orientation(): number
Gets the particle orientation mode.
number
set orientation(arg: number): void
Sets the particle orientation mode. Can be:
number
void
get particleNormal(): Vec3
Gets the particle normal.
set particleNormal(arg: Vec3): void
Sets the particle normal. This only applies to particle system with the orientation modes
PARTICLEORIENTATION_WORLD and PARTICLEORIENTATION_EMITTER.
void
get preWarm(): boolean
Gets whether the particle system will be initialized as though it has already completed a full cycle.
boolean
set preWarm(arg: boolean): void
Sets whether the particle system will be initialized as though it has already completed a full cycle. This only works with looping particle systems.
boolean
void
get radialSpeedGraph(): Curve
Gets the radial speed graph.
set radialSpeedGraph(arg: Curve): void
Sets the radial speed graph. Velocity vector points from emitter origin to particle position.
void
get radialSpeedGraph2(): Curve
Gets the second radial speed graph.
set radialSpeedGraph2(arg: Curve): void
Sets the second radial speed graph. If not null, particles pick random values between radialSpeedGraph and radialSpeedGraph2. Velocity vector points from emitter origin to particle position.
void
get randomizeAnimIndex(): boolean
Gets whether each particle emitted by the system will play a random animation from the
sprite sheet, up to animNumAnimations.
boolean
set randomizeAnimIndex(arg: boolean): void
Sets whether each particle emitted by the system will play a random animation from the
sprite sheet, up to animNumAnimations.
boolean
void
get rate(): number
Gets the minimal interval in seconds between particle births.
number
set rate(arg: number): void
Sets the minimal interval in seconds between particle births.
number
void
get rate2(): number
Gets the maximal interval in seconds between particle births.
number
set rate2(arg: number): void
Sets the maximal interval in seconds between particle births.
number
void
get renderAsset(): Asset
Gets the Render Asset used to set the mesh.
set renderAsset(arg: Asset): void
Sets the Render Asset used to set the mesh.
void
get rotationSpeedGraph(): Curve
Gets the rotation speed graph.
set rotationSpeedGraph(arg: Curve): void
Sets the rotation speed graph.
void
get rotationSpeedGraph2(): Curve
Gets the second rotation speed graph.
set rotationSpeedGraph2(arg: Curve): void
Sets the second rotation speed graph. If not null, particles pick random values between rotationSpeedGraph and rotationSpeedGraph2.
void
get scaleGraph(): Curve
Gets the scale graph.
set scaleGraph(arg: Curve): void
Sets the scale graph.
void
get scaleGraph2(): Curve
Gets the second scale graph.
set scaleGraph2(arg: Curve): void
Sets the second scale graph. If not null, particles pick random values between scaleGraph
and scaleGraph2.
void
get screenSpace(): boolean
Gets whether particles are rendered in 2D screen space.
boolean
set screenSpace(arg: boolean): void
Sets whether particles are rendered in 2D screen space. This needs to be set when particle system is part of hierarchy with ScreenComponent as its ancestor, and allows particle system to integrate with the rendering of ElementComponents. Note that an entity with ParticleSystem component cannot be parented directly to ScreenComponent, but has to be a child of a ElementComponent, for example LayoutGroupComponent.
boolean
void
get sort(): number
Gets the particle sorting mode.
number
set sort(arg: number): void
Sets the particle sorting mode. Forces CPU simulation, so be careful.
number
void
get startAngle(): number
Gets the minimal initial Euler angle of a particle.
number
set startAngle(arg: number): void
Sets the minimal initial Euler angle of a particle.
number
void
get startAngle2(): number
Gets the maximal initial Euler angle of a particle.
number
set startAngle2(arg: number): void
Sets the maximal initial Euler angle of a particle.
number
void
get stretch(): number
Gets how much particles are stretched in their direction of motion.
number
set stretch(arg: number): void
Sets how much particles are stretched in their direction of motion. This is a value in world units that controls the amount by which particles are stretched based on their velocity. Particles are stretched from their center towards their previous position.
number
void
get velocityGraph(): CurveSet
Gets the world space velocity graph.
set velocityGraph(arg: CurveSet): void
Sets the world space velocity graph.
void
get velocityGraph2(): CurveSet
Gets the second world space velocity graph.
set velocityGraph2(arg: CurveSet): void
Sets the second world space velocity graph. If not null, particles pick random values between velocityGraph and velocityGraph2.
void
get wrap(): boolean
Gets whether particles wrap based on the set wrap bounds.
boolean
set wrap(arg: boolean): void
Sets whether particles wrap based on the set wrap bounds.
boolean
void
get wrapBounds(): Vec3
Gets the wrap bounds of the particle system.
set wrapBounds(arg: Vec3): void
Sets the wrap bounds of the particle system. This is half extents of a world space box volume centered on the owner entity's position. If a particle crosses the boundary of one side of the volume, it teleports to the opposite side.
void
fire(
name: string,
arg1?: any,
arg2?: any,
arg3?: any,
arg4?: any,
arg5?: any,
arg6?: any,
arg7?: any,
arg8?: any): EventHandler
Fire an event, all additional arguments are passed on to the event listener.
string
Name of event to fire.
any
First argument that is passed to the event handler.
any
Second argument that is passed to the event handler.
any
Third argument that is passed to the event handler.
any
Fourth argument that is passed to the event handler.
any
Fifth argument that is passed to the event handler.
any
Sixth argument that is passed to the event handler.
any
Seventh argument that is passed to the event handler.
any
Eighth argument that is passed to the event handler.
Self for chaining.
obj.fire('test', 'This is the message')
Component.fire
hasEvent(name: string): boolean
Test if there are any handlers bound to an event name.
string
The name of the event to test.
boolean
True if the object has handlers bound to the specified event name.
obj.on('test', () => {}) // bind an event to 'test'
obj.hasEvent('test') // returns true
obj.hasEvent('hello') // returns false
Component.hasEvent
isPlaying(): boolean
Checks if simulation is in progress.
boolean
True if the particle system is currently playing and false otherwise.
off(
name?: string,
callback?: HandleEventCallback,
scope?: any): EventHandler
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
string
Name of the event to unbind.
HandleEventCallback
Function to be unbound.
any
Scope that was used as the this when the event is fired.
Self for chaining.
const handler = () => {}
obj.on('test', handler)
obj.off() // Removes all events
obj.off('test') // Removes all events called 'test'
obj.off('test', handler) // Removes all handler functions, called 'test'
obj.off('test', handler, this) // Removes all handler functions, called 'test' with scope this
Component.off
on(
name: string,
callback: HandleEventCallback,
scope?: any): EventHandle
Attach an event handler to an event.
string
Name of the event to bind the callback to.
HandleEventCallback
Function that is called when event is fired. Note the callback is limited to 8 arguments.
any = ...
Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
obj.on('test', (a, b) => {
console.log(a + b)
})
obj.fire('test', 1, 2) // prints 3 to the console
const evt = obj.on('test', (a, b) => {
console.log(a + b)
})
// some time later
evt.off()
Component.on
once(
name: string,
callback: HandleEventCallback,
scope?: any): EventHandle
Attach an event handler to an event. This handler will be removed after being fired once.
string
Name of the event to bind the callback to.
HandleEventCallback
Function that is called when event is fired. Note the callback is limited to 8 arguments.
any = ...
Object to use as 'this' when the event is fired, defaults to current this.
obj.once('test', (a, b) => {
console.log(a + b)
})
obj.fire('test', 1, 2) // prints 3 to the console
obj.fire('test', 1, 2) // not going to get handled
Component.once
pause(): void
Freezes the simulation.
void
play(): void
Enables/unfreezes the simulation.
void
reset(): void
Resets particle state, doesn't affect playing.
void
stop(): void
Disables the emission of new particles, lets existing to finish their simulation.
void
unpause(): void
Unfreezes the simulation.
void