import { EmitterGroup } from './EmitterGroup'; import { IEmitterOptions, IDistribution, IEmitterPositionState, IEmitterVelocityState, IEmitterAcceleratorState, IEmitterDragState, IEmitterWiggleState, IEmitterMaxAgeState, IEmitterOpacityState, IEmitterSizeState, IEmitterAngleState, IEmitterColorState, IUpdateMap, IParticleBasePropKeys, IShaderAttributes, IShaderAttributeKeys, IShaderAttributeKeyArray, IEmitterOrbitState, IEmitterRotationState } from './types'; /** * An Emitter instance. * @typedef {Object} Emitter * @see Emitter */ /** * A map of options to configure an Emitter instance. * * @typedef {Object} EmitterOptions * * @property {IDistribution} [type=BOX] The default distribution this emitter should use to control * its particle's spawn position and force behaviour. * Must be an IDistribution.* value. * * * @property {Number} [particleCount=100] The total number of particles this emitter will hold. NOTE: this is not the number * of particles emitted in a second, or anything like that. The number of particles * emitted per-second is calculated by particleCount / maxAge (approximately!) * * @property {Number|null} [duration=null] The duration in seconds that this emitter should live for. If not specified, the emitter * will emit particles indefinitely. * NOTE: When an emitter is older than a specified duration, the emitter is NOT removed from * it's group, but rather is just marked as dead, allowing it to be reanimated at a later time * using `Emitter.prototype.enable()`. * * @property {Boolean} [isStatic=false] Whether this emitter should be not be simulated (true). * @property {Boolean} [activeMultiplier=1] A value between 0 and 1 describing what percentage of this emitter's particlesPerSecond should be * emitted, where 0 is 0%, and 1 is 100%. * For example, having an emitter with 100 particles, a maxAge of 2, yields a particlesPerSecond * value of 50. Setting `activeMultiplier` to 0.5, then, will only emit 25 particles per second (0.5 = 50%). * Values greater than 1 will emulate a burst of particles, causing the emitter to run out of particles * before it's next activation cycle. * * @property {Boolean} [direction=1] The direction of the emitter. If value is `1`, emitter will start at beginning of particle's lifecycle. * If value is `-1`, emitter will start at end of particle's lifecycle and work it's way backwards. * * @property {Object} [maxAge={}] An object describing the particle's maximum age in seconds. * @property {Number} [maxAge.value=2] A number between 0 and 1 describing the amount of maxAge to apply to all particles. * @property {Number} [maxAge.spread=0] A number describing the maxAge variance on a per-particle basis. * * * @property {Object} [position={}] An object describing this emitter's position. * @property {Object} [position.value=new THREE.Vector3()] A THREE.Vector3 instance describing this emitter's base position. * @property {Object} [position.spread=new THREE.Vector3()] A THREE.Vector3 instance describing this emitter's position variance on a per-particle basis. * Note that when using a SPHERE or DISC distribution, only the x-component * of this vector is used. * When using a LINE distribution, this value is the endpoint of the LINE. * @property {Object} [position.spreadClamp=new THREE.Vector3()] A THREE.Vector3 instance describing the numeric multiples the particle's should * be spread out over. * Note that when using a SPHERE or DISC distribution, only the x-component * of this vector is used. * When using a LINE distribution, this property is ignored. * @property {Number} [position.radius=10] This emitter's base radius. * @property {Object} [position.radiusScale=new THREE.Vector3()] A THREE.Vector3 instance describing the radius's scale in all three axes. Allows a SPHERE or DISC to be squashed or stretched. * @property {distribution} [position.distribution=value of the `type` option.] A specific distribution to use when radiusing particles. Overrides the `type` option. * @property {Boolean} [position.randomise=false] When a particle is re-spawned, whether it's position should be re-randomised or not. Can incur a performance hit. * * * @property {Object} [velocity={}] An object describing this particle velocity. * @property {Object} [velocity.value=new THREE.Vector3()] A THREE.Vector3 instance describing this emitter's base velocity. * @property {Object} [velocity.spread=new THREE.Vector3()] A THREE.Vector3 instance describing this emitter's velocity variance on a per-particle basis. * Note that when using a SPHERE or DISC distribution, only the x-component * of this vector is used. * @property {distribution} [velocity.distribution=value of the `type` option.] A specific distribution to use when calculating a particle's velocity. Overrides the `type` option. * @property {Boolean} [velocity.randomise=false] When a particle is re-spawned, whether it's velocity should be re-randomised or not. Can incur a performance hit. * * * @property {Object} [acceleration={}] An object describing this particle's acceleration. * @property {Object} [acceleration.value=new THREE.Vector3()] A THREE.Vector3 instance describing this emitter's base acceleration. * @property {Object} [acceleration.spread=new THREE.Vector3()] A THREE.Vector3 instance describing this emitter's acceleration variance on a per-particle basis. * Note that when using a SPHERE or DISC distribution, only the x-component * of this vector is used. * @property {distribution} [acceleration.distribution=value of the `type` option.] A specific distribution to use when calculating a particle's acceleration. Overrides the `type` option. * @property {Boolean} [acceleration.randomise=false] When a particle is re-spawned, whether it's acceleration should be re-randomised or not. Can incur a performance hit. * * * @property {Object} [drag={}] An object describing this particle drag. Drag is applied to both velocity and acceleration values. * @property {Number} [drag.value=0] A number between 0 and 1 describing the amount of drag to apply to all particles. * @property {Number} [drag.spread=0] A number describing the drag variance on a per-particle basis. * @property {Boolean} [drag.randomise=false] When a particle is re-spawned, whether it's drag should be re-randomised or not. Can incur a performance hit. * * * @property {Object} [wiggle={}] This is quite a fun one! The values of this object will determine whether a particle will wiggle, or jiggle, or wave, * or shimmy, or waggle, or... Well you get the idea. The wiggle is calculated over-time, meaning that a particle will * start off with no wiggle, and end up wiggling about with the distance of the `value` specified by the time it dies. * It's quite handy to simulate fire embers, or similar effects where the particle's position should slightly change over * time, and such change isn't easily controlled by rotation, velocity, or acceleration. The wiggle is a combination of sin and cos calculations, so is circular in nature. * @property {Number} [wiggle.value=0] A number describing the amount of wiggle to apply to all particles. It's measured in distance. * @property {Number} [wiggle.spread=0] A number describing the wiggle variance on a per-particle basis. * * * @property {Object} [orbit={}] An object describing this emitter's orbit behaviour. It can either be static, or set to rotate from 0radians to the value of `orbit.value` * over a particle's lifetime. Orbit values affect both a particle's position and the forces applied to it. * @property {Object} [orbit.axis=new THREE.Vector3(0, 1, 0)] A THREE.Vector3 instance describing this emitter's axis of orbit. * @property {Object} [orbit.axisSpread=new THREE.Vector3()] A THREE.Vector3 instance describing the amount of variance to apply to the axis of orbit on * a per-particle basis. * @property {Number} [orbit.angle=0] The angle of orbiting, given in radians. If `orbit.static` is true, the emitter will start off orbiting at this angle, and stay as such. * Otherwise, the particles will orbit from 0 radians to this value over their lifetimes. * @property {Number} [orbit.angleSpread=0] The amount of variance in each particle's orbit angle. * @property {Boolean} [orbit.static=false] Whether the orbit should be static or not. * @property {Object} [orbit.center=The value of `position.value`] A THREE.Vector3 instance describing the center point around which the particles orbit. * @property {Boolean} [orbit.randomise=false] When a particle is re-spawned, whether it's orbit behaviour should be re-randomised or not. Can incur a performance hit. * * * @property {Object} [color={}] An object describing a particle's color. This property is a "value-over-lifetime" property, meaning an array of values and spreads can be * given to describe specific value changes over a particle's lifetime. * Depending on the value of valueOverLifetimeLength, if arrays of THREE.Color instances are given, then the array will be interpolated to * have a length matching the value of valueOverLifetimeLength. * @property {Object} [color.value=new THREE.Color()] Either a single THREE.Color instance, or an array of THREE.Color instances to describe the color of a particle over it's lifetime. * @property {Object} [color.spread=new THREE.Vector3()] Either a single THREE.Vector3 instance, or an array of THREE.Vector3 instances to describe the color variance of a particle over it's lifetime. * @property {Boolean} [color.randomise=false] When a particle is re-spawned, whether it's color should be re-randomised or not. Can incur a performance hit. * * * @property {Object} [opacity={}] An object describing a particle's opacity. This property is a "value-over-lifetime" property, meaning an array of values and spreads can be * given to describe specific value changes over a particle's lifetime. * Depending on the value of valueOverLifetimeLength, if arrays of numbers are given, then the array will be interpolated to * have a length matching the value of valueOverLifetimeLength. * @property {Number} [opacity.value=1] Either a single number, or an array of numbers to describe the opacity of a particle over it's lifetime. * @property {Number} [opacity.spread=0] Either a single number, or an array of numbers to describe the opacity variance of a particle over it's lifetime. * @property {Boolean} [opacity.randomise=false] When a particle is re-spawned, whether it's opacity should be re-randomised or not. Can incur a performance hit. * * * @property {Object} [size={}] An object describing a particle's size. This property is a "value-over-lifetime" property, meaning an array of values and spreads can be * given to describe specific value changes over a particle's lifetime. * Depending on the value of valueOverLifetimeLength, if arrays of numbers are given, then the array will be interpolated to * have a length matching the value of valueOverLifetimeLength. * @property {Number} [size.value=1] Either a single number, or an array of numbers to describe the size of a particle over it's lifetime. * @property {Number} [size.spread=0] Either a single number, or an array of numbers to describe the size variance of a particle over it's lifetime. * @property {Boolean} [size.randomise=false] When a particle is re-spawned, whether it's size should be re-randomised or not. Can incur a performance hit. * * * @property {Object} [angle={}] An object describing a particle's angle. The angle is a 2d-rotation, measured in radians, applied to the particle's texture. * NOTE: if a particle's texture is a sprite-sheet, this value IS IGNORED. * This property is a "value-over-lifetime" property, meaning an array of values and spreads can be * given to describe specific value changes over a particle's lifetime. * Depending on the value of valueOverLifetimeLength, if arrays of numbers are given, then the array will be interpolated to * have a length matching the value of valueOverLifetimeLength. * @property {Number} [angle.value=0] Either a single number, or an array of numbers to describe the angle of a particle over it's lifetime. * @property {Number} [angle.spread=0] Either a single number, or an array of numbers to describe the angle variance of a particle over it's lifetime. * @property {Boolean} [angle.randomise=false] When a particle is re-spawned, whether it's angle should be re-randomised or not. Can incur a performance hit. * * @property {Number} [rotation={}] An object describing each particle's rotation behaviour. A particle can either be static, or set to rotate by a given amount of radians * over it's lifetime. Rotation values affect only the rotation of a particle. Note that rotation values do not apply to directional billboarded particles or when randomParticleRotationAngle is set on the emitter group. * For cylindrically or spherically billboarded particles the rotation axis always defaults to (0, 0, 1). * * @property {Object} [rotation.axis=new THREE.Vector3(0, 0, 1)] A THREE.Vector3 instance describing the axis around which particles rotate. Note that for cylindcrically and spherically billboarded particles this always defaults to an axis of (0. 0. 1) * @property {Object} [rotation.axisSpread=new THREE.Vector3()] A THREE.Vector3 instance describing the amount of variance to apply to the rotation axis on a per-particle basis. Note that for cylindcrical and spherical particles this defaults to (0. 0. 0). * @property {Number} [rotation.angle=0] The angle of rotation, given in radians. If `rotation.static` is true, the particle will start off rotating at this angle, and stay as such. * Otherwise, the particles will rotate from 0 radians to this value over their lifetimes. * @property {Number} [rotation.angleSpread=0] The amount of variance in each particle's rotation angle. * @property {Boolean} [rotation.static=false] Whether the rotation should be static or not. * @property {Boolean} [rotation.randomise=false] When a particle is re-spawned, whether it's rotation behaviour should be re-randomised or not. Can incur a performance hit. */ /** * The Emitter class. * * @constructor * * @param {EmitterOptions} options A map of options to configure the emitter. */ export declare class Emitter { uuid: string; isEmitter: boolean; position: IEmitterPositionState; velocity: IEmitterVelocityState; acceleration: IEmitterAcceleratorState; drag: IEmitterDragState; wiggle: IEmitterWiggleState; orbit: IEmitterOrbitState; maxAge: IEmitterMaxAgeState; color: IEmitterColorState; opacity: IEmitterOpacityState; size: IEmitterSizeState; rotation: IEmitterRotationState; angle: IEmitterAngleState; particleCount: number; duration: number | null; isStatic: boolean; activeMultiplier: number; direction: number; alive: boolean; particlesPerSecond: number; activationIndex: number; attributeOffset: number; attributeEnd: number; age: number; activeParticleCount: number; group: InstanceType | null; attributes: IShaderAttributes | null; paramsArray: Float32Array | Uint8Array | null; resetFlags: Partial>; updateFlags: Partial>; updateCounts: Partial>; updateMap: IUpdateMap; bufferUpdateRanges: Partial>; attributeKeys: IShaderAttributeKeyArray | null; attributeCount: number; activationEnd: number | undefined; private _onFinishCbs; onFinish(fn?: () => unknown): void; private _type; set type(value: IDistribution); get type(): IDistribution; constructor(options?: IEmitterOptions); setBufferUpdateRanges: (keys: IShaderAttributeKeyArray) => void; calculatePPSValue: (groupMaxAge: number) => void; setAttributeOffset: (startIndex: number) => void; private _assignValue; assignPositionValue: (index: number) => void; assignForceValueAll: (attrName: IParticleBasePropKeys) => void; assignForceValue: (index: number, attrName: IParticleBasePropKeys) => void; assignAbsLifetimeValue: (index: number, propName: 'opacity' | 'size') => void; assignAngleValue: (index: number) => void; assignParamsValue: (index: number) => void; assignOrbitValue: (index: number) => void; assignRotationValue: (index: number) => void; assignColorValue: (index: number) => void; assignWorldSpawnPosition: (index: number) => void; private _resetParticle; private _updateAttributeUpdateRange; onRemove: () => void; private _decrementParticleCount; private _incrementParticleCount; private _checkParticleAges; private _activateParticles; /** * Simulates one frame's worth of particles, updating particles * that are already alive, and marking ones that are currently dead * but should be alive as alive. * * If the emitter is marked as static, then this function will do nothing. * * @param {Number} dt The number of seconds to simulate (deltaTime) */ tick: (dt: number) => void; /** * Resets all the emitter's particles to their start positions * and marks the particles as dead if the `force` argument is * true. * * @param {Boolean} [force=undefined] If true, all particles will be marked as dead instantly. * @return {Emitter} This emitter instance. */ reset: (force?: boolean) => this; private _emitterStateFactory; /** * Enables the emitter. If not already enabled, the emitter * will start emitting particles. * * @return {Emitter} This emitter instance. */ enable: () => this; /** * Disables th emitter, but does not instantly remove it's * particles fromt the scene. When called, the emitter will be * 'switched off' and just stop emitting. Any particle's alive will * be allowed to finish their lifecycle. * @return {Emitter} This emitter instance. */ disable: () => this; /** * Remove this emitter from it's parent group (if it has been added to one). * Delgates to removeEmitter(). * * When called, all particle's belonging to this emitter will be instantly * removed from the scene. * @return {Emitter} This emitter instance. * @see ParticleGroup.removeEmitter */ remove: () => this; }