babylon.animatable.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Animatable = (function () {
  4. function Animatable(scene, target, fromFrame, toFrame, loopAnimation, speedRatio, onAnimationEnd, animations) {
  5. if (typeof fromFrame === "undefined") { fromFrame = 0; }
  6. if (typeof toFrame === "undefined") { toFrame = 100; }
  7. if (typeof loopAnimation === "undefined") { loopAnimation = false; }
  8. if (typeof speedRatio === "undefined") { 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. this._paused = true;
  43. };
  44. Animatable.prototype.restart = function () {
  45. this._paused = false;
  46. };
  47. Animatable.prototype.stop = function () {
  48. var index = this._scene._activeAnimatables.indexOf(this);
  49. if (index > -1) {
  50. this._scene._activeAnimatables.splice(index, 1);
  51. }
  52. if (this.onAnimationEnd) {
  53. this.onAnimationEnd();
  54. }
  55. };
  56. Animatable.prototype._animate = function (delay) {
  57. if (this._paused) {
  58. return true;
  59. }
  60. if (!this._localDelayOffset) {
  61. this._localDelayOffset = delay;
  62. }
  63. // Animating
  64. var running = false;
  65. var animations = this._animations;
  66. for (var index = 0; index < animations.length; index++) {
  67. var animation = animations[index];
  68. var isRunning = animation.animate(delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this.speedRatio);
  69. running = running || isRunning;
  70. }
  71. if (!running && this.onAnimationEnd) {
  72. this.onAnimationEnd();
  73. }
  74. return running;
  75. };
  76. return Animatable;
  77. })();
  78. BABYLON.Animatable = Animatable;
  79. })(BABYLON || (BABYLON = {}));
  80. //# sourceMappingURL=babylon.animatable.js.map