@nebula-spatial/studio 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +2 -0
  2. package/dist/assets/openusd_three_loader-DLiqJWUM.js +13769 -0
  3. package/dist/assets/usd-export-worker-BRxTLqer.js +182 -0
  4. package/dist/assets/usd-worker-DekqMsQv.js +1392 -0
  5. package/dist/{builders-BAXRR5o5.js → builders-lydx4-Rh.js} +1 -1
  6. package/dist/core/session-persistence-controller.d.ts +55 -0
  7. package/dist/doc/placement-policy.d.ts +4 -0
  8. package/dist/editor/editor.d.ts +3 -1
  9. package/dist/editor/index.d.ts +2 -0
  10. package/dist/editor/session-persistence.d.ts +54 -0
  11. package/dist/editor.js +727 -490
  12. package/dist/export-evidence-z2Ne7Trf.js +2387 -0
  13. package/dist/generalization.js +2 -2
  14. package/dist/index.d.ts +4 -2
  15. package/dist/index.js +314 -306
  16. package/dist/mjcf-visual-IOy-ucto.js +72 -0
  17. package/dist/mujoco-runtime-BYZnrvbR.js +467 -0
  18. package/dist/persist/indexeddb-store.d.ts +22 -2
  19. package/dist/persist/session.d.ts +22 -0
  20. package/dist/persist/snapshot.d.ts +24 -0
  21. package/dist/{physics-facts-tfQYyNTD.js → physics-facts-D-URIBrt.js} +8 -7
  22. package/dist/{placement-policy-DY_FNRDu.js → placement-policy-C6dV6Tf-.js} +161 -141
  23. package/dist/ports/persistence.d.ts +45 -1
  24. package/dist/project/contracts.d.ts +3 -0
  25. package/dist/remote-asset-resolver-D-UeyDMD.js +311 -0
  26. package/dist/{scene-graph-DBLKAhxa.js → scene-graph-DVOXjMmp.js} +2 -2
  27. package/dist/scene-session-PhoFXFCY.js +22006 -0
  28. package/dist/scene.js +2 -2
  29. package/dist/session-2bp8YOA4.js +963 -0
  30. package/dist/session-B3WbC7Y2.js +296 -0
  31. package/dist/session-B9kEf4xN.js +915 -0
  32. package/dist/session-DYThdzLZ.js +825 -0
  33. package/dist/studio/index.d.ts +5 -0
  34. package/dist/studio/indexeddb-persistence.d.ts +2 -0
  35. package/dist/studio/indexeddb-session-persistence.d.ts +11 -0
  36. package/dist/studio/scene-package-asset-sources.d.ts +14 -0
  37. package/dist/studio.js +1423 -1220
  38. package/dist/urdf-session-CRXL4bHf.js +1230 -0
  39. package/dist/usd-session-CTzInpNy.js +7385 -0
  40. package/dist/version.d.ts +1 -1
  41. package/dist/view/scene-session.d.ts +5 -1
  42. package/dist/wasm-module-DZn2AM1W.js +13 -0
  43. package/dist/xacro-IpPHTMYs.js +76 -0
  44. package/package.json +1 -1
  45. package/dist/asset-source-BExlEcRt.js +0 -444
  46. package/dist/assets/usd-export-worker-BsGubtAE.js +0 -1
  47. package/dist/editorial-BkAFWfbg.js +0 -83
  48. package/dist/export-evidence-B_0zRmb8.js +0 -5027
  49. package/dist/remote-asset-resolver-Cb8cfNmw.js +0 -136
  50. package/dist/scene-session-BV1HnxNh.js +0 -3506
