@nebula-spatial/viewer 0.5.7 → 0.5.9

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.
@@ -1,792 +0,0 @@
1
- var le = Object.defineProperty;
2
- var ce = (t, e, n) => e in t ? le(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var R = (t, e, n) => ce(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { Vector3 as k, LineBasicMaterial as ue, MeshBasicMaterial as fe, DoubleSide as de, WireframeGeometry as me, LineSegments as pe, Mesh as he, EdgesGeometry as G } from "three";
5
- import { disposeModelResources as _e } from "./resources-CHhCm2f7.js";
6
- import { s as Q, t as be, u as Ee, v as Ie, U as ge, q as ye } from "./index-BTAC6njT.js";
7
- const we = /* @__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
- ]), Se = /* @__PURE__ */ new Set(["step", "reset", "grab", "up-axis"]), Oe = Object.freeze({
24
- kind: "visual-adaptation",
25
- title: "视觉适配信息",
26
- summary: "部分材质细节采用近似表示,不影响资产结构与模型查看。",
27
- tone: "info"
28
- }), Ne = Object.freeze({
29
- kind: "unsupported-by-viewer",
30
- title: "视觉预览模式",
31
- summary: "当前仿真链路未能建立物理模型,资产视觉内容仍可正常查看。",
32
- tone: "info"
33
- });
34
- function W(t, e) {
35
- return t === "E_URDF_INERTIA" ? {
36
- kind: "invalid-asset",
37
- title: "物理定义无效",
38
- summary: "该 URDF 未声明动力学仿真所需的有效惯性数据,动力学模型无法建立。",
39
- tone: "warning"
40
- } : {
41
- kind: "invalid-asset",
42
- title: "物理定义无效",
43
- summary: e === "usd-physics" ? "该 USD 资产的物理参数或关节定义无效,物理模型无法建立。" : "该资产的物理参数缺失或无效,物理模型无法建立。",
44
- tone: "warning"
45
- };
46
- }
47
- function je(t) {
48
- return t === "visual-material" ? {
49
- kind: "visual-adaptation",
50
- title: "视觉材质近似",
51
- summary: "部分材质信息未完整转换,当前显示使用近似材质。",
52
- tone: "info"
53
- } : Oe;
54
- }
55
- function se(t, e) {
56
- const n = e.split(":").at(-1);
57
- if (n && Se.has(n))
58
- return {
59
- kind: "runtime-failure",
60
- title: "仿真运行异常",
61
- summary: "仿真初始化或运行过程中发生异常,物理仿真已停止;资产视觉内容仍可正常查看。",
62
- tone: "warning"
63
- };
64
- if (t === "E_MUJOCO_INITIALIZE") {
65
- if (e === "mjcf-physics")
66
- return {
67
- kind: "runtime-failure",
68
- title: "物理模型初始化失败",
69
- summary: "MuJoCo 物理模型初始化失败,资产仍可进行视觉预览。",
70
- tone: "warning"
71
- };
72
- if (e === "urdf-physics")
73
- return {
74
- kind: "runtime-failure",
75
- title: "动力学初始化失败",
76
- summary: "URDF 动力学初始化失败,当前保留运动学预览。",
77
- tone: "warning"
78
- };
79
- if (e === "usd-physics")
80
- return {
81
- kind: "runtime-failure",
82
- title: "物理模型初始化失败",
83
- summary: "当前 USD 物理模型未能完成 MuJoCo 初始化,资产视觉内容仍可正常查看。",
84
- tone: "warning"
85
- };
86
- }
87
- return we.has(t) ? W(t, e) : e === "usd-physics" || t.startsWith("E_USD_") ? {
88
- kind: "unsupported-by-viewer",
89
- title: "视觉预览模式",
90
- summary: "当前 Viewer 未覆盖该 USD 资产使用的部分物理语义,视觉与结构信息可正常查看,物理仿真未启动。",
91
- tone: "info"
92
- } : t.startsWith("E_MJCF_") || t.startsWith("E_URDF_") ? W(t, e) : Ne;
93
- }
94
- function He(t, e) {
95
- const n = t.notice ?? (e === "physics-validation" ? W(t.code, t.source) : e === "visual-adaptation" || e === "visual-material" ? je(e) : se(t.code, t.source ?? e));
96
- return { ...t, stage: e, notice: n };
97
- }
98
- function Ye(t, e, n) {
99
- if (e.throwIfAborted(), t instanceof Error && (t.name === "AbortError" || ["E_ABORTED", "E_SUPERSEDED"].includes(String(t.code)))) throw t;
100
- const o = t && typeof t == "object" && "code" in t && typeof t.code == "string" ? t.code : "E_PHYSICS_INITIALIZE", i = t instanceof Error ? t.message : String(t);
101
- return { code: o, source: n, message: i, notice: se(o, n) };
102
- }
103
- function ve(t, e, n) {
104
- const o = new Map(t.map((r) => [r.id, r])), i = /* @__PURE__ */ new Map(), s = (r, f = /* @__PURE__ */ new Set()) => {
105
- if (i.has(r)) return i.get(r);
106
- const c = o.get(r);
107
- if (!c) return null;
108
- if (!c.mimic) {
109
- const u = { root: r, multiplier: 1, offset: 0 };
110
- return i.set(r, u), u;
111
- }
112
- if (f.has(r) || !o.has(c.mimic.joint) || !Number.isFinite(c.mimic.multiplier) || !Number.isFinite(c.mimic.offset))
113
- return i.set(r, null), null;
114
- f.add(r);
115
- const d = s(c.mimic.joint, f);
116
- if (f.delete(r), !d)
117
- return i.set(r, null), null;
118
- const l = {
119
- root: d.root,
120
- multiplier: c.mimic.multiplier * d.multiplier,
121
- offset: c.mimic.multiplier * d.offset + c.mimic.offset
122
- };
123
- return i.set(r, l), l;
124
- }, a = new Map(t.map((r) => {
125
- const f = s(r.id);
126
- return [r.id, f ?? { root: r.id, multiplier: 1, offset: 0 }];
127
- })), h = /* @__PURE__ */ new Map();
128
- for (const r of t) {
129
- const f = a.get(r.id);
130
- h.has(f.root) || h.set(f.root, { lower: -1 / 0, upper: 1 / 0, feasible: !0 });
131
- const c = r.limits;
132
- if (!c || Number.isNaN(c.lower) || Number.isNaN(c.upper) || c.lower > c.upper) continue;
133
- const d = h.get(f.root);
134
- if (f.multiplier === 0) {
135
- (f.offset < c.lower || f.offset > c.upper) && (d.feasible = !1);
136
- continue;
137
- }
138
- const l = (c.lower - f.offset) / f.multiplier, u = (c.upper - f.offset) / f.multiplier;
139
- d.lower = Math.max(d.lower, Math.min(l, u)), d.upper = Math.min(d.upper, Math.max(l, u)), d.lower > d.upper && (d.feasible = !1);
140
- }
141
- const I = Object.fromEntries(t.map((r) => [r.id, r.defaultValue])), _ = t.map((r) => {
142
- if (a.get(r.id).root !== r.id) return r;
143
- if (r.mimic && !i.get(r.id)) {
144
- const { mimic: l, ...u } = r;
145
- return u;
146
- }
147
- const c = h.get(r.id);
148
- let d;
149
- return c.feasible ? (Number.isFinite(c.lower) || Number.isFinite(c.upper)) && (d = { lower: c.lower, upper: c.upper }) : d = { lower: r.defaultValue, upper: r.defaultValue }, d ? { ...r, controlLimits: d } : r;
150
- }), D = new Map(_.map((r) => [r.id, r])), j = /* @__PURE__ */ new Set(), A = /* @__PURE__ */ new Set(), L = /* @__PURE__ */ new Set();
151
- let M = !1;
152
- const J = () => {
153
- for (const r of A) r();
154
- };
155
- let g = !1, x = [], E = Object.freeze({
156
- kind: "joints",
157
- revision: 0,
158
- format: e,
159
- joints: _,
160
- jointValues: Object.freeze({ ...I }),
161
- selectedJointId: null,
162
- playing: !1,
163
- ...n.controlMode ? { controlMode: n.controlMode } : {},
164
- ...n.controlMode === "physics" ? { jointTargets: Object.freeze({ ...I }) } : {}
165
- });
166
- const T = (r) => {
167
- if (!g) {
168
- E = Object.freeze({ ...E, ...r, revision: E.revision + 1 });
169
- for (const f of j) f(E);
170
- }
171
- }, B = () => E.playing && !(n.controlMode === "kinematic" && E.previewing === !0), P = (r, f) => {
172
- const c = r.controlLimits ?? r.limits;
173
- return c && !Number.isNaN(c.lower) && !Number.isNaN(c.upper) && c.lower <= c.upper ? Math.max(c.lower, Math.min(c.upper, f)) : f;
174
- }, U = (r, f, c = !1) => {
175
- var p, y, S;
176
- x = f;
177
- const d = {}, l = /* @__PURE__ */ new Map();
178
- for (const b of t) {
179
- if (a.get(b.id).root !== b.id) continue;
180
- const N = D.get(b.id);
181
- l.set(b.id, P(N, r[b.id] ?? N.defaultValue));
182
- }
183
- for (const b of t) {
184
- const O = a.get(b.id), N = l.get(O.root) ?? ((p = o.get(O.root)) == null ? void 0 : p.defaultValue) ?? b.defaultValue;
185
- d[b.id] = O.multiplier * N + O.offset;
186
- }
187
- c && Object.assign(d, I);
188
- const u = n.apply(d, f), m = n.controlMode === "physics" && ((y = n.isDriveActive) == null ? void 0 : y.call(n)) === !1 ? u ?? d : d;
189
- n.controlMode === "physics" && ((S = n.isDriveActive) == null ? void 0 : S.call(n)) === !1 && (x = []), T({
190
- jointValues: Object.freeze({ ...u ?? d }),
191
- ...n.controlMode === "physics" ? { jointTargets: Object.freeze({ ...m }) } : {}
192
- }), n.requestRender();
193
- };
194
- return {
195
- kind: "joints",
196
- getSnapshot: () => E,
197
- subscribe(r) {
198
- return g ? () => {
199
- } : (j.add(r), () => j.delete(r));
200
- },
201
- onManualInput(r) {
202
- return g ? () => {
203
- } : (A.add(r), () => A.delete(r));
204
- },
205
- onIntroFinished(r) {
206
- return g ? () => {
207
- } : M ? (r(), () => {
208
- }) : (L.add(r), () => L.delete(r));
209
- },
210
- notifyIntroFinished() {
211
- if (!(g || M)) {
212
- M = !0;
213
- for (const r of L) r();
214
- L.clear();
215
- }
216
- },
217
- setPreviewPose(r) {
218
- if (g || B() || n.controlMode !== "kinematic") return;
219
- const f = _.filter((d) => !d.mimic && Number.isFinite(r[d.id]) && ["revolute", "continuous", "prismatic"].includes(d.type));
220
- if (!f.length) return;
221
- const c = { ...E.jointValues };
222
- for (const d of f) c[d.id] = r[d.id];
223
- U(c, f.map((d) => d.id));
224
- },
225
- resetPreviewPose() {
226
- !g && !E.playing && n.controlMode === "kinematic" && U({ ...I }, [], !0);
227
- },
228
- setPreviewing(r) {
229
- !g && !!E.previewing !== r && T({ previewing: r });
230
- },
231
- select(r) {
232
- g || r !== null && !o.has(r) || r === E.selectedJointId || T({ selectedJointId: r });
233
- },
234
- setJointValue(r, f) {
235
- const c = D.get(r);
236
- if (g || B() || !c || c.mimic || !Number.isFinite(f) || !["revolute", "continuous", "prismatic"].includes(c.type) || (J(), g || E.playing)) return;
237
- const d = P(c, f), l = E.jointTargets ?? E.jointValues;
238
- d !== l[r] && U({ ...E.jointValues, [r]: d }, [r]);
239
- },
240
- resetJoint(r) {
241
- const f = D.get(r);
242
- g || B() || !f || f.mimic || (J(), !(g || E.playing) && U({ ...E.jointValues, [r]: f.defaultValue }, [r]));
243
- },
244
- resetPose() {
245
- g || B() || (J(), !g && !E.playing && U({ ...I }, t.filter((r) => a.get(r.id).root === r.id).map((r) => r.id), !0));
246
- },
247
- setPlaying(r) {
248
- !g && E.playing !== r && T({
249
- playing: r,
250
- ...n.controlMode === "physics" ? { jointTargets: Object.freeze({ ...E.jointValues }) } : {}
251
- });
252
- },
253
- syncValues(r, f = !1) {
254
- var l;
255
- if (g) return;
256
- const c = { ...E.jointValues };
257
- let d = !1;
258
- for (const u of t) {
259
- const m = r[u.id];
260
- m !== void 0 && Number.isFinite(m) && m !== c[u.id] && (c[u.id] = m, d = !0);
261
- }
262
- if ((f || E.playing) && (x = []), d || f) {
263
- const u = { ...c };
264
- for (const m of x) u[m] = ((l = E.jointTargets) == null ? void 0 : l[m]) ?? c[m];
265
- T({
266
- jointValues: Object.freeze(c),
267
- ...n.controlMode === "physics" ? { jointTargets: Object.freeze(u) } : {}
268
- });
269
- }
270
- },
271
- dispose() {
272
- g = !0, j.clear(), A.clear(), L.clear();
273
- }
274
- };
275
- }
276
- function Ke(t, e, n, o, i, s) {
277
- try {
278
- return De(t, e, n, o, s);
279
- } catch (a) {
280
- try {
281
- i == null || i(a);
282
- } catch {
283
- }
284
- return;
285
- }
286
- }
287
- function De(t, e, n, o, i) {
288
- var r, f, c, d;
289
- const s = t.model, a = t.mujoco, h = t.data;
290
- if (!s || !a || !h) return;
291
- const I = [], _ = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), L = (l) => {
292
- try {
293
- const u = Number(s.nu ?? 0);
294
- if (!Number.isFinite(u) || u <= 0) return {};
295
- const m = s.actuator_trntype, p = s.actuator_trnid, y = s.actuator_forcerange, S = s.actuator_biasprm;
296
- if (!m || !p) return {};
297
- for (let b = 0; b < u; b++) {
298
- if (m[b] !== a.mjtTrn.mjTRN_JOINT.value || p[b * 2] !== l) continue;
299
- const O = Number(s.actuator_gear[b * 6]);
300
- if (!Number.isFinite(O)) continue;
301
- const N = s.actuator_biastype[b] === a.mjtBias.mjBIAS_AFFINE.value, V = s.actuator_gaintype[b] === a.mjtGain.mjGAIN_FIXED.value, w = N ? -Number(S == null ? void 0 : S[b * 10 + 1]) + 0 : void 0, C = N ? -Number(S == null ? void 0 : S[b * 10 + 2]) + 0 : void 0, q = Number(s.actuator_gainprm[b * 10]), ae = {
302
- type: V && N && w != null && w > 0 && q === w ? "position" : V && N && w === 0 && C != null && C > 0 && q === C ? "velocity" : V && s.actuator_biastype[b] === a.mjtBias.mjBIAS_NONE.value ? "motor" : "general",
303
- ...Number.isFinite(w) ? { stiffness: w * O * O } : {},
304
- ...Number.isFinite(C) ? { damping: C * O * O } : {}
305
- }, H = s.actuator(b);
306
- let Y;
307
- try {
308
- Y = !!H.forcelimited;
309
- } finally {
310
- H.delete();
311
- }
312
- const K = Number(y == null ? void 0 : y[b * 2]), X = Number(y == null ? void 0 : y[b * 2 + 1]), Z = Y && Number.isFinite(K) && Number.isFinite(X) ? Math.max(Math.abs(K), Math.abs(X)) * Math.abs(O) : void 0;
313
- return { drive: ae, ...Z != null ? { maxEffort: Z } : {} };
314
- }
315
- } catch {
316
- }
317
- return {};
318
- };
319
- for (let l = 0; l < s.njnt; l++) {
320
- const u = s.jnt_type[l], m = u === a.mjtJoint.mjJNT_HINGE.value;
321
- if (!m && u !== a.mjtJoint.mjJNT_SLIDE.value) continue;
322
- const p = a.mj_id2name(s, a.mjtObj.mjOBJ_JOINT.value, l);
323
- if (!p) continue;
324
- const y = s.jnt_bodyid[l], S = s.body_parentid[y], b = s.jnt(l);
325
- try {
326
- const O = (r = i == null ? void 0 : i.mimics) == null ? void 0 : r.get(p), N = L(l), V = Number((f = s.body_mass) == null ? void 0 : f[y]), w = (c = i == null ? void 0 : i.metadata) == null ? void 0 : c.get(p), C = ((d = i == null ? void 0 : i.limits) == null ? void 0 : d.get(p)) ?? (b.limited ? { lower: s.jnt_range[l * 2], upper: s.jnt_range[l * 2 + 1] } : void 0);
327
- I.push({
328
- id: p,
329
- name: p.split("/").pop() || p,
330
- type: m ? "revolute" : "prismatic",
331
- parent: S > 0 ? a.mj_id2name(s, a.mjtObj.mjOBJ_BODY.value, S) : null,
332
- child: a.mj_id2name(s, a.mjtObj.mjOBJ_BODY.value, y),
333
- axis: Array.from(s.jnt_axis.slice(l * 3, l * 3 + 3)),
334
- unit: m ? "rad" : "m",
335
- defaultValue: h.qpos[s.jnt_qposadr[l]],
336
- ...C ? { limits: C } : {},
337
- ...(w == null ? void 0 : w.movingMass) != null ? { movingMass: w.movingMass } : Number.isFinite(V) && V > 0 ? { movingMass: V } : {},
338
- ...w != null && w.drive ? { drive: w.drive } : N.drive ? { drive: N.drive } : {},
339
- ...(w == null ? void 0 : w.maxEffort) != null ? { maxEffort: w.maxEffort } : N.maxEffort != null ? { maxEffort: N.maxEffort } : {},
340
- ...O ? { mimic: { ...O } } : {}
341
- }), _.set(p, l), D.set(p, y), j.has(y) || j.set(y, p), A.set(y, p);
342
- } finally {
343
- b.delete();
344
- }
345
- }
346
- if (!I.length) return;
347
- const M = /* @__PURE__ */ new Map(), J = I.map((l) => {
348
- const u = D.get(l.id);
349
- let m = M.get(u);
350
- if (!m) {
351
- let p = s.body_parentid[u];
352
- for (; p > 0 && !j.has(p); ) p = s.body_parentid[p];
353
- m = A.get(p);
354
- }
355
- return M.set(u, l.id), { ...l, parentJointId: m ?? null };
356
- }), g = ve(J, e, {
357
- controlMode: e === "usd" ? "kinematic" : "physics",
358
- apply(l, u) {
359
- if (e === "usd")
360
- t.setJointValuesKinematic(l);
361
- else {
362
- const m = Object.fromEntries(u.map((p) => [p, l[p]]));
363
- t.setJointTargets(m);
364
- }
365
- return n(), t.getJointValues(I.map((m) => m.id));
366
- },
367
- ...e === "mjcf" ? { isDriveActive: () => t.isJointDriveActive } : {},
368
- requestRender: o
369
- }), x = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new Map();
370
- for (let l = 1; l < s.nbody; l++) {
371
- const u = a.mj_id2name(s, a.mjtObj.mjOBJ_BODY.value, l);
372
- if (!u) continue;
373
- x.set(u, l), E.set(l, u);
374
- let m = l;
375
- for (; m > 0 && !j.has(m); ) m = s.body_parentid[m];
376
- T.set(u, j.get(m) ?? null);
377
- }
378
- for (const [l, u] of D) {
379
- const m = [];
380
- for (const [p, y] of E) {
381
- let S = p;
382
- for (; S > 0 && S !== u; ) S = s.body_parentid[S];
383
- S === u && m.push(y);
384
- }
385
- B.set(l, Object.freeze(m));
386
- }
387
- let P = !1;
388
- const U = () => !P && t.model === s && t.data === h;
389
- return {
390
- ...g,
391
- pickRoots() {
392
- return U() && (i != null && i.root) ? [i.root] : [];
393
- },
394
- objectForBody(l) {
395
- var u;
396
- return U() && x.has(l) ? ((u = i == null ? void 0 : i.objectForBody) == null ? void 0 : u.call(i, l)) ?? null : null;
397
- },
398
- jointForBody(l) {
399
- return U() ? T.get(l) ?? null : null;
400
- },
401
- bodiesForJoint(l) {
402
- return U() ? B.get(l) ?? [] : [];
403
- },
404
- jointWorldFrame(l) {
405
- const u = _.get(l);
406
- if (!U() || u === void 0) return null;
407
- const m = new k().fromArray(h.xanchor, u * 3), p = new k().fromArray(h.xaxis, u * 3);
408
- return !m.toArray().every(Number.isFinite) || !p.toArray().every(Number.isFinite) || p.lengthSq() < 1e-12 ? null : (i != null && i.root ? (i.root.updateWorldMatrix(!0, !1), m.applyMatrix4(i.root.matrixWorld), p.transformDirection(i.root.matrixWorld)) : p.normalize(), { position: m, axis: p });
409
- },
410
- dispose() {
411
- P || (P = !0, g.dispose());
412
- }
413
- };
414
- }
415
- class Xe {
416
- constructor(e, n) {
417
- R(this, "root");
418
- R(this, "bodies", /* @__PURE__ */ new Map());
419
- R(this, "links", /* @__PURE__ */ new Map());
420
- R(this, "disposed", !1);
421
- this.runtime = e, this.root = n.root;
422
- const o = e.mujoco, i = e.model;
423
- for (const [s, a] of n.bindings) {
424
- const h = o.mj_name2id(i, o.mjtObj.mjOBJ_BODY.value, s);
425
- if (h < 0) throw ee(`Physics body missing for visual link: ${s}`, "E_SIMULATION_BIND");
426
- this.links.set(s, a), a.userData.bodyId = h, this.bodies.set(h, a);
427
- }
428
- if (this.bodies.size !== n.expectedLinkCount) throw ee("Visual body binding count mismatch.", "E_SIMULATION_BIND");
429
- this.sync();
430
- }
431
- objectForLink(e) {
432
- return this.links.get(e) ?? null;
433
- }
434
- bodyPoses() {
435
- return new Map([...this.bodies.values()].map((e) => [e.name, { position: e.position.clone(), quaternion: e.quaternion.clone() }]));
436
- }
437
- sync() {
438
- if (this.disposed || !this.runtime.data) return;
439
- const { xpos: e, xquat: n } = this.runtime.data;
440
- for (const [o, i] of this.bodies) {
441
- const s = o * 3, a = o * 4;
442
- i.position.set(e[s], e[s + 1], e[s + 2]), i.quaternion.set(n[a + 1], n[a + 2], n[a + 3], n[a]);
443
- }
444
- this.root.updateMatrixWorld(!0);
445
- }
446
- dispose() {
447
- this.disposed || (this.disposed = !0, this.bodies.clear(), this.links.clear(), _e(this.root));
448
- }
449
- }
450
- function ee(t, e) {
451
- return Object.assign(new Error(t), { code: e });
452
- }
453
- const Me = /<UDIM>/i;
454
- function Ue(t, e) {
455
- const n = te(t).replaceAll("\\", "/");
456
- if (!Me.test(n)) return null;
457
- const o = ne(n), i = o.split("/").at(-1);
458
- if (!i) return { paths: [], tiles: [] };
459
- const s = Le(i);
460
- if (!s) return { paths: [], tiles: [] };
461
- const a = [];
462
- for (const _ of new Set(e)) {
463
- const D = te(_).replaceAll("\\", "/"), j = ne(D), A = j.split("/").at(-1);
464
- if (!A) continue;
465
- const L = s.exec(A);
466
- if (!L) continue;
467
- const M = Number(L[1]);
468
- !Number.isInteger(M) || M < 1001 || M > 9999 || a.push({
469
- path: _,
470
- tile: M,
471
- score: Re(o, j)
472
- });
473
- }
474
- if (!a.length) return { paths: [], tiles: [] };
475
- const h = Math.max(...a.map((_) => _.score)), I = a.filter((_) => _.score === h).sort((_, D) => _.tile - D.tile || _.path.localeCompare(D.path));
476
- return {
477
- paths: I.map((_) => _.path),
478
- tiles: I.map((_) => _.tile)
479
- };
480
- }
481
- function Ze(t) {
482
- if (!t.tiles.length) return null;
483
- const e = t.tiles.map(Ae), n = Math.min(...e.map(({ column: a }) => a)), o = Math.max(...e.map(({ column: a }) => a)), i = Math.min(...e.map(({ row: a }) => a)), s = Math.max(...e.map(({ row: a }) => a));
484
- return {
485
- minColumn: n,
486
- maxColumn: o,
487
- minRow: i,
488
- maxRow: s,
489
- columns: o - n + 1,
490
- rows: s - i + 1
491
- };
492
- }
493
- function Ae(t) {
494
- const e = t - 1001;
495
- return {
496
- column: (e % 10 + 10) % 10,
497
- row: Math.floor(e / 10)
498
- };
499
- }
500
- function Le(t) {
501
- const e = t.split(/<UDIM>/i);
502
- return e.length !== 2 ? null : new RegExp(`^${ie(e[0])}(\\d{4})${ie(e[1])}$`, "i");
503
- }
504
- function Re(t, e) {
505
- const n = t.split("/").slice(0, -1).filter(Boolean), o = e.split("/").slice(0, -1).filter(Boolean);
506
- let i = 0;
507
- for (; i < n.length && i < o.length; ) {
508
- const s = n.at(-1 - i), a = o.at(-1 - i);
509
- if ((s == null ? void 0 : s.toLowerCase()) !== (a == null ? void 0 : a.toLowerCase())) break;
510
- i += 1;
511
- }
512
- return i;
513
- }
514
- function te(t) {
515
- const e = t.replace(/%3CUDIM%3E/gi, "<UDIM>");
516
- try {
517
- return decodeURIComponent(e);
518
- } catch {
519
- return e;
520
- }
521
- }
522
- function ne(t) {
523
- const e = t.search(/[?#]/);
524
- return e < 0 ? t : t.slice(0, e);
525
- }
526
- function ie(t) {
527
- return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
528
- }
529
- class Qe {
530
- constructor(e) {
531
- R(this, "entries", /* @__PURE__ */ new Map());
532
- R(this, "objectUrls", /* @__PURE__ */ new Map());
533
- R(this, "objectUrlPaths", /* @__PURE__ */ new Map());
534
- /**
535
- * Reads that already failed, so a missing resource is not requested again by
536
- * the visual adapter after the reference prefetch has recorded it.
537
- */
538
- R(this, "failures", /* @__PURE__ */ new Map());
539
- this.source = e;
540
- const n = e.original;
541
- if (Te(n))
542
- for (const o of n.files) this.entries.set(v(o.path), o.file);
543
- else typeof Blob < "u" && n instanceof Blob ? this.entries.set(e.entryPath ?? e.filename ?? "asset", n) : n instanceof ArrayBuffer ? this.entries.set(e.entryPath ?? e.filename ?? "asset", new Blob([n])) : typeof n == "object" && n !== null && "kind" in n && n.kind === "buffer" && this.entries.set(e.entryPath ?? e.filename ?? "asset", new Blob([n.buffer]));
544
- }
545
- paths() {
546
- return [...this.entries.keys()];
547
- }
548
- hasLocalFiles() {
549
- return this.entries.size > 0;
550
- }
551
- put(e, n) {
552
- this.entries.set(v(e), n);
553
- }
554
- relativePaths(e = "", n = !1) {
555
- return [...this.relativeEntries(e, n)].map(([o]) => o);
556
- }
557
- asSourceRecord(e = "", n = !1) {
558
- return Object.fromEntries(this.relativeEntries(e, n));
559
- }
560
- *relativeEntries(e = "", n = !1) {
561
- const o = v(e), i = o ? `${o}/` : "";
562
- for (const [s, a] of this.entries)
563
- if (!i || s.startsWith(i)) yield [i ? s.slice(i.length) : s, a];
564
- else if (n) {
565
- const h = o.split("/"), I = s.split("/");
566
- let _ = 0;
567
- for (; _ < h.length && h[_] === I[_]; ) _++;
568
- yield [[...h.slice(_).map(() => ".."), ...I.slice(_)].join("/"), a];
569
- }
570
- }
571
- resolve(e, n = "") {
572
- const o = this.find(e, n);
573
- if (o) return o;
574
- const i = v(n).split("/").slice(0, -1).join("/");
575
- if (this.source.url) return v(`${i}/${e.replace(/^package:\/\//, "")}`);
576
- throw F(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
577
- }
578
- find(e, n = "") {
579
- const o = v(e.replace(/^package:\/\//, ""));
580
- if ($(o)) return this.entries.has(o) ? o : null;
581
- const i = v(n).split("/").slice(0, -1).join("/");
582
- for (const a of [v(`${i}/${e.replace(/^package:\/\//, "")}`), o])
583
- if (this.entries.has(a)) return a;
584
- const s = this.paths().filter(
585
- (a) => !$(a) && (a === o || a.endsWith(`/${o}`) || o.endsWith(`/${a}`))
586
- );
587
- return s.length === 1 ? s[0] : null;
588
- }
589
- async text(e) {
590
- await this.ensure(e);
591
- const n = this.entries.get(this.resolve(e));
592
- if (!n) throw F(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
593
- return n.text();
594
- }
595
- async bytes(e) {
596
- await this.ensure(e);
597
- const n = this.entries.get(this.resolve(e));
598
- if (!n) throw F(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
599
- return new Uint8Array(await n.arrayBuffer());
600
- }
601
- getBlob(e) {
602
- const n = this.resolve(e), o = this.entries.get(n);
603
- if (!o) throw F(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
604
- return o;
605
- }
606
- async ensure(e) {
607
- const n = v(e);
608
- if (this.entries.has(n)) return;
609
- const o = this.failures.get(n);
610
- if (o) throw o;
611
- try {
612
- const i = await this.source.resolve(n);
613
- if (!/^https?:\/\//i.test(i) && !/^blob:/i.test(i))
614
- throw F(`Simulation resource not found: ${e}. Upload the complete asset folder or provide a resourceResolver/baseUrl.`, Q);
615
- const s = await fetch(i, { signal: this.source.signal });
616
- if (!s.ok) {
617
- const I = s.status === 401 || s.status === 403 ? be : s.status === 404 || s.status === 410 ? Q : Ee;
618
- throw F(`Simulation resource request failed (${s.status}): ${i}`, I);
619
- }
620
- const a = await s.blob();
621
- this.source.signal.throwIfAborted();
622
- const h = await Ie(a);
623
- if (h) throw F(`Simulation resource is not usable (${h}): ${i}`, ge);
624
- this.entries.set(n, a);
625
- } catch (i) {
626
- throw ye(i) === "aborted" || this.failures.set(n, i instanceof Error ? i : new Error(String(i))), i;
627
- }
628
- }
629
- /** The recorded failure for a resource, if a previous read already failed. */
630
- failureOf(e) {
631
- return this.failures.get(v(e));
632
- }
633
- objectUrl(e) {
634
- const n = this.resolve(e);
635
- let o = this.objectUrls.get(n);
636
- return o || (o = URL.createObjectURL(this.getBlob(n)), this.objectUrls.set(n, o), this.objectUrlPaths.set(o, n)), o;
637
- }
638
- pathForObjectUrl(e) {
639
- return this.objectUrlPaths.get(e) ?? null;
640
- }
641
- /**
642
- * Resolve a texture relative to the directory containing the entry layer.
643
- * Pass the entry directory, not the entry file path.
644
- */
645
- findTexture(e, n = "") {
646
- const o = this.findPresent(e, n);
647
- if (o) return o;
648
- const i = this.udimTextureSet(e);
649
- return (i == null ? void 0 : i.paths.length) === 1 ? i.paths[0] : null;
650
- }
651
- udimTextureSet(e) {
652
- return Ue(e, this.paths());
653
- }
654
- objectUrlIfPresent(e, n = "") {
655
- const o = this.findTexture(e, n);
656
- return o ? this.objectUrl(o) : null;
657
- }
658
- findPresent(e, n = "") {
659
- if ($(e)) return this.entries.has(e) ? e : null;
660
- const o = v(n), i = o ? `${o}/` : "", s = v(e), a = i ? this.paths().filter((h) => {
661
- if (!h.startsWith(i)) return !1;
662
- const I = h.slice(i.length);
663
- return I === s || s.endsWith(`/${I}`);
664
- }) : [];
665
- return a.length === 1 ? a[0] : this.find(e);
666
- }
667
- dispose() {
668
- for (const e of this.objectUrls.values()) URL.revokeObjectURL(e);
669
- this.objectUrls.clear(), this.objectUrlPaths.clear(), this.entries.clear(), this.failures.clear();
670
- }
671
- }
672
- async function et(t, e) {
673
- if (e.hasLocalFiles()) return e.text(t.entryPath ?? t.filename ?? e.paths()[0]);
674
- const n = await fetch(t.url ?? await t.resolve(t.entryPath ?? ""), { signal: t.signal });
675
- if (!n.ok) throw F(`Simulation asset request failed: ${n.status}`, "E_ASSET_FETCH");
676
- return n.text();
677
- }
678
- function tt(t) {
679
- return v(t);
680
- }
681
- function v(t) {
682
- if ($(t)) return t;
683
- const e = [];
684
- for (const n of t.replaceAll("\\", "/").split("/"))
685
- !n || n === "." || (n === ".." && e.length && e.at(-1) !== ".." ? e.pop() : e.push(n));
686
- return e.join("/");
687
- }
688
- function $(t) {
689
- return /^[a-z][a-z\d+.-]*:/i.test(t) && !/^package:\/\//i.test(t);
690
- }
691
- function Te(t) {
692
- return typeof t == "object" && t !== null && "kind" in t && t.kind === "files";
693
- }
694
- function F(t, e) {
695
- return Object.assign(new Error(t), { code: e });
696
- }
697
- function nt() {
698
- return { errors: [], warnings: [], approximations: [], droppedFeatures: [] };
699
- }
700
- function it(t, e = {}) {
701
- const n = Object.freeze({ schemaVersion: 1, ...t });
702
- return Ce(n, e), n;
703
- }
704
- function Ce(t, e = {}) {
705
- if (!t.id.trim() || !t.name.trim()) throw z("Asset IR id and name are required.", "E_ASSET_IR_INVALID");
706
- if (t.source.format !== "usd" && t.links.length === 0) throw z("Asset IR requires at least one link.", "E_ASSET_IR_INVALID");
707
- const n = /* @__PURE__ */ new Set();
708
- for (const i of t.links) {
709
- if (!i.id || n.has(i.id)) throw z(`Invalid or duplicate link: ${i.id}`, "E_ASSET_IR_INVALID");
710
- n.add(i.id);
711
- }
712
- const o = /* @__PURE__ */ new Set();
713
- for (const i of t.joints) {
714
- if (!i.id || o.has(i.id) || !e.allowInvalidGraph && (!n.has(i.parent) || !n.has(i.child)))
715
- throw z(`Invalid joint: ${i.id}`, "E_ASSET_IR_INVALID");
716
- o.add(i.id);
717
- }
718
- }
719
- function z(t, e) {
720
- return Object.assign(new Error(t), { code: e });
721
- }
722
- const oe = 3073715, rt = 16758861, Fe = 0.96, xe = 0.1, Be = 20, Ve = 1;
723
- function st(t = oe) {
724
- return new ue({
725
- color: t,
726
- transparent: !0,
727
- opacity: Fe,
728
- depthTest: !1,
729
- depthWrite: !1,
730
- linewidth: 2,
731
- toneMapped: !1,
732
- fog: !1
733
- });
734
- }
735
- function ot(t = oe) {
736
- return new fe({
737
- color: t,
738
- transparent: !0,
739
- opacity: xe,
740
- depthTest: !0,
741
- depthWrite: !1,
742
- side: de,
743
- polygonOffset: !0,
744
- polygonOffsetFactor: -1,
745
- polygonOffsetUnits: -1,
746
- toneMapped: !1,
747
- fog: !1
748
- });
749
- }
750
- function at(t, e, n = "feature", o) {
751
- const i = n === "mesh" ? new me(t) : Pe(t), s = new pe(i, e);
752
- if (s.renderOrder = 9, o) {
753
- const a = new he(t.clone(), o);
754
- a.name = "collision-volume", a.renderOrder = 8, a.userData.collisionDebugRole = "volume", s.add(a), s.userData.collisionDebugRole = "outline";
755
- }
756
- return s;
757
- }
758
- function Pe(t) {
759
- let e = new G(t, Be);
760
- return re(t, e) || (e.dispose(), e = new G(t, Ve)), re(t, e) || (e.dispose(), e = new G(t, 0)), e;
761
- }
762
- const Je = 256, ze = 0.5;
763
- function re(t, e) {
764
- var h, I;
765
- const n = e.getAttribute("position");
766
- if (!n || n.count === 0) return !1;
767
- const o = t.getAttribute("position");
768
- if (!o || o.count < Je) return !0;
769
- t.computeBoundingBox(), e.computeBoundingBox();
770
- const i = (h = t.boundingBox) == null ? void 0 : h.getSize(new k()), s = (I = e.boundingBox) == null ? void 0 : I.getSize(new k());
771
- if (!i || !s) return !1;
772
- const a = i.length();
773
- return !Number.isFinite(a) || a <= 0 ? !0 : s.length() / a >= ze;
774
- }
775
- export {
776
- rt as C,
777
- Xe as S,
778
- ot as a,
779
- at as b,
780
- st as c,
781
- it as d,
782
- Ke as e,
783
- nt as f,
784
- Qe as g,
785
- et as h,
786
- W as i,
787
- tt as n,
788
- Ye as p,
789
- Ue as r,
790
- Ze as u,
791
- He as w
792
- };