You should use nb and not nb.length for the upper bound of your loop. Also, dispose does not exist for a particle, try SPS.removeParticles(indexStart, indexEnd) instead:
However, I wasn’t able to remove the particles from the display with removeParticles, maybe @jerome will have an idea about this (I have also tested with SPS.particles[i].isVisible = false but it didn’t work neither).
If you want to remove (or add) particles from (to) an expandable SPS, you can call SPS.removeParticles(i,j) as many times that you need, then you need to tell the SPS to rebuild its geometry at least once to get the final result (it’s not recomputed each to call to removeParticles() for performance reasons).
Finally call again setParticles() to set their final positions, rotations, colors, etc.
and now its deleted all the cubes including inside and out side of the Gizmo Box, the problem is how can I deleted the cubes outside the Gizmo box, I mean I just keep the cube inside the box and deleted the cubes outside,
if you push the delete button then all the cubes removed.
don’t forget to set back the particles after the call to buildMesh() : https://www.babylonjs-playground.com/#ZEZLAT#73
I don’t know what your code is supposed to do, neither if removeParticles(i,i) is just called once or many times. Your example is quite complex.
You can find simpler examples of how removing particles works in the documentation link I posted formerly.
I just want to get the particles boundingbox and if it was in the Gizmo box boundingbox then just removing the particles outside the Gizmo box. I find an example for removing but when I testing on my code, its remove all the particles.