@forgeax/engine-math 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +294 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/__tests__/_arbs.d.ts +36 -0
  5. package/dist/__tests__/_arbs.d.ts.map +1 -0
  6. package/dist/__tests__/_fixtures.d.ts +61 -0
  7. package/dist/__tests__/_fixtures.d.ts.map +1 -0
  8. package/dist/__tests__/bounds2.test.d.ts +2 -0
  9. package/dist/__tests__/bounds2.test.d.ts.map +1 -0
  10. package/dist/__tests__/box3.test.d.ts +2 -0
  11. package/dist/__tests__/box3.test.d.ts.map +1 -0
  12. package/dist/__tests__/easing.test.d.ts +2 -0
  13. package/dist/__tests__/easing.test.d.ts.map +1 -0
  14. package/dist/__tests__/euler.test-d.d.ts +2 -0
  15. package/dist/__tests__/euler.test-d.d.ts.map +1 -0
  16. package/dist/__tests__/mat3.test-d.d.ts +2 -0
  17. package/dist/__tests__/mat3.test-d.d.ts.map +1 -0
  18. package/dist/__tests__/mat4.property.test.d.ts +2 -0
  19. package/dist/__tests__/mat4.property.test.d.ts.map +1 -0
  20. package/dist/__tests__/mat4.test-d.d.ts +2 -0
  21. package/dist/__tests__/mat4.test-d.d.ts.map +1 -0
  22. package/dist/__tests__/mat4.test.d.ts +2 -0
  23. package/dist/__tests__/mat4.test.d.ts.map +1 -0
  24. package/dist/__tests__/noise.test.d.ts +2 -0
  25. package/dist/__tests__/noise.test.d.ts.map +1 -0
  26. package/dist/__tests__/quat.basis.test.d.ts +2 -0
  27. package/dist/__tests__/quat.basis.test.d.ts.map +1 -0
  28. package/dist/__tests__/quat.interpolation.test.d.ts +2 -0
  29. package/dist/__tests__/quat.interpolation.test.d.ts.map +1 -0
  30. package/dist/__tests__/quat.lookat.test.d.ts +2 -0
  31. package/dist/__tests__/quat.lookat.test.d.ts.map +1 -0
  32. package/dist/__tests__/quat.property.test.d.ts +2 -0
  33. package/dist/__tests__/quat.property.test.d.ts.map +1 -0
  34. package/dist/__tests__/quat.rotateaxis.test.d.ts +2 -0
  35. package/dist/__tests__/quat.rotateaxis.test.d.ts.map +1 -0
  36. package/dist/__tests__/quat.test-d.d.ts +2 -0
  37. package/dist/__tests__/quat.test-d.d.ts.map +1 -0
  38. package/dist/__tests__/ray.property.test.d.ts +2 -0
  39. package/dist/__tests__/ray.property.test.d.ts.map +1 -0
  40. package/dist/__tests__/ray.test.d.ts +2 -0
  41. package/dist/__tests__/ray.test.d.ts.map +1 -0
  42. package/dist/__tests__/types.test-d.d.ts +2 -0
  43. package/dist/__tests__/types.test-d.d.ts.map +1 -0
  44. package/dist/__tests__/vec-catmull-rom.test.d.ts +2 -0
  45. package/dist/__tests__/vec-catmull-rom.test.d.ts.map +1 -0
  46. package/dist/__tests__/vec-smooth-damp.test.d.ts +2 -0
  47. package/dist/__tests__/vec-smooth-damp.test.d.ts.map +1 -0
  48. package/dist/__tests__/vec2.test-d.d.ts +2 -0
  49. package/dist/__tests__/vec2.test-d.d.ts.map +1 -0
  50. package/dist/__tests__/vec3.property.test.d.ts +2 -0
  51. package/dist/__tests__/vec3.property.test.d.ts.map +1 -0
  52. package/dist/__tests__/vec3.test-d.d.ts +2 -0
  53. package/dist/__tests__/vec3.test-d.d.ts.map +1 -0
  54. package/dist/__tests__/vec4.test-d.d.ts +2 -0
  55. package/dist/__tests__/vec4.test-d.d.ts.map +1 -0
  56. package/dist/_internal/epsilon.d.ts +9 -0
  57. package/dist/_internal/epsilon.d.ts.map +1 -0
  58. package/dist/_internal/scalar.d.ts +40 -0
  59. package/dist/_internal/scalar.d.ts.map +1 -0
  60. package/dist/box2.d.ts +35 -0
  61. package/dist/box2.d.ts.map +1 -0
  62. package/dist/box3.d.ts +76 -0
  63. package/dist/box3.d.ts.map +1 -0
  64. package/dist/circle2.d.ts +29 -0
  65. package/dist/circle2.d.ts.map +1 -0
  66. package/dist/color.d.ts +64 -0
  67. package/dist/color.d.ts.map +1 -0
  68. package/dist/easing.d.ts +18 -0
  69. package/dist/easing.d.ts.map +1 -0
  70. package/dist/euler.d.ts +51 -0
  71. package/dist/euler.d.ts.map +1 -0
  72. package/dist/f32-to-f16-bytes.d.ts +10 -0
  73. package/dist/f32-to-f16-bytes.d.ts.map +1 -0
  74. package/dist/frustum.d.ts +49 -0
  75. package/dist/frustum.d.ts.map +1 -0
  76. package/dist/index.d.ts +20 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.mjs +3688 -0
  79. package/dist/index.mjs.map +1 -0
  80. package/dist/mat3.d.ts +70 -0
  81. package/dist/mat3.d.ts.map +1 -0
  82. package/dist/mat4.d.ts +329 -0
  83. package/dist/mat4.d.ts.map +1 -0
  84. package/dist/noise.d.ts +12 -0
  85. package/dist/noise.d.ts.map +1 -0
  86. package/dist/quat.d.ts +312 -0
  87. package/dist/quat.d.ts.map +1 -0
  88. package/dist/ray.d.ts +144 -0
  89. package/dist/ray.d.ts.map +1 -0
  90. package/dist/ray2.d.ts +38 -0
  91. package/dist/ray2.d.ts.map +1 -0
  92. package/dist/sphere.d.ts +41 -0
  93. package/dist/sphere.d.ts.map +1 -0
  94. package/dist/types.d.ts +57 -0
  95. package/dist/types.d.ts.map +1 -0
  96. package/dist/vec2.d.ts +76 -0
  97. package/dist/vec2.d.ts.map +1 -0
  98. package/dist/vec3.d.ts +82 -0
  99. package/dist/vec3.d.ts.map +1 -0
  100. package/dist/vec4.d.ts +61 -0
  101. package/dist/vec4.d.ts.map +1 -0
  102. package/package.json +57 -0
  103. package/src/__tests__/_arbs.ts +149 -0
  104. package/src/__tests__/_fixtures.ts +118 -0
  105. package/src/__tests__/bounds2.test.ts +146 -0
  106. package/src/__tests__/box3.test.ts +277 -0
  107. package/src/__tests__/easing.test.ts +109 -0
  108. package/src/__tests__/euler.test-d.ts +63 -0
  109. package/src/__tests__/mat3.test-d.ts +47 -0
  110. package/src/__tests__/mat4.property.test.ts +256 -0
  111. package/src/__tests__/mat4.test-d.ts +130 -0
  112. package/src/__tests__/mat4.test.ts +162 -0
  113. package/src/__tests__/noise.test.ts +75 -0
  114. package/src/__tests__/quat.basis.test.ts +134 -0
  115. package/src/__tests__/quat.interpolation.test.ts +45 -0
  116. package/src/__tests__/quat.lookat.test.ts +103 -0
  117. package/src/__tests__/quat.property.test.ts +150 -0
  118. package/src/__tests__/quat.rotateaxis.test.ts +149 -0
  119. package/src/__tests__/quat.test-d.ts +138 -0
  120. package/src/__tests__/ray.property.test.ts +105 -0
  121. package/src/__tests__/ray.test.ts +539 -0
  122. package/src/__tests__/types.test-d.ts +64 -0
  123. package/src/__tests__/vec-catmull-rom.test.ts +125 -0
  124. package/src/__tests__/vec-smooth-damp.test.ts +167 -0
  125. package/src/__tests__/vec2.test-d.ts +59 -0
  126. package/src/__tests__/vec3.property.test.ts +72 -0
  127. package/src/__tests__/vec3.test-d.ts +65 -0
  128. package/src/__tests__/vec4.test-d.ts +61 -0
  129. package/src/_internal/epsilon.ts +29 -0
  130. package/src/_internal/scalar.ts +90 -0
  131. package/src/box2.ts +168 -0
  132. package/src/box3.ts +372 -0
  133. package/src/circle2.ts +134 -0
  134. package/src/color.ts +177 -0
  135. package/src/easing.ts +49 -0
  136. package/src/euler.ts +239 -0
  137. package/src/f32-to-f16-bytes.ts +71 -0
  138. package/src/frustum.ts +240 -0
  139. package/src/index.ts +65 -0
  140. package/src/mat3.ts +286 -0
  141. package/src/mat4.ts +1334 -0
  142. package/src/noise.ts +78 -0
  143. package/src/quat.ts +847 -0
  144. package/src/ray.ts +575 -0
  145. package/src/ray2.ts +198 -0
  146. package/src/sphere.ts +138 -0
  147. package/src/types.ts +78 -0
  148. package/src/vec2.ts +229 -0
  149. package/src/vec3.ts +294 -0
  150. package/src/vec4.ts +235 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,3688 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/box2.ts
