babylon.easing.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. EasingFunction._EASINGMODE_EASEIN = 0;
  58. EasingFunction._EASINGMODE_EASEOUT = 1;
  59. EasingFunction._EASINGMODE_EASEINOUT = 2;
  60. return EasingFunction;
  61. })();
  62. BABYLON.EasingFunction = EasingFunction;
  63. var CircleEase = (function (_super) {
  64. __extends(CircleEase, _super);
  65. function CircleEase() {
  66. _super.apply(this, arguments);
  67. }
  68. CircleEase.prototype.easeInCore = function (gradient) {
  69. gradient = Math.max(0, Math.min(1, gradient));
  70. return (1.0 - Math.sqrt(1.0 - (gradient * gradient)));
  71. };
  72. return CircleEase;
  73. })(EasingFunction);
  74. BABYLON.CircleEase = CircleEase;
  75. var BackEase = (function (_super) {
  76. __extends(BackEase, _super);
  77. function BackEase(amplitude) {
  78. if (typeof amplitude === "undefined") { amplitude = 1; }
  79. _super.call(this);
  80. this.amplitude = amplitude;
  81. }
  82. BackEase.prototype.easeInCore = function (gradient) {
  83. var num = Math.max(0, this.amplitude);
  84. return (Math.pow(gradient, 3.0) - ((gradient * num) * Math.sin(3.1415926535897931 * gradient)));
  85. };
  86. return BackEase;
  87. })(EasingFunction);
  88. BABYLON.BackEase = BackEase;
  89. var BounceEase = (function (_super) {
  90. __extends(BounceEase, _super);
  91. function BounceEase(bounces, bounciness) {
  92. if (typeof bounces === "undefined") { bounces = 3; }
  93. if (typeof bounciness === "undefined") { bounciness = 2; }
  94. _super.call(this);
  95. this.bounces = bounces;
  96. this.bounciness = bounciness;
  97. }
  98. BounceEase.prototype.easeInCore = function (gradient) {
  99. var y = Math.max(0.0, this.bounces);
  100. var bounciness = this.bounciness;
  101. if (bounciness <= 1.0) {
  102. bounciness = 1.001;
  103. }
  104. var num9 = Math.pow(bounciness, y);
  105. var num5 = 1.0 - bounciness;
  106. var num4 = ((1.0 - num9) / num5) + (num9 * 0.5);
  107. var num15 = gradient * num4;
  108. var num65 = Math.log((-num15 * (1.0 - bounciness)) + 1.0) / Math.log(bounciness);
  109. var num3 = Math.floor(num65);
  110. var num13 = num3 + 1.0;
  111. var num8 = (1.0 - Math.pow(bounciness, num3)) / (num5 * num4);
  112. var num12 = (1.0 - Math.pow(bounciness, num13)) / (num5 * num4);
  113. var num7 = (num8 + num12) * 0.5;
  114. var num6 = gradient - num7;
  115. var num2 = num7 - num8;
  116. return (((-Math.pow(1.0 / bounciness, y - num3) / (num2 * num2)) * (num6 - num2)) * (num6 + num2));
  117. };
  118. return BounceEase;
  119. })(EasingFunction);
  120. BABYLON.BounceEase = BounceEase;
  121. var CubicEase = (function (_super) {
  122. __extends(CubicEase, _super);
  123. function CubicEase() {
  124. _super.apply(this, arguments);
  125. }
  126. CubicEase.prototype.easeInCore = function (gradient) {
  127. return (gradient * gradient * gradient);
  128. };
  129. return CubicEase;
  130. })(EasingFunction);
  131. BABYLON.CubicEase = CubicEase;
  132. var ElasticEase = (function (_super) {
  133. __extends(ElasticEase, _super);
  134. function ElasticEase(oscillations, springiness) {
  135. if (typeof oscillations === "undefined") { oscillations = 3; }
  136. if (typeof springiness === "undefined") { springiness = 3; }
  137. _super.call(this);
  138. this.oscillations = oscillations;
  139. this.springiness = springiness;
  140. }
  141. ElasticEase.prototype.easeInCore = function (gradient) {
  142. var num2;
  143. var num3 = Math.max(0.0, this.oscillations);
  144. var num = Math.max(0.0, this.springiness);
  145. if (num == 0) {
  146. num2 = gradient;
  147. } else {
  148. num2 = (Math.exp(num * gradient) - 1.0) / (Math.exp(num) - 1.0);
  149. }
  150. return (num2 * Math.sin(((6.2831853071795862 * num3) + 1.5707963267948966) * gradient));
  151. };
  152. return ElasticEase;
  153. })(EasingFunction);
  154. BABYLON.ElasticEase = ElasticEase;
  155. var ExponentialEase = (function (_super) {
  156. __extends(ExponentialEase, _super);
  157. function ExponentialEase(exponent) {
  158. if (typeof exponent === "undefined") { exponent = 2; }
  159. _super.call(this);
  160. this.exponent = exponent;
  161. }
  162. ExponentialEase.prototype.easeInCore = function (gradient) {
  163. if (this.exponent <= 0) {
  164. return gradient;
  165. }
  166. return ((Math.exp(this.exponent * gradient) - 1.0) / (Math.exp(this.exponent) - 1.0));
  167. };
  168. return ExponentialEase;
  169. })(EasingFunction);
  170. BABYLON.ExponentialEase = ExponentialEase;
  171. var PowerEase = (function (_super) {
  172. __extends(PowerEase, _super);
  173. function PowerEase(power) {
  174. if (typeof power === "undefined") { power = 2; }
  175. _super.call(this);
  176. this.power = power;
  177. }
  178. PowerEase.prototype.easeInCore = function (gradient) {
  179. var y = Math.max(0.0, this.power);
  180. return Math.pow(gradient, y);
  181. };
  182. return PowerEase;
  183. })(EasingFunction);
  184. BABYLON.PowerEase = PowerEase;
  185. var QuadraticEase = (function (_super) {
  186. __extends(QuadraticEase, _super);
  187. function QuadraticEase() {
  188. _super.apply(this, arguments);
  189. }
  190. QuadraticEase.prototype.easeInCore = function (gradient) {
  191. return (gradient * gradient);
  192. };
  193. return QuadraticEase;
  194. })(EasingFunction);
  195. BABYLON.QuadraticEase = QuadraticEase;
  196. var QuarticEase = (function (_super) {
  197. __extends(QuarticEase, _super);
  198. function QuarticEase() {
  199. _super.apply(this, arguments);
  200. }
  201. QuarticEase.prototype.easeInCore = function (gradient) {
  202. return (gradient * gradient * gradient * gradient);
  203. };
  204. return QuarticEase;
  205. })(EasingFunction);
  206. BABYLON.QuarticEase = QuarticEase;
  207. var QuinticEase = (function (_super) {
  208. __extends(QuinticEase, _super);
  209. function QuinticEase() {
  210. _super.apply(this, arguments);
  211. }
  212. QuinticEase.prototype.easeInCore = function (gradient) {
  213. return (gradient * gradient * gradient * gradient * gradient);
  214. };
  215. return QuinticEase;
  216. })(EasingFunction);
  217. BABYLON.QuinticEase = QuinticEase;
  218. var SineEase = (function (_super) {
  219. __extends(SineEase, _super);
  220. function SineEase() {
  221. _super.apply(this, arguments);
  222. }
  223. SineEase.prototype.easeInCore = function (gradient) {
  224. return (1.0 - Math.sin(1.5707963267948966 * (1.0 - gradient)));
  225. };
  226. return SineEase;
  227. })(EasingFunction);
  228. BABYLON.SineEase = SineEase;
  229. var BezierCurveEase = (function (_super) {
  230. __extends(BezierCurveEase, _super);
  231. function BezierCurveEase(x1, y1, x2, y2) {
  232. if (typeof x1 === "undefined") { x1 = 0; }
  233. if (typeof y1 === "undefined") { y1 = 0; }
  234. if (typeof x2 === "undefined") { x2 = 1; }
  235. if (typeof y2 === "undefined") { y2 = 1; }
  236. _super.call(this);
  237. this.x1 = x1;
  238. this.y1 = y1;
  239. this.x2 = x2;
  240. this.y2 = y2;
  241. }
  242. BezierCurveEase.prototype.easeInCore = function (gradient) {
  243. return BABYLON.BezierCurve.interpolate(gradient, this.x1, this.y1, this.x2, this.y2);
  244. };
  245. return BezierCurveEase;
  246. })(EasingFunction);
  247. BABYLON.BezierCurveEase = BezierCurveEase;
  248. })(BABYLON || (BABYLON = {}));
  249. //# sourceMappingURL=babylon.easing.js.map