babylon.animatable.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Animatable = (function () {
  4. function Animatable(scene, target, fromFrame, toFrame, loopAnimation, speedRatio, onAnimationEnd, animations) {
  5. if (fromFrame === void 0) { fromFrame = 0; }
  6. if (toFrame === void 0) { toFrame = 100; }
  7. if (loopAnimation === void 0) { loopAnimation = false; }
  8. if (speedRatio === void 0) { speedRatio = 1.0; }
  9. this.target = target;
  10. this.fromFrame = fromFrame;
  11. this.toFrame = toFrame;
  12. this.loopAnimation = loopAnimation;
  13. this.speedRatio = speedRatio;
  14. this.onAnimationEnd = onAnimationEnd;
  15. this._animations = new Array();
  16. this._paused = false;
  17. this.animationStarted = false;
  18. if (animations) {
  19. this.appendAnimations(target, animations);
  20. }
  21. this._scene = scene;
  22. scene._activeAnimatables.push(this);
  23. }
  24. // Methods
  25. Animatable.prototype.appendAnimations = function (target, animations) {
  26. for (var index = 0; index < animations.length; index++) {
  27. var animation = animations[index];
  28. animation._target = target;
  29. this._animations.push(animation);
  30. }
  31. };
  32. Animatable.prototype.getAnimationByTargetProperty = function (property) {
  33. var animations = this._animations;
  34. for (var index = 0; index < animations.length; index++) {
  35. if (animations[index].targetProperty === property) {
  36. return animations[index];
  37. }
  38. }
  39. return null;
  40. };
  41. Animatable.prototype.reset = function () {
  42. var animations = this._animations;
  43. for (var index = 0; index < animations.length; index++) {
  44. animations[index].reset();
  45. }
  46. this._localDelayOffset = null;
  47. this._pausedDelay = null;
  48. };
  49. Animatable.prototype.pause = function () {
  50. if (this._paused) {
  51. return;
  52. }
  53. this._paused = true;
  54. };
  55. Animatable.prototype.restart = function () {
  56. this._paused = false;
  57. };
  58. Animatable.prototype.stop = function () {
  59. var index = this._scene._activeAnimatables.indexOf(this);
  60. if (index > -1) {
  61. this._scene._activeAnimatables.splice(index, 1);
  62. }
  63. if (this.onAnimationEnd) {
  64. this.onAnimationEnd();
  65. }
  66. };
  67. Animatable.prototype._animate = function (delay) {
  68. if (this._paused) {
  69. if (!this._pausedDelay) {
  70. this._pausedDelay = delay;
  71. }
  72. return true;
  73. }
  74. if (!this._localDelayOffset) {
  75. this._localDelayOffset = delay;
  76. }
  77. else if (this._pausedDelay) {
  78. this._localDelayOffset += delay - this._pausedDelay;
  79. this._pausedDelay = null;
  80. }
  81. // Animating
  82. var running = false;
  83. var animations = this._animations;
  84. for (var index = 0; index < animations.length; index++) {
  85. var animation = animations[index];
  86. var isRunning = animation.animate(delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this.speedRatio);
  87. running = running || isRunning;
  88. }
  89. if (!running) {
  90. // Remove from active animatables
  91. index = this._scene._activeAnimatables.indexOf(this);
  92. this._scene._activeAnimatables.splice(index, 1);
  93. }
  94. if (!running && this.onAnimationEnd) {
  95. this.onAnimationEnd();
  96. }
  97. return running;
  98. };
  99. return Animatable;
  100. })();
  101. BABYLON.Animatable = Animatable;
  102. })(BABYLON || (BABYLON = {}));
  103. //# sourceMappingURL=babylon.animatable.js.map