Added SDK 0.28.0
The ParticleManager is used to create and manage GPU based particle systems.
The ParticleManager is data-driven, with particle systems represented entirely by an easily serializable ParticleArchetype description.
Warning
GPU Particle system depends on having access to at least 4 vertex texture units. This is not a required feature for WebGL conformance and must be checked for on the GraphicsDevice.
if (graphicsDevice.maxSupported("VERTEX_TEXTURE_UNITS") < 4)
{
// GPU Particle System cannot be used!
}
Summary
Create a new ParticleManager
Syntax
var particleManager = ParticleManager.create(graphicsDevice, textureManager, shaderManager);
Summary
Initialize the particle manager, this must be called before any particle systems are created using the particleManager.
Syntax
particleManager.initialize(scene, passIndex);
The passIndex for transparent renderables defined by the renderer in use.
For example, if using the DefaultRendering object, this should be set to renderer.passIndex.transparent. The pass index is used to define the ordering of draw calls so that particle systems (as a generally transparent medium) will be rendered after normal geometry, and will be z-sorted along with other transparent geometry in the Scene.
Summary
Register a particle animation object to be referenced by particle systems created by the particle manager.
Syntax
particleManager.registerParticleAnimation(definition);
The particle animation definition.
The name of the particle animation defined will be used to look up this definition when creating particle systems.
Summary
Register a particle animation system object to be referenced by particle systems created by the particle manager.
Syntax
particleManager.registerAnimationSystem(name, definition);
Summary
Register a function to be used to create a ParticleGeometry object as required by the particle manager.
Syntax
particleManager.registerGeometry(name, constructor)
Function to construct a shared geometry instance.
Function takes as parameters the GraphicsDevice and an initial particle capacity for the geometry to be created with.
Summary
Register the set of functions required to create and work with a ParticleRenderer in the particle manager.
Syntax
particleManager.registerRenderer(name, parser, compressor, loader, constructor, geometry);
A function taking as arguments a ParticleParticleBuildError object for reporting warnings and parse errors, and the compressed JSON object representing those values configurable for the renderer.
This function should verify the input JSON object for correctness, reporting warnings and errors as necessary and return the complete set of configurable options (including defaults if necessary) to be applied to an instance of this renderer.
A function taking as argument the complete set of configurable options for the renderer, and returning its minimal representation.
The parser and compressor should be inverses of each-other.
A function taking as arguments the complete set of configurable options for the renderer instance, a function to be used for loading shaders (accepting the shader path as argument) and a function to be used for loading textures (accepting the texture path as argument).
This function should invoke the provided loader functions for all shaders and textures required by the renderer, and for the specific input set of options. These functions will be processed asynchronously.
Summary
Register the set of functions required to create and work with a ParticleUpdater in the particle manager.
Syntax
particleManager.registerUpdater(name, parser, compressor, loader, constructor);
A function taking as arguments a ParticleBuildError object for reporting warnings and parse errors, and the compressed JSON object representing those values configurable for the updater.
This function should verify the input JSON object for correctness, reporting warnings and errors as necessary and return the complete set of configurable options (including defaults if necessary) to be applied to an instance of this updater.
A function taking as argument the complete set of configurable options for the updater, and returning its minimal representation.
The parser and compressor should be inverses of each-other.
A function taking as arguments the complete set of configurable options for the updater instance, a function to be used for loading shaders (accepting the shader path as argument) and a function to be used for loading textures (accepting the texture path as argument).
This function should invoke the provided loader functions for all shaders and textures required by the updater, and for the specific input set of options. These functions will be processed asynchronously.
Summary
Register the set of functions required to create and work with a ParticleSynchronizer in the particle manager.
Syntax
particleManager.registerSynchronizer(name, parser, compressor, constructor);
A function taking as arguments a ParticleBuildError object for reporting warnings and parse errors, and the compressed JSON object representing those values configurable for the synchronizer.
This function should verify the input JSON object for correctness, reporting warnings and errors as necessary and return the complete set of configurable options (including defaults if necessary) to be applied to an instance of this synchronizer.
A function taking as argument the complete set of configurable options for the synchronizer, and returning its minimal representation.
The parser and compressor should be inverses of each-other.
Summary
Register the set of functions required to create and work with a ParticleEmitter in the particle manager.
Syntax
particleManager.registerEmitter(name, parser, compressor, constructor);
A function taking as arguments a ParticleBuildError object for reporting warnings and parse errors, and the compressed JSON object representing those values configurable for the emitter. A final argument to this function is the name of all particles defined for the system archetype currently being parsed so that this function may verify emitters reference only particles defined for the system.
This function should verify the input JSON object for correctness, reporting warnings and errors as necessary and return the complete set of configurable options (including defaults if necessary) to be applied to an instance of this emitter.
A function taking as argument the complete set of configurable options for the emitter, and returning its minimal representation.
The parser and compressor should be inverses of each-other.
Summary
Compute the amount of time covered by the given particle animation in seconds.
Syntax
var lifeTime = particleManager.computeAnimationLifeTime(particleAnimationName);
Summary
Load all assets required by a particle system archetype.
This must be performed before creating a system from its archetype, and it is assumed that all required textures and shaders have completed their load before a system is created.
Syntax
particleManager.loadArchetype(archetype, onload);
Summary
Destroy all instances of an archetype, and any other generated data such as run-time packed textures and object pools. This has the effect of completely resetting the state of an archetype, so that when used to again create instances it will be as though it was never used in the past. This should be used to clean up an archetype that will no longer be used.
Note that this does not actually destroy the archetype, the archetype itself may be used again.
Syntax
particleManager.destroyArchetype(archetype);
Summary
Re-build any existing particle instances making use of the provided archetype, with the new provided archetype. This feature is not expected to be performant, but is invaluable in performing live-updates of particle systems in a world for purposes of in-game editors.
As some properties, such as particle system extents and particle capacities are immutable, this is the only way of easily effecting such changes for current systems in use.
Existing references to particle instances will remain valid, with the existing particle instance objects re-used for the replaced systems.
Emitters of the new instance will all be enabled, this is not intended for use with short-lived effects that are already created.
Syntax
particleManager.replaceArchetype(oldArchetype, newArchetype);
The old particle archetype. All instances of this archetype will be modified in-place to make use of the new archetype.
The old archetype will remain valid for further use if necessary.
Summary
Create a ParticleInstance of a particle system from its archetype.
It is assumed that this archetype has had all its required textures and shaders pre-loaded.
The emitters of the system will be enabled automatically. If a timeout is specified, then the emitters will have its timeout function called to enable the emitter as long as is necessary to have the effect come to a natural end when the instance is removed.
Syntax
var instance = particleManager.createInstance(archetype, timeout);
The amount of time this instance should exist for. Once this amount of time has passed, the instance will be automatically removed from the scene if necessary, and recycled.
This parameter should be specified for the creation of short-lived effects, the manager makes use of an internal optimized data structure for handling large numbers of short-lived effects in conjunction with the updates of the particleManager.
Summary
Destroy a ParticleInstance, removing it from the scene and releasing it for re-use by another instantiation of the same archetype.
Syntax
particleManager.destroyInstance(instance);
Summary
Destroy every instance associated with the particle particleManager.
Syntax
particleManager.clear(archetype);
Summary
Destroy the particle particleManager. This will destroy all state associated with every archetype used with this manager including all existing particle instances, and will also destroy shared texture and render target states, and release any other allocated GPU memory, ensuring all memory allocated on the CPU is released for garbage collection.
The manager nor any particle instance created with it may be used after this call.
Syntax
particleManager.destroy();
Summary
Update the particle particleManager.
This call will update the internal clock of the manager used by all created particle systems to track the passage of time, and will also be used to cull short-lived instances created in the manager automatically when required even if they are off-screen (or never made visible at all).
Syntax
particleManager.update(timeStep);
The amount of elapsed time to be added to the managers timer in seconds.
There is no need to tie this update to a fixed time-step, as this will have no effect on how the systems are updated when rendered. Any fixed time-step simulation of systems is the responsibility of individual system synchronizers.
Summary
Add the provided ParticleInstance as a child of the given scene node to the scene.
Syntax
particleManager.addInstanceToScene(instance, parent);
Summary
Remove the provided ParticleInstance from the scene.
Syntax
particleManager.removeInstanceFromScene(instance);
Summary
Compress the provided archetype, returning a minimal description from which the archetype can be recovered.
This can be used to save space when saving or transferring archetypes, and will be used when serializing an archetype.
Syntax
var description = particleManager.compressArchetype(archetype);
The particle system archetype to be compressed.
The original archetype will be left intact.
Summary
Parse a given archetype into a fully prepared object for use in manager, this allows an archetype to be specified with only those fields that are not equal to the defaults.
If parsing fails for whatever reason, then an exception will be thrown containing all reported warnings and errors for parsing stages.
To disable fail on warnings, set failOnWarnings to false on the particle manager.
Syntax
var archetype = particleManager.parseArchetype(description);
The archetype description to be parsed.
The description will be left intact, and may - if ever required - be re-used.
Summary
Serialize the provided archetype to a JSON string, this method will first compress the archetype to its minimal description.
This method can be used as a cost-efficient way of saving archetypes to file.
Syntax
var serializedString = particleManager.serializeArchetype(archetype);
The archetype to be serialized.
The archetype will be left intact for continued use.
Summary
Deserializes an archetype from its compressed JSON representation, this method will parse the archetype description into a fully prepared archetype object for use in the particleManager.
Syntax
var archetype = particleManager.deserializeArchetype(jsonString);
Summary
Gather metrics regarding the state of the particle manager and its memory usage.
Syntax
var metrics = particleManager.gatherMetrics(archetype);
The return object has fields:
The total number of ParticleInstances created is the sum of numInstances and numPooledInstances. The numAllocatedInstances is always less than or equal to numInstances, and numActiveInstances is always less than or equal to numAllocatedInstances.
Summary
Gather metrics about individual ParticleInstances.
Syntax
var metrics = particleManager.gatherInstanceMetrics(archetype);
The return value is an array of objects having the following fields:
If an instance is active, then it is also allocated.
The ParticleInstance object will be created by the ParticleManager encapsulating the state of a current system.
Summary
The ParticleRenderable created for this instance. This property will always be defined, and may be used to move/translate/scale the particle system using the renderable’s local-transform.
This renderable should not be added or removed from a Scene manually. Instead the addInstanceToScene and removeInstanceFromScene methods of the ParticleManager should be used.
Note
Read Only
Summary
The ParticleSynchronizer created for this instance. This property will always be defined, and may be used to add and remove emitters at run-time for a particular instance.
Note
Read Only
Summary
The ParticleSystem created for this instance.
This system will be lazily allocated when the instance has first become visible, and may never exist at all.
Note
Read Only