@nebula-spatial/viewer 0.5.18 → 0.6.1

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 (48) hide show
  1. package/CHANGELOG.md +83 -35
  2. package/README.md +5 -0
  3. package/dist/asset-ir-BXa1EdOy.js +637 -0
  4. package/dist/assets/source-types.d.ts +10 -0
  5. package/dist/assets/types.d.ts +61 -6
  6. package/dist/assets/{usd-worker-B6-1I5dT.js → usd-worker-r6Nuoxlk.js} +671 -584
  7. package/dist/index-CHf9y9eX.js +17406 -0
  8. package/dist/index.d.ts +21 -2
  9. package/dist/index.js +29 -18
  10. package/dist/{mjcf-visual-CtY2Wk3w.js → mjcf-visual-DxMXiBnu.js} +12 -13
  11. package/dist/mujoco-runtime-BA88JuDR.js +791 -0
  12. package/dist/physics-guide-size-CplAlsve.js +12 -0
  13. package/dist/scene/instances.d.ts +36 -0
  14. package/dist/scene/joints.d.ts +129 -0
  15. package/dist/scene/session.d.ts +26 -0
  16. package/dist/scene/types.d.ts +292 -0
  17. package/dist/session-DLi-MvLB.js +240 -0
  18. package/dist/{session-DxTeRKCd.js → session-DqEr1CxY.js} +581 -567
  19. package/dist/session-ZNb3ZYLq.js +562 -0
  20. package/dist/simulation/physics-runtime-state.d.ts +73 -0
  21. package/dist/simulation/types.d.ts +151 -0
  22. package/dist/simulation/usd-dependency-probe.d.ts +42 -0
  23. package/dist/simulation/usd-inspection.d.ts +66 -0
  24. package/dist/spark-renderer-BGF_AaI9.js +25 -0
  25. package/dist/spark.module-kM8pwA1o.js +9278 -0
  26. package/dist/types.d.ts +75 -1
  27. package/dist/ui/camera-axis-gizmo.d.ts +5 -0
  28. package/dist/urdf-session-CKlR-fOQ.js +1230 -0
  29. package/dist/usd-session-DyNMsD-v.js +11199 -0
  30. package/dist/version.d.ts +1 -1
  31. package/dist/visual/classification.d.ts +20 -0
  32. package/dist/{xacro-x2TeKQ7T.js → xacro-BCLnc3tY.js} +1 -1
  33. package/openusd/openusd-runtime-manifest.json +6 -6
  34. package/openusd/openusd_probe.js +1 -1
  35. package/openusd/openusd_probe.wasm +0 -0
  36. package/package.json +2 -1
  37. package/runtime-assets.d.mts +9 -9
  38. package/runtime-assets.mjs +11 -11
  39. package/vite.d.mts +7 -7
  40. package/vite.mjs +115 -115
  41. package/dist/collision-debug-BSJoz5J7.js +0 -2947
  42. package/dist/index-E8DHSeyT.js +0 -11499
  43. package/dist/mujoco-runtime-fDWdXNEc.js +0 -739
  44. package/dist/resources-CHhCm2f7.js +0 -27
  45. package/dist/session-DB-osaBL.js +0 -801
  46. package/dist/stage-BnRjc-Rp.js +0 -592
  47. package/dist/urdf-session-Q_c3Rd1M.js +0 -1264
  48. package/dist/usd-session-tW3LxVFs.js +0 -10647
