babylon.particle.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. module BABYLON {
  2. export class Particle {
  3. public position = Vector3.Zero();
  4. public direction = Vector3.Zero();
  5. public color = new Color4(0, 0, 0, 0);
  6. public colorStep = new Color4(0, 0, 0, 0);
  7. public lifeTime = 1.0;
  8. public age = 0;
  9. public size = 0;
  10. public angle = 0;
  11. public angularSpeed = 0;
  12. constructor(private particleSystem: ParticleSystem, public cellIndex: number = 0, public invertU: number = 0, public invertV: number = 0, private _loopAnimation = false, private _fromIndex = 0, private _toIndex = 0, private _delay = 0, private _sheetDirection = 1, private _time = 0, private disposeWhenFinishedAnimating = false) {
  13. }
  14. public updateCellIndex(deltaTime: number): void {
  15. this._time += deltaTime;
  16. if (this._time > this._delay) {
  17. this._time = this._time % this._delay;
  18. this.cellIndex += this._sheetDirection;
  19. if (this.cellIndex > this._toIndex) {
  20. if (this._loopAnimation) {
  21. this.cellIndex = this._fromIndex;
  22. }
  23. else {
  24. this.cellIndex = this._toIndex;
  25. if (this.disposeWhenFinishedAnimating) {
  26. this.readyForRecycling();
  27. }
  28. }
  29. }
  30. }
  31. }
  32. public copyTo(other: Particle) {
  33. other.position.copyFrom(this.position);
  34. other.direction.copyFrom(this.direction);
  35. other.color.copyFrom(this.color);
  36. other.colorStep.copyFrom(this.colorStep);
  37. other.lifeTime = this.lifeTime;
  38. other.age = this.age;
  39. other.size = this.size;
  40. other.angle = this.angle;
  41. other.angularSpeed = this.angularSpeed;
  42. other.particleSystem = this.particleSystem;
  43. other.cellIndex = this.cellIndex;
  44. other.invertU = this.invertU;
  45. other.invertV = this.invertV;
  46. other._loopAnimation = this._loopAnimation;
  47. other._fromIndex = this._fromIndex;
  48. other._toIndex = this._toIndex;
  49. other._delay = this._delay;
  50. other._sheetDirection = this._sheetDirection;
  51. other._time = this._time;
  52. other.disposeWhenFinishedAnimating = this.disposeWhenFinishedAnimating;
  53. }
  54. public readyForRecycling() {
  55. this.age = this.lifeTime;
  56. }
  57. }
  58. }