babylon.animatable.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.pause = function () {
  42. if (this._paused) {
  43. return;
  44. }
  45. this._paused = true;
  46. };
  47. Animatable.prototype.restart = function () {
  48. this._paused = false;
  49. };
  50. Animatable.prototype.stop = function () {
  51. var index = this._scene._activeAnimatables.indexOf(this);
  52. if (index > -1) {
  53. this._scene._activeAnimatables.splice(index, 1);
  54. }
  55. if (this.onAnimationEnd) {
  56. this.onAnimationEnd();
  57. }
  58. };
  59. Animatable.prototype._animate = function (delay) {
  60. if (this._paused) {
  61. if (!this._pausedDelay) {
  62. this._pausedDelay = delay;
  63. }
  64. return true;
  65. }
  66. if (!this._localDelayOffset) {
  67. this._localDelayOffset = delay;
  68. }
  69. else if (this._pausedDelay) {
  70. this._localDelayOffset += delay - this._pausedDelay;
  71. this._pausedDelay = null;
  72. }
  73. // Animating
  74. var running = false;
  75. var animations = this._animations;
  76. for (var index = 0; index < animations.length; index++) {
  77. var animation = animations[index];
  78. var isRunning = animation.animate(delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this.speedRatio);
  79. running = running || isRunning;
  80. }
  81. if (!running) {
  82. // Remove from active animatables
  83. index = this._scene._activeAnimatables.indexOf(this);
  84. this._scene._activeAnimatables.splice(index, 1);
  85. }
  86. if (!running && this.onAnimationEnd) {
  87. this.onAnimationEnd();
  88. }
  89. return running;
  90. };
  91. return Animatable;
  92. })();
  93. BABYLON.Animatable = Animatable;
  94. })(BABYLON || (BABYLON = {}));
  95. //# sourceMappingURL=babylon.animatable.js.map