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 : http://doc.babylonjs.com/overviews/Solid_Particle_System

Hierarchy

  • SolidParticleSystem

Implements

Index

Constructors

constructor

Find examples in Playground
  • 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: object
      • Optional bSphereRadiusFactor?: number
      • Optional boundingSphereOnly?: boolean
      • Optional enableDepthSort?: boolean
      • Optional isPickable?: boolean
      • Optional particleIntersection?: boolean
      • Optional updatable?: boolean

    Returns SolidParticleSystem

Properties

billboard

Find examples in Playground
billboard: boolean

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

computeBoundingBox

Find examples in Playground
computeBoundingBox: boolean

Gets if setParticles() computes or not the mesh bounding box when computing the particle positions.

computeParticleColor

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

computeParticleRotation

Find examples in Playground
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 setting computeParticleRotation to false will prevents the particle to rotate.

computeParticleTexture

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

computeParticleVertex

Find examples in Playground
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.

counter

Find examples in Playground
counter: number

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

depthSortParticles

Find examples in Playground
depthSortParticles: boolean

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

depthSortedParticles

Find examples in Playground
depthSortedParticles: DepthSortedParticle[]

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

isAlwaysVisible

Find examples in Playground
isAlwaysVisible: boolean

isVisibilityBoxLocked

Find examples in Playground
isVisibilityBoxLocked: boolean

Gets if the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates. doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility

mesh

Find examples in Playground
mesh: Mesh

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

name

Find examples in Playground
name: string

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

nbParticles

Find examples in Playground
nbParticles: number

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

particles

Find examples in Playground
particles: SolidParticle[]

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

pickedParticles

Find examples in Playground
pickedParticles: object[]

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. Please read : http://doc.babylonjs.com/overviews/Solid_Particle_System#pickable-particles

recomputeNormals

Find examples in Playground
recomputeNormals: boolean

Recompute normals when adding a shape

vars

Find examples in Playground
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 : http://doc.babylonjs.com/overviews/Solid_Particle_System#garbage-collector-concerns

Methods

addShape

Find examples in Playground
  • addShape(mesh: Mesh, nb: number, options?: object): number
  • Adds some particles to the SPS from the model shape. Returns the shape id. Please read the doc : http://doc.babylonjs.com/overviews/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: object

      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

      • Optional positionFunction?: any
      • Optional vertexFunction?: any

    Returns number

    the number of shapes in the system

afterUpdateParticles

Find examples in Playground
  • 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

beforeUpdateParticles

Find examples in Playground
  • 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

buildMesh

Find examples in Playground
  • 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

digest

Find examples in Playground
  • 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: object

      (optional integer, default 1) is the number of mesh facets per particle, this parameter is overriden 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

      • Optional delta?: number
      • Optional facetNb?: number
      • Optional number?: number

    Returns SolidParticleSystem

    the current SPS

dispose

Find examples in Playground
  • dispose(): void

initParticles

Find examples in Playground
  • initParticles(): void

rebuildMesh

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

    Returns SolidParticleSystem

    the SPS.

recycleParticle

Find examples in Playground

refreshVisibleSize

Find examples in Playground

setParticles

Find examples in Playground
  • 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.

    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.

setVisibilityBox

Find examples in Playground
  • setVisibilityBox(size: number): void

updateParticle

Find examples in Playground

updateParticleVertex

Find examples in Playground

Generated using TypeDoc