I have some cubes and Gizmo box, and I want to deleted the cubes inside the Gizmo box.
I use following code for my deleted button:
selectInButton.onPointerClickObservable.add(function () {
//force any transformations
boxG.computeWorldMatrix(true);
for (let i = 0; i < nb.length; i++) {
let inX =
boxG.getBoundingInfo().boundingBox.minimumWorld.x <
SPS.particles[i]._boundingInfo.boundingBox.minimumWorld.x &&
SPS.particles[i]._boundingInfo.boundingBox.maximumWorld.x <
boxG.getBoundingInfo().boundingBox.maximumWorld.x;
let inY =
boxG.getBoundingInfo().boundingBox.minimumWorld.y <
SPS.particles[i]._boundingInfo.boundingBox.minimumWorld.y &&
SPS.particles[i]._boundingInfo.boundingBox.maximumWorld.y <
boxG.getBoundingInfo().boundingBox.maximumWorld.y;
let inZ =
boxG.getBoundingInfo().boundingBox.minimumWorld.z <
SPS.particles[i]._boundingInfo.boundingBox.minimumWorld.z &&
SPS.particles[i]._boundingInfo.boundingBox.maximumWorld.z <
boxG.getBoundingInfo().boundingBox.maximumWorld.z;
let inside = inX && inY && inZ;
if (inside == false) {
SPS.particles[i].dispose();
}
}
});
but the problem is when I push the delete button, the cubes didn’t deleted, but I don’t know what is the problem. is it possible help me to solve it
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.
now on the console everything is ok, I read all the document, but I cannot understand why all the cubes remove from the screen, but as can be seen in the console , 8 cube should remain on the screen.