@nebula-spatial/viewer 0.5.14 → 0.5.16

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