Expandable Solid Particle System

Wuuuuut!!! This one is definitely an expected one!

1 Like

Usage

    var sps = new BABYLON.SolidParticleSystem("sps", scene, {expandable: true});
    var model = BABYLON.MeshBuilder.CreateBox("m", {}, scene);
    sps.addShape(model, 1000);
    sps.buildMesh();

     // ... further in the code
    sps.removeParticles(700, 999);  // removes the last 300 particles
    sps.removeParticles(0, 9);      // then removes the first 10
    sps.buildMesh();                // like for adding particles after the sps creation,
                                    // the call to buildMesh() is required

Documentation and PG example to come soon

2 Likes

PG (once the build is merged) : Babylon.js Playground
Each click removes the 100 first and 2 last particles from the SPS until it remains less than 102 ones.
Open the console to check the remaining number.

1 Like

Rock and roll!

1 Like

yeah, its online :slight_smile:
https://playground.babylonjs.com/#0MXVDK

click to remove the particles

2 Likes

You rock !!!

1 Like

Still two features to add to the expandable SPS and it will be done (before writting the doc, my favorite part :unamused: )
I think then it will maybe be usable to build some simple vortex engine or some dynamic maze generator.

2 Likes

Upcoming two last features of the expandable SPS

  • the user can now generate particles and store them aside for a further use
  • formerly stored or removed particles can be inserted back in the SPS on demand
// let's create an expandable SPS
var stock = [];
var sps = new BABYLON.SolidParticleSystem("sps", scene, {expandable: true});
sps.addShape(boxes, 1000);   // let's add 1000 boxes
sps.addShape(sphere, 500, {storage: stock});  // let's store the 500 spheres aside in the stock array
sps.buildMesh();

// farther in the code, let's remove 500 boxes from the SPS
var removed = sps.removeParticles(0, 499);
sps.buildMesh();

// farther again, let's restore the spheres and the removed boxes
sps.insertParticlesFromArray(stock);
sps.insertParticlesFromArray(removed);
sps.buildMesh();
5 Likes

documented with examples : Solid Particle System - Babylon.js Documentation

btw, I like this very fast doc building process : PR done less than 1hour before and doc already online :slight_smile:

2 Likes

dynamic test https://playground.babylonjs.com/#X1T859#3
Every 3 frames, a new particle is cloned from a stock array and inserted in the SPS until it reaches 300 particles, then they are removed one by one, then re-inserted one by one and so on…
As you can see on the FPS meter, the removal process consumes more CPU than the addition one, what is expected because a removal is a deletion AND a recreation (so insertion) process.
This test shows how the underlying memory allocations and collections behave (quite well on my machine).

It looks like it still remains a tiny bug on the normals in the insertion process … investigating.
[EDIT] the same using addShape() instead of insertParticlesFromArray() working as well https://playground.babylonjs.com/#X1T859#4

1 Like

ok, bug found and fix pushed

I’ve just had an idea about another (long time requested) feature to add to the SPS to keep its rank in the friendly competition wtih CPU/GPU particles and instances.
Not sure that I will be able to achieve it though but implementation ideas start to come to my mind. I’ll probably give a try in the next weeks.

Would you buy a MultiMaterial SPS ? :wink:

2 Likes

Oh yeah!

May I ask what will MultiMaterial brings to the table ? I am using SPS a lot as it is one of the best things in the world (lot of meshes could be merged into one while remains movable).

I am currently using material with texture that cointains many “subtextures” and for each particle I just set proper UVS for each particle and it works perfectly.

How it will differ with multimaterial option available ? It will allow to set different material properties for each of the “submaterials” ? If so, it would be certainly great because at the moment all of my “subtextures” off course share the same material properties.

The way you’re using the SPS is actually the right way to do when using a single material and parts of a single texture.

Now let’s imagine that we want to manage some particles with, say, a standard material with a texture, some others with a standard material and a bump texture and some more others with a PBR materials.
The support of the MultiMaterial will allow to have, say, 300 particles of each of those three different materials, so 900 particles mixed together, and rendered with minimum possible number of draw calls (so 3 or 4 in total according to each material specification).
Of course, the subtextures will go on working, even, with MultiMaterials, so you’ll be able to use both features together :wink:

[EDIT] just because you asked about it MultiMaterial Solid Particle System

1 Like

That is what I call customer support!!!

1 Like

:smile:

Thanx very much for this information. Basically at this moment I need to create 3 SPS to achieve the same result that I would have with that multimaterial (from your example) right ?

I have one more question related to SPS if I may … and maybe you will kill me outright and tell me that SPS shall not be used that way but I would like to know if there is some possibility to bind SPS particle to the bone of animated mesh - I will explain why.

Lets imagine scenario where you have like 20 orcs on the screen … and these orcs are all the same but they have different weapons - lets say sword, axe, spear, club, knife. Right now I have to use instances so there is one “core” mesh for each weapon type and as many instances as needed.

It still means 5 draw calls (one for each weapon type) but if I could position SPS particles properly to animated orc, I could have SPS that would contain all weapon types and thus only 1 draw call. I believe that binding mesh to the bone is just about positioning so seems not to be completely impossible to acheive with SPS :))

The same could be applied to parts of armor … in reality it could save lot of draw calls :slight_smile:

Thanx for not killing me outright ! :slight_smile:

1 Like

arf, no worry
For now (and because I don’t know anything about them), there’s no bones support in the SPS. The thing that closes the most to bones is the particle parenting and particle pivot used together.

And you’re right : you can now do with 1 SPS what you used to do with 3 ones.
The number of draw calls depends directly on the number of used materials : one at least for a standard material, can be more for some more sophisticated effects.

1 Like

LIKE: that!

TOPIC: particles to make enemy?

PSEUDO CODE…

  • init: LOOP PARTICLE INSTANCES,

  • bone.position.copyFrom(inst.pos)

  • inst.parent = bone.

  • “stash” - bone.pos, rots.

  • runtime: transform bones, *

  • update sps position automatically by parent? **


deleted a bunch of txt on LookAt between particles, with groups to create little animals… stuff like that.
thx!

:partying_face:

:eagle: : )

1 Like