Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SolidParticleSystem

The SPS is a single updatable mesh. The solid particles are simply separate parts or faces fo 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/how_to/Solid_Particle_System

Hierarchy

  • SolidParticleSystem

Implements

Index

Constructors

constructor

  • new SolidParticleSystem(name: string, scene: Scene, options?: { bSphereRadiusFactor?: number; boundingSphereOnly?: boolean; enableDepthSort?: boolean; enableMultiMaterial?: boolean; expandable?: boolean; isPickable?: boolean; particleIntersection?: boolean; updatable?: boolean; useModelMaterial?: boolean }): SolidParticleSystem
  • Creates a SPS (Solid Particle System) object.

    example

    bSphereRadiusFactor = 1.0 / Math.sqrt(3.0) => the bounding sphere exactly matches a spherical mesh.

    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.

    • Optional options: { bSphereRadiusFactor?: number; boundingSphereOnly?: 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.
      • Optional bSphereRadiusFactor?: number
      • Optional boundingSphereOnly?: boolean
      • Optional enableDepthSort?: boolean
      • Optional enableMultiMaterial?: boolean
      • Optional expandable?: boolean
      • Optional isPickable?: boolean
      • Optional particleIntersection?: boolean
      • Optional updatable?: boolean
      • Optional useModelMaterial?: boolean

    Returns SolidParticleSystem

Properties

billboardSearch playground for billboard

billboard: boolean

If the particles must ever face the camera (default false). Useful for planar particles.

counterSearch playground for counter

counter: number

This a counter ofr your own usage. It's not set by any SPS functions.

depthSortedParticlesSearch playground for depthSortedParticles

depthSortedParticles: DepthSortedParticle[]

This array is populated when enableDepthSort is set to true. Each element of this array is an instance of the class DepthSortedParticle.

meshSearch playground for mesh

mesh: Mesh

The SPS mesh. It's a standard BJS Mesh, so all the methods from the Mesh class are available.

nameSearch playground for name

name: string

The SPS name. This name is also given to the underlying mesh.

nbParticlesSearch playground for nbParticles

nbParticles: number

The SPS total number of particles. Read only. Use SPS.counter instead if you need to set your own value.

particlesSearch playground for particles

particles: SolidParticle[]

The SPS array of Solid Particle objects. Just access each particle as with any classic array. Example : var p = SPS.particles[i];

pickedBySubMeshSearch playground for pickedBySubMesh

pickedBySubMesh: { faceId: number; idx: number }[][]

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/how_to/Solid_Particle_System#pickable-particles

pickedParticlesSearch playground for pickedParticles

pickedParticles: { faceId: number; idx: number }[]

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/how_to/Solid_Particle_System#pickable-particles

recomputeNormalsSearch playground for recomputeNormals

recomputeNormals: boolean

Recompute normals when adding a shape

varsSearch playground for vars

vars: any

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/how_to/Solid_Particle_System#garbage-collector-concerns

Accessors

autoUpdateSubMeshes

  • get autoUpdateSubMeshes(): boolean
  • set autoUpdateSubMeshes(val: boolean): any
  • If the subMeshes must be updated on the next call to setParticles()

    Returns boolean

  • If the subMeshes must be updated on the next call to setParticles()

    Parameters

    • val: boolean

    Returns any

computeBoundingBox

  • get computeBoundingBox(): boolean
  • set computeBoundingBox(val: boolean): any
  • Gets if setParticles() computes or not the mesh bounding box when computing the particle positions.

    Returns boolean

  • Tells to setParticles() to compute or not the mesh bounding box when computing the particle positions.

    Parameters

    • val: boolean

    Returns any

computeParticleColor

  • get computeParticleColor(): boolean
  • set computeParticleColor(val: boolean): any
  • 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 setting computeParticleColor to false will keep yet the last colors set.

    Returns boolean

  • 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 setting computeParticleColor to false will keep yet the last colors set.

    Parameters

    • val: boolean

    Returns any

computeParticleRotation

  • get computeParticleRotation(): boolean
  • set computeParticleRotation(val: boolean): any
  • 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 setting computeParticleRotation to false will prevents the particle to rotate.

    Returns boolean

  • 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 setting computeParticleRotation to false will prevents the particle to rotate.

    Parameters

    • val: boolean

    Returns any

computeParticleTexture

  • get computeParticleTexture(): boolean
  • set computeParticleTexture(val: boolean): any
  • 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 setting computeParticleTexture to false will keep yet the last colors set.

    Returns 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 setting computeParticleTexture to false will keep yet the last colors set.

    Parameters

    • val: boolean

    Returns any

computeParticleVertex

  • get computeParticleVertex(): boolean
  • set computeParticleVertex(val: boolean): any
  • 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

  • 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 any

depthSortParticles

  • get depthSortParticles(): boolean
  • set depthSortParticles(val: boolean): any
  • Gets if setParticles() sorts or not the distance between each particle and the camera. Skipped when enableDepthSort is set to false (default) at construction time. Default : true

    Returns boolean

  • Tells to setParticles() to sort or not the distance between each particle and the camera. Skipped when enableDepthSort is set to false (default) at construction time. Default : true

    Parameters

    • val: boolean

    Returns any

expandable

  • get expandable(): boolean
  • Gets if the SPS is created as expandable at construction time. Default : false

    Returns boolean

isAlwaysVisible

  • get isAlwaysVisible(): boolean
  • set isAlwaysVisible(val: boolean): any

isVisibilityBoxLocked

  • get isVisibilityBoxLocked(): boolean
  • set isVisibilityBoxLocked(val: boolean): any

materials

  • The SPS used material array.

    Returns Material[]

multimaterial

  • The SPS computed multimaterial object

    Returns MultiMaterial

  • The SPS computed multimaterial object

    Parameters

    Returns any

multimaterialEnabled

  • get multimaterialEnabled(): boolean
  • Gets if the SPS supports the Multi Materials

    Returns boolean

useModelMaterial

  • get useModelMaterial(): boolean
  • Gets if the SPS uses the model materials for its own multimaterial.

    Returns boolean

Methods

addShapeSearch playground for addShape

  • addShape(mesh: Mesh, nb: number, options?: { positionFunction?: any; storage?: []; vertexFunction?: any }): number
  • Adds some particles to the SPS from the model shape. Returns the shape id. Please read the doc : https://doc.babylonjs.com/how_to/Solid_Particle_System#create-an-immutable-sps

    Parameters

    • mesh: Mesh

      is any Mesh object that will be used as a model for the solid particles.

    • nb: number

      (positive integer) the number of particles to be created from this model

    • Optional options: { positionFunction?: any; storage?: []; vertexFunction?: any }

      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.

      • Optional positionFunction?: any
      • Optional storage?: []
      • Optional vertexFunction?: any

    Returns number

    the number of shapes in the system

afterUpdateParticlesSearch playground for afterUpdateParticles

  • afterUpdateParticles(start?: number, stop?: number, update?: boolean): void
  • 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

    • Optional start: number

      the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()

    • Optional stop: number

      the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()

    • Optional update: boolean

      the boolean update value actually passed to setParticles()

    Returns void

beforeUpdateParticlesSearch playground for beforeUpdateParticles

  • beforeUpdateParticles(start?: number, stop?: number, update?: boolean): void
  • 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

    • Optional start: number

      the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()

    • Optional stop: number

      the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()

    • Optional update: boolean

      the boolean update value actually passed to setParticles()

    Returns void

buildMeshSearch playground for buildMesh

  • 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

computeSubMeshesSearch playground for computeSubMeshes

  • 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.

digestSearch playground for digest

  • digest(mesh: Mesh, options?: { delta?: number; facetNb?: number; number?: number; storage?: [] }): SolidParticleSystem
  • Digests 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 property position set yet.

    Parameters

    • mesh: Mesh

      ( Mesh ) is the mesh to be digested

    • Optional options: { delta?: number; facetNb?: number; number?: number; storage?: [] }

      (optional integer, default 1) is the number of mesh facets per particle, this parameter is overridden by the parameter number if any {delta} (optional integer, default 0) is the random extra number of facets per particle , each particle will have between facetNb and facetNb + delta facets {number} (optional positive integer) is the wanted number of particles : each particle is built with mesh_total_facets / number facets {storage} (optional existing array) is an array where the particles will be stored for a further use instead of being inserted in the SPS.

      • Optional delta?: number
      • Optional facetNb?: number
      • Optional number?: number
      • Optional storage?: []

    Returns SolidParticleSystem

    the current SPS

disposeSearch playground for dispose

  • dispose(): void
  • Disposes the SPS.

    Returns void

getParticleByIdSearch playground for getParticleById

  • 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.

getParticlesByShapeIdSearch playground for getParticlesByShapeId

  • 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

getParticlesByShapeIdToRefSearch playground for getParticlesByShapeIdToRef

  • Populates the passed array "ref" with the particles having the passed shapeId.

    Parameters

    Returns SolidParticleSystem

    the SPS

initParticlesSearch playground for initParticles

  • initParticles(): void

insertParticlesFromArraySearch playground for insertParticlesFromArray

  • 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

pickedParticleSearch playground for pickedParticle

  • 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

    Returns Nullable<{ faceId: number; idx: number }>

    or null

rebuildMeshSearch playground for rebuildMesh

  • Rebuilds the whole mesh and updates the VBO : custom positions and vertices are recomputed if needed.

    Parameters

    • Optional reset: boolean

      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.

recycleParticleSearch playground for recycleParticle

refreshVisibleSizeSearch playground for refreshVisibleSize

removeParticlesSearch playground for removeParticles

  • 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

setMultiMaterialSearch playground for setMultiMaterial

  • setMultiMaterial(materials: Material[]): void
  • 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

setParticlesSearch playground for setParticles

  • 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

    • Optional start: number

      The particle index in the particle array where to start to compute the particle property values (default 0)

    • Optional end: number

      The particle index in the particle array where to stop to compute the particle property values (default nbParticle - 1)

    • Optional update: boolean

      If the mesh must be finally updated on this call after all the particle computations (default true)

    Returns SolidParticleSystem

    the SPS.

setVisibilityBoxSearch playground for setVisibilityBox

  • setVisibilityBox(size: number): void
  • Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.

    Parameters

    Returns void

updateParticleSearch playground for updateParticle

updateParticleVertexSearch playground for updateParticleVertex

Legend

  • Constructor
  • Property
  • Method
  • Accessor
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method