Solid Particle Animation
To animate the particles, you need to reset and draw them on each render cycle, for example with
scene.onBeforeRenderObservable.add(() => { SPS.setParticles();})As mentioned previously, all solid particle behaviors have to be implemented by you. This includes using billboard mode. You can set it using
SPS.billboard = true; //false by defaultThe required rotation for the mesh to face the camera has to be calculated on each render frame, so the render loop above needs to be added.
Billboard set to true, comment line 35 for false: Solid Particle Billboards
To animate solid particles, their properties have to be updated frame by frame during rendering. To do this, you need to code a custom myUpdateParticle(particle). You can then set
SPS.updateParticle = myUpdateParticleThis is sufficient because setParticles calls updateParticle.
Let's make some tetrahedrons bounce up and down. We use a cosine function to produce varying heights.
let y = h * (1 + Math.cos(angle))will give y from 0 to 2h as the angle varies.
Bouncing tetrahedrons: Bouncing Tetrahedrons Bouncing tetrahedrons SPS mesh rotating: Bouncing Tetrahedrons With Meshes Rotating
Another very useful custom function is recycle(particle), which you call from updateParticle under some condition, for example
const updateParticle = (particle) => { if (particle condition) { recycleParticle(particle) } doUpdate(particle);}A fountain of recycled tetrahedra: A Fountain Of Recycled Tetrahedra
Before moving much further, it is time to bring together in one place all the features for managing the SPS and its particles.