babylon.animatable.js 1.4 KB

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