Making Explosions

I have been playing around with variations of this WebPU particle emitter (mostly just the smoke part).

How does this work? It appears that simply initializing values is enough to make it to work. Is there an underlying particle subroutine that these instructions activate? Conversely, how do you make the particles fade away and stop the emitter?

To answer my own question:

Instead of making the smoke fade away, I made the smoke plume progressively smaller.

In the original example, the particles are defined within the setup as smokeInstancedSprite. So I made this definition available externally. I also defined the size multiplier externally (e.g. SmkSiz) and then referenced this value in the setup.

In the variables, I added:

const smokeInstancedSprite = 0;
let SmkSiz = 40;

In the setup, I changed following lines to this:

smokeInstancedSprite = new THREE.Mesh(new THREE.PlaneGeometry(1,1),smokeNodeMaterial);
smokeInstancedSprite.scale.setScalar(SmkSiz);

The first line no longer has the leading const since it is defined externally and the second line references SmkSiz.

In the compute section, I added these instructions:

smokeInstancedSprite.scale.setScalar(SmkSiz);
if (SmkSiz) SmkSiz = SmkSiz - 0.01;
if (SmkSiz < 0) SmkSiz = 0;

The results is that the smoke plume slowly gets smaller. (Is it reducing only one particle per frame?)

Once it is down to zero, I can remove the smoke emitter from the scene. I generally do not use the scene.add command to make the smoke visible. Instead, I attach the smoke to a visible object using an object.add command. So to remove the now invisible smoke from the scene, I can use an object.remove command.

I don’t want to remove the smoke entirely from memory, since I can re-use it many times elsewhere. When I do that, I can restore the smoke to the original size by resetting the SmkSiz to the original value.

Let my know if there is a better way to do this.

Here is a CodePen example.

MORE (Jul 1)
I have modified the program to include all of the parts of the explosion in a single Explosion Group. Furthermore, the overall explosion has been modified so that you can repeat the explosion once the original explosion has died down. Or you could initialize several Explosion Groups so that one is always available when you need it.