Expandable and pickable SPS fails picking after multiple adding and removing of particles

Hello,

I am using Babylon SPS to add and remove particles that are pickable, in most cases, it works great.
However, in the following scenario, it starts to mess up the pickedParticles array and picking becomes unreliable (some particles are pickable some are not).

The steps to reproduce are as follows:

  1. Have an expandable and pickable SPS
  2. Add shapes X count
  3. Remove all but a few particles
  4. Add 2 times X particles
  5. Try to pick a particle

Expected:
The picked particle is selected every time
Real:
In some cases, the selection selects another particle.

Demo: https://www.babylonjs-playground.com/#JKRLKH#1 (try to pick more than one particle *some work OK)

I have not yet tried to fix the bug, I think I will have some time this weekend to try and fix it.

Pinging the Boss of SPS @jerome

It really looks like a bug …I was convicted to have fixed it already, grrrr. I’ll have a look, but please don’t expect me to be fast at these times.

1 Like

Of course, it is not a very big problem, at the moment I can detect the bug and recreate the whole SPS when it happens, and I am using relatively small SPS instances so I can update them quickly. This might be a good feature for the SPS, having several meshes for performance reasons when updating.
My use case has 50K particles that need to update their color and sometimes to be deleted and added all in real-time (60FPS). And I am just using several SPS instances for that and it is working pretty nice.

Thank you very much for the quick answer. I will try to dig deeper this weekend and hopefully send a pull request.

Actually the current way of doing should be now by using the method .pickedParticle(pickingInfo) :

scene.onPointerDown = function(evt, pickResult) {
  var meshFaceId = pickResult.faceId; // get the mesh picked face
  if (meshFaceId == -1) {
    return;
  } // return if nothing picked
  var picked = SPS.pickedParticle(pickResult); // get the picked particle data : idx and faceId
  var idx = picked.idx;                         
  var p = SPS.particles[idx];                   // get the actual picked particle
  p.color.r = 1; // turn it red
  p.color.b = 0;
  p.color.g = 0;
  p.velocity.y = -1; // drop it
  SPS.setParticles();
};

This method was added to deal correctly with the multimaterial picked particles. Maybe this broke the adding/removal particle picking ?

Hi,

I tried with SPS.pickedParticle(pickResult),

Unfortunately the same result.

The demo is updated to use the method.

ooops… I just forgot to write in my former post that it was the same (wrong) result …

No problem,

You can see the pickedParticles array in the console now in the demo it becomes 2K elements although having just 500 particles, this is what I am using as a flag that I need to recreate the SPS atm.

Working on it …

2 Likes

Fix submitted.

1 Like

Thank you very much!

and merged!

1 Like