babylon.animatable.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON._Animatable = function (target, from, to, loop, speedRatio, onAnimationEnd) {
  5. this.target = target;
  6. this.fromFrame = from;
  7. this.toFrame = to;
  8. this.loopAnimation = loop;
  9. this.speedRatio = speedRatio ? speedRatio : 1.0;
  10. this.onAnimationEnd = onAnimationEnd;
  11. };
  12. // Members
  13. BABYLON._Animatable.prototype.target = null;
  14. BABYLON._Animatable.prototype.animationStarted = false;
  15. BABYLON._Animatable.prototype.loopAnimation = false;
  16. BABYLON._Animatable.prototype.fromFrame = 0;
  17. BABYLON._Animatable.prototype.toFrame = 100;
  18. BABYLON._Animatable.prototype.speedRatio = 1.0;
  19. // Methods
  20. BABYLON._Animatable.prototype._animate = function (delay) {
  21. if (!this._localDelayOffset) {
  22. this._localDelayOffset = delay;
  23. }
  24. // Animating
  25. var running = false;
  26. var animations = this.target.animations;
  27. for (var index = 0; index < animations.length; index++) {
  28. var isRunning = animations[index].animate(this.target, delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this.speedRatio);
  29. running = running || isRunning;
  30. }
  31. if (!running && this.onAnimationEnd) {
  32. this.onAnimationEnd();
  33. }
  34. return running;
  35. };
  36. })();