@Alex -
Sounds like you youāve got a plan. However, I do not recommend keeping emitters and particle systems in your scene any longer than while it is emitting particles. There are exceptions of course, but I find that I can manage memory and optimize my scene much better if I dispose of emitters and particle systems when not in use. This is a much cleaner way to manage your scene and your resources. Itās a practice that I donāt personally see utilized enough. And I doubt most developers are in the habit of disposing of elements when not in use.
@Wingnut -
I get what you are referring to, as a scene might require multiple emitters depending on varying particle systems. But this generally does not require defining multiple particle systems; unless your scene requires multiple unique particle systems due to dramatic changes. Otherwise it is a waste of resources to define the same particle system more than once.
One modification to particle systems that I might recommend is that I often set the lifetime and other settings with variables so that I can control these values based upon the desired display time. So if you make the settings dynamic, you can use the same particle system and display different results using multiple emitters. Particle systems are already defined in a range between values, and you can expand this further if you set these values with variables. I often use random number generators as well to generate different display values using the same defined particle system. This way, I generally donāt need to define a particle system more than once⦠and I simply call these with a function when theyāre needed in my scene. Then once the emitter is inactive, Iāll almost always dispose of the emitter and particle system to save on memory and GPU. I find that this provides me with a substantial boost in frame rate. Otherwise I find my frame rate lowered if the emitters and systems remain in the scene. So do a test - dispose of your emitters and particle systems and watch your frame rate immediately climb.
Galen
For reference⦠below is a typical particle system and function which calls the system that I generally copy into a scene to get me started ā
export const generateSadContrails = (rootNode, scene) => {
const ConTrailSad = BABYLON.MeshBuilder.CreateCylinder(āConTrailSadā, {
diameterBottom: 0.48, diameterTop: 0, height: 1.5, tessellation: 30
}, scene);
ConTrailSad.rotation.x = -Math.PI / 2;
ConTrailSad.position.x = -0.5;
ConTrailSad.position.z = -3.3;
ConTrailSad.position.y = -100;
ConTrailSad.visibility = 0;
ConTrailSad.parent = rootNode;
// Sad Con Trail particle system
const ConParticleS = new BABYLON.ParticleSystem(āConParticleSā, 400, scene);
ConParticleS.particleTexture = new BABYLON.Texture(ā./Demos/images/flare.pngā, scene);
ConParticleS.emitter = ConTrailSad;
ConParticleS.minEmitBox = new BABYLON.Vector3(0.5, 1, 0.5);
ConParticleS.maxEmitBox = new BABYLON.Vector3(0.5, -1, 0.5);
ConParticleS.color1 = new BABYLON.Color4(0.1, 0.1, 0.1, 1.0);
ConParticleS.color2 = new BABYLON.Color4(0.2, 0.2, 0.2, 1.0);
ConParticleS.colorDead = new BABYLON.Color4(0.2, 0.2, 0.2, 0.0);
ConParticleS.minSize = 0.3;
ConParticleS.maxSize = 1.5;
ConParticleS.minLifeTime = 0.01;
ConParticleS.maxLifeTime = Math.random() * (0.1 - 0.01) + 0.01;
ConParticleS.emitRate = 200;
ConParticleS.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE;
ConParticleS.gravity = new BABYLON.Vector3(0, 0, 0);
ConParticleS.direction1 = new BABYLON.Vector3(0, 0, 0);
ConParticleS.minAngularSpeed = 0;
ConParticleS.maxAngularSpeed = Math.PI;
ConParticleS.minEmitPower = 0.1;
ConParticleS.maxEmitPower = 1;
ConParticleS.updateSpeed = 0.005;
ConParticleS.start();
};