@@ -1,2947 +0,0 @@
1
- var Cn = Object.defineProperty;
2
- var On = (n, t, e) => t in n ? Cn(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var Z = (n, t, e) => On(n, typeof t != "symbol" ? t + "" : t, e);
4
- import { Vector3 as U, Box3 as st, Matrix4 as mt, BufferAttribute as bn, Line3 as ct, Plane as An, Vector2 as ht, Triangle as Et, BackSide as Fn, DoubleSide as _n, REVISION as Sn, Ray as zn, FrontSide as He, Mesh as $t, LineSegments as Ve, LineLoop as Bn, Line as Tn, Points as Pn, Sphere as Vn, BatchedMesh as jn, LineBasicMaterial as $n, MeshBasicMaterial as kn, WireframeGeometry as qn, EdgesGeometry as we } from "three";
5
- import { disposeModelResources as Jn } from "./resources-CHhCm2f7.js";
6
- import { t as Lt, u as We, v as Hn, w as Wn, x as Yn, U as Xn, p as Gn } from "./index-E8DHSeyT.js";
7
- const Zn = /* @__PURE__ */ new Set([
8
- "E_MJCF_INCLUDE_CYCLE",
9
- "E_MJCF_PARSE",
10
- "E_URDF_COMPILE",
11
- "E_URDF_INERTIA",
12
- "E_USD_INVALID_COLLISION_GEOMETRY",
13
- "E_USD_INVALID_COLLISION_GROUP",
14
- "E_USD_INVALID_EQUALITY_CONNECT",
15
- "E_USD_INVALID_JOINT_REFERENCE",
16
- "E_USD_INVALID_MASS",
17
- "E_USD_INVALID_MIMIC",
18
- "E_USD_INVALID_UNITS",
19
- "E_USD_MISSING_COLLISION_GEOMETRY",
20
- "E_USD_MULTIPLE_PHYSICS_SCENES",
21
- "E_USD_PARTIAL_INERTIA",
22
- "E_USD_UNREACHABLE_BODIES"
23
- ]), Kn = /* @__PURE__ */ new Set(["step", "reset", "grab", "up-axis"]), Qn = Object.freeze({
24
- kind: "visual-adaptation",
25
- title: "视觉适配信息",
26
- summary: "部分材质细节采用近似表示,不影响资产结构与模型查看。",
27
- tone: "info"
28
- }), ti = Object.freeze({
29
- kind: "unsupported-by-viewer",
30
- title: "视觉预览模式",
31
- summary: "当前仿真链路未能建立物理模型,资产视觉内容仍可正常查看。",
32
- tone: "info"
33
- });
34
- function Me(n, t) {
35
- return n === "E_URDF_INERTIA" ? {
36
- kind: "invalid-asset",
37
- title: "物理定义无效",
38
- summary: "该 URDF 未声明动力学仿真所需的有效惯性数据,动力学模型无法建立。",
39
- tone: "warning"
40
- } : {
41
- kind: "invalid-asset",
42
- title: "物理定义无效",
43
- summary: t === "usd-physics" ? "该 USD 资产的物理参数或关节定义无效,物理模型无法建立。" : "该资产的物理参数缺失或无效,物理模型无法建立。",
44
- tone: "warning"
45
- };
46
- }
47
- function ei(n) {
48
- return n === "visual-material" ? {
49
- kind: "visual-adaptation",
50
- title: "视觉材质近似",
51
- summary: "部分材质信息未完整转换,当前显示使用近似材质。",
52
- tone: "info"
53
- } : Qn;
54
- }
55
- function In(n, t) {
56
- const e = t.split(":").at(-1);
57
- if (e && Kn.has(e))
58
- return {
59
- kind: "runtime-failure",
60
- title: "仿真运行异常",
61
- summary: "仿真初始化或运行过程中发生异常,物理仿真已停止;资产视觉内容仍可正常查看。",
62
- tone: "warning"
63
- };
64
- if (n === "E_MUJOCO_INITIALIZE") {
65
- if (t === "mjcf-physics")
66
- return {
67
- kind: "runtime-failure",
68
- title: "物理模型初始化失败",
69
- summary: "MuJoCo 物理模型初始化失败,资产仍可进行视觉预览。",
70
- tone: "warning"
71
- };
72
- if (t === "urdf-physics")
73
- return {
74
- kind: "runtime-failure",
75
- title: "动力学初始化失败",
76
- summary: "URDF 动力学初始化失败,当前保留运动学预览。",
77
- tone: "warning"
78
- };
79
- if (t === "usd-physics")
80
- return {
81
- kind: "runtime-failure",
82
- title: "物理模型初始化失败",
83
- summary: "当前 USD 物理模型未能完成 MuJoCo 初始化,资产视觉内容仍可正常查看。",
84
- tone: "warning"
85
- };
86
- }
87
- return Zn.has(n) ? Me(n, t) : t === "usd-physics" || n.startsWith("E_USD_") ? {
88
- kind: "unsupported-by-viewer",
89
- title: "视觉预览模式",
90
- summary: "当前 Viewer 未覆盖该 USD 资产使用的部分物理语义,视觉与结构信息可正常查看,物理仿真未启动。",
91
- tone: "info"
92
- } : n.startsWith("E_MJCF_") || n.startsWith("E_URDF_") ? Me(n, t) : ti;
93
- }
94
- function Ms(n, t) {
95
- const e = n.notice ?? (t === "physics-validation" ? Me(n.code, n.source) : t === "visual-adaptation" || t === "visual-material" ? ei(t) : In(n.code, n.source ?? t));
96
- return { ...n, stage: t, notice: e };
97
- }
98
- function vs(n, t, e) {
99
- if (t.throwIfAborted(), n instanceof Error && (n.name === "AbortError" || ["E_ABORTED", "E_SUPERSEDED"].includes(String(n.code)))) throw n;
100
- const i = n && typeof n == "object" && "code" in n && typeof n.code == "string" ? n.code : "E_PHYSICS_INITIALIZE", s = n instanceof Error ? n.message : String(n);
101
- return { code: i, source: e, message: s, notice: In(i, e) };
102
- }
103
- function ni(n, t, e) {
104
- const i = new Map(n.map((h) => [h.id, h])), s = /* @__PURE__ */ new Map(), o = (h, A = /* @__PURE__ */ new Set()) => {
105
- if (s.has(h)) return s.get(h);
106
- const B = i.get(h);
107
- if (!B) return null;
108
- if (!B.mimic) {
109
- const x = { root: h, multiplier: 1, offset: 0 };
110
- return s.set(h, x), x;
111
- }
112
- if (A.has(h) || !i.has(B.mimic.joint) || !Number.isFinite(B.mimic.multiplier) || !Number.isFinite(B.mimic.offset))
113
- return s.set(h, null), null;
114
- A.add(h);
115
- const b = o(B.mimic.joint, A);
116
- if (A.delete(h), !b)
117
- return s.set(h, null), null;
118
- const T = {
119
- root: b.root,
120
- multiplier: B.mimic.multiplier * b.multiplier,
121
- offset: B.mimic.multiplier * b.offset + B.mimic.offset
122
- };
123
- return s.set(h, T), T;
124
- }, r = new Map(n.map((h) => {
125
- const A = o(h.id);
126
- return [h.id, A ?? { root: h.id, multiplier: 1, offset: 0 }];
127
- })), a = /* @__PURE__ */ new Map();
128
- for (const h of n) {
129
- const A = r.get(h.id);
130
- a.has(A.root) || a.set(A.root, { lower: -1 / 0, upper: 1 / 0, feasible: !0 });
131
- const B = h.limits;
132
- if (!B || Number.isNaN(B.lower) || Number.isNaN(B.upper) || B.lower > B.upper) continue;
133
- const b = a.get(A.root);
134
- if (A.multiplier === 0) {
135
- (A.offset < B.lower || A.offset > B.upper) && (b.feasible = !1);
136
- continue;
137
- }
138
- const T = (B.lower - A.offset) / A.multiplier, x = (B.upper - A.offset) / A.multiplier;
139
- b.lower = Math.max(b.lower, Math.min(T, x)), b.upper = Math.min(b.upper, Math.max(T, x)), b.lower > b.upper && (b.feasible = !1);
140
- }
141
- const c = Object.fromEntries(n.map((h) => [h.id, h.defaultValue])), d = n.map((h) => {
142
- if (r.get(h.id).root !== h.id) return h;
143
- if (h.mimic && !s.get(h.id)) {
144
- const { mimic: T, ...x } = h;
145
- return x;
146
- }
147
- const B = a.get(h.id);
148
- let b;
149
- return B.feasible ? (Number.isFinite(B.lower) || Number.isFinite(B.upper)) && (b = { lower: B.lower, upper: B.upper }) : b = { lower: h.defaultValue, upper: h.defaultValue }, b ? { ...h, controlLimits: b } : h;
150
- }), f = new Map(d.map((h) => [h.id, h])), l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set();
151
- let S = !1;
152
- const P = () => {
153
- for (const h of u) h();
154
- };
155
- let _ = !1, I = [], m = Object.freeze({
156
- kind: "joints",
157
- revision: 0,
158
- format: t,
159
- joints: d,
160
- jointValues: Object.freeze({ ...c }),
161
- selectedJointId: null,
162
- playing: !1,
163
- ...e.controlMode ? { controlMode: e.controlMode } : {},
164
- ...e.controlMode === "physics" ? { jointTargets: Object.freeze({ ...c }) } : {}
165
- });
166
- const g = (h) => {
167
- if (!_) {
168
- m = Object.freeze({ ...m, ...h, revision: m.revision + 1 });
169
- for (const A of l) A(m);
170
- }
171
- }, y = () => m.playing && !(e.controlMode === "kinematic" && m.previewing === !0), w = (h, A) => {
172
- const B = h.controlLimits ?? h.limits;
173
- return B && !Number.isNaN(B.lower) && !Number.isNaN(B.upper) && B.lower <= B.upper ? Math.max(B.lower, Math.min(B.upper, A)) : A;
174
- }, E = (h, A, B = !1) => {
175
- var v, N, L;
176
- I = A;
177
- const b = {}, T = /* @__PURE__ */ new Map();
178
- for (const R of n) {
179
- if (r.get(R.id).root !== R.id) continue;
180
- const q = f.get(R.id);
181
- T.set(R.id, w(q, h[R.id] ?? q.defaultValue));
182
- }
183
- for (const R of n) {
184
- const j = r.get(R.id), q = T.get(j.root) ?? ((v = i.get(j.root)) == null ? void 0 : v.defaultValue) ?? R.defaultValue;
185
- b[R.id] = j.multiplier * q + j.offset;
186
- }
187
- B && Object.assign(b, c);
188
- const x = e.apply(b, A), M = e.controlMode === "physics" && ((N = e.isDriveActive) == null ? void 0 : N.call(e)) === !1 ? x ?? b : b;
189
- e.controlMode === "physics" && ((L = e.isDriveActive) == null ? void 0 : L.call(e)) === !1 && (I = []), g({
190
- jointValues: Object.freeze({ ...x ?? b }),
191
- ...e.controlMode === "physics" ? { jointTargets: Object.freeze({ ...M }) } : {}
192
- }), e.requestRender();
193
- };
194
- return {
195
- kind: "joints",
196
- getSnapshot: () => m,
197
- subscribe(h) {
198
- return _ ? () => {
199
- } : (l.add(h), () => l.delete(h));
200
- },
201
- onManualInput(h) {
202
- return _ ? () => {
203
- } : (u.add(h), () => u.delete(h));
204
- },
205
- onIntroFinished(h) {
206
- return _ ? () => {
207
- } : S ? (h(), () => {
208
- }) : (p.add(h), () => p.delete(h));
209
- },
210
- notifyIntroFinished() {
211
- if (!(_ || S)) {
212
- S = !0;
213
- for (const h of p) h();
214
- p.clear();
215
- }
216
- },
217
- setPreviewPose(h) {
218
- if (_ || y() || e.controlMode !== "kinematic") return;
219
- const A = d.filter((b) => !b.mimic && Number.isFinite(h[b.id]) && ["revolute", "continuous", "prismatic"].includes(b.type));
220
- if (!A.length) return;
221
- const B = { ...m.jointValues };
222
- for (const b of A) B[b.id] = h[b.id];
223
- E(B, A.map((b) => b.id));
224
- },
225
- resetPreviewPose() {
226
- !_ && !m.playing && e.controlMode === "kinematic" && E({ ...c }, [], !0);
227
- },
228
- setPreviewing(h) {
229
- !_ && !!m.previewing !== h && g({ previewing: h });
230
- },
231
- select(h) {
232
- _ || h !== null && !i.has(h) || h === m.selectedJointId || g({ selectedJointId: h });
233
- },
234
- setJointValue(h, A) {
235
- const B = f.get(h);
236
- if (_ || y() || !B || B.mimic || !Number.isFinite(A) || !["revolute", "continuous", "prismatic"].includes(B.type) || (P(), _ || m.playing)) return;
237
- const b = w(B, A), T = m.jointTargets ?? m.jointValues;
238
- b !== T[h] && E({ ...m.jointValues, [h]: b }, [h]);
239
- },
240
- resetJoint(h) {
241
- const A = f.get(h);
242
- _ || y() || !A || A.mimic || (P(), !(_ || m.playing) && E({ ...m.jointValues, [h]: A.defaultValue }, [h]));
243
- },
244
- resetPose() {
245
- _ || y() || (P(), !_ && !m.playing && E({ ...c }, n.filter((h) => r.get(h.id).root === h.id).map((h) => h.id), !0));
246
- },
247
- setPlaying(h) {
248
- !_ && m.playing !== h && g({
249
- playing: h,
250
- ...e.controlMode === "physics" ? { jointTargets: Object.freeze({ ...m.jointValues }) } : {}
251
- });
252
- },
253
- syncValues(h, A = !1) {
254
- var T;
255
- if (_) return;
256
- const B = { ...m.jointValues };
257
- let b = !1;
258
- for (const x of n) {
259
- const M = h[x.id];
260
- M !== void 0 && Number.isFinite(M) && M !== B[x.id] && (B[x.id] = M, b = !0);
261
- }
262
- if ((A || m.playing) && (I = []), b || A) {
263
- const x = { ...B };
264
- for (const M of I) x[M] = ((T = m.jointTargets) == null ? void 0 : T[M]) ?? B[M];
265
- g({
266
- jointValues: Object.freeze(B),
267
- ...e.controlMode === "physics" ? { jointTargets: Object.freeze(x) } : {}
268
- });
269
- }
270
- },
271
- dispose() {
272
- _ = !0, l.clear(), u.clear(), p.clear();
273
- }
274
- };
275
- }
276
- function Ns(n, t, e, i, s, o) {
277
- try {
278
- return ii(n, t, e, i, o);
279
- } catch (r) {
280
- try {
281
- s == null || s(r);
282
- } catch {
283
- }
284
- return;
285
- }
286
- }
287
- function ii(n, t, e, i, s) {
288
- var h, A, B, b;
289
- const o = n.model, r = n.mujoco, a = n.data;
290
- if (!o || !r || !a) return;
291
- const c = [], d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), p = (T) => {
292
- try {
293
- const x = Number(o.nu ?? 0);
294
- if (!Number.isFinite(x) || x <= 0) return {};
295
- const M = o.actuator_trntype, v = o.actuator_trnid, N = o.actuator_forcerange, L = o.actuator_biasprm;
296
- if (!M || !v) return {};
297
- for (let R = 0; R < x; R++) {
298
- if (M[R] !== r.mjtTrn.mjTRN_JOINT.value || v[R * 2] !== T) continue;
299
- const j = Number(o.actuator_gear[R * 6]);
300
- if (!Number.isFinite(j)) continue;
301
- const q = o.actuator_biastype[R] === r.mjtBias.mjBIAS_AFFINE.value, et = o.actuator_gaintype[R] === r.mjtGain.mjGAIN_FIXED.value, C = q ? -Number(L == null ? void 0 : L[R * 10 + 1]) + 0 : void 0, K = q ? -Number(L == null ? void 0 : L[R * 10 + 2]) + 0 : void 0, Ut = Number(o.actuator_gainprm[R * 10]), lt = {
302
- type: et && q && C != null && C > 0 && Ut === C ? "position" : et && q && C === 0 && K != null && K > 0 && Ut === K ? "velocity" : et && o.actuator_biastype[R] === r.mjtBias.mjBIAS_NONE.value ? "motor" : "general",
303
- ...Number.isFinite(C) ? { stiffness: C * j * j } : {},
304
- ...Number.isFinite(K) ? { damping: K * j * j } : {}
305
- }, kt = o.actuator(R);
306
- let qt;
307
- try {
308
- qt = !!kt.forcelimited;
309
- } finally {
310
- kt.delete();
311
- }
312
- const Jt = Number(N == null ? void 0 : N[R * 2]), Ht = Number(N == null ? void 0 : N[R * 2 + 1]), Wt = qt && Number.isFinite(Jt) && Number.isFinite(Ht) ? Math.max(Math.abs(Jt), Math.abs(Ht)) * Math.abs(j) : void 0;
313
- return { drive: lt, ...Wt != null ? { maxEffort: Wt } : {} };
314
- }
315
- } catch {
316
- }
317
- return {};
318
- };
319
- for (let T = 0; T < o.njnt; T++) {
320
- const x = o.jnt_type[T], M = x === r.mjtJoint.mjJNT_HINGE.value;
321
- if (!M && x !== r.mjtJoint.mjJNT_SLIDE.value) continue;
322
- const v = r.mj_id2name(o, r.mjtObj.mjOBJ_JOINT.value, T);
323
- if (!v) continue;
324
- const N = o.jnt_bodyid[T], L = o.body_parentid[N], R = o.jnt(T);
325
- try {
326
- const j = (h = s == null ? void 0 : s.mimics) == null ? void 0 : h.get(v), q = p(T), et = Number((A = o.body_mass) == null ? void 0 : A[N]), C = (B = s == null ? void 0 : s.metadata) == null ? void 0 : B.get(v), K = ((b = s == null ? void 0 : s.limits) == null ? void 0 : b.get(v)) ?? (R.limited ? { lower: o.jnt_range[T * 2], upper: o.jnt_range[T * 2 + 1] } : void 0);
327
- c.push({
328
- id: v,
329
- name: v.split("/").pop() || v,
330
- type: M ? "revolute" : "prismatic",
331
- parent: L > 0 ? r.mj_id2name(o, r.mjtObj.mjOBJ_BODY.value, L) : null,
332
- child: r.mj_id2name(o, r.mjtObj.mjOBJ_BODY.value, N),
333
- axis: Array.from(o.jnt_axis.slice(T * 3, T * 3 + 3)),
334
- unit: M ? "rad" : "m",
335
- defaultValue: a.qpos[o.jnt_qposadr[T]],
336
- ...K ? { limits: K } : {},
337
- ...(C == null ? void 0 : C.movingMass) != null ? { movingMass: C.movingMass } : Number.isFinite(et) && et > 0 ? { movingMass: et } : {},
338
- ...C != null && C.drive ? { drive: C.drive } : q.drive ? { drive: q.drive } : {},
339
- ...(C == null ? void 0 : C.maxEffort) != null ? { maxEffort: C.maxEffort } : q.maxEffort != null ? { maxEffort: q.maxEffort } : {},
340
- ...j ? { mimic: { ...j } } : {}
341
- }), d.set(v, T), f.set(v, N), l.has(N) || l.set(N, v), u.set(N, v);
342
- } finally {
343
- R.delete();
344
- }
345
- }
346
- if (!c.length) return;
347
- const S = /* @__PURE__ */ new Map(), P = c.map((T) => {
348
- const x = f.get(T.id);
349
- let M = S.get(x);
350
- if (!M) {
351
- let v = o.body_parentid[x];
352
- for (; v > 0 && !l.has(v); ) v = o.body_parentid[v];
353
- M = u.get(v);
354
- }
355
- return S.set(x, T.id), { ...T, parentJointId: M ?? null };
356
- }), _ = ni(P, t, {
357
- controlMode: t === "usd" ? "kinematic" : "physics",
358
- apply(T, x) {
359
- if (t === "usd")
360
- n.setJointValuesKinematic(T);
361
- else {
362
- const M = Object.fromEntries(x.map((v) => [v, T[v]]));
363
- n.setJointTargets(M);
364
- }
365
- return e(), n.getJointValues(c.map((M) => M.id));
366
- },
367
- ...t === "mjcf" ? { isDriveActive: () => n.isJointDriveActive } : {},
368
- requestRender: i
369
- }), I = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
370
- for (let T = 1; T < o.nbody; T++) {
371
- const x = r.mj_id2name(o, r.mjtObj.mjOBJ_BODY.value, T);
372
- if (!x) continue;
373
- I.set(x, T), m.set(T, x);
374
- let M = T;
375
- for (; M > 0 && !l.has(M); ) M = o.body_parentid[M];
376
- g.set(x, l.get(M) ?? null);
377
- }
378
- for (const [T, x] of f) {
379
- const M = [];
380
- for (const [v, N] of m) {
381
- let L = v;
382
- for (; L > 0 && L !== x; ) L = o.body_parentid[L];
383
- L === x && M.push(N);
384
- }
385
- y.set(T, Object.freeze(M));
386
- }
387
- let w = !1;
388
- const E = () => !w && n.model === o && n.data === a;
389
- return {
390
- ..._,
391
- pickRoots() {
392
- return E() && (s != null && s.root) ? [s.root] : [];
393
- },
394
- objectForBody(T) {
395
- var x;
396
- return E() && I.has(T) ? ((x = s == null ? void 0 : s.objectForBody) == null ? void 0 : x.call(s, T)) ?? null : null;
397
- },
398
- jointForBody(T) {
399
- return E() ? g.get(T) ?? null : null;
400
- },
401
- bodiesForJoint(T) {
402
- return E() ? y.get(T) ?? [] : [];
403
- },
404
- jointWorldFrame(T) {
405
- const x = d.get(T);
406
- if (!E() || x === void 0) return null;
407
- const M = new U().fromArray(a.xanchor, x * 3), v = new U().fromArray(a.xaxis, x * 3);
408
- return !M.toArray().every(Number.isFinite) || !v.toArray().every(Number.isFinite) || v.lengthSq() < 1e-12 ? null : (s != null && s.root ? (s.root.updateWorldMatrix(!0, !1), M.applyMatrix4(s.root.matrixWorld), v.transformDirection(s.root.matrixWorld)) : v.normalize(), { position: M, axis: v });
409
- },
410
- dispose() {
411
- w || (w = !0, _.dispose());
412
- }
413
- };
414
- }
415
- const En = 0, si = 1, ri = 2, Ye = 2, xe = 1.25, Xe = 1, W = 6 * 4 + 4 + 4, z = W / 4, Mn = 65535, fe = Math.pow(2, -24), je = Symbol("SKIP_GENERATION"), vn = {
416
- strategy: En,
417
- maxDepth: 40,
418
- maxLeafSize: 10,
419
- useSharedArrayBuffer: !1,
420
- setBoundingBox: !0,
421
- onProgress: null,
422
- indirect: !1,
423
- verbose: !0,
424
- range: null,
425
- [je]: !1
426
- };
427
- function O(n, t, e) {
428
- return e.min.x = t[n], e.min.y = t[n + 1], e.min.z = t[n + 2], e.max.x = t[n + 3], e.max.y = t[n + 4], e.max.z = t[n + 5], e;
429
- }
430
- function Ge(n) {
431
- let t = -1, e = -1 / 0;
432
- for (let i = 0; i < 3; i++) {
433
- const s = n[i + 3] - n[i];
434
- s > e && (e = s, t = i);
435
- }
436
- return t;
437
- }
438
- function Ze(n, t) {
439
- t.set(n);
440
- }
441
- function Ke(n, t, e) {
442
- let i, s;
443
- for (let o = 0; o < 3; o++) {
444
- const r = o + 3;
445
- i = n[o], s = t[o], e[o] = i < s ? i : s, i = n[r], s = t[r], e[r] = i > s ? i : s;
446
- }
447
- }
448
- function Yt(n, t, e) {
449
- for (let i = 0; i < 3; i++) {
450
- const s = t[n + 2 * i], o = t[n + 2 * i + 1], r = s - o, a = s + o;
451
- r < e[i] && (e[i] = r), a > e[i + 3] && (e[i + 3] = a);
452
- }
453
- }
454
- function Rt(n) {
455
- const t = n[3] - n[0], e = n[4] - n[1], i = n[5] - n[2];
456
- return 2 * (t * e + e * i + i * t);
457
- }
458
- function V(n, t) {
459
- return t[n + 15] === Mn;
460
- }
461
- function Y(n, t) {
462
- return t[n + 6];
463
- }
464
- function X(n, t) {
465
- return t[n + 14];
466
- }
467
- function $(n) {
468
- return n + z;
469
- }
470
- function k(n, t) {
471
- const e = t[n + 6];
472
- return n + e * z;
473
- }
474
- function $e(n, t) {
475
- return t[n + 7];
476
- }
477
- function be(n, t, e, i, s) {
478
- let o = 1 / 0, r = 1 / 0, a = 1 / 0, c = -1 / 0, d = -1 / 0, f = -1 / 0, l = 1 / 0, u = 1 / 0, p = 1 / 0, S = -1 / 0, P = -1 / 0, _ = -1 / 0;
479
- const I = n.offset || 0;
480
- for (let m = (t - I) * 6, g = (t + e - I) * 6; m < g; m += 6) {
481
- const y = n[m + 0], w = n[m + 1], E = y - w, h = y + w;
482
- E < o && (o = E), h > c && (c = h), y < l && (l = y), y > S && (S = y);
483
- const A = n[m + 2], B = n[m + 3], b = A - B, T = A + B;
484
- b < r && (r = b), T > d && (d = T), A < u && (u = A), A > P && (P = A);
485
- const x = n[m + 4], M = n[m + 5], v = x - M, N = x + M;
486
- v < a && (a = v), N > f && (f = N), x < p && (p = x), x > _ && (_ = x);
487
- }
488
- i[0] = o, i[1] = r, i[2] = a, i[3] = c, i[4] = d, i[5] = f, s[0] = l, s[1] = u, s[2] = p, s[3] = S, s[4] = P, s[5] = _;
489
- }
490
- const rt = 32, oi = (n, t) => n.candidate - t.candidate, ut = /* @__PURE__ */ new Array(rt).fill().map(() => ({
491
- count: 0,
492
- bounds: new Float32Array(6),
493
- rightCacheBounds: new Float32Array(6),
494
- leftCacheBounds: new Float32Array(6),
495
- candidate: 0
496
- })), Xt = /* @__PURE__ */ new Float32Array(6);
497
- function ci(n, t, e, i, s, o) {
498
- let r = -1, a = 0;
499
- if (o === En)
500
- r = Ge(t), r !== -1 && (a = (t[r] + t[r + 3]) / 2);
501
- else if (o === si)
502
- r = Ge(n), r !== -1 && (a = ai(e, i, s, r));
503
- else if (o === ri) {
504
- const c = Rt(n);
505
- let d = xe * s;
506
- const f = e.offset || 0, l = (i - f) * 6, u = (i + s - f) * 6;
507
- for (let p = 0; p < 3; p++) {
508
- const S = t[p], I = (t[p + 3] - S) / rt;
509
- if (s < rt / 4) {
510
- const m = [...ut];
511
- m.length = s;
512
- let g = 0;
513
- for (let w = l; w < u; w += 6, g++) {
514
- const E = m[g];
515
- E.candidate = e[w + 2 * p], E.count = 0;
516
- const {
517
- bounds: h,
518
- leftCacheBounds: A,
519
- rightCacheBounds: B
520
- } = E;
521
- for (let b = 0; b < 3; b++)
522
- B[b] = 1 / 0, B[b + 3] = -1 / 0, A[b] = 1 / 0, A[b + 3] = -1 / 0, h[b] = 1 / 0, h[b + 3] = -1 / 0;
523
- Yt(w, e, h);
524
- }
525
- m.sort(oi);
526
- let y = s;
527
- for (let w = 0; w < y; w++) {
528
- const E = m[w];
529
- for (; w + 1 < y && m[w + 1].candidate === E.candidate; )
530
- m.splice(w + 1, 1), y--;
531
- }
532
- for (let w = l; w < u; w += 6) {
533
- const E = e[w + 2 * p];
534
- for (let h = 0; h < y; h++) {
535
- const A = m[h];
536
- E >= A.candidate ? Yt(w, e, A.rightCacheBounds) : (Yt(w, e, A.leftCacheBounds), A.count++);
537
- }
538
- }
539
- for (let w = 0; w < y; w++) {
540
- const E = m[w], h = E.count, A = s - E.count, B = E.leftCacheBounds, b = E.rightCacheBounds;
541
- let T = 0;
542
- h !== 0 && (T = Rt(B) / c);
543
- let x = 0;
544
- A !== 0 && (x = Rt(b) / c);
545
- const M = Xe + xe * (T * h + x * A);
546
- M < d && (r = p, d = M, a = E.candidate);
547
- }
548
- } else {
549
- for (let y = 0; y < rt; y++) {
550
- const w = ut[y];
551
- w.count = 0, w.candidate = S + I + y * I;
552
- const E = w.bounds;
553
- for (let h = 0; h < 3; h++)
554
- E[h] = 1 / 0, E[h + 3] = -1 / 0;
555
- }
556
- for (let y = l; y < u; y += 6) {
557
- let h = ~~((e[y + 2 * p] - S) / I);
558
- h >= rt && (h = rt - 1);
559
- const A = ut[h];
560
- A.count++, Yt(y, e, A.bounds);
561
- }
562
- const m = ut[rt - 1];
563
- Ze(m.bounds, m.rightCacheBounds);
564
- for (let y = rt - 2; y >= 0; y--) {
565
- const w = ut[y], E = ut[y + 1];
566
- Ke(w.bounds, E.rightCacheBounds, w.rightCacheBounds);
567
- }
568
- let g = 0;
569
- for (let y = 0; y < rt - 1; y++) {
570
- const w = ut[y], E = w.count, h = w.bounds, B = ut[y + 1].rightCacheBounds;
571
- E !== 0 && (g === 0 ? Ze(h, Xt) : Ke(h, Xt, Xt)), g += E;
572
- let b = 0, T = 0;
573
- g !== 0 && (b = Rt(Xt) / c);
574
- const x = s - g;
575
- x !== 0 && (T = Rt(B) / c);
576
- const M = Xe + xe * (b * g + T * x);
577
- M < d && (r = p, d = M, a = w.candidate);
578
- }
579
- }
580
- }
581
- } else
582
- console.warn(`BVH: Invalid build strategy value ${o} used.`);
583
- return { axis: r, pos: a };
584
- }
585
- function ai(n, t, e, i) {
586
- let s = 0;
587
- const o = n.offset;
588
- for (let r = t, a = t + e; r < a; r++)
589
- s += n[(r - o) * 6 + i * 2];
590
- return s / e;
591
- }
592
- class Ae {
593
- constructor() {
594
- this.boundingData = new Float32Array(6);
595
- }
596
- }
597
- function li(n, t, e, i, s, o) {
598
- let r = i, a = i + s - 1;
599
- const c = o.pos, d = o.axis * 2, f = e.offset || 0;
600
- for (; ; ) {
601
- for (; r <= a && e[(r - f) * 6 + d] < c; )
602
- r++;
603
- for (; r <= a && e[(a - f) * 6 + d] >= c; )
604
- a--;
605
- if (r < a) {
606
- for (let l = 0; l < t; l++) {
607
- let u = n[r * t + l];
608
- n[r * t + l] = n[a * t + l], n[a * t + l] = u;
609
- }
610
- for (let l = 0; l < 6; l++) {
611
- const u = r - f, p = a - f, S = e[u * 6 + l];
612
- e[u * 6 + l] = e[p * 6 + l], e[p * 6 + l] = S;
613
- }
614
- r++, a--;
615
- } else
616
- return r;
617
- }
618
- }
619
- let Nn, de, ve, Un;
620
- const ui = Math.pow(2, 32);
621
- function Ne(n) {
622
- return "count" in n ? 1 : 1 + Ne(n.left) + Ne(n.right);
623
- }
624
- function fi(n, t, e) {
625
- return Nn = new Float32Array(e), de = new Uint32Array(e), ve = new Uint16Array(e), Un = new Uint8Array(e), Ue(n, t);
626
- }
627
- function Ue(n, t) {
628
- const e = n / 4, i = n / 2, s = "count" in t, o = t.boundingData;
629
- for (let r = 0; r < 6; r++)
630
- Nn[e + r] = o[r];
631
- if (s)
632
- return t.buffer ? (Un.set(new Uint8Array(t.buffer), n), n + t.buffer.byteLength) : (de[e + 6] = t.offset, ve[i + 14] = t.count, ve[i + 15] = Mn, n + W);
633
- {
634
- const { left: r, right: a, splitAxis: c } = t, d = n + W;
635
- let f = Ue(d, r);
636
- const l = n / W, p = f / W - l;
637
- if (p > ui)
638
- throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");
639
- return de[e + 6] = p, de[e + 7] = c, Ue(f, a);
640
- }
641
- }
642
- function di(n, t, e, i, s, o) {
643
- const {
644
- maxDepth: r,
645
- verbose: a,
646
- maxLeafSize: c,
647
- strategy: d,
648
- onProgress: f
649
- } = s, l = n.primitiveBuffer, u = n.primitiveBufferStride, p = new Float32Array(6);
650
- let S = !1;
651
- const P = new Ae();
652
- return be(t, e, i, P.boundingData, p), I(P, e, i, p), P;
653
- function _(m) {
654
- f && f((m - o.offset) / o.count);
655
- }
656
- function I(m, g, y, w = null, E = 0) {
657
- if (!S && E >= r && (S = !0, a && console.warn(`BVH: Max depth of ${r} reached when generating BVH. Consider increasing maxDepth.`)), y <= c || E >= r)
658
- return _(g + y), m.offset = g, m.count = y, m;
659
- const h = ci(m.boundingData, w, t, g, y, d);
660
- if (h.axis === -1)
661
- return _(g + y), m.offset = g, m.count = y, m;
662
- const A = li(l, u, t, g, y, h);
663
- if (A === g || A === g + y)
664
- _(g + y), m.offset = g, m.count = y;
665
- else {
666
- m.splitAxis = h.axis;
667
- const B = new Ae(), b = g, T = A - g;
668
- m.left = B, be(t, b, T, B.boundingData, p), I(B, b, T, p, E + 1);
669
- const x = new Ae(), M = A, v = y - T;
670
- m.right = x, be(t, M, v, x.boundingData, p), I(x, M, v, p, E + 1);
671
- }
672
- return m;
673
- }
674
- }
675
- function pi(n, t) {
676
- const e = t.useSharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer, i = n.getRootRanges(t.range), s = i[0], o = i[i.length - 1], r = {
677
- offset: s.offset,
678
- count: o.offset + o.count - s.offset
679
- }, a = new Float32Array(6 * r.count);
680
- a.offset = r.offset, n.computePrimitiveBounds(r.offset, r.count, a), n._roots = i.map((c) => {
681
- const d = di(n, a, c.offset, c.count, t, r), f = Ne(d), l = new e(W * f);
682
- return fi(0, d, l), l;
683
- });
684
- }
685
- class ke {
686
- constructor(t) {
687
- this._getNewPrimitive = t, this._primitives = [];
688
- }
689
- getPrimitive() {
690
- const t = this._primitives;
691
- return t.length === 0 ? this._getNewPrimitive() : t.pop();
692
- }
693
- releasePrimitive(t) {
694
- this._primitives.push(t);
695
- }
696
- }
697
- class mi {
698
- constructor() {
699
- this.float32Array = null, this.uint16Array = null, this.uint32Array = null;
700
- const t = [];
701
- let e = null;
702
- this.setBuffer = (i) => {
703
- e && t.push(e), e = i, this.float32Array = new Float32Array(i), this.uint16Array = new Uint16Array(i), this.uint32Array = new Uint32Array(i);
704
- }, this.clearBuffer = () => {
705
- e = null, this.float32Array = null, this.uint16Array = null, this.uint32Array = null, t.length !== 0 && this.setBuffer(t.pop());
706
- };
707
- }
708
- }
709
- const D = /* @__PURE__ */ new mi();
710
- let pt, vt;
711
- const bt = [], Gt = /* @__PURE__ */ new ke(() => new st());
712
- function hi(n, t, e, i, s, o) {
713
- pt = Gt.getPrimitive(), vt = Gt.getPrimitive(), bt.push(pt, vt), D.setBuffer(n._roots[t]);
714
- const r = Le(0, n.geometry, e, i, s, o);
715
- D.clearBuffer(), Gt.releasePrimitive(pt), Gt.releasePrimitive(vt), bt.pop(), bt.pop();
716
- const a = bt.length;
717
- return a > 0 && (vt = bt[a - 1], pt = bt[a - 2]), r;
718
- }
719
- function Le(n, t, e, i, s = null, o = 0, r = 0) {
720
- const { float32Array: a, uint16Array: c, uint32Array: d } = D;
721
- let f = n * 2;
722
- if (V(f, c)) {
723
- const u = Y(n, d), p = X(f, c);
724
- return O(n, a, pt), i(u, p, !1, r, o + n / z, pt);
725
- } else {
726
- let b = function(x) {
727
- const { uint16Array: M, uint32Array: v } = D;
728
- let N = x * 2;
729
- for (; !V(N, M); )
730
- x = $(x), N = x * 2;
731
- return Y(x, v);
732
- }, T = function(x) {
733
- const { uint16Array: M, uint32Array: v } = D;
734
- let N = x * 2;
735
- for (; !V(N, M); )
736
- x = k(x, v), N = x * 2;
737
- return Y(x, v) + X(N, M);
738
- };
739
- const u = $(n), p = k(n, d);
740
- let S = u, P = p, _, I, m, g;
741
- if (s && (m = pt, g = vt, O(S, a, m), O(P, a, g), _ = s(m), I = s(g), I < _)) {
742
- S = p, P = u;
743
- const x = _;
744
- _ = I, I = x, m = g;
745
- }
746
- m || (m = pt, O(S, a, m));
747
- const y = V(S * 2, c), w = e(m, y, _, r + 1, o + S / z);
748
- let E;
749
- if (w === Ye) {
750
- const x = b(S), v = T(S) - x;
751
- E = i(x, v, !0, r + 1, o + S / z, m);
752
- } else
753
- E = w && Le(
754
- S,
755
- t,
756
- e,
757
- i,
758
- s,
759
- o,
760
- r + 1
761
- );
762
- if (E) return !0;
763
- g = vt, O(P, a, g);
764
- const h = V(P * 2, c), A = e(g, h, I, r + 1, o + P / z);
765
- let B;
766
- if (A === Ye) {
767
- const x = b(P), v = T(P) - x;
768
- B = i(x, v, !0, r + 1, o + P / z, g);
769
- } else
770
- B = A && Le(
771
- P,
772
- t,
773
- e,
774
- i,
775
- s,
776
- o,
777
- r + 1
778
- );
779
- return !!B;
780
- }
781
- }
782
- const jt = /* @__PURE__ */ new D.constructor(), pe = /* @__PURE__ */ new D.constructor(), dt = /* @__PURE__ */ new ke(() => new st()), At = /* @__PURE__ */ new st(), _t = /* @__PURE__ */ new st(), _e = /* @__PURE__ */ new st(), Se = /* @__PURE__ */ new st();
783
- let Be = !1;
784
- function yi(n, t, e, i) {
785
- if (Be)
786
- throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");
787
- Be = !0;
788
- const s = n._roots, o = t._roots;
789
- let r, a = 0, c = 0;
790
- const d = new mt().copy(e).invert();
791
- for (let f = 0, l = s.length; f < l; f++) {
792
- jt.setBuffer(s[f]), c = 0;
793
- const u = dt.getPrimitive();
794
- O(0, jt.float32Array, u), u.applyMatrix4(d);
795
- for (let p = 0, S = o.length; p < S && (pe.setBuffer(o[p]), r = nt(
796
- 0,
797
- 0,
798
- e,
799
- d,
800
- i,
801
- a,
802
- c,
803
- 0,
804
- 0,
805
- u
806
- ), pe.clearBuffer(), c += o[p].byteLength / W, !r); p++)
807
- ;
808
- if (dt.releasePrimitive(u), jt.clearBuffer(), a += s[f].byteLength / W, r)
809
- break;
810
- }
811
- return Be = !1, r;
812
- }
813
- function nt(n, t, e, i, s, o = 0, r = 0, a = 0, c = 0, d = null, f = !1) {
814
- let l, u;
815
- f ? (l = pe, u = jt) : (l = jt, u = pe);
816
- const p = l.float32Array, S = l.uint32Array, P = l.uint16Array, _ = u.float32Array, I = u.uint32Array, m = u.uint16Array, g = n * 2, y = t * 2, w = V(g, P), E = V(y, m);
817
- let h = !1;
818
- if (E && w)
819
- f ? h = s(
820
- Y(t, I),
821
- X(t * 2, m),
822
- Y(n, S),
823
- X(n * 2, P),
824
- c,
825
- r + t / z,
826
- a,
827
- o + n / z
828
- ) : h = s(
829
- Y(n, S),
830
- X(n * 2, P),
831
- Y(t, I),
832
- X(t * 2, m),
833
- a,
834
- o + n / z,
835
- c,
836
- r + t / z
837
- );
838
- else if (E) {
839
- const A = dt.getPrimitive();
840
- O(t, _, A), A.applyMatrix4(e);
841
- const B = $(n), b = k(n, S);
842
- O(B, p, At), O(b, p, _t);
843
- const T = A.intersectsBox(At), x = A.intersectsBox(_t);
844
- h = T && nt(
845
- t,
846
- B,
847
- i,
848
- e,
849
- s,
850
- r,
851
- o,
852
- c,
853
- a + 1,
854
- A,
855
- !f
856
- ) || x && nt(
857
- t,
858
- b,
859
- i,
860
- e,
861
- s,
862
- r,
863
- o,
864
- c,
865
- a + 1,
866
- A,
867
- !f
868
- ), dt.releasePrimitive(A);
869
- } else {
870
- const A = $(t), B = k(t, I);
871
- O(A, _, _e), O(B, _, Se);
872
- const b = d.intersectsBox(_e), T = d.intersectsBox(Se);
873
- if (b && T)
874
- h = nt(
875
- n,
876
- A,
877
- e,
878
- i,
879
- s,
880
- o,
881
- r,
882
- a,
883
- c + 1,
884
- d,
885
- f
886
- ) || nt(
887
- n,
888
- B,
889
- e,
890
- i,
891
- s,
892
- o,
893
- r,
894
- a,
895
- c + 1,
896
- d,
897
- f
898
- );
899
- else if (b)
900
- if (w)
901
- h = nt(
902
- n,
903
- A,
904
- e,
905
- i,
906
- s,
907
- o,
908
- r,
909
- a,
910
- c + 1,
911
- d,
912
- f
913
- );
914
- else {
915
- const x = dt.getPrimitive();
916
- x.copy(_e).applyMatrix4(e);
917
- const M = $(n), v = k(n, S);
918
- O(M, p, At), O(v, p, _t);
919
- const N = x.intersectsBox(At), L = x.intersectsBox(_t);
920
- h = N && nt(
921
- A,
922
- M,
923
- i,
924
- e,
925
- s,
926
- r,
927
- o,
928
- c,
929
- a + 1,
930
- x,
931
- !f
932
- ) || L && nt(
933
- A,
934
- v,
935
- i,
936
- e,
937
- s,
938
- r,
939
- o,
940
- c,
941
- a + 1,
942
- x,
943
- !f
944
- ), dt.releasePrimitive(x);
945
- }
946
- else if (T)
947
- if (w)
948
- h = nt(
949
- n,
950
- B,
951
- e,
952
- i,
953
- s,
954
- o,
955
- r,
956
- a,
957
- c + 1,
958
- d,
959
- f
960
- );
961
- else {
962
- const x = dt.getPrimitive();
963
- x.copy(Se).applyMatrix4(e);
964
- const M = $(n), v = k(n, S);
965
- O(M, p, At), O(v, p, _t);
966
- const N = x.intersectsBox(At), L = x.intersectsBox(_t);
967
- h = N && nt(
968
- B,
969
- M,
970
- i,
971
- e,
972
- s,
973
- r,
974
- o,
975
- c,
976
- a + 1,
977
- x,
978
- !f
979
- ) || L && nt(
980
- B,
981
- v,
982
- i,
983
- e,
984
- s,
985
- r,
986
- o,
987
- c,
988
- a + 1,
989
- x,
990
- !f
991
- ), dt.releasePrimitive(x);
992
- }
993
- }
994
- return h;
995
- }
996
- const Qe = /* @__PURE__ */ new st(), St = /* @__PURE__ */ new Float32Array(6);
997
- class gi {
998
- constructor() {
999
- this._roots = null, this.primitiveBuffer = null, this.primitiveBufferStride = null;
1000
- }
1001
- init(t) {
1002
- t = {
1003
- ...vn,
1004
- ...t
1005
- }, pi(this, t);
1006
- }
1007
- getRootRanges() {
1008
- throw new Error("BVH: getRootRanges() not implemented");
1009
- }
1010
- // write the i-th primitive bounds in a 6-value min / max format to the buffer
1011
- // starting at the given "writeOffset"
1012
- writePrimitiveBounds() {
1013
- throw new Error("BVH: writePrimitiveBounds() not implemented");
1014
- }
1015
- // writes the union bounds of all primitives in the given range in a min / max format
1016
- // to the buffer
1017
- writePrimitiveRangeBounds(t, e, i, s) {
1018
- let o = 1 / 0, r = 1 / 0, a = 1 / 0, c = -1 / 0, d = -1 / 0, f = -1 / 0;
1019
- for (let l = t, u = t + e; l < u; l++) {
1020
- this.writePrimitiveBounds(l, St, 0);
1021
- const [p, S, P, _, I, m] = St;
1022
- p < o && (o = p), _ > c && (c = _), S < r && (r = S), I > d && (d = I), P < a && (a = P), m > f && (f = m);
1023
- }
1024
- return i[s + 0] = o, i[s + 1] = r, i[s + 2] = a, i[s + 3] = c, i[s + 4] = d, i[s + 5] = f, i;
1025
- }
1026
- computePrimitiveBounds(t, e, i) {
1027
- const s = i.offset || 0;
1028
- for (let o = t, r = t + e; o < r; o++) {
1029
- this.writePrimitiveBounds(o, St, 0);
1030
- const [a, c, d, f, l, u] = St, p = (a + f) / 2, S = (c + l) / 2, P = (d + u) / 2, _ = (f - a) / 2, I = (l - c) / 2, m = (u - d) / 2, g = (o - s) * 6;
1031
- i[g + 0] = p, i[g + 1] = _ + (Math.abs(p) + _) * fe, i[g + 2] = S, i[g + 3] = I + (Math.abs(S) + I) * fe, i[g + 4] = P, i[g + 5] = m + (Math.abs(P) + m) * fe;
1032
- }
1033
- return i;
1034
- }
1035
- shiftPrimitiveOffsets(t) {
1036
- const e = this._indirectBuffer;
1037
- if (e)
1038
- for (let i = 0, s = e.length; i < s; i++)
1039
- e[i] += t;
1040
- else {
1041
- const i = this._roots;
1042
- for (let s = 0; s < i.length; s++) {
1043
- const o = i[s], r = new Uint32Array(o), a = new Uint16Array(o), c = o.byteLength / W;
1044
- for (let d = 0; d < c; d++) {
1045
- const f = z * d, l = 2 * f;
1046
- V(l, a) && (r[f + 6] += t);
1047
- }
1048
- }
1049
- }
1050
- }
1051
- traverse(t, e = 0) {
1052
- const i = this._roots[e], s = new Uint32Array(i), o = new Uint16Array(i);
1053
- r(0);
1054
- function r(a, c = 0) {
1055
- const d = a * 2, f = V(d, o);
1056
- if (f) {
1057
- const l = s[a + 6], u = o[d + 14];
1058
- t(c, f, new Float32Array(i, a * 4, 6), l, u);
1059
- } else {
1060
- const l = $(a), u = k(a, s), p = $e(a, s);
1061
- t(c, f, new Float32Array(i, a * 4, 6), p) || (r(l, c + 1), r(u, c + 1));
1062
- }
1063
- }
1064
- }
1065
- refit() {
1066
- const t = this._roots;
1067
- for (let e = 0, i = t.length; e < i; e++) {
1068
- const s = t[e], o = new Uint32Array(s), r = new Uint16Array(s), a = new Float32Array(s), c = s.byteLength / W;
1069
- for (let d = c - 1; d >= 0; d--) {
1070
- const f = d * z, l = f * 2;
1071
- if (V(l, r)) {
1072
- const p = Y(f, o), S = X(l, r);
1073
- this.writePrimitiveRangeBounds(p, S, St, 0), a.set(St, f);
1074
- } else {
1075
- const p = $(f), S = k(f, o);
1076
- for (let P = 0; P < 3; P++) {
1077
- const _ = a[p + P], I = a[p + P + 3], m = a[S + P], g = a[S + P + 3];
1078
- a[f + P] = _ < m ? _ : m, a[f + P + 3] = I > g ? I : g;
1079
- }
1080
- }
1081
- }
1082
- }
1083
- }
1084
- getBoundingBox(t) {
1085
- return t.makeEmpty(), this._roots.forEach((i) => {
1086
- O(0, new Float32Array(i), Qe), t.union(Qe);
1087
- }), t;
1088
- }
1089
- // Base shapecast implementation that can be used by subclasses
1090
- // TODO: see if we can get rid of "iterateFunc" here as well as the primitive so the function
1091
- // API aligns with the "shapecast" implementation
1092
- shapecast(t) {
1093
- let {
1094
- boundsTraverseOrder: e,
1095
- intersectsBounds: i,
1096
- intersectsRange: s,
1097
- intersectsPrimitive: o,
1098
- scratchPrimitive: r,
1099
- iterate: a
1100
- } = t;
1101
- if (s && o) {
1102
- const l = s;
1103
- s = (u, p, S, P, _) => l(u, p, S, P, _) ? !0 : a(u, p, this, o, S, P, r);
1104
- } else s || (o ? s = (l, u, p, S) => a(l, u, this, o, p, S, r) : s = (l, u, p) => p);
1105
- let c = !1, d = 0;
1106
- const f = this._roots;
1107
- for (let l = 0, u = f.length; l < u; l++) {
1108
- const p = f[l];
1109
- if (c = hi(this, l, i, s, e, d), c)
1110
- break;
1111
- d += p.byteLength / W;
1112
- }
1113
- return c;
1114
- }
1115
- bvhcast(t, e, i) {
1116
- let { intersectsRanges: s } = i;
1117
- return yi(this, t, e, s);
1118
- }
1119
- }
1120
- function wi() {
1121
- return typeof SharedArrayBuffer < "u";
1122
- }
1123
- function qe(n) {
1124
- return n.index ? n.index.count : n.attributes.position.count;
1125
- }
1126
- function he(n) {
1127
- return qe(n) / 3;
1128
- }
1129
- function xi(n, t = ArrayBuffer) {
1130
- return n > 65535 ? new Uint32Array(new t(4 * n)) : new Uint16Array(new t(2 * n));
1131
- }
1132
- function bi(n, t) {
1133
- if (!n.index) {
1134
- const e = n.attributes.position.count, i = t.useSharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer, s = xi(e, i);
1135
- n.setIndex(new bn(s, 1));
1136
- for (let o = 0; o < e; o++)
1137
- s[o] = o;
1138
- }
1139
- }
1140
- function Ai(n, t, e) {
1141
- const i = qe(n) / e, s = t || n.drawRange, o = s.start / e, r = (s.start + s.count) / e, a = Math.max(0, o), c = Math.min(i, r) - a;
1142
- return {
1143
- offset: Math.floor(a),
1144
- count: Math.floor(c)
1145
- };
1146
- }
1147
- function _i(n, t) {
1148
- return n.groups.map((e) => ({
1149
- offset: e.start / t,
1150
- count: e.count / t
1151
- }));
1152
- }
1153
- function tn(n, t, e) {
1154
- const i = Ai(n, t, e), s = _i(n, e);
1155
- if (!s.length)
1156
- return [i];
1157
- const o = [], r = i.offset, a = i.offset + i.count, c = qe(n) / e, d = [];
1158
- for (const u of s) {
1159
- const { offset: p, count: S } = u, P = p, _ = isFinite(S) ? S : c - p, I = p + _;
1160
- P < a && I > r && (d.push({ pos: Math.max(r, P), isStart: !0 }), d.push({ pos: Math.min(a, I), isStart: !1 }));
1161
- }
1162
- d.sort((u, p) => u.pos !== p.pos ? u.pos - p.pos : u.type === "end" ? -1 : 1);
1163
- let f = 0, l = null;
1164
- for (const u of d) {
1165
- const p = u.pos;
1166
- f !== 0 && p !== l && o.push({
1167
- offset: l,
1168
- count: p - l
1169
- }), f += u.isStart ? 1 : -1, l = p;
1170
- }
1171
- return o;
1172
- }
1173
- function Si(n, t) {
1174
- const e = n[n.length - 1], i = e.offset + e.count > 2 ** 16, s = n.reduce((d, f) => d + f.count, 0), o = i ? 4 : 2, r = t ? new SharedArrayBuffer(s * o) : new ArrayBuffer(s * o), a = i ? new Uint32Array(r) : new Uint16Array(r);
1175
- let c = 0;
1176
- for (let d = 0; d < n.length; d++) {
1177
- const { offset: f, count: l } = n[d];
1178
- for (let u = 0; u < l; u++)
1179
- a[c + u] = f + u;
1180
- c += l;
1181
- }
1182
- return a;
1183
- }
1184
- class Bi extends gi {
1185
- get indirect() {
1186
- return !!this._indirectBuffer;
1187
- }
1188
- get primitiveStride() {
1189
- return null;
1190
- }
1191
- get primitiveBufferStride() {
1192
- return this.indirect ? 1 : this.primitiveStride;
1193
- }
1194
- set primitiveBufferStride(t) {
1195
- }
1196
- get primitiveBuffer() {
1197
- return this.indirect ? this._indirectBuffer : this.geometry.index.array;
1198
- }
1199
- set primitiveBuffer(t) {
1200
- }
1201
- constructor(t, e = {}) {
1202
- if (t.isBufferGeometry) {
1203
- if (t.index && t.index.isInterleavedBufferAttribute)
1204
- throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.");
1205
- } else throw new Error("BVH: Only BufferGeometries are supported.");
1206
- if (e.useSharedArrayBuffer && !wi())
1207
- throw new Error("BVH: SharedArrayBuffer is not available.");
1208
- super(), this.geometry = t, this.resolvePrimitiveIndex = e.indirect ? (i) => this._indirectBuffer[i] : (i) => i, this.primitiveBuffer = null, this.primitiveBufferStride = null, this._indirectBuffer = null, e = {
1209
- ...vn,
1210
- ...e
1211
- }, e[je] || this.init(e);
1212
- }
1213
- init(t) {
1214
- const { geometry: e, primitiveStride: i } = this;
1215
- if (t.indirect) {
1216
- const s = tn(e, t.range, i), o = Si(s, t.useSharedArrayBuffer);
1217
- this._indirectBuffer = o;
1218
- } else
1219
- bi(e, t);
1220
- super.init(t), !e.boundingBox && t.setBoundingBox && (e.boundingBox = this.getBoundingBox(new st()));
1221
- }
1222
- // Abstract methods to be implemented by subclasses
1223
- getRootRanges(t) {
1224
- return this.indirect ? [{ offset: 0, count: this._indirectBuffer.length }] : tn(this.geometry, t, this.primitiveStride);
1225
- }
1226
- raycastObject3D() {
1227
- throw new Error("BVH: raycastObject3D() not implemented");
1228
- }
1229
- }
1230
- class at {
1231
- constructor() {
1232
- this.min = 1 / 0, this.max = -1 / 0;
1233
- }
1234
- setFromPointsField(t, e) {
1235
- let i = 1 / 0, s = -1 / 0;
1236
- for (let o = 0, r = t.length; o < r; o++) {
1237
- const c = t[o][e];
1238
- i = c < i ? c : i, s = c > s ? c : s;
1239
- }
1240
- this.min = i, this.max = s;
1241
- }
1242
- setFromPoints(t, e) {
1243
- let i = 1 / 0, s = -1 / 0;
1244
- for (let o = 0, r = e.length; o < r; o++) {
1245
- const a = e[o], c = t.dot(a);
1246
- i = c < i ? c : i, s = c > s ? c : s;
1247
- }
1248
- this.min = i, this.max = s;
1249
- }
1250
- isSeparated(t) {
1251
- return this.min > t.max || t.min > this.max;
1252
- }
1253
- }
1254
- at.prototype.setFromBox = /* @__PURE__ */ function() {
1255
- const n = /* @__PURE__ */ new U();
1256
- return function(e, i) {
1257
- const s = i.min, o = i.max;
1258
- let r = 1 / 0, a = -1 / 0;
1259
- for (let c = 0; c <= 1; c++)
1260
- for (let d = 0; d <= 1; d++)
1261
- for (let f = 0; f <= 1; f++) {
1262
- n.x = s.x * c + o.x * (1 - c), n.y = s.y * d + o.y * (1 - d), n.z = s.z * f + o.z * (1 - f);
1263
- const l = e.dot(n);
1264
- r = Math.min(l, r), a = Math.max(l, a);
1265
- }
1266
- this.min = r, this.max = a;
1267
- };
1268
- }();
1269
- const Ti = /* @__PURE__ */ function() {
1270
- const n = /* @__PURE__ */ new U(), t = /* @__PURE__ */ new U(), e = /* @__PURE__ */ new U();
1271
- return function(s, o, r) {
1272
- const a = s.start, c = n, d = o.start, f = t;
1273
- e.subVectors(a, d), n.subVectors(s.end, s.start), t.subVectors(o.end, o.start);
1274
- const l = e.dot(f), u = f.dot(c), p = f.dot(f), S = e.dot(c), _ = c.dot(c) * p - u * u;
1275
- let I, m;
1276
- _ !== 0 ? I = (l * u - S * p) / _ : I = 0, m = (l + I * u) / p, r.x = I, r.y = m;
1277
- };
1278
- }(), Je = /* @__PURE__ */ function() {
1279
- const n = /* @__PURE__ */ new ht(), t = /* @__PURE__ */ new U(), e = /* @__PURE__ */ new U();
1280
- return function(s, o, r, a) {
1281
- Ti(s, o, n);
1282
- let c = n.x, d = n.y;
1283
- if (c >= 0 && c <= 1 && d >= 0 && d <= 1) {
1284
- s.at(c, r), o.at(d, a);
1285
- return;
1286
- } else if (c >= 0 && c <= 1) {
1287
- d < 0 ? o.at(0, a) : o.at(1, a), s.closestPointToPoint(a, !0, r);
1288
- return;
1289
- } else if (d >= 0 && d <= 1) {
1290
- c < 0 ? s.at(0, r) : s.at(1, r), o.closestPointToPoint(r, !0, a);
1291
- return;
1292
- } else {
1293
- let f;
1294
- c < 0 ? f = s.start : f = s.end;
1295
- let l;
1296
- d < 0 ? l = o.start : l = o.end;
1297
- const u = t, p = e;
1298
- if (s.closestPointToPoint(l, !0, t), o.closestPointToPoint(f, !0, e), u.distanceToSquared(l) <= p.distanceToSquared(f)) {
1299
- r.copy(u), a.copy(l);
1300
- return;
1301
- } else {
1302
- r.copy(f), a.copy(p);
1303
- return;
1304
- }
1305
- }
1306
- };
1307
- }(), Pi = /* @__PURE__ */ function() {
1308
- const n = /* @__PURE__ */ new U(), t = /* @__PURE__ */ new U(), e = /* @__PURE__ */ new An(), i = /* @__PURE__ */ new ct();
1309
- return function(o, r) {
1310
- const { radius: a, center: c } = o, { a: d, b: f, c: l } = r;
1311
- if (i.start = d, i.end = f, i.closestPointToPoint(c, !0, n).distanceTo(c) <= a || (i.start = d, i.end = l, i.closestPointToPoint(c, !0, n).distanceTo(c) <= a) || (i.start = f, i.end = l, i.closestPointToPoint(c, !0, n).distanceTo(c) <= a)) return !0;
1312
- const P = r.getPlane(e);
1313
- if (Math.abs(P.distanceToPoint(c)) <= a) {
1314
- const I = P.projectPoint(c, t);
1315
- if (r.containsPoint(I)) return !0;
1316
- }
1317
- return !1;
1318
- };
1319
- }(), Ii = ["x", "y", "z"], ot = 1e-15, en = ot * ot;
1320
- function Q(n) {
1321
- return Math.abs(n) < ot;
1322
- }
1323
- class it extends Et {
1324
- constructor(...t) {
1325
- super(...t), this.isExtendedTriangle = !0, this.satAxes = new Array(4).fill().map(() => new U()), this.satBounds = new Array(4).fill().map(() => new at()), this.points = [this.a, this.b, this.c], this.plane = new An(), this.isDegenerateIntoSegment = !1, this.isDegenerateIntoPoint = !1, this.degenerateSegment = new ct(), this.needsUpdate = !0;
1326
- }
1327
- intersectsSphere(t) {
1328
- return Pi(t, this);
1329
- }
1330
- update() {
1331
- const t = this.a, e = this.b, i = this.c, s = this.points, o = this.satAxes, r = this.satBounds, a = o[0], c = r[0];
1332
- this.getNormal(a), c.setFromPoints(a, s);
1333
- const d = o[1], f = r[1];
1334
- d.subVectors(t, e), f.setFromPoints(d, s);
1335
- const l = o[2], u = r[2];
1336
- l.subVectors(e, i), u.setFromPoints(l, s);
1337
- const p = o[3], S = r[3];
1338
- p.subVectors(i, t), S.setFromPoints(p, s);
1339
- const P = d.length(), _ = l.length(), I = p.length();
1340
- this.isDegenerateIntoPoint = !1, this.isDegenerateIntoSegment = !1, P < ot ? _ < ot || I < ot ? this.isDegenerateIntoPoint = !0 : (this.isDegenerateIntoSegment = !0, this.degenerateSegment.start.copy(t), this.degenerateSegment.end.copy(i)) : _ < ot ? I < ot ? this.isDegenerateIntoPoint = !0 : (this.isDegenerateIntoSegment = !0, this.degenerateSegment.start.copy(e), this.degenerateSegment.end.copy(t)) : I < ot && (this.isDegenerateIntoSegment = !0, this.degenerateSegment.start.copy(i), this.degenerateSegment.end.copy(e)), this.plane.setFromNormalAndCoplanarPoint(a, t), this.needsUpdate = !1;
1341
- }
1342
- }
1343
- it.prototype.closestPointToSegment = /* @__PURE__ */ function() {
1344
- const n = /* @__PURE__ */ new U(), t = /* @__PURE__ */ new U(), e = /* @__PURE__ */ new ct();
1345
- return function(s, o = null, r = null) {
1346
- const { start: a, end: c } = s, d = this.points;
1347
- let f, l = 1 / 0;
1348
- for (let u = 0; u < 3; u++) {
1349
- const p = (u + 1) % 3;
1350
- e.start.copy(d[u]), e.end.copy(d[p]), Je(e, s, n, t), f = n.distanceToSquared(t), f < l && (l = f, o && o.copy(n), r && r.copy(t));
1351
- }
1352
- return this.closestPointToPoint(a, n), f = a.distanceToSquared(n), f < l && (l = f, o && o.copy(n), r && r.copy(a)), this.closestPointToPoint(c, n), f = c.distanceToSquared(n), f < l && (l = f, o && o.copy(n), r && r.copy(c)), Math.sqrt(l);
1353
- };
1354
- }();
1355
- it.prototype.intersectsTriangle = /* @__PURE__ */ function() {
1356
- const n = /* @__PURE__ */ new it(), t = /* @__PURE__ */ new at(), e = /* @__PURE__ */ new at(), i = /* @__PURE__ */ new U(), s = /* @__PURE__ */ new U(), o = /* @__PURE__ */ new U(), r = /* @__PURE__ */ new U(), a = /* @__PURE__ */ new ct(), c = /* @__PURE__ */ new ct(), d = /* @__PURE__ */ new U(), f = /* @__PURE__ */ new ht(), l = /* @__PURE__ */ new ht();
1357
- function u(g, y, w, E) {
1358
- const h = i;
1359
- !g.isDegenerateIntoPoint && !g.isDegenerateIntoSegment ? h.copy(g.plane.normal) : h.copy(y.plane.normal);
1360
- const A = g.satBounds, B = g.satAxes;
1361
- for (let x = 1; x < 4; x++) {
1362
- const M = A[x], v = B[x];
1363
- if (t.setFromPoints(v, y.points), M.isSeparated(t) || (r.copy(h).cross(v), t.setFromPoints(r, g.points), e.setFromPoints(r, y.points), t.isSeparated(e))) return !1;
1364
- }
1365
- const b = y.satBounds, T = y.satAxes;
1366
- for (let x = 1; x < 4; x++) {
1367
- const M = b[x], v = T[x];
1368
- if (t.setFromPoints(v, g.points), M.isSeparated(t) || (r.crossVectors(h, v), t.setFromPoints(r, g.points), e.setFromPoints(r, y.points), t.isSeparated(e))) return !1;
1369
- }
1370
- return w && (E || console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."), w.start.set(0, 0, 0), w.end.set(0, 0, 0)), !0;
1371
- }
1372
- function p(g, y, w, E, h, A, B, b, T, x, M) {
1373
- let v = B / (B - b);
1374
- x.x = E + (h - E) * v, M.start.subVectors(y, g).multiplyScalar(v).add(g), v = B / (B - T), x.y = E + (A - E) * v, M.end.subVectors(w, g).multiplyScalar(v).add(g);
1375
- }
1376
- function S(g, y, w, E, h, A, B, b, T, x, M) {
1377
- if (h > 0)
1378
- p(g.c, g.a, g.b, E, y, w, T, B, b, x, M);
1379
- else if (A > 0)
1380
- p(g.b, g.a, g.c, w, y, E, b, B, T, x, M);
1381
- else if (b * T > 0 || B != 0)
1382
- p(g.a, g.b, g.c, y, w, E, B, b, T, x, M);
1383
- else if (b != 0)
1384
- p(g.b, g.a, g.c, w, y, E, b, B, T, x, M);
1385
- else if (T != 0)
1386
- p(g.c, g.a, g.b, E, y, w, T, B, b, x, M);
1387
- else
1388
- return !0;
1389
- return !1;
1390
- }
1391
- function P(g, y, w, E) {
1392
- const h = y.degenerateSegment, A = g.plane.distanceToPoint(h.start), B = g.plane.distanceToPoint(h.end);
1393
- return Q(A) ? Q(B) ? u(g, y, w, E) : (w && (w.start.copy(h.start), w.end.copy(h.start)), g.containsPoint(h.start)) : Q(B) ? (w && (w.start.copy(h.end), w.end.copy(h.end)), g.containsPoint(h.end)) : g.plane.intersectLine(h, i) != null ? (w && (w.start.copy(i), w.end.copy(i)), g.containsPoint(i)) : !1;
1394
- }
1395
- function _(g, y, w) {
1396
- const E = y.a;
1397
- return Q(g.plane.distanceToPoint(E)) && g.containsPoint(E) ? (w && (w.start.copy(E), w.end.copy(E)), !0) : !1;
1398
- }
1399
- function I(g, y, w) {
1400
- const E = g.degenerateSegment, h = y.a;
1401
- return E.closestPointToPoint(h, !0, i), h.distanceToSquared(i) < en ? (w && (w.start.copy(h), w.end.copy(h)), !0) : !1;
1402
- }
1403
- function m(g, y, w, E) {
1404
- if (g.isDegenerateIntoSegment)
1405
- if (y.isDegenerateIntoSegment) {
1406
- const h = g.degenerateSegment, A = y.degenerateSegment, B = s, b = o;
1407
- h.delta(B), A.delta(b);
1408
- const T = i.subVectors(A.start, h.start), x = B.x * b.y - B.y * b.x;
1409
- if (Q(x))
1410
- return !1;
1411
- const M = (T.x * b.y - T.y * b.x) / x, v = -(B.x * T.y - B.y * T.x) / x;
1412
- if (M < 0 || M > 1 || v < 0 || v > 1)
1413
- return !1;
1414
- const N = h.start.z + B.z * M, L = A.start.z + b.z * v;
1415
- return Q(N - L) ? (w && (w.start.copy(h.start).addScaledVector(B, M), w.end.copy(h.start).addScaledVector(B, M)), !0) : !1;
1416
- } else return y.isDegenerateIntoPoint ? I(g, y, w) : P(y, g, w, E);
1417
- else {
1418
- if (g.isDegenerateIntoPoint)
1419
- return y.isDegenerateIntoPoint ? y.a.distanceToSquared(g.a) < en ? (w && (w.start.copy(g.a), w.end.copy(g.a)), !0) : !1 : y.isDegenerateIntoSegment ? I(y, g, w) : _(y, g, w);
1420
- if (y.isDegenerateIntoPoint)
1421
- return _(g, y, w);
1422
- if (y.isDegenerateIntoSegment)
1423
- return P(g, y, w, E);
1424
- }
1425
- }
1426
- return function(y, w = null, E = !1) {
1427
- this.needsUpdate && this.update(), y.isExtendedTriangle ? y.needsUpdate && y.update() : (n.copy(y), n.update(), y = n);
1428
- const h = m(this, y, w, E);
1429
- if (h !== void 0)
1430
- return h;
1431
- const A = this.plane, B = y.plane;
1432
- let b = B.distanceToPoint(this.a), T = B.distanceToPoint(this.b), x = B.distanceToPoint(this.c);
1433
- Q(b) && (b = 0), Q(T) && (T = 0), Q(x) && (x = 0);
1434
- const M = b * T, v = b * x;
1435
- if (M > 0 && v > 0)
1436
- return !1;
1437
- let N = A.distanceToPoint(y.a), L = A.distanceToPoint(y.b), R = A.distanceToPoint(y.c);
1438
- Q(N) && (N = 0), Q(L) && (L = 0), Q(R) && (R = 0);
1439
- const j = N * L, q = N * R;
1440
- if (j > 0 && q > 0)
1441
- return !1;
1442
- s.copy(A.normal), o.copy(B.normal);
1443
- const et = s.cross(o);
1444
- let C = 0, K = Math.abs(et.x);
1445
- const Ut = Math.abs(et.y);
1446
- Ut > K && (K = Ut, C = 1), Math.abs(et.z) > K && (C = 2);
1447
- const lt = Ii[C], kt = this.a[lt], qt = this.b[lt], Jt = this.c[lt], Ht = y.a[lt], Wt = y.b[lt], Dn = y.c[lt];
1448
- if (S(this, kt, qt, Jt, M, v, b, T, x, f, a))
1449
- return u(this, y, w, E);
1450
- if (S(y, Ht, Wt, Dn, j, q, N, L, R, l, c))
1451
- return u(this, y, w, E);
1452
- if (f.y < f.x) {
1453
- const ge = f.y;
1454
- f.y = f.x, f.x = ge, d.copy(a.start), a.start.copy(a.end), a.end.copy(d);
1455
- }
1456
- if (l.y < l.x) {
1457
- const ge = l.y;
1458
- l.y = l.x, l.x = ge, d.copy(c.start), c.start.copy(c.end), c.end.copy(d);
1459
- }
1460
- return f.y < l.x || l.y < f.x ? !1 : (w && (l.x > f.x ? w.start.copy(c.start) : w.start.copy(a.start), l.y < f.y ? w.end.copy(c.end) : w.end.copy(a.end)), !0);
1461
- };
1462
- }();
1463
- it.prototype.distanceToPoint = /* @__PURE__ */ function() {
1464
- const n = /* @__PURE__ */ new U();
1465
- return function(e) {
1466
- return this.closestPointToPoint(e, n), e.distanceTo(n);
1467
- };
1468
- }();
1469
- it.prototype.distanceToTriangle = /* @__PURE__ */ function() {
1470
- const n = /* @__PURE__ */ new U(), t = /* @__PURE__ */ new U(), e = ["a", "b", "c"], i = /* @__PURE__ */ new ct(), s = /* @__PURE__ */ new ct();
1471
- return function(r, a = null, c = null) {
1472
- const d = a || c ? i : null;
1473
- if (this.intersectsTriangle(r, d))
1474
- return (a || c) && (a && d.getCenter(a), c && d.getCenter(c)), 0;
1475
- let f = 1 / 0;
1476
- for (let l = 0; l < 3; l++) {
1477
- let u;
1478
- const p = e[l], S = r[p];
1479
- this.closestPointToPoint(S, n), u = S.distanceToSquared(n), u < f && (f = u, a && a.copy(n), c && c.copy(S));
1480
- const P = this[p];
1481
- r.closestPointToPoint(P, n), u = P.distanceToSquared(n), u < f && (f = u, a && a.copy(P), c && c.copy(n));
1482
- }
1483
- for (let l = 0; l < 3; l++) {
1484
- const u = e[l], p = e[(l + 1) % 3];
1485
- i.set(this[u], this[p]);
1486
- for (let S = 0; S < 3; S++) {
1487
- const P = e[S], _ = e[(S + 1) % 3];
1488
- s.set(r[P], r[_]), Je(i, s, n, t);
1489
- const I = n.distanceToSquared(t);
1490
- I < f && (f = I, a && a.copy(n), c && c.copy(t));
1491
- }
1492
- }
1493
- return Math.sqrt(f);
1494
- };
1495
- }();
1496
- class G {
1497
- constructor(t, e, i) {
1498
- this.isOrientedBox = !0, this.min = new U(), this.max = new U(), this.matrix = new mt(), this.invMatrix = new mt(), this.points = new Array(8).fill().map(() => new U()), this.satAxes = new Array(3).fill().map(() => new U()), this.satBounds = new Array(3).fill().map(() => new at()), this.alignedSatBounds = new Array(3).fill().map(() => new at()), this.needsUpdate = !1, t && this.min.copy(t), e && this.max.copy(e), i && this.matrix.copy(i);
1499
- }
1500
- set(t, e, i) {
1501
- this.min.copy(t), this.max.copy(e), this.matrix.copy(i), this.needsUpdate = !0;
1502
- }
1503
- copy(t) {
1504
- this.min.copy(t.min), this.max.copy(t.max), this.matrix.copy(t.matrix), this.needsUpdate = !0;
1505
- }
1506
- }
1507
- G.prototype.update = /* @__PURE__ */ function() {
1508
- return function() {
1509
- const t = this.matrix, e = this.min, i = this.max, s = this.points;
1510
- for (let d = 0; d <= 1; d++)
1511
- for (let f = 0; f <= 1; f++)
1512
- for (let l = 0; l <= 1; l++) {
1513
- const u = 1 * d | 2 * f | 4 * l, p = s[u];
1514
- p.x = d ? i.x : e.x, p.y = f ? i.y : e.y, p.z = l ? i.z : e.z, p.applyMatrix4(t);
1515
- }
1516
- const o = this.satBounds, r = this.satAxes, a = s[0];
1517
- for (let d = 0; d < 3; d++) {
1518
- const f = r[d], l = o[d], u = 1 << d, p = s[u];
1519
- f.subVectors(a, p), l.setFromPoints(f, s);
1520
- }
1521
- const c = this.alignedSatBounds;
1522
- c[0].setFromPointsField(s, "x"), c[1].setFromPointsField(s, "y"), c[2].setFromPointsField(s, "z"), this.invMatrix.copy(this.matrix).invert(), this.needsUpdate = !1;
1523
- };
1524
- }();
1525
- G.prototype.intersectsBox = /* @__PURE__ */ function() {
1526
- const n = /* @__PURE__ */ new at();
1527
- return function(e) {
1528
- this.needsUpdate && this.update();
1529
- const i = e.min, s = e.max, o = this.satBounds, r = this.satAxes, a = this.alignedSatBounds;
1530
- if (n.min = i.x, n.max = s.x, a[0].isSeparated(n) || (n.min = i.y, n.max = s.y, a[1].isSeparated(n)) || (n.min = i.z, n.max = s.z, a[2].isSeparated(n))) return !1;
1531
- for (let c = 0; c < 3; c++) {
1532
- const d = r[c], f = o[c];
1533
- if (n.setFromBox(d, e), f.isSeparated(n)) return !1;
1534
- }
1535
- return !0;
1536
- };
1537
- }();
1538
- G.prototype.intersectsTriangle = /* @__PURE__ */ function() {
1539
- const n = /* @__PURE__ */ new it(), t = /* @__PURE__ */ new Array(3), e = /* @__PURE__ */ new at(), i = /* @__PURE__ */ new at(), s = /* @__PURE__ */ new U();
1540
- return function(r) {
1541
- this.needsUpdate && this.update(), r.isExtendedTriangle ? r.needsUpdate && r.update() : (n.copy(r), n.update(), r = n);
1542
- const a = this.satBounds, c = this.satAxes;
1543
- t[0] = r.a, t[1] = r.b, t[2] = r.c;
1544
- for (let u = 0; u < 3; u++) {
1545
- const p = a[u], S = c[u];
1546
- if (e.setFromPoints(S, t), p.isSeparated(e)) return !1;
1547
- }
1548
- const d = r.satBounds, f = r.satAxes, l = this.points;
1549
- for (let u = 0; u < 3; u++) {
1550
- const p = d[u], S = f[u];
1551
- if (e.setFromPoints(S, l), p.isSeparated(e)) return !1;
1552
- }
1553
- for (let u = 0; u < 3; u++) {
1554
- const p = c[u];
1555
- for (let S = 0; S < 4; S++) {
1556
- const P = f[S];
1557
- if (s.crossVectors(p, P), e.setFromPoints(s, t), i.setFromPoints(s, l), e.isSeparated(i)) return !1;
1558
- }
1559
- }
1560
- return !0;
1561
- };
1562
- }();
1563
- G.prototype.closestPointToPoint = /* @__PURE__ */ function() {
1564
- return function(t, e) {
1565
- return this.needsUpdate && this.update(), e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min, this.max).applyMatrix4(this.matrix), e;
1566
- };
1567
- }();
1568
- G.prototype.distanceToPoint = function() {
1569
- const n = new U();
1570
- return function(e) {
1571
- return this.closestPointToPoint(e, n), e.distanceTo(n);
1572
- };
1573
- }();
1574
- G.prototype.distanceToBox = /* @__PURE__ */ function() {
1575
- const n = ["x", "y", "z"], t = /* @__PURE__ */ new Array(12).fill().map(() => new ct()), e = /* @__PURE__ */ new Array(12).fill().map(() => new ct()), i = /* @__PURE__ */ new U(), s = /* @__PURE__ */ new U();
1576
- return function(r, a = 0, c = null, d = null) {
1577
- if (this.needsUpdate && this.update(), this.intersectsBox(r))
1578
- return (c || d) && (r.getCenter(s), this.closestPointToPoint(s, i), r.closestPointToPoint(i, s), c && c.copy(i), d && d.copy(s)), 0;
1579
- const f = a * a, l = r.min, u = r.max, p = this.points;
1580
- let S = 1 / 0;
1581
- for (let _ = 0; _ < 8; _++) {
1582
- const I = p[_];
1583
- s.copy(I).clamp(l, u);
1584
- const m = I.distanceToSquared(s);
1585
- if (m < S && (S = m, c && c.copy(I), d && d.copy(s), m < f))
1586
- return Math.sqrt(m);
1587
- }
1588
- let P = 0;
1589
- for (let _ = 0; _ < 3; _++)
1590
- for (let I = 0; I <= 1; I++)
1591
- for (let m = 0; m <= 1; m++) {
1592
- const g = (_ + 1) % 3, y = (_ + 2) % 3, w = I << g | m << y, E = 1 << _ | I << g | m << y, h = p[w], A = p[E];
1593
- t[P].set(h, A);
1594
- const b = n[_], T = n[g], x = n[y], M = e[P], v = M.start, N = M.end;
1595
- v[b] = l[b], v[T] = I ? l[T] : u[T], v[x] = m ? l[x] : u[T], N[b] = u[b], N[T] = I ? l[T] : u[T], N[x] = m ? l[x] : u[T], P++;
1596
- }
1597
- for (let _ = 0; _ <= 1; _++)
1598
- for (let I = 0; I <= 1; I++)
1599
- for (let m = 0; m <= 1; m++) {
1600
- s.x = _ ? u.x : l.x, s.y = I ? u.y : l.y, s.z = m ? u.z : l.z, this.closestPointToPoint(s, i);
1601
- const g = s.distanceToSquared(i);
1602
- if (g < S && (S = g, c && c.copy(i), d && d.copy(s), g < f))
1603
- return Math.sqrt(g);
1604
- }
1605
- for (let _ = 0; _ < 12; _++) {
1606
- const I = t[_];
1607
- for (let m = 0; m < 12; m++) {
1608
- const g = e[m];
1609
- Je(I, g, i, s);
1610
- const y = i.distanceToSquared(s);
1611
- if (y < S && (S = y, c && c.copy(i), d && d.copy(s), y < f))
1612
- return Math.sqrt(y);
1613
- }
1614
- }
1615
- return Math.sqrt(S);
1616
- };
1617
- }();
1618
- class Ei extends ke {
1619
- constructor() {
1620
- super(() => new it());
1621
- }
1622
- }
1623
- const tt = /* @__PURE__ */ new Ei(), Dt = /* @__PURE__ */ new U(), Te = /* @__PURE__ */ new U();
1624
- function Mi(n, t, e = {}, i = 0, s = 1 / 0) {
1625
- const o = i * i, r = s * s;
1626
- let a = 1 / 0, c = null;
1627
- if (n.shapecast(
1628
- {
1629
- boundsTraverseOrder: (f) => (Dt.copy(t).clamp(f.min, f.max), Dt.distanceToSquared(t)),
1630
- intersectsBounds: (f, l, u) => u < a && u < r,
1631
- intersectsTriangle: (f, l) => {
1632
- f.closestPointToPoint(t, Dt);
1633
- const u = t.distanceToSquared(Dt);
1634
- return u < a && (Te.copy(Dt), a = u, c = l), u < o;
1635
- }
1636
- }
1637
- ), a === 1 / 0) return null;
1638
- const d = Math.sqrt(a);
1639
- return e.point ? e.point.copy(Te) : e.point = Te.clone(), e.distance = d, e.faceIndex = c, e;
1640
- }
1641
- const Zt = parseInt(Sn) >= 169, vi = parseInt(Sn) <= 161, gt = /* @__PURE__ */ new U(), wt = /* @__PURE__ */ new U(), xt = /* @__PURE__ */ new U(), Kt = /* @__PURE__ */ new ht(), Qt = /* @__PURE__ */ new ht(), te = /* @__PURE__ */ new ht(), nn = /* @__PURE__ */ new U(), sn = /* @__PURE__ */ new U(), rn = /* @__PURE__ */ new U(), Ct = /* @__PURE__ */ new U();
1642
- function Ni(n, t, e, i, s, o, r, a) {
1643
- let c;
1644
- if (o === Fn ? c = n.intersectTriangle(i, e, t, !0, s) : c = n.intersectTriangle(t, e, i, o !== _n, s), c === null) return null;
1645
- const d = n.origin.distanceTo(s);
1646
- return d < r || d > a ? null : {
1647
- distance: d,
1648
- point: s.clone()
1649
- };
1650
- }
1651
- function on(n, t, e, i, s, o, r, a, c, d, f) {
1652
- gt.fromBufferAttribute(t, o), wt.fromBufferAttribute(t, r), xt.fromBufferAttribute(t, a);
1653
- const l = Ni(n, gt, wt, xt, Ct, c, d, f);
1654
- if (l) {
1655
- if (i) {
1656
- Kt.fromBufferAttribute(i, o), Qt.fromBufferAttribute(i, r), te.fromBufferAttribute(i, a), l.uv = new ht();
1657
- const p = Et.getInterpolation(Ct, gt, wt, xt, Kt, Qt, te, l.uv);
1658
- Zt || (l.uv = p);
1659
- }
1660
- if (s) {
1661
- Kt.fromBufferAttribute(s, o), Qt.fromBufferAttribute(s, r), te.fromBufferAttribute(s, a), l.uv1 = new ht();
1662
- const p = Et.getInterpolation(Ct, gt, wt, xt, Kt, Qt, te, l.uv1);
1663
- Zt || (l.uv1 = p), vi && (l.uv2 = l.uv1);
1664
- }
1665
- if (e) {
1666
- nn.fromBufferAttribute(e, o), sn.fromBufferAttribute(e, r), rn.fromBufferAttribute(e, a), l.normal = new U();
1667
- const p = Et.getInterpolation(Ct, gt, wt, xt, nn, sn, rn, l.normal);
1668
- l.normal.dot(n.direction) > 0 && l.normal.multiplyScalar(-1), Zt || (l.normal = p);
1669
- }
1670
- const u = {
1671
- a: o,
1672
- b: r,
1673
- c: a,
1674
- normal: new U(),
1675
- materialIndex: 0
1676
- };
1677
- if (Et.getNormal(gt, wt, xt, u.normal), l.face = u, l.faceIndex = o, Zt) {
1678
- const p = new U();
1679
- Et.getBarycoord(Ct, gt, wt, xt, p), l.barycoord = p;
1680
- }
1681
- }
1682
- return l;
1683
- }
1684
- function cn(n) {
1685
- return n && n.isMaterial ? n.side : n;
1686
- }
1687
- function ye(n, t, e, i, s, o, r) {
1688
- const a = i * 3;
1689
- let c = a + 0, d = a + 1, f = a + 2;
1690
- const { index: l, groups: u } = n;
1691
- n.index && (c = l.getX(c), d = l.getX(d), f = l.getX(f));
1692
- const { position: p, normal: S, uv: P, uv1: _ } = n.attributes;
1693
- if (Array.isArray(t)) {
1694
- const I = i * 3;
1695
- for (let m = 0, g = u.length; m < g; m++) {
1696
- const { start: y, count: w, materialIndex: E } = u[m];
1697
- if (I >= y && I < y + w) {
1698
- const h = cn(t[E]), A = on(e, p, S, P, _, c, d, f, h, o, r);
1699
- if (A)
1700
- if (A.faceIndex = i, A.face.materialIndex = E, s)
1701
- s.push(A);
1702
- else
1703
- return A;
1704
- }
1705
- }
1706
- } else {
1707
- const I = cn(t), m = on(e, p, S, P, _, c, d, f, I, o, r);
1708
- if (m)
1709
- if (m.faceIndex = i, m.face.materialIndex = 0, s)
1710
- s.push(m);
1711
- else
1712
- return m;
1713
- }
1714
- return null;
1715
- }
1716
- function F(n, t, e, i) {
1717
- const s = n.a, o = n.b, r = n.c;
1718
- let a = t, c = t + 1, d = t + 2;
1719
- e && (a = e.getX(a), c = e.getX(c), d = e.getX(d)), s.x = i.getX(a), s.y = i.getY(a), s.z = i.getZ(a), o.x = i.getX(c), o.y = i.getY(c), o.z = i.getZ(c), r.x = i.getX(d), r.y = i.getY(d), r.z = i.getZ(d);
1720
- }
1721
- function Ui(n, t, e, i, s, o, r, a) {
1722
- const { geometry: c, _indirectBuffer: d } = n;
1723
- for (let f = i, l = i + s; f < l; f++)
1724
- ye(c, t, e, f, o, r, a);
1725
- }
1726
- function Li(n, t, e, i, s, o, r) {
1727
- const { geometry: a, _indirectBuffer: c } = n;
1728
- let d = 1 / 0, f = null;
1729
- for (let l = i, u = i + s; l < u; l++) {
1730
- let p;
1731
- p = ye(a, t, e, l, null, o, r), p && p.distance < d && (f = p, d = p.distance);
1732
- }
1733
- return f;
1734
- }
1735
- function Ri(n, t, e, i, s, o, r) {
1736
- const { geometry: a } = e, { index: c } = a, d = a.attributes.position;
1737
- for (let f = n, l = t + n; f < l; f++) {
1738
- let u;
1739
- if (u = f, F(r, u * 3, c, d), r.needsUpdate = !0, i(r, u, s, o))
1740
- return !0;
1741
- }
1742
- return !1;
1743
- }
1744
- function Di(n, t = null) {
1745
- t && Array.isArray(t) && (t = new Set(t));
1746
- const e = n.geometry, i = e.index ? e.index.array : null, s = e.attributes.position;
1747
- let o, r, a, c, d = 0;
1748
- const f = n._roots;
1749
- for (let u = 0, p = f.length; u < p; u++)
1750
- o = f[u], r = new Uint32Array(o), a = new Uint16Array(o), c = new Float32Array(o), l(0, d), d += o.byteLength;
1751
- function l(u, p, S = !1) {
1752
- const P = u * 2;
1753
- if (V(P, a)) {
1754
- const _ = Y(u, r), I = X(P, a);
1755
- let m = 1 / 0, g = 1 / 0, y = 1 / 0, w = -1 / 0, E = -1 / 0, h = -1 / 0;
1756
- for (let A = 3 * _, B = 3 * (_ + I); A < B; A++) {
1757
- let b = i[A];
1758
- const T = s.getX(b), x = s.getY(b), M = s.getZ(b);
1759
- T < m && (m = T), T > w && (w = T), x < g && (g = x), x > E && (E = x), M < y && (y = M), M > h && (h = M);
1760
- }
1761
- return c[u + 0] !== m || c[u + 1] !== g || c[u + 2] !== y || c[u + 3] !== w || c[u + 4] !== E || c[u + 5] !== h ? (c[u + 0] = m, c[u + 1] = g, c[u + 2] = y, c[u + 3] = w, c[u + 4] = E, c[u + 5] = h, !0) : !1;
1762
- } else {
1763
- const _ = $(u), I = k(u, r);
1764
- let m = S, g = !1, y = !1;
1765
- if (t) {
1766
- if (!m) {
1767
- const b = _ / z + p / W, T = I / z + p / W;
1768
- g = t.has(b), y = t.has(T), m = !g && !y;
1769
- }
1770
- } else
1771
- g = !0, y = !0;
1772
- const w = m || g, E = m || y;
1773
- let h = !1;
1774
- w && (h = l(_, p, m));
1775
- let A = !1;
1776
- E && (A = l(I, p, m));
1777
- const B = h || A;
1778
- if (B)
1779
- for (let b = 0; b < 3; b++) {
1780
- const T = _ + b, x = I + b, M = c[T], v = c[T + 3], N = c[x], L = c[x + 3];
1781
- c[u + b] = M < N ? M : N, c[u + b + 3] = v > L ? v : L;
1782
- }
1783
- return B;
1784
- }
1785
- }
1786
- }
1787
- function yt(n, t, e, i, s) {
1788
- let o, r, a, c, d, f;
1789
- const l = 1 / e.direction.x, u = 1 / e.direction.y, p = 1 / e.direction.z, S = e.origin.x, P = e.origin.y, _ = e.origin.z;
1790
- let I = t[n], m = t[n + 3], g = t[n + 1], y = t[n + 3 + 1], w = t[n + 2], E = t[n + 3 + 2];
1791
- return l >= 0 ? (o = (I - S) * l, r = (m - S) * l) : (o = (m - S) * l, r = (I - S) * l), u >= 0 ? (a = (g - P) * u, c = (y - P) * u) : (a = (y - P) * u, c = (g - P) * u), o > c || a > r || ((a > o || isNaN(o)) && (o = a), (c < r || isNaN(r)) && (r = c), p >= 0 ? (d = (w - _) * p, f = (E - _) * p) : (d = (E - _) * p, f = (w - _) * p), o > f || d > r) ? !1 : ((d > o || o !== o) && (o = d), (f < r || r !== r) && (r = f), o <= s && r >= i);
1792
- }
1793
- function Ci(n, t, e, i, s, o, r, a) {
1794
- const { geometry: c, _indirectBuffer: d } = n;
1795
- for (let f = i, l = i + s; f < l; f++) {
1796
- let u = d ? d[f] : f;
1797
- ye(c, t, e, u, o, r, a);
1798
- }
1799
- }
1800
- function Oi(n, t, e, i, s, o, r) {
1801
- const { geometry: a, _indirectBuffer: c } = n;
1802
- let d = 1 / 0, f = null;
1803
- for (let l = i, u = i + s; l < u; l++) {
1804
- let p;
1805
- p = ye(a, t, e, c ? c[l] : l, null, o, r), p && p.distance < d && (f = p, d = p.distance);
1806
- }
1807
- return f;
1808
- }
1809
- function Fi(n, t, e, i, s, o, r) {
1810
- const { geometry: a } = e, { index: c } = a, d = a.attributes.position;
1811
- for (let f = n, l = t + n; f < l; f++) {
1812
- let u;
1813
- if (u = e.resolveTriangleIndex(f), F(r, u * 3, c, d), r.needsUpdate = !0, i(r, u, s, o))
1814
- return !0;
1815
- }
1816
- return !1;
1817
- }
1818
- function zi(n, t, e, i, s, o, r) {
1819
- D.setBuffer(n._roots[t]), Re(0, n, e, i, s, o, r), D.clearBuffer();
1820
- }
1821
- function Re(n, t, e, i, s, o, r) {
1822
- const { float32Array: a, uint16Array: c, uint32Array: d } = D, f = n * 2;
1823
- if (V(f, c)) {
1824
- const u = Y(n, d), p = X(f, c);
1825
- Ui(t, e, i, u, p, s, o, r);
1826
- } else {
1827
- const u = $(n);
1828
- yt(u, a, i, o, r) && Re(u, t, e, i, s, o, r);
1829
- const p = k(n, d);
1830
- yt(p, a, i, o, r) && Re(p, t, e, i, s, o, r);
1831
- }
1832
- }
1833
- const Vi = ["x", "y", "z"];
1834
- function ji(n, t, e, i, s, o) {
1835
- D.setBuffer(n._roots[t]);
1836
- const r = De(0, n, e, i, s, o);
1837
- return D.clearBuffer(), r;
1838
- }
1839
- function De(n, t, e, i, s, o) {
1840
- const { float32Array: r, uint16Array: a, uint32Array: c } = D;
1841
- let d = n * 2;
1842
- if (V(d, a)) {
1843
- const l = Y(n, c), u = X(d, a);
1844
- return Li(t, e, i, l, u, s, o);
1845
- } else {
1846
- const l = $e(n, c), u = Vi[l], S = i.direction[u] >= 0;
1847
- let P, _;
1848
- S ? (P = $(n), _ = k(n, c)) : (P = k(n, c), _ = $(n));
1849
- const m = yt(P, r, i, s, o) ? De(P, t, e, i, s, o) : null;
1850
- if (m) {
1851
- const w = m.point[u];
1852
- if (S ? w <= r[_ + l] : (
1853
- // min bounding data
1854
- w >= r[_ + l + 3]
1855
- ))
1856
- return m;
1857
- }
1858
- const y = yt(_, r, i, s, o) ? De(_, t, e, i, s, o) : null;
1859
- return m && y ? m.distance <= y.distance ? m : y : m || y || null;
1860
- }
1861
- }
1862
- const ee = /* @__PURE__ */ new st(), Bt = /* @__PURE__ */ new it(), Tt = /* @__PURE__ */ new it(), Ot = /* @__PURE__ */ new mt(), an = /* @__PURE__ */ new G(), ne = /* @__PURE__ */ new G();
1863
- function $i(n, t, e, i) {
1864
- D.setBuffer(n._roots[t]);
1865
- const s = Ce(0, n, e, i);
1866
- return D.clearBuffer(), s;
1867
- }
1868
- function Ce(n, t, e, i, s = null) {
1869
- const { float32Array: o, uint16Array: r, uint32Array: a } = D;
1870
- let c = n * 2;
1871
- if (s === null && (e.boundingBox || e.computeBoundingBox(), an.set(e.boundingBox.min, e.boundingBox.max, i), s = an), V(c, r)) {
1872
- const f = t.geometry, l = f.index, u = f.attributes.position, p = e.index, S = e.attributes.position, P = Y(n, a), _ = X(c, r);
1873
- if (Ot.copy(i).invert(), e.boundsTree)
1874
- return O(n, o, ne), ne.matrix.copy(Ot), ne.needsUpdate = !0, e.boundsTree.shapecast({
1875
- intersectsBounds: (m) => ne.intersectsBox(m),
1876
- intersectsTriangle: (m) => {
1877
- m.a.applyMatrix4(i), m.b.applyMatrix4(i), m.c.applyMatrix4(i), m.needsUpdate = !0;
1878
- for (let g = P * 3, y = (_ + P) * 3; g < y; g += 3)
1879
- if (F(Tt, g, l, u), Tt.needsUpdate = !0, m.intersectsTriangle(Tt))
1880
- return !0;
1881
- return !1;
1882
- }
1883
- });
1884
- {
1885
- const I = he(e);
1886
- for (let m = P * 3, g = (_ + P) * 3; m < g; m += 3) {
1887
- F(Bt, m, l, u), Bt.a.applyMatrix4(Ot), Bt.b.applyMatrix4(Ot), Bt.c.applyMatrix4(Ot), Bt.needsUpdate = !0;
1888
- for (let y = 0, w = I * 3; y < w; y += 3)
1889
- if (F(Tt, y, p, S), Tt.needsUpdate = !0, Bt.intersectsTriangle(Tt))
1890
- return !0;
1891
- }
1892
- }
1893
- } else {
1894
- const f = $(n), l = k(n, a);
1895
- return O(f, o, ee), !!(s.intersectsBox(ee) && Ce(f, t, e, i, s) || (O(l, o, ee), s.intersectsBox(ee) && Ce(l, t, e, i, s)));
1896
- }
1897
- }
1898
- const ie = /* @__PURE__ */ new mt(), Pe = /* @__PURE__ */ new G(), Ft = /* @__PURE__ */ new G(), ki = /* @__PURE__ */ new U(), qi = /* @__PURE__ */ new U(), Ji = /* @__PURE__ */ new U(), Hi = /* @__PURE__ */ new U();
1899
- function Wi(n, t, e, i = {}, s = {}, o = 0, r = 1 / 0) {
1900
- t.boundingBox || t.computeBoundingBox(), Pe.set(t.boundingBox.min, t.boundingBox.max, e), Pe.needsUpdate = !0;
1901
- const a = n.geometry, c = a.attributes.position, d = a.index, f = t.attributes.position, l = t.index, u = tt.getPrimitive(), p = tt.getPrimitive();
1902
- let S = ki, P = qi, _ = null, I = null;
1903
- s && (_ = Ji, I = Hi);
1904
- let m = 1 / 0, g = null, y = null;
1905
- return ie.copy(e).invert(), Ft.matrix.copy(ie), n.shapecast(
1906
- {
1907
- boundsTraverseOrder: (w) => Pe.distanceToBox(w),
1908
- intersectsBounds: (w, E, h) => h < m && h < r ? (E && (Ft.min.copy(w.min), Ft.max.copy(w.max), Ft.needsUpdate = !0), !0) : !1,
1909
- intersectsRange: (w, E) => {
1910
- if (t.boundsTree)
1911
- return t.boundsTree.shapecast({
1912
- boundsTraverseOrder: (A) => Ft.distanceToBox(A),
1913
- intersectsBounds: (A, B, b) => b < m && b < r,
1914
- intersectsRange: (A, B) => {
1915
- for (let b = A, T = A + B; b < T; b++) {
1916
- F(p, 3 * b, l, f), p.a.applyMatrix4(e), p.b.applyMatrix4(e), p.c.applyMatrix4(e), p.needsUpdate = !0;
1917
- for (let x = w, M = w + E; x < M; x++) {
1918
- F(u, 3 * x, d, c), u.needsUpdate = !0;
1919
- const v = u.distanceToTriangle(p, S, _);
1920
- if (v < m && (P.copy(S), I && I.copy(_), m = v, g = x, y = b), v < o)
1921
- return !0;
1922
- }
1923
- }
1924
- }
1925
- });
1926
- {
1927
- const h = he(t);
1928
- for (let A = 0, B = h; A < B; A++) {
1929
- F(p, 3 * A, l, f), p.a.applyMatrix4(e), p.b.applyMatrix4(e), p.c.applyMatrix4(e), p.needsUpdate = !0;
1930
- for (let b = w, T = w + E; b < T; b++) {
1931
- F(u, 3 * b, d, c), u.needsUpdate = !0;
1932
- const x = u.distanceToTriangle(p, S, _);
1933
- if (x < m && (P.copy(S), I && I.copy(_), m = x, g = b, y = A), x < o)
1934
- return !0;
1935
- }
1936
- }
1937
- }
1938
- }
1939
- }
1940
- ), tt.releasePrimitive(u), tt.releasePrimitive(p), m === 1 / 0 ? null : (i.point ? i.point.copy(P) : i.point = P.clone(), i.distance = m, i.faceIndex = g, s && (s.point ? s.point.copy(I) : s.point = I.clone(), s.point.applyMatrix4(ie), P.applyMatrix4(ie), s.distance = P.sub(s.point).length(), s.faceIndex = y), i);
1941
- }
1942
- function Yi(n, t = null) {
1943
- t && Array.isArray(t) && (t = new Set(t));
1944
- const e = n.geometry, i = e.index ? e.index.array : null, s = e.attributes.position;
1945
- let o, r, a, c, d = 0;
1946
- const f = n._roots;
1947
- for (let u = 0, p = f.length; u < p; u++)
1948
- o = f[u], r = new Uint32Array(o), a = new Uint16Array(o), c = new Float32Array(o), l(0, d), d += o.byteLength;
1949
- function l(u, p, S = !1) {
1950
- const P = u * 2;
1951
- if (V(P, a)) {
1952
- const _ = Y(u, r), I = X(P, a);
1953
- let m = 1 / 0, g = 1 / 0, y = 1 / 0, w = -1 / 0, E = -1 / 0, h = -1 / 0;
1954
- for (let A = _, B = _ + I; A < B; A++) {
1955
- const b = 3 * n.resolveTriangleIndex(A);
1956
- for (let T = 0; T < 3; T++) {
1957
- let x = b + T;
1958
- x = i ? i[x] : x;
1959
- const M = s.getX(x), v = s.getY(x), N = s.getZ(x);
1960
- M < m && (m = M), M > w && (w = M), v < g && (g = v), v > E && (E = v), N < y && (y = N), N > h && (h = N);
1961
- }
1962
- }
1963
- return c[u + 0] !== m || c[u + 1] !== g || c[u + 2] !== y || c[u + 3] !== w || c[u + 4] !== E || c[u + 5] !== h ? (c[u + 0] = m, c[u + 1] = g, c[u + 2] = y, c[u + 3] = w, c[u + 4] = E, c[u + 5] = h, !0) : !1;
1964
- } else {
1965
- const _ = $(u), I = k(u, r);
1966
- let m = S, g = !1, y = !1;
1967
- if (t) {
1968
- if (!m) {
1969
- const b = _ / z + p / W, T = I / z + p / W;
1970
- g = t.has(b), y = t.has(T), m = !g && !y;
1971
- }
1972
- } else
1973
- g = !0, y = !0;
1974
- const w = m || g, E = m || y;
1975
- let h = !1;
1976
- w && (h = l(_, p, m));
1977
- let A = !1;
1978
- E && (A = l(I, p, m));
1979
- const B = h || A;
1980
- if (B)
1981
- for (let b = 0; b < 3; b++) {
1982
- const T = _ + b, x = I + b, M = c[T], v = c[T + 3], N = c[x], L = c[x + 3];
1983
- c[u + b] = M < N ? M : N, c[u + b + 3] = v > L ? v : L;
1984
- }
1985
- return B;
1986
- }
1987
- }
1988
- }
1989
- function Xi(n, t, e, i, s, o, r) {
1990
- D.setBuffer(n._roots[t]), Oe(0, n, e, i, s, o, r), D.clearBuffer();
1991
- }
1992
- function Oe(n, t, e, i, s, o, r) {
1993
- const { float32Array: a, uint16Array: c, uint32Array: d } = D, f = n * 2;
1994
- if (V(f, c)) {
1995
- const u = Y(n, d), p = X(f, c);
1996
- Ci(t, e, i, u, p, s, o, r);
1997
- } else {
1998
- const u = $(n);
1999
- yt(u, a, i, o, r) && Oe(u, t, e, i, s, o, r);
2000
- const p = k(n, d);
2001
- yt(p, a, i, o, r) && Oe(p, t, e, i, s, o, r);
2002
- }
2003
- }
2004
- const Gi = ["x", "y", "z"];
2005
- function Zi(n, t, e, i, s, o) {
2006
- D.setBuffer(n._roots[t]);
2007
- const r = Fe(0, n, e, i, s, o);
2008
- return D.clearBuffer(), r;
2009
- }
2010
- function Fe(n, t, e, i, s, o) {
2011
- const { float32Array: r, uint16Array: a, uint32Array: c } = D;
2012
- let d = n * 2;
2013
- if (V(d, a)) {
2014
- const l = Y(n, c), u = X(d, a);
2015
- return Oi(t, e, i, l, u, s, o);
2016
- } else {
2017
- const l = $e(n, c), u = Gi[l], S = i.direction[u] >= 0;
2018
- let P, _;
2019
- S ? (P = $(n), _ = k(n, c)) : (P = k(n, c), _ = $(n));
2020
- const m = yt(P, r, i, s, o) ? Fe(P, t, e, i, s, o) : null;
2021
- if (m) {
2022
- const w = m.point[u];
2023
- if (S ? w <= r[_ + l] : (
2024
- // min bounding data
2025
- w >= r[_ + l + 3]
2026
- ))
2027
- return m;
2028
- }
2029
- const y = yt(_, r, i, s, o) ? Fe(_, t, e, i, s, o) : null;
2030
- return m && y ? m.distance <= y.distance ? m : y : m || y || null;
2031
- }
2032
- }
2033
- const se = /* @__PURE__ */ new st(), Pt = /* @__PURE__ */ new it(), It = /* @__PURE__ */ new it(), zt = /* @__PURE__ */ new mt(), ln = /* @__PURE__ */ new G(), re = /* @__PURE__ */ new G();
2034
- function Ki(n, t, e, i) {
2035
- D.setBuffer(n._roots[t]);
2036
- const s = ze(0, n, e, i);
2037
- return D.clearBuffer(), s;
2038
- }
2039
- function ze(n, t, e, i, s = null) {
2040
- const { float32Array: o, uint16Array: r, uint32Array: a } = D;
2041
- let c = n * 2;
2042
- if (s === null && (e.boundingBox || e.computeBoundingBox(), ln.set(e.boundingBox.min, e.boundingBox.max, i), s = ln), V(c, r)) {
2043
- const f = t.geometry, l = f.index, u = f.attributes.position, p = e.index, S = e.attributes.position, P = Y(n, a), _ = X(c, r);
2044
- if (zt.copy(i).invert(), e.boundsTree)
2045
- return O(n, o, re), re.matrix.copy(zt), re.needsUpdate = !0, e.boundsTree.shapecast({
2046
- intersectsBounds: (m) => re.intersectsBox(m),
2047
- intersectsTriangle: (m) => {
2048
- m.a.applyMatrix4(i), m.b.applyMatrix4(i), m.c.applyMatrix4(i), m.needsUpdate = !0;
2049
- for (let g = P, y = _ + P; g < y; g++)
2050
- if (F(It, 3 * t.resolveTriangleIndex(g), l, u), It.needsUpdate = !0, m.intersectsTriangle(It))
2051
- return !0;
2052
- return !1;
2053
- }
2054
- });
2055
- {
2056
- const I = he(e);
2057
- for (let m = P, g = _ + P; m < g; m++) {
2058
- const y = t.resolveTriangleIndex(m);
2059
- F(Pt, 3 * y, l, u), Pt.a.applyMatrix4(zt), Pt.b.applyMatrix4(zt), Pt.c.applyMatrix4(zt), Pt.needsUpdate = !0;
2060
- for (let w = 0, E = I * 3; w < E; w += 3)
2061
- if (F(It, w, p, S), It.needsUpdate = !0, Pt.intersectsTriangle(It))
2062
- return !0;
2063
- }
2064
- }
2065
- } else {
2066
- const f = $(n), l = k(n, a);
2067
- return O(f, o, se), !!(s.intersectsBox(se) && ze(f, t, e, i, s) || (O(l, o, se), s.intersectsBox(se) && ze(l, t, e, i, s)));
2068
- }
2069
- }
2070
- const oe = /* @__PURE__ */ new mt(), Ie = /* @__PURE__ */ new G(), Vt = /* @__PURE__ */ new G(), Qi = /* @__PURE__ */ new U(), ts = /* @__PURE__ */ new U(), es = /* @__PURE__ */ new U(), ns = /* @__PURE__ */ new U();
2071
- function is(n, t, e, i = {}, s = {}, o = 0, r = 1 / 0) {
2072
- t.boundingBox || t.computeBoundingBox(), Ie.set(t.boundingBox.min, t.boundingBox.max, e), Ie.needsUpdate = !0;
2073
- const a = n.geometry, c = a.attributes.position, d = a.index, f = t.attributes.position, l = t.index, u = tt.getPrimitive(), p = tt.getPrimitive();
2074
- let S = Qi, P = ts, _ = null, I = null;
2075
- s && (_ = es, I = ns);
2076
- let m = 1 / 0, g = null, y = null;
2077
- return oe.copy(e).invert(), Vt.matrix.copy(oe), n.shapecast(
2078
- {
2079
- boundsTraverseOrder: (w) => Ie.distanceToBox(w),
2080
- intersectsBounds: (w, E, h) => h < m && h < r ? (E && (Vt.min.copy(w.min), Vt.max.copy(w.max), Vt.needsUpdate = !0), !0) : !1,
2081
- intersectsRange: (w, E) => {
2082
- if (t.boundsTree) {
2083
- const h = t.boundsTree;
2084
- return h.shapecast({
2085
- boundsTraverseOrder: (A) => Vt.distanceToBox(A),
2086
- intersectsBounds: (A, B, b) => b < m && b < r,
2087
- intersectsRange: (A, B) => {
2088
- for (let b = A, T = A + B; b < T; b++) {
2089
- const x = h.resolveTriangleIndex(b);
2090
- F(p, 3 * x, l, f), p.a.applyMatrix4(e), p.b.applyMatrix4(e), p.c.applyMatrix4(e), p.needsUpdate = !0;
2091
- for (let M = w, v = w + E; M < v; M++) {
2092
- const N = n.resolveTriangleIndex(M);
2093
- F(u, 3 * N, d, c), u.needsUpdate = !0;
2094
- const L = u.distanceToTriangle(p, S, _);
2095
- if (L < m && (P.copy(S), I && I.copy(_), m = L, g = M, y = b), L < o)
2096
- return !0;
2097
- }
2098
- }
2099
- }
2100
- });
2101
- } else {
2102
- const h = he(t);
2103
- for (let A = 0, B = h; A < B; A++) {
2104
- F(p, 3 * A, l, f), p.a.applyMatrix4(e), p.b.applyMatrix4(e), p.c.applyMatrix4(e), p.needsUpdate = !0;
2105
- for (let b = w, T = w + E; b < T; b++) {
2106
- const x = n.resolveTriangleIndex(b);
2107
- F(u, 3 * x, d, c), u.needsUpdate = !0;
2108
- const M = u.distanceToTriangle(p, S, _);
2109
- if (M < m && (P.copy(S), I && I.copy(_), m = M, g = b, y = A), M < o)
2110
- return !0;
2111
- }
2112
- }
2113
- }
2114
- }
2115
- }
2116
- ), tt.releasePrimitive(u), tt.releasePrimitive(p), m === 1 / 0 ? null : (i.point ? i.point.copy(P) : i.point = P.clone(), i.distance = m, i.faceIndex = g, s && (s.point ? s.point.copy(I) : s.point = I.clone(), s.point.applyMatrix4(oe), P.applyMatrix4(oe), s.distance = P.sub(s.point).length(), s.faceIndex = y), i);
2117
- }
2118
- function un(n, t, e) {
2119
- return n === null ? null : (n.point.applyMatrix4(t.matrixWorld), n.distance = n.point.distanceTo(e.ray.origin), n.object = t, n);
2120
- }
2121
- const ce = /* @__PURE__ */ new G(), ae = /* @__PURE__ */ new zn(), fn = /* @__PURE__ */ new U(), dn = /* @__PURE__ */ new mt(), pn = /* @__PURE__ */ new U(), Ee = ["getX", "getY", "getZ"];
2122
- class me extends Bi {
2123
- static serialize(t, e = {}) {
2124
- e = {
2125
- cloneBuffers: !0,
2126
- ...e
2127
- };
2128
- const i = t.geometry, s = t._roots, o = t._indirectBuffer, r = i.getIndex(), a = {
2129
- version: 1,
2130
- roots: null,
2131
- index: null,
2132
- indirectBuffer: null
2133
- };
2134
- return e.cloneBuffers ? (a.roots = s.map((c) => c.slice()), a.index = r ? r.array.slice() : null, a.indirectBuffer = o ? o.slice() : null) : (a.roots = s, a.index = r ? r.array : null, a.indirectBuffer = o), a;
2135
- }
2136
- static deserialize(t, e, i = {}) {
2137
- i = {
2138
- setIndex: !0,
2139
- indirect: !!t.indirectBuffer,
2140
- ...i
2141
- };
2142
- const { index: s, roots: o, indirectBuffer: r } = t;
2143
- t.version || (console.warn(
2144
- "MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."
2145
- ), c(o));
2146
- const a = new me(e, { ...i, [je]: !0 });
2147
- if (a._roots = o, a._indirectBuffer = r || null, i.setIndex) {
2148
- const d = e.getIndex();
2149
- if (d === null) {
2150
- const f = new bn(t.index, 1, !1);
2151
- e.setIndex(f);
2152
- } else d.array !== s && (d.array.set(s), d.needsUpdate = !0);
2153
- }
2154
- return a;
2155
- function c(d) {
2156
- for (let f = 0; f < d.length; f++) {
2157
- const l = d[f], u = new Uint32Array(l), p = new Uint16Array(l);
2158
- for (let S = 0, P = l.byteLength / W; S < P; S++) {
2159
- const _ = z * S, I = 2 * _;
2160
- V(I, p) || (u[_ + 6] = u[_ + 6] / z - S);
2161
- }
2162
- }
2163
- }
2164
- }
2165
- get primitiveStride() {
2166
- return 3;
2167
- }
2168
- get resolveTriangleIndex() {
2169
- return this.resolvePrimitiveIndex;
2170
- }
2171
- constructor(t, e = {}) {
2172
- e.maxLeafTris && (console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'), e = {
2173
- ...e,
2174
- maxLeafSize: e.maxLeafTris
2175
- }), super(t, e);
2176
- }
2177
- // implement abstract methods from BVH base class
2178
- shiftTriangleOffsets(t) {
2179
- return super.shiftPrimitiveOffsets(t);
2180
- }
2181
- // write primitive bounds to the buffer - used only for validateBounds at the moment
2182
- writePrimitiveBounds(t, e, i) {
2183
- const s = this.geometry, o = this._indirectBuffer, r = s.attributes.position, a = s.index ? s.index.array : null, d = (o ? o[t] : t) * 3;
2184
- let f = d + 0, l = d + 1, u = d + 2;
2185
- a && (f = a[f], l = a[l], u = a[u]);
2186
- for (let p = 0; p < 3; p++) {
2187
- const S = r[Ee[p]](f), P = r[Ee[p]](l), _ = r[Ee[p]](u);
2188
- let I = S;
2189
- P < I && (I = P), _ < I && (I = _);
2190
- let m = S;
2191
- P > m && (m = P), _ > m && (m = _), e[i + p] = I, e[i + p + 3] = m;
2192
- }
2193
- return e;
2194
- }
2195
- // precomputes the bounding box for each triangle; required for quickly calculating tree splits.
2196
- // result is an array of size count * 6 where triangle i maps to a
2197
- // [x_center, x_delta, y_center, y_delta, z_center, z_delta] tuple starting at index (i - offset) * 6,
2198
- // representing the center and half-extent in each dimension of triangle i
2199
- computePrimitiveBounds(t, e, i) {
2200
- const s = this.geometry, o = this._indirectBuffer, r = s.attributes.position, a = s.index ? s.index.array : null, c = r.normalized;
2201
- if (t < 0 || e + t - i.offset > i.length / 6)
2202
- throw new Error("MeshBVH: compute triangle bounds range is invalid.");
2203
- const d = r.array, f = r.offset || 0;
2204
- let l = 3;
2205
- r.isInterleavedBufferAttribute && (l = r.data.stride);
2206
- const u = ["getX", "getY", "getZ"], p = i.offset;
2207
- for (let S = t, P = t + e; S < P; S++) {
2208
- const I = (o ? o[S] : S) * 3, m = (S - p) * 6;
2209
- let g = I + 0, y = I + 1, w = I + 2;
2210
- a && (g = a[g], y = a[y], w = a[w]), c || (g = g * l + f, y = y * l + f, w = w * l + f);
2211
- for (let E = 0; E < 3; E++) {
2212
- let h, A, B;
2213
- c ? (h = r[u[E]](g), A = r[u[E]](y), B = r[u[E]](w)) : (h = d[g + E], A = d[y + E], B = d[w + E]);
2214
- let b = h;
2215
- A < b && (b = A), B < b && (b = B);
2216
- let T = h;
2217
- A > T && (T = A), B > T && (T = B);
2218
- const x = (T - b) / 2, M = E * 2;
2219
- i[m + M + 0] = b + x, i[m + M + 1] = x + (Math.abs(b) + x) * fe;
2220
- }
2221
- }
2222
- return i;
2223
- }
2224
- raycastObject3D(t, e, i = []) {
2225
- const { material: s } = t;
2226
- if (s === void 0)
2227
- return;
2228
- dn.copy(t.matrixWorld).invert(), ae.copy(e.ray).applyMatrix4(dn), pn.setFromMatrixScale(t.matrixWorld), fn.copy(ae.direction).multiply(pn);
2229
- const o = fn.length(), r = e.near / o, a = e.far / o;
2230
- if (e.firstHitOnly === !0) {
2231
- let c = this.raycastFirst(ae, s, r, a);
2232
- c = un(c, t, e), c && i.push(c);
2233
- } else {
2234
- const c = this.raycast(ae, s, r, a);
2235
- for (let d = 0, f = c.length; d < f; d++) {
2236
- const l = un(c[d], t, e);
2237
- l && i.push(l);
2238
- }
2239
- }
2240
- return i;
2241
- }
2242
- refit(t = null) {
2243
- return (this.indirect ? Yi : Di)(this, t);
2244
- }
2245
- /* Core Cast Functions */
2246
- raycast(t, e = He, i = 0, s = 1 / 0) {
2247
- const o = this._roots, r = [], a = this.indirect ? Xi : zi;
2248
- for (let c = 0, d = o.length; c < d; c++)
2249
- a(this, c, e, t, r, i, s);
2250
- return r;
2251
- }
2252
- raycastFirst(t, e = He, i = 0, s = 1 / 0) {
2253
- const o = this._roots;
2254
- let r = null;
2255
- const a = this.indirect ? Zi : ji;
2256
- for (let c = 0, d = o.length; c < d; c++) {
2257
- const f = a(this, c, e, t, i, s);
2258
- f != null && (r == null || f.distance < r.distance) && (r = f);
2259
- }
2260
- return r;
2261
- }
2262
- intersectsGeometry(t, e) {
2263
- let i = !1;
2264
- const s = this._roots, o = this.indirect ? Ki : $i;
2265
- for (let r = 0, a = s.length; r < a && (i = o(this, r, t, e), !i); r++)
2266
- ;
2267
- return i;
2268
- }
2269
- shapecast(t) {
2270
- const e = tt.getPrimitive(), i = super.shapecast(
2271
- {
2272
- ...t,
2273
- intersectsPrimitive: t.intersectsTriangle,
2274
- scratchPrimitive: e,
2275
- // TODO: is the performance significant enough for the added complexity here?
2276
- // can we just use one function?
2277
- iterate: this.indirect ? Fi : Ri
2278
- }
2279
- );
2280
- return tt.releasePrimitive(e), i;
2281
- }
2282
- bvhcast(t, e, i) {
2283
- let {
2284
- intersectsRanges: s,
2285
- intersectsTriangles: o
2286
- } = i;
2287
- const r = tt.getPrimitive(), a = this.geometry.index, c = this.geometry.attributes.position, d = this.indirect ? (S) => {
2288
- const P = this.resolveTriangleIndex(S);
2289
- F(r, P * 3, a, c);
2290
- } : (S) => {
2291
- F(r, S * 3, a, c);
2292
- }, f = tt.getPrimitive(), l = t.geometry.index, u = t.geometry.attributes.position, p = t.indirect ? (S) => {
2293
- const P = t.resolveTriangleIndex(S);
2294
- F(f, P * 3, l, u);
2295
- } : (S) => {
2296
- F(f, S * 3, l, u);
2297
- };
2298
- if (o) {
2299
- if (!(t instanceof me))
2300
- throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');
2301
- const S = (P, _, I, m, g, y, w, E) => {
2302
- for (let h = I, A = I + m; h < A; h++) {
2303
- p(h), f.a.applyMatrix4(e), f.b.applyMatrix4(e), f.c.applyMatrix4(e), f.needsUpdate = !0;
2304
- for (let B = P, b = P + _; B < b; B++)
2305
- if (d(B), r.needsUpdate = !0, o(r, f, B, h, g, y, w, E))
2306
- return !0;
2307
- }
2308
- return !1;
2309
- };
2310
- if (s) {
2311
- const P = s;
2312
- s = function(_, I, m, g, y, w, E, h) {
2313
- return P(_, I, m, g, y, w, E, h) ? !0 : S(_, I, m, g, y, w, E, h);
2314
- };
2315
- } else
2316
- s = S;
2317
- }
2318
- return super.bvhcast(t, e, { intersectsRanges: s });
2319
- }
2320
- /* Derived Cast Functions */
2321
- intersectsBox(t, e) {
2322
- return ce.set(t.min, t.max, e), ce.needsUpdate = !0, this.shapecast(
2323
- {
2324
- intersectsBounds: (i) => ce.intersectsBox(i),
2325
- intersectsTriangle: (i) => ce.intersectsTriangle(i)
2326
- }
2327
- );
2328
- }
2329
- intersectsSphere(t) {
2330
- return this.shapecast(
2331
- {
2332
- intersectsBounds: (e) => t.intersectsBox(e),
2333
- intersectsTriangle: (e) => e.intersectsSphere(t)
2334
- }
2335
- );
2336
- }
2337
- closestPointToGeometry(t, e, i = {}, s = {}, o = 0, r = 1 / 0) {
2338
- return (this.indirect ? is : Wi)(
2339
- this,
2340
- t,
2341
- e,
2342
- i,
2343
- s,
2344
- o,
2345
- r
2346
- );
2347
- }
2348
- closestPointToPoint(t, e = {}, i = 0, s = 1 / 0) {
2349
- return Mi(
2350
- this,
2351
- t,
2352
- e,
2353
- i,
2354
- s
2355
- );
2356
- }
2357
- }
2358
- const Mt = {
2359
- Mesh: $t.prototype.raycast,
2360
- Line: Tn.prototype.raycast,
2361
- LineSegments: Ve.prototype.raycast,
2362
- LineLoop: Bn.prototype.raycast,
2363
- Points: Pn.prototype.raycast,
2364
- BatchedMesh: jn.prototype.raycast
2365
- }, J = /* @__PURE__ */ new $t(), le = [];
2366
- function mn(n, t) {
2367
- if (this.isBatchedMesh)
2368
- ss.call(this, n, t);
2369
- else {
2370
- const { geometry: e } = this;
2371
- if (e.boundsTree)
2372
- e.boundsTree.raycastObject3D(this, n, t);
2373
- else {
2374
- let i;
2375
- if (this instanceof $t)
2376
- i = Mt.Mesh;
2377
- else if (this instanceof Ve)
2378
- i = Mt.LineSegments;
2379
- else if (this instanceof Bn)
2380
- i = Mt.LineLoop;
2381
- else if (this instanceof Tn)
2382
- i = Mt.Line;
2383
- else if (this instanceof Pn)
2384
- i = Mt.Points;
2385
- else
2386
- throw new Error("BVH: Fallback raycast function not found.");
2387
- i.call(this, n, t);
2388
- }
2389
- }
2390
- }
2391
- function ss(n, t) {
2392
- if (this.boundsTrees) {
2393
- const e = this.boundsTrees, i = this._drawInfo || this._instanceInfo, s = this._drawRanges || this._geometryInfo, o = this.matrixWorld;
2394
- J.material = this.material, J.geometry = this.geometry;
2395
- const r = J.geometry.boundsTree, a = J.geometry.drawRange;
2396
- J.geometry.boundingSphere === null && (J.geometry.boundingSphere = new Vn());
2397
- for (let c = 0, d = i.length; c < d; c++) {
2398
- if (!this.getVisibleAt(c))
2399
- continue;
2400
- const f = i[c].geometryIndex;
2401
- if (J.geometry.boundsTree = e[f], this.getMatrixAt(c, J.matrixWorld).premultiply(o), !J.geometry.boundsTree) {
2402
- this.getBoundingBoxAt(f, J.geometry.boundingBox), this.getBoundingSphereAt(f, J.geometry.boundingSphere);
2403
- const l = s[f];
2404
- J.geometry.setDrawRange(l.start, l.count);
2405
- }
2406
- J.raycast(n, le);
2407
- for (let l = 0, u = le.length; l < u; l++) {
2408
- const p = le[l];
2409
- p.object = this, p.batchId = c, t.push(p);
2410
- }
2411
- le.length = 0;
2412
- }
2413
- J.geometry.boundsTree = r, J.geometry.drawRange = a, J.material = null, J.geometry = null;
2414
- } else
2415
- Mt.BatchedMesh.call(this, n, t);
2416
- }
2417
- const rs = { dispose() {
2418
- } };
2419
- function os(n) {
2420
- const t = [], e = /* @__PURE__ */ new Set();
2421
- for (const s of n)
2422
- s.traverse((o) => {
2423
- if (!(o instanceof $t) || e.has(o) || (e.add(o), !cs(o))) return;
2424
- const r = o.geometry;
2425
- let a = r.boundsTree, c = !1;
2426
- if (!a) {
2427
- try {
2428
- a = new me(r, { maxLeafSize: 20, indirect: !0, verbose: !1 });
2429
- } catch {
2430
- return;
2431
- }
2432
- r.boundsTree = a, c = !0;
2433
- }
2434
- o.raycast !== mn && (t.push({
2435
- mesh: o,
2436
- originalRaycast: o.raycast,
2437
- tree: a,
2438
- ownsTree: c
2439
- }), o.raycast = mn);
2440
- });
2441
- if (t.length === 0) return rs;
2442
- let i = !1;
2443
- return {
2444
- dispose() {
2445
- if (!i) {
2446
- i = !0;
2447
- for (const s of t) {
2448
- s.mesh.raycast = s.originalRaycast;
2449
- const o = s.mesh.geometry;
2450
- s.ownsTree && o.boundsTree === s.tree && delete o.boundsTree;
2451
- }
2452
- t.length = 0;
2453
- }
2454
- }
2455
- };
2456
- }
2457
- function cs(n) {
2458
- return n.isSkinnedMesh || n.isInstancedMesh || n.isBatchedMesh ? !1 : !Object.values(n.geometry.morphAttributes).some((t) => t.length > 0);
2459
- }
2460
- class Us {
2461
- constructor(t, e, i = {}) {
2462
- Z(this, "root");
2463
- Z(this, "bodies", /* @__PURE__ */ new Map());
2464
- Z(this, "links", /* @__PURE__ */ new Map());
2465
- Z(this, "raycastAcceleration");
2466
- Z(this, "disposed", !1);
2467
- this.runtime = t, this.root = e.root, this.raycastAcceleration = i.accelerateRaycast === !1 ? null : os([this.root]);
2468
- const s = t.mujoco, o = t.model;
2469
- for (const [r, a] of e.bindings) {
2470
- const c = s.mj_name2id(o, s.mjtObj.mjOBJ_BODY.value, r);
2471
- if (c < 0) throw hn(`Physics body missing for visual link: ${r}`, "E_SIMULATION_BIND");
2472
- this.links.set(r, a), a.userData.bodyId = c, this.bodies.set(c, a);
2473
- }
2474
- if (this.bodies.size !== e.expectedLinkCount) throw hn("Visual body binding count mismatch.", "E_SIMULATION_BIND");
2475
- this.sync();
2476
- }
2477
- objectForLink(t) {
2478
- return this.links.get(t) ?? null;
2479
- }
2480
- bodyPoses() {
2481
- return new Map([...this.bodies.values()].map((t) => [t.name, { position: t.position.clone(), quaternion: t.quaternion.clone() }]));
2482
- }
2483
- sync() {
2484
- if (this.disposed || !this.runtime.data) return;
2485
- const { xpos: t, xquat: e } = this.runtime.data;
2486
- for (const [i, s] of this.bodies) {
2487
- const o = i * 3, r = i * 4;
2488
- s.position.set(t[o], t[o + 1], t[o + 2]), s.quaternion.set(e[r + 1], e[r + 2], e[r + 3], e[r]);
2489
- }
2490
- this.root.updateMatrixWorld(!0);
2491
- }
2492
- dispose() {
2493
- var t;
2494
- this.disposed || (this.disposed = !0, this.bodies.clear(), this.links.clear(), (t = this.raycastAcceleration) == null || t.dispose(), Jn(this.root));
2495
- }
2496
- }
2497
- function hn(n, t) {
2498
- return Object.assign(new Error(n), { code: t });
2499
- }
2500
- const as = /<UDIM>/i;
2501
- function ls(n, t) {
2502
- const e = yn(n).replaceAll("\\", "/");
2503
- if (!as.test(e)) return null;
2504
- const i = gn(e), s = i.split("/").at(-1);
2505
- if (!s) return { paths: [], tiles: [] };
2506
- const o = fs(s);
2507
- if (!o) return { paths: [], tiles: [] };
2508
- const r = [];
2509
- for (const d of new Set(t)) {
2510
- const f = yn(d).replaceAll("\\", "/"), l = gn(f), u = l.split("/").at(-1);
2511
- if (!u) continue;
2512
- const p = o.exec(u);
2513
- if (!p) continue;
2514
- const S = Number(p[1]);
2515
- !Number.isInteger(S) || S < 1001 || S > 9999 || r.push({
2516
- path: d,
2517
- tile: S,
2518
- score: ds(i, l)
2519
- });
2520
- }
2521
- if (!r.length) return { paths: [], tiles: [] };
2522
- const a = Math.max(...r.map((d) => d.score)), c = r.filter((d) => d.score === a).sort((d, f) => d.tile - f.tile || d.path.localeCompare(f.path));
2523
- return {
2524
- paths: c.map((d) => d.path),
2525
- tiles: c.map((d) => d.tile)
2526
- };
2527
- }
2528
- function Ls(n) {
2529
- if (!n.tiles.length) return null;
2530
- const t = n.tiles.map(us), e = Math.min(...t.map(({ column: r }) => r)), i = Math.max(...t.map(({ column: r }) => r)), s = Math.min(...t.map(({ row: r }) => r)), o = Math.max(...t.map(({ row: r }) => r));
2531
- return {
2532
- minColumn: e,
2533
- maxColumn: i,
2534
- minRow: s,
2535
- maxRow: o,
2536
- columns: i - e + 1,
2537
- rows: o - s + 1
2538
- };
2539
- }
2540
- function us(n) {
2541
- const t = n - 1001;
2542
- return {
2543
- column: (t % 10 + 10) % 10,
2544
- row: Math.floor(t / 10)
2545
- };
2546
- }
2547
- function fs(n) {
2548
- const t = n.split(/<UDIM>/i);
2549
- return t.length !== 2 ? null : new RegExp(`^${wn(t[0])}(\\d{4})${wn(t[1])}$`, "i");
2550
- }
2551
- function ds(n, t) {
2552
- const e = n.split("/").slice(0, -1).filter(Boolean), i = t.split("/").slice(0, -1).filter(Boolean);
2553
- let s = 0;
2554
- for (; s < e.length && s < i.length; ) {
2555
- const o = e.at(-1 - s), r = i.at(-1 - s);
2556
- if ((o == null ? void 0 : o.toLowerCase()) !== (r == null ? void 0 : r.toLowerCase())) break;
2557
- s += 1;
2558
- }
2559
- return s;
2560
- }
2561
- function yn(n) {
2562
- const t = n.replace(/%3CUDIM%3E/gi, "<UDIM>");
2563
- try {
2564
- return decodeURIComponent(t);
2565
- } catch {
2566
- return t;
2567
- }
2568
- }
2569
- function gn(n) {
2570
- const t = n.search(/[?#]/);
2571
- return t < 0 ? n : n.slice(0, t);
2572
- }
2573
- function wn(n) {
2574
- return n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2575
- }
2576
- class Rs {
2577
- constructor(t) {
2578
- Z(this, "entries", /* @__PURE__ */ new Map());
2579
- Z(this, "manifestPaths", /* @__PURE__ */ new Set());
2580
- Z(this, "objectUrls", /* @__PURE__ */ new Map());
2581
- Z(this, "objectUrlPaths", /* @__PURE__ */ new Map());
2582
- /**
2583
- * Reads that already failed, so a missing resource is not requested again by
2584
- * the visual adapter after the reference prefetch has recorded it.
2585
- */
2586
- Z(this, "failures", /* @__PURE__ */ new Map());
2587
- Z(this, "pending", /* @__PURE__ */ new Map());
2588
- Z(this, "disposed", !1);
2589
- this.source = t;
2590
- for (const i of t.resourcePaths ?? []) {
2591
- const s = H(i);
2592
- s && this.manifestPaths.add(s);
2593
- }
2594
- const e = t.original;
2595
- if (ys(e))
2596
- for (const i of e.files) this.entries.set(H(i.path), i.file);
2597
- else typeof Blob < "u" && e instanceof Blob ? this.entries.set(t.entryPath ?? t.filename ?? "asset", e) : e instanceof ArrayBuffer ? this.entries.set(t.entryPath ?? t.filename ?? "asset", new Blob([e])) : typeof e == "object" && e !== null && "kind" in e && e.kind === "buffer" && this.entries.set(t.entryPath ?? t.filename ?? "asset", new Blob([e.buffer]));
2598
- }
2599
- paths() {
2600
- return [.../* @__PURE__ */ new Set([...this.entries.keys(), ...this.manifestPaths])];
2601
- }
2602
- hasLocalFiles() {
2603
- return this.entries.size > 0;
2604
- }
2605
- put(t, e) {
2606
- const i = H(t);
2607
- this.entries.set(i, e), this.manifestPaths.add(i);
2608
- }
2609
- hasBlob(t) {
2610
- const e = this.find(t);
2611
- return e !== null && this.entries.has(e);
2612
- }
2613
- relativePaths(t = "", e = !1) {
2614
- return [...this.relativeEntries(t, e)].map(([i]) => i);
2615
- }
2616
- asSourceRecord(t = "", e = !1) {
2617
- return Object.fromEntries(this.relativeEntries(t, e));
2618
- }
2619
- *relativeEntries(t = "", e = !1) {
2620
- const i = H(t), s = i ? `${i}/` : "";
2621
- for (const [o, r] of this.entries)
2622
- if (!s || o.startsWith(s)) yield [s ? o.slice(s.length) : o, r];
2623
- else if (e) {
2624
- const a = i.split("/"), c = o.split("/");
2625
- let d = 0;
2626
- for (; d < a.length && a[d] === c[d]; ) d++;
2627
- yield [[...a.slice(d).map(() => ".."), ...c.slice(d)].join("/"), r];
2628
- }
2629
- }
2630
- resolve(t, e = "") {
2631
- const i = this.find(t, e);
2632
- if (i) return i;
2633
- const s = H(e).split("/").slice(0, -1).join("/");
2634
- if (this.source.url) return H(`${s}/${t.replace(/^package:\/\//, "")}`);
2635
- throw ft(`Simulation resource not found: ${t}`, "E_ASSET_RESOURCE_NOT_FOUND");
2636
- }
2637
- find(t, e = "") {
2638
- const i = H(t.replace(/^package:\/\//, ""));
2639
- if (Nt(i)) return this.entries.has(i) ? i : null;
2640
- const s = H(e).split("/").slice(0, -1).join("/");
2641
- for (const r of [H(`${s}/${t.replace(/^package:\/\//, "")}`), i])
2642
- if (this.entries.has(r)) return r;
2643
- const o = this.paths().filter(
2644
- (r) => !Nt(r) && (r === i || r.endsWith(`/${i}`) || i.endsWith(`/${r}`))
2645
- );
2646
- return o.length === 1 ? o[0] : null;
2647
- }
2648
- async text(t) {
2649
- await this.ensure(t);
2650
- const e = this.entries.get(this.resolve(t));
2651
- if (!e) throw ft(`Simulation resource not found: ${t}`, "E_ASSET_RESOURCE_NOT_FOUND");
2652
- return e.text();
2653
- }
2654
- async bytes(t) {
2655
- await this.ensure(t);
2656
- const e = this.entries.get(this.resolve(t));
2657
- if (!e) throw ft(`Simulation resource not found: ${t}`, "E_ASSET_RESOURCE_NOT_FOUND");
2658
- return new Uint8Array(await e.arrayBuffer());
2659
- }
2660
- getBlob(t) {
2661
- const e = this.resolve(t), i = this.entries.get(e);
2662
- if (!i) throw ft(`Simulation resource not found: ${t}`, "E_ASSET_RESOURCE_NOT_FOUND");
2663
- return i;
2664
- }
2665
- async ensure(t, e = this.source.signal) {
2666
- if (Lt(e), this.disposed) throw new DOMException("The resource package was disposed.", "AbortError");
2667
- const i = H(t);
2668
- if (this.entries.has(i)) return;
2669
- const s = this.failures.get(i);
2670
- if (s) throw s;
2671
- let o = this.pending.get(i);
2672
- if (!o) {
2673
- const a = new AbortController(), c = () => a.abort();
2674
- this.source.signal.aborted ? a.abort() : this.source.signal.addEventListener("abort", c, { once: !0 }), a.signal.addEventListener("abort", () => this.source.signal.removeEventListener("abort", c), { once: !0 });
2675
- const d = {
2676
- controller: a,
2677
- waiters: 0,
2678
- promise: Promise.resolve().then(() => this.readResource(i, t, a.signal))
2679
- };
2680
- this.pending.set(i, d);
2681
- const f = () => {
2682
- this.source.signal.removeEventListener("abort", c), this.pending.get(i) === d && this.pending.delete(i);
2683
- };
2684
- d.promise.then(f, f), o = d;
2685
- }
2686
- const r = o;
2687
- return r.waiters++, new Promise((a, c) => {
2688
- let d = !1;
2689
- const f = () => d ? !1 : (d = !0, e.removeEventListener("abort", l), r.controller.signal.removeEventListener("abort", l), r.waiters--, !0), l = () => {
2690
- f() && (r.waiters === 0 && this.pending.get(i) === r && (this.pending.delete(i), r.controller.abort()), c(new DOMException("The operation was aborted.", "AbortError")));
2691
- };
2692
- e.addEventListener("abort", l, { once: !0 }), r.controller.signal.addEventListener("abort", l, { once: !0 }), (e.aborted || r.controller.signal.aborted) && l(), r.promise.then(
2693
- () => {
2694
- f() && a();
2695
- },
2696
- (u) => {
2697
- f() && c(u);
2698
- }
2699
- );
2700
- });
2701
- }
2702
- async readResource(t, e, i) {
2703
- try {
2704
- Lt(i);
2705
- const s = await this.source.resolve(t, i);
2706
- if (Lt(i), !/^https?:\/\//i.test(s) && !/^blob:/i.test(s))
2707
- throw ft(`Simulation resource not found: ${e}. Upload the complete asset folder or provide a resourceResolver/baseUrl.`, We);
2708
- const o = await fetch(s, { signal: i });
2709
- if (!o.ok) {
2710
- const c = o.status === 401 || o.status === 403 ? Hn : o.status === 404 || o.status === 410 ? We : Wn;
2711
- throw ft(`Simulation resource request failed (${o.status}): ${s}`, c);
2712
- }
2713
- const r = await o.blob();
2714
- Lt(i);
2715
- const a = await Yn(r);
2716
- if (Lt(i), a) throw ft(`Simulation resource is not usable (${a}): ${s}`, Xn);
2717
- this.entries.set(t, r);
2718
- } catch (s) {
2719
- throw i.aborted ? new DOMException("The operation was aborted.", "AbortError") : (Gn(s) === "aborted" || this.failures.set(t, s instanceof Error ? s : new Error(String(s))), s);
2720
- }
2721
- }
2722
- /** The recorded failure for a resource, if a previous read already failed. */
2723
- failureOf(t) {
2724
- return this.failures.get(H(t));
2725
- }
2726
- objectUrl(t) {
2727
- const e = this.resolve(t);
2728
- let i = this.objectUrls.get(e);
2729
- return i || (i = URL.createObjectURL(this.getBlob(e)), this.objectUrls.set(e, i), this.objectUrlPaths.set(i, e)), i;
2730
- }
2731
- pathForObjectUrl(t) {
2732
- return this.objectUrlPaths.get(t) ?? null;
2733
- }
2734
- /**
2735
- * Resolve a texture relative to the directory containing the entry layer.
2736
- * Pass the entry directory, not the entry file path.
2737
- */
2738
- findTexture(t, e = "") {
2739
- const i = this.findPresent(t, e);
2740
- if (i) return i;
2741
- const s = this.udimTextureSet(t, e);
2742
- return (s == null ? void 0 : s.paths.length) === 1 ? s.paths[0] : null;
2743
- }
2744
- udimTextureSet(t, e = "") {
2745
- const i = this.bindPackageReference(t, e), s = this.texturesUnderEntryDirectory(e);
2746
- return ls(i, s.length ? s : this.paths());
2747
- }
2748
- /**
2749
- * Package files below the entry directory named like UDIM tiles. A set the
2750
- * entry directory does not contain falls back to the whole package.
2751
- */
2752
- texturesUnderEntryDirectory(t) {
2753
- const e = H(t);
2754
- return e ? this.paths().filter((i) => i.startsWith(`${e}/`) && /\d{4}\.[^/]*$/i.test(i)) : [];
2755
- }
2756
- objectUrlIfPresent(t, e = "") {
2757
- const i = this.findTexture(t, e);
2758
- return i && this.entries.has(i) ? this.objectUrl(i) : null;
2759
- }
2760
- findPresent(t, e = "") {
2761
- if (Nt(t)) {
2762
- if (this.entries.has(t)) return t;
2763
- const c = this.bindPackageReference(t, e);
2764
- return c === t ? null : this.findPresent(c, e);
2765
- }
2766
- const i = H(e), s = i ? `${i}/` : "", o = H(t), r = H(s ? `${s}${o}` : o);
2767
- if (this.entries.has(r)) return r;
2768
- const a = s ? this.paths().filter((c) => {
2769
- if (!c.startsWith(s)) return !1;
2770
- const d = c.slice(s.length);
2771
- return d === o || o.endsWith(`/${d}`);
2772
- }) : [];
2773
- return a.length === 1 ? a[0] : this.find(t);
2774
- }
2775
- /**
2776
- * Rewrites a protocol reference (`https://bucket/asset/textures/a.png`,
2777
- * `file:///asset/textures/a.png`) into the package path it names, relative to
2778
- * the entry directory, preferring the longest tail of the URL path that
2779
- * repeats inside the package. The file name alone is never enough to bind,
2780
- * so an unrelated same-name file elsewhere in the package is not guessed.
2781
- * References that are not URLs, or that bind to nothing, are returned as-is.
2782
- */
2783
- bindPackageReference(t, e = "") {
2784
- const i = H(e), s = i ? `${i}/` : "", o = hs(t).flatMap((a) => a.split("/")).filter(Boolean);
2785
- if (!o.length) return t;
2786
- let r = null;
2787
- for (const a of this.paths()) {
2788
- if (Nt(a) || s && !a.startsWith(s)) continue;
2789
- const c = a.split("/");
2790
- let d = 0;
2791
- for (; d < o.length && d < c.length && ps(o.at(-1 - d), c.at(-1 - d)); ) d += 1;
2792
- d < 2 || (!r || d > r.depth) && (r = { path: a, depth: d });
2793
- }
2794
- return r ? s && r.path.startsWith(s) ? r.path.slice(s.length) : r.path : t;
2795
- }
2796
- dispose() {
2797
- this.disposed = !0;
2798
- for (const t of this.pending.values()) t.controller.abort();
2799
- this.pending.clear();
2800
- for (const t of this.objectUrls.values()) URL.revokeObjectURL(t);
2801
- this.objectUrls.clear(), this.objectUrlPaths.clear(), this.entries.clear(), this.manifestPaths.clear(), this.failures.clear();
2802
- }
2803
- }
2804
- async function Ds(n, t) {
2805
- if (t.hasLocalFiles()) return t.text(n.entryPath ?? n.filename ?? t.paths()[0]);
2806
- const e = await fetch(n.url ?? await n.resolve(n.entryPath ?? ""), { signal: n.signal });
2807
- if (!e.ok) throw ft(`Simulation asset request failed: ${e.status}`, "E_ASSET_FETCH");
2808
- return e.text();
2809
- }
2810
- function Cs(n) {
2811
- return H(n);
2812
- }
2813
- function H(n) {
2814
- if (Nt(n)) return n;
2815
- const t = [];
2816
- for (const e of n.replaceAll("\\", "/").split("/"))
2817
- !e || e === "." || (e === ".." && t.length && t.at(-1) !== ".." ? t.pop() : t.push(e));
2818
- return t.join("/");
2819
- }
2820
- function Nt(n) {
2821
- return /^[a-z][a-z\d+.-]*:/i.test(n) && !/^package:\/\//i.test(n);
2822
- }
2823
- function ps(n, t) {
2824
- const e = n.search(/[?#]/);
2825
- return t === (e < 0 ? n : n.slice(0, e));
2826
- }
2827
- function ms(n) {
2828
- try {
2829
- return decodeURIComponent(n);
2830
- } catch {
2831
- return n;
2832
- }
2833
- }
2834
- function hs(n) {
2835
- if (!Nt(n) || /^(?:data|blob):/i.test(n)) return [];
2836
- let t;
2837
- try {
2838
- t = new URL(n, "file:///").pathname;
2839
- } catch {
2840
- t = n.replace(/^[a-z][a-z\d+.-]*:\/\/[^/]*/i, "").replace(/[?#].*$/, "");
2841
- }
2842
- return t.split("/").filter(Boolean).map(ms);
2843
- }
2844
- function ys(n) {
2845
- return typeof n == "object" && n !== null && "kind" in n && n.kind === "files";
2846
- }
2847
- function ft(n, t) {
2848
- return Object.assign(new Error(n), { code: t });
2849
- }
2850
- function Os() {
2851
- return { errors: [], warnings: [], approximations: [], droppedFeatures: [] };
2852
- }
2853
- function Fs(n, t = {}) {
2854
- const e = Object.freeze({ schemaVersion: 1, ...n });
2855
- return gs(e, t), e;
2856
- }
2857
- function gs(n, t = {}) {
2858
- if (!n.id.trim() || !n.name.trim()) throw ue("Asset IR id and name are required.", "E_ASSET_IR_INVALID");
2859
- if (n.source.format !== "usd" && n.links.length === 0) throw ue("Asset IR requires at least one link.", "E_ASSET_IR_INVALID");
2860
- const e = /* @__PURE__ */ new Set();
2861
- for (const s of n.links) {
2862
- if (!s.id || e.has(s.id)) throw ue(`Invalid or duplicate link: ${s.id}`, "E_ASSET_IR_INVALID");
2863
- e.add(s.id);
2864
- }
2865
- const i = /* @__PURE__ */ new Set();
2866
- for (const s of n.joints) {
2867
- if (!s.id || i.has(s.id) || !t.allowInvalidGraph && (!e.has(s.parent) || !e.has(s.child)))
2868
- throw ue(`Invalid joint: ${s.id}`, "E_ASSET_IR_INVALID");
2869
- i.add(s.id);
2870
- }
2871
- }
2872
- function ue(n, t) {
2873
- return Object.assign(new Error(n), { code: t });
2874
- }
2875
- const Ln = 3073715, zs = 16758861, ws = 0.96, xs = 0.1, bs = 20, As = 1;
2876
- function Vs(n = Ln) {
2877
- return new $n({
2878
- color: n,
2879
- transparent: !0,
2880
- opacity: ws,
2881
- depthTest: !1,
2882
- depthWrite: !1,
2883
- linewidth: 2,
2884
- toneMapped: !1,
2885
- fog: !1
2886
- });
2887
- }
2888
- function js(n = Ln) {
2889
- return new kn({
2890
- color: n,
2891
- transparent: !0,
2892
- opacity: xs,
2893
- depthTest: !0,
2894
- depthWrite: !1,
2895
- side: _n,
2896
- polygonOffset: !0,
2897
- polygonOffsetFactor: -1,
2898
- polygonOffsetUnits: -1,
2899
- toneMapped: !1,
2900
- fog: !1
2901
- });
2902
- }
2903
- function $s(n, t, e = "feature", i) {
2904
- const s = e === "mesh" ? new qn(n) : _s(n), o = new Ve(s, t);
2905
- if (o.renderOrder = 9, i) {
2906
- const r = new $t(n.clone(), i);
2907
- r.name = "collision-volume", r.renderOrder = 8, r.userData.collisionDebugRole = "volume", o.add(r), o.userData.collisionDebugRole = "outline";
2908
- }
2909
- return o;
2910
- }
2911
- function _s(n) {
2912
- let t = new we(n, bs);
2913
- return xn(n, t) || (t.dispose(), t = new we(n, As)), xn(n, t) || (t.dispose(), t = new we(n, 0)), t;
2914
- }
2915
- const Ss = 256, Bs = 0.5;
2916
- function xn(n, t) {
2917
- var a, c;
2918
- const e = t.getAttribute("position");
2919
- if (!e || e.count === 0) return !1;
2920
- const i = n.getAttribute("position");
2921
- if (!i || i.count < Ss) return !0;
2922
- n.computeBoundingBox(), t.computeBoundingBox();
2923
- const s = (a = n.boundingBox) == null ? void 0 : a.getSize(new U()), o = (c = t.boundingBox) == null ? void 0 : c.getSize(new U());
2924
- if (!s || !o) return !1;
2925
- const r = s.length();
2926
- return !Number.isFinite(r) || r <= 0 ? !0 : o.length() / r >= Bs;
2927
- }
2928
- export {
2929
- zs as C,
2930
- me as M,
2931
- Us as S,
2932
- js as a,
2933
- $s as b,
2934
- Vs as c,
2935
- Fs as d,
2936
- Ns as e,
2937
- Os as f,
2938
- Rs as g,
2939
- Ds as h,
2940
- mn as i,
2941
- Me as j,
2942
- Cs as n,
2943
- vs as p,
2944
- ls as r,
2945
- Ls as u,
2946
- Ms as w
2947
- };