Home Reference Source
import System from 'three-nebula/src/core/System.js'
public class | source

System

The core of the three-system particle engine. A System instance can contain multiple emitters, each with their own initializers and behaviours.

Static Method Summary

Static Public Methods
public static

fromJSON(json: object, THREE: object): System

this method was deprecated. use fromJSONAsync instead

Creates a System instance from a JSON object.

public static

fromJSONAsync(json: object, THREE: object, options: object): Promise<System>

Loads a System instance from JSON asynchronously.

Constructor Summary

Public Constructor
public

constructor(THREE: object, preParticles: number, integrationType: string): *

Constructs a System instance.

Member Summary

Public Members
public

Determines if the system can update or not.

public

emitters: array<Emitter>

The emitters in the particle system.

public

Internal event dispatcher

public

The integration algorithm type to use.

public

A pool used to manage the internal system cache of objects

public

The number of particles to start with.

public

renderers: array<Renderer>

The renderers for the system.

public

The class type.

Method Summary

Public Methods
public

Adds an emitter to the System instance.

public

addRenderer(renderer: Renderer): System

Adds a renderer to the System instance and initializes it.

public

destroy(): *

Destroys all emitters, renderers and the Nebula pool.

public

Proxy method for the internal event dispatcher's dispatchEvent method.

public

emit(hooks: object): Promise

Wires up life cycle methods and causes a system's emitters to emit particles. Expects emitters to have their totalEmitTimes and life set already. Inifnite systems will resolve immediately.

public

getCount(): integer

Gets a count of the total number of particles in the system.

public

Removes an emitter from the System instance.

public

removeRenderer(renderer: Renderer): System

Removes a renderer from the System instance.

public

update(delta: number): Promise

Updates the particle system based on the delta passed.

Static Public Methods

public static fromJSON(json: object, THREE: object): System source

this method was deprecated. use fromJSONAsync instead

Creates a System instance from a JSON object.

Params:

NameTypeAttributeDescription
json object

The JSON to create the System instance from

THREE object

The Web GL Api to use eg., THREE

Return:

System

public static fromJSONAsync(json: object, THREE: object, options: object): Promise<System> source

Loads a System instance from JSON asynchronously. Ensures all textures are fully loaded before resolving with the instantiated System instance.

Params:

NameTypeAttributeDescription
json object

The JSON to create the System instance from

THREE object

The Web GL Api to use eg., THREE

options object
  • nullable: true

Optional config options

Return:

Promise<System>

Public Constructors

public constructor(THREE: object, preParticles: number, integrationType: string): * source

Constructs a System instance.

Params:

NameTypeAttributeDescription
THREE object

ThreeJs

preParticles number
  • optional
  • default: POOL_MAX

The number of particles to start with

integrationType string
  • optional
  • default: INTEGRATION_TYPE_EULER

The integration type to use

Return:

*

void

Public Members

public canUpdate: boolean source

Determines if the system can update or not. Set to false when destroying to ensure that external calls to update do not throw errors.

public emitters: array<Emitter> source

The emitters in the particle system.

public eventDispatcher: EventDispatcher source

Internal event dispatcher

public integrationType: * source

The integration algorithm type to use.

public pool: Pool source

A pool used to manage the internal system cache of objects

public preParticles: number source

The number of particles to start with.

public renderers: array<Renderer> source

The renderers for the system.

public type: string source

The class type.

Public Methods

public addEmitter(emitter: Emitter): System source

Adds an emitter to the System instance. Dispatches the EMITTER_ADDED event.

Params:

NameTypeAttributeDescription
emitter Emitter

The emitter to add

Return:

System

public addRenderer(renderer: Renderer): System source

Adds a renderer to the System instance and initializes it.

Params:

NameTypeAttributeDescription
renderer Renderer

The renderer to add

Return:

System

public destroy(): * source

Destroys all emitters, renderers and the Nebula pool. Ensures that this.update will not perform any operations while the system is being destroyed.

Return:

*

void

public dispatch(event: string, target: object<System|Emitter|Particle>) source

Proxy method for the internal event dispatcher's dispatchEvent method.

Params:

NameTypeAttributeDescription
event string

The event to dispatch

target object<System|Emitter|Particle>
  • optional
  • default: this

The event target

public emit(hooks: object): Promise source

Wires up life cycle methods and causes a system's emitters to emit particles. Expects emitters to have their totalEmitTimes and life set already. Inifnite systems will resolve immediately.

Params:

NameTypeAttributeDescription
hooks object

Functions to hook into the life cycle API

hooks.onStart function

Called when the system starts to emit particles

hooks.onUpdate function

Called each time the system updates

hooks.onEnd function

Called when the system's emitters have all died

Return:

Promise

public getCount(): integer source

Gets a count of the total number of particles in the system.

Return:

integer

public removeEmitter(emitter: Emitter): System source

Removes an emitter from the System instance. Dispatches the EMITTER_REMOVED event.

Params:

NameTypeAttributeDescription
emitter Emitter

The emitter to remove

Return:

System

public removeRenderer(renderer: Renderer): System source

Removes a renderer from the System instance.

Params:

NameTypeAttributeDescription
renderer Renderer

Return:

System

public update(delta: number): Promise source

Updates the particle system based on the delta passed.

Params:

NameTypeAttributeDescription
delta number

Delta time

Return:

Promise

Example:

animate = () => {
  threeRenderer.render(threeScene, threeCamera);
  system.update();
  requestAnimationFrame(animate);
}
animate();