Class SolidParticleSystem
Implements
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
-
new SolidParticleSystem(
name: string,
scene: Scene,
options?: {
autoFixFaceOrientation?: boolean;
boundingSphereOnly?: boolean;
bSphereRadiusFactor?: number;
camera?: TargetCamera;
computeBoundingBox?: boolean;
enableDepthSort?: boolean;
enableMultiMaterial?: boolean;
expandable?: boolean;
isPickable?: boolean;
particleIntersection?: boolean;
updatable?: boolean;
useModelMaterial?: boolean;
},
): SolidParticleSystemCreates a SPS (Solid Particle System) object.
Parameters
- name: string
(String) is the SPS name, this will be the underlying mesh name.
- scene: Scene
(Scene) is the scene in which the SPS is added.
Optionaloptions: {
autoFixFaceOrientation?: boolean;
boundingSphereOnly?: boolean;
bSphereRadiusFactor?: number;
camera?: TargetCamera;
computeBoundingBox?: boolean;
enableDepthSort?: boolean;
enableMultiMaterial?: boolean;
expandable?: boolean;
isPickable?: boolean;
particleIntersection?: boolean;
updatable?: boolean;
useModelMaterial?: boolean;
}defines the options of the sps e.g.
- updatable (optional boolean, default true) : if the SPS must be updatable or immutable.
- isPickable (optional boolean, default false) : if the solid particles must be pickable.
- enableDepthSort (optional boolean, default false) : if the solid particles must be sorted in the geometry according to their distance to the camera.
- useModelMaterial (optional boolean, default false) : if the model materials must be used to create the SPS multimaterial. This enables the multimaterial supports of the SPS.
- enableMultiMaterial (optional boolean, default false) : if the solid particles can be given different materials.
- expandable (optional boolean, default false) : if particles can still be added after the initial SPS mesh creation.
- particleIntersection (optional boolean, default false) : if the solid particle intersections must be computed.
- boundingSphereOnly (optional boolean, default false) : if the particle intersection must be computed only with the bounding sphere (no bounding box computation, so faster).
- bSphereRadiusFactor (optional float, default 1.0) : a number to multiply the bounding sphere radius by in order to reduce it for instance.
- computeBoundingBox (optional boolean, default false): if the bounding box of the entire SPS will be computed (for occlusion detection, for example). If it is false, the bounding box will be the bounding box of the first particle.
- autoFixFaceOrientation (optional boolean, default false): if the particle face orientations will be flipped for transformations that change orientation (scale (-1, 1, 1), for example)
- camera (optional Camera) : the camera to use with the particule system. If not provided, use the scene active camera.
Returns SolidParticleSystem
- name: string
Properties
billboard
If the particles must ever face the camera (default false). Useful for planar particles.
counter
This a counter ofr your own usage. It's not set by any SPS functions.
depth Sorted Particles
This array is populated when enableDepthSort is set to true.
Each element of this array is an instance of the class DepthSortedParticle.
mesh
The SPS mesh. It's a standard BJS Mesh, so all the methods from the Mesh class are available.
name
The SPS name. This name is also given to the underlying mesh.
nb Particles
The SPS total number of particles. Read only. Use SPS.counter instead if you need to set your own value.
particles
The SPS array of Solid Particle objects. Just access each particle as with any classic array. Example : var p = SPS.particles[i];
picked By Sub Mesh
This array is populated when the SPS is set as 'pickable'
Each key of this array is a submesh index.
Each element of this array is a second array defined like this :
Each key of this second array is a faceId value that you can get from a pickResult object.
Each element of this second array is an object {idx: int, faceId: int}.
idx is the picked particle index in the SPS.particles array
faceId is the picked face index counted within this particle.
It's better to use the method SPS.pickedParticle(pickingInfo) rather than using directly this array.
Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/picking_sps
picked Particles
This array is populated when the SPS is set as 'pickable'.
Each key of this array is a faceId value that you can get from a pickResult object.
Each element of this array is an object {idx: int, faceId: int}.
idx is the picked particle index in the SPS.particles array
faceId is the picked face index counted within this particle.
This array is the first element of the pickedBySubMesh array : sps.pickBySubMesh[0].
It's not pertinent to use it when using a SPS with the support for MultiMaterial enabled.
Use the method SPS.pickedParticle(pickingInfo) instead.
Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/picking_sps
recompute Normals
Recompute normals when adding a shape
update Speed
The overall motion speed (0.01 is default update speed, faster updates = faster animation)
vars
This empty object is intended to store some SPS specific or temporary values in order to lower the Garbage Collector activity. Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/optimize_sps#limit-garbage-collection
Accessors
auto Update Sub Meshes
-
get autoUpdateSubMeshes(): boolean
If the subMeshes must be updated on the next call to setParticles()
Returns boolean
-
set autoUpdateSubMeshes(val: boolean): void
Parameters
- val: boolean
Returns void
compute Bounding Box
-
get computeBoundingBox(): boolean
Gets if
setParticles()computes or not the mesh bounding box when computing the particle positions.Returns boolean
-
set computeBoundingBox(val: boolean): void
Tells to
setParticles()to compute or not the mesh bounding box when computing the particle positions.Parameters
- val: boolean
Returns void
compute Particle Color
-
get computeParticleColor(): boolean
Gets if
setParticles()computes the particle colors or not. Default value : true. The SPS is faster when it's set to false. Note : the particle colors are stored values, so settingcomputeParticleColorto false will keep yet the last colors set.Returns boolean
-
set computeParticleColor(val: boolean): void
Tells to
setParticles()to compute the particle colors or not. Default value : true. The SPS is faster when it's set to false. Note : the particle colors are stored values, so settingcomputeParticleColorto false will keep yet the last colors set.Parameters
- val: boolean
Returns void
compute Particle Rotation
-
get computeParticleRotation(): boolean
Gets if
setParticles()computes the particle rotations or not. Default value : true. The SPS is faster when it's set to false. Note : the particle rotations aren't stored values, so settingcomputeParticleRotationto false will prevents the particle to rotate.Returns boolean
-
set computeParticleRotation(val: boolean): void
Tells to
setParticles()to compute the particle rotations or not. Default value : true. The SPS is faster when it's set to false. Note : the particle rotations aren't stored values, so settingcomputeParticleRotationto false will prevents the particle to rotate.Parameters
- val: boolean
Returns void
compute Particle Texture
-
get computeParticleTexture(): boolean
Gets if
setParticles()computes the particle textures or not. Default value : true. The SPS is faster when it's set to false. Note : the particle textures are stored values, so settingcomputeParticleTextureto false will keep yet the last colors set.Returns boolean
-
set computeParticleTexture(val: boolean): void
Parameters
- val: boolean
Returns void
compute Particle Vertex
-
get computeParticleVertex(): boolean
Gets if
setParticles()calls the vertex function for each vertex of each particle, or not. Default value : false. The SPS is faster when it's set to false. Note : the particle custom vertex positions aren't stored values.Returns boolean
-
set computeParticleVertex(val: boolean): void
Tells to
setParticles()to call the vertex function for each vertex of each particle, or not. Default value : false. The SPS is faster when it's set to false. Note : the particle custom vertex positions aren't stored values.Parameters
- val: boolean
Returns void
depth Sort Particles
-
get depthSortParticles(): boolean
Gets if
setParticles()sorts or not the distance between each particle and the camera. Skipped whenenableDepthSortis set tofalse(default) at construction time. Default :trueReturns boolean
-
set depthSortParticles(val: boolean): void
Tells to
setParticles()to sort or not the distance between each particle and the camera. Skipped whenenableDepthSortis set tofalse(default) at construction time. Default :trueParameters
- val: boolean
Returns void
expandable
-
get expandable(): boolean
Gets if the SPS is created as expandable at construction time. Default :
falseReturns boolean
is Always Visible
-
get isAlwaysVisible(): boolean
Gets whether the SPS as always visible or not doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
Returns boolean
-
set isAlwaysVisible(val: boolean): void
Sets the SPS as always visible or not doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
Parameters
- val: boolean
Returns void
is Visibility Box Locked
-
get isVisibilityBoxLocked(): boolean
Gets if the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates. doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
Returns boolean
-
set isVisibilityBoxLocked(val: boolean): void
Sets the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates. doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
Parameters
- val: boolean
Returns void
materials
-
The SPS used material array.
Returns Material[]
multimaterial
-
The SPS computed multimaterial object
Returns MultiMaterial
-
Parameters
- mm: MultiMaterial
Returns void
multimaterial Enabled
-
get multimaterialEnabled(): boolean
Gets if the SPS supports the Multi Materials
Returns boolean
started
-
get started(): boolean
Gets if the particle system is started
Returns boolean
stopped
-
get stopped(): boolean
Gets if the particle system is stopped
Returns boolean
use Model Material
-
get useModelMaterial(): boolean
Gets if the SPS uses the model materials for its own multimaterial.
Returns boolean
Methods
add Shape
-
addShape(
mesh: AbstractMesh,
nb: number,
options?: { positionFunction?: any; storage?: []; vertexFunction?: any },
): numberAdds some particles to the SPS from the model shape. Returns the shape id. Please read the doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/immutable_sps
Parameters
- mesh: AbstractMesh
is any Mesh object that will be used as a model for the solid particles. If the mesh does not have vertex normals, it will turn on the recomputeNormals attribute.
- nb: number
(positive integer) the number of particles to be created from this model
Optionaloptions: { positionFunction?: any; storage?: []; vertexFunction?: any }{positionFunction} is an optional javascript function to called for each particle on SPS creation. {vertexFunction} is an optional javascript function to called for each vertex of each particle on SPS creation {storage} (optional existing array) is an array where the particles will be stored for a further use instead of being inserted in the SPS.
Returns number
the number of shapes in the system
- mesh: AbstractMesh
after Update Particles
-
This will be called by
setParticles()after all the other treatments and just before the actual mesh update. This will be passed three parameters. This does nothing and may be overwritten by the user.Parameters
Optionalstart: numberthe particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
Optionalstop: numberthe particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
Optionalupdate: booleanthe boolean update value actually passed to setParticles()
Returns void
before Update Particles
-
This will be called before any other treatment by
setParticles()and will be passed three parameters. This does nothing and may be overwritten by the user.Parameters
Optionalstart: numberthe particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
Optionalstop: numberthe particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
Optionalupdate: booleanthe boolean update value actually passed to setParticles()
Returns void
build Mesh
-
Builds the SPS underlying mesh. Returns a standard Mesh. If no model shape was added to the SPS, the returned mesh is just a single triangular plane.
Returns Mesh
the created mesh
compute Sub Meshes
-
Computes the required SubMeshes according the materials assigned to the particles.
Returns SolidParticleSystem
the solid particle system. Does nothing if called before the SPS mesh is built.
digest
-
digest(
mesh: Mesh,
options?: {
delta?: number;
facetNb?: number;
number?: number;
storage?: [];
uvKind?: number;
},
): SolidParticleSystemDigests the mesh and generates as many solid particles in the system as wanted. Returns the SPS. These particles will have the same geometry than the mesh parts and will be positioned at the same localisation than the mesh original places. Thus the particles generated from
digest()have their propertypositionset yet.Parameters
- mesh: Mesh
( Mesh ) is the mesh to be digested
Optionaloptions: {
delta?: number;
facetNb?: number;
number?: number;
storage?: [];
uvKind?: number;
}{facetNb} (optional integer, default 1) is the number of mesh facets per particle, this parameter is overridden by the parameter
numberif any {delta} (optional integer, default 0) is the random extra number of facets per particle , each particle will have betweenfacetNbandfacetNb + deltafacets {number} (optional positive integer) is the wanted number of particles : each particle is built withmesh_total_facets / numberfacets {storage} (optional existing array) is an array where the particles will be stored for a further use instead of being inserted in the SPS. {uvKind} (optional positive integer, default 0) is the kind of UV to read from. Use -1 to deduce it from the diffuse/albedo texture (if any) of the mesh material
Returns SolidParticleSystem
the current SPS
- mesh: Mesh
dispose
-
Disposes the SPS.
Returns void
get Particle By Id
-
Returns a SolidParticle object from its identifier : particle.id
Parameters
- id: number
(integer) the particle Id
Returns Nullable<SolidParticle>
the searched particle or null if not found in the SPS.
- id: number
get Particles By Shape Id
-
Returns a new array populated with the particles having the passed shapeId.
Parameters
- shapeId: number
(integer) the shape identifier
Returns SolidParticle[]
a new solid particle array
- shapeId: number
get Particles By Shape Id To Ref
-
Populates the passed array "ref" with the particles having the passed shapeId.
Parameters
- shapeId: number
the shape identifier
- ref: SolidParticle[]
array to populate
Returns SolidParticleSystem
the SPS
- shapeId: number
init Particles
-
This function does nothing. It may be overwritten to set all the particle first values. The SPS doesn't call this function, you may have to call it by your own. doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles
Returns void
insert Particles From Array
-
Inserts some pre-created particles in the solid particle system so that they can be managed by setParticles().
Parameters
- solidParticleArray: SolidParticle[]
an array populated with Solid Particles objects
Returns SolidParticleSystem
the SPS
- solidParticleArray: SolidParticle[]
picked Particle
-
Returns an object {idx: number faceId: number} for the picked particle from the passed pickingInfo object. idx is the particle index in the SPS faceId is the picked face index counted within this particle. Returns null if the pickInfo can't identify a picked particle.
Parameters
- pickingInfo: PickingInfo
(PickingInfo object)
Returns Nullable<{ faceId: number; idx: number }>
or null
- pickingInfo: PickingInfo
rebuild Mesh
-
Rebuilds the whole mesh and updates the VBO : custom positions and vertices are recomputed if needed.
Parameters
- reset: boolean = false
boolean, default false : if the particles must be reset at position and rotation zero, scaling 1, color white, initial UVs and not parented.
Returns SolidParticleSystem
the SPS.
- reset: boolean = false
recycle Particle
-
This function does nothing. It may be overwritten to recycle a particle. The SPS doesn't call this function, you may have to call it by your own. doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles
Parameters
- particle: SolidParticle
The particle to recycle
Returns SolidParticle
the recycled particle
- particle: SolidParticle
refresh Visible Size
-
Visibility helper : Recomputes the visible size according to the mesh bounding box doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
Returns SolidParticleSystem
the SPS.
remove Particles
-
Removes the particles from the start-th to the end-th included from an expandable SPS (required). Returns an array with the removed particles. If the number of particles to remove is lower than zero or greater than the global remaining particle number, then an empty array is returned. The SPS can't be empty so at least one particle needs to remain in place. Under the hood, the VertexData array, so the VBO buffer, is recreated each call.
Parameters
- start: number
index of the first particle to remove
- end: number
index of the last particle to remove (included)
Returns SolidParticle[]
an array populated with the removed particles
- start: number
set Multi Material
-
Sets the SPS MultiMaterial from the passed materials. Note : the passed array is internally copied and not used then by reference.
Parameters
- materials: Material[]
an array of material objects. This array indexes are the materialIndex values of the particles.
Returns void
- materials: Material[]
set Particles
-
Sets all the particles : this method actually really updates the mesh according to the particle positions, rotations, colors, textures, etc. This method calls
updateParticle()for each particle of the SPS. For an animated SPS, it is usually called within the render loop. This methods does nothing if called on a non updatable or not yet built SPS. Example : buildMesh() not called after having added or removed particles from an expandable SPS.Parameters
- start: number = 0
The particle index in the particle array where to start to compute the particle property values (default 0)
- end: number = ...
The particle index in the particle array where to stop to compute the particle property values (default nbParticle - 1)
- update: boolean = true
If the mesh must be finally updated on this call after all the particle computations (default true)
Returns SolidParticleSystem
the SPS.
- start: number = 0
set Visibility Box
-
Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.
Parameters
- size: number
the size (float) of the visibility box note : this doesn't lock the SPS mesh bounding box. doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
Returns void
- size: number
start
-
Starts the particle system and begins to emit. This will call buildMesh(), initParticles(), setParticles() and register the update loop.
Parameters
- delay: number = 0
defines the delay in milliseconds before starting the system (0 by default)
Returns void
- delay: number = 0
stop
-
Stops the particle system.
Returns void
update Particle
-
Updates a particle : this function should be overwritten by the user. It is called on each particle by
setParticles(). This is the place to code each particle behavior. doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particlesParameters
- particle: SolidParticle
The particle to update
Returns SolidParticle
the updated particle
- particle: SolidParticle
update Particle Vertex
-
updateParticleVertex(
particle: SolidParticle,
vertex: SolidParticleVertex,
pt: number,
): SolidParticleSystemUpdates a vertex of a particle : it can be overwritten by the user. This will be called on each vertex particle by
setParticles()ifcomputeParticleVertexis set to true only.Parameters
- particle: SolidParticle
the current particle
- vertex: SolidParticleVertex
the current vertex of the current particle : a SolidParticleVertex object
- pt: number
the index of the current vertex in the particle shape doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_vertices
Returns SolidParticleSystem
the sps
- particle: SolidParticle
The SPS is a single updatable mesh. The solid particles are simply separate parts or faces of this big mesh. As it is just a mesh, the SPS has all the same properties than any other BJS mesh : not more, not less. It can be scaled, rotated, translated, enlighted, textured, moved, etc.
The SPS is also a particle system. It provides some methods to manage the particles. However it is behavior agnostic. This means it has no emitter, no particle physics, no particle recycler. You have to implement your own behavior.
Full documentation here : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_intro