babylon.animatable.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 && this.onAnimationEnd) {
  82. this.onAnimationEnd();
  83. }
  84. return running;
  85. };
  86. return Animatable;
  87. })();
  88. BABYLON.Animatable = Animatable;
  89. })(BABYLON || (BABYLON = {}));
  90. //# sourceMappingURL=babylon.animatable.js.map