API

Picking Solid Particles

Pickable Particles

You can make your particles pickable by using the isPickable parameter (default false) when creating your SPS:

import { SolidParticleSystem } from "@babylonjs/core/Particles/solidParticleSystem";
var SPS = new SolidParticleSystem("SPS", scene, { isPickable: true });

This sets the underlying mesh as pickable and populates two arrays called SPS.pickedParticles and SPS.pickebBySubMesh. So don't set your SPS as pickable if you don't need it to be, as this saves a lot of memory.
To retrieve the particle picking data from these arrays, use the method SPS.pickedParticle(pickingInfo), which returns an object with these properties:

  • idx : the picked particle idx
  • faceId : the face index of the picked particle (counted within this particle)

Example :

import { SolidParticleSystem } from "@babylonjs/core/Particles/solidParticleSystem";
var SPS = new SolidParticleSystem("SPS", scene, { isPickable: true });
// add shapes, build the mesh, init particles, etc
SPS.setParticles(); // initial SPS draw
SPS.refreshVisibleSize(); // force the BBox recomputation
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();
};

SPS pickability is directly related to the size of its bounding box (please read the 'SPS Visibility' part). So, to make sure your particles are pickable, remember to force the bounding box size to be recomputed at least once after the particles have been positioned in space with setParticles().
Pickable particle example (no SPS update in the render loop): Pickable Solid Particles Example Pickable particle example (particle rotation): Pickable Solid Particles That Rotate