123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- module BABYLON {
- /**
- * A particle represents one of the element emitted by a particle system.
- * This is mainly define by its coordinates, direction, velocity and age.
- */
- export class Particle {
- /**
- * The world position of the particle in the scene.
- */
- public position = Vector3.Zero();
- /**
- * The world direction of the particle in the scene.
- */
- public direction = Vector3.Zero();
- /**
- * The color of the particle.
- */
- public color = new Color4(0, 0, 0, 0);
- /**
- * The color change of the particle per step.
- */
- public colorStep = new Color4(0, 0, 0, 0);
- /**
- * Defines how long will the life of the particle be.
- */
- public lifeTime = 1.0;
- /**
- * The current age of the particle.
- */
- public age = 0;
- /**
- * The current size of the particle.
- */
- public size = 0;
- /**
- * The current scale of the particle.
- */
- public scale = new Vector2(1, 1);
- /**
- * The current angle of the particle.
- */
- public angle = 0;
- /**
- * Defines how fast is the angle changing.
- */
- public angularSpeed = 0;
- /**
- * Defines the cell index used by the particle to be rendered from a sprite.
- */
- public cellIndex: number = 0;
- /** @hidden */
- public _initialDirection: Nullable<Vector3>;
- /** @hidden */
- public _initialSize: number;
- /** @hidden */
- public _currentColorGradient: Nullable<ColorGradient>;
- /** @hidden */
- public _currentColor1 = new Color4(0, 0, 0, 0);
- /** @hidden */
- public _currentColor2 = new Color4(0, 0, 0, 0);
- /**
- * Creates a new instance Particle
- * @param particleSystem the particle system the particle belongs to
- */
- constructor(
- /**
- * particleSystem the particle system the particle belongs to.
- */
- public particleSystem: ParticleSystem) {
- if (!this.particleSystem.isAnimationSheetEnabled) {
- return;
- }
- this.updateCellInfoFromSystem();
- }
- private updateCellInfoFromSystem(): void {
- this.cellIndex = this.particleSystem.startSpriteCellID;
- }
- /**
- * Defines how the sprite cell index is updated for the particle
- */
- public updateCellIndex(): void {
- let dist = (this.particleSystem.endSpriteCellID - this.particleSystem.startSpriteCellID);
- let ratio = Scalar.Clamp(((this.age * this.particleSystem.spriteCellChangeSpeed) / this.lifeTime) % this.lifeTime);
- this.cellIndex = this.particleSystem.startSpriteCellID + (ratio * dist) | 0;
- }
- /**
- * Copy the properties of particle to another one.
- * @param other the particle to copy the information to.
- */
- public copyTo(other: Particle) {
- other.position.copyFrom(this.position);
- if (this._initialDirection) {
- if (other._initialDirection) {
- other._initialDirection.copyFrom(this._initialDirection);
- } else {
- other._initialDirection = this._initialDirection.clone();
- }
- } else {
- other._initialDirection = null;
- }
- other.direction.copyFrom(this.direction);
- other.color.copyFrom(this.color);
- other.colorStep.copyFrom(this.colorStep);
- other.lifeTime = this.lifeTime;
- other.age = this.age;
- other.size = this.size;
- other.scale.copyFrom(this.scale);
- other.angle = this.angle;
- other.angularSpeed = this.angularSpeed;
- other.particleSystem = this.particleSystem;
- other.cellIndex = this.cellIndex;
- if (this._currentColorGradient) {
- other._currentColorGradient = this._currentColorGradient;
- other._currentColor1.copyFrom(this._currentColor1);
- other._currentColor2.copyFrom(this._currentColor2);
- }
- }
- }
- }
|