three_src_math_MathUtils.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import "./chunk-JC4IRQUL.js";
  2. // node_modules/.pnpm/three@0.151.3/node_modules/three/src/math/MathUtils.js
  3. var _lut = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"];
  4. var _seed = 1234567;
  5. var DEG2RAD = Math.PI / 180;
  6. var RAD2DEG = 180 / Math.PI;
  7. function generateUUID() {
  8. const d0 = Math.random() * 4294967295 | 0;
  9. const d1 = Math.random() * 4294967295 | 0;
  10. const d2 = Math.random() * 4294967295 | 0;
  11. const d3 = Math.random() * 4294967295 | 0;
  12. const uuid = _lut[d0 & 255] + _lut[d0 >> 8 & 255] + _lut[d0 >> 16 & 255] + _lut[d0 >> 24 & 255] + "-" + _lut[d1 & 255] + _lut[d1 >> 8 & 255] + "-" + _lut[d1 >> 16 & 15 | 64] + _lut[d1 >> 24 & 255] + "-" + _lut[d2 & 63 | 128] + _lut[d2 >> 8 & 255] + "-" + _lut[d2 >> 16 & 255] + _lut[d2 >> 24 & 255] + _lut[d3 & 255] + _lut[d3 >> 8 & 255] + _lut[d3 >> 16 & 255] + _lut[d3 >> 24 & 255];
  13. return uuid.toLowerCase();
  14. }
  15. function clamp(value, min, max) {
  16. return Math.max(min, Math.min(max, value));
  17. }
  18. function euclideanModulo(n, m) {
  19. return (n % m + m) % m;
  20. }
  21. function mapLinear(x, a1, a2, b1, b2) {
  22. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  23. }
  24. function inverseLerp(x, y, value) {
  25. if (x !== y) {
  26. return (value - x) / (y - x);
  27. } else {
  28. return 0;
  29. }
  30. }
  31. function lerp(x, y, t) {
  32. return (1 - t) * x + t * y;
  33. }
  34. function damp(x, y, lambda, dt) {
  35. return lerp(x, y, 1 - Math.exp(-lambda * dt));
  36. }
  37. function pingpong(x, length = 1) {
  38. return length - Math.abs(euclideanModulo(x, length * 2) - length);
  39. }
  40. function smoothstep(x, min, max) {
  41. if (x <= min)
  42. return 0;
  43. if (x >= max)
  44. return 1;
  45. x = (x - min) / (max - min);
  46. return x * x * (3 - 2 * x);
  47. }
  48. function smootherstep(x, min, max) {
  49. if (x <= min)
  50. return 0;
  51. if (x >= max)
  52. return 1;
  53. x = (x - min) / (max - min);
  54. return x * x * x * (x * (x * 6 - 15) + 10);
  55. }
  56. function randInt(low, high) {
  57. return low + Math.floor(Math.random() * (high - low + 1));
  58. }
  59. function randFloat(low, high) {
  60. return low + Math.random() * (high - low);
  61. }
  62. function randFloatSpread(range) {
  63. return range * (0.5 - Math.random());
  64. }
  65. function seededRandom(s) {
  66. if (s !== void 0)
  67. _seed = s;
  68. let t = _seed += 1831565813;
  69. t = Math.imul(t ^ t >>> 15, t | 1);
  70. t ^= t + Math.imul(t ^ t >>> 7, t | 61);
  71. return ((t ^ t >>> 14) >>> 0) / 4294967296;
  72. }
  73. function degToRad(degrees) {
  74. return degrees * DEG2RAD;
  75. }
  76. function radToDeg(radians) {
  77. return radians * RAD2DEG;
  78. }
  79. function isPowerOfTwo(value) {
  80. return (value & value - 1) === 0 && value !== 0;
  81. }
  82. function ceilPowerOfTwo(value) {
  83. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  84. }
  85. function floorPowerOfTwo(value) {
  86. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  87. }
  88. function setQuaternionFromProperEuler(q, a, b, c, order) {
  89. const cos = Math.cos;
  90. const sin = Math.sin;
  91. const c2 = cos(b / 2);
  92. const s2 = sin(b / 2);
  93. const c13 = cos((a + c) / 2);
  94. const s13 = sin((a + c) / 2);
  95. const c1_3 = cos((a - c) / 2);
  96. const s1_3 = sin((a - c) / 2);
  97. const c3_1 = cos((c - a) / 2);
  98. const s3_1 = sin((c - a) / 2);
  99. switch (order) {
  100. case "XYX":
  101. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  102. break;
  103. case "YZY":
  104. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  105. break;
  106. case "ZXZ":
  107. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  108. break;
  109. case "XZX":
  110. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  111. break;
  112. case "YXY":
  113. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  114. break;
  115. case "ZYZ":
  116. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  117. break;
  118. default:
  119. console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: " + order);
  120. }
  121. }
  122. function denormalize(value, array) {
  123. switch (array.constructor) {
  124. case Float32Array:
  125. return value;
  126. case Uint16Array:
  127. return value / 65535;
  128. case Uint8Array:
  129. return value / 255;
  130. case Int16Array:
  131. return Math.max(value / 32767, -1);
  132. case Int8Array:
  133. return Math.max(value / 127, -1);
  134. default:
  135. throw new Error("Invalid component type.");
  136. }
  137. }
  138. function normalize(value, array) {
  139. switch (array.constructor) {
  140. case Float32Array:
  141. return value;
  142. case Uint16Array:
  143. return Math.round(value * 65535);
  144. case Uint8Array:
  145. return Math.round(value * 255);
  146. case Int16Array:
  147. return Math.round(value * 32767);
  148. case Int8Array:
  149. return Math.round(value * 127);
  150. default:
  151. throw new Error("Invalid component type.");
  152. }
  153. }
  154. var MathUtils = {
  155. DEG2RAD,
  156. RAD2DEG,
  157. generateUUID,
  158. clamp,
  159. euclideanModulo,
  160. mapLinear,
  161. inverseLerp,
  162. lerp,
  163. damp,
  164. pingpong,
  165. smoothstep,
  166. smootherstep,
  167. randInt,
  168. randFloat,
  169. randFloatSpread,
  170. seededRandom,
  171. degToRad,
  172. radToDeg,
  173. isPowerOfTwo,
  174. ceilPowerOfTwo,
  175. floorPowerOfTwo,
  176. setQuaternionFromProperEuler,
  177. normalize,
  178. denormalize
  179. };
  180. export {
  181. DEG2RAD,
  182. MathUtils,
  183. RAD2DEG,
  184. ceilPowerOfTwo,
  185. clamp,
  186. damp,
  187. degToRad,
  188. denormalize,
  189. euclideanModulo,
  190. floorPowerOfTwo,
  191. generateUUID,
  192. inverseLerp,
  193. isPowerOfTwo,
  194. lerp,
  195. mapLinear,
  196. normalize,
  197. pingpong,
  198. radToDeg,
  199. randFloat,
  200. randFloatSpread,
  201. randInt,
  202. seededRandom,
  203. setQuaternionFromProperEuler,
  204. smootherstep,
  205. smoothstep
  206. };
  207. //# sourceMappingURL=three_src_math_MathUtils.js.map