babylon.easing.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var EasingFunction = (function () {
  10. function EasingFunction() {
  11. // Properties
  12. this._easingMode = EasingFunction.EASINGMODE_EASEIN;
  13. }
  14. Object.defineProperty(EasingFunction, "EASINGMODE_EASEIN", {
  15. get: function () {
  16. return EasingFunction._EASINGMODE_EASEIN;
  17. },
  18. enumerable: true,
  19. configurable: true
  20. });
  21. Object.defineProperty(EasingFunction, "EASINGMODE_EASEOUT", {
  22. get: function () {
  23. return EasingFunction._EASINGMODE_EASEOUT;
  24. },
  25. enumerable: true,
  26. configurable: true
  27. });
  28. Object.defineProperty(EasingFunction, "EASINGMODE_EASEINOUT", {
  29. get: function () {
  30. return EasingFunction._EASINGMODE_EASEINOUT;
  31. },
  32. enumerable: true,
  33. configurable: true
  34. });
  35. EasingFunction.prototype.setEasingMode = function (easingMode) {
  36. var n = Math.min(Math.max(easingMode, 0), 2);
  37. this._easingMode = n;
  38. };
  39. EasingFunction.prototype.getEasingMode = function () {
  40. return this._easingMode;
  41. };
  42. EasingFunction.prototype.easeInCore = function (gradient) {
  43. throw new Error('You must implement this method');
  44. };
  45. EasingFunction.prototype.ease = function (gradient) {
  46. switch (this._easingMode) {
  47. case EasingFunction.EASINGMODE_EASEIN:
  48. return this.easeInCore(gradient);
  49. case EasingFunction.EASINGMODE_EASEOUT:
  50. return (1 - this.easeInCore(1 - gradient));
  51. }
  52. if (gradient >= 0.5) {
  53. return (((1 - this.easeInCore((1 - gradient) * 2)) * 0.5) + 0.5);
  54. }
  55. return (this.easeInCore(gradient * 2) * 0.5);
  56. };
  57. //Statics
  58. EasingFunction._EASINGMODE_EASEIN = 0;
  59. EasingFunction._EASINGMODE_EASEOUT = 1;
  60. EasingFunction._EASINGMODE_EASEINOUT = 2;
  61. return EasingFunction;
  62. })();
  63. BABYLON.EasingFunction = EasingFunction;
  64. var CircleEase = (function (_super) {
  65. __extends(CircleEase, _super);
  66. function CircleEase() {
  67. _super.apply(this, arguments);
  68. }
  69. CircleEase.prototype.easeInCore = function (gradient) {
  70. gradient = Math.max(0, Math.min(1, gradient));
  71. return (1.0 - Math.sqrt(1.0 - (gradient * gradient)));
  72. };
  73. return CircleEase;
  74. })(EasingFunction);
  75. BABYLON.CircleEase = CircleEase;
  76. var BackEase = (function (_super) {
  77. __extends(BackEase, _super);
  78. function BackEase(amplitude) {
  79. if (amplitude === void 0) { amplitude = 1; }
  80. _super.call(this);
  81. this.amplitude = amplitude;
  82. }
  83. BackEase.prototype.easeInCore = function (gradient) {
  84. var num = Math.max(0, this.amplitude);
  85. return (Math.pow(gradient, 3.0) - ((gradient * num) * Math.sin(3.1415926535897931 * gradient)));
  86. };
  87. return BackEase;
  88. })(EasingFunction);
  89. BABYLON.BackEase = BackEase;
  90. var BounceEase = (function (_super) {
  91. __extends(BounceEase, _super);
  92. function BounceEase(bounces, bounciness) {
  93. if (bounces === void 0) { bounces = 3; }
  94. if (bounciness === void 0) { bounciness = 2; }
  95. _super.call(this);
  96. this.bounces = bounces;
  97. this.bounciness = bounciness;
  98. }
  99. BounceEase.prototype.easeInCore = function (gradient) {
  100. var y = Math.max(0.0, this.bounces);
  101. var bounciness = this.bounciness;
  102. if (bounciness <= 1.0) {
  103. bounciness = 1.001;
  104. }
  105. var num9 = Math.pow(bounciness, y);
  106. var num5 = 1.0 - bounciness;
  107. var num4 = ((1.0 - num9) / num5) + (num9 * 0.5);
  108. var num15 = gradient * num4;
  109. var num65 = Math.log((-num15 * (1.0 - bounciness)) + 1.0) / Math.log(bounciness);
  110. var num3 = Math.floor(num65);
  111. var num13 = num3 + 1.0;
  112. var num8 = (1.0 - Math.pow(bounciness, num3)) / (num5 * num4);
  113. var num12 = (1.0 - Math.pow(bounciness, num13)) / (num5 * num4);
  114. var num7 = (num8 + num12) * 0.5;
  115. var num6 = gradient - num7;
  116. var num2 = num7 - num8;
  117. return (((-Math.pow(1.0 / bounciness, y - num3) / (num2 * num2)) * (num6 - num2)) * (num6 + num2));
  118. };
  119. return BounceEase;
  120. })(EasingFunction);
  121. BABYLON.BounceEase = BounceEase;
  122. var CubicEase = (function (_super) {
  123. __extends(CubicEase, _super);
  124. function CubicEase() {
  125. _super.apply(this, arguments);
  126. }
  127. CubicEase.prototype.easeInCore = function (gradient) {
  128. return (gradient * gradient * gradient);
  129. };
  130. return CubicEase;
  131. })(EasingFunction);
  132. BABYLON.CubicEase = CubicEase;
  133. var ElasticEase = (function (_super) {
  134. __extends(ElasticEase, _super);
  135. function ElasticEase(oscillations, springiness) {
  136. if (oscillations === void 0) { oscillations = 3; }
  137. if (springiness === void 0) { springiness = 3; }
  138. _super.call(this);
  139. this.oscillations = oscillations;
  140. this.springiness = springiness;
  141. }
  142. ElasticEase.prototype.easeInCore = function (gradient) {
  143. var num2;
  144. var num3 = Math.max(0.0, this.oscillations);
  145. var num = Math.max(0.0, this.springiness);
  146. if (num == 0) {
  147. num2 = gradient;
  148. }
  149. else {
  150. num2 = (Math.exp(num * gradient) - 1.0) / (Math.exp(num) - 1.0);
  151. }
  152. return (num2 * Math.sin(((6.2831853071795862 * num3) + 1.5707963267948966) * gradient));
  153. };
  154. return ElasticEase;
  155. })(EasingFunction);
  156. BABYLON.ElasticEase = ElasticEase;
  157. var ExponentialEase = (function (_super) {
  158. __extends(ExponentialEase, _super);
  159. function ExponentialEase(exponent) {
  160. if (exponent === void 0) { exponent = 2; }
  161. _super.call(this);
  162. this.exponent = exponent;
  163. }
  164. ExponentialEase.prototype.easeInCore = function (gradient) {
  165. if (this.exponent <= 0) {
  166. return gradient;
  167. }
  168. return ((Math.exp(this.exponent * gradient) - 1.0) / (Math.exp(this.exponent) - 1.0));
  169. };
  170. return ExponentialEase;
  171. })(EasingFunction);
  172. BABYLON.ExponentialEase = ExponentialEase;
  173. var PowerEase = (function (_super) {
  174. __extends(PowerEase, _super);
  175. function PowerEase(power) {
  176. if (power === void 0) { power = 2; }
  177. _super.call(this);
  178. this.power = power;
  179. }
  180. PowerEase.prototype.easeInCore = function (gradient) {
  181. var y = Math.max(0.0, this.power);
  182. return Math.pow(gradient, y);
  183. };
  184. return PowerEase;
  185. })(EasingFunction);
  186. BABYLON.PowerEase = PowerEase;
  187. var QuadraticEase = (function (_super) {
  188. __extends(QuadraticEase, _super);
  189. function QuadraticEase() {
  190. _super.apply(this, arguments);
  191. }
  192. QuadraticEase.prototype.easeInCore = function (gradient) {
  193. return (gradient * gradient);
  194. };
  195. return QuadraticEase;
  196. })(EasingFunction);
  197. BABYLON.QuadraticEase = QuadraticEase;
  198. var QuarticEase = (function (_super) {
  199. __extends(QuarticEase, _super);
  200. function QuarticEase() {
  201. _super.apply(this, arguments);
  202. }
  203. QuarticEase.prototype.easeInCore = function (gradient) {
  204. return (gradient * gradient * gradient * gradient);
  205. };
  206. return QuarticEase;
  207. })(EasingFunction);
  208. BABYLON.QuarticEase = QuarticEase;
  209. var QuinticEase = (function (_super) {
  210. __extends(QuinticEase, _super);
  211. function QuinticEase() {
  212. _super.apply(this, arguments);
  213. }
  214. QuinticEase.prototype.easeInCore = function (gradient) {
  215. return (gradient * gradient * gradient * gradient * gradient);
  216. };
  217. return QuinticEase;
  218. })(EasingFunction);
  219. BABYLON.QuinticEase = QuinticEase;
  220. var SineEase = (function (_super) {
  221. __extends(SineEase, _super);
  222. function SineEase() {
  223. _super.apply(this, arguments);
  224. }
  225. SineEase.prototype.easeInCore = function (gradient) {
  226. return (1.0 - Math.sin(1.5707963267948966 * (1.0 - gradient)));
  227. };
  228. return SineEase;
  229. })(EasingFunction);
  230. BABYLON.SineEase = SineEase;
  231. var BezierCurveEase = (function (_super) {
  232. __extends(BezierCurveEase, _super);
  233. function BezierCurveEase(x1, y1, x2, y2) {
  234. if (x1 === void 0) { x1 = 0; }
  235. if (y1 === void 0) { y1 = 0; }
  236. if (x2 === void 0) { x2 = 1; }
  237. if (y2 === void 0) { y2 = 1; }
  238. _super.call(this);
  239. this.x1 = x1;
  240. this.y1 = y1;
  241. this.x2 = x2;
  242. this.y2 = y2;
  243. }
  244. BezierCurveEase.prototype.easeInCore = function (gradient) {
  245. return BABYLON.BezierCurve.interpolate(gradient, this.x1, this.y1, this.x2, this.y2);
  246. };
  247. return BezierCurveEase;
  248. })(EasingFunction);
  249. BABYLON.BezierCurveEase = BezierCurveEase;
  250. })(BABYLON || (BABYLON = {}));
  251. //# sourceMappingURL=babylon.easing.js.map