123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- import type { Immutable, Nullable } from "../types";
- import { FactorGradient, Color3Gradient } from "../Misc/gradients";
- import { Observable } from "../Misc/observable";
- import { Vector3, Matrix } from "../Maths/math.vector";
- import { VertexBuffer } from "../Buffers/buffer";
- import type { Effect } from "../Materials/effect";
- import type { IDisposable, Scene } from "../scene";
- import type { IParticleSystem } from "./IParticleSystem";
- import { BaseParticleSystem } from "./baseParticleSystem";
- import { Particle } from "./particle";
- import type { IAnimatable } from "../Animations/animatable.interface";
- import { DrawWrapper } from "../Materials/drawWrapper";
- import "../Shaders/particles.fragment";
- import "../Shaders/particles.vertex";
- import type { DataBuffer } from "../Buffers/dataBuffer";
- import { Color4, Color3 } from "../Maths/math.color";
- import type { AbstractEngine } from "../Engines/abstractEngine";
- import "../Engines/Extensions/engine.alpha";
- /**
- * This represents a thin particle system in Babylon.
- * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.
- * Particles can take different shapes while emitted like box, sphere, cone or you can write your custom function.
- * This thin version contains a limited subset of the total features in order to provide users with a way to get particles but with a smaller footprint
- * @example https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro
- */
- export declare class ThinParticleSystem extends BaseParticleSystem implements IDisposable, IAnimatable, IParticleSystem {
- /**
- * This function can be defined to provide custom update for active particles.
- * This function will be called instead of regular update (age, position, color, etc.).
- * Do not forget that this function will be called on every frame so try to keep it simple and fast :)
- */
- updateFunction: (particles: Particle[]) => void;
- private _emitterWorldMatrix;
- private _emitterInverseWorldMatrix;
- /**
- * This function can be defined to specify initial direction for every new particle.
- * It by default use the emitterType defined function
- */
- startDirectionFunction: (worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean) => void;
- /**
- * This function can be defined to specify initial position for every new particle.
- * It by default use the emitterType defined function
- */
- startPositionFunction: (worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean) => void;
- /**
- * @internal
- */
- _inheritedVelocityOffset: Vector3;
- /**
- * An event triggered when the system is disposed
- */
- onDisposeObservable: Observable<IParticleSystem>;
- /**
- * An event triggered when the system is stopped
- */
- onStoppedObservable: Observable<IParticleSystem>;
- private _onDisposeObserver;
- /**
- * Sets a callback that will be triggered when the system is disposed
- */
- set onDispose(callback: () => void);
- private _particles;
- private _epsilon;
- private _capacity;
- private _stockParticles;
- private _newPartsExcess;
- private _vertexData;
- private _vertexBuffer;
- private _vertexBuffers;
- private _spriteBuffer;
- private _indexBuffer;
- private _linesIndexBuffer;
- private _linesIndexBufferUseInstancing;
- private _drawWrappers;
- /** @internal */
- _customWrappers: {
- [blendMode: number]: Nullable<DrawWrapper>;
- };
- private _scaledColorStep;
- private _colorDiff;
- private _scaledDirection;
- private _scaledGravity;
- private _currentRenderId;
- private _alive;
- private _useInstancing;
- private _vertexArrayObject;
- private _started;
- private _stopped;
- private _actualFrame;
- private _scaledUpdateSpeed;
- private _vertexBufferSize;
- /** @internal */
- _currentEmitRateGradient: Nullable<FactorGradient>;
- /** @internal */
- _currentEmitRate1: number;
- /** @internal */
- _currentEmitRate2: number;
- /** @internal */
- _currentStartSizeGradient: Nullable<FactorGradient>;
- /** @internal */
- _currentStartSize1: number;
- /** @internal */
- _currentStartSize2: number;
- /** Indicates that the update of particles is done in the animate function */
- readonly updateInAnimate = true;
- private readonly _rawTextureWidth;
- private _rampGradientsTexture;
- private _useRampGradients;
- /** Gets or sets a matrix to use to compute projection */
- defaultProjectionMatrix: Matrix;
- /** Gets or sets a matrix to use to compute view */
- defaultViewMatrix: Matrix;
- /** Gets or sets a boolean indicating that ramp gradients must be used
- * @see https://doc.babylonjs.com/features/featuresDeepDive/particles/particle_system/particle_system_intro#ramp-gradients
- */
- get useRampGradients(): boolean;
- set useRampGradients(value: boolean);
- /**
- * Specifies if the particles are updated in emitter local space or world space
- */
- isLocal: boolean;
- /** Indicates that the particle system is CPU based */
- readonly isGPU = false;
- /**
- * Gets the current list of active particles
- */
- get particles(): Particle[];
- /**
- * Gets the number of particles active at the same time.
- * @returns The number of active particles.
- */
- getActiveCount(): number;
- /**
- * Returns the string "ParticleSystem"
- * @returns a string containing the class name
- */
- getClassName(): string;
- /**
- * Gets a boolean indicating that the system is stopping
- * @returns true if the system is currently stopping
- */
- isStopping(): boolean;
- /**
- * Gets the custom effect used to render the particles
- * @param blendMode Blend mode for which the effect should be retrieved
- * @returns The effect
- */
- getCustomEffect(blendMode?: number): Nullable<Effect>;
- private _getCustomDrawWrapper;
- /**
- * Sets the custom effect used to render the particles
- * @param effect The effect to set
- * @param blendMode Blend mode for which the effect should be set
- */
- setCustomEffect(effect: Nullable<Effect>, blendMode?: number): void;
- /** @internal */
- private _onBeforeDrawParticlesObservable;
- /**
- * Observable that will be called just before the particles are drawn
- */
- get onBeforeDrawParticlesObservable(): Observable<Nullable<Effect>>;
- /**
- * Gets the name of the particle vertex shader
- */
- get vertexShaderName(): string;
- /**
- * Gets the vertex buffers used by the particle system
- */
- get vertexBuffers(): Immutable<{
- [key: string]: VertexBuffer;
- }>;
- /**
- * Gets the index buffer used by the particle system (or null if no index buffer is used (if _useInstancing=true))
- */
- get indexBuffer(): Nullable<DataBuffer>;
- /**
- * Instantiates a particle system.
- * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.
- * @param name The name of the particle system
- * @param capacity The max number of particles alive at the same time
- * @param sceneOrEngine The scene the particle system belongs to or the engine to use if no scene
- * @param customEffect a custom effect used to change the way particles are rendered by default
- * @param isAnimationSheetEnabled Must be true if using a spritesheet to animate the particles texture
- * @param epsilon Offset used to render the particles
- */
- constructor(name: string, capacity: number, sceneOrEngine: Scene | AbstractEngine, customEffect?: Nullable<Effect>, isAnimationSheetEnabled?: boolean, epsilon?: number);
- /** @internal */
- _emitFromParticle: (particle: Particle) => void;
- serialize(serializeTexture: boolean): void;
- /**
- * Clones the particle system.
- * @param name The name of the cloned object
- * @param newEmitter The new emitter to use
- * @param cloneTexture Also clone the textures if true
- */
- clone(name: string, newEmitter: any, cloneTexture?: boolean): ThinParticleSystem;
- private _addFactorGradient;
- private _removeFactorGradient;
- /**
- * Adds a new life time gradient
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param factor defines the life time factor to affect to the specified gradient
- * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
- * @returns the current particle system
- */
- addLifeTimeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
- /**
- * Remove a specific life time gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeLifeTimeGradient(gradient: number): IParticleSystem;
- /**
- * Adds a new size gradient
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param factor defines the size factor to affect to the specified gradient
- * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
- * @returns the current particle system
- */
- addSizeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
- /**
- * Remove a specific size gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeSizeGradient(gradient: number): IParticleSystem;
- /**
- * Adds a new color remap gradient
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param min defines the color remap minimal range
- * @param max defines the color remap maximal range
- * @returns the current particle system
- */
- addColorRemapGradient(gradient: number, min: number, max: number): IParticleSystem;
- /**
- * Remove a specific color remap gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeColorRemapGradient(gradient: number): IParticleSystem;
- /**
- * Adds a new alpha remap gradient
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param min defines the alpha remap minimal range
- * @param max defines the alpha remap maximal range
- * @returns the current particle system
- */
- addAlphaRemapGradient(gradient: number, min: number, max: number): IParticleSystem;
- /**
- * Remove a specific alpha remap gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeAlphaRemapGradient(gradient: number): IParticleSystem;
- /**
- * Adds a new angular speed gradient
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param factor defines the angular speed to affect to the specified gradient
- * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
- * @returns the current particle system
- */
- addAngularSpeedGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
- /**
- * Remove a specific angular speed gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeAngularSpeedGradient(gradient: number): IParticleSystem;
- /**
- * Adds a new velocity gradient
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param factor defines the velocity to affect to the specified gradient
- * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
- * @returns the current particle system
- */
- addVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
- /**
- * Remove a specific velocity gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeVelocityGradient(gradient: number): IParticleSystem;
- /**
- * Adds a new limit velocity gradient
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param factor defines the limit velocity value to affect to the specified gradient
- * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
- * @returns the current particle system
- */
- addLimitVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
- /**
- * Remove a specific limit velocity gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeLimitVelocityGradient(gradient: number): IParticleSystem;
- /**
- * Adds a new drag gradient
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param factor defines the drag value to affect to the specified gradient
- * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
- * @returns the current particle system
- */
- addDragGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
- /**
- * Remove a specific drag gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeDragGradient(gradient: number): IParticleSystem;
- /**
- * Adds a new emit rate gradient (please note that this will only work if you set the targetStopDuration property)
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param factor defines the emit rate value to affect to the specified gradient
- * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
- * @returns the current particle system
- */
- addEmitRateGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
- /**
- * Remove a specific emit rate gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeEmitRateGradient(gradient: number): IParticleSystem;
- /**
- * Adds a new start size gradient (please note that this will only work if you set the targetStopDuration property)
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param factor defines the start size value to affect to the specified gradient
- * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
- * @returns the current particle system
- */
- addStartSizeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
- /**
- * Remove a specific start size gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeStartSizeGradient(gradient: number): IParticleSystem;
- private _createRampGradientTexture;
- /**
- * Gets the current list of ramp gradients.
- * You must use addRampGradient and removeRampGradient to update this list
- * @returns the list of ramp gradients
- */
- getRampGradients(): Nullable<Array<Color3Gradient>>;
- /** Force the system to rebuild all gradients that need to be resync */
- forceRefreshGradients(): void;
- private _syncRampGradientTexture;
- /**
- * Adds a new ramp gradient used to remap particle colors
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param color defines the color to affect to the specified gradient
- * @returns the current particle system
- */
- addRampGradient(gradient: number, color: Color3): ThinParticleSystem;
- /**
- * Remove a specific ramp gradient
- * @param gradient defines the gradient to remove
- * @returns the current particle system
- */
- removeRampGradient(gradient: number): ThinParticleSystem;
- /**
- * Adds a new color gradient
- * @param gradient defines the gradient to use (between 0 and 1)
- * @param color1 defines the color to affect to the specified gradient
- * @param color2 defines an additional color used to define a range ([color, color2]) with main color to pick the final color from
- * @returns this particle system
- */
- addColorGradient(gradient: number, color1: Color4, color2?: Color4): IParticleSystem;
- /**
- * Remove a specific color gradient
- * @param gradient defines the gradient to remove
- * @returns this particle system
- */
- removeColorGradient(gradient: number): IParticleSystem;
- /**
- * Resets the draw wrappers cache
- */
- resetDrawCache(): void;
- private _fetchR;
- protected _reset(): void;
- private _resetEffect;
- private _createVertexBuffers;
- private _createIndexBuffer;
- /**
- * Gets the maximum number of particles active at the same time.
- * @returns The max number of active particles.
- */
- getCapacity(): number;
- /**
- * Gets whether there are still active particles in the system.
- * @returns True if it is alive, otherwise false.
- */
- isAlive(): boolean;
- /**
- * Gets if the system has been started. (Note: this will still be true after stop is called)
- * @returns True if it has been started, otherwise false.
- */
- isStarted(): boolean;
- /** @internal */
- _preStart(): void;
- /**
- * Starts the particle system and begins to emit
- * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
- */
- start(delay?: number): void;
- /**
- * Stops the particle system.
- * @param stopSubEmitters if true it will stop the current system and all created sub-Systems if false it will stop the current root system only, this param is used by the root particle system only. The default value is true.
- */
- stop(stopSubEmitters?: boolean): void;
- /** @internal */
- _postStop(stopSubEmitters: boolean): void;
- /**
- * Remove all active particles
- */
- reset(): void;
- /**
- * @internal (for internal use only)
- */
- _appendParticleVertex(index: number, particle: Particle, offsetX: number, offsetY: number): void;
- /**
- * "Recycles" one of the particle by copying it back to the "stock" of particles and removing it from the active list.
- * Its lifetime will start back at 0.
- * @param particle
- */
- recycleParticle: (particle: Particle) => void;
- private _createParticle;
- /** @internal */
- _prepareParticle(particle: Particle): void;
- private _update;
- /**
- * @internal
- */
- static _GetAttributeNamesOrOptions(isAnimationSheetEnabled?: boolean, isBillboardBased?: boolean, useRampGradients?: boolean): string[];
- /**
- * @internal
- */
- static _GetEffectCreationOptions(isAnimationSheetEnabled?: boolean, useLogarithmicDepth?: boolean, applyFog?: boolean): string[];
- /**
- * Fill the defines array according to the current settings of the particle system
- * @param defines Array to be updated
- * @param blendMode blend mode to take into account when updating the array
- */
- fillDefines(defines: Array<string>, blendMode: number): void;
- /**
- * Fill the uniforms, attributes and samplers arrays according to the current settings of the particle system
- * @param uniforms Uniforms array to fill
- * @param attributes Attributes array to fill
- * @param samplers Samplers array to fill
- */
- fillUniformsAttributesAndSamplerNames(uniforms: Array<string>, attributes: Array<string>, samplers: Array<string>): void;
- /**
- * @internal
- */
- private _getWrapper;
- /**
- * Animates the particle system for the current frame by emitting new particles and or animating the living ones.
- * @param preWarmOnly will prevent the system from updating the vertex buffer (default is false)
- */
- animate(preWarmOnly?: boolean): void;
- private _appendParticleVertices;
- /**
- * Rebuilds the particle system.
- */
- rebuild(): void;
- /**
- * Is this system ready to be used/rendered
- * @returns true if the system is ready
- */
- isReady(): boolean;
- private _render;
- /**
- * Renders the particle system in its current state.
- * @returns the current number of particles
- */
- render(): number;
- /** @internal */
- _onDispose(disposeAttachedSubEmitters?: boolean, disposeEndSubEmitters?: boolean): void;
- /**
- * Disposes the particle system and free the associated resources
- * @param disposeTexture defines if the particle texture must be disposed as well (true by default)
- * @param disposeAttachedSubEmitters defines if the attached sub-emitters must be disposed as well (false by default)
- * @param disposeEndSubEmitters defines if the end type sub-emitters must be disposed as well (false by default)
- */
- dispose(disposeTexture?: boolean, disposeAttachedSubEmitters?: boolean, disposeEndSubEmitters?: boolean): void;
- }
|