@@ -0,0 +1,1392 @@
1
+ function Ie(e, t) {
2
+ return /^https?:$/.test(t.protocol) && e.origin === t.origin && !e.username && !e.password && e.pathname.startsWith(new URL(".", t).pathname);
3
+ }
4
+ function je(e, t) {
5
+ for (const n of e) for (const c of n.shaders) for (const i of Object.values(c.inputs)) {
6
+ if (!i || typeof i != "object" || Array.isArray(i)) continue;
7
+ const s = i, o = [s.path, s.url, s.resolvedPath].find((u) => typeof u == "string" && u);
8
+ !o || /^(?:data|blob):/i.test(o) || /\.mdl(?:[?#].*)?$/i.test(o) || t(s, o);
9
+ }
10
+ }
11
+ function Ve(e, t, n) {
12
+ const c = [];
13
+ try {
14
+ return je(e, (i, s) => {
15
+ if (t(s)) return;
16
+ const o = {};
17
+ for (const u of ["path", "resolvedPath", "url"])
18
+ u in i && (o[u] = i[u], delete i[u]);
19
+ c.push({ asset: i, values: o });
20
+ }), n();
21
+ } finally {
22
+ for (const { asset: i, values: s } of c) Object.assign(i, s);
23
+ }
24
+ }
25
+ const Ge = "E_ASSET_RESOURCE_NOT_FOUND", Ae = "E_ASSET_RESOURCE_INVALID", Be = "E_ASSET_FETCH", Fe = "E_ASSET_EXTERNAL_DENIED", ze = "E_ASSET_AUTH", He = /* @__PURE__ */ new Set([
26
+ "png",
27
+ "jpg",
28
+ "jpeg",
29
+ "webp",
30
+ "avif",
31
+ "gif",
32
+ "bmp",
33
+ "tga",
34
+ "dds",
35
+ "hdr",
36
+ "exr",
37
+ "ktx2"
38
+ ]), We = /* @__PURE__ */ new Set(["usd", "usda", "usdc", "usdz"]);
39
+ function Xe(e) {
40
+ var n;
41
+ return ((n = (e.split(/[?#]/, 1)[0] ?? e).split(".").pop()) == null ? void 0 : n.toLowerCase()) ?? "";
42
+ }
43
+ function qe(e) {
44
+ const t = Xe(e);
45
+ return He.has(t) && !We.has(t);
46
+ }
47
+ function Je(e, t) {
48
+ return Object.assign(new Error(e), { code: t });
49
+ }
50
+ function Ze(e) {
51
+ var c;
52
+ if (e instanceof Error && e.name === "AbortError") return "aborted";
53
+ const t = e == null ? void 0 : e.code;
54
+ if (t === Ge) return "missing";
55
+ if (t === Ae) return "invalid";
56
+ if (t === Be) return "unavailable";
57
+ if (t === ze || t === Fe) return "denied";
58
+ const n = (c = /\((\d{3})\)/.exec(e instanceof Error ? e.message : "")) == null ? void 0 : c[1];
59
+ return n === "404" || n === "410" ? "missing" : n === "401" || n === "403" ? "denied" : n != null && n.startsWith("5") ? "unavailable" : "unknown";
60
+ }
61
+ function Ye(e) {
62
+ const t = Ze(e);
63
+ return t === "missing" || t === "invalid" || t === "unavailable";
64
+ }
65
+ function Ke(e, t) {
66
+ return e && /\bhtml\b/i.test(e) ? `返回 HTML 页面(${e})` : e && !/^text\//i.test(e) ? null : /^\uFEFF?\s*(?:<!doctype\s+html|<html|<\?xml[^>]*\bhtml)/i.test(t) ? "返回 HTML 兜底页" : null;
67
+ }
68
+ function Qe(e, t) {
69
+ return t.byteLength ? Ke(e, new TextDecoder().decode(t.subarray(0, 512))) : "响应内容为空";
70
+ }
71
+ const et = /<UDIM>/i;
72
+ function tt(e, t) {
73
+ const n = _e(e).replaceAll("\\", "/");
74
+ if (!et.test(n)) return null;
75
+ const c = be(n), i = c.split("/").at(-1);
76
+ if (!i) return { paths: [], tiles: [] };
77
+ const s = nt(i);
78
+ if (!s) return { paths: [], tiles: [] };
79
+ const o = [];
80
+ for (const a of new Set(t)) {
81
+ const l = _e(a).replaceAll("\\", "/"), f = be(l), h = f.split("/").at(-1);
82
+ if (!h) continue;
83
+ const p = s.exec(h);
84
+ if (!p) continue;
85
+ const b = Number(p[1]);
86
+ !Number.isInteger(b) || b < 1001 || b > 9999 || o.push({
87
+ path: a,
88
+ tile: b,
89
+ score: rt(c, f)
90
+ });
91
+ }
92
+ if (!o.length) return { paths: [], tiles: [] };
93
+ const u = Math.max(...o.map((a) => a.score)), r = o.filter((a) => a.score === u).sort((a, l) => a.tile - l.tile || a.path.localeCompare(l.path));
94
+ return {
95
+ paths: r.map((a) => a.path),
96
+ tiles: r.map((a) => a.tile)
97
+ };
98
+ }
99
+ function nt(e) {
100
+ const t = e.split(/<UDIM>/i);
101
+ return t.length !== 2 ? null : new RegExp(`^${Se(t[0])}(\\d{4})${Se(t[1])}$`, "i");
102
+ }
103
+ function rt(e, t) {
104
+ const n = e.split("/").slice(0, -1).filter(Boolean), c = t.split("/").slice(0, -1).filter(Boolean);
105
+ let i = 0;
106
+ for (; i < n.length && i < c.length; ) {
107
+ const s = n.at(-1 - i), o = c.at(-1 - i);
108
+ if ((s == null ? void 0 : s.toLowerCase()) !== (o == null ? void 0 : o.toLowerCase())) break;
109
+ i += 1;
110
+ }
111
+ return i;
112
+ }
113
+ function _e(e) {
114
+ const t = e.replace(/%3CUDIM%3E/gi, "<UDIM>");
115
+ try {
116
+ return decodeURIComponent(t);
117
+ } catch {
118
+ return t;
119
+ }
120
+ }
121
+ function be(e) {
122
+ const t = e.search(/[?#]/);
123
+ return t < 0 ? e : e.slice(0, t);
124
+ }
125
+ function Se(e) {
126
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
127
+ }
128
+ const st = 67324752, ot = 33639248, at = 101010256, ue = 4294967295, it = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "webp"]);
129
+ function ct(e) {
130
+ return e.length > 3 && e[0] === 80 && e[1] === 75;
131
+ }
132
+ async function ut(e, t = {}) {
133
+ const n = new DataView(e.buffer, e.byteOffset, e.byteLength), c = gt(n);
134
+ if (c < 0) throw new Error("Not a zip package: end of central directory not found.");
135
+ const i = n.getUint16(c + 10, !0);
136
+ let s = n.getUint32(c + 16, !0);
137
+ if (i === 65535 || s === ue) throw new Error("ZIP64 usdz packages are not supported.");
138
+ const o = /* @__PURE__ */ new Map(), u = [];
139
+ for (let r = 0; r < i; r += 1) {
140
+ if (s + 46 > n.byteLength || n.getUint32(s, !0) !== ot)
141
+ throw new Error(`Corrupt zip central directory at entry ${r}.`);
142
+ const a = n.getUint16(s + 10, !0), l = n.getUint32(s + 20, !0), f = n.getUint16(s + 28, !0), h = n.getUint16(s + 30, !0), p = n.getUint16(s + 32, !0), b = n.getUint32(s + 42, !0);
143
+ if (l === ue || b === ue)
144
+ throw new Error("ZIP64 usdz packages are not supported.");
145
+ const v = new TextDecoder().decode(e.subarray(s + 46, s + 46 + f));
146
+ s += 46 + f + h + p, !v.endsWith("/") && (t.include && !t.include(v) || u.push(dt(e, n, b, l, a).then((S) => ({ name: v, data: S }))));
147
+ }
148
+ for (const { name: r, data: a } of await Promise.all(u)) o.set(r, a);
149
+ return o;
150
+ }
151
+ function lt(e) {
152
+ if (typeof URL > "u" || typeof URL.createObjectURL != "function") return null;
153
+ const t = new Map([...e].filter(([o]) => Me(o)));
154
+ if (t.size === 0) return null;
155
+ const n = /* @__PURE__ */ new Map();
156
+ for (const o of t.keys()) {
157
+ const u = o.split("/").pop() ?? o;
158
+ n.set(u, n.has(u) ? null : o);
159
+ }
160
+ const c = /* @__PURE__ */ new Map(), i = (o) => {
161
+ let u = c.get(o);
162
+ if (!u) {
163
+ const r = t.get(o);
164
+ u = URL.createObjectURL(new Blob([new Uint8Array(r)], { type: pt(o) })), c.set(o, u);
165
+ }
166
+ return u;
167
+ }, s = (o) => {
168
+ if (!o) return null;
169
+ const u = ht(ft(o));
170
+ if (!u) return null;
171
+ if (t.has(u)) return i(u);
172
+ const r = [...t.keys()].filter((f) => f.endsWith(`/${u}`));
173
+ if (r.length === 1) return i(r[0]);
174
+ const a = [...t.keys()].filter((f) => u.endsWith(`/${f}`));
175
+ if (a.length === 1) return i(a[0]);
176
+ const l = n.get(u.split("/").pop() ?? "");
177
+ return l ? i(l) : null;
178
+ };
179
+ for (const o of t.keys()) i(o);
180
+ return {
181
+ urls: c,
182
+ resolve: (o) => s(o.resolvedPath) ?? s(o.path) ?? s(o.url) ?? null,
183
+ dispose: () => {
184
+ for (const o of c.values()) URL.revokeObjectURL(o);
185
+ c.clear();
186
+ }
187
+ };
188
+ }
189
+ function Me(e) {
190
+ return it.has(Ne(e));
191
+ }
192
+ async function dt(e, t, n, c, i) {
193
+ if (t.getUint32(n, !0) !== st) throw new Error("Corrupt zip local file header.");
194
+ const s = t.getUint16(n + 26, !0), o = t.getUint16(n + 28, !0), u = n + 30 + s + o, r = e.subarray(u, u + c);
195
+ if (i === 0) return r.slice();
196
+ if (i !== 8) throw new Error(`Unsupported zip compression method ${i}.`);
197
+ const a = new Blob([new Uint8Array(r)]).stream().pipeThrough(new DecompressionStream("deflate-raw"));
198
+ return new Uint8Array(await new Response(a).arrayBuffer());
199
+ }
200
+ function ft(e) {
201
+ const t = e.indexOf("[");
202
+ return t >= 0 && e.endsWith("]") ? e.slice(t + 1, -1) : e;
203
+ }
204
+ function ht(e) {
205
+ const t = [];
206
+ for (const n of e.replaceAll("\\", "/").split("/"))
207
+ !n || n === "." || (n === ".." ? t.pop() : t.push(n));
208
+ return t.join("/");
209
+ }
210
+ function Ne(e) {
211
+ const t = e.split(/[?#]/)[0] ?? e, n = t.lastIndexOf(".");
212
+ return n < 0 ? "" : t.slice(n + 1).toLowerCase();
213
+ }
214
+ function pt(e) {
215
+ switch (Ne(e)) {
216
+ case "png":
217
+ return "image/png";
218
+ case "jpg":
219
+ case "jpeg":
220
+ return "image/jpeg";
221
+ case "webp":
222
+ return "image/webp";
223
+ default:
224
+ return "application/octet-stream";
225
+ }
226
+ }
227
+ function gt(e) {
228
+ const t = Math.max(0, e.byteLength - 65535 - 22);
229
+ for (let n = e.byteLength - 22; n >= t; n -= 1)
230
+ if (e.getUint32(n, !0) === at) return n;
231
+ return -1;
232
+ }
233
+ const mt = 1, wt = 1, yt = "9590c7fb3e7636719062", _t = {
234
+ file: "openusd_probe.js",
235
+ sha256: "83a14d264f2348a0899de8f1bc0c021fdcd8cae554ef545fb9e5b88da6f30b4e",
236
+ bytes: 95918
237
+ }, bt = {
238
+ file: "openusd_probe.wasm",
239
+ sha256: "e5fdec65f543d38b9ab956b7698fbd597cd7c49c0f8dbd13f334086a59c9670f",
240
+ bytes: 10652138
241
+ };
242
+ var St = {
243
+ schemaVersion: mt,
244
+ apiVersion: wt,
245
+ runtimeId: yt,
246
+ js: _t,
247
+ wasm: bt
248
+ };
249
+ const Ut = Et(St);
250
+ function Et(e) {
251
+ if (!e || typeof e != "object") throw new Error("OpenUSD runtime manifest is missing.");
252
+ const t = e;
253
+ if (t.schemaVersion !== 1 || !Number.isInteger(t.apiVersion) || Number(t.apiVersion) < 1 || typeof t.runtimeId != "string" || !/^[0-9a-f]{20}$/.test(t.runtimeId))
254
+ throw new Error("OpenUSD runtime manifest metadata is invalid.");
255
+ return Object.freeze({
256
+ schemaVersion: t.schemaVersion,
257
+ apiVersion: Number(t.apiVersion),
258
+ runtimeId: t.runtimeId,
259
+ js: Ue(t.js, "openusd_probe.js"),
260
+ wasm: Ue(t.wasm, "openusd_probe.wasm")
261
+ });
262
+ }
263
+ function Ue(e, t) {
264
+ if (!e || typeof e != "object") throw new Error(`OpenUSD runtime manifest omits ${t}.`);
265
+ const n = e;
266
+ if (n.file !== t || typeof n.sha256 != "string" || !/^[0-9a-f]{64}$/.test(n.sha256) || !Number.isInteger(n.bytes) || Number(n.bytes) < 1)
267
+ throw new Error(`OpenUSD runtime manifest is invalid for ${t}.`);
268
+ return Object.freeze({
269
+ file: t,
270
+ sha256: n.sha256,
271
+ bytes: Number(n.bytes)
272
+ });
273
+ }
274
+ function Pt(e, t, n) {
275
+ return WebAssembly.instantiate(e, t).then(
276
+ (c) => n(c, e),
277
+ (c) => {
278
+ setTimeout(() => {
279
+ throw c;
280
+ });
281
+ }
282
+ ), {};
283
+ }
284
+ function Te(e, t) {
285
+ const n = async (s, o) => {
286
+ var r;
287
+ const u = e.GetPrimAtPath(s);
288
+ try {
289
+ return o(u);
290
+ } finally {
291
+ (r = u == null ? void 0 : u.delete) == null || r.call(u);
292
+ }
293
+ }, c = (s, o) => {
294
+ var r, a, l, f;
295
+ const u = (r = s == null ? void 0 : s.GetAttribute) == null ? void 0 : r.call(s, o);
296
+ if (!u) return [];
297
+ try {
298
+ return ((a = u.IsValid) == null ? void 0 : a.call(u)) !== !0 ? [] : (((l = u.GetConnections) == null ? void 0 : l.call(u)) ?? []).map((h) => {
299
+ var b, v;
300
+ if (typeof h == "string") return h;
301
+ const p = String(((b = h.GetString) == null ? void 0 : b.call(h)) ?? h.path ?? "");
302
+ return (v = h.delete) == null || v.call(h), p;
303
+ }).filter(Boolean);
304
+ } finally {
305
+ (f = u.delete) == null || f.call(u);
306
+ }
307
+ }, i = (s) => {
308
+ var u;
309
+ const o = s && ((u = t.UsdShade) != null && u.ComputeBoundMaterialPath) ? t.UsdShade.ComputeBoundMaterialPath(s) : null;
310
+ return o ? {
311
+ found: !0,
312
+ materialPath: String(o.materialPath ?? ""),
313
+ resolvedTargetPath: String(o.resolvedTargetPath ?? ""),
314
+ bindingRelationshipPath: String(o.bindingRelationshipPath ?? "")
315
+ } : { found: !1, materialPath: "", resolvedTargetPath: "", bindingRelationshipPath: "" };
316
+ };
317
+ return {
318
+ async stageMetadata(s) {
319
+ var u;
320
+ const o = e.GetPseudoRoot();
321
+ try {
322
+ const r = o.GetMetadata(s);
323
+ return { valid: !0, found: r != null, value: r };
324
+ } finally {
325
+ (u = o.delete) == null || u.call(o);
326
+ }
327
+ },
328
+ async primInfo(s) {
329
+ return n(s, (o) => {
330
+ var u, r, a, l;
331
+ return {
332
+ valid: !!o && ((u = o.IsValid) == null ? void 0 : u.call(o)) !== !1,
333
+ name: String(((r = o.GetName) == null ? void 0 : r.call(o)) ?? s.split("/").pop() ?? ""),
334
+ path: s,
335
+ typeName: String(((a = o.GetTypeName) == null ? void 0 : a.call(o)) ?? ""),
336
+ instance: ((l = o.IsInstance) == null ? void 0 : l.call(o)) === !0
337
+ };
338
+ });
339
+ },
340
+ async primChildren(s) {
341
+ return n(s, (o) => {
342
+ var u;
343
+ return (((u = o.GetChildren) == null ? void 0 : u.call(o)) ?? []).map((r) => {
344
+ var l, f;
345
+ const a = String(r.__path ?? ((l = r.GetPath) == null ? void 0 : l.call(r)) ?? "");
346
+ return (f = r.delete) == null || f.call(r), a;
347
+ });
348
+ });
349
+ },
350
+ async primDescendants(s, o = "") {
351
+ var u;
352
+ return (((u = e.GetDescendants) == null ? void 0 : u.call(e, s, o)) ?? []).map(String);
353
+ },
354
+ async primAttributes(s) {
355
+ return n(s, (o) => {
356
+ var u;
357
+ return (((u = o.GetAttributes) == null ? void 0 : u.call(o)) ?? []).map((r) => {
358
+ var l, f;
359
+ const a = String(((l = r.GetName) == null ? void 0 : l.call(r)) ?? "");
360
+ return (f = r.delete) == null || f.call(r), a;
361
+ });
362
+ });
363
+ },
364
+ async primMetadata(s, o) {
365
+ return n(s, (u) => {
366
+ var l;
367
+ const r = (l = u == null ? void 0 : u.GetMetadata) == null ? void 0 : l.call(u, o), a = typeof r == "string" ? r : r && typeof r == "object" && typeof r.string == "string" ? String(r.string) : void 0;
368
+ return {
369
+ valid: !0,
370
+ found: r != null,
371
+ ...r != null ? { value: r } : {},
372
+ ...a !== void 0 ? { text: a } : {}
373
+ };
374
+ });
375
+ },
376
+ async relationshipTargets(s, o) {
377
+ return n(s, (u) => {
378
+ var a, l, f;
379
+ const r = (a = u == null ? void 0 : u.GetRelationship) == null ? void 0 : a.call(u, o);
380
+ if (!r) return [];
381
+ try {
382
+ return (((l = r.GetTargets) == null ? void 0 : l.call(r)) ?? []).map((h) => {
383
+ var p;
384
+ return typeof h == "string" ? h : String(((p = h.GetString) == null ? void 0 : p.call(h)) ?? h.path ?? "");
385
+ }).filter(Boolean);
386
+ } finally {
387
+ (f = r.delete) == null || f.call(r);
388
+ }
389
+ });
390
+ },
391
+ async attributeValue(s, o) {
392
+ return n(s, (u) => {
393
+ var a, l, f, h;
394
+ const r = (a = u == null ? void 0 : u.GetAttribute) == null ? void 0 : a.call(u, o);
395
+ if (!r) return { valid: !1, authored: !1, value: null };
396
+ try {
397
+ const p = ((l = r.IsValid) == null ? void 0 : l.call(r)) === !0;
398
+ return {
399
+ valid: p,
400
+ authored: p && ((f = r.HasAuthoredValue) == null ? void 0 : f.call(r)) === !0,
401
+ value: p ? r.Get() : null
402
+ };
403
+ } finally {
404
+ (h = r.delete) == null || h.call(r);
405
+ }
406
+ });
407
+ },
408
+ async attributeValues(s) {
409
+ const o = {};
410
+ for (const u of s)
411
+ o[u.path] = await n(u.path, (r) => Object.fromEntries(
412
+ u.names.map((a) => {
413
+ var f, h, p, b;
414
+ const l = (f = r == null ? void 0 : r.GetAttribute) == null ? void 0 : f.call(r, a);
415
+ if (!l) return [a, { valid: !1, authored: !1, value: null }];
416
+ try {
417
+ const v = ((h = l.IsValid) == null ? void 0 : h.call(l)) === !0;
418
+ return [a, {
419
+ valid: v,
420
+ authored: v && ((p = l.HasAuthoredValue) == null ? void 0 : p.call(l)) === !0,
421
+ value: v ? l.Get() : null
422
+ }];
423
+ } finally {
424
+ (b = l.delete) == null || b.call(l);
425
+ }
426
+ })
427
+ ));
428
+ return o;
429
+ },
430
+ async attributeMetadata(s, o, u) {
431
+ return n(s, (r) => {
432
+ var l, f, h;
433
+ const a = (l = r == null ? void 0 : r.GetAttribute) == null ? void 0 : l.call(r, o);
434
+ if (!a) return { valid: !1, found: !1 };
435
+ try {
436
+ if (((f = a.IsValid) == null ? void 0 : f.call(a)) !== !0) return { valid: !1, found: !1 };
437
+ const p = a.GetMetadata(u);
438
+ return {
439
+ valid: !0,
440
+ found: p != null,
441
+ ...p != null ? { value: p } : {}
442
+ };
443
+ } finally {
444
+ (h = a.delete) == null || h.call(a);
445
+ }
446
+ });
447
+ },
448
+ async attributeConnections(s, o) {
449
+ return n(s, (u) => c(u, o));
450
+ },
451
+ async boundMaterial(s) {
452
+ return n(s, i);
453
+ }
454
+ };
455
+ }
456
+ const vt = /^physics$/i, xt = /^(newton|mjc|mujoco)(?:[_-]|$)/i, Rt = /^(physx|newton|mjc|mujoco)(?:[_-]|)/i;
457
+ function It(e, t = []) {
458
+ const n = new Set(t.map(Ee)), c = [];
459
+ for (const i of e) {
460
+ if (!vt.test(i.setName) || n.has(Ee(i))) continue;
461
+ const s = i.variantNames.map((r, a) => ({ selection: r, index: a, rank: At(r) })).filter((r) => r.rank !== null);
462
+ if (s.length === 0 || i.selection && xt.test(i.selection)) continue;
463
+ const o = le(i.selection), u = [...s].sort((r, a) => {
464
+ const l = o !== null && le(r.selection) === o, f = o !== null && le(a.selection) === o;
465
+ return Number(f) - Number(l) || r.rank - a.rank || r.index - a.index;
466
+ })[0];
467
+ c.push({
468
+ primPath: i.primPath,
469
+ setName: i.setName,
470
+ selection: u.selection
471
+ });
472
+ }
473
+ return c;
474
+ }
475
+ function At(e) {
476
+ return /^newton(?:[_-]|$)/i.test(e) ? 0 : /^mjc(?:[_-]|$)/i.test(e) ? 1 : /^mujoco(?:[_-]|$)/i.test(e) ? 2 : null;
477
+ }
478
+ function le(e) {
479
+ return e && e.replace(Rt, "").toLowerCase() || null;
480
+ }
481
+ function Ee(e) {
482
+ return `${e.primPath}\0${e.setName}`;
483
+ }
484
+ const Mt = [
485
+ 1,
486
+ 0,
487
+ 0,
488
+ 0,
489
+ 0,
490
+ 1,
491
+ 0,
492
+ 0,
493
+ 0,
494
+ 0,
495
+ 1,
496
+ 0,
497
+ 0,
498
+ 0,
499
+ 0,
500
+ 1
501
+ ];
502
+ function Nt(e) {
503
+ const t = new Map(e.map((s) => [s.path, s])), n = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set(), i = (s) => {
504
+ const o = n.get(s.path);
505
+ if (o) return o;
506
+ if (c.has(s.path)) return Pe(s.localMatrix);
507
+ c.add(s.path);
508
+ const u = Pe(s.localMatrix), r = s.parentPath ? t.get(s.parentPath) : void 0, a = !r || s.resetsXformStack ? u : ve(u, i(r));
509
+ return c.delete(s.path), n.set(s.path, a), a;
510
+ };
511
+ return e.map((s) => {
512
+ if (!s.resetsXformStack || !s.parentPath) return s;
513
+ const o = t.get(s.parentPath);
514
+ if (!o) return s;
515
+ const u = i(o), r = Dt(u);
516
+ return r ? {
517
+ ...s,
518
+ localMatrix: ve(i(s), r)
519
+ } : s;
520
+ });
521
+ }
522
+ function Pe(e) {
523
+ return Tt(e) ? e : Mt;
524
+ }
525
+ function Tt(e) {
526
+ return (e == null ? void 0 : e.length) === 16 && e.every(Number.isFinite);
527
+ }
528
+ function ve(e, t) {
529
+ const n = new Array(16);
530
+ for (let c = 0; c < 4; c++)
531
+ for (let i = 0; i < 4; i++) {
532
+ let s = 0;
533
+ for (let o = 0; o < 4; o++)
534
+ s += e[c * 4 + o] * t[o * 4 + i];
535
+ n[c * 4 + i] = s;
536
+ }
537
+ return n;
538
+ }
539
+ function Dt(e) {
540
+ const [
541
+ t,
542
+ n,
543
+ c,
544
+ ,
545
+ i,
546
+ s,
547
+ o,
548
+ ,
549
+ u,
550
+ r,
551
+ a,
552
+ ,
553
+ l,
554
+ f,
555
+ h
556
+ ] = e, p = s * a - o * r, b = c * r - n * a, v = n * o - c * s, S = t * p + i * b + u * v, d = Math.max(
557
+ Math.abs(t * s * a),
558
+ Math.abs(t * o * r),
559
+ Math.abs(n * i * a),
560
+ Math.abs(n * o * u),
561
+ Math.abs(c * i * r),
562
+ Math.abs(c * s * u),
563
+ 1
564
+ );
565
+ if (!Number.isFinite(S) || Math.abs(S) <= Number.EPSILON * d * 16)
566
+ return null;
567
+ const m = 1 / S, y = p * m, A = b * m, M = v * m, T = (o * u - i * a) * m, $ = (t * a - c * u) * m, L = (c * i - t * o) * m, C = (i * r - s * u) * m, z = (n * u - t * r) * m, w = (t * s - n * i) * m;
568
+ return [
569
+ y,
570
+ A,
571
+ M,
572
+ 0,
573
+ T,
574
+ $,
575
+ L,
576
+ 0,
577
+ C,
578
+ z,
579
+ w,
580
+ 0,
581
+ -(l * y + f * T + h * C),
582
+ -(l * A + f * $ + h * z),
583
+ -(l * M + f * L + h * w),
584
+ 1
585
+ ];
586
+ }
587
+ function Ot(e, t = []) {
588
+ return {
589
+ stage: e.stage,
590
+ view: {
591
+ ...e.view,
592
+ prims: Nt(e.view.prims)
593
+ },
594
+ elements: e.elements,
595
+ materials: e.materials,
596
+ materialAliases: e.materialAliases,
597
+ physics: $t(),
598
+ joints: [],
599
+ cameras: [],
600
+ lights: [],
601
+ skels: e.skels,
602
+ animations: e.animations,
603
+ variants: t
604
+ };
605
+ }
606
+ function kt(e, t) {
607
+ e.physics = t.physics, e.joints = t.joints;
608
+ }
609
+ function $t() {
610
+ return {
611
+ scenes: [],
612
+ rigidBodies: [],
613
+ colliders: [],
614
+ materials: [],
615
+ articulationRoots: []
616
+ };
617
+ }
618
+ const Lt = /* @__PURE__ */ new Set(["usd", "usda", "usdc", "usdz"]);
619
+ async function Ct(e) {
620
+ const t = await import(
621
+ /* @vite-ignore */
622
+ e.moduleUrl
623
+ ), n = t.default ?? t.createOpenUsdProbe, c = e.wasmModule ? {
624
+ instantiateWasm(S, d) {
625
+ return Pt(e.wasmModule, S, d);
626
+ }
627
+ } : {
628
+ wasmBinary: await (typeof e.wasmBinary == "function" ? e.wasmBinary() : e.wasmBinary ?? Xt(e.wasmUrl))
629
+ }, i = await n(c), s = e.apiVersion ?? Ut.apiVersion, o = Number(i.ccall("usd_probe_api_version", "number", [], []));
630
+ if (o !== s)
631
+ throw Object.assign(
632
+ new Error(`OpenUSD runtime API mismatch: expected ${s}, received ${o}.`),
633
+ { code: "E_USD_RUNTIME_VERSION" }
634
+ );
635
+ const u = e.memfsRoot ?? "/asset", r = e.fetchBytes ?? (async (S) => {
636
+ const d = await fetch(S);
637
+ if (!d.ok) throw Object.assign(new Error(`USD resource request failed (${d.status}): ${S}`), {
638
+ code: d.status === 401 || d.status === 403 ? "E_ASSET_AUTH" : "E_ASSET_FETCH"
639
+ });
640
+ const m = new Uint8Array(await d.arrayBuffer()), y = Qe(d.headers.get("content-type"), m);
641
+ if (y) throw Je(`USD resource is not usable (${y}): ${S}`, Ae);
642
+ return m;
643
+ }), a = (S, d, m) => JSON.parse(i.ccall(S, "string", d, m)), l = /* @__PURE__ */ new Set(), f = xe(i);
644
+ let h = 0, p = null;
645
+ async function b() {
646
+ return p || (p = (async () => {
647
+ const S = `${u}/__viewer_warmup__`, d = `${S}/empty.usda`;
648
+ i.FS.mkdirTree(S), i.FS.writeFile(d, new TextEncoder().encode(`#usda 1.0
649
+ `));
650
+ let m;
651
+ try {
652
+ const y = a("usd_probe_stage_open", ["string"], [d]);
653
+ if (y.ok !== !0 || y.stageId === void 0)
654
+ throw new Error(y.error ?? "Failed to initialize the USD Stage runtime.");
655
+ m = y.stageId;
656
+ } finally {
657
+ m !== void 0 && a("usd_probe_stage_release", ["number"], [m]), i.FS.analyzePath(d, !0).exists && i.FS.unlink(d);
658
+ }
659
+ })(), p);
660
+ }
661
+ async function v(S, d) {
662
+ const m = new URL(d.sourcePath, "file:///"), y = `${u}/load-${++h}`, A = K(m.href, y), M = /* @__PURE__ */ new Set(), T = /* @__PURE__ */ new Map(), $ = /* @__PURE__ */ new Map(), L = d.readTextureBytes ?? !0, C = d.collectTextureUrls ?? !L, z = C || L ? De : Ht, w = /* @__PURE__ */ new Map();
663
+ let R, _ = null, H = null;
664
+ const G = () => {
665
+ R !== void 0 && l.delete(R) && a("usd_probe_stage_release", ["number"], [R]), _ == null || _.dispose(), $e(i.FS, y);
666
+ };
667
+ try {
668
+ const U = await Re(S);
669
+ pe(i, A, U, M), T.set(A, z(U));
670
+ for (const [g, P] of Object.entries(d.files ?? {})) {
671
+ const E = K(new URL(g, m).href, y), F = await Re(P);
672
+ M.has(E) || T.set(E, z(F)), pe(i, E, F, M);
673
+ }
674
+ const x = new Set(M), W = [...d.packagePaths ?? []];
675
+ for (const g of d.packagePaths ?? [])
676
+ x.add(K(new URL(g, m).href, y));
677
+ const oe = [...new Set(d.resourcePaths ?? [])], X = d.externalReferenceMode ?? "complete", j = ct(U) ? await ut(U, { include: Me }) : null;
678
+ let q = {};
679
+ if (!j && d.autoResolveAssets !== !1) {
680
+ const g = d.resolveBytes ?? ((P) => r(P));
681
+ q = await Bt(
682
+ i,
683
+ m,
684
+ y,
685
+ g,
686
+ a,
687
+ M,
688
+ w,
689
+ C ? $ : null,
690
+ T,
691
+ d.maxFiles ?? 1024,
692
+ d.maxDepth ?? 8,
693
+ d.maxConcurrency ?? 1,
694
+ X,
695
+ x,
696
+ W,
697
+ oe,
698
+ L,
699
+ d.onReferenceSkipped,
700
+ d.onResourceFailed
701
+ );
702
+ }
703
+ _ = j ? lt(j) : null;
704
+ const D = d.textureResolver || _ ? (g) => {
705
+ var P;
706
+ return ((P = d.textureResolver) == null ? void 0 : P.call(d, g)) ?? (_ == null ? void 0 : _.resolve(g)) ?? null;
707
+ } : void 0, J = Object.keys(q).length > 0;
708
+ if (J && typeof i._usd_probe_stage_open_mapped != "function")
709
+ throw Object.assign(new Error("USD dependency mapping requires the matching packaged openusd_probe.js and .wasm runtime."), { code: "E_USD_RUNTIME_VERSION" });
710
+ const I = J ? a("usd_probe_stage_open_mapped", ["string", "string"], [A, JSON.stringify(q)]) : a("usd_probe_stage_open", ["string"], [A]);
711
+ if (!I.ok) throw new Error(I.error ?? `Failed to open ${A}`);
712
+ R = I.stageId, l.add(I.stageId);
713
+ const B = d.variantSelections ?? [];
714
+ let V = [], O = B;
715
+ if (d.selectMuJoCoPhysicsVariant !== !1) {
716
+ if (typeof i._usd_probe_stage_variants != "function")
717
+ throw Object.assign(
718
+ new Error("USD variant discovery requires the matching packaged openusd_probe runtime."),
719
+ { code: "E_USD_RUNTIME_VERSION" }
720
+ );
721
+ const g = a("usd_probe_stage_variants", ["number"], [I.stageId]);
722
+ if (g.ok !== !0)
723
+ throw new Error(String(g.error ?? "Failed to enumerate USD variants."));
724
+ V = g.variants ?? [], O = [
725
+ ...B,
726
+ ...It(V, B)
727
+ ];
728
+ }
729
+ for (const g of O) {
730
+ const P = a(
731
+ "usd_probe_stage_set_variant",
732
+ ["number", "string", "string", "string"],
733
+ [I.stageId, g.primPath, g.setName, g.selection]
734
+ );
735
+ if (P.ok !== !0)
736
+ throw new Error(String(P.error ?? `Failed to select USD variant ${g.primPath}:${g.setName}=${g.selection}`));
737
+ }
738
+ const Z = xe(i, w), ae = Z.openStage(I.stageId);
739
+ if (d.selectMuJoCoPhysicsVariant !== !1) {
740
+ const g = new Set(B.map(fe)), P = /* @__PURE__ */ new Set();
741
+ for (const E of O) {
742
+ const F = fe(E);
743
+ if (g.has(F)) continue;
744
+ const k = V.find((ye) => ye.primPath === E.primPath && ye.setName === E.setName);
745
+ if (!(k != null && k.selection) || k.selection === E.selection || ae.GetDescendants(E.primPath, "MjcActuator").length === 0) continue;
746
+ const we = a(
747
+ "usd_probe_stage_set_variant",
748
+ ["number", "string", "string", "string"],
749
+ [I.stageId, E.primPath, E.setName, k.selection]
750
+ );
751
+ if (we.ok !== !0)
752
+ throw new Error(String(we.error ?? `Failed to restore authored USD variant ${E.primPath}:${E.setName}=${k.selection}`));
753
+ P.add(F);
754
+ }
755
+ P.size > 0 && (O = O.filter((E) => !P.has(fe(E))));
756
+ }
757
+ const ge = await jt(i, I.stageId, A, {
758
+ batchSize: d.geometryBatchSize,
759
+ onProgress: d.onGeometryProgress
760
+ });
761
+ ke(ge.materials, w);
762
+ const Le = new Map(O.map((g) => [
763
+ `${g.primPath}\0${g.setName}`,
764
+ g.selection
765
+ ])), Ce = V.map((g) => ({
766
+ ...g,
767
+ selection: Le.get(`${g.primPath}\0${g.setName}`) ?? g.selection
768
+ })), ce = Ot(ge, Ce), me = j ? void 0 : d.isTextureAllowed ?? (X === "package" ? (g) => {
769
+ const P = new URL(g, m);
770
+ return x.has(K(P.href, y)) || Ie(P, m);
771
+ } : void 0);
772
+ return {
773
+ data: ce,
774
+ pxr: Z,
775
+ stage: ae,
776
+ entryPath: A,
777
+ textureURLs: $,
778
+ buildModel: async () => {
779
+ const { createUSDLoadedModel: g } = await import("./openusd_three_loader-DLiqJWUM.js"), P = () => g(
780
+ ce,
781
+ Z,
782
+ A,
783
+ {
784
+ sourcePath: d.sourcePath,
785
+ // The Viewer normalises USD to world Z-up and draws its own studio
786
+ // lighting. Textures remain enabled unless the host explicitly
787
+ // injects its own loader/cache.
788
+ convertZUp: d.convertZUp ?? !1,
789
+ loadLights: d.loadLights ?? !1,
790
+ loadTextures: d.loadTextures ?? !0,
791
+ ...d.textureLoader ? { textureLoader: d.textureLoader } : {},
792
+ ...d.textureCache ? { textureCache: d.textureCache } : {},
793
+ ...D ? { textureResolver: D } : {}
794
+ },
795
+ ae,
796
+ {
797
+ // Keep package texture identities on the model so the visual adapter
798
+ // can resolve textures referenced by unsupported-but-known MDL nodes.
799
+ usdzTextureURLs: (_ == null ? void 0 : _.urls) ?? /* @__PURE__ */ new Map(),
800
+ autoTextureURLs: /* @__PURE__ */ new Map()
801
+ }
802
+ ), E = me ? Ve(ce.materials, me, P) : P();
803
+ E.usdQuery = Te(ae, Z);
804
+ const F = E.dispose.bind(E);
805
+ let k = !1;
806
+ return E.dispose = () => {
807
+ k || (k = !0, F(), G());
808
+ }, E;
809
+ },
810
+ readPhysics() {
811
+ return H || (H = (async () => {
812
+ if (typeof i._usd_probe_scene_physics != "function")
813
+ throw Object.assign(
814
+ new Error("USD physics phase requires the matching packaged openusd_probe runtime."),
815
+ { code: "E_USD_RUNTIME_VERSION" }
816
+ );
817
+ const g = a("usd_probe_scene_physics", ["number"], [I.stageId]);
818
+ if (g.ok !== !0) throw new Error(String(g.error ?? "Failed to extract USD physics."));
819
+ return g;
820
+ })(), H);
821
+ },
822
+ release: G
823
+ };
824
+ } catch (U) {
825
+ throw G(), U;
826
+ }
827
+ }
828
+ return {
829
+ runtime: i,
830
+ pxr: f,
831
+ warmup: b,
832
+ async parseAsync(S, d) {
833
+ const m = await v(S, d);
834
+ try {
835
+ return kt(m.data, await m.readPhysics()), await m.buildModel();
836
+ } catch (y) {
837
+ throw m.release(), y;
838
+ }
839
+ },
840
+ async parseVisualSceneAsync(S, d) {
841
+ return await v(S, d);
842
+ }
843
+ };
844
+ }
845
+ function xe(e, t = /* @__PURE__ */ new Map()) {
846
+ const n = (r, a, l) => JSON.parse(e.ccall(r, "string", a, l));
847
+ class c {
848
+ constructor(a) {
849
+ this.path = a;
850
+ }
851
+ delete() {
852
+ }
853
+ }
854
+ const i = (r, a, l) => {
855
+ let f = null;
856
+ const h = () => f ?? (f = n(
857
+ "usd_probe_attribute_value",
858
+ ["number", "string", "string"],
859
+ [r, a, l]
860
+ ));
861
+ return {
862
+ IsValid: () => h().valid === !0,
863
+ Get: () => {
864
+ const p = h();
865
+ return p.valid === !0 ? typeof p.value == "string" ? t.get(p.value) ?? p.value : p.value : null;
866
+ },
867
+ HasAuthoredValue: () => h().authored === !0,
868
+ GetName: () => l,
869
+ GetMetadata: (p) => {
870
+ const b = n("usd_probe_attribute_metadata", ["number", "string", "string", "string"], [r, a, l, p]);
871
+ return b.valid === !0 && b.found === !0 ? b.value ?? null : null;
872
+ },
873
+ // The viewer accepts either plain strings or objects with GetString().
874
+ GetConnections: () => n("usd_probe_attribute_connections", ["number", "string", "string"], [r, a, l]).paths ?? [],
875
+ delete: () => {
876
+ }
877
+ };
878
+ }, s = (r, a) => ({
879
+ __path: a,
880
+ __stageId: r,
881
+ IsValid: () => n("usd_probe_prim_info", ["number", "string"], [r, a]).valid === !0,
882
+ GetName: () => String(a.split("/").pop() ?? ""),
883
+ GetPath: () => new c(a),
884
+ GetTypeName: () => String(n("usd_probe_prim_info", ["number", "string"], [r, a]).typeName ?? ""),
885
+ IsInstance: () => n("usd_probe_prim_info", ["number", "string"], [r, a]).instance === !0,
886
+ GetAttribute: (l) => i(r, a, l),
887
+ GetAttributes: () => (n("usd_probe_prim_attributes", ["number", "string"], [r, a]).names ?? []).map((l) => i(r, a, l)),
888
+ GetChildren: () => (n("usd_probe_prim_children", ["number", "string"], [r, a]).paths ?? []).map((l) => s(r, l)),
889
+ GetRelationship: (l) => {
890
+ const f = n(
891
+ "usd_probe_relationship_targets",
892
+ ["number", "string", "string"],
893
+ [r, a, l]
894
+ ).paths ?? [];
895
+ return {
896
+ GetTargets: () => f.map((h) => new c(h)),
897
+ delete: () => {
898
+ }
899
+ };
900
+ },
901
+ GetMetadata: (l) => {
902
+ const f = n("usd_probe_prim_metadata", ["number", "string", "string"], [r, a, l]);
903
+ return f.valid !== !0 ? null : typeof f.text == "string" ? f.text : f.found === !0 ? f.value : null;
904
+ },
905
+ delete: () => {
906
+ }
907
+ }), o = (r) => ({
908
+ GetPrimAtPath: (a) => s(r, typeof a == "string" ? a : a.path),
909
+ GetPseudoRoot: () => Object.assign(s(r, "/"), {
910
+ // Stage-level metadata (metersPerUnit, upAxis, defaultPrim) is authored on
911
+ // the layer, not composed onto the pseudo-root prim.
912
+ GetMetadata: (a) => {
913
+ const l = n("usd_probe_stage_metadata", ["number", "string"], [r, a]);
914
+ return l.found === !0 ? l.value : null;
915
+ },
916
+ GetName: () => "",
917
+ IsValid: () => !0
918
+ }),
919
+ GetDescendants: (a, l = "") => n(
920
+ "usd_probe_prim_descendants",
921
+ ["number", "string", "string"],
922
+ [r, a, l]
923
+ ).paths ?? [],
924
+ delete: () => {
925
+ }
926
+ }), { FS: u } = e;
927
+ return {
928
+ FS: {
929
+ createDir: (r) => u.mkdirTree(r),
930
+ writeFile: (r, a) => u.writeFile(r, a),
931
+ exists: (r) => u.analyzePath(r, !0).exists,
932
+ listDir: (r) => u.readdir(r).filter((a) => a !== "." && a !== "..").map((a) => {
933
+ const l = `${r.replace(/\/+$/, "")}/${a}`;
934
+ return { path: l, name: a, isDir: u.isDir(u.stat(l).mode) };
935
+ }),
936
+ deleteFile: (r) => u.unlink(r),
937
+ deleteDir: (r) => u.rmdir(r)
938
+ },
939
+ Sdf: { Path: c },
940
+ Usd: { TimeCode: { Default: () => ({ delete: () => {
941
+ } }) } },
942
+ UsdShade: {
943
+ ComputeBoundMaterialPath: (r) => {
944
+ const a = n("usd_probe_bound_material", ["number", "string"], [r.__stageId, r.__path]);
945
+ return a.found !== !0 ? null : {
946
+ materialPath: String(a.materialPath ?? ""),
947
+ resolvedTargetPath: String(a.resolvedTargetPath ?? ""),
948
+ bindingRelationshipPath: String(a.bindingRelationshipPath ?? "")
949
+ };
950
+ }
951
+ },
952
+ UsdUtils: {
953
+ ExtractSanitizedExternalReferences: (r) => n("usd_probe_external_references", ["string"], [r]).paths ?? []
954
+ },
955
+ openStage: o
956
+ };
957
+ }
958
+ async function jt(e, t, n, c = {}) {
959
+ var u;
960
+ if (typeof e._usd_probe_scene_visual != "function" || typeof e._usd_probe_scene_geometry != "function" || typeof e._usd_probe_scene_geometry_end != "function")
961
+ throw Object.assign(
962
+ new Error("USD visual phases require the matching packaged openusd_probe runtime."),
963
+ { code: "E_USD_RUNTIME_VERSION" }
964
+ );
965
+ const i = JSON.parse(e.ccall(
966
+ "usd_probe_scene_visual",
967
+ "string",
968
+ ["number", "string"],
969
+ [t, n]
970
+ ));
971
+ if (i.error) throw new Error(i.error);
972
+ const s = i, o = Math.max(1, Math.floor(c.batchSize ?? 8));
973
+ try {
974
+ for (const [r, a] of s.elements.entries()) {
975
+ const f = a.geometry.streamIndex;
976
+ if (!Number.isInteger(f))
977
+ throw new Error(`USD scene geometry is missing a stream index for ${a.path}`);
978
+ const h = JSON.parse(e.ccall(
979
+ "usd_probe_scene_geometry",
980
+ "string",
981
+ ["number", "number"],
982
+ [t, f]
983
+ ));
984
+ if (!h.ok) throw new Error(h.error ?? `Failed to stream USD geometry for ${a.path}`);
985
+ a.geometry = Object.fromEntries(
986
+ Object.entries(h.geometry ?? {}).map(([p, b]) => [p, Gt(e, b)])
987
+ ), (u = c.onProgress) == null || u.call(c, r + 1, s.elements.length, a.path), (r + 1) % o === 0 && await Vt();
988
+ }
989
+ } finally {
990
+ e.ccall("usd_probe_scene_geometry_end", "string", ["number"], [t]);
991
+ }
992
+ return s;
993
+ }
994
+ function Vt() {
995
+ return new Promise((e) => setTimeout(e, 0));
996
+ }
997
+ function Gt(e, t) {
998
+ if (!t || typeof t != "object") return t ?? null;
999
+ const { ptr: n, length: c, kind: i } = t;
1000
+ return typeof n != "number" ? t : c ? (i === "i32" ? new Int32Array(e.HEAP32.buffer, n, c) : new Float32Array(e.HEAPF32.buffer, n, c)).slice() : i === "i32" ? new Int32Array() : new Float32Array();
1001
+ }
1002
+ async function Bt(e, t, n, c, i, s, o, u, r, a, l, f, h, p, b, v, S, d, m) {
1003
+ const y = {}, A = [.../* @__PURE__ */ new Set([
1004
+ ...b,
1005
+ ...v
1006
+ ])];
1007
+ let M = [
1008
+ { url: t, depth: 0, recurse: !0, absolute: !1, baseUrl: t }
1009
+ ];
1010
+ const T = /* @__PURE__ */ new Set(), $ = /* @__PURE__ */ new Set();
1011
+ for (; M.length; ) {
1012
+ const L = M;
1013
+ M = [];
1014
+ const C = [];
1015
+ for (const w of L) {
1016
+ const R = w.absolute ? w.url.href : de(w.url.href, t);
1017
+ if (!T.has(R)) {
1018
+ if (w.depth > l) throw new Error(`USD dependency depth limit exceeded (${l}): ${R}`);
1019
+ if (T.size >= a) throw new Error(`USD dependency limit exceeded (${a}).`);
1020
+ T.add(R), C.push({ item: w, identifier: R });
1021
+ }
1022
+ }
1023
+ M = (await Ft(
1024
+ C,
1025
+ Math.max(1, f),
1026
+ async ({ item: w, identifier: R }) => {
1027
+ const _ = K(w.url.href, n);
1028
+ if (!s.has(_) || w.absolute && !p.has(_)) {
1029
+ let U;
1030
+ try {
1031
+ U = await c(w.url, R, w.baseUrl);
1032
+ } catch (x) {
1033
+ if (!w.owner || !qe(R) || !Ye(x)) throw x;
1034
+ const W = `${n}/__unavailable__/${encodeURIComponent(R)}`;
1035
+ return y[w.owner.path][w.owner.reference] = W, o.set(W, R), m == null || m(R, x), [];
1036
+ }
1037
+ r.set(_, De(U)), pe(e, _, U, s);
1038
+ }
1039
+ if (o.set(_, R), !w.recurse) return [];
1040
+ if (y[_] ?? (y[_] = {}), r.get(_) === !1) return [];
1041
+ const H = i("usd_probe_external_references", ["string"], [_]).paths ?? [], G = [];
1042
+ for (const U of H) {
1043
+ if (!U || /^(?:data|blob):/i.test(U) || /\.mdl(?:[?#].*)?$/i.test(U)) continue;
1044
+ let x;
1045
+ try {
1046
+ x = new URL(U, w.url);
1047
+ } catch {
1048
+ continue;
1049
+ }
1050
+ const W = /^(?:[a-z][a-z\d+.-]*:|\/)/i.test(U), oe = K(x.href, n), X = tt(oe, A);
1051
+ if (X && X.paths.length > 0) {
1052
+ const I = `${n}/__deferred_udim__/${encodeURIComponent(U)}`;
1053
+ y[_][U] = I, o.set(I, U);
1054
+ for (const B of X.paths) {
1055
+ const V = new URL(B, w.url), O = w.absolute || /^(?:[a-z][a-z\d+.-]*:|\/)/i.test(B), Z = O ? V.href : de(V.href, t);
1056
+ T.has(Z) || G.push({
1057
+ url: V,
1058
+ depth: w.depth + 1,
1059
+ recurse: !1,
1060
+ absolute: O,
1061
+ baseUrl: w.url,
1062
+ owner: { path: _, reference: U }
1063
+ });
1064
+ }
1065
+ continue;
1066
+ }
1067
+ const j = oe, q = w.absolute || W, D = q ? x.href : de(x.href, t), J = w.recurse && zt(x.pathname);
1068
+ if (h === "package" && !p.has(j) && !Ie(x, t)) {
1069
+ const I = `${n}/__skipped__/${encodeURIComponent(D)}`;
1070
+ y[_][U] = I, o.set(I, D), $.has(D) || ($.add(D), d == null || d(D));
1071
+ continue;
1072
+ }
1073
+ if (!J && u && (u.set(D, x.href), u.set(U, x.href)), y[_][U] = j, !J && !S) {
1074
+ o.set(j, D);
1075
+ continue;
1076
+ }
1077
+ T.has(D) || G.push({
1078
+ url: x,
1079
+ depth: w.depth + 1,
1080
+ recurse: J,
1081
+ absolute: q,
1082
+ baseUrl: w.url,
1083
+ owner: { path: _, reference: U }
1084
+ });
1085
+ }
1086
+ return G;
1087
+ }
1088
+ )).flat();
1089
+ }
1090
+ return y;
1091
+ }
1092
+ async function Ft(e, t, n) {
1093
+ const c = new Array(e.length);
1094
+ let i = 0;
1095
+ const s = Array.from({ length: Math.min(t, e.length) }, async () => {
1096
+ for (; i < e.length; ) {
1097
+ const o = i++;
1098
+ c[o] = await n(e[o]);
1099
+ }
1100
+ });
1101
+ return await Promise.all(s), c;
1102
+ }
1103
+ function zt(e) {
1104
+ var n, c;
1105
+ const t = (c = (n = e.split(/[?#]/, 1)[0]) == null ? void 0 : n.split(".").pop()) == null ? void 0 : c.toLowerCase();
1106
+ return t != null && Lt.has(t);
1107
+ }
1108
+ function De(e) {
1109
+ return Oe(e) ? e.includes(64) : !0;
1110
+ }
1111
+ function Ht(e) {
1112
+ return Oe(e) ? Wt(e, [
1113
+ "subLayers",
1114
+ "references",
1115
+ "payload",
1116
+ "payloads",
1117
+ "clipAssetPaths"
1118
+ ]) : !0;
1119
+ }
1120
+ function Oe(e) {
1121
+ let t = e[0] === 239 && e[1] === 187 && e[2] === 191 ? 3 : 0;
1122
+ for (; t < e.length && t < 64 && /\s/.test(String.fromCharCode(e[t])); ) t += 1;
1123
+ return e[t] === 35 && e[t + 1] === 117 && e[t + 2] === 115 && e[t + 3] === 100 && e[t + 4] === 97;
1124
+ }
1125
+ function Wt(e, t) {
1126
+ const n = /* @__PURE__ */ new Map();
1127
+ let c = 1;
1128
+ for (const s of t) {
1129
+ const o = s.charCodeAt(0);
1130
+ n.set(o, [...n.get(o) ?? [], s]), c = Math.max(c, s.length);
1131
+ }
1132
+ const i = e.length - c;
1133
+ for (let s = 0; s <= i; ++s) {
1134
+ const o = n.get(e[s]);
1135
+ if (o)
1136
+ for (const u of o) {
1137
+ let r = !0;
1138
+ for (let a = 1; a < u.length; ++a)
1139
+ if (e[s + a] !== u.charCodeAt(a)) {
1140
+ r = !1;
1141
+ break;
1142
+ }
1143
+ if (r) return !0;
1144
+ }
1145
+ }
1146
+ return !1;
1147
+ }
1148
+ function de(e, t) {
1149
+ const n = new URL(e);
1150
+ if (n.protocol !== t.protocol || n.host !== t.host) return n.href;
1151
+ const c = new URL(".", t).pathname.split("/").filter(Boolean), i = n.pathname.split("/").filter(Boolean);
1152
+ let s = 0;
1153
+ for (; s < c.length && c[s] === i[s]; ) s++;
1154
+ const o = [...c.slice(s).map(() => ".."), ...i.slice(s)].join("/");
1155
+ return decodeURIComponent(o) + n.search + n.hash;
1156
+ }
1157
+ function K(e, t) {
1158
+ const n = new URL(e), c = encodeURIComponent(`${n.protocol}//${n.host}`);
1159
+ let i = n.pathname.split("/").map((s) => decodeURIComponent(s).replaceAll("/", "%2F").replaceAll("\\", "%5C")).join("/");
1160
+ if (n.search || n.hash) {
1161
+ const s = i.lastIndexOf("."), o = s > i.lastIndexOf("/") ? s : i.length;
1162
+ i = `${i.slice(0, o)}.__url_${encodeURIComponent(n.search + n.hash)}${i.slice(o)}`;
1163
+ }
1164
+ return `${t}/${c}${i}`;
1165
+ }
1166
+ function ke(e, t) {
1167
+ if (!e || typeof e != "object" || ArrayBuffer.isView(e)) return;
1168
+ const n = e;
1169
+ if (typeof n.path == "string" && typeof n.resolvedPath == "string") {
1170
+ for (const c of ["path", "resolvedPath"]) {
1171
+ const i = n[c];
1172
+ n[c] = t.get(i) ?? i;
1173
+ }
1174
+ return;
1175
+ }
1176
+ for (const c of Object.values(e)) ke(c, t);
1177
+ }
1178
+ function $e(e, t) {
1179
+ if (e.analyzePath(t).exists) {
1180
+ for (const n of e.readdir(t)) {
1181
+ if (n === "." || n === "..") continue;
1182
+ const c = `${t}/${n}`;
1183
+ e.isDir(e.stat(c).mode) ? $e(e, c) : e.unlink(c);
1184
+ }
1185
+ e.rmdir(t);
1186
+ }
1187
+ }
1188
+ function pe(e, t, n, c) {
1189
+ c.has(t) || (e.FS.mkdirTree(t.split("/").slice(0, -1).join("/") || "/"), e.FS.writeFile(t, n), c.add(t));
1190
+ }
1191
+ function fe(e) {
1192
+ return `${e.primPath}\0${e.setName}`;
1193
+ }
1194
+ async function Re(e) {
1195
+ return typeof e == "string" ? new TextEncoder().encode(e) : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(await e.arrayBuffer());
1196
+ }
1197
+ async function Xt(e) {
1198
+ if (!e) throw new Error("createSingleThreadUsd needs wasmUrl or wasmBinary.");
1199
+ return (await fetch(e)).arrayBuffer();
1200
+ }
1201
+ function qt(e) {
1202
+ if (e.length < 30) return null;
1203
+ const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (c, i) => {
1204
+ for (let s = 0; s < i.length; s += 1)
1205
+ if (e[c + s] !== i.charCodeAt(s)) return !1;
1206
+ return !0;
1207
+ };
1208
+ if (e[0] === 137 && n(1, "PNG") && n(12, "IHDR"))
1209
+ return Q(t.getUint32(16), t.getUint32(20));
1210
+ if (e[0] === 255 && e[1] === 216) {
1211
+ let c = 2;
1212
+ for (; c + 9 < e.length; ) {
1213
+ if (e[c] !== 255) return null;
1214
+ const i = e[c + 1], s = e[c + 2] << 8 | e[c + 3];
1215
+ if (i >= 192 && i <= 207 && i !== 196 && i !== 200 && i !== 204)
1216
+ return Q(
1217
+ e[c + 7] << 8 | e[c + 8],
1218
+ e[c + 5] << 8 | e[c + 6]
1219
+ );
1220
+ if (s < 2) return null;
1221
+ c += 2 + s;
1222
+ }
1223
+ return null;
1224
+ }
1225
+ if (n(0, "RIFF") && n(8, "WEBP")) {
1226
+ if (n(12, "VP8 "))
1227
+ return Q(
1228
+ t.getUint16(26, !0) & 16383,
1229
+ t.getUint16(28, !0) & 16383
1230
+ );
1231
+ if (n(12, "VP8L")) {
1232
+ const c = t.getUint32(21, !0);
1233
+ return Q((c & 16383) + 1, (c >>> 14 & 16383) + 1);
1234
+ }
1235
+ if (n(12, "VP8X")) {
1236
+ const c = (i) => e[i] | e[i + 1] << 8 | e[i + 2] << 16;
1237
+ return Q(c(24) + 1, c(27) + 1);
1238
+ }
1239
+ }
1240
+ return null;
1241
+ }
1242
+ function Jt(e, t) {
1243
+ const n = Math.max(e.width, e.height);
1244
+ if (t <= 0 || n <= t) return e;
1245
+ const c = t / n;
1246
+ return {
1247
+ width: Math.max(1, Math.round(e.width * c)),
1248
+ height: Math.max(1, Math.round(e.height * c))
1249
+ };
1250
+ }
1251
+ function Q(e, t) {
1252
+ return e > 0 && t > 0 ? { width: e, height: t } : null;
1253
+ }
1254
+ function Y(e) {
1255
+ return e instanceof Error ? {
1256
+ name: e.name,
1257
+ message: e.message,
1258
+ ...typeof e.code == "string" ? { code: e.code } : {},
1259
+ ...e.stack ? { stack: e.stack } : {}
1260
+ } : { name: "Error", message: String(e) };
1261
+ }
1262
+ const te = globalThis;
1263
+ let re = null, ee = null, se = null, ie = null, he = !1, Zt = 1;
1264
+ const ne = /* @__PURE__ */ new Map();
1265
+ function N(e, t) {
1266
+ te.postMessage(e, t);
1267
+ }
1268
+ function Yt(e, t, n) {
1269
+ const c = Zt++;
1270
+ return new Promise((i, s) => {
1271
+ ne.set(c, { resolve: i, reject: s }), N({
1272
+ type: "resource-request",
1273
+ id: c,
1274
+ url: e.href,
1275
+ identifier: t,
1276
+ ...n ? { baseUrl: n.href } : {}
1277
+ });
1278
+ });
1279
+ }
1280
+ function Kt(e) {
1281
+ return re ?? (re = Ct(e)), re;
1282
+ }
1283
+ function Qt(e) {
1284
+ const t = /* @__PURE__ */ new Set();
1285
+ for (const n of e.elements)
1286
+ for (const c of Object.values(n.geometry ?? {}))
1287
+ ArrayBuffer.isView(c) && t.add(c.buffer);
1288
+ return [...t];
1289
+ }
1290
+ async function en(e) {
1291
+ if (!se) throw new Error("USD worker has no live stage");
1292
+ const t = se[e.method];
1293
+ return { type: "query-result", id: e.id, value: await t.apply(se, e.args) };
1294
+ }
1295
+ async function tn(e, t) {
1296
+ if (typeof createImageBitmap != "function")
1297
+ throw new Error("This browser cannot decode USD textures in a worker.");
1298
+ const n = await fetch(e);
1299
+ if (!n.ok) throw new Error(`HTTP ${n.status} for ${e}`);
1300
+ const c = new Uint8Array(await n.arrayBuffer()), i = qt(c), s = {
1301
+ imageOrientation: "flipY",
1302
+ premultiplyAlpha: "none",
1303
+ colorSpaceConversion: "none"
1304
+ };
1305
+ if (i) {
1306
+ const o = Jt(i, Math.min(4096, Math.max(1, t)));
1307
+ (o.width !== i.width || o.height !== i.height) && (s.resizeWidth = o.width, s.resizeHeight = o.height, s.resizeQuality = "high");
1308
+ }
1309
+ return createImageBitmap(new Blob([c]), s);
1310
+ }
1311
+ te.onmessage = async (e) => {
1312
+ const t = e.data;
1313
+ if (t.type === "resource-result") {
1314
+ const n = ne.get(t.id);
1315
+ if (!n) return;
1316
+ ne.delete(t.id), t.error ? n.reject(Object.assign(new Error(t.error.message), {
1317
+ name: t.error.name,
1318
+ ...t.error.code ? { code: t.error.code } : {}
1319
+ })) : n.resolve(t.bytes ?? new Uint8Array());
1320
+ return;
1321
+ }
1322
+ if (t.type === "query") {
1323
+ try {
1324
+ N(await en(t));
1325
+ } catch (n) {
1326
+ N({ type: "error", id: t.id, error: Y(n) });
1327
+ }
1328
+ return;
1329
+ }
1330
+ if (t.type === "decode-texture") {
1331
+ try {
1332
+ const n = await tn(t.url, t.maxDimension);
1333
+ N({
1334
+ type: "texture-decoded",
1335
+ id: t.id,
1336
+ bitmap: n,
1337
+ width: n.width,
1338
+ height: n.height
1339
+ }, [n]);
1340
+ } catch (n) {
1341
+ N({ type: "error", id: t.id, error: Y(n) });
1342
+ }
1343
+ return;
1344
+ }
1345
+ if (t.type === "dispose") {
1346
+ for (const n of ne.values()) n.reject(new Error("USD worker disposed"));
1347
+ ne.clear(), ee == null || ee(), se = null, ie = null, he = !1, re = null, ee = null, te.close();
1348
+ return;
1349
+ }
1350
+ if (t.type === "extract-physics") {
1351
+ if (he || !ie) return;
1352
+ he = !0;
1353
+ try {
1354
+ N({ type: "physics-ready", phase: await ie() });
1355
+ } catch (n) {
1356
+ N({ type: "physics-failed", error: Y(n) });
1357
+ }
1358
+ return;
1359
+ }
1360
+ if (t.type === "prepare") {
1361
+ try {
1362
+ const n = await Kt(t.runtime);
1363
+ t.warmup && await n.warmup(), N({ type: "worker-ready" });
1364
+ } catch (n) {
1365
+ N({ type: "error", error: Y(n) }), te.close();
1366
+ }
1367
+ return;
1368
+ }
1369
+ try {
1370
+ if (!re) throw new Error("USD worker was not prepared before load");
1371
+ const c = await (await re).parseVisualSceneAsync(t.input, {
1372
+ ...t.options,
1373
+ packagePaths: t.options.packagePaths,
1374
+ readTextureBytes: !0,
1375
+ loadTextures: !1,
1376
+ convertZUp: !1,
1377
+ loadLights: !1,
1378
+ resolveBytes: Yt,
1379
+ onReferenceSkipped: (o) => N({ type: "event", event: "reference-skipped", identifier: o }),
1380
+ onResourceFailed: (o, u) => N({ type: "event", event: "resource-failed", identifier: o, error: Y(u) })
1381
+ });
1382
+ ee = c.release, se = Te(c.stage, c.pxr), ie = c.readPhysics;
1383
+ const i = c.data, s = Qt(i);
1384
+ N({
1385
+ type: "visual-ready",
1386
+ data: i,
1387
+ textureURLs: [...c.textureURLs ?? []]
1388
+ }, s);
1389
+ } catch (n) {
1390
+ N({ type: "error", error: Y(n) }), te.close();
1391
+ }
1392
+ };