Class ParticleEmitter

All Implemented Interfaces:
HasLocalTransform, CloneableSmartAsset, Collidable, Savable, JmeCloneable, Cloneable

public class ParticleEmitter extends Geometry
ParticleEmitter is a special kind of geometry which simulates a particle system.

Particle emitters can be used to simulate various kinds of phenomena, such as fire, smoke, explosions and much more.

Particle emitters have many properties which are used to control the simulation. The interpretation of these properties depends on the ParticleInfluencer that has been assigned to the emitter via setParticleInfluencer(com.jme3.effect.influencers.ParticleInfluencer). By default, the DefaultParticleInfluencer implementation is used.

  • Constructor Details

    • ParticleEmitter

      public ParticleEmitter(String name, ParticleMesh.Type type, int numParticles)
    • ParticleEmitter

      protected ParticleEmitter()
      For serialization only. Do not use.
  • Method Details

    • clone

      public ParticleEmitter clone()
      Description copied from class: Geometry
      This version of clone is a shallow clone, in other words, the same mesh is referenced as the original geometry. Exception: if the mesh is marked as being a software animated mesh, (bind pose is set) then the positions and normals are deep copied.
      Specified by:
      clone in interface CloneableSmartAsset
      Overrides:
      clone in class Geometry
      Returns:
      A clone of this Spatial, the scene graph in its entirety is cloned and can be altered independently of the original scene graph. Note that meshes of geometries are not cloned explicitly, they are shared if static, or specially cloned if animated.
      See Also:
    • clone

      public ParticleEmitter clone(boolean cloneMaterial)
      Description copied from class: Geometry
      This version of clone is a shallow clone, in other words, the same mesh is referenced as the original geometry. Exception: if the mesh is marked as being a software animated mesh, (bind pose is set) then the positions and normals are deep copied.
      Overrides:
      clone in class Geometry
      Parameters:
      cloneMaterial - true to clone materials, false to share them
      Returns:
      A clone of this Spatial, the scene graph in its entirety is cloned and can be altered independently of the original scene graph. Note that meshes of geometries are not cloned explicitly, they are shared if static, or specially cloned if animated.
      See Also:
    • oldClone

      public ParticleEmitter oldClone(boolean cloneMaterial)
      The old clone() method that did not use the new Cloner utility.
      Overrides:
      oldClone in class Spatial
      Parameters:
      cloneMaterial - ignored
      Returns:
      never
    • cloneFields

      public void cloneFields(Cloner cloner, Object original)
      Called internally by com.jme3.util.clone.Cloner. Do not call directly.
      Specified by:
      cloneFields in interface JmeCloneable
      Overrides:
      cloneFields in class Geometry
      Parameters:
      cloner - The cloner that is performing the cloning operation. The cloneFields method can call back into the cloner to make clones of its subordinate fields.
      original - The original object from which this object was cloned. This is provided for the very rare case that this object needs to refer to its original for some reason. In general, all of the relevant values should have been transferred during the shallow clone, and this object need only clone what it wants.
    • setShape

      public void setShape(EmitterShape shape)
    • getShape

      public EmitterShape getShape()
    • setParticleInfluencer

      public void setParticleInfluencer(ParticleInfluencer particleInfluencer)
      Set the ParticleInfluencer to influence this particle emitter.
      Parameters:
      particleInfluencer - the ParticleInfluencer to influence this particle emitter.
      See Also:
    • getParticleInfluencer

      public ParticleInfluencer getParticleInfluencer()
      Returns the ParticleInfluencer that influences this particle emitter.
      Returns:
      the ParticleInfluencer that influences this particle emitter.
      See Also:
    • getMeshType

      public ParticleMesh.Type getMeshType()
      Returns the mesh type used by the particle emitter.
      Returns:
      the mesh type used by the particle emitter.
      See Also:
    • setMeshType

      public void setMeshType(ParticleMesh.Type meshType)
      Sets the type of mesh used by the particle emitter.
      Parameters:
      meshType - The mesh type to use
    • isInWorldSpace

      public boolean isInWorldSpace()
      Returns true if particles should spawn in world space.
      Returns:
      true if particles should spawn in world space.
      See Also:
    • setInWorldSpace

      public void setInWorldSpace(boolean worldSpace)
      Set to true if particles should spawn in world space.

      If set to true and the particle emitter is moved in the scene, then particles that have already spawned won't be affected by this motion. If set to false, the particles will emit in local space and when the emitter is moved, so are all the particles that were emitted previously.

      Parameters:
      worldSpace - true if particles should spawn in world space.
    • getNumVisibleParticles

      public int getNumVisibleParticles()
      Returns the number of visible particles (spawned but not dead).
      Returns:
      the number of visible particles
    • setNumParticles

      public final void setNumParticles(int numParticles)
      Set the maximum amount of particles that can exist at the same time with this emitter. Calling this method many times is not recommended.
      Parameters:
      numParticles - the maximum amount of particles that can exist at the same time with this emitter.
    • getMaxNumParticles

      public int getMaxNumParticles()
    • getParticles

      public Particle[] getParticles()
      Returns a list of all particles (shouldn't be used in most cases).

      This includes both existing and non-existing particles. The size of the array is set to the numParticles value specified in the constructor or setNumParticles(int) method.

      Returns:
      a list of all particles.
    • getFaceNormal

      public Vector3f getFaceNormal()
      Get the normal which particles are facing.
      Returns:
      the normal which particles are facing.
      See Also:
    • setFaceNormal

      public void setFaceNormal(Vector3f faceNormal)
      Sets the normal which particles are facing.

      By default, particles will face the camera, but for some effects (e.g. shockwave) it may be necessary to face a specific direction instead. To restore normal functionality, provide null as the argument for faceNormal.

      Parameters:
      faceNormal - The normals particles should face, or null if particles should face the camera.
    • getRotateSpeed

      public float getRotateSpeed()
      Returns the rotation speed in radians/sec for particles.
      Returns:
      the rotation speed in radians/sec for particles.
      See Also:
    • setRotateSpeed

      public void setRotateSpeed(float rotateSpeed)
      Set the rotation speed in radians/sec for particles spawned after the invocation of this method.
      Parameters:
      rotateSpeed - the rotation speed in radians/sec for particles spawned after the invocation of this method.
    • isRandomAngle

      public boolean isRandomAngle()
      Returns true if every particle spawned should have a random facing angle.
      Returns:
      true if every particle spawned should have a random facing angle.
      See Also:
    • setRandomAngle

      public void setRandomAngle(boolean randomAngle)
      Set to true if every particle spawned should have a random facing angle.
      Parameters:
      randomAngle - if every particle spawned should have a random facing angle.
    • isSelectRandomImage

      public boolean isSelectRandomImage()
      Returns true if every particle spawned should get a random image.
      Returns:
      True if every particle spawned should get a random image.
      See Also:
    • setSelectRandomImage

      public void setSelectRandomImage(boolean selectRandomImage)
      Set to true if every particle spawned should get a random image from a pool of images constructed from the texture, with X by Y possible images.

      By default, X and Y are equal to 1, thus allowing only 1 possible image to be selected, but if the particle is configured with multiple images by using setImagesX(int) and {#link ParticleEmitter#setImagesY(int) } methods, then multiple images can be selected. Setting to false will cause each particle to have an animation of images displayed, starting at image 1, and going until image X*Y when the particle reaches its end of life.

      Parameters:
      selectRandomImage - True if every particle spawned should get a random image.
    • isFacingVelocity

      public boolean isFacingVelocity()
      Check if particles spawned should face their velocity.
      Returns:
      True if particles spawned should face their velocity.
      See Also:
    • setFacingVelocity

      public void setFacingVelocity(boolean followVelocity)
      Set to true if particles spawned should face their velocity (or direction to which they are moving towards).

      This is typically used for e.g. spark effects.

      Parameters:
      followVelocity - True if particles spawned should face their velocity.
    • getEndColor

      public ColorRGBA getEndColor()
      Get the end color of the particles spawned.
      Returns:
      the end color of the particles spawned.
      See Also:
    • setEndColor

      public void setEndColor(ColorRGBA endColor)
      Set the end color of the particles spawned.

      The particle color at any time is determined by blending the start color and end color based on the particle's current time of life relative to its end of life.

      Parameters:
      endColor - the end color of the particles spawned.
    • getEndSize

      public float getEndSize()
      Get the end size of the particles spawned.
      Returns:
      the end size of the particles spawned.
      See Also:
    • setEndSize

      public void setEndSize(float endSize)
      Set the end size of the particles spawned.

      The particle size at any time is determined by blending the start size and end size based on the particle's current time of life relative to its end of life.

      Parameters:
      endSize - the end size of the particles spawned.
    • getGravity

      public Vector3f getGravity()
      Get the gravity vector.
      Returns:
      the gravity vector.
      See Also:
    • setGravity

      public void setGravity(Vector3f gravity)
      This method sets the gravity vector.
      Parameters:
      gravity - the gravity vector
    • setGravity

      public void setGravity(float x, float y, float z)
      Sets the gravity vector.
      Parameters:
      x - the x component of the gravity vector
      y - the y component of the gravity vector
      z - the z component of the gravity vector
    • getHighLife

      public float getHighLife()
      Get the high value of life.
      Returns:
      the high value of life.
      See Also:
    • setHighLife

      public void setHighLife(float highLife)
      Set the high value of life.

      The particle's lifetime/expiration is determined by randomly selecting a time between low life and high life.

      Parameters:
      highLife - the high value of life.
    • getImagesX

      public int getImagesX()
      Get the number of images along the X axis (width).
      Returns:
      the number of images along the X axis (width).
      See Also:
    • setImagesX

      public void setImagesX(int imagesX)
      Set the number of images along the X axis (width).

      To determine how multiple particle images are selected and used, see the setSelectRandomImage(boolean) method.

      Parameters:
      imagesX - the number of images along the X axis (width).
    • getImagesY

      public int getImagesY()
      Get the number of images along the Y axis (height).
      Returns:
      the number of images along the Y axis (height).
      See Also:
    • setImagesY

      public void setImagesY(int imagesY)
      Set the number of images along the Y axis (height).

      To determine how multiple particle images are selected and used, see the setSelectRandomImage(boolean) method.

      Parameters:
      imagesY - the number of images along the Y axis (height).
    • getLowLife

      public float getLowLife()
      Get the low value of life.
      Returns:
      the low value of life.
      See Also:
    • setLowLife

      public void setLowLife(float lowLife)
      Set the low value of life.

      The particle's lifetime/expiration is determined by randomly selecting a time between low life and high life.

      Parameters:
      lowLife - the low value of life.
    • getParticlesPerSec

      public float getParticlesPerSec()
      Get the number of particles to spawn per second.
      Returns:
      the number of particles to spawn per second.
      See Also:
    • setParticlesPerSec

      public void setParticlesPerSec(float particlesPerSec)
      Set the number of particles to spawn per second.
      Parameters:
      particlesPerSec - the number of particles to spawn per second.
    • getStartColor

      public ColorRGBA getStartColor()
      Get the start color of the particles spawned.
      Returns:
      the start color of the particles spawned.
      See Also:
    • setStartColor

      public void setStartColor(ColorRGBA startColor)
      Set the start color of the particles spawned.

      The particle color at any time is determined by blending the start color and end color based on the particle's current time of life relative to its end of life.

      Parameters:
      startColor - the start color of the particles spawned
    • getStartSize

      public float getStartSize()
      Get the start color of the particles spawned.
      Returns:
      the start color of the particles spawned.
      See Also:
    • setStartSize

      public void setStartSize(float startSize)
      Set the start size of the particles spawned.

      The particle size at any time is determined by blending the start size and end size based on the particle's current time of life relative to its end of life.

      Parameters:
      startSize - the start size of the particles spawned.
    • getInitialVelocity

      @Deprecated public Vector3f getInitialVelocity()
      Deprecated.
      Use ParticleEmitter.getParticleInfluencer().getInitialVelocity() instead.
      Returns:
      the pre-existing velocity vector
    • setInitialVelocity

      @Deprecated public void setInitialVelocity(Vector3f initialVelocity)
      Deprecated.
      This method is deprecated. Use ParticleEmitter.getParticleInfluencer().setInitialVelocity(initialVelocity); instead.
      Parameters:
      initialVelocity - Set the initial velocity a particle is spawned with, the initial velocity given in the parameter will be varied according to the velocity variation set in setVelocityVariation(float). The particle will move with this velocity unless it is affected by gravity.
      See Also:
    • getVelocityVariation

      @Deprecated public float getVelocityVariation()
      Deprecated.
      This method is deprecated. Use ParticleEmitter.getParticleInfluencer().getVelocityVariation(); instead.
      Returns:
      the initial velocity variation factor
    • setVelocityVariation

      @Deprecated public void setVelocityVariation(float variation)
      Deprecated.
      This method is deprecated. Use ParticleEmitter.getParticleInfluencer().setVelocityVariation(variation); instead.
      Parameters:
      variation - Set the variation by which the initial velocity of the particle is determined. variation should be a value from 0 to 1, where 0 means particles are to spawn with exactly the velocity specified in ParticleInfluencer.setInitialVelocity(com.jme3.math.Vector3f), and 1 means particles are to spawn with a completely random velocity.
    • emitAllParticles

      public void emitAllParticles()
      Instantly emits all the particles possible to be emitted. Any particles which are currently inactive will be spawned immediately.
    • emitParticles

      public void emitParticles(int num)
      Instantly emits available particles, up to num.
      Parameters:
      num - the maximum number of particles to emit
    • killAllParticles

      public void killAllParticles()
      Instantly kills all active particles, after this method is called, all particles will be dead and no longer visible.
    • killParticle

      public void killParticle(int index)
      Kills the particle at the given index.
      Parameters:
      index - The index of the particle to kill
      See Also:
    • updateParticle

      protected void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max)
    • setEnabled

      public void setEnabled(boolean enabled)
      Set to enable or disable the particle emitter

      When a particle is disabled, it will be "frozen in time" and not update.

      Parameters:
      enabled - True to enable the particle emitter
    • isEnabled

      public boolean isEnabled()
      Check if a particle emitter is enabled for update.
      Returns:
      True if a particle emitter is enabled for update.
      See Also:
    • updateFromControl

      public void updateFromControl(float tpf)
      Callback from Control.update(), do not use.
      Parameters:
      tpf - time per frame (in seconds)
    • preload

      public void preload(RenderManager rm, ViewPort vp)
    • write

      public void write(JmeExporter ex) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class Geometry
      Throws:
      IOException
    • read

      public void read(JmeImporter im) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class Geometry
      Throws:
      IOException