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:
Have an expandable and pickable SPS
Add shapes X count
Remove all but a few particles
Add 2 times X particles
Try to pick a particle
Expected:
The picked particle is selected every time
Real:
In some cases, the selection selects another particle.
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 ?
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.
I am also trying to add and remove the particles from the SPS but facing the same errors. Picking not working fine after addition or removal. Really appreciate if any one can share workaround this problem. Our whole project depends on this feature.