SgParticleSystem¶
The Particle System API is a Lua-based interface designed for creating and controlling advanced particle effects in games. It provides a comprehensive and easy-to-use set of functions that enable developers to manage particle systems, control their behavior, and customize visual properties dynamically during runtime. The API mirrors common practices in modern particle system engines, offering extensive control over emission properties, particle lifetimes, velocities, colors, and transformations. This package integrates seamlessly with Lua environments, offering efficient management of particle effects with minimal overhead.
Reference¶
- class SgParticleSystem¶
- module:
- create(options, parent)¶
Create a new particle system object in the scenegraph.
- Parameters:¶
options (
table
) – A table of options to fill the parametersparent (
SceneObject
) – The parent scene object to add this to
- Returns:¶
a promise which will resolve to the created object
- Return type:¶
Promise
- fromObject(obj)¶
Create a particlesystem object from another scene object.
- Parameters:¶
obj (
SceneObject
) – The scene object to convert
- destroy()¶
Destroys the particle system.
- getParticlesCount()¶
Returns the number of particles in the particle system.
- getPause()¶
Returns the pause state of the particle system.
- getSpawnAmount()¶
Returns the spawn amount.
- getSpawnRate()¶
Returns the spawn rate.
- getRespawn(value)¶
Sets the respawn flag for the particle system.
- Parameters:¶
value (
boolean
) – The respawn flag state to set.
- getPrewarm()¶
Returns the prewarm flag state. WIP
- getPrewarmAmount()¶
Returns the prewarm amount.
- getEmitter()¶
Returns the emitter parameters.
- getDuration()¶
Returns the duration of the particle system.
- getEmissionFlag()¶
Returns the emission flag state.
- getContinuousEmissionFlag()¶
Returns the continuous emission flag state.
- getLocalCoordsFlag()¶
Returns the local coordinates flag state.
- getAngularVelocity()¶
Returns the angular velocity of the particles.
- getRotationDirection()¶
Returns the direction the particles will rotate to.
anti-clockwise and 0 stand still.
- getLifeDelta()¶
Returns the life delta of the particles.
- getLifeDeltaRandom()¶
Returns the random life delta of the particles.
- getGravity()¶
Returns the gravity applied to the particles.
- getOrbitalVelocity()¶
Returns the orbital velocity of the particles.
- getOrbitalDecay()¶
Returns the orbital decay of the particles.
- getOrbitalCenterPoint()¶
Returns the orbital center point of the particles.
- getOrbitalPlane()¶
Returns the orbital plane of the particles.
- getParticleLife()¶
Returns the life of the particles.
- getParticleLife()
Returns the life of the particles.
- getParticleSize()¶
Returns the particle size.
- getInitialVelocity()¶
Returns the particle initial velocity.
- getFinalVelocity()¶
Returns the particle final velocity.
- getFinalVelocityApproachValue()¶
Returns the particle final velocity approach value.
- getTarget()¶
Returns the target direction.
- getTargetForce()¶
Returns the target force strength.
- getTargetDeletionThreshold()¶
Sets the target deletion threshold.
- getRandomVelocity()¶
Returns the random velocity factor.
- getNormalVelocity()¶
Returns the velocity applied on the direction of normals on a emitter.
- getSpread()¶
Returns the spread factor.
- getBBoxFlag()¶
Returns the bounding box flag state.
- getBoundingBox()¶
Returns the bounding box dimensions.
- getParticleColor()¶
Returns the particle color.
- getParticleRandomColorFactor()¶
Returns the particle random color factor.
- getFinalColorFlag()¶
Returns the final color flag for the particles.
This indicates whether the final color property is enabled.
- getFinalColor()¶
Returns the final color of the particles.
- getTextureBlendingFlag()¶
Returns the texture blending flag for the particles.
This indicates whether texture blending is enabled.
- getTextureBlendingFlag()
Returns the texture blending value for the particles. The value is between 0 and 1.
- getTextureHue()¶
Returns the hue of the particle’s texture.
- getParticleFadeOverLifetimeFlag()¶
Returns the particle fade-over-lifetime flag.
This indicates whether particles fade over their lifetime.
- getNoiseStrength()¶
Sets the noise strength for the particle system.
- getNoiseFrequency()¶
Sets the noise frequency for the particle system.
- getNoiseOctaves()¶
Sets the noise octaves for the particle system.
- setEmitter(shape, type, size)¶
Sets the emitter parameters.
- Parameters:¶
shape (
str
) – The shape of the emitter.type (
str
) – The type of the emitter.size (
number
) – The size of the emitter.
Usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
local emitterShape local emitterType local emitterConfig = { size = 10, radius = 5, outerRadius = 8, height = 20, width = 15, depth = 10, life = 5.0, lifeRandomness = 0.2 } function update() particleSystem:setEmitter(SgParticleSystem.EmissionShapes[emitterShape:getValue() + 1], SgParticleSystem.EmissionTypes[emitterType:getValue() + 1], emitterConfig) end function rendergui() gui.text("Emitter shape") gui.combo("Emtiter shape", emitterShape, SgParticleSystem.EmissionShapes) gui.combo("Emtiter type", emitterType, SgParticleSystem.EmissionTypes) gui.endDialog() end
- setPause(value)¶
Sets the pause state of the particle system.
- Parameters:¶
value (
boolean
) – The pause state to set.
- killAllParticles()¶
Kills all particles in the system.
- hideParticles()¶
Hides all particles in the system.
- showParticles()¶
Shows all particles in the system.
- restart()¶
Restarts the particle system.
- setRespawn(value)¶
Sets the respawn flag for the particle system.
- Parameters:¶
value (
boolean
) – The respawn flag state to set.
- setSpawnAmount(value)¶
Sets the spawn amount.
- Parameters:¶
value (
number
) – The number of particles to spawn.
- setSpawnRate(value)¶
Sets the spawn rate.
- Parameters:¶
value (
number
) – The rate of particle spawning.
- setPrewarm(value)¶
Sets the prewarm flag.
- Parameters:¶
value (
boolean
) – The prewarm flag state to set.
- setPrewarmAmount(value)¶
Sets the prewarm amount.
- Parameters:¶
value (
number
) – The number of particles to prewarm.
- runPrewarm()¶
Runs the prewarm process.
- setDuration(value)¶
Sets the duration of the particle system.
- Parameters:¶
value (
number
) – The duration of the particle system.
- setEmissionFlag(value)¶
Sets the emission flag.
- Parameters:¶
value (
boolean
) – The emission flag state to set.
- setContinuousEmissionFlag(value)¶
Sets the continuous emission flag.
- Parameters:¶
value (
boolean
) – The continuous emission flag state to set.
- setLocalCoordsFlag(value)¶
Sets the local coordinates flag.
- Parameters:¶
value (
boolean
) – The local coordinates flag state to set.
- updateEmitterMatrices(object)¶
Updates the emitter matrices.
- Parameters:¶
object (
table
) – The object containing the emitter matrices data.
- updateEmitterPosition(object)¶
Updates the emitter position.
- Parameters:¶
object (
table
) – The object containing the emitter position data.
- emitAllParticles()¶
Emits all particles at once.
- emitNewParticles(particleCount, continuous)¶
Emits new particles.
- Parameters:¶
particleCount (
number
) – The number of particles to emit.continuous (
boolean
) – Whether to emit particles continuously.
- setParticleLife(life, lifeRandomness)¶
Sets the particle life parameters.
- Parameters:¶
life (
number
) – The lifespan of the particles.lifeRandomness (
number
) – The randomness factor for the lifespan.
- setLifeDeltaRandom(value)¶
Sets the life delta randomness.
- Parameters:¶
value (
number
) – The randomness factor for the life delta.
- setGravity(value)¶
Sets the gravity for the particle system.
- Parameters:¶
value (
number
) – The gravity value.
- setOrbitalVelocity(value)¶
Sets the orbital velocity.
- Parameters:¶
value (
number
) – The orbital velocity value.
- setOrbitalDecay(value)¶
Sets the orbital decay.
- Parameters:¶
value (
number
) – The orbital decay value.
- setOrbitalCenterPoint(value)¶
Sets the orbital center point.
- Parameters:¶
value (
table
) – The center point coordinates for the orbital motion.
- setOrbitalPlane(value)¶
Sets the orbital plane.
- Parameters:¶
value (
table
) – The orbital plane identifier.
- setTarget(direction)¶
Sets the target direction for the particle system.
- Parameters:¶
direction (
table
) – The target direction vector.
- setTargetForce(strength)¶
Sets the target force strength.
- Parameters:¶
strength (
number
) – The strength of the force towards the target.
- setTargetDeletionThreshold(value)¶
Sets the target deletion threshold.
- Parameters:¶
value (
number
) – The deletion threshold value for particles targeting an object. A value of -1 will not kill particles.
- setRandomVelocity(value)¶
Sets the random velocity factor.
- Parameters:¶
value (
number
) – The random velocity factor.
- setInitialVelocity(velocity)¶
Sets the initial velocity for particles.
- Parameters:¶
velocity (
table
) – The initial velocity vector.
- setFinalVelocity(target)¶
Sets the final velocity parameters.
- Parameters:¶
target (
table
) – The target velocity vector.
- setFinalVelocityApproachValue(approachValue)¶
Sets the final velocity appraoch value.
- Parameters:¶
approachValue (
number
) – The approach value of the final velocity.
- setNormalVelocity(velocityFactor)¶
Sets the velocity applied on the direction of normals on a emitter. Used when emission type is set to normals. @see setEmitter()
- Parameters:¶
velocityFactor (
number
) – The velocity factor.
- setSpread(value)¶
Sets the spread value for the particle system.
- Parameters:¶
value (
number
) – The spread value.
- setBBoxFlag(boolean)¶
Sets the bounding box flag.
- Parameters:¶
boolean (
boolean
) – The bounding box flag state to set.
- setBoundingBox(bboxMin, bboxMax)¶
Sets the bounding box dimensions.
- Parameters:¶
bboxMin (
table
) – The minimum boundary of the bounding box.bboxMax (
table
) – The maximum boundary of the bounding box.
- setParticleSize(minSize, maxSize, approach)¶
Sets the particle size.
- Parameters:¶
minSize (
number
) – The minimum size of the particles.maxSize (
number
) – The maximum size of the particles.approach (
str
) – The approach to transition between sizes.
- setAngularVelocity(velocity, direction)¶
Sets the angular velocity and direction.
- Parameters:¶
velocity (
number
) – The angular velocity.direction (
table
) – The direction vector for angular velocity.
- setParticleRandomColorFactor(factor)¶
Sets the particle random color factor.
- Parameters:¶
factor (
number
) – The random color factor.
- setParticleTexture(texture)¶
Sets the particle texture.
- Parameters:¶
texture (
str
) – The texture identifier for the particles.
- setParticleColor(r, g, b, a)¶
Sets the particle color.
- Parameters:¶
r (
number
) – The red component of the color.g (
number
) – The green component of the color.b (
number
) – The blue component of the color.a (
number
) – The alpha (transparency) component of the color.
- setParticleFinalColor(r, g, b, a)¶
Sets the particle final color.
- Parameters:¶
r (
number
) – The red component of the final color.g (
number
) – The green component of the final color.b (
number
) – The blue component of the final color.a (
number
) – The alpha (transparency) component of the final color.
- setFinalColorFlag(value)¶
Sets the final color flag.
- Parameters:¶
value (
boolean
) – The final color flag state to set.
- setTextureBlendingFlag(value)¶
Sets the texture blending flag.
- Parameters:¶
value (
boolean
) – The texture blending flag state to set.
- setBlendingValue(value)¶
Sets the texture blending value.
- Parameters:¶
value (
number
) – The texture blending value to set.
- setTextureHue(value)¶
Sets the texture hue shift.
- Parameters:¶
value (
number
) – The hue shift value for the texture.
- setParticleFadeOverLifetimeFlag(value)¶
Sets the particle fade over lifetime flag.
- Parameters:¶
value (
boolean
) – The fade over lifetime flag state to set.
- setSpriteSpeed(fps)¶
Sets the sprite animation speed.
- Parameters:¶
fps (
number
) – The frames per second for the sprite animation.
- setSpriteRollingWithLifeFlag(boolean)¶
Sets the sprite rolling with life flag.
- Parameters:¶
boolean (
boolean
) – The sprite rolling with life flag state to set.
- setSpriteCols(nCols)¶
Sets the number of columns in the sprite sheet.
- Parameters:¶
nCols (
number
) – The number of columns in the sprite sheet.
- setSpriteRows(nRows)¶
Sets the number of rows in the sprite sheet.
- Parameters:¶
nRows (
number
) – The number of rows in the sprite sheet.
- setAtlasSize(width, height)¶
Sets the atlas size for the sprites.
- Parameters:¶
width (
number
) – The width of the sprite atlas.height (
number
) – The height of the sprite atlas.
- setNoiseStrength(value)¶
Sets the noise strength for the particle system.
- Parameters:¶
value (
number
) – The noise strength value.
- setNoiseFrequency(value)¶
Sets the noise frequency for the particle system.
- Parameters:¶
value (
number
) – The noise frequency value.
- setNoiseOctaves(value)¶
Sets the noise octaves for the particle system.
- Parameters:¶
value (
number
) – The noise octaves value.
- generateNoise()¶
Renders a new noise texture to be applied to the particle system.
Examples¶
local SgParticleSystem = require 'engine/sceneobjects/sgparticles'
local Transform = require 'engine/math/transform'
local Quaternion = require 'engine/math/quaternion'
particleSystem = SgParticleSystem:findByName("YourParticleSystemName")
local transform = Transform.new(Vector3.new(10, 0, 0), Quaternion.new(0, 0, 0, 1), Vector3.new(25, 25, 25))
particleSystem:translate(transform)