8
+ var box2_exports = {};
9
+ __export(box2_exports, {
10
+ center: () => center,
11
+ closestPoint: () => closestPoint,
12
+ containsBox: () => containsBox,
13
+ containsPoint: () => containsPoint,
14
+ create: () => create,
15
+ fromCenter: () => fromCenter,
16
+ fromPoints: () => fromPoints,
17
+ grow: () => grow,
18
+ halfSize: () => halfSize,
19
+ intersectsBox: () => intersectsBox,
20
+ intersectsCircle: () => intersectsCircle,
21
+ merge: () => merge,
22
+ shrink: () => shrink
23
+ });
24
+ function create(minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY) {
25
+ return Float32Array.of(minX, minY, maxX, maxY);
26
+ }
27
+ function fromCenter(out, center3, halfSize2) {
28
+ const cx = center3[0];
29
+ const cy = center3[1];
30
+ const hx = Math.abs(halfSize2[0]);
31
+ const hy = Math.abs(halfSize2[1]);
32
+ out[0] = cx - hx;
33
+ out[1] = cy - hy;
34
+ out[2] = cx + hx;
35
+ out[3] = cy + hy;
36
+ return out;
37
+ }
38
+ function fromPoints(out, points) {
39
+ out[0] = Number.POSITIVE_INFINITY;
40
+ out[1] = Number.POSITIVE_INFINITY;
41
+ out[2] = Number.NEGATIVE_INFINITY;
42
+ out[3] = Number.NEGATIVE_INFINITY;
43
+ for (let i = 0; i < points.length; i++) {
44
+ const point = points[i];
45
+ const x = point[0];
46
+ const y = point[1];
47
+ if (x < out[0]) out[0] = x;
48
+ if (y < out[1]) out[1] = y;
49
+ if (x > out[2]) out[2] = x;
50
+ if (y > out[3]) out[3] = y;
51
+ }
52
+ return out;
53
+ }
54
+ function center(out, box) {
55
+ out[0] = (box[0] + box[2]) * 0.5;
56
+ out[1] = (box[1] + box[3]) * 0.5;
57
+ return out;
58
+ }
59
+ function halfSize(out, box) {
60
+ out[0] = (box[2] - box[0]) * 0.5;
61
+ out[1] = (box[3] - box[1]) * 0.5;
62
+ return out;
63
+ }
64
+ function closestPoint(out, box, point) {
65
+ const x = point[0];
66
+ const y = point[1];
67
+ const minX = box[0];
68
+ const minY = box[1];
69
+ const maxX = box[2];
70
+ const maxY = box[3];
71
+ out[0] = x < minX ? minX : x > maxX ? maxX : x;
72
+ out[1] = y < minY ? minY : y > maxY ? maxY : y;
73
+ return out;
74
+ }
75
+ function containsPoint(box, point) {
76
+ const x = point[0];
77
+ const y = point[1];
78
+ return x >= box[0] && x <= box[2] && y >= box[1] && y <= box[3];
79
+ }
80
+ function containsBox(box, other) {
81
+ return other[0] >= box[0] && other[1] >= box[1] && other[2] <= box[2] && other[3] <= box[3];
82
+ }
83
+ function intersectsBox(a, b) {
84
+ return a[2] >= b[0] && a[0] <= b[2] && a[3] >= b[1] && a[1] <= b[3];
85
+ }
86
+ function intersectsCircle(box, circle) {
87
+ const cx = circle[0];
88
+ const cy = circle[1];
89
+ const radius2 = circle[2];
90
+ if (radius2 < 0) return false;
91
+ const closestX = cx < box[0] ? box[0] : cx > box[2] ? box[2] : cx;
92
+ const closestY = cy < box[1] ? box[1] : cy > box[3] ? box[3] : cy;
93
+ const dx = cx - closestX;
94
+ const dy = cy - closestY;
95
+ return dx * dx + dy * dy <= radius2 * radius2;
96
+ }
97
+ function merge(out, a, b) {
98
+ out[0] = Math.min(a[0], b[0]);
99
+ out[1] = Math.min(a[1], b[1]);
100
+ out[2] = Math.max(a[2], b[2]);
101
+ out[3] = Math.max(a[3], b[3]);
102
+ return out;
103
+ }
104
+ function grow(out, box, amount) {
105
+ const x = Math.abs(amount[0]);
106
+ const y = Math.abs(amount[1]);
107
+ out[0] = box[0] - x;
108
+ out[1] = box[1] - y;
109
+ out[2] = box[2] + x;
110
+ out[3] = box[3] + y;
111
+ return out;
112
+ }
113
+ function shrink(out, box, amount) {
114
+ const x = Math.abs(amount[0]);
115
+ const y = Math.abs(amount[1]);
116
+ out[0] = box[0] + x;
117
+ out[1] = box[1] + y;
118
+ out[2] = box[2] - x;
119
+ out[3] = box[3] - y;
120
+ return out;
121
+ }
122
+
123
+ // src/box3.ts
124
+ var box3_exports = {};
125
+ __export(box3_exports, {
126
+ containsPoint: () => containsPoint2,
127
+ create: () => create2,
128
+ expandByPoint: () => expandByPoint,
129
+ fromPoints: () => fromPoints2,
130
+ fromPositions: () => fromPositions,
131
+ intersectsBox: () => intersectsBox2,
132
+ transformBox3: () => transformBox3
133
+ });
134
+ function create2(minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, minZ = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY, maxZ = Number.NEGATIVE_INFINITY) {
135
+ return Float32Array.of(minX, minY, minZ, maxX, maxY, maxZ);
136
+ }
137
+ function expandByPoint(out, point) {
138
+ const px = point[0];
139
+ const py = point[1];
140
+ const pz = point[2];
141
+ if (px < out[0]) out[0] = px;
142
+ if (py < out[1]) out[1] = py;
143
+ if (pz < out[2]) out[2] = pz;
144
+ if (px > out[3]) out[3] = px;
145
+ if (py > out[4]) out[4] = py;
146
+ if (pz > out[5]) out[5] = pz;
147
+ return out;
148
+ }
149
+ function containsPoint2(box, point) {
150
+ const px = point[0];
151
+ const py = point[1];
152
+ const pz = point[2];
153
+ return px >= box[0] && px <= box[3] && py >= box[1] && py <= box[4] && pz >= box[2] && pz <= box[5];
154
+ }
155
+ function intersectsBox2(a, b) {
156
+ return a[3] >= b[0] && a[0] <= b[3] && a[4] >= b[1] && a[1] <= b[4] && a[5] >= b[2] && a[2] <= b[5];
157
+ }
158
+ function fromPoints2(out, points) {
159
+ out[0] = Number.POSITIVE_INFINITY;
160
+ out[1] = Number.POSITIVE_INFINITY;
161
+ out[2] = Number.POSITIVE_INFINITY;
162
+ out[3] = Number.NEGATIVE_INFINITY;
163
+ out[4] = Number.NEGATIVE_INFINITY;
164
+ out[5] = Number.NEGATIVE_INFINITY;
165
+ for (let i = 0; i < points.length; i++) {
166
+ const p = points[i];
167
+ const px = p[0];
168
+ const py = p[1];
169
+ const pz = p[2];
170
+ if (px < out[0]) out[0] = px;
171
+ if (py < out[1]) out[1] = py;
172
+ if (pz < out[2]) out[2] = pz;
173
+ if (px > out[3]) out[3] = px;
174
+ if (py > out[4]) out[4] = py;
175
+ if (pz > out[5]) out[5] = pz;
176
+ }
177
+ return out;
178
+ }
179
+ function fromPositions(out, positions) {
180
+ out[0] = Number.POSITIVE_INFINITY;
181
+ out[1] = Number.POSITIVE_INFINITY;
182
+ out[2] = Number.POSITIVE_INFINITY;
183
+ out[3] = Number.NEGATIVE_INFINITY;
184
+ out[4] = Number.NEGATIVE_INFINITY;
185
+ out[5] = Number.NEGATIVE_INFINITY;
186
+ if (positions.length < 3) return out;
187
+ let minX = positions[0];
188
+ let minY = positions[1];
189
+ let minZ = positions[2];
190
+ let maxX = minX;
191
+ let maxY = minY;
192
+ let maxZ = minZ;
193
+ for (let i = 3; i < positions.length; i += 3) {
194
+ const x = positions[i];
195
+ const y = positions[i + 1];
196
+ const z = positions[i + 2];
197
+ if (x < minX) minX = x;
198
+ if (y < minY) minY = y;
199
+ if (z < minZ) minZ = z;
200
+ if (x > maxX) maxX = x;
201
+ if (y > maxY) maxY = y;
202
+ if (z > maxZ) maxZ = z;
203
+ }
204
+ out[0] = minX;
205
+ out[1] = minY;
206
+ out[2] = minZ;
207
+ out[3] = maxX;
208
+ out[4] = maxY;
209
+ out[5] = maxZ;
210
+ return out;
211
+ }
212
+ function transformBox3(out, box, m) {
213
+ const bx = box[0];
214
+ const by = box[1];
215
+ const bz = box[2];
216
+ const bX = box[3];
217
+ const bY = box[4];
218
+ const bZ = box[5];
219
+ const m00 = m[0];
220
+ const m01 = m[1];
221
+ const m02 = m[2];
222
+ const m03 = m[3];
223
+ const m10 = m[4];
224
+ const m11 = m[5];
225
+ const m12 = m[6];
226
+ const m13 = m[7];
227
+ const m20 = m[8];
228
+ const m21 = m[9];
229
+ const m22 = m[10];
230
+ const m23 = m[11];
231
+ const m30 = m[12];
232
+ const m31 = m[13];
233
+ const m32 = m[14];
234
+ const m33 = m[15];
235
+ let x = m00 * bx + m10 * by + m20 * bz + m30;
236
+ let y = m01 * bx + m11 * by + m21 * bz + m31;
237
+ let z = m02 * bx + m12 * by + m22 * bz + m32;
238
+ let w = m03 * bx + m13 * by + m23 * bz + m33;
239
+ if (w !== 0) {
240
+ const iw = 1 / w;
241
+ x *= iw;
242
+ y *= iw;
243
+ z *= iw;
244
+ }
245
+ let minX = x, maxX = x, minY = y, maxY = y, minZ = z, maxZ = z;
246
+ x = m00 * bX + m10 * by + m20 * bz + m30;
247
+ y = m01 * bX + m11 * by + m21 * bz + m31;
248
+ z = m02 * bX + m12 * by + m22 * bz + m32;
249
+ w = m03 * bX + m13 * by + m23 * bz + m33;
250
+ if (w !== 0) {
251
+ const iw = 1 / w;
252
+ x *= iw;
253
+ y *= iw;
254
+ z *= iw;
255
+ }
256
+ if (x < minX) minX = x;
257
+ if (x > maxX) maxX = x;
258
+ if (y < minY) minY = y;
259
+ if (y > maxY) maxY = y;
260
+ if (z < minZ) minZ = z;
261
+ if (z > maxZ) maxZ = z;
262
+ x = m00 * bx + m10 * bY + m20 * bz + m30;
263
+ y = m01 * bx + m11 * bY + m21 * bz + m31;
264
+ z = m02 * bx + m12 * bY + m22 * bz + m32;
265
+ w = m03 * bx + m13 * bY + m23 * bz + m33;
266
+ if (w !== 0) {
267
+ const iw = 1 / w;
268
+ x *= iw;
269
+ y *= iw;
270
+ z *= iw;
271
+ }
272
+ if (x < minX) minX = x;
273
+ if (x > maxX) maxX = x;
274
+ if (y < minY) minY = y;
275
+ if (y > maxY) maxY = y;
276
+ if (z < minZ) minZ = z;
277
+ if (z > maxZ) maxZ = z;
278
+ x = m00 * bX + m10 * bY + m20 * bz + m30;
279
+ y = m01 * bX + m11 * bY + m21 * bz + m31;
280
+ z = m02 * bX + m12 * bY + m22 * bz + m32;
281
+ w = m03 * bX + m13 * bY + m23 * bz + m33;
282
+ if (w !== 0) {
283
+ const iw = 1 / w;
284
+ x *= iw;
285
+ y *= iw;
286
+ z *= iw;
287
+ }
288
+ if (x < minX) minX = x;
289
+ if (x > maxX) maxX = x;
290
+ if (y < minY) minY = y;
291
+ if (y > maxY) maxY = y;
292
+ if (z < minZ) minZ = z;
293
+ if (z > maxZ) maxZ = z;
294
+ x = m00 * bx + m10 * by + m20 * bZ + m30;
295
+ y = m01 * bx + m11 * by + m21 * bZ + m31;
296
+ z = m02 * bx + m12 * by + m22 * bZ + m32;
297
+ w = m03 * bx + m13 * by + m23 * bZ + m33;
298
+ if (w !== 0) {
299
+ const iw = 1 / w;
300
+ x *= iw;
301
+ y *= iw;
302
+ z *= iw;
303
+ }
304
+ if (x < minX) minX = x;
305
+ if (x > maxX) maxX = x;
306
+ if (y < minY) minY = y;
307
+ if (y > maxY) maxY = y;
308
+ if (z < minZ) minZ = z;
309
+ if (z > maxZ) maxZ = z;
310
+ x = m00 * bX + m10 * by + m20 * bZ + m30;
311
+ y = m01 * bX + m11 * by + m21 * bZ + m31;
312
+ z = m02 * bX + m12 * by + m22 * bZ + m32;
313
+ w = m03 * bX + m13 * by + m23 * bZ + m33;
314
+ if (w !== 0) {
315
+ const iw = 1 / w;
316
+ x *= iw;
317
+ y *= iw;
318
+ z *= iw;
319
+ }
320
+ if (x < minX) minX = x;
321
+ if (x > maxX) maxX = x;
322
+ if (y < minY) minY = y;
323
+ if (y > maxY) maxY = y;
324
+ if (z < minZ) minZ = z;
325
+ if (z > maxZ) maxZ = z;
326
+ x = m00 * bx + m10 * bY + m20 * bZ + m30;
327
+ y = m01 * bx + m11 * bY + m21 * bZ + m31;
328
+ z = m02 * bx + m12 * bY + m22 * bZ + m32;
329
+ w = m03 * bx + m13 * bY + m23 * bZ + m33;
330
+ if (w !== 0) {
331
+ const iw = 1 / w;
332
+ x *= iw;
333
+ y *= iw;
334
+ z *= iw;
335
+ }
336
+ if (x < minX) minX = x;
337
+ if (x > maxX) maxX = x;
338
+ if (y < minY) minY = y;
339
+ if (y > maxY) maxY = y;
340
+ if (z < minZ) minZ = z;
341
+ if (z > maxZ) maxZ = z;
342
+ x = m00 * bX + m10 * bY + m20 * bZ + m30;
343
+ y = m01 * bX + m11 * bY + m21 * bZ + m31;
344
+ z = m02 * bX + m12 * bY + m22 * bZ + m32;
345
+ w = m03 * bX + m13 * bY + m23 * bZ + m33;
346
+ if (w !== 0) {
347
+ const iw = 1 / w;
348
+ x *= iw;
349
+ y *= iw;
350
+ z *= iw;
351
+ }
352
+ if (x < minX) minX = x;
353
+ if (x > maxX) maxX = x;
354
+ if (y < minY) minY = y;
355
+ if (y > maxY) maxY = y;
356
+ if (z < minZ) minZ = z;
357
+ if (z > maxZ) maxZ = z;
358
+ out[0] = minX;
359
+ out[1] = minY;
360
+ out[2] = minZ;
361
+ out[3] = maxX;
362
+ out[4] = maxY;
363
+ out[5] = maxZ;
364
+ return out;
365
+ }
366
+
367
+ // src/circle2.ts
368
+ var circle2_exports = {};
369
+ __export(circle2_exports, {
370
+ center: () => center2,
371
+ closestPoint: () => closestPoint2,
372
+ containsPoint: () => containsPoint3,
373
+ create: () => create3,
374
+ fromPoints: () => fromPoints3,
375
+ intersectsBox: () => intersectsBox3,
376
+ intersectsCircle: () => intersectsCircle2,
377
+ merge: () => merge2,
378
+ radius: () => radius,
379
+ toBox: () => toBox
380
+ });
381
+ function create3(cx = 0, cy = 0, radius2 = 0) {
382
+ return Float32Array.of(cx, cy, radius2 < 0 ? 0 : radius2);
383
+ }
384
+ function fromPoints3(out, points) {
385
+ if (points.length === 0) {
386
+ out[0] = 0;
387
+ out[1] = 0;
388
+ out[2] = -1;
389
+ return out;
390
+ }
391
+ const bounds = create();
392
+ fromPoints(bounds, points);
393
+ const cx = (bounds[0] + bounds[2]) * 0.5;
394
+ const cy = (bounds[1] + bounds[3]) * 0.5;
395
+ let radiusSq = 0;
396
+ for (let i = 0; i < points.length; i++) {
397
+ const point = points[i];
398
+ const dx = point[0] - cx;
399
+ const dy = point[1] - cy;
400
+ const distanceSq2 = dx * dx + dy * dy;
401
+ if (distanceSq2 > radiusSq) radiusSq = distanceSq2;
402
+ }
403
+ out[0] = cx;
404
+ out[1] = cy;
405
+ out[2] = Math.sqrt(radiusSq);
406
+ return out;
407
+ }
408
+ function toBox(out, circle) {
409
+ const cx = circle[0];
410
+ const cy = circle[1];
411
+ const radius2 = circle[2];
412
+ out[0] = cx - radius2;
413
+ out[1] = cy - radius2;
414
+ out[2] = cx + radius2;
415
+ out[3] = cy + radius2;
416
+ return out;
417
+ }
418
+ function center2(out, circle) {
419
+ out[0] = circle[0];
420
+ out[1] = circle[1];
421
+ return out;
422
+ }
423
+ function radius(circle) {
424
+ return circle[2];
425
+ }
426
+ function closestPoint2(out, circle, point) {
427
+ const dx = point[0] - circle[0];
428
+ const dy = point[1] - circle[1];
429
+ const distanceSq2 = dx * dx + dy * dy;
430
+ const r = circle[2];
431
+ if (r < 0) {
432
+ out[0] = circle[0];
433
+ out[1] = circle[1];
434
+ return out;
435
+ }
436
+ if (distanceSq2 <= r * r || distanceSq2 < 1e-12) {
437
+ out[0] = point[0];
438
+ out[1] = point[1];
439
+ return out;
440
+ }
441
+ const scale6 = r / Math.sqrt(distanceSq2);
442
+ out[0] = circle[0] + dx * scale6;
443
+ out[1] = circle[1] + dy * scale6;
444
+ return out;
445
+ }
446
+ function containsPoint3(circle, point) {
447
+ const dx = point[0] - circle[0];
448
+ const dy = point[1] - circle[1];
449
+ const r = circle[2];
450
+ return r >= 0 && dx * dx + dy * dy <= r * r;
451
+ }
452
+ function intersectsCircle2(a, b) {
453
+ const dx = a[0] - b[0];
454
+ const dy = a[1] - b[1];
455
+ const radius2 = a[2] + b[2];
456
+ return a[2] >= 0 && b[2] >= 0 && dx * dx + dy * dy <= radius2 * radius2;
457
+ }
458
+ function intersectsBox3(circle, box) {
459
+ return intersectsCircle(box, circle);
460
+ }
461
+ function merge2(out, a, b) {
462
+ const ax = a[0];
463
+ const ay = a[1];
464
+ const ar = a[2];
465
+ const bx = b[0];
466
+ const by = b[1];
467
+ const br = b[2];
468
+ const dx = bx - ax;
469
+ const dy = by - ay;
470
+ const distance4 = Math.sqrt(dx * dx + dy * dy);
471
+ if (ar >= distance4 + br) return createInto(out, ax, ay, ar);
472
+ if (br >= distance4 + ar) return createInto(out, bx, by, br);
473
+ if (distance4 < 1e-12) return createInto(out, ax, ay, Math.max(ar, br));
474
+ const nextRadius = (distance4 + ar + br) * 0.5;
475
+ const shift = (nextRadius - ar) / distance4;
476
+ return createInto(out, ax + dx * shift, ay + dy * shift, nextRadius);
477
+ }
478
+ function createInto(out, cx, cy, r) {
479
+ out[0] = cx;
480
+ out[1] = cy;
481
+ out[2] = r;
482
+ return out;
483
+ }
484
+
485
+ // src/color.ts
486
+ var color_exports = {};
487
+ __export(color_exports, {
488
+ clone: () => clone,
489
+ create: () => create4,
490
+ fromHex: () => fromHex,
491
+ linearToSrgb: () => linearToSrgb,
492
+ srgbToLinear: () => srgbToLinear,
493
+ toHex: () => toHex
494
+ });
495
+ function create4(r = 0, g = 0, b = 0, a = 1) {
496
+ return Float32Array.of(r, g, b, a);
497
+ }
498
+ function clone(c) {
499
+ return Float32Array.of(c[0], c[1], c[2], c[3]);
500
+ }
501
+ function srgbChannelToLinear(v) {
502
+ if (Number.isNaN(v)) return Number.NaN;
503
+ if (v <= 0) return v;
504
+ if (v <= 0.04045) return v / 12.92;
505
+ return ((v + 0.055) / 1.055) ** 2.4;
506
+ }
507
+ function linearChannelToSrgb(v) {
508
+ if (Number.isNaN(v)) return Number.NaN;
509
+ if (v <= 0) return v;
510
+ if (v <= 31308e-7) return v * 12.92;
511
+ return 1.055 * v ** (1 / 2.4) - 0.055;
512
+ }
513
+ function srgbToLinear(out, c) {
514
+ out[0] = srgbChannelToLinear(c[0]);
515
+ out[1] = srgbChannelToLinear(c[1]);
516
+ out[2] = srgbChannelToLinear(c[2]);
517
+ out[3] = c[3];
518
+ return out;
519
+ }
520
+ function linearToSrgb(out, c) {
521
+ out[0] = linearChannelToSrgb(c[0]);
522
+ out[1] = linearChannelToSrgb(c[1]);
523
+ out[2] = linearChannelToSrgb(c[2]);
524
+ out[3] = c[3];
525
+ return out;
526
+ }
527
+ var HEX_PATTERN = /^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})?$/;
528
+ function fromHex(out, hex) {
529
+ const match = typeof hex === "string" ? HEX_PATTERN.exec(hex) : null;
530
+ if (match === null) {
531
+ out[0] = 0;
532
+ out[1] = 0;
533
+ out[2] = 0;
534
+ out[3] = 1;
535
+ return out;
536
+ }
537
+ out[0] = Number.parseInt(match[1], 16) / 255;
538
+ out[1] = Number.parseInt(match[2], 16) / 255;
539
+ out[2] = Number.parseInt(match[3], 16) / 255;
540
+ out[3] = match[4] !== void 0 ? Number.parseInt(match[4], 16) / 255 : 1;
541
+ return out;
542
+ }
543
+ function toHexByte(v) {
544
+ if (Number.isNaN(v)) return "00";
545
+ const clamped = Math.max(0, Math.min(1, v));
546
+ const byte = Math.round(clamped * 255);
547
+ return byte.toString(16).padStart(2, "0");
548
+ }
549
+ function toHex(c) {
550
+ const r = toHexByte(c[0]);
551
+ const g = toHexByte(c[1]);
552
+ const b = toHexByte(c[2]);
553
+ const aValue = c[3];
554
+ if (aValue >= 1 || Number.isNaN(aValue)) {
555
+ return `#${r}${g}${b}`;
556
+ }
557
+ const a = toHexByte(aValue);
558
+ return `#${r}${g}${b}${a}`;
559
+ }
560
+
561
+ // src/easing.ts
562
+ var easing_exports = {};
563
+ __export(easing_exports, {
564
+ cubicInOut: () => cubicInOut,
565
+ elasticInOut: () => elasticInOut,
566
+ smootherstep: () => smootherstep,
567
+ smoothstep: () => smoothstep
568
+ });
569
+
570
+ // src/_internal/scalar.ts
571
+ function lerp(a, b, t) {
572
+ return a + (b - a) * t;
573
+ }
574
+ function lengthSq4(a) {
575
+ const x = a[0];
576
+ const y = a[1];
577
+ const z = a[2];
578
+ const w = a[3];
579
+ return x * x + y * y + z * z + w * w;
580
+ }
581
+ function normalize4(out, a, epsilon) {
582
+ const lenSq = lengthSq4(a);
583
+ if (lenSq < epsilon) {
584
+ out[0] = 0;
585
+ out[1] = 0;
586
+ out[2] = 0;
587
+ out[3] = 0;
588
+ return;
589
+ }
590
+ const inv = 1 / Math.sqrt(lenSq);
591
+ out[0] = a[0] * inv;
592
+ out[1] = a[1] * inv;
593
+ out[2] = a[2] * inv;
594
+ out[3] = a[3] * inv;
595
+ }
596
+ function smoothDecayFactor(decayRate, dt) {
597
+ return 1 - Math.exp(-decayRate * dt);
598
+ }
599
+ function catmullRomScalar(a, b, c, d, t) {
600
+ const c0 = b;
601
+ const c1 = 0.5 * (c - a);
602
+ const c2 = a - 2.5 * b + 2 * c - 0.5 * d;
603
+ const c3 = -0.5 * a + 1.5 * b - 1.5 * c + 0.5 * d;
604
+ const t2 = t * t;
605
+ const t3 = t2 * t;
606
+ return c0 + c1 * t + c2 * t2 + c3 * t3;
607
+ }
608
+ function clamp(v, min4, max4) {
609
+ if (v < min4) return min4;
610
+ if (v > max4) return max4;
611
+ return v;
612
+ }
613
+
614
+ // src/easing.ts
615
+ function cubicInOut(t) {
616
+ const x = clamp(t, 0, 1);
617
+ return x < 0.5 ? 4 * x * x * x : 1 - (-2 * x + 2) ** 3 / 2;
618
+ }
619
+ function smoothstep(t) {
620
+ const x = clamp(t, 0, 1);
621
+ return x * x * (3 - 2 * x);
622
+ }
623
+ function smootherstep(t) {
624
+ const x = clamp(t, 0, 1);
625
+ return x * x * x * (x * (x * 6 - 15) + 10);
626
+ }
627
+ function elasticInOut(t) {
628
+ const x = clamp(t, 0, 1);
629
+ if (x === 0 || x === 1) return x;
630
+ const c5 = 2 * Math.PI / 4.5;
631
+ return x < 0.5 ? -(2 ** (20 * x - 10) * Math.sin((20 * x - 11.125) * c5)) / 2 : 2 ** (-20 * x + 10) * Math.sin((20 * x - 11.125) * c5) / 2 + 1;
632
+ }
633
+
634
+ // src/euler.ts
635
+ var euler_exports = {};
636
+ __export(euler_exports, {
637
+ clone: () => clone3,
638
+ create: () => create6,
639
+ fromQuat: () => fromQuat,
640
+ fromRotationMatrix: () => fromRotationMatrix2,
641
+ set: () => set,
642
+ toQuat: () => toQuat
643
+ });
644
+
645
+ // src/quat.ts
646
+ var quat_exports = {};
647
+ __export(quat_exports, {
648
+ clone: () => clone2,
649
+ conjugate: () => conjugate,
650
+ create: () => create5,
651
+ dot: () => dot,
652
+ eulerY: () => eulerY,
653
+ forward: () => forward,
654
+ fromAxisAngle: () => fromAxisAngle,
655
+ fromEuler: () => fromEuler,
656
+ fromLookAt: () => fromLookAt,
657
+ fromRotationMatrix: () => fromRotationMatrix,
658
+ fromUnitVectors: () => fromUnitVectors,
659
+ identity: () => identity,
660
+ invert: () => invert,
661
+ length: () => length,
662
+ lengthSq: () => lengthSq,
663
+ multiply: () => multiply,
664
+ nlerp: () => nlerp,
665
+ normalize: () => normalize,
666
+ right: () => right,
667
+ rotateAxis: () => rotateAxis,
668
+ slerp: () => slerp,
669
+ transformVec3: () => transformVec3,
670
+ up: () => up
671
+ });
672
+
673
+ // src/_internal/epsilon.ts
674
+ var EPS_NORMALIZE = 1e-12;
675
+ var EPS_DET = 1e-8;
676
+ var EPS_QUAT_PARALLEL = 1e-6;
677
+ var EPS_SLERP_DOT_LIMIT = 1e-6;
678
+
679
+ // src/quat.ts
680
+ var UNIT_X = [1, 0, 0];
681
+ var UNIT_Y = [0, 1, 0];
682
+ var UNIT_NEG_Z = [0, 0, -1];
683
+ function create5() {
684
+ return new Float32Array(4);
685
+ }
686
+ function clone2(a) {
687
+ return Float32Array.of(a[0], a[1], a[2], a[3]);
688
+ }
689
+ function identity(out) {
690
+ out[0] = 0;
691
+ out[1] = 0;
692
+ out[2] = 0;
693
+ out[3] = 1;
694
+ return out;
695
+ }
696
+ function fromAxisAngle(out, axis, angleRadians) {
697
+ const ax = axis[0];
698
+ const ay = axis[1];
699
+ const az = axis[2];
700
+ const lenSq = ax * ax + ay * ay + az * az;
701
+ if (lenSq < EPS_NORMALIZE) {
702
+ return identity(out);
703
+ }
704
+ const inv = 1 / Math.sqrt(lenSq);
705
+ const half = angleRadians / 2;
706
+ const s = Math.sin(half);
707
+ out[0] = ax * inv * s;
708
+ out[1] = ay * inv * s;
709
+ out[2] = az * inv * s;
710
+ out[3] = Math.cos(half);
711
+ return out;
712
+ }
713
+ function fromEuler(out, x, y, z, order) {
714
+ const c1 = Math.cos(x / 2);
715
+ const c2 = Math.cos(y / 2);
716
+ const c3 = Math.cos(z / 2);
717
+ const s1 = Math.sin(x / 2);
718
+ const s2 = Math.sin(y / 2);
719
+ const s3 = Math.sin(z / 2);
720
+ switch (order) {
721
+ case "XYZ":
722
+ out[0] = s1 * c2 * c3 + c1 * s2 * s3;
723
+ out[1] = c1 * s2 * c3 - s1 * c2 * s3;
724
+ out[2] = c1 * c2 * s3 + s1 * s2 * c3;
725
+ out[3] = c1 * c2 * c3 - s1 * s2 * s3;
726
+ break;
727
+ case "YXZ":
728
+ out[0] = s1 * c2 * c3 + c1 * s2 * s3;
729
+ out[1] = c1 * s2 * c3 - s1 * c2 * s3;
730
+ out[2] = c1 * c2 * s3 - s1 * s2 * c3;
731
+ out[3] = c1 * c2 * c3 + s1 * s2 * s3;
732
+ break;
733
+ case "ZXY":
734
+ out[0] = s1 * c2 * c3 - c1 * s2 * s3;
735
+ out[1] = c1 * s2 * c3 + s1 * c2 * s3;
736
+ out[2] = c1 * c2 * s3 + s1 * s2 * c3;
737
+ out[3] = c1 * c2 * c3 - s1 * s2 * s3;
738
+ break;
739
+ case "ZYX":
740
+ out[0] = s1 * c2 * c3 - c1 * s2 * s3;
741
+ out[1] = c1 * s2 * c3 + s1 * c2 * s3;
742
+ out[2] = c1 * c2 * s3 - s1 * s2 * c3;
743
+ out[3] = c1 * c2 * c3 + s1 * s2 * s3;
744
+ break;
745
+ case "YZX":
746
+ out[0] = s1 * c2 * c3 + c1 * s2 * s3;
747
+ out[1] = c1 * s2 * c3 + s1 * c2 * s3;
748
+ out[2] = c1 * c2 * s3 - s1 * s2 * c3;
749
+ out[3] = c1 * c2 * c3 - s1 * s2 * s3;
750
+ break;
751
+ case "XZY":
752
+ out[0] = s1 * c2 * c3 - c1 * s2 * s3;
753
+ out[1] = c1 * s2 * c3 - s1 * c2 * s3;
754
+ out[2] = c1 * c2 * s3 + s1 * s2 * c3;
755
+ out[3] = c1 * c2 * c3 + s1 * s2 * s3;
756
+ break;
757
+ default:
758
+ out[0] = s1 * c2 * c3 + c1 * s2 * s3;
759
+ out[1] = c1 * s2 * c3 - s1 * c2 * s3;
760
+ out[2] = c1 * c2 * s3 + s1 * s2 * c3;
761
+ out[3] = c1 * c2 * c3 - s1 * s2 * s3;
762
+ break;
763
+ }
764
+ return out;
765
+ }
766
+ function fromRotationMatrix(out, m) {
767
+ const m00 = m[0];
768
+ const m01 = m[1];
769
+ const m02 = m[2];
770
+ const m10 = m[3];
771
+ const m11 = m[4];
772
+ const m12 = m[5];
773
+ const m20 = m[6];
774
+ const m21 = m[7];
775
+ const m22 = m[8];
776
+ const trace = m00 + m11 + m22;
777
+ if (trace > 0) {
778
+ const s = 0.5 / Math.sqrt(trace + 1);
779
+ out[0] = (m12 - m21) * s;
780
+ out[1] = (m20 - m02) * s;
781
+ out[2] = (m01 - m10) * s;
782
+ out[3] = 0.25 / s;
783
+ } else if (m00 > m11 && m00 > m22) {
784
+ const s = 2 * Math.sqrt(1 + m00 - m11 - m22);
785
+ out[0] = 0.25 * s;
786
+ out[1] = (m10 + m01) / s;
787
+ out[2] = (m20 + m02) / s;
788
+ out[3] = (m12 - m21) / s;
789
+ } else if (m11 > m22) {
790
+ const s = 2 * Math.sqrt(1 + m11 - m00 - m22);
791
+ out[0] = (m10 + m01) / s;
792
+ out[1] = 0.25 * s;
793
+ out[2] = (m21 + m12) / s;
794
+ out[3] = (m20 - m02) / s;
795
+ } else {
796
+ const s = 2 * Math.sqrt(1 + m22 - m00 - m11);
797
+ out[0] = (m20 + m02) / s;
798
+ out[1] = (m21 + m12) / s;
799
+ out[2] = 0.25 * s;
800
+ out[3] = (m01 - m10) / s;
801
+ }
802
+ return out;
803
+ }
804
+ function fromLookAt(out, eye, target, up2) {
805
+ const ex = eye[0];
806
+ const ey = eye[1];
807
+ const ez = eye[2];
808
+ let fx = ex - target[0];
809
+ let fy = ey - target[1];
810
+ let fz = ez - target[2];
811
+ const fLenSq = fx * fx + fy * fy + fz * fz;
812
+ if (fLenSq < EPS_NORMALIZE) {
813
+ return identity(out);
814
+ }
815
+ const fInv = 1 / Math.sqrt(fLenSq);
816
+ fx *= fInv;
817
+ fy *= fInv;
818
+ fz *= fInv;
819
+ const upx = up2[0];
820
+ const upy = up2[1];
821
+ const upz = up2[2];
822
+ let rx = upy * fz - upz * fy;
823
+ let ry = upz * fx - upx * fz;
824
+ let rz = upx * fy - upy * fx;
825
+ let rLenSq = rx * rx + ry * ry + rz * rz;
826
+ if (rLenSq < EPS_NORMALIZE) {
827
+ rx = -fy;
828
+ ry = fx;
829
+ rz = 0;
830
+ rLenSq = rx * rx + ry * ry + rz * rz;
831
+ if (rLenSq < EPS_NORMALIZE) {
832
+ rx = 0;
833
+ ry = -fz;
834
+ rz = fy;
835
+ rLenSq = rx * rx + ry * ry + rz * rz;
836
+ }
837
+ }
838
+ const rInv = 1 / Math.sqrt(rLenSq);
839
+ rx *= rInv;
840
+ ry *= rInv;
841
+ rz *= rInv;
842
+ const ux = fy * rz - fz * ry;
843
+ const uy = fz * rx - fx * rz;
844
+ const uz = fx * ry - fy * rx;
845
+ const m3 = new Float32Array(9);
846
+ m3[0] = rx;
847
+ m3[1] = ry;
848
+ m3[2] = rz;
849
+ m3[3] = ux;
850
+ m3[4] = uy;
851
+ m3[5] = uz;
852
+ m3[6] = fx;
853
+ m3[7] = fy;
854
+ m3[8] = fz;
855
+ return fromRotationMatrix(out, m3);
856
+ }
857
+ function fromUnitVectors(out, v, w) {
858
+ const vx = v[0];
859
+ const vy = v[1];
860
+ const vz = v[2];
861
+ const wx = w[0];
862
+ const wy = w[1];
863
+ const wz = w[2];
864
+ const d = vx * wx + vy * wy + vz * wz;
865
+ if (d > 1 - EPS_QUAT_PARALLEL) {
866
+ return identity(out);
867
+ }
868
+ if (d < -1 + EPS_QUAT_PARALLEL) {
869
+ let ax;
870
+ let ay;
871
+ let az;
872
+ if (Math.abs(vy) < 1 - EPS_QUAT_PARALLEL) {
873
+ ax = -vz;
874
+ ay = 0;
875
+ az = vx;
876
+ } else {
877
+ ax = 0;
878
+ ay = vz;
879
+ az = -vy;
880
+ }
881
+ const axLen = Math.sqrt(ax * ax + ay * ay + az * az);
882
+ if (axLen < EPS_NORMALIZE) {
883
+ return identity(out);
884
+ }
885
+ const axInv = 1 / axLen;
886
+ out[0] = ax * axInv;
887
+ out[1] = ay * axInv;
888
+ out[2] = az * axInv;
889
+ out[3] = 0;
890
+ return out;
891
+ }
892
+ const cx = vy * wz - vz * wy;
893
+ const cy = vz * wx - vx * wz;
894
+ const cz = vx * wy - vy * wx;
895
+ const sw = 1 + d;
896
+ const len = Math.sqrt(cx * cx + cy * cy + cz * cz + sw * sw);
897
+ const inv = 1 / len;
898
+ out[0] = cx * inv;
899
+ out[1] = cy * inv;
900
+ out[2] = cz * inv;
901
+ out[3] = sw * inv;
902
+ return out;
903
+ }
904
+ function multiply(out, a, b) {
905
+ const ax = a[0];
906
+ const ay = a[1];
907
+ const az = a[2];
908
+ const aw = a[3];
909
+ const bx = b[0];
910
+ const by = b[1];
911
+ const bz = b[2];
912
+ const bw = b[3];
913
+ out[0] = aw * bx + ax * bw + ay * bz - az * by;
914
+ out[1] = aw * by - ax * bz + ay * bw + az * bx;
915
+ out[2] = aw * bz + ax * by - ay * bx + az * bw;
916
+ out[3] = aw * bw - ax * bx - ay * by - az * bz;
917
+ return out;
918
+ }
919
+ function rotateAxis(out, q, axis, angleRadians) {
920
+ const qx = q[0];
921
+ const qy = q[1];
922
+ const qz = q[2];
923
+ const qw = q[3];
924
+ const ax = axis[0];
925
+ const ay = axis[1];
926
+ const az = axis[2];
927
+ const axisLen = Math.sqrt(ax * ax + ay * ay + az * az);
928
+ let dx = 0;
929
+ let dy = 0;
930
+ let dz = 0;
931
+ let dw = 1;
932
+ if (axisLen >= EPS_NORMALIZE) {
933
+ const half = angleRadians * 0.5;
934
+ const s = Math.sin(half) / axisLen;
935
+ dx = ax * s;
936
+ dy = ay * s;
937
+ dz = az * s;
938
+ dw = Math.cos(half);
939
+ }
940
+ let rx = dw * qx + dx * qw + dy * qz - dz * qy;
941
+ let ry = dw * qy - dx * qz + dy * qw + dz * qx;
942
+ let rz = dw * qz + dx * qy - dy * qx + dz * qw;
943
+ let rw = dw * qw - dx * qx - dy * qy - dz * qz;
944
+ const len = Math.sqrt(rx * rx + ry * ry + rz * rz + rw * rw);
945
+ if (len >= EPS_NORMALIZE) {
946
+ const inv = 1 / len;
947
+ rx *= inv;
948
+ ry *= inv;
949
+ rz *= inv;
950
+ rw *= inv;
951
+ }
952
+ out[0] = rx;
953
+ out[1] = ry;
954
+ out[2] = rz;
955
+ out[3] = rw;
956
+ return out;
957
+ }
958
+ function slerp(out, a, b, t) {
959
+ const ax = a[0];
960
+ const ay = a[1];
961
+ const az = a[2];
962
+ const aw = a[3];
963
+ let bx = b[0];
964
+ let by = b[1];
965
+ let bz = b[2];
966
+ let bw = b[3];
967
+ let cosTheta = ax * bx + ay * by + az * bz + aw * bw;
968
+ if (cosTheta < 0) {
969
+ bx = -bx;
970
+ by = -by;
971
+ bz = -bz;
972
+ bw = -bw;
973
+ cosTheta = -cosTheta;
974
+ }
975
+ if (cosTheta > 1 - EPS_SLERP_DOT_LIMIT) {
976
+ return nlerp(out, a, b, t);
977
+ }
978
+ const theta = Math.acos(cosTheta);
979
+ const sinTheta = Math.sin(theta);
980
+ const wa = Math.sin((1 - t) * theta) / sinTheta;
981
+ const wb = Math.sin(t * theta) / sinTheta;
982
+ out[0] = wa * ax + wb * bx;
983
+ out[1] = wa * ay + wb * by;
984
+ out[2] = wa * az + wb * bz;
985
+ out[3] = wa * aw + wb * bw;
986
+ return out;
987
+ }
988
+ function nlerp(out, a, b, t) {
989
+ const ax = a[0];
990
+ const ay = a[1];
991
+ const az = a[2];
992
+ const aw = a[3];
993
+ let bx = b[0];
994
+ let by = b[1];
995
+ let bz = b[2];
996
+ let bw = b[3];
997
+ const cosTheta = ax * bx + ay * by + az * bz + aw * bw;
998
+ if (cosTheta < 0) {
999
+ bx = -bx;
1000
+ by = -by;
1001
+ bz = -bz;
1002
+ bw = -bw;
1003
+ }
1004
+ out[0] = ax + t * (bx - ax);
1005
+ out[1] = ay + t * (by - ay);
1006
+ out[2] = az + t * (bz - az);
1007
+ out[3] = aw + t * (bw - aw);
1008
+ const lenSq = out[0] * out[0] + out[1] * out[1] + out[2] * out[2] + out[3] * out[3];
1009
+ if (lenSq < EPS_NORMALIZE) {
1010
+ return identity(out);
1011
+ }
1012
+ const inv = 1 / Math.sqrt(lenSq);
1013
+ out[0] = out[0] * inv;
1014
+ out[1] = out[1] * inv;
1015
+ out[2] = out[2] * inv;
1016
+ out[3] = out[3] * inv;
1017
+ return out;
1018
+ }
1019
+ function invert(out, a) {
1020
+ const ax = a[0];
1021
+ const ay = a[1];
1022
+ const az = a[2];
1023
+ const aw = a[3];
1024
+ const lenSq = ax * ax + ay * ay + az * az + aw * aw;
1025
+ if (lenSq < EPS_NORMALIZE) {
1026
+ return identity(out);
1027
+ }
1028
+ const inv = 1 / lenSq;
1029
+ out[0] = -ax * inv;
1030
+ out[1] = -ay * inv;
1031
+ out[2] = -az * inv;
1032
+ out[3] = aw * inv;
1033
+ return out;
1034
+ }
1035
+ function conjugate(out, a) {
1036
+ out[0] = -a[0];
1037
+ out[1] = -a[1];
1038
+ out[2] = -a[2];
1039
+ out[3] = a[3];
1040
+ return out;
1041
+ }
1042
+ function dot(a, b) {
1043
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
1044
+ }
1045
+ function length(a) {
1046
+ return Math.sqrt(lengthSq(a));
1047
+ }
1048
+ function lengthSq(a) {
1049
+ return lengthSq4(a);
1050
+ }
1051
+ function transformVec3(out, q, v) {
1052
+ const qx = q[0];
1053
+ const qy = q[1];
1054
+ const qz = q[2];
1055
+ const qw = q[3];
1056
+ const vx = v[0];
1057
+ const vy = v[1];
1058
+ const vz = v[2];
1059
+ const tx = 2 * (qy * vz - qz * vy);
1060
+ const ty = 2 * (qz * vx - qx * vz);
1061
+ const tz = 2 * (qx * vy - qy * vx);
1062
+ out[0] = vx + qw * tx + (qy * tz - qz * ty);
1063
+ out[1] = vy + qw * ty + (qz * tx - qx * tz);
1064
+ out[2] = vz + qw * tz + (qx * ty - qy * tx);
1065
+ return out;
1066
+ }
1067
+ function normalize(out, a) {
1068
+ normalize4(out, a, EPS_NORMALIZE);
1069
+ return out;
1070
+ }
1071
+ function eulerY(theta) {
1072
+ const out = create5();
1073
+ return fromEuler(out, 0, theta, 0, "YXZ");
1074
+ }
1075
+ function right(out, q) {
1076
+ return transformVec3(out, q, UNIT_X);
1077
+ }
1078
+ function up(out, q) {
1079
+ return transformVec3(out, q, UNIT_Y);
1080
+ }
1081
+ function forward(out, q) {
1082
+ return transformVec3(out, q, UNIT_NEG_Z);
1083
+ }
1084
+
1085
+ // src/euler.ts
1086
+ function create6() {
1087
+ return { x: 0, y: 0, z: 0, order: "XYZ" };
1088
+ }
1089
+ function clone3(a) {
1090
+ return { x: a.x, y: a.y, z: a.z, order: a.order };
1091
+ }
1092
+ function set(out, x, y, z, order) {
1093
+ out.x = x;
1094
+ out.y = y;
1095
+ out.z = z;
1096
+ out.order = order;
1097
+ return out;
1098
+ }
1099
+ function toQuat(out, e) {
1100
+ return fromEuler(out, e.x, e.y, e.z, e.order);
1101
+ }
1102
+ function fromQuat(out, q, order) {
1103
+ const x = q[0];
1104
+ const y = q[1];
1105
+ const z = q[2];
1106
+ const w = q[3];
1107
+ const xx = x * x;
1108
+ const xy = x * y;
1109
+ const xz = x * z;
1110
+ const yy = y * y;
1111
+ const yz = y * z;
1112
+ const zz = z * z;
1113
+ const wx = w * x;
1114
+ const wy = w * y;
1115
+ const wz = w * z;
1116
+ const m = new Float32Array(9);
1117
+ m[0] = 1 - 2 * (yy + zz);
1118
+ m[1] = 2 * (xy + wz);
1119
+ m[2] = 2 * (xz - wy);
1120
+ m[3] = 2 * (xy - wz);
1121
+ m[4] = 1 - 2 * (xx + zz);
1122
+ m[5] = 2 * (yz + wx);
1123
+ m[6] = 2 * (xz + wy);
1124
+ m[7] = 2 * (yz - wx);
1125
+ m[8] = 1 - 2 * (xx + yy);
1126
+ return fromRotationMatrix2(out, m, order);
1127
+ }
1128
+ function fromRotationMatrix2(out, m, order) {
1129
+ const _11 = m[0];
1130
+ const _21 = m[1];
1131
+ const _31 = m[2];
1132
+ const _12 = m[3];
1133
+ const _22 = m[4];
1134
+ const _32 = m[5];
1135
+ const _13 = m[6];
1136
+ const _23 = m[7];
1137
+ const _33 = m[8];
1138
+ out.order = order;
1139
+ switch (order) {
1140
+ case "XYZ":
1141
+ out.y = Math.asin(clamp11(_13));
1142
+ if (Math.abs(_13) < 1 - 1e-7) {
1143
+ out.x = Math.atan2(-_23, _33);
1144
+ out.z = Math.atan2(-_12, _11);
1145
+ } else {
1146
+ out.x = Math.atan2(_32, _22);
1147
+ out.z = 0;
1148
+ }
1149
+ break;
1150
+ case "YXZ":
1151
+ out.x = Math.asin(-clamp11(_23));
1152
+ if (Math.abs(_23) < 1 - 1e-7) {
1153
+ out.y = Math.atan2(_13, _33);
1154
+ out.z = Math.atan2(_21, _22);
1155
+ } else {
1156
+ out.y = Math.atan2(-_31, _11);
1157
+ out.z = 0;
1158
+ }
1159
+ break;
1160
+ case "ZXY":
1161
+ out.x = Math.asin(clamp11(_32));
1162
+ if (Math.abs(_32) < 1 - 1e-7) {
1163
+ out.y = Math.atan2(-_31, _33);
1164
+ out.z = Math.atan2(-_12, _22);
1165
+ } else {
1166
+ out.y = 0;
1167
+ out.z = Math.atan2(_21, _11);
1168
+ }
1169
+ break;
1170
+ case "ZYX":
1171
+ out.y = Math.asin(-clamp11(_31));
1172
+ if (Math.abs(_31) < 1 - 1e-7) {
1173
+ out.x = Math.atan2(_32, _33);
1174
+ out.z = Math.atan2(_21, _11);
1175
+ } else {
1176
+ out.x = 0;
1177
+ out.z = Math.atan2(-_12, _22);
1178
+ }
1179
+ break;
1180
+ case "YZX":
1181
+ out.z = Math.asin(clamp11(_21));
1182
+ if (Math.abs(_21) < 1 - 1e-7) {
1183
+ out.x = Math.atan2(-_23, _22);
1184
+ out.y = Math.atan2(-_31, _11);
1185
+ } else {
1186
+ out.x = 0;
1187
+ out.y = Math.atan2(_13, _33);
1188
+ }
1189
+ break;
1190
+ case "XZY":
1191
+ out.z = Math.asin(-clamp11(_12));
1192
+ if (Math.abs(_12) < 1 - 1e-7) {
1193
+ out.x = Math.atan2(_32, _22);
1194
+ out.y = Math.atan2(_13, _11);
1195
+ } else {
1196
+ out.x = Math.atan2(-_23, _33);
1197
+ out.y = 0;
1198
+ }
1199
+ break;
1200
+ default:
1201
+ out.y = Math.asin(clamp11(_13));
1202
+ if (Math.abs(_13) < 1 - 1e-7) {
1203
+ out.x = Math.atan2(-_23, _33);
1204
+ out.z = Math.atan2(-_12, _11);
1205
+ } else {
1206
+ out.x = Math.atan2(_32, _22);
1207
+ out.z = 0;
1208
+ }
1209
+ out.order = "XYZ";
1210
+ break;
1211
+ }
1212
+ return out;
1213
+ }
1214
+ function clamp11(v) {
1215
+ if (v < -1) return -1;
1216
+ if (v > 1) return 1;
1217
+ return v;
1218
+ }
1219
+
1220
+ // src/f32-to-f16-bytes.ts
1221
+ var f32_to_f16_bytes_exports = {};
1222
+ __export(f32_to_f16_bytes_exports, {
1223
+ f32ToF16Bytes: () => f32ToF16Bytes
1224
+ });
1225
+ function f32ToF16Bytes(src) {
1226
+ const f32 = new Float32Array(src.buffer, src.byteOffset, src.byteLength / 4);
1227
+ const out = new Uint8Array(f32.length * 2);
1228
+ const view = new DataView(out.buffer);
1229
+ const scratch = new ArrayBuffer(4);
1230
+ const scratchF = new Float32Array(scratch);
1231
+ const scratchU = new Uint32Array(scratch);
1232
+ for (let i = 0; i < f32.length; i++) {
1233
+ scratchF[0] = f32[i] ?? 0;
1234
+ const bits = scratchU[0] ?? 0;
1235
+ const sign = bits >>> 31 & 1;
1236
+ const exp = bits >>> 23 & 255;
1237
+ let mant = bits & 8388607;
1238
+ let half;
1239
+ if (exp === 255) {
1240
+ half = sign << 15 | 31744 | (mant ? 512 : 0);
1241
+ } else if (exp === 0) {
1242
+ half = sign << 15;
1243
+ } else {
1244
+ const e = exp - 127 + 15;
1245
+ if (e >= 31) {
1246
+ half = sign << 15 | 31744;
1247
+ } else if (e <= 0) {
1248
+ if (e < -10) {
1249
+ half = sign << 15;
1250
+ } else {
1251
+ mant = (mant | 8388608) >> 1 - e;
1252
+ if (mant & 4096) mant += 8192;
1253
+ half = sign << 15 | mant >> 13;
1254
+ }
1255
+ } else {
1256
+ if (mant & 4096) {
1257
+ mant += 8192;
1258
+ if (mant & 8388608) {
1259
+ mant = 0;
1260
+ half = sign << 15 | e + 1 << 10;
1261
+ } else {
1262
+ half = sign << 15 | e << 10 | mant >> 13;
1263
+ }
1264
+ } else {
1265
+ half = sign << 15 | e << 10 | mant >> 13;
1266
+ }
1267
+ }
1268
+ }
1269
+ view.setUint16(i * 2, half & 65535, true);
1270
+ }
1271
+ return out;
1272
+ }
1273
+
1274
+ // src/frustum.ts
1275
+ var frustum_exports = {};
1276
+ __export(frustum_exports, {
1277
+ create: () => create7,
1278
+ fromViewProjection: () => fromViewProjection,
1279
+ intersectsBox: () => intersectsBox4,
1280
+ intersectsSphere: () => intersectsSphere
1281
+ });
1282
+ function create7() {
1283
+ return new Float32Array(24);
1284
+ }
1285
+ function fromViewProjection(out, vp) {
1286
+ const m0 = vp[0];
1287
+ const m1 = vp[1];
1288
+ const m2 = vp[2];
1289
+ const m3 = vp[3];
1290
+ const m4 = vp[4];
1291
+ const m5 = vp[5];
1292
+ const m6 = vp[6];
1293
+ const m7 = vp[7];
1294
+ const m8 = vp[8];
1295
+ const m9 = vp[9];
1296
+ const m10 = vp[10];
1297
+ const m11 = vp[11];
1298
+ const m12 = vp[12];
1299
+ const m13 = vp[13];
1300
+ const m14 = vp[14];
1301
+ const m15 = vp[15];
1302
+ let nx = m3 + m0, ny = m7 + m4, nz = m11 + m8, d = m15 + m12;
1303
+ let len = Math.sqrt(nx * nx + ny * ny + nz * nz);
1304
+ if (len > 0) {
1305
+ const il = 1 / len;
1306
+ nx *= il;
1307
+ ny *= il;
1308
+ nz *= il;
1309
+ d *= il;
1310
+ }
1311
+ out[0] = nx;
1312
+ out[1] = ny;
1313
+ out[2] = nz;
1314
+ out[3] = d;
1315
+ nx = m3 - m0;
1316
+ ny = m7 - m4;
1317
+ nz = m11 - m8;
1318
+ d = m15 - m12;
1319
+ len = Math.sqrt(nx * nx + ny * ny + nz * nz);
1320
+ if (len > 0) {
1321
+ const il = 1 / len;
1322
+ nx *= il;
1323
+ ny *= il;
1324
+ nz *= il;
1325
+ d *= il;
1326
+ }
1327
+ out[4] = nx;
1328
+ out[5] = ny;
1329
+ out[6] = nz;
1330
+ out[7] = d;
1331
+ nx = m3 + m1;
1332
+ ny = m7 + m5;
1333
+ nz = m11 + m9;
1334
+ d = m15 + m13;
1335
+ len = Math.sqrt(nx * nx + ny * ny + nz * nz);
1336
+ if (len > 0) {
1337
+ const il = 1 / len;
1338
+ nx *= il;
1339
+ ny *= il;
1340
+ nz *= il;
1341
+ d *= il;
1342
+ }
1343
+ out[8] = nx;
1344
+ out[9] = ny;
1345
+ out[10] = nz;
1346
+ out[11] = d;
1347
+ nx = m3 - m1;
1348
+ ny = m7 - m5;
1349
+ nz = m11 - m9;
1350
+ d = m15 - m13;
1351
+ len = Math.sqrt(nx * nx + ny * ny + nz * nz);
1352
+ if (len > 0) {
1353
+ const il = 1 / len;
1354
+ nx *= il;
1355
+ ny *= il;
1356
+ nz *= il;
1357
+ d *= il;
1358
+ }
1359
+ out[12] = nx;
1360
+ out[13] = ny;
1361
+ out[14] = nz;
1362
+ out[15] = d;
1363
+ nx = m3 + m2;
1364
+ ny = m7 + m6;
1365
+ nz = m11 + m10;
1366
+ d = m15 + m14;
1367
+ len = Math.sqrt(nx * nx + ny * ny + nz * nz);
1368
+ if (len > 0) {
1369
+ const il = 1 / len;
1370
+ nx *= il;
1371
+ ny *= il;
1372
+ nz *= il;
1373
+ d *= il;
1374
+ }
1375
+ out[16] = nx;
1376
+ out[17] = ny;
1377
+ out[18] = nz;
1378
+ out[19] = d;
1379
+ nx = m3 - m2;
1380
+ ny = m7 - m6;
1381
+ nz = m11 - m10;
1382
+ d = m15 - m14;
1383
+ len = Math.sqrt(nx * nx + ny * ny + nz * nz);
1384
+ if (len > 0) {
1385
+ const il = 1 / len;
1386
+ nx *= il;
1387
+ ny *= il;
1388
+ nz *= il;
1389
+ d *= il;
1390
+ }
1391
+ out[20] = nx;
1392
+ out[21] = ny;
1393
+ out[22] = nz;
1394
+ out[23] = d;
1395
+ return out;
1396
+ }
1397
+ function intersectsBox4(f, box) {
1398
+ const bx = box[0];
1399
+ const by = box[1];
1400
+ const bz = box[2];
1401
+ const bX = box[3];
1402
+ const bY = box[4];
1403
+ const bZ = box[5];
1404
+ for (let i = 0; i < 6; i++) {
1405
+ const off = i * 4;
1406
+ const nx = f[off];
1407
+ const ny = f[off + 1];
1408
+ const nz = f[off + 2];
1409
+ const d = f[off + 3];
1410
+ const px = nx >= 0 ? bX : bx;
1411
+ const py = ny >= 0 ? bY : by;
1412
+ const pz = nz >= 0 ? bZ : bz;
1413
+ if (nx * px + ny * py + nz * pz + d < 0) {
1414
+ return false;
1415
+ }
1416
+ }
1417
+ return true;
1418
+ }
1419
+ function intersectsSphere(f, center3, radius2) {
1420
+ const cx = center3[0];
1421
+ const cy = center3[1];
1422
+ const cz = center3[2];
1423
+ for (let i = 0; i < 6; i++) {
1424
+ const off = i * 4;
1425
+ const nx = f[off];
1426
+ const ny = f[off + 1];
1427
+ const nz = f[off + 2];
1428
+ const sd = f[off + 3];
1429
+ const dist = nx * cx + ny * cy + nz * cz + sd;
1430
+ if (dist < -radius2) {
1431
+ return false;
1432
+ }
1433
+ }
1434
+ return true;
1435
+ }
1436
+
1437
+ // src/mat3.ts
1438
+ var mat3_exports = {};
1439
+ __export(mat3_exports, {
1440
+ clone: () => clone4,
1441
+ create: () => create8,
1442
+ equals: () => equals,
1443
+ fromMat4: () => fromMat4,
1444
+ identity: () => identity2,
1445
+ invert: () => invert2,
1446
+ multiply: () => multiply2,
1447
+ normalMatrix: () => normalMatrix,
1448
+ scale: () => scale,
1449
+ transpose: () => transpose
1450
+ });
1451
+ function create8() {
1452
+ return new Float32Array(9);
1453
+ }
1454
+ function clone4(a) {
1455
+ return Float32Array.of(
1456
+ a[0],
1457
+ a[1],
1458
+ a[2],
1459
+ a[3],
1460
+ a[4],
1461
+ a[5],
1462
+ a[6],
1463
+ a[7],
1464
+ a[8]
1465
+ );
1466
+ }
1467
+ function identity2(out) {
1468
+ out[0] = 1;
1469
+ out[1] = 0;
1470
+ out[2] = 0;
1471
+ out[3] = 0;
1472
+ out[4] = 1;
1473
+ out[5] = 0;
1474
+ out[6] = 0;
1475
+ out[7] = 0;
1476
+ out[8] = 1;
1477
+ return out;
1478
+ }
1479
+ function equals(a, b, epsilon = 1e-6) {
1480
+ for (let i = 0; i < 9; i++) {
1481
+ const av = a[i];
1482
+ const bv = b[i];
1483
+ if (Number.isNaN(av) || Number.isNaN(bv)) return false;
1484
+ if (Math.abs(av - bv) > epsilon) return false;
1485
+ }
1486
+ return true;
1487
+ }
1488
+ function multiply2(out, a, b) {
1489
+ const a00 = a[0];
1490
+ const a01 = a[1];
1491
+ const a02 = a[2];
1492
+ const a10 = a[3];
1493
+ const a11 = a[4];
1494
+ const a12 = a[5];
1495
+ const a20 = a[6];
1496
+ const a21 = a[7];
1497
+ const a22 = a[8];
1498
+ const b00 = b[0];
1499
+ const b01 = b[1];
1500
+ const b02 = b[2];
1501
+ const b10 = b[3];
1502
+ const b11 = b[4];
1503
+ const b12 = b[5];
1504
+ const b20 = b[6];
1505
+ const b21 = b[7];
1506
+ const b22 = b[8];
1507
+ out[0] = a00 * b00 + a10 * b01 + a20 * b02;
1508
+ out[1] = a01 * b00 + a11 * b01 + a21 * b02;
1509
+ out[2] = a02 * b00 + a12 * b01 + a22 * b02;
1510
+ out[3] = a00 * b10 + a10 * b11 + a20 * b12;
1511
+ out[4] = a01 * b10 + a11 * b11 + a21 * b12;
1512
+ out[5] = a02 * b10 + a12 * b11 + a22 * b12;
1513
+ out[6] = a00 * b20 + a10 * b21 + a20 * b22;
1514
+ out[7] = a01 * b20 + a11 * b21 + a21 * b22;
1515
+ out[8] = a02 * b20 + a12 * b21 + a22 * b22;
1516
+ return out;
1517
+ }
1518
+ function transpose(out, a) {
1519
+ const a01 = a[1];
1520
+ const a02 = a[2];
1521
+ const a12 = a[5];
1522
+ const a10 = a[3];
1523
+ const a20 = a[6];
1524
+ const a21 = a[7];
1525
+ out[0] = a[0];
1526
+ out[1] = a10;
1527
+ out[2] = a20;
1528
+ out[3] = a01;
1529
+ out[4] = a[4];
1530
+ out[5] = a21;
1531
+ out[6] = a02;
1532
+ out[7] = a12;
1533
+ out[8] = a[8];
1534
+ return out;
1535
+ }
1536
+ function invert2(out, a) {
1537
+ const a00 = a[0];
1538
+ const a01 = a[1];
1539
+ const a02 = a[2];
1540
+ const a10 = a[3];
1541
+ const a11 = a[4];
1542
+ const a12 = a[5];
1543
+ const a20 = a[6];
1544
+ const a21 = a[7];
1545
+ const a22 = a[8];
1546
+ const b01 = a22 * a11 - a12 * a21;
1547
+ const b11 = -a22 * a10 + a12 * a20;
1548
+ const b21 = a21 * a10 - a11 * a20;
1549
+ const det = a00 * b01 + a01 * b11 + a02 * b21;
1550
+ if (Math.abs(det) < EPS_DET) {
1551
+ return identity2(out);
1552
+ }
1553
+ const invDet = 1 / det;
1554
+ out[0] = b01 * invDet;
1555
+ out[1] = (-a22 * a01 + a02 * a21) * invDet;
1556
+ out[2] = (a12 * a01 - a02 * a11) * invDet;
1557
+ out[3] = b11 * invDet;
1558
+ out[4] = (a22 * a00 - a02 * a20) * invDet;
1559
+ out[5] = (-a12 * a00 + a02 * a10) * invDet;
1560
+ out[6] = b21 * invDet;
1561
+ out[7] = (-a21 * a00 + a01 * a20) * invDet;
1562
+ out[8] = (a11 * a00 - a01 * a10) * invDet;
1563
+ return out;
1564
+ }
1565
+ function scale(out, a, v) {
1566
+ const x = v[0];
1567
+ const y = v[1];
1568
+ const z = v[2];
1569
+ out[0] = a[0] * x;
1570
+ out[1] = a[1] * x;
1571
+ out[2] = a[2] * x;
1572
+ out[3] = a[3] * y;
1573
+ out[4] = a[4] * y;
1574
+ out[5] = a[5] * y;
1575
+ out[6] = a[6] * z;
1576
+ out[7] = a[7] * z;
1577
+ out[8] = a[8] * z;
1578
+ return out;
1579
+ }
1580
+ function fromMat4(out, m) {
1581
+ out[0] = m[0];
1582
+ out[1] = m[1];
1583
+ out[2] = m[2];
1584
+ out[3] = m[4];
1585
+ out[4] = m[5];
1586
+ out[5] = m[6];
1587
+ out[6] = m[8];
1588
+ out[7] = m[9];
1589
+ out[8] = m[10];
1590
+ return out;
1591
+ }
1592
+ function normalMatrix(out, m) {
1593
+ const m00 = m[0];
1594
+ const m01 = m[1];
1595
+ const m02 = m[2];
1596
+ const m10 = m[4];
1597
+ const m11 = m[5];
1598
+ const m12 = m[6];
1599
+ const m20 = m[8];
1600
+ const m21 = m[9];
1601
+ const m22 = m[10];
1602
+ const b01 = m22 * m11 - m12 * m21;
1603
+ const b11 = -m22 * m10 + m12 * m20;
1604
+ const b21 = m21 * m10 - m11 * m20;
1605
+ const det = m00 * b01 + m01 * b11 + m02 * b21;
1606
+ if (Math.abs(det) < EPS_DET) {
1607
+ return identity2(out);
1608
+ }
1609
+ const invDet = 1 / det;
1610
+ out[0] = b01 * invDet;
1611
+ out[3] = (-m22 * m01 + m02 * m21) * invDet;
1612
+ out[6] = (m12 * m01 - m02 * m11) * invDet;
1613
+ out[1] = b11 * invDet;
1614
+ out[4] = (m22 * m00 - m02 * m20) * invDet;
1615
+ out[7] = (-m12 * m00 + m02 * m10) * invDet;
1616
+ out[2] = b21 * invDet;
1617
+ out[5] = (-m21 * m00 + m01 * m20) * invDet;
1618
+ out[8] = (m11 * m00 - m01 * m10) * invDet;
1619
+ return out;
1620
+ }
1621
+
1622
+ // src/mat4.ts
1623
+ var mat4_exports = {};
1624
+ __export(mat4_exports, {
1625
+ clone: () => clone6,
1626
+ compose: () => compose,
1627
+ computeViewProj: () => computeViewProj,
1628
+ create: () => create10,
1629
+ decompose: () => decompose,
1630
+ equals: () => equals3,
1631
+ fromQuat: () => fromQuat2,
1632
+ fromRotation: () => fromRotation,
1633
+ fromScaling: () => fromScaling,
1634
+ fromTranslation: () => fromTranslation,
1635
+ getForward: () => getForward,
1636
+ getRight: () => getRight,
1637
+ getTranslation: () => getTranslation,
1638
+ getUp: () => getUp,
1639
+ identity: () => identity3,
1640
+ invert: () => invert3,
1641
+ lookAt: () => lookAt,
1642
+ multiply: () => multiply3,
1643
+ orthographic: () => orthographic,
1644
+ orthographicNO: () => orthographicNO,
1645
+ orthographicReverseZ: () => orthographicReverseZ,
1646
+ perspective: () => perspective,
1647
+ perspectiveNO: () => perspectiveNO,
1648
+ perspectiveReverseZ: () => perspectiveReverseZ,
1649
+ projectPoint: () => projectPoint,
1650
+ rotate: () => rotate,
1651
+ scale: () => scale3,
1652
+ transformDirection: () => transformDirection,
1653
+ transformPoint: () => transformPoint,
1654
+ transformVec3: () => transformVec32,
1655
+ translate: () => translate,
1656
+ transpose: () => transpose2,
1657
+ unproject: () => unproject
1658
+ });
1659
+
1660
+ // src/vec3.ts
1661
+ var vec3_exports = {};
1662
+ __export(vec3_exports, {
1663
+ add: () => add,
1664
+ catmullRom: () => catmullRom,
1665
+ clone: () => clone5,
1666
+ copy: () => copy,
1667
+ create: () => create9,
1668
+ cross: () => cross,
1669
+ distance: () => distance,
1670
+ distanceSq: () => distanceSq,
1671
+ dot: () => dot2,
1672
+ equals: () => equals2,
1673
+ length: () => length2,
1674
+ lengthSq: () => lengthSq2,
1675
+ lerp: () => lerp2,
1676
+ max: () => max,
1677
+ min: () => min,
1678
+ negate: () => negate,
1679
+ normalize: () => normalize2,
1680
+ scale: () => scale2,
1681
+ set: () => set2,
1682
+ smoothDamp: () => smoothDamp,
1683
+ sub: () => sub
1684
+ });
1685
+ function create9(x = 0, y = 0, z = 0) {
1686
+ return Float32Array.of(x, y, z);
1687
+ }
1688
+ function clone5(a) {
1689
+ return Float32Array.of(a[0], a[1], a[2]);
1690
+ }
1691
+ function copy(out, a) {
1692
+ out[0] = a[0];
1693
+ out[1] = a[1];
1694
+ out[2] = a[2];
1695
+ return out;
1696
+ }
1697
+ function set2(out, x, y, z) {
1698
+ out[0] = x;
1699
+ out[1] = y;
1700
+ out[2] = z;
1701
+ return out;
1702
+ }
1703
+ function equals2(a, b, epsilon = 1e-6) {
1704
+ const ax = a[0];
1705
+ const ay = a[1];
1706
+ const az = a[2];
1707
+ const bx = b[0];
1708
+ const by = b[1];
1709
+ const bz = b[2];
1710
+ if (Number.isNaN(ax) || Number.isNaN(ay) || Number.isNaN(az) || Number.isNaN(bx) || Number.isNaN(by) || Number.isNaN(bz)) {
1711
+ return false;
1712
+ }
1713
+ return Math.abs(ax - bx) <= epsilon && Math.abs(ay - by) <= epsilon && Math.abs(az - bz) <= epsilon;
1714
+ }
1715
+ function add(out, a, b) {
1716
+ const ax = a[0];
1717
+ const ay = a[1];
1718
+ const az = a[2];
1719
+ const bx = b[0];
1720
+ const by = b[1];
1721
+ const bz = b[2];
1722
+ out[0] = ax + bx;
1723
+ out[1] = ay + by;
1724
+ out[2] = az + bz;
1725
+ return out;
1726
+ }
1727
+ function sub(out, a, b) {
1728
+ const ax = a[0];
1729
+ const ay = a[1];
1730
+ const az = a[2];
1731
+ const bx = b[0];
1732
+ const by = b[1];
1733
+ const bz = b[2];
1734
+ out[0] = ax - bx;
1735
+ out[1] = ay - by;
1736
+ out[2] = az - bz;
1737
+ return out;
1738
+ }
1739
+ function scale2(out, a, s) {
1740
+ out[0] = a[0] * s;
1741
+ out[1] = a[1] * s;
1742
+ out[2] = a[2] * s;
1743
+ return out;
1744
+ }
1745
+ function negate(out, a) {
1746
+ out[0] = 0 - a[0];
1747
+ out[1] = 0 - a[1];
1748
+ out[2] = 0 - a[2];
1749
+ return out;
1750
+ }
1751
+ function dot2(a, b) {
1752
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
1753
+ }
1754
+ function cross(out, a, b) {
1755
+ const ax = a[0];
1756
+ const ay = a[1];
1757
+ const az = a[2];
1758
+ const bx = b[0];
1759
+ const by = b[1];
1760
+ const bz = b[2];
1761
+ out[0] = ay * bz - az * by;
1762
+ out[1] = az * bx - ax * bz;
1763
+ out[2] = ax * by - ay * bx;
1764
+ return out;
1765
+ }
1766
+ function lengthSq2(a) {
1767
+ const x = a[0];
1768
+ const y = a[1];
1769
+ const z = a[2];
1770
+ return x * x + y * y + z * z;
1771
+ }
1772
+ function length2(a) {
1773
+ const x = a[0];
1774
+ const y = a[1];
1775
+ const z = a[2];
1776
+ return Math.sqrt(x * x + y * y + z * z);
1777
+ }
1778
+ function distance(a, b) {
1779
+ const dx = a[0] - b[0];
1780
+ const dy = a[1] - b[1];
1781
+ const dz = a[2] - b[2];
1782
+ return Math.sqrt(dx * dx + dy * dy + dz * dz);
1783
+ }
1784
+ function distanceSq(a, b) {
1785
+ const dx = a[0] - b[0];
1786
+ const dy = a[1] - b[1];
1787
+ const dz = a[2] - b[2];
1788
+ return dx * dx + dy * dy + dz * dz;
1789
+ }
1790
+ function normalize2(out, a) {
1791
+ const x = a[0];
1792
+ const y = a[1];
1793
+ const z = a[2];
1794
+ const lenSq = x * x + y * y + z * z;
1795
+ if (lenSq < EPS_NORMALIZE) {
1796
+ out[0] = 0;
1797
+ out[1] = 0;
1798
+ out[2] = 0;
1799
+ return out;
1800
+ }
1801
+ const inv = 1 / Math.sqrt(lenSq);
1802
+ out[0] = x * inv;
1803
+ out[1] = y * inv;
1804
+ out[2] = z * inv;
1805
+ return out;
1806
+ }
1807
+ function lerp2(out, a, b, t) {
1808
+ const ax = a[0];
1809
+ const ay = a[1];
1810
+ const az = a[2];
1811
+ const bx = b[0];
1812
+ const by = b[1];
1813
+ const bz = b[2];
1814
+ out[0] = lerp(ax, bx, t);
1815
+ out[1] = lerp(ay, by, t);
1816
+ out[2] = lerp(az, bz, t);
1817
+ return out;
1818
+ }
1819
+ function smoothDamp(out, current, target, decayRate, dt) {
1820
+ return lerp2(out, current, target, smoothDecayFactor(decayRate, dt));
1821
+ }
1822
+ function catmullRom(out, p0, p1, p2, p3, t) {
1823
+ const x = catmullRomScalar(p0[0], p1[0], p2[0], p3[0], t);
1824
+ const y = catmullRomScalar(p0[1], p1[1], p2[1], p3[1], t);
1825
+ const z = catmullRomScalar(p0[2], p1[2], p2[2], p3[2], t);
1826
+ out[0] = x;
1827
+ out[1] = y;
1828
+ out[2] = z;
1829
+ return out;
1830
+ }
1831
+ function min(out, a, b) {
1832
+ out[0] = Math.min(a[0], b[0]);
1833
+ out[1] = Math.min(a[1], b[1]);
1834
+ out[2] = Math.min(a[2], b[2]);
1835
+ return out;
1836
+ }
1837
+ function max(out, a, b) {
1838
+ out[0] = Math.max(a[0], b[0]);
1839
+ out[1] = Math.max(a[1], b[1]);
1840
+ out[2] = Math.max(a[2], b[2]);
1841
+ return out;
1842
+ }
1843
+
1844
+ // src/mat4.ts
1845
+ function create10() {
1846
+ return new Float32Array(16);
1847
+ }
1848
+ function clone6(a) {
1849
+ const r = new Float32Array(16);
1850
+ for (let i = 0; i < 16; i++) r[i] = a[i];
1851
+ return r;
1852
+ }
1853
+ function identity3(out) {
1854
+ out[0] = 1;
1855
+ out[1] = 0;
1856
+ out[2] = 0;
1857
+ out[3] = 0;
1858
+ out[4] = 0;
1859
+ out[5] = 1;
1860
+ out[6] = 0;
1861
+ out[7] = 0;
1862
+ out[8] = 0;
1863
+ out[9] = 0;
1864
+ out[10] = 1;
1865
+ out[11] = 0;
1866
+ out[12] = 0;
1867
+ out[13] = 0;
1868
+ out[14] = 0;
1869
+ out[15] = 1;
1870
+ return out;
1871
+ }
1872
+ function equals3(a, b, epsilon = 1e-6) {
1873
+ for (let i = 0; i < 16; i++) {
1874
+ const av = a[i];
1875
+ const bv = b[i];
1876
+ if (Number.isNaN(av) || Number.isNaN(bv)) return false;
1877
+ if (Math.abs(av - bv) > epsilon) return false;
1878
+ }
1879
+ return true;
1880
+ }
1881
+ function multiply3(out, a, b) {
1882
+ const a00 = a[0];
1883
+ const a01 = a[1];
1884
+ const a02 = a[2];
1885
+ const a03 = a[3];
1886
+ const a10 = a[4];
1887
+ const a11 = a[5];
1888
+ const a12 = a[6];
1889
+ const a13 = a[7];
1890
+ const a20 = a[8];
1891
+ const a21 = a[9];
1892
+ const a22 = a[10];
1893
+ const a23 = a[11];
1894
+ const a30 = a[12];
1895
+ const a31 = a[13];
1896
+ const a32 = a[14];
1897
+ const a33 = a[15];
1898
+ const b00 = b[0];
1899
+ const b01 = b[1];
1900
+ const b02 = b[2];
1901
+ const b03 = b[3];
1902
+ const b10 = b[4];
1903
+ const b11 = b[5];
1904
+ const b12 = b[6];
1905
+ const b13 = b[7];
1906
+ const b20 = b[8];
1907
+ const b21 = b[9];
1908
+ const b22 = b[10];
1909
+ const b23 = b[11];
1910
+ const b30 = b[12];
1911
+ const b31 = b[13];
1912
+ const b32 = b[14];
1913
+ const b33 = b[15];
1914
+ out[0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03;
1915
+ out[1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03;
1916
+ out[2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03;
1917
+ out[3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03;
1918
+ out[4] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13;
1919
+ out[5] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13;
1920
+ out[6] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13;
1921
+ out[7] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13;
1922
+ out[8] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23;
1923
+ out[9] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23;
1924
+ out[10] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23;
1925
+ out[11] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23;
1926
+ out[12] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33;
1927
+ out[13] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33;
1928
+ out[14] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33;
1929
+ out[15] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33;
1930
+ return out;
1931
+ }
1932
+ function transpose2(out, a) {
1933
+ const a01 = a[1];
1934
+ const a02 = a[2];
1935
+ const a03 = a[3];
1936
+ const a12 = a[6];
1937
+ const a13 = a[7];
1938
+ const a23 = a[11];
1939
+ const a10 = a[4];
1940
+ const a20 = a[8];
1941
+ const a30 = a[12];
1942
+ const a21 = a[9];
1943
+ const a31 = a[13];
1944
+ const a32 = a[14];
1945
+ out[0] = a[0];
1946
+ out[1] = a10;
1947
+ out[2] = a20;
1948
+ out[3] = a30;
1949
+ out[4] = a01;
1950
+ out[5] = a[5];
1951
+ out[6] = a21;
1952
+ out[7] = a31;
1953
+ out[8] = a02;
1954
+ out[9] = a12;
1955
+ out[10] = a[10];
1956
+ out[11] = a32;
1957
+ out[12] = a03;
1958
+ out[13] = a13;
1959
+ out[14] = a23;
1960
+ out[15] = a[15];
1961
+ return out;
1962
+ }
1963
+ function invert3(out, a) {
1964
+ const a00 = a[0];
1965
+ const a01 = a[1];
1966
+ const a02 = a[2];
1967
+ const a03 = a[3];
1968
+ const a10 = a[4];
1969
+ const a11 = a[5];
1970
+ const a12 = a[6];
1971
+ const a13 = a[7];
1972
+ const a20 = a[8];
1973
+ const a21 = a[9];
1974
+ const a22 = a[10];
1975
+ const a23 = a[11];
1976
+ const a30 = a[12];
1977
+ const a31 = a[13];
1978
+ const a32 = a[14];
1979
+ const a33 = a[15];
1980
+ const b00 = a00 * a11 - a01 * a10;
1981
+ const b01 = a00 * a12 - a02 * a10;
1982
+ const b02 = a00 * a13 - a03 * a10;
1983
+ const b03 = a01 * a12 - a02 * a11;
1984
+ const b04 = a01 * a13 - a03 * a11;
1985
+ const b05 = a02 * a13 - a03 * a12;
1986
+ const b06 = a20 * a31 - a21 * a30;
1987
+ const b07 = a20 * a32 - a22 * a30;
1988
+ const b08 = a20 * a33 - a23 * a30;
1989
+ const b09 = a21 * a32 - a22 * a31;
1990
+ const b10 = a21 * a33 - a23 * a31;
1991
+ const b11 = a22 * a33 - a23 * a32;
1992
+ const det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1993
+ if (Math.abs(det) < EPS_DET) {
1994
+ return identity3(out);
1995
+ }
1996
+ const invDet = 1 / det;
1997
+ out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet;
1998
+ out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * invDet;
1999
+ out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * invDet;
2000
+ out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * invDet;
2001
+ out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * invDet;
2002
+ out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * invDet;
2003
+ out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * invDet;
2004
+ out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * invDet;
2005
+ out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * invDet;
2006
+ out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * invDet;
2007
+ out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * invDet;
2008
+ out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * invDet;
2009
+ out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * invDet;
2010
+ out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * invDet;
2011
+ out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * invDet;
2012
+ out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * invDet;
2013
+ return out;
2014
+ }
2015
+ function scale3(out, a, v) {
2016
+ const x = v[0];
2017
+ const y = v[1];
2018
+ const z = v[2];
2019
+ out[0] = a[0] * x;
2020
+ out[1] = a[1] * x;
2021
+ out[2] = a[2] * x;
2022
+ out[3] = a[3] * x;
2023
+ out[4] = a[4] * y;
2024
+ out[5] = a[5] * y;
2025
+ out[6] = a[6] * y;
2026
+ out[7] = a[7] * y;
2027
+ out[8] = a[8] * z;
2028
+ out[9] = a[9] * z;
2029
+ out[10] = a[10] * z;
2030
+ out[11] = a[11] * z;
2031
+ out[12] = a[12];
2032
+ out[13] = a[13];
2033
+ out[14] = a[14];
2034
+ out[15] = a[15];
2035
+ return out;
2036
+ }
2037
+ function translate(out, a, v) {
2038
+ const x = v[0];
2039
+ const y = v[1];
2040
+ const z = v[2];
2041
+ if (a === out) {
2042
+ out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
2043
+ out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
2044
+ out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
2045
+ out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
2046
+ return out;
2047
+ }
2048
+ const a00 = a[0];
2049
+ const a01 = a[1];
2050
+ const a02 = a[2];
2051
+ const a03 = a[3];
2052
+ const a10 = a[4];
2053
+ const a11 = a[5];
2054
+ const a12 = a[6];
2055
+ const a13 = a[7];
2056
+ const a20 = a[8];
2057
+ const a21 = a[9];
2058
+ const a22 = a[10];
2059
+ const a23 = a[11];
2060
+ out[0] = a00;
2061
+ out[1] = a01;
2062
+ out[2] = a02;
2063
+ out[3] = a03;
2064
+ out[4] = a10;
2065
+ out[5] = a11;
2066
+ out[6] = a12;
2067
+ out[7] = a13;
2068
+ out[8] = a20;
2069
+ out[9] = a21;
2070
+ out[10] = a22;
2071
+ out[11] = a23;
2072
+ out[12] = a00 * x + a10 * y + a20 * z + a[12];
2073
+ out[13] = a01 * x + a11 * y + a21 * z + a[13];
2074
+ out[14] = a02 * x + a12 * y + a22 * z + a[14];
2075
+ out[15] = a03 * x + a13 * y + a23 * z + a[15];
2076
+ return out;
2077
+ }
2078
+ function rotate(out, a, axis, rad) {
2079
+ let x = axis[0];
2080
+ let y = axis[1];
2081
+ let z = axis[2];
2082
+ const lenSq = x * x + y * y + z * z;
2083
+ if (lenSq < EPS_NORMALIZE) {
2084
+ if (out !== a) {
2085
+ for (let i = 0; i < 16; i++) out[i] = a[i];
2086
+ }
2087
+ return out;
2088
+ }
2089
+ const invLen = 1 / Math.sqrt(lenSq);
2090
+ x *= invLen;
2091
+ y *= invLen;
2092
+ z *= invLen;
2093
+ const s = Math.sin(rad);
2094
+ const c = Math.cos(rad);
2095
+ const t = 1 - c;
2096
+ const r00 = x * x * t + c;
2097
+ const r01 = y * x * t + z * s;
2098
+ const r02 = z * x * t - y * s;
2099
+ const r10 = x * y * t - z * s;
2100
+ const r11 = y * y * t + c;
2101
+ const r12 = z * y * t + x * s;
2102
+ const r20 = x * z * t + y * s;
2103
+ const r21 = y * z * t - x * s;
2104
+ const r22 = z * z * t + c;
2105
+ const a00 = a[0];
2106
+ const a01 = a[1];
2107
+ const a02 = a[2];
2108
+ const a03 = a[3];
2109
+ const a10 = a[4];
2110
+ const a11 = a[5];
2111
+ const a12 = a[6];
2112
+ const a13 = a[7];
2113
+ const a20 = a[8];
2114
+ const a21 = a[9];
2115
+ const a22 = a[10];
2116
+ const a23 = a[11];
2117
+ out[0] = a00 * r00 + a10 * r01 + a20 * r02;
2118
+ out[1] = a01 * r00 + a11 * r01 + a21 * r02;
2119
+ out[2] = a02 * r00 + a12 * r01 + a22 * r02;
2120
+ out[3] = a03 * r00 + a13 * r01 + a23 * r02;
2121
+ out[4] = a00 * r10 + a10 * r11 + a20 * r12;
2122
+ out[5] = a01 * r10 + a11 * r11 + a21 * r12;
2123
+ out[6] = a02 * r10 + a12 * r11 + a22 * r12;
2124
+ out[7] = a03 * r10 + a13 * r11 + a23 * r12;
2125
+ out[8] = a00 * r20 + a10 * r21 + a20 * r22;
2126
+ out[9] = a01 * r20 + a11 * r21 + a21 * r22;
2127
+ out[10] = a02 * r20 + a12 * r21 + a22 * r22;
2128
+ out[11] = a03 * r20 + a13 * r21 + a23 * r22;
2129
+ out[12] = a[12];
2130
+ out[13] = a[13];
2131
+ out[14] = a[14];
2132
+ out[15] = a[15];
2133
+ return out;
2134
+ }
2135
+ function lookAt(out, eye, target, up2) {
2136
+ const ex = eye[0];
2137
+ const ey = eye[1];
2138
+ const ez = eye[2];
2139
+ const tx = target[0];
2140
+ const ty = target[1];
2141
+ const tz = target[2];
2142
+ const upx = up2[0];
2143
+ const upy = up2[1];
2144
+ const upz = up2[2];
2145
+ let fx = ex - tx;
2146
+ let fy = ey - ty;
2147
+ let fz = ez - tz;
2148
+ const fLenSq = fx * fx + fy * fy + fz * fz;
2149
+ if (fLenSq < EPS_NORMALIZE) {
2150
+ return identity3(out);
2151
+ }
2152
+ const fInv = 1 / Math.sqrt(fLenSq);
2153
+ fx *= fInv;
2154
+ fy *= fInv;
2155
+ fz *= fInv;
2156
+ let rx = upy * fz - upz * fy;
2157
+ let ry = upz * fx - upx * fz;
2158
+ let rz = upx * fy - upy * fx;
2159
+ let rLenSq = rx * rx + ry * ry + rz * rz;
2160
+ if (rLenSq < EPS_NORMALIZE) {
2161
+ rx = 0 * fz - 1 * fy;
2162
+ ry = 1 * fx - 0 * fz;
2163
+ rz = 0 * fy - 0 * fx;
2164
+ rLenSq = rx * rx + ry * ry + rz * rz;
2165
+ if (rLenSq < EPS_NORMALIZE) {
2166
+ rx = 0 * fz - 0 * fy;
2167
+ ry = 0 * fx - 1 * fz;
2168
+ rz = 1 * fy - 0 * fx;
2169
+ rLenSq = rx * rx + ry * ry + rz * rz;
2170
+ }
2171
+ }
2172
+ const rInv = 1 / Math.sqrt(rLenSq);
2173
+ rx *= rInv;
2174
+ ry *= rInv;
2175
+ rz *= rInv;
2176
+ const ux = fy * rz - fz * ry;
2177
+ const uy = fz * rx - fx * rz;
2178
+ const uz = fx * ry - fy * rx;
2179
+ out[0] = rx;
2180
+ out[1] = ux;
2181
+ out[2] = fx;
2182
+ out[3] = 0;
2183
+ out[4] = ry;
2184
+ out[5] = uy;
2185
+ out[6] = fy;
2186
+ out[7] = 0;
2187
+ out[8] = rz;
2188
+ out[9] = uz;
2189
+ out[10] = fz;
2190
+ out[11] = 0;
2191
+ out[12] = -(rx * ex + ry * ey + rz * ez);
2192
+ out[13] = -(ux * ex + uy * ey + uz * ez);
2193
+ out[14] = -(fx * ex + fy * ey + fz * ez);
2194
+ out[15] = 1;
2195
+ return out;
2196
+ }
2197
+ function compose(out, t, r, s) {
2198
+ const x = r[0];
2199
+ const y = r[1];
2200
+ const z = r[2];
2201
+ const w = r[3];
2202
+ const x2 = x + x;
2203
+ const y2 = y + y;
2204
+ const z2 = z + z;
2205
+ const xx = x * x2;
2206
+ const xy = x * y2;
2207
+ const xz = x * z2;
2208
+ const yy = y * y2;
2209
+ const yz = y * z2;
2210
+ const zz = z * z2;
2211
+ const wx = w * x2;
2212
+ const wy = w * y2;
2213
+ const wz = w * z2;
2214
+ const sx = s[0];
2215
+ const sy = s[1];
2216
+ const sz = s[2];
2217
+ out[0] = (1 - (yy + zz)) * sx;
2218
+ out[1] = (xy + wz) * sx;
2219
+ out[2] = (xz - wy) * sx;
2220
+ out[3] = 0;
2221
+ out[4] = (xy - wz) * sy;
2222
+ out[5] = (1 - (xx + zz)) * sy;
2223
+ out[6] = (yz + wx) * sy;
2224
+ out[7] = 0;
2225
+ out[8] = (xz + wy) * sz;
2226
+ out[9] = (yz - wx) * sz;
2227
+ out[10] = (1 - (xx + yy)) * sz;
2228
+ out[11] = 0;
2229
+ out[12] = t[0];
2230
+ out[13] = t[1];
2231
+ out[14] = t[2];
2232
+ out[15] = 1;
2233
+ return out;
2234
+ }
2235
+ function decompose(out_t, out_r, out_s, m) {
2236
+ out_t[0] = m[12];
2237
+ out_t[1] = m[13];
2238
+ out_t[2] = m[14];
2239
+ const sx = Math.hypot(m[0], m[1], m[2]);
2240
+ const sy = Math.hypot(m[4], m[5], m[6]);
2241
+ const sz = Math.hypot(m[8], m[9], m[10]);
2242
+ const det = m[0] * (m[5] * m[10] - m[6] * m[9]) - m[1] * (m[4] * m[10] - m[6] * m[8]) + m[2] * (m[4] * m[9] - m[5] * m[8]);
2243
+ const sxFinal = det < 0 ? -sx : sx;
2244
+ out_s[0] = sxFinal;
2245
+ out_s[1] = sy;
2246
+ out_s[2] = sz;
2247
+ const invSx = sxFinal === 0 ? 0 : 1 / sxFinal;
2248
+ const invSy = sy === 0 ? 0 : 1 / sy;
2249
+ const invSz = sz === 0 ? 0 : 1 / sz;
2250
+ const r00 = m[0] * invSx;
2251
+ const r01 = m[1] * invSx;
2252
+ const r02 = m[2] * invSx;
2253
+ const r10 = m[4] * invSy;
2254
+ const r11 = m[5] * invSy;
2255
+ const r12 = m[6] * invSy;
2256
+ const r20 = m[8] * invSz;
2257
+ const r21 = m[9] * invSz;
2258
+ const r22 = m[10] * invSz;
2259
+ const trace = r00 + r11 + r22;
2260
+ if (trace > 0) {
2261
+ const s = 0.5 / Math.sqrt(trace + 1);
2262
+ out_r[0] = (r12 - r21) * s;
2263
+ out_r[1] = (r20 - r02) * s;
2264
+ out_r[2] = (r01 - r10) * s;
2265
+ out_r[3] = 0.25 / s;
2266
+ } else if (r00 > r11 && r00 > r22) {
2267
+ const s = 2 * Math.sqrt(1 + r00 - r11 - r22);
2268
+ out_r[0] = 0.25 * s;
2269
+ out_r[1] = (r10 + r01) / s;
2270
+ out_r[2] = (r20 + r02) / s;
2271
+ out_r[3] = (r12 - r21) / s;
2272
+ } else if (r11 > r22) {
2273
+ const s = 2 * Math.sqrt(1 + r11 - r00 - r22);
2274
+ out_r[0] = (r10 + r01) / s;
2275
+ out_r[1] = 0.25 * s;
2276
+ out_r[2] = (r21 + r12) / s;
2277
+ out_r[3] = (r20 - r02) / s;
2278
+ } else {
2279
+ const s = 2 * Math.sqrt(1 + r22 - r00 - r11);
2280
+ out_r[0] = (r20 + r02) / s;
2281
+ out_r[1] = (r21 + r12) / s;
2282
+ out_r[2] = 0.25 * s;
2283
+ out_r[3] = (r01 - r10) / s;
2284
+ }
2285
+ }
2286
+ function fromQuat2(out, q) {
2287
+ const x = q[0];
2288
+ const y = q[1];
2289
+ const z = q[2];
2290
+ const w = q[3];
2291
+ const x2 = x + x;
2292
+ const y2 = y + y;
2293
+ const z2 = z + z;
2294
+ const xx = x * x2;
2295
+ const xy = x * y2;
2296
+ const xz = x * z2;
2297
+ const yy = y * y2;
2298
+ const yz = y * z2;
2299
+ const zz = z * z2;
2300
+ const wx = w * x2;
2301
+ const wy = w * y2;
2302
+ const wz = w * z2;
2303
+ out[0] = 1 - (yy + zz);
2304
+ out[1] = xy + wz;
2305
+ out[2] = xz - wy;
2306
+ out[3] = 0;
2307
+ out[4] = xy - wz;
2308
+ out[5] = 1 - (xx + zz);
2309
+ out[6] = yz + wx;
2310
+ out[7] = 0;
2311
+ out[8] = xz + wy;
2312
+ out[9] = yz - wx;
2313
+ out[10] = 1 - (xx + yy);
2314
+ out[11] = 0;
2315
+ out[12] = 0;
2316
+ out[13] = 0;
2317
+ out[14] = 0;
2318
+ out[15] = 1;
2319
+ return out;
2320
+ }
2321
+ function fromTranslation(out, v) {
2322
+ out[0] = 1;
2323
+ out[1] = 0;
2324
+ out[2] = 0;
2325
+ out[3] = 0;
2326
+ out[4] = 0;
2327
+ out[5] = 1;
2328
+ out[6] = 0;
2329
+ out[7] = 0;
2330
+ out[8] = 0;
2331
+ out[9] = 0;
2332
+ out[10] = 1;
2333
+ out[11] = 0;
2334
+ out[12] = v[0];
2335
+ out[13] = v[1];
2336
+ out[14] = v[2];
2337
+ out[15] = 1;
2338
+ return out;
2339
+ }
2340
+ function fromScaling(out, v) {
2341
+ out[0] = v[0];
2342
+ out[1] = 0;
2343
+ out[2] = 0;
2344
+ out[3] = 0;
2345
+ out[4] = 0;
2346
+ out[5] = v[1];
2347
+ out[6] = 0;
2348
+ out[7] = 0;
2349
+ out[8] = 0;
2350
+ out[9] = 0;
2351
+ out[10] = v[2];
2352
+ out[11] = 0;
2353
+ out[12] = 0;
2354
+ out[13] = 0;
2355
+ out[14] = 0;
2356
+ out[15] = 1;
2357
+ return out;
2358
+ }
2359
+ function fromRotation(out, axis, rad) {
2360
+ let x = axis[0];
2361
+ let y = axis[1];
2362
+ let z = axis[2];
2363
+ const lenSq = x * x + y * y + z * z;
2364
+ if (lenSq < EPS_NORMALIZE) {
2365
+ return identity3(out);
2366
+ }
2367
+ const invLen = 1 / Math.sqrt(lenSq);
2368
+ x *= invLen;
2369
+ y *= invLen;
2370
+ z *= invLen;
2371
+ const s = Math.sin(rad);
2372
+ const c = Math.cos(rad);
2373
+ const t = 1 - c;
2374
+ out[0] = x * x * t + c;
2375
+ out[1] = y * x * t + z * s;
2376
+ out[2] = z * x * t - y * s;
2377
+ out[3] = 0;
2378
+ out[4] = x * y * t - z * s;
2379
+ out[5] = y * y * t + c;
2380
+ out[6] = z * y * t + x * s;
2381
+ out[7] = 0;
2382
+ out[8] = x * z * t + y * s;
2383
+ out[9] = y * z * t - x * s;
2384
+ out[10] = z * z * t + c;
2385
+ out[11] = 0;
2386
+ out[12] = 0;
2387
+ out[13] = 0;
2388
+ out[14] = 0;
2389
+ out[15] = 1;
2390
+ return out;
2391
+ }
2392
+ function perspective(out, fovYRadians, aspect, near, far) {
2393
+ const f = 1 / Math.tan(fovYRadians / 2);
2394
+ out[0] = f / aspect;
2395
+ out[1] = 0;
2396
+ out[2] = 0;
2397
+ out[3] = 0;
2398
+ out[4] = 0;
2399
+ out[5] = f;
2400
+ out[6] = 0;
2401
+ out[7] = 0;
2402
+ out[8] = 0;
2403
+ out[9] = 0;
2404
+ out[11] = -1;
2405
+ out[12] = 0;
2406
+ out[13] = 0;
2407
+ out[15] = 0;
2408
+ if (far === Number.POSITIVE_INFINITY) {
2409
+ out[10] = -1;
2410
+ out[14] = -near;
2411
+ } else {
2412
+ const nf = 1 / (near - far);
2413
+ out[10] = far * nf;
2414
+ out[14] = far * near * nf;
2415
+ }
2416
+ return out;
2417
+ }
2418
+ function perspectiveNO(out, fovYRadians, aspect, near, far) {
2419
+ const f = 1 / Math.tan(fovYRadians / 2);
2420
+ out[0] = f / aspect;
2421
+ out[1] = 0;
2422
+ out[2] = 0;
2423
+ out[3] = 0;
2424
+ out[4] = 0;
2425
+ out[5] = f;
2426
+ out[6] = 0;
2427
+ out[7] = 0;
2428
+ out[8] = 0;
2429
+ out[9] = 0;
2430
+ out[11] = -1;
2431
+ out[12] = 0;
2432
+ out[13] = 0;
2433
+ out[15] = 0;
2434
+ if (far === Number.POSITIVE_INFINITY) {
2435
+ out[10] = -1;
2436
+ out[14] = -2 * near;
2437
+ } else {
2438
+ const nf = 1 / (near - far);
2439
+ out[10] = (far + near) * nf;
2440
+ out[14] = 2 * far * near * nf;
2441
+ }
2442
+ return out;
2443
+ }
2444
+ function perspectiveReverseZ(out, fovYRadians, aspect, near, far) {
2445
+ const f = 1 / Math.tan(fovYRadians / 2);
2446
+ out[0] = f / aspect;
2447
+ out[1] = 0;
2448
+ out[2] = 0;
2449
+ out[3] = 0;
2450
+ out[4] = 0;
2451
+ out[5] = f;
2452
+ out[6] = 0;
2453
+ out[7] = 0;
2454
+ out[8] = 0;
2455
+ out[9] = 0;
2456
+ out[11] = -1;
2457
+ out[12] = 0;
2458
+ out[13] = 0;
2459
+ out[15] = 0;
2460
+ if (far === Number.POSITIVE_INFINITY) {
2461
+ out[10] = 0;
2462
+ out[14] = near;
2463
+ } else {
2464
+ const fn = 1 / (far - near);
2465
+ out[10] = near * fn;
2466
+ out[14] = near * far * fn;
2467
+ }
2468
+ return out;
2469
+ }
2470
+ function orthographic(out, left, right2, bottom, top, near, far) {
2471
+ const lr = 1 / (left - right2);
2472
+ const bt = 1 / (bottom - top);
2473
+ const nf = 1 / (near - far);
2474
+ out[0] = -2 * lr;
2475
+ out[1] = 0;
2476
+ out[2] = 0;
2477
+ out[3] = 0;
2478
+ out[4] = 0;
2479
+ out[5] = -2 * bt;
2480
+ out[6] = 0;
2481
+ out[7] = 0;
2482
+ out[8] = 0;
2483
+ out[9] = 0;
2484
+ out[10] = nf;
2485
+ out[11] = 0;
2486
+ out[12] = (left + right2) * lr;
2487
+ out[13] = (top + bottom) * bt;
2488
+ out[14] = near * nf;
2489
+ out[15] = 1;
2490
+ return out;
2491
+ }
2492
+ function orthographicNO(out, left, right2, bottom, top, near, far) {
2493
+ const lr = 1 / (left - right2);
2494
+ const bt = 1 / (bottom - top);
2495
+ const nf = 1 / (near - far);
2496
+ out[0] = -2 * lr;
2497
+ out[1] = 0;
2498
+ out[2] = 0;
2499
+ out[3] = 0;
2500
+ out[4] = 0;
2501
+ out[5] = -2 * bt;
2502
+ out[6] = 0;
2503
+ out[7] = 0;
2504
+ out[8] = 0;
2505
+ out[9] = 0;
2506
+ out[10] = 2 * nf;
2507
+ out[11] = 0;
2508
+ out[12] = (left + right2) * lr;
2509
+ out[13] = (top + bottom) * bt;
2510
+ out[14] = (near + far) * nf;
2511
+ out[15] = 1;
2512
+ return out;
2513
+ }
2514
+ function orthographicReverseZ(out, left, right2, bottom, top, near, far) {
2515
+ const lr = 1 / (left - right2);
2516
+ const bt = 1 / (bottom - top);
2517
+ const fn = 1 / (far - near);
2518
+ out[0] = -2 * lr;
2519
+ out[1] = 0;
2520
+ out[2] = 0;
2521
+ out[3] = 0;
2522
+ out[4] = 0;
2523
+ out[5] = -2 * bt;
2524
+ out[6] = 0;
2525
+ out[7] = 0;
2526
+ out[8] = 0;
2527
+ out[9] = 0;
2528
+ out[10] = fn;
2529
+ out[11] = 0;
2530
+ out[12] = (left + right2) * lr;
2531
+ out[13] = (top + bottom) * bt;
2532
+ out[14] = far * fn;
2533
+ out[15] = 1;
2534
+ return out;
2535
+ }
2536
+ function transformVec32(out, m, v) {
2537
+ const x = v[0];
2538
+ const y = v[1];
2539
+ const z = v[2];
2540
+ const m00 = m[0];
2541
+ const m01 = m[1];
2542
+ const m02 = m[2];
2543
+ const m03 = m[3];
2544
+ const m10 = m[4];
2545
+ const m11 = m[5];
2546
+ const m12 = m[6];
2547
+ const m13 = m[7];
2548
+ const m20 = m[8];
2549
+ const m21 = m[9];
2550
+ const m22 = m[10];
2551
+ const m23 = m[11];
2552
+ const m30 = m[12];
2553
+ const m31 = m[13];
2554
+ const m32 = m[14];
2555
+ const m33 = m[15];
2556
+ const w = m03 * x + m13 * y + m23 * z + m33;
2557
+ if (w === 0) {
2558
+ out[0] = 0;
2559
+ out[1] = 0;
2560
+ out[2] = 0;
2561
+ return out;
2562
+ }
2563
+ const invW = 1 / w;
2564
+ out[0] = (m00 * x + m10 * y + m20 * z + m30) * invW;
2565
+ out[1] = (m01 * x + m11 * y + m21 * z + m31) * invW;
2566
+ out[2] = (m02 * x + m12 * y + m22 * z + m32) * invW;
2567
+ return out;
2568
+ }
2569
+ var transformPoint = transformVec32;
2570
+ function transformDirection(out, m, v) {
2571
+ const x = v[0];
2572
+ const y = v[1];
2573
+ const z = v[2];
2574
+ const m00 = m[0];
2575
+ const m01 = m[1];
2576
+ const m02 = m[2];
2577
+ const m10 = m[4];
2578
+ const m11 = m[5];
2579
+ const m12 = m[6];
2580
+ const m20 = m[8];
2581
+ const m21 = m[9];
2582
+ const m22 = m[10];
2583
+ out[0] = m00 * x + m10 * y + m20 * z;
2584
+ out[1] = m01 * x + m11 * y + m21 * z;
2585
+ out[2] = m02 * x + m12 * y + m22 * z;
2586
+ return normalize2(out, out);
2587
+ }
2588
+ function getTranslation(out, m) {
2589
+ out[0] = m[12];
2590
+ out[1] = m[13];
2591
+ out[2] = m[14];
2592
+ return out;
2593
+ }
2594
+ function getForward(out, m) {
2595
+ out[0] = -m[8];
2596
+ out[1] = -m[9];
2597
+ out[2] = -m[10];
2598
+ return normalize2(out, out);
2599
+ }
2600
+ function getUp(out, m) {
2601
+ out[0] = m[4];
2602
+ out[1] = m[5];
2603
+ out[2] = m[6];
2604
+ return normalize2(out, out);
2605
+ }
2606
+ function getRight(out, m) {
2607
+ out[0] = m[0];
2608
+ out[1] = m[1];
2609
+ out[2] = m[2];
2610
+ return normalize2(out, out);
2611
+ }
2612
+ function unproject(out, ndcPoint, invVP) {
2613
+ return transformVec32(out, invVP, ndcPoint);
2614
+ }
2615
+ function projectPoint(out, worldPos, viewProj) {
2616
+ return transformVec32(out, viewProj, worldPos);
2617
+ }
2618
+ function computeViewProj(out, eye, target, up2, fovYRadians, aspect, near, far) {
2619
+ const view = lookAt(create10(), eye, target, up2);
2620
+ const proj = perspective(create10(), fovYRadians, aspect, near, far);
2621
+ return multiply3(out, proj, view);
2622
+ }
2623
+
2624
+ // src/noise.ts
2625
+ var noise_exports = {};
2626
+ __export(noise_exports, {
2627
+ perlin1d: () => perlin1d
2628
+ });
2629
+ var PERM = new Uint8Array([
2630
+ 151,
2631
+ 160,
2632
+ 137,
2633
+ 91,
2634
+ 90,
2635
+ 15,
2636
+ 131,
2637
+ 13,
2638
+ 201,
2639
+ 95,
2640
+ 96,
2641
+ 53,
2642
+ 194,
2643
+ 233,
2644
+ 7,
2645
+ 225,
2646
+ 140,
2647
+ 36,
2648
+ 103,
2649
+ 30,
2650
+ 69,
2651
+ 142,
2652
+ 8,
2653
+ 99,
2654
+ 37,
2655
+ 240,
2656
+ 21,
2657
+ 10,
2658
+ 23,
2659
+ 190,
2660
+ 6,
2661
+ 148,
2662
+ 247,
2663
+ 120,
2664
+ 234,
2665
+ 75,
2666
+ 0,
2667
+ 26,
2668
+ 197,
2669
+ 62,
2670
+ 94,
2671
+ 252,
2672
+ 219,
2673
+ 203,
2674
+ 117,
2675
+ 35,
2676
+ 11,
2677
+ 32,
2678
+ 57,
2679
+ 177,
2680
+ 33,
2681
+ 88,
2682
+ 237,
2683
+ 149,
2684
+ 56,
2685
+ 87,
2686
+ 174,
2687
+ 20,
2688
+ 125,
2689
+ 136,
2690
+ 171,
2691
+ 168,
2692
+ 68,
2693
+ 175,
2694
+ 74,
2695
+ 165,
2696
+ 71,
2697
+ 134,
2698
+ 139,
2699
+ 48,
2700
+ 27,
2701
+ 166,
2702
+ 77,
2703
+ 146,
2704
+ 158,
2705
+ 231,
2706
+ 83,
2707
+ 111,
2708
+ 229,
2709
+ 122,
2710
+ 60,
2711
+ 211,
2712
+ 133,
2713
+ 230,
2714
+ 220,
2715
+ 105,
2716
+ 92,
2717
+ 41,
2718
+ 55,
2719
+ 46,
2720
+ 245,
2721
+ 40,
2722
+ 244,
2723
+ 102,
2724
+ 143,
2725
+ 54,
2726
+ 65,
2727
+ 25,
2728
+ 63,
2729
+ 161,
2730
+ 1,
2731
+ 216,
2732
+ 80,
2733
+ 73,
2734
+ 209,
2735
+ 76,
2736
+ 132,
2737
+ 187,
2738
+ 208,
2739
+ 89,
2740
+ 18,
2741
+ 169,
2742
+ 200,
2743
+ 196,
2744
+ 135,
2745
+ 130,
2746
+ 116,
2747
+ 188,
2748
+ 159,
2749
+ 86,
2750
+ 164,
2751
+ 100,
2752
+ 109,
2753
+ 198,
2754
+ 173,
2755
+ 186,
2756
+ 3,
2757
+ 64,
2758
+ 52,
2759
+ 217,
2760
+ 226,
2761
+ 250,
2762
+ 124,
2763
+ 123,
2764
+ 5,
2765
+ 202,
2766
+ 38,
2767
+ 147,
2768
+ 118,
2769
+ 126,
2770
+ 255,
2771
+ 82,
2772
+ 85,
2773
+ 212,
2774
+ 207,
2775
+ 206,
2776
+ 59,
2777
+ 227,
2778
+ 47,
2779
+ 16,
2780
+ 58,
2781
+ 17,
2782
+ 182,
2783
+ 189,
2784
+ 28,
2785
+ 42,
2786
+ 223,
2787
+ 183,
2788
+ 170,
2789
+ 213,
2790
+ 119,
2791
+ 248,
2792
+ 152,
2793
+ 2,
2794
+ 44,
2795
+ 154,
2796
+ 163,
2797
+ 70,
2798
+ 221,
2799
+ 153,
2800
+ 101,
2801
+ 155,
2802
+ 167,
2803
+ 43,
2804
+ 172,
2805
+ 9,
2806
+ 129,
2807
+ 22,
2808
+ 39,
2809
+ 253,
2810
+ 19,
2811
+ 98,
2812
+ 108,
2813
+ 110,
2814
+ 79,
2815
+ 113,
2816
+ 224,
2817
+ 232,
2818
+ 178,
2819
+ 185,
2820
+ 112,
2821
+ 104,
2822
+ 218,
2823
+ 246,
2824
+ 97,
2825
+ 228,
2826
+ 251,
2827
+ 34,
2828
+ 242,
2829
+ 193,
2830
+ 238,
2831
+ 210,
2832
+ 144,
2833
+ 12,
2834
+ 191,
2835
+ 179,
2836
+ 162,
2837
+ 241,
2838
+ 81,
2839
+ 51,
2840
+ 145,
2841
+ 235,
2842
+ 249,
2843
+ 14,
2844
+ 239,
2845
+ 107,
2846
+ 49,
2847
+ 192,
2848
+ 214,
2849
+ 31,
2850
+ 181,
2851
+ 199,
2852
+ 106,
2853
+ 157,
2854
+ 184,
2855
+ 84,
2856
+ 204,
2857
+ 176,
2858
+ 115,
2859
+ 121,
2860
+ 50,
2861
+ 45,
2862
+ 127,
2863
+ 4,
2864
+ 150,
2865
+ 254,
2866
+ 138,
2867
+ 236,
2868
+ 205,
2869
+ 93,
2870
+ 222,
2871
+ 114,
2872
+ 67,
2873
+ 29,
2874
+ 24,
2875
+ 72,
2876
+ 243,
2877
+ 141,
2878
+ 128,
2879
+ 195,
2880
+ 78,
2881
+ 66,
2882
+ 215,
2883
+ 61,
2884
+ 156,
2885
+ 180
2886
+ ]);
2887
+ function fade(t) {
2888
+ return t * t * t * (t * (t * 6 - 15) + 10);
2889
+ }
2890
+ function dotGrad(hash, xf) {
2891
+ return hash & 1 ? xf : -xf;
2892
+ }
2893
+ function perlin1d(x) {
2894
+ const xFloor = Math.floor(x);
2895
+ const xi0 = xFloor & 255;
2896
+ const xi1 = xFloor + 1 & 255;
2897
+ const xf0 = x - xFloor;
2898
+ const xf1 = xf0 - 1;
2899
+ const t = fade(xf0);
2900
+ const h0 = PERM[xi0] ?? 0;
2901
+ const h1 = PERM[xi1] ?? 0;
2902
+ const a = dotGrad(h0, xf0);
2903
+ const b = dotGrad(h1, xf1);
2904
+ return a + t * (b - a);
2905
+ }
2906
+
2907
+ // src/ray.ts
2908
+ var ray_exports = {};
2909
+ __export(ray_exports, {
2910
+ create: () => create11,
2911
+ getDirection: () => getDirection,
2912
+ getOrigin: () => getOrigin,
2913
+ rayAabbIntersects: () => rayAabbIntersects,
2914
+ rayTriangleIntersects: () => rayTriangleIntersects,
2915
+ screenToRay: () => screenToRay,
2916
+ setDirection: () => setDirection,
2917
+ setOrigin: () => setOrigin,
2918
+ worldToScreen: () => worldToScreen
2919
+ });
2920
+ function create11(out, origin, direction) {
2921
+ const r = out ?? new Float32Array(6);
2922
+ if (origin) {
2923
+ r[0] = origin[0];
2924
+ r[1] = origin[1];
2925
+ r[2] = origin[2];
2926
+ } else {
2927
+ r[0] = 0;
2928
+ r[1] = 0;
2929
+ r[2] = 0;
2930
+ }
2931
+ if (direction) {
2932
+ const dx = direction[0];
2933
+ const dy = direction[1];
2934
+ const dz = direction[2];
2935
+ const lenSq = dx * dx + dy * dy + dz * dz;
2936
+ if (lenSq < 1e-12) {
2937
+ r[3] = 0;
2938
+ r[4] = 0;
2939
+ r[5] = 0;
2940
+ } else {
2941
+ const inv = 1 / Math.sqrt(lenSq);
2942
+ r[3] = dx * inv;
2943
+ r[4] = dy * inv;
2944
+ r[5] = dz * inv;
2945
+ }
2946
+ } else {
2947
+ r[3] = 0;
2948
+ r[4] = 0;
2949
+ r[5] = -1;
2950
+ }
2951
+ return r;
2952
+ }
2953
+ function getOrigin(out, r) {
2954
+ out[0] = r[0];
2955
+ out[1] = r[1];
2956
+ out[2] = r[2];
2957
+ return out;
2958
+ }
2959
+ function getDirection(out, r) {
2960
+ out[0] = r[3];
2961
+ out[1] = r[4];
2962
+ out[2] = r[5];
2963
+ return out;
2964
+ }
2965
+ function setOrigin(r, o) {
2966
+ r[0] = o[0];
2967
+ r[1] = o[1];
2968
+ r[2] = o[2];
2969
+ return r;
2970
+ }
2971
+ function setDirection(r, d) {
2972
+ const dx = d[0];
2973
+ const dy = d[1];
2974
+ const dz = d[2];
2975
+ const lenSq = dx * dx + dy * dy + dz * dz;
2976
+ if (lenSq < 1e-12) {
2977
+ r[3] = 0;
2978
+ r[4] = 0;
2979
+ r[5] = 0;
2980
+ } else {
2981
+ const inv = 1 / Math.sqrt(lenSq);
2982
+ r[3] = dx * inv;
2983
+ r[4] = dy * inv;
2984
+ r[5] = dz * inv;
2985
+ }
2986
+ return r;
2987
+ }
2988
+ function rayAabbIntersects(r, aabb) {
2989
+ const ox = r[0];
2990
+ const oy = r[1];
2991
+ const oz = r[2];
2992
+ const dx = r[3];
2993
+ const dy = r[4];
2994
+ const dz = r[5];
2995
+ const minX = aabb[0];
2996
+ const minY = aabb[1];
2997
+ const minZ = aabb[2];
2998
+ const maxX = aabb[3];
2999
+ const maxY = aabb[4];
3000
+ const maxZ = aabb[5];
3001
+ const invX = 1 / dx;
3002
+ const invY = 1 / dy;
3003
+ const invZ = 1 / dz;
3004
+ let t1x = (minX - ox) * invX;
3005
+ let t2x = (maxX - ox) * invX;
3006
+ if (invX < 0) {
3007
+ const tmp = t1x;
3008
+ t1x = t2x;
3009
+ t2x = tmp;
3010
+ }
3011
+ let tnear = Number.isNaN(t1x) ? -Infinity : t1x;
3012
+ let tfar = Number.isNaN(t2x) ? Infinity : t2x;
3013
+ let t1y = (minY - oy) * invY;
3014
+ let t2y = (maxY - oy) * invY;
3015
+ if (invY < 0) {
3016
+ const tmp = t1y;
3017
+ t1y = t2y;
3018
+ t2y = tmp;
3019
+ }
3020
+ if (!Number.isNaN(t1y) && t1y > tnear) tnear = t1y;
3021
+ if (!Number.isNaN(t2y) && t2y < tfar) tfar = t2y;
3022
+ if (tnear > tfar) return { hit: false, tmin: 0 };
3023
+ let t1z = (minZ - oz) * invZ;
3024
+ let t2z = (maxZ - oz) * invZ;
3025
+ if (invZ < 0) {
3026
+ const tmp = t1z;
3027
+ t1z = t2z;
3028
+ t2z = tmp;
3029
+ }
3030
+ if (!Number.isNaN(t1z) && t1z > tnear) tnear = t1z;
3031
+ if (!Number.isNaN(t2z) && t2z < tfar) tfar = t2z;
3032
+ if (tfar >= 0 && tfar >= tnear) {
3033
+ return { hit: true, tmin: tnear > 0 ? tnear : 0 };
3034
+ }
3035
+ return { hit: false, tmin: 0 };
3036
+ }
3037
+ var _nearNdC = new Float32Array(3);
3038
+ var _farNdC = new Float32Array(3);
3039
+ var _nearWorld = new Float32Array(3);
3040
+ var _farWorld = new Float32Array(3);
3041
+ var _tmpInvVP = new Float32Array(16);
3042
+ function screenToRay(out, screenX, screenY, vpWidth, vpHeight, view, proj, _kind) {
3043
+ if (!Number.isFinite(screenX) || !Number.isFinite(screenY) || !Number.isFinite(vpWidth) || !Number.isFinite(vpHeight) || vpWidth <= 0 || vpHeight <= 0) {
3044
+ out[0] = 0;
3045
+ out[1] = 0;
3046
+ out[2] = 0;
3047
+ out[3] = 0;
3048
+ out[4] = 0;
3049
+ out[5] = -1;
3050
+ return out;
3051
+ }
3052
+ const sx = screenX < 0 ? 0 : screenX > vpWidth ? vpWidth : screenX;
3053
+ const sy = screenY < 0 ? 0 : screenY > vpHeight ? vpHeight : screenY;
3054
+ const ndcX = 2 * sx / vpWidth - 1;
3055
+ const ndcY = 1 - 2 * sy / vpHeight;
3056
+ multiply3(_tmpInvVP, proj, view);
3057
+ invert3(_tmpInvVP, _tmpInvVP);
3058
+ _nearNdC[0] = ndcX;
3059
+ _nearNdC[1] = ndcY;
3060
+ _nearNdC[2] = 0;
3061
+ _farNdC[0] = ndcX;
3062
+ _farNdC[1] = ndcY;
3063
+ _farNdC[2] = 1;
3064
+ unproject(_nearWorld, _nearNdC, _tmpInvVP);
3065
+ unproject(_farWorld, _farNdC, _tmpInvVP);
3066
+ out[0] = _nearWorld[0];
3067
+ out[1] = _nearWorld[1];
3068
+ out[2] = _nearWorld[2];
3069
+ const dx = _farWorld[0] - _nearWorld[0];
3070
+ const dy = _farWorld[1] - _nearWorld[1];
3071
+ const dz = _farWorld[2] - _nearWorld[2];
3072
+ const lenSq = dx * dx + dy * dy + dz * dz;
3073
+ if (lenSq < 1e-12) {
3074
+ out[3] = 0;
3075
+ out[4] = 0;
3076
+ out[5] = -1;
3077
+ } else {
3078
+ const inv = 1 / Math.sqrt(lenSq);
3079
+ out[3] = dx * inv;
3080
+ out[4] = dy * inv;
3081
+ out[5] = dz * inv;
3082
+ }
3083
+ return out;
3084
+ }
3085
+ function worldToScreen(out, worldPos, viewProj, canvasW, canvasH) {
3086
+ if (!(canvasW > 0) || !(canvasH > 0)) {
3087
+ return { onScreen: false, behind: false };
3088
+ }
3089
+ const x = worldPos[0];
3090
+ const y = worldPos[1];
3091
+ const z = worldPos[2];
3092
+ const clipX = viewProj[0] * x + viewProj[4] * y + viewProj[8] * z + viewProj[12];
3093
+ const clipY = viewProj[1] * x + viewProj[5] * y + viewProj[9] * z + viewProj[13];
3094
+ const clipZ = viewProj[2] * x + viewProj[6] * y + viewProj[10] * z + viewProj[14];
3095
+ const clipW = viewProj[3] * x + viewProj[7] * y + viewProj[11] * z + viewProj[15];
3096
+ if (clipW < 0) {
3097
+ return { onScreen: false, behind: true };
3098
+ }
3099
+ const invW = 1 / clipW;
3100
+ const ndcX = clipX * invW;
3101
+ const ndcY = clipY * invW;
3102
+ const ndcZ = clipZ * invW;
3103
+ out[0] = (ndcX * 0.5 + 0.5) * canvasW;
3104
+ out[1] = (1 - (ndcY * 0.5 + 0.5)) * canvasH;
3105
+ const onScreen = ndcX >= -1 && ndcX <= 1 && ndcY >= -1 && ndcY <= 1 && ndcZ >= 0 && ndcZ <= 1;
3106
+ return { onScreen, behind: false };
3107
+ }
3108
+ var RAY_TRI_EPSILON = 1e-8;
3109
+ function rayTriangleIntersects(r, a, b, c) {
3110
+ if (Number.isNaN(r[0]) || Number.isNaN(r[1]) || Number.isNaN(r[2]) || Number.isNaN(r[3]) || Number.isNaN(r[4]) || Number.isNaN(r[5]) || Number.isNaN(a[0]) || Number.isNaN(a[1]) || Number.isNaN(a[2]) || Number.isNaN(b[0]) || Number.isNaN(b[1]) || Number.isNaN(b[2]) || Number.isNaN(c[0]) || Number.isNaN(c[1]) || Number.isNaN(c[2])) {
3111
+ return { hit: false, t: 0, u: 0, v: 0 };
3112
+ }
3113
+ const ox = r[0];
3114
+ const oy = r[1];
3115
+ const oz = r[2];
3116
+ const dx = r[3];
3117
+ const dy = r[4];
3118
+ const dz = r[5];
3119
+ const e1x = b[0] - a[0];
3120
+ const e1y = b[1] - a[1];
3121
+ const e1z = b[2] - a[2];
3122
+ const e2x = c[0] - a[0];
3123
+ const e2y = c[1] - a[1];
3124
+ const e2z = c[2] - a[2];
3125
+ const px = dy * e2z - dz * e2y;
3126
+ const py = dz * e2x - dx * e2z;
3127
+ const pz = dx * e2y - dy * e2x;
3128
+ const det = e1x * px + e1y * py + e1z * pz;
3129
+ if (Math.abs(det) < RAY_TRI_EPSILON) {
3130
+ return { hit: false, t: 0, u: 0, v: 0 };
3131
+ }
3132
+ const invDet = 1 / det;
3133
+ const tx = ox - a[0];
3134
+ const ty = oy - a[1];
3135
+ const tz = oz - a[2];
3136
+ const u = (tx * px + ty * py + tz * pz) * invDet;
3137
+ if (u < 0 || u > 1) {
3138
+ return { hit: false, t: 0, u, v: 0 };
3139
+ }
3140
+ const qx = ty * e1z - tz * e1y;
3141
+ const qy = tz * e1x - tx * e1z;
3142
+ const qz = tx * e1y - ty * e1x;
3143
+ const v = (dx * qx + dy * qy + dz * qz) * invDet;
3144
+ if (v < 0 || u + v > 1) {
3145
+ return { hit: false, t: 0, u, v };
3146
+ }
3147
+ const t = (e2x * qx + e2y * qy + e2z * qz) * invDet;
3148
+ if (t <= 0) {
3149
+ return { hit: false, t, u, v };
3150
+ }
3151
+ return { hit: true, t, u, v };
3152
+ }
3153
+
3154
+ // src/ray2.ts
3155
+ var ray2_exports = {};
3156
+ __export(ray2_exports, {
3157
+ aabbCastIntersects: () => aabbCastIntersects,
3158
+ circleCastIntersects: () => circleCastIntersects,
3159
+ create: () => create12,
3160
+ getDirection: () => getDirection2,
3161
+ getMaxDistance: () => getMaxDistance,
3162
+ getOrigin: () => getOrigin2,
3163
+ rayAabbIntersects: () => rayAabbIntersects2,
3164
+ rayCircleIntersects: () => rayCircleIntersects,
3165
+ setDirection: () => setDirection2,
3166
+ setMaxDistance: () => setMaxDistance,
3167
+ setOrigin: () => setOrigin2
3168
+ });
3169
+ function create12(out, origin, direction, maxDistance = Number.POSITIVE_INFINITY) {
3170
+ const ray = out ?? new Float32Array(5);
3171
+ ray[0] = origin ? origin[0] : 0;
3172
+ ray[1] = origin ? origin[1] : 0;
3173
+ const dx = direction ? direction[0] : 0;
3174
+ const dy = direction ? direction[1] : 1;
3175
+ const lengthSq6 = dx * dx + dy * dy;
3176
+ if (lengthSq6 < 1e-12) {
3177
+ ray[2] = 0;
3178
+ ray[3] = 0;
3179
+ } else {
3180
+ const invLength = 1 / Math.sqrt(lengthSq6);
3181
+ ray[2] = dx * invLength;
3182
+ ray[3] = dy * invLength;
3183
+ }
3184
+ ray[4] = maxDistance < 0 ? 0 : maxDistance;
3185
+ return ray;
3186
+ }
3187
+ function getOrigin2(out, ray) {
3188
+ out[0] = ray[0];
3189
+ out[1] = ray[1];
3190
+ return out;
3191
+ }
3192
+ function getDirection2(out, ray) {
3193
+ out[0] = ray[2];
3194
+ out[1] = ray[3];
3195
+ return out;
3196
+ }
3197
+ function getMaxDistance(ray) {
3198
+ return ray[4];
3199
+ }
3200
+ function setOrigin2(ray, origin) {
3201
+ ray[0] = origin[0];
3202
+ ray[1] = origin[1];
3203
+ return ray;
3204
+ }
3205
+ function setDirection2(ray, direction) {
3206
+ const dx = direction[0];
3207
+ const dy = direction[1];
3208
+ const lengthSq6 = dx * dx + dy * dy;
3209
+ if (lengthSq6 < 1e-12) {
3210
+ ray[2] = 0;
3211
+ ray[3] = 0;
3212
+ } else {
3213
+ const invLength = 1 / Math.sqrt(lengthSq6);
3214
+ ray[2] = dx * invLength;
3215
+ ray[3] = dy * invLength;
3216
+ }
3217
+ return ray;
3218
+ }
3219
+ function setMaxDistance(ray, maxDistance) {
3220
+ ray[4] = maxDistance < 0 ? 0 : maxDistance;
3221
+ return ray;
3222
+ }
3223
+ function rayAabbIntersects2(ray, box) {
3224
+ return rayAabbValues(ray, box[0], box[1], box[2], box[3]);
3225
+ }
3226
+ function rayCircleIntersects(ray, circle) {
3227
+ return rayCircleValues(ray, circle[0], circle[1], circle[2]);
3228
+ }
3229
+ function aabbCastIntersects(ray, moving, target) {
3230
+ return rayAabbValues(
3231
+ ray,
3232
+ target[0] - moving[2],
3233
+ target[1] - moving[3],
3234
+ target[2] - moving[0],
3235
+ target[3] - moving[1]
3236
+ );
3237
+ }
3238
+ function circleCastIntersects(ray, moving, target) {
3239
+ return rayCircleValues(
3240
+ ray,
3241
+ target[0] - moving[0],
3242
+ target[1] - moving[1],
3243
+ target[2] + moving[2]
3244
+ );
3245
+ }
3246
+ function rayAabbValues(ray, minX, minY, maxX, maxY) {
3247
+ const ox = ray[0];
3248
+ const oy = ray[1];
3249
+ const dx = ray[2];
3250
+ const dy = ray[3];
3251
+ let near = 0;
3252
+ let far = ray[4];
3253
+ if (minX > maxX || minY > maxY || far < 0) return miss();
3254
+ if (Math.abs(dx) < 1e-12) {
3255
+ if (ox < minX || ox > maxX) return miss();
3256
+ } else {
3257
+ let a = (minX - ox) / dx;
3258
+ let b = (maxX - ox) / dx;
3259
+ if (a > b) [a, b] = [b, a];
3260
+ if (a > near) near = a;
3261
+ if (b < far) far = b;
3262
+ }
3263
+ if (Math.abs(dy) < 1e-12) {
3264
+ if (oy < minY || oy > maxY) return miss();
3265
+ } else {
3266
+ let a = (minY - oy) / dy;
3267
+ let b = (maxY - oy) / dy;
3268
+ if (a > b) [a, b] = [b, a];
3269
+ if (a > near) near = a;
3270
+ if (b < far) far = b;
3271
+ }
3272
+ return near <= far && far >= 0 ? { hit: true, t: near } : miss();
3273
+ }
3274
+ function rayCircleValues(ray, cx, cy, radius2) {
3275
+ const ox = ray[0] - cx;
3276
+ const oy = ray[1] - cy;
3277
+ const dx = ray[2];
3278
+ const dy = ray[3];
3279
+ const maxDistance = ray[4];
3280
+ if (radius2 < 0 || maxDistance < 0) return miss();
3281
+ const directionLengthSq = dx * dx + dy * dy;
3282
+ const radiusSq = radius2 * radius2;
3283
+ const originDistanceSq = ox * ox + oy * oy;
3284
+ if (originDistanceSq <= radiusSq) return maxDistance >= 0 ? { hit: true, t: 0 } : miss();
3285
+ if (directionLengthSq < 1e-12) return miss();
3286
+ const projected = ox * dx + oy * dy;
3287
+ const constant = originDistanceSq - radiusSq;
3288
+ const discriminant = projected * projected - directionLengthSq * constant;
3289
+ if (discriminant < 0) return miss();
3290
+ const entry = (-projected - Math.sqrt(discriminant)) / directionLengthSq;
3291
+ const t = entry < 0 ? 0 : entry;
3292
+ return t <= maxDistance ? { hit: true, t } : miss();
3293
+ }
3294
+ function miss() {
3295
+ return { hit: false, t: 0 };
3296
+ }
3297
+
3298
+ // src/sphere.ts
3299
+ var sphere_exports = {};
3300
+ __export(sphere_exports, {
3301
+ containsPoint: () => containsPoint4,
3302
+ create: () => create13,
3303
+ expandByPoint: () => expandByPoint2,
3304
+ fromPoints: () => fromPoints4,
3305
+ intersectsBox: () => intersectsBox5
3306
+ });
3307
+ function create13(cx = 0, cy = 0, cz = 0, radius2 = 0) {
3308
+ return Float32Array.of(cx, cy, cz, radius2);
3309
+ }
3310
+ function expandByPoint2(out, point) {
3311
+ const r = out[3];
3312
+ const px = point[0];
3313
+ const py = point[1];
3314
+ const pz = point[2];
3315
+ if (r < 0) {
3316
+ out[0] = px;
3317
+ out[1] = py;
3318
+ out[2] = pz;
3319
+ out[3] = 0;
3320
+ return out;
3321
+ }
3322
+ const dx = px - out[0];
3323
+ const dy = py - out[1];
3324
+ const dz = pz - out[2];
3325
+ const d = Math.sqrt(dx * dx + dy * dy + dz * dz);
3326
+ if (d > r) out[3] = d;
3327
+ return out;
3328
+ }
3329
+ function containsPoint4(s, point) {
3330
+ const r = s[3];
3331
+ if (r < 0) return false;
3332
+ const dx = point[0] - s[0];
3333
+ const dy = point[1] - s[1];
3334
+ const dz = point[2] - s[2];
3335
+ return dx * dx + dy * dy + dz * dz <= r * r;
3336
+ }
3337
+ function intersectsBox5(s, b) {
3338
+ const r = s[3];
3339
+ if (r < 0) return false;
3340
+ const cx = s[0];
3341
+ const cy = s[1];
3342
+ const cz = s[2];
3343
+ const minX = b[0];
3344
+ const minY = b[1];
3345
+ const minZ = b[2];
3346
+ const maxX = b[3];
3347
+ const maxY = b[4];
3348
+ const maxZ = b[5];
3349
+ const qx = cx < minX ? minX : cx > maxX ? maxX : cx;
3350
+ const qy = cy < minY ? minY : cy > maxY ? maxY : cy;
3351
+ const qz = cz < minZ ? minZ : cz > maxZ ? maxZ : cz;
3352
+ const dx = cx - qx;
3353
+ const dy = cy - qy;
3354
+ const dz = cz - qz;
3355
+ return dx * dx + dy * dy + dz * dz <= r * r;
3356
+ }
3357
+ function fromPoints4(out, points) {
3358
+ if (points.length === 0) {
3359
+ out[0] = 0;
3360
+ out[1] = 0;
3361
+ out[2] = 0;
3362
+ out[3] = -1;
3363
+ return out;
3364
+ }
3365
+ const aabb = create2();
3366
+ for (let i = 0; i < points.length; i++) {
3367
+ expandByPoint(aabb, points[i]);
3368
+ }
3369
+ const cx = (aabb[0] + aabb[3]) * 0.5;
3370
+ const cy = (aabb[1] + aabb[4]) * 0.5;
3371
+ const cz = (aabb[2] + aabb[5]) * 0.5;
3372
+ let rSq = 0;
3373
+ for (let i = 0; i < points.length; i++) {
3374
+ const p = points[i];
3375
+ const dx = p[0] - cx;
3376
+ const dy = p[1] - cy;
3377
+ const dz = p[2] - cz;
3378
+ const d2 = dx * dx + dy * dy + dz * dz;
3379
+ if (d2 > rSq) rSq = d2;
3380
+ }
3381
+ out[0] = cx;
3382
+ out[1] = cy;
3383
+ out[2] = cz;
3384
+ out[3] = Math.sqrt(rSq);
3385
+ return out;
3386
+ }
3387
+
3388
+ // src/vec2.ts
3389
+ var vec2_exports = {};
3390
+ __export(vec2_exports, {
3391
+ add: () => add2,
3392
+ catmullRom: () => catmullRom2,
3393
+ clone: () => clone7,
3394
+ copy: () => copy2,
3395
+ create: () => create14,
3396
+ distance: () => distance2,
3397
+ dot: () => dot3,
3398
+ equals: () => equals4,
3399
+ length: () => length3,
3400
+ lengthSq: () => lengthSq3,
3401
+ lerp: () => lerp3,
3402
+ max: () => max2,
3403
+ min: () => min2,
3404
+ negate: () => negate2,
3405
+ normalize: () => normalize3,
3406
+ perp: () => perp,
3407
+ scale: () => scale4,
3408
+ set: () => set3,
3409
+ smoothDamp: () => smoothDamp2,
3410
+ sub: () => sub2
3411
+ });
3412
+ function create14(x = 0, y = 0) {
3413
+ return Float32Array.of(x, y);
3414
+ }
3415
+ function clone7(a) {
3416
+ return Float32Array.of(a[0], a[1]);
3417
+ }
3418
+ function copy2(out, a) {
3419
+ out[0] = a[0];
3420
+ out[1] = a[1];
3421
+ return out;
3422
+ }
3423
+ function set3(out, x, y) {
3424
+ out[0] = x;
3425
+ out[1] = y;
3426
+ return out;
3427
+ }
3428
+ function equals4(a, b, epsilon = 1e-6) {
3429
+ const ax = a[0];
3430
+ const ay = a[1];
3431
+ const bx = b[0];
3432
+ const by = b[1];
3433
+ if (Number.isNaN(ax) || Number.isNaN(ay) || Number.isNaN(bx) || Number.isNaN(by)) return false;
3434
+ return Math.abs(ax - bx) <= epsilon && Math.abs(ay - by) <= epsilon;
3435
+ }
3436
+ function add2(out, a, b) {
3437
+ const ax = a[0];
3438
+ const ay = a[1];
3439
+ const bx = b[0];
3440
+ const by = b[1];
3441
+ out[0] = ax + bx;
3442
+ out[1] = ay + by;
3443
+ return out;
3444
+ }
3445
+ function sub2(out, a, b) {
3446
+ const ax = a[0];
3447
+ const ay = a[1];
3448
+ const bx = b[0];
3449
+ const by = b[1];
3450
+ out[0] = ax - bx;
3451
+ out[1] = ay - by;
3452
+ return out;
3453
+ }
3454
+ function scale4(out, a, s) {
3455
+ out[0] = a[0] * s;
3456
+ out[1] = a[1] * s;
3457
+ return out;
3458
+ }
3459
+ function negate2(out, a) {
3460
+ out[0] = 0 - a[0];
3461
+ out[1] = 0 - a[1];
3462
+ return out;
3463
+ }
3464
+ function dot3(a, b) {
3465
+ return a[0] * b[0] + a[1] * b[1];
3466
+ }
3467
+ function lengthSq3(a) {
3468
+ const x = a[0];
3469
+ const y = a[1];
3470
+ return x * x + y * y;
3471
+ }
3472
+ function length3(a) {
3473
+ const x = a[0];
3474
+ const y = a[1];
3475
+ return Math.sqrt(x * x + y * y);
3476
+ }
3477
+ function distance2(a, b) {
3478
+ const dx = a[0] - b[0];
3479
+ const dy = a[1] - b[1];
3480
+ return Math.sqrt(dx * dx + dy * dy);
3481
+ }
3482
+ function normalize3(out, a) {
3483
+ const x = a[0];
3484
+ const y = a[1];
3485
+ const lenSq = x * x + y * y;
3486
+ if (lenSq < EPS_NORMALIZE) {
3487
+ out[0] = 0;
3488
+ out[1] = 0;
3489
+ return out;
3490
+ }
3491
+ const inv = 1 / Math.sqrt(lenSq);
3492
+ out[0] = x * inv;
3493
+ out[1] = y * inv;
3494
+ return out;
3495
+ }
3496
+ function lerp3(out, a, b, t) {
3497
+ const ax = a[0];
3498
+ const ay = a[1];
3499
+ const bx = b[0];
3500
+ const by = b[1];
3501
+ out[0] = lerp(ax, bx, t);
3502
+ out[1] = lerp(ay, by, t);
3503
+ return out;
3504
+ }
3505
+ function smoothDamp2(out, current, target, decayRate, dt) {
3506
+ return lerp3(out, current, target, smoothDecayFactor(decayRate, dt));
3507
+ }
3508
+ function catmullRom2(out, p0, p1, p2, p3, t) {
3509
+ const x = catmullRomScalar(p0[0], p1[0], p2[0], p3[0], t);
3510
+ const y = catmullRomScalar(p0[1], p1[1], p2[1], p3[1], t);
3511
+ out[0] = x;
3512
+ out[1] = y;
3513
+ return out;
3514
+ }
3515
+ function min2(out, a, b) {
3516
+ out[0] = Math.min(a[0], b[0]);
3517
+ out[1] = Math.min(a[1], b[1]);
3518
+ return out;
3519
+ }
3520
+ function max2(out, a, b) {
3521
+ out[0] = Math.max(a[0], b[0]);
3522
+ out[1] = Math.max(a[1], b[1]);
3523
+ return out;
3524
+ }
3525
+ function perp(out, a) {
3526
+ const x = a[0];
3527
+ const y = a[1];
3528
+ out[0] = 0 - y;
3529
+ out[1] = x;
3530
+ return out;
3531
+ }
3532
+
3533
+ // src/vec4.ts
3534
+ var vec4_exports = {};
3535
+ __export(vec4_exports, {
3536
+ add: () => add3,
3537
+ clone: () => clone8,
3538
+ copy: () => copy3,
3539
+ create: () => create15,
3540
+ distance: () => distance3,
3541
+ dot: () => dot4,
3542
+ equals: () => equals5,
3543
+ length: () => length4,
3544
+ lengthSq: () => lengthSq5,
3545
+ lerp: () => lerp4,
3546
+ max: () => max3,
3547
+ min: () => min3,
3548
+ negate: () => negate3,
3549
+ normalize: () => normalize5,
3550
+ scale: () => scale5,
3551
+ set: () => set4,
3552
+ smoothDamp: () => smoothDamp3,
3553
+ sub: () => sub3
3554
+ });
3555
+ function create15(x = 0, y = 0, z = 0, w = 0) {
3556
+ return Float32Array.of(x, y, z, w);
3557
+ }
3558
+ function clone8(a) {
3559
+ return Float32Array.of(a[0], a[1], a[2], a[3]);
3560
+ }
3561
+ function copy3(out, a) {
3562
+ out[0] = a[0];
3563
+ out[1] = a[1];
3564
+ out[2] = a[2];
3565
+ out[3] = a[3];
3566
+ return out;
3567
+ }
3568
+ function set4(out, x, y, z, w) {
3569
+ out[0] = x;
3570
+ out[1] = y;
3571
+ out[2] = z;
3572
+ out[3] = w;
3573
+ return out;
3574
+ }
3575
+ function equals5(a, b, epsilon = 1e-6) {
3576
+ const ax = a[0];
3577
+ const ay = a[1];
3578
+ const az = a[2];
3579
+ const aw = a[3];
3580
+ const bx = b[0];
3581
+ const by = b[1];
3582
+ const bz = b[2];
3583
+ const bw = b[3];
3584
+ if (Number.isNaN(ax) || Number.isNaN(ay) || Number.isNaN(az) || Number.isNaN(aw) || Number.isNaN(bx) || Number.isNaN(by) || Number.isNaN(bz) || Number.isNaN(bw)) {
3585
+ return false;
3586
+ }
3587
+ return Math.abs(ax - bx) <= epsilon && Math.abs(ay - by) <= epsilon && Math.abs(az - bz) <= epsilon && Math.abs(aw - bw) <= epsilon;
3588
+ }
3589
+ function add3(out, a, b) {
3590
+ const ax = a[0];
3591
+ const ay = a[1];
3592
+ const az = a[2];
3593
+ const aw = a[3];
3594
+ const bx = b[0];
3595
+ const by = b[1];
3596
+ const bz = b[2];
3597
+ const bw = b[3];
3598
+ out[0] = ax + bx;
3599
+ out[1] = ay + by;
3600
+ out[2] = az + bz;
3601
+ out[3] = aw + bw;
3602
+ return out;
3603
+ }
3604
+ function sub3(out, a, b) {
3605
+ const ax = a[0];
3606
+ const ay = a[1];
3607
+ const az = a[2];
3608
+ const aw = a[3];
3609
+ const bx = b[0];
3610
+ const by = b[1];
3611
+ const bz = b[2];
3612
+ const bw = b[3];
3613
+ out[0] = ax - bx;
3614
+ out[1] = ay - by;
3615
+ out[2] = az - bz;
3616
+ out[3] = aw - bw;
3617
+ return out;
3618
+ }
3619
+ function scale5(out, a, s) {
3620
+ out[0] = a[0] * s;
3621
+ out[1] = a[1] * s;
3622
+ out[2] = a[2] * s;
3623
+ out[3] = a[3] * s;
3624
+ return out;
3625
+ }
3626
+ function negate3(out, a) {
3627
+ out[0] = 0 - a[0];
3628
+ out[1] = 0 - a[1];
3629
+ out[2] = 0 - a[2];
3630
+ out[3] = 0 - a[3];
3631
+ return out;
3632
+ }
3633
+ function dot4(a, b) {
3634
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
3635
+ }
3636
+ function lengthSq5(a) {
3637
+ return lengthSq4(a);
3638
+ }
3639
+ function length4(a) {
3640
+ return Math.sqrt(lengthSq4(a));
3641
+ }
3642
+ function distance3(a, b) {
3643
+ const dx = a[0] - b[0];
3644
+ const dy = a[1] - b[1];
3645
+ const dz = a[2] - b[2];
3646
+ const dw = a[3] - b[3];
3647
+ return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
3648
+ }
3649
+ function normalize5(out, a) {
3650
+ normalize4(out, a, EPS_NORMALIZE);
3651
+ return out;
3652
+ }
3653
+ function lerp4(out, a, b, t) {
3654
+ const ax = a[0];
3655
+ const ay = a[1];
3656
+ const az = a[2];
3657
+ const aw = a[3];
3658
+ const bx = b[0];
3659
+ const by = b[1];
3660
+ const bz = b[2];
3661
+ const bw = b[3];
3662
+ out[0] = lerp(ax, bx, t);
3663
+ out[1] = lerp(ay, by, t);
3664
+ out[2] = lerp(az, bz, t);
3665
+ out[3] = lerp(aw, bw, t);
3666
+ return out;
3667
+ }
3668
+ function smoothDamp3(out, current, target, decayRate, dt) {
3669
+ return lerp4(out, current, target, smoothDecayFactor(decayRate, dt));
3670
+ }
3671
+ function min3(out, a, b) {
3672
+ out[0] = Math.min(a[0], b[0]);
3673
+ out[1] = Math.min(a[1], b[1]);
3674
+ out[2] = Math.min(a[2], b[2]);
3675
+ out[3] = Math.min(a[3], b[3]);
3676
+ return out;
3677
+ }
3678
+ function max3(out, a, b) {
3679
+ out[0] = Math.max(a[0], b[0]);
3680
+ out[1] = Math.max(a[1], b[1]);
3681
+ out[2] = Math.max(a[2], b[2]);
3682
+ out[3] = Math.max(a[3], b[3]);
3683
+ return out;
3684
+ }
3685
+
3686
+ export { box2_exports as box2, box3_exports as box3, circle2_exports as circle2, color_exports as color, easing_exports as easing, euler_exports as euler, frustum_exports as frustum, f32_to_f16_bytes_exports as halfFloat, mat3_exports as mat3, mat4_exports as mat4, noise_exports as noise, quat_exports as quat, ray_exports as ray, ray2_exports as ray2, sphere_exports as sphere, vec2_exports as vec2, vec3_exports as vec3, vec4_exports as vec4 };
3687
+ //# sourceMappingURL=index.mjs.map
3688
+ //# sourceMappingURL=index.mjs.map