Cloning With the Solid Particle System
Using the Solid Particle System to Copy Meshes
There is more to the Solid Particle System (SPS) than just producing multiple copies of a mesh and these are considered in full in the Particles section. The SPS places multiple copies of a mesh all together into just one mesh. This means that instead of multiple draw calls there is just one draw call for the single mesh.
The SPS is a single updatable mesh with the same properties as any other Babylon.js mesh.
In order to produce multiple copies of a mesh you follow this script
Example :
javascript
SPS = new BABYLON.SolidParticleSystem("SPS", scene); //create the SPSconst tetra = BABYLON.MeshBuilder.CreatePolyhedron("tetra", {}); //create the meshSPS.addShape(tetra, 1500); // add as many copies as you want to the SPStetra.dispose(); //dispose of the original meshconst spsMesh = SPS.buildMesh(); //builds the SPS mesh
//Set the function to initialise the particle propertiesSPS.initParticles = () => { for (let p = 0; p < SPS.nbParticles; p++) { const particle = SPS.particles[p] particle.position.x = BABYLON.Scalar.RandomRange(-50, 50); particle.position.y = BABYLON.Scalar.RandomRange(-50, 50); particle.position.z = BABYLON.Scalar.RandomRange(-50, 50); const scale = BABYLON.Scalar.RandomRange(0.5, 1.5); particle.scale.x = scale; particle.scale.y = scale; particle.scale.z = scale;
particle.rotation.x = BABYLON.Scalar.RandomRange(0, Math.PI); particle.rotation.y = BABYLON.Scalar.RandomRange(0, Math.PI); particle.rotation.z = BABYLON.Scalar.RandomRange(0, Math.PI); }} ;
SPS.initParticles(); //call the initialising functionSPS.setParticles(); //apply the properties and display the mesh