12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- module BABYLON {
- /**
- * This class is made for on one-liner static method to help creating particle system set.
- */
- export class ParticleHelper {
- /**
- * Gets or sets base Assets URL
- */
- public static BaseAssetsUrl = "https://assets.babylonjs.com/particles";
- /**
- * Create a default particle system that you can tweak
- * @param emitter defines the emitter to use
- * @param capacity defines the system capacity (default is 500 particles)
- * @param scene defines the hosting scene
- * @returns the new Particle system
- */
- public static CreateDefault(emitter: Nullable<AbstractMesh | Vector3>, capacity = 500, scene?: Scene): ParticleSystem {
- var system = new ParticleSystem("default system", capacity, scene!);
-
- system.emitter = emitter;
- system.particleTexture = new Texture("https://www.babylonjs.com/assets/Flare.png", system.getScene());
- system.createConeEmitter(0.1, Math.PI / 4);
- // Particle color
- system.color1 = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
- system.color2 = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
- system.colorDead = new BABYLON.Color4(1.0, 1.0, 1.0, 0.0);
-
- // Particle Size
- system.minSize = 0.1;
- system.maxSize = 0.1;
- // Emission speed
- system.minEmitPower = 2;
- system.maxEmitPower = 2;
- // Update speed
- system.updateSpeed = 1 / 60;
- system.emitRate = 30;
- return system;
- }
- /**
- * This is the main static method (one-liner) of this helper to create different particle systems
- * @param type This string represents the type to the particle system to create
- * @param scene The scene where the particle system should live
- * @param gpu If the system will use gpu
- * @returns the ParticleSystemSet created
- */
- public static CreateAsync(type: string, scene: Nullable<Scene>, gpu: boolean = false): Promise<ParticleSystemSet> {
-
- if (!scene) {
- scene = Engine.LastCreatedScene;;
- }
- let token = {};
- scene!._addPendingData(token);
- return new Promise((resolve, reject) => {
- if (gpu && !GPUParticleSystem.IsSupported) {
- scene!._removePendingData(token);
- return reject("Particle system with GPU is not supported.");
- }
- Tools.LoadFile(`${ParticleHelper.BaseAssetsUrl}/systems/${type}.json`, (data, response) => {
- scene!._removePendingData(token);
- const newData = JSON.parse(data.toString());
- return resolve(ParticleSystemSet.Parse(newData, scene!, gpu));
- }, undefined, undefined, undefined, (req, exception) => {
- scene!._removePendingData(token);
- return reject(`An error occured while the creation of your particle system. Check if your type '${type}' exists.`);
- });
- });
- }
- /**
- * Static function used to export a particle system to a ParticleSystemSet variable.
- * Please note that the emitter shape is not exported
- * @param system defines the particle systems to export
- */
- public static ExportSet(systems: IParticleSystem[]): ParticleSystemSet {
- var set = new ParticleSystemSet();
- for (var system of systems) {
- set.systems.push(system);
- }
- return set;
- }
- }
- }
|