@nebula-spatial/viewer 0.5.15 → 0.5.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1564 +0,0 @@
1
- function Ne(e, t) {
2
- return /^https?:$/.test(t.protocol) && e.origin === t.origin && !e.username && !e.password && we(e.pathname).startsWith(we(new URL(".", t).pathname));
3
- }
4
- function we(e) {
5
- return e.endsWith("/") ? e : e.slice(0, e.lastIndexOf("/") + 1);
6
- }
7
- function Ge(e, t) {
8
- for (const n of e) for (const a of n.shaders) for (const i of Object.values(a.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 Ve(e, t, n) {
15
- const a = [];
16
- try {
17
- return Ge(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
- a.push({ asset: i, values: r });
23
- }), n();
24
- } finally {
25
- for (const { asset: i, values: s } of a) Object.assign(i, s);
26
- }
27
- }
28
- const Be = "E_ASSET_RESOURCE_NOT_FOUND", De = "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
- ]), Xe = /* @__PURE__ */ new Set(["usd", "usda", "usdc", "usdz"]);
42
- function Je(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 = Je(e);
48
- return We.has(t) && !Xe.has(t);
49
- }
50
- function Ze(e, t) {
51
- return Object.assign(new Error(e), { code: t });
52
- }
53
- function Ye(e) {
54
- var a;
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 === De) return "invalid";
59
- if (t === Fe) return "unavailable";
60
- if (t === He || t === ze) return "denied";
61
- const n = (a = /\((\d{3})\)/.exec(e instanceof Error ? e.message : "")) == null ? void 0 : a[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 = ye(e).replaceAll("\\", "/");
77
- if (!tt.test(n)) return null;
78
- const a = _e(n), i = a.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 u of new Set(t)) {
84
- const h = ye(u).replaceAll("\\", "/"), g = _e(h), l = g.split("/").at(-1);
85
- if (!l) continue;
86
- const f = s.exec(l);
87
- if (!f) continue;
88
- const p = Number(f[1]);
89
- !Number.isInteger(p) || p < 1001 || p > 9999 || r.push({
90
- path: u,
91
- tile: p,
92
- score: st(a, g)
93
- });
94
- }
95
- if (!r.length) return { paths: [], tiles: [] };
96
- const c = Math.max(...r.map((u) => u.score)), o = r.filter((u) => u.score === c).sort((u, h) => u.tile - h.tile || u.path.localeCompare(h.path));
97
- return {
98
- paths: o.map((u) => u.path),
99
- tiles: o.map((u) => u.tile)
100
- };
101
- }
102
- function rt(e) {
103
- const t = e.split(/<UDIM>/i);
104
- return t.length !== 2 ? null : new RegExp(`^${Ee(t[0])}(\\d{4})${Ee(t[1])}$`, "i");
105
- }
106
- function st(e, t) {
107
- const n = e.split("/").slice(0, -1).filter(Boolean), a = t.split("/").slice(0, -1).filter(Boolean);
108
- let i = 0;
109
- for (; i < n.length && i < a.length; ) {
110
- const s = n.at(-1 - i), r = a.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 ye(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 _e(e) {
125
- const t = e.search(/[?#]/);
126
- return t < 0 ? e : e.slice(0, t);
127
- }
128
- function Ee(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), a = mt(n);
137
- if (a < 0) throw new Error("Not a zip package: end of central directory not found.");
138
- const i = n.getUint16(a + 10, !0);
139
- let s = n.getUint32(a + 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 o = 0; o < i; o += 1) {
143
- if (s + 46 > n.byteLength || n.getUint32(s, !0) !== at)
144
- throw new Error(`Corrupt zip central directory at entry ${o}.`);
145
- const u = n.getUint16(s + 10, !0), h = n.getUint32(s + 20, !0), g = n.getUint16(s + 28, !0), l = n.getUint16(s + 30, !0), f = n.getUint16(s + 32, !0), p = n.getUint32(s + 42, !0);
146
- if (h === ie || p === ie)
147
- throw new Error("ZIP64 usdz packages are not supported.");
148
- const _ = new TextDecoder().decode(e.subarray(s + 46, s + 46 + g));
149
- s += 46 + g + l + f, !_.endsWith("/") && (t.include && !t.include(_) || c.push(ft(e, n, p, h, u).then((y) => ({ name: _, data: y }))));
150
- }
151
- for (const { name: o, data: u } of await Promise.all(c)) r.set(o, u);
152
- return r;
153
- }
154
- function dt(e) {
155
- if (typeof URL > "u" || typeof URL.createObjectURL != "function") return null;
156
- const t = new Map([...e].filter(([r]) => Me(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 a = /* @__PURE__ */ new Map(), i = (r) => {
164
- let c = a.get(r);
165
- if (!c) {
166
- const o = t.get(r);
167
- c = URL.createObjectURL(new Blob([new Uint8Array(o)], { type: gt(r) })), a.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 o = [...t.keys()].filter((g) => g.endsWith(`/${c}`));
176
- if (o.length === 1) return i(o[0]);
177
- const u = [...t.keys()].filter((g) => c.endsWith(`/${g}`));
178
- if (u.length === 1) return i(u[0]);
179
- const h = n.get(c.split("/").pop() ?? "");
180
- return h ? i(h) : null;
181
- };
182
- for (const r of t.keys()) i(r);
183
- return {
184
- urls: a,
185
- resolve: (r) => s(r.resolvedPath) ?? s(r.path) ?? s(r.url) ?? null,
186
- dispose: () => {
187
- for (const r of a.values()) URL.revokeObjectURL(r);
188
- a.clear();
189
- }
190
- };
191
- }
192
- function Me(e) {
193
- return ct.has(xe(e));
194
- }
195
- async function ft(e, t, n, a, 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, o = e.subarray(c, c + a);
198
- if (i === 0) return o.slice();
199
- if (i !== 8) throw new Error(`Unsupported zip compression method ${i}.`);
200
- const u = new Blob([new Uint8Array(o)]).stream().pipeThrough(new DecompressionStream("deflate-raw"));
201
- return new Uint8Array(await new Response(u).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 xe(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 (xe(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 = 3, _t = "26ba7dc16b5a87a490fb", Et = {
237
- file: "openusd_probe.js",
238
- sha256: "83a14d264f2348a0899de8f1bc0c021fdcd8cae554ef545fb9e5b88da6f30b4e",
239
- bytes: 95918
240
- }, St = {
241
- file: "openusd_probe.wasm",
242
- sha256: "ee1fa0050c8d220e13666325f81fc730940b6704a0900952cbef1505def8c3b4",
243
- bytes: 10659670
244
- };
245
- var bt = {
246
- schemaVersion: wt,
247
- apiVersion: yt,
248
- runtimeId: _t,
249
- js: Et,
250
- wasm: St
251
- };
252
- const Ut = vt(bt);
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: Se(t.js, "openusd_probe.js"),
263
- wasm: Se(t.wasm, "openusd_probe.wasm")
264
- });
265
- }
266
- function Se(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 It(e, t, n) {
278
- return WebAssembly.instantiate(e, t).then(
279
- (a) => n(a, e),
280
- (a) => {
281
- setTimeout(() => {
282
- throw a;
283
- });
284
- }
285
- ), {};
286
- }
287
- function ke(e, t) {
288
- const n = async (s, r) => {
289
- var o;
290
- const c = e.GetPrimAtPath(s);
291
- try {
292
- return r(c);
293
- } finally {
294
- (o = c == null ? void 0 : c.delete) == null || o.call(c);
295
- }
296
- }, a = (s, r) => {
297
- var o, u, h, g;
298
- const c = (o = s == null ? void 0 : s.GetAttribute) == null ? void 0 : o.call(s, r);
299
- if (!c) return [];
300
- try {
301
- return ((u = c.IsValid) == null ? void 0 : u.call(c)) !== !0 ? [] : (((h = c.GetConnections) == null ? void 0 : h.call(c)) ?? []).map((l) => {
302
- var p, _;
303
- if (typeof l == "string") return l;
304
- const f = String(((p = l.GetString) == null ? void 0 : p.call(l)) ?? l.path ?? "");
305
- return (_ = l.delete) == null || _.call(l), 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 o = r.GetMetadata(s);
326
- return { valid: !0, found: o != null, value: o };
327
- } finally {
328
- (c = r.delete) == null || c.call(r);
329
- }
330
- },
331
- async primInfo(s) {
332
- return n(s, (r) => {
333
- var c, o, u, h;
334
- return {
335
- valid: !!r && ((c = r.IsValid) == null ? void 0 : c.call(r)) !== !1,
336
- name: String(((o = r.GetName) == null ? void 0 : o.call(r)) ?? s.split("/").pop() ?? ""),
337
- path: s,
338
- typeName: String(((u = r.GetTypeName) == null ? void 0 : u.call(r)) ?? ""),
339
- instance: ((h = r.IsInstance) == null ? void 0 : h.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((o) => {
347
- var h, g;
348
- const u = String(o.__path ?? ((h = o.GetPath) == null ? void 0 : h.call(o)) ?? "");
349
- return (g = o.delete) == null || g.call(o), u;
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((o) => {
361
- var h, g;
362
- const u = String(((h = o.GetName) == null ? void 0 : h.call(o)) ?? "");
363
- return (g = o.delete) == null || g.call(o), u;
364
- });
365
- });
366
- },
367
- async primMetadata(s, r) {
368
- return n(s, (c) => {
369
- var h;
370
- const o = (h = c == null ? void 0 : c.GetMetadata) == null ? void 0 : h.call(c, r), u = typeof o == "string" ? o : o && typeof o == "object" && typeof o.string == "string" ? String(o.string) : void 0;
371
- return {
372
- valid: !0,
373
- found: o != null,
374
- ...o != null ? { value: o } : {},
375
- ...u !== void 0 ? { text: u } : {}
376
- };
377
- });
378
- },
379
- async relationshipTargets(s, r) {
380
- return n(s, (c) => {
381
- var u, h, g;
382
- const o = (u = c == null ? void 0 : c.GetRelationship) == null ? void 0 : u.call(c, r);
383
- if (!o) return [];
384
- try {
385
- return (((h = o.GetTargets) == null ? void 0 : h.call(o)) ?? []).map((l) => {
386
- var f;
387
- return typeof l == "string" ? l : String(((f = l.GetString) == null ? void 0 : f.call(l)) ?? l.path ?? "");
388
- }).filter(Boolean);
389
- } finally {
390
- (g = o.delete) == null || g.call(o);
391
- }
392
- });
393
- },
394
- async attributeValue(s, r) {
395
- return n(s, (c) => {
396
- var u, h, g, l;
397
- const o = (u = c == null ? void 0 : c.GetAttribute) == null ? void 0 : u.call(c, r);
398
- if (!o) return { valid: !1, authored: !1, value: null };
399
- try {
400
- const f = ((h = o.IsValid) == null ? void 0 : h.call(o)) === !0;
401
- return {
402
- valid: f,
403
- authored: f && ((g = o.HasAuthoredValue) == null ? void 0 : g.call(o)) === !0,
404
- value: f ? o.Get() : null
405
- };
406
- } finally {
407
- (l = o.delete) == null || l.call(o);
408
- }
409
- });
410
- },
411
- async attributeValues(s) {
412
- const r = {};
413
- for (const c of s)
414
- r[c.path] = await n(c.path, (o) => Object.fromEntries(
415
- c.names.map((u) => {
416
- var g, l, f, p;
417
- const h = (g = o == null ? void 0 : o.GetAttribute) == null ? void 0 : g.call(o, u);
418
- if (!h) return [u, { valid: !1, authored: !1, value: null }];
419
- try {
420
- const _ = ((l = h.IsValid) == null ? void 0 : l.call(h)) === !0;
421
- return [u, {
422
- valid: _,
423
- authored: _ && ((f = h.HasAuthoredValue) == null ? void 0 : f.call(h)) === !0,
424
- value: _ ? h.Get() : null
425
- }];
426
- } finally {
427
- (p = h.delete) == null || p.call(h);
428
- }
429
- })
430
- ));
431
- return r;
432
- },
433
- async attributeMetadata(s, r, c) {
434
- return n(s, (o) => {
435
- var h, g, l;
436
- const u = (h = o == null ? void 0 : o.GetAttribute) == null ? void 0 : h.call(o, r);
437
- if (!u) return { valid: !1, found: !1 };
438
- try {
439
- if (((g = u.IsValid) == null ? void 0 : g.call(u)) !== !0) return { valid: !1, found: !1 };
440
- const f = u.GetMetadata(c);
441
- return {
442
- valid: !0,
443
- found: f != null,
444
- ...f != null ? { value: f } : {}
445
- };
446
- } finally {
447
- (l = u.delete) == null || l.call(u);
448
- }
449
- });
450
- },
451
- async attributeConnections(s, r) {
452
- return n(s, (c) => a(c, r));
453
- },
454
- async boundMaterial(s) {
455
- return n(s, i);
456
- }
457
- };
458
- }
459
- const Rt = /^physics$/i, Pt = /^(newton|mjc|mujoco)(?:[_-]|$)/i, At = /^(physx|newton|mjc|mujoco)(?:[_-]|)/i;
460
- function Nt(e, t = []) {
461
- const n = new Set(t.map(be)), a = [];
462
- for (const i of e) {
463
- if (!Rt.test(i.setName) || n.has(be(i))) continue;
464
- const s = i.variantNames.map((o, u) => ({ selection: o, index: u, rank: Dt(o) })).filter((o) => o.rank !== null);
465
- if (s.length === 0 || i.selection && Pt.test(i.selection)) continue;
466
- const r = ce(i.selection), c = [...s].sort((o, u) => {
467
- const h = r !== null && ce(o.selection) === r, g = r !== null && ce(u.selection) === r;
468
- return Number(g) - Number(h) || o.rank - u.rank || o.index - u.index;
469
- })[0];
470
- a.push({
471
- primPath: i.primPath,
472
- setName: i.setName,
473
- selection: c.selection
474
- });
475
- }
476
- return a;
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(At, "").toLowerCase() || null;
483
- }
484
- function be(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 o = e[t];
492
- if (/\s/.test(o)) {
493
- t++;
494
- continue;
495
- }
496
- if (o === "#") {
497
- for (; t < e.length && e[t] !== `
498
- `; ) t++;
499
- continue;
500
- }
501
- if (o === '"' || o === "@" || o === "<") {
502
- const h = o === "<" ? ">" : o, g = o === '"' && e.slice(t, t + 3) === '"""';
503
- t += g ? 3 : 1;
504
- const l = 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] === h) {
511
- const f = e.slice(l, t);
512
- return t += g ? 3 : 1, { kind: o === "<" ? "path" : "string", value: f };
513
- }
514
- t++;
515
- }
516
- throw new Error("Unterminated USDA string or path");
517
- }
518
- if ("{}()[]=,".includes(o))
519
- return t++, { kind: "symbol", value: o };
520
- const u = t;
521
- for (; t < e.length && !/[\s{}()\[\]=,<>"@#]/.test(e[t]); ) t++;
522
- if (u === t) {
523
- t++;
524
- continue;
525
- }
526
- return { kind: "word", value: e.slice(u, t) };
527
- }
528
- }, a = () => {
529
- let o = 1, u;
530
- for (; o && (u = n()); )
531
- u.value === "[" && u.kind === "symbol" ? o++ : u.value === "]" && u.kind === "symbol" && o--;
532
- if (o) throw new Error("Unterminated USDA list");
533
- }, i = () => {
534
- let o = 1, u;
535
- for (; o && (u = n()); )
536
- u.value === "{" && u.kind === "symbol" ? o++ : u.value === "}" && u.kind === "symbol" && o--;
537
- if (o) 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 === "[" ? a() : 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 l = n(), f = (l == null ? void 0 : l.kind) === "string" ? l : n();
547
- if (!f || f.kind !== "string") throw new Error("Invalid USDA prim header");
548
- const p = [...r].reverse().find(Boolean), _ = `${(p == null ? void 0 : p.path) ?? ""}/${f.value}`, y = { 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(), E = n();
559
- if ((S == null ? void 0 : S.value) !== "=") throw new Error("Invalid USDA apiSchemas");
560
- if ((E == null ? void 0 : E.kind) === "word" && E.value === "None") continue;
561
- if ((E == null ? void 0 : E.value) !== "[") throw new Error(`Invalid USDA apiSchemas at ${_}: ${E == null ? void 0 : E.value}`);
562
- for (; (d = n()) && d.value !== "]"; )
563
- d.kind === "string" && d.value.startsWith("PhysxMimicJointAPI:") && y.schemas.push(d.value);
564
- if (!d) throw new Error("Unterminated USDA apiSchemas");
565
- } else d.value === "[" && d.kind === "symbol" && a();
566
- }
567
- if (!d) throw new Error("Unterminated USDA prim header");
568
- s.set(_, y), r.push({ path: _, prim: y });
569
- continue;
570
- }
571
- if (c.value !== "rel" || !r.at(-1)) continue;
572
- const o = n();
573
- if (!o || o.kind !== "word" || !/^physxMimicJoint:[^:]+:referenceJoint$/.test(o.value)) continue;
574
- const u = n(), h = n();
575
- if ((u == null ? void 0 : u.value) !== "=" || !h) continue;
576
- const g = [];
577
- if (h.kind === "path") g.push(h.value);
578
- else if (h.value === "[") {
579
- let l;
580
- for (; (l = n()) && l.value !== "]"; ) l.kind === "path" && g.push(l.value);
581
- if (!l) throw new Error("Unterminated USDA relationship");
582
- }
583
- r.at(-1).prim.relationships.set(o.value, g);
584
- }
585
- return new Map([...s].filter(([, o]) => o.schemas.length || o.relationships.size));
586
- }
587
- const xt = [
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 kt(e) {
606
- const t = new Map(e.map((s) => [s.path, s])), n = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), i = (s) => {
607
- const r = n.get(s.path);
608
- if (r) return r;
609
- if (a.has(s.path)) return Ue(s.localMatrix);
610
- a.add(s.path);
611
- const c = Ue(s.localMatrix), o = s.parentPath ? t.get(s.parentPath) : void 0, u = !o || s.resetsXformStack ? c : ve(c, i(o));
612
- return a.delete(s.path), n.set(s.path, u), u;
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), o = Ot(c);
619
- return o ? {
620
- ...s,
621
- localMatrix: ve(i(s), o)
622
- } : s;
623
- });
624
- }
625
- function Ue(e) {
626
- return Tt(e) ? e : xt;
627
- }
628
- function Tt(e) {
629
- return (e == null ? void 0 : e.length) === 16 && e.every(Number.isFinite);
630
- }
631
- function ve(e, t) {
632
- const n = new Array(16);
633
- for (let a = 0; a < 4; a++)
634
- for (let i = 0; i < 4; i++) {
635
- let s = 0;
636
- for (let r = 0; r < 4; r++)
637
- s += e[a * 4 + r] * t[r * 4 + i];
638
- n[a * 4 + i] = s;
639
- }
640
- return n;
641
- }
642
- function Ot(e) {
643
- const [
644
- t,
645
- n,
646
- a,
647
- ,
648
- i,
649
- s,
650
- r,
651
- ,
652
- c,
653
- o,
654
- u,
655
- ,
656
- h,
657
- g,
658
- l
659
- ] = e, f = s * u - r * o, p = a * o - n * u, _ = n * r - a * s, y = t * f + i * p + c * _, d = Math.max(
660
- Math.abs(t * s * u),
661
- Math.abs(t * r * o),
662
- Math.abs(n * i * u),
663
- Math.abs(n * r * c),
664
- Math.abs(a * i * o),
665
- Math.abs(a * s * c),
666
- 1
667
- );
668
- if (!Number.isFinite(y) || Math.abs(y) <= Number.EPSILON * d * 16)
669
- return null;
670
- const m = 1 / y, S = f * m, E = p * m, N = _ * m, G = (r * c - i * u) * m, T = (t * u - a * c) * m, V = (a * i - t * r) * m, b = (i * o - s * c) * m, P = (n * c - t * o) * m, U = (t * s - n * i) * m;
671
- return [
672
- S,
673
- E,
674
- N,
675
- 0,
676
- G,
677
- T,
678
- V,
679
- 0,
680
- b,
681
- P,
682
- U,
683
- 0,
684
- -(h * S + g * G + l * b),
685
- -(h * E + g * T + l * P),
686
- -(h * N + g * V + l * U),
687
- 1
688
- ];
689
- }
690
- function $t(e, t = []) {
691
- return {
692
- stage: e.stage,
693
- view: {
694
- ...e.view,
695
- prims: kt(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, Gt = /(^|[\s(\[])(?:[A-Za-z]:[\\/]|\/)(?:[^ \t\r\n()'"]+[\\/])*[^ \t\r\n()'"]+\.(?:cpp|cxx|cc|hpp|c|h|mjs|js|ts)(?::\d+)*/gi, Vt = /<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(Gt, "$1<OpenUSD source>").replace(Vt, "<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 Ie(e = {}) {
752
- const t = e.console ?? console, n = /* @__PURE__ */ new Set(), a = Math.max(1, e.maxUniqueDiagnostics ?? 64);
753
- let i = !1;
754
- const s = (r) => {
755
- var o;
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 >= a) {
759
- i || (i = !0, t.warn(
760
- `[openusd] further runtime diagnostics suppressed after ${a} unique messages`
761
- ));
762
- return;
763
- }
764
- n.add(c), (o = e.onDiagnostic) == null || o.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 o of c.split(/\r?\n/)) {
770
- const u = zt(o.trim());
771
- u && s(u);
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, a = e.wasmModule ? {
781
- printErr: Ie({ onDiagnostic: e.onRuntimeDiagnostic }),
782
- instantiateWasm(y, d) {
783
- return It(e.wasmModule, y, d);
784
- }
785
- } : {
786
- printErr: Ie({ onDiagnostic: e.onRuntimeDiagnostic }),
787
- wasmBinary: await (typeof e.wasmBinary == "function" ? e.wasmBinary() : e.wasmBinary ?? tn(e.wasmUrl))
788
- }, i = await n(a), 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", o = e.fetchBytes ?? (async (y) => {
795
- const d = await fetch(y);
796
- if (!d.ok) throw Object.assign(new Error(`USD resource request failed (${d.status}): ${y}`), {
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}): ${y}`, De);
801
- return m;
802
- }), u = (y, d, m) => JSON.parse(i.ccall(y, "string", d, m)), h = /* @__PURE__ */ new Set(), g = Re(i);
803
- let l = 0, f = null;
804
- async function p() {
805
- return f || (f = (async () => {
806
- const y = `${c}/__viewer_warmup__`, d = `${y}/empty.usda`;
807
- i.FS.mkdirTree(y), i.FS.writeFile(d, new TextEncoder().encode(`#usda 1.0
808
- `));
809
- let m;
810
- try {
811
- const S = u("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 && u("usd_probe_stage_release", ["number"], [m]), i.FS.analyzePath(d, !0).exists && i.FS.unlink(d);
817
- }
818
- })(), f);
819
- }
820
- async function _(y, d) {
821
- const m = new URL(d.sourcePath, "file:///"), S = `${c}/load-${++l}`, E = J(m.href, S), N = /* @__PURE__ */ new Set(), G = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map(), V = d.readTextureBytes ?? !0, b = d.collectTextureUrls ?? !V, P = b || V ? Te : Qt, U = /* @__PURE__ */ new Map();
822
- let F, D = null, I = null;
823
- const A = () => {
824
- F !== void 0 && h.delete(F) && u("usd_probe_stage_release", ["number"], [F]), D == null || D.dispose(), Le(i.FS, S);
825
- };
826
- try {
827
- const O = await Ae(y);
828
- de(i, E, O, N), G.set(E, P(O));
829
- for (const [w, R] of Object.entries(d.files ?? {})) {
830
- const v = J(new URL(w, m).href, S), B = await Ae(R);
831
- N.has(v) || G.set(v, P(B)), de(i, v, B, N);
832
- }
833
- const z = new Set(N);
834
- for (const w of d.packagePaths ?? [])
835
- z.add(J(new URL(w, m).href, S));
836
- const L = d.externalReferenceMode ?? "complete", C = ut(O) ? await lt(O, { include: Me }) : null;
837
- let H = {};
838
- if (!C && d.autoResolveAssets !== !1) {
839
- const w = d.resolveBytes ?? ((R) => o(R));
840
- H = await Zt(
841
- i,
842
- m,
843
- S,
844
- w,
845
- u,
846
- N,
847
- U,
848
- b ? T : null,
849
- G,
850
- d.maxFiles ?? 1024,
851
- d.maxDepth ?? 8,
852
- d.maxConcurrency ?? 1,
853
- L,
854
- z,
855
- V,
856
- d.onReferenceSkipped,
857
- d.onResourceFailed
858
- );
859
- }
860
- D = C ? dt(C) : null;
861
- const q = d.textureResolver || D ? (w) => {
862
- var R;
863
- return ((R = d.textureResolver) == null ? void 0 : R.call(d, w)) ?? (D == null ? void 0 : D.resolve(w)) ?? null;
864
- } : void 0, M = Object.keys(H).length > 0;
865
- if (M && typeof i._usd_probe_stage_open_mapped != "function")
866
- throw Object.assign(new Error("USD dependency mapping requires the matching packaged openusd_probe.js and .wasm runtime."), { code: "E_USD_RUNTIME_VERSION" });
867
- const x = M ? u("usd_probe_stage_open_mapped", ["string", "string"], [E, JSON.stringify(H)]) : u("usd_probe_stage_open", ["string"], [E]);
868
- if (!x.ok) throw new Error(x.error ?? `Failed to open ${E}`);
869
- F = x.stageId, h.add(x.stageId);
870
- const $ = d.variantSelections ?? [];
871
- let ne = [], W = $;
872
- if (d.selectMuJoCoPhysicsVariant !== !1) {
873
- if (typeof i._usd_probe_stage_variants != "function")
874
- throw Object.assign(
875
- new Error("USD variant discovery requires the matching packaged openusd_probe runtime."),
876
- { code: "E_USD_RUNTIME_VERSION" }
877
- );
878
- const w = u("usd_probe_stage_variants", ["number"], [x.stageId]);
879
- if (w.ok !== !0)
880
- throw new Error(String(w.error ?? "Failed to enumerate USD variants."));
881
- ne = w.variants ?? [], W = [
882
- ...$,
883
- ...Nt(ne, $)
884
- ];
885
- }
886
- for (const w of W) {
887
- const R = u(
888
- "usd_probe_stage_set_variant",
889
- ["number", "string", "string", "string"],
890
- [x.stageId, w.primPath, w.setName, w.selection]
891
- );
892
- if (R.ok !== !0)
893
- throw new Error(String(R.error ?? `Failed to select USD variant ${w.primPath}:${w.setName}=${w.selection}`));
894
- }
895
- const re = Re(i, U, E), se = re.openStage(x.stageId);
896
- if (d.selectMuJoCoPhysicsVariant !== !1) {
897
- const w = new Set($.map(ue)), R = /* @__PURE__ */ new Set();
898
- for (const v of W) {
899
- const B = ue(v);
900
- if (w.has(B)) continue;
901
- const j = ne.find((me) => me.primPath === v.primPath && me.setName === v.setName);
902
- if (!(j != null && j.selection) || j.selection === v.selection || se.GetDescendants(v.primPath, "MjcActuator").length === 0) continue;
903
- const ge = u(
904
- "usd_probe_stage_set_variant",
905
- ["number", "string", "string", "string"],
906
- [x.stageId, v.primPath, v.setName, j.selection]
907
- );
908
- if (ge.ok !== !0)
909
- throw new Error(String(ge.error ?? `Failed to restore authored USD variant ${v.primPath}:${v.setName}=${j.selection}`));
910
- R.add(B);
911
- }
912
- R.size > 0 && (W = W.filter((v) => !R.has(ue(v))));
913
- }
914
- const fe = await Xt(i, x.stageId, E, {
915
- batchSize: d.geometryBatchSize,
916
- onProgress: d.onGeometryProgress
917
- });
918
- $e(fe.materials, U);
919
- const Ce = new Map(W.map((w) => [
920
- `${w.primPath}\0${w.setName}`,
921
- w.selection
922
- ])), je = ne.map((w) => ({
923
- ...w,
924
- selection: Ce.get(`${w.primPath}\0${w.setName}`) ?? w.selection
925
- })), ae = $t(fe, je), he = d.isTextureAllowed ?? (L === "package" ? (w) => {
926
- const R = new URL(w, m);
927
- return z.has(J(R.href, S)) || Ne(R, m);
928
- } : void 0), pe = C ? void 0 : he ? (w) => T.has(w) || he(w) : T.size > 0 ? (w) => T.has(w) : void 0;
929
- return {
930
- data: ae,
931
- pxr: re,
932
- stage: se,
933
- entryPath: E,
934
- textureURLs: T,
935
- buildModel: async () => {
936
- const { createUSDLoadedModel: w } = await import("@openusd-wasm/three-loader"), R = () => w(
937
- ae,
938
- re,
939
- E,
940
- {
941
- sourcePath: d.sourcePath,
942
- // The Viewer normalises USD to world Z-up and draws its own studio
943
- // lighting. Textures remain enabled unless the host explicitly
944
- // injects its own loader/cache.
945
- convertZUp: d.convertZUp ?? !1,
946
- loadLights: d.loadLights ?? !1,
947
- loadTextures: d.loadTextures ?? !0,
948
- ...d.textureLoader ? { textureLoader: d.textureLoader } : {},
949
- ...d.textureCache ? { textureCache: d.textureCache } : {},
950
- ...q ? { textureResolver: q } : {}
951
- },
952
- se,
953
- {
954
- // Keep package texture identities on the model so the visual adapter
955
- // can resolve textures referenced by unsupported-but-known MDL nodes.
956
- usdzTextureURLs: (D == null ? void 0 : D.urls) ?? /* @__PURE__ */ new Map(),
957
- autoTextureURLs: /* @__PURE__ */ new Map()
958
- }
959
- ), v = pe ? Ve(ae.materials, pe, R) : R();
960
- v.usdQuery = ke(se, re);
961
- const B = v.dispose.bind(v);
962
- let j = !1;
963
- return v.dispose = () => {
964
- j || (j = !0, B(), A());
965
- }, v;
966
- },
967
- readPhysics() {
968
- return I || (I = (async () => {
969
- if (typeof i._usd_probe_scene_physics != "function")
970
- throw Object.assign(
971
- new Error("USD physics phase requires the matching packaged openusd_probe runtime."),
972
- { code: "E_USD_RUNTIME_VERSION" }
973
- );
974
- const w = u("usd_probe_scene_physics", ["number"], [x.stageId]);
975
- if (w.ok !== !0) throw new Error(String(w.error ?? "Failed to extract USD physics."));
976
- return w;
977
- })(), I);
978
- },
979
- release: A
980
- };
981
- } catch (O) {
982
- throw A(), O;
983
- }
984
- }
985
- return {
986
- runtime: i,
987
- pxr: g,
988
- warmup: p,
989
- async parseAsync(y, d) {
990
- const m = await _(y, d);
991
- try {
992
- return Lt(m.data, await m.readPhysics()), await m.buildModel();
993
- } catch (S) {
994
- throw m.release(), S;
995
- }
996
- },
997
- async parseVisualSceneAsync(y, d) {
998
- return await _(y, d);
999
- }
1000
- };
1001
- }
1002
- function Re(e, t = /* @__PURE__ */ new Map(), n) {
1003
- const a = (l, f, p) => JSON.parse(e.ccall(l, "string", f, p));
1004
- class i {
1005
- constructor(f) {
1006
- this.path = f;
1007
- }
1008
- GetString() {
1009
- return this.path;
1010
- }
1011
- delete() {
1012
- }
1013
- }
1014
- let s;
1015
- const r = /* @__PURE__ */ new Map(), c = (l, f) => {
1016
- if (!s) {
1017
- const S = e._usd_probe_flatten_stage;
1018
- if (n && typeof S == "function") {
1019
- const E = e.ccall("usd_probe_flatten_stage", "string", ["string"], [n]);
1020
- if (typeof E != "string" || !E.startsWith("#usda")) throw new Error("Unable to read flattened USD joint metadata");
1021
- s = Mt(E);
1022
- } else
1023
- s = /* @__PURE__ */ new Map();
1024
- }
1025
- const p = s.get(f);
1026
- if (p || r.has(f)) return p ?? r.get(f);
1027
- const _ = ["rotX", "rotY", "rotZ", "transX", "transY", "transZ", "X", "Y", "Z"], y = [], d = /* @__PURE__ */ new Map();
1028
- for (const S of _) {
1029
- const E = `physxMimicJoint:${S}:referenceJoint`, N = a("usd_probe_relationship_targets", ["number", "string", "string"], [l, f, E]).paths ?? [];
1030
- N.length && (y.push(`PhysxMimicJointAPI:${S}`), d.set(E, N));
1031
- }
1032
- const m = y.length ? { schemas: y, relationships: d } : void 0;
1033
- return m && r.set(f, m), m;
1034
- }, o = (l, f, p) => {
1035
- let _ = null;
1036
- const y = () => _ ?? (_ = a(
1037
- "usd_probe_attribute_value",
1038
- ["number", "string", "string"],
1039
- [l, f, p]
1040
- ));
1041
- return {
1042
- IsValid: () => y().valid === !0,
1043
- Get: () => {
1044
- const d = y();
1045
- return d.valid === !0 ? typeof d.value == "string" ? t.get(d.value) ?? d.value : d.value : null;
1046
- },
1047
- HasAuthoredValue: () => y().authored === !0,
1048
- GetName: () => p,
1049
- GetMetadata: (d) => {
1050
- const m = a("usd_probe_attribute_metadata", ["number", "string", "string", "string"], [l, f, p, d]);
1051
- return m.valid === !0 && m.found === !0 ? m.value ?? null : null;
1052
- },
1053
- // The viewer accepts either plain strings or objects with GetString().
1054
- GetConnections: () => a("usd_probe_attribute_connections", ["number", "string", "string"], [l, f, p]).paths ?? [],
1055
- delete: () => {
1056
- }
1057
- };
1058
- }, u = (l, f) => ({
1059
- __path: f,
1060
- __stageId: l,
1061
- IsValid: () => a("usd_probe_prim_info", ["number", "string"], [l, f]).valid === !0,
1062
- GetName: () => String(f.split("/").pop() ?? ""),
1063
- GetPath: () => new i(f),
1064
- GetTypeName: () => String(a("usd_probe_prim_info", ["number", "string"], [l, f]).typeName ?? ""),
1065
- IsInstance: () => a("usd_probe_prim_info", ["number", "string"], [l, f]).instance === !0,
1066
- GetAppliedSchemas: () => {
1067
- var p;
1068
- return ((p = c(l, f)) == null ? void 0 : p.schemas) ?? [];
1069
- },
1070
- GetRelationships: () => {
1071
- var p;
1072
- return [...((p = c(l, f)) == null ? void 0 : p.relationships) ?? []].map(([_, y]) => ({
1073
- GetName: () => _,
1074
- GetTargets: () => y.map((d) => new i(d)),
1075
- delete: () => {
1076
- }
1077
- }));
1078
- },
1079
- GetAttribute: (p) => o(l, f, p),
1080
- GetAttributes: () => (a("usd_probe_prim_attributes", ["number", "string"], [l, f]).names ?? []).map((p) => o(l, f, p)),
1081
- GetChildren: () => (a("usd_probe_prim_children", ["number", "string"], [l, f]).paths ?? []).map((p) => u(l, p)),
1082
- GetRelationship: (p) => {
1083
- const _ = a(
1084
- "usd_probe_relationship_targets",
1085
- ["number", "string", "string"],
1086
- [l, f, p]
1087
- ).paths ?? [];
1088
- return {
1089
- GetName: () => p,
1090
- GetTargets: () => _.map((y) => new i(y)),
1091
- delete: () => {
1092
- }
1093
- };
1094
- },
1095
- GetMetadata: (p) => {
1096
- const _ = a("usd_probe_prim_metadata", ["number", "string", "string"], [l, f, p]);
1097
- return _.valid !== !0 ? null : typeof _.text == "string" ? _.text : _.found === !0 ? _.value : null;
1098
- },
1099
- delete: () => {
1100
- }
1101
- }), h = (l) => ({
1102
- GetPrimAtPath: (f) => u(l, typeof f == "string" ? f : f.path),
1103
- GetPseudoRoot: () => Object.assign(u(l, "/"), {
1104
- // Stage-level metadata (metersPerUnit, upAxis, defaultPrim) is authored on
1105
- // the layer, not composed onto the pseudo-root prim.
1106
- GetMetadata: (f) => {
1107
- const p = a("usd_probe_stage_metadata", ["number", "string"], [l, f]);
1108
- return p.found === !0 ? p.value : null;
1109
- },
1110
- GetName: () => "",
1111
- IsValid: () => !0
1112
- }),
1113
- GetDescendants: (f, p = "") => a(
1114
- "usd_probe_prim_descendants",
1115
- ["number", "string", "string"],
1116
- [l, f, p]
1117
- ).paths ?? [],
1118
- delete: () => {
1119
- }
1120
- }), { FS: g } = e;
1121
- return {
1122
- FS: {
1123
- createDir: (l) => g.mkdirTree(l),
1124
- writeFile: (l, f) => g.writeFile(l, f),
1125
- exists: (l) => g.analyzePath(l, !0).exists,
1126
- listDir: (l) => g.readdir(l).filter((f) => f !== "." && f !== "..").map((f) => {
1127
- const p = `${l.replace(/\/+$/, "")}/${f}`;
1128
- return { path: p, name: f, isDir: g.isDir(g.stat(p).mode) };
1129
- }),
1130
- deleteFile: (l) => g.unlink(l),
1131
- deleteDir: (l) => g.rmdir(l)
1132
- },
1133
- Sdf: { Path: i },
1134
- Usd: { TimeCode: { Default: () => ({ delete: () => {
1135
- } }) } },
1136
- UsdShade: {
1137
- ComputeBoundMaterialPath: (l) => {
1138
- const f = a("usd_probe_bound_material", ["number", "string"], [l.__stageId, l.__path]);
1139
- return f.found !== !0 ? null : {
1140
- materialPath: String(f.materialPath ?? ""),
1141
- resolvedTargetPath: String(f.resolvedTargetPath ?? ""),
1142
- bindingRelationshipPath: String(f.bindingRelationshipPath ?? "")
1143
- };
1144
- }
1145
- },
1146
- UsdUtils: {
1147
- ExtractSanitizedExternalReferences: (l) => a("usd_probe_external_references", ["string"], [l]).paths ?? []
1148
- },
1149
- openStage: h
1150
- };
1151
- }
1152
- async function Xt(e, t, n, a = {}) {
1153
- var c;
1154
- if (typeof e._usd_probe_scene_visual != "function" || typeof e._usd_probe_scene_geometry != "function" || typeof e._usd_probe_scene_geometry_end != "function")
1155
- throw Object.assign(
1156
- new Error("USD visual phases require the matching packaged openusd_probe runtime."),
1157
- { code: "E_USD_RUNTIME_VERSION" }
1158
- );
1159
- const i = JSON.parse(e.ccall(
1160
- "usd_probe_scene_visual",
1161
- "string",
1162
- ["number", "string"],
1163
- [t, n]
1164
- ));
1165
- if (i.error) throw new Error(i.error);
1166
- const s = i, r = Math.max(1, Math.floor(a.batchSize ?? 8));
1167
- try {
1168
- for (const [o, u] of s.elements.entries()) {
1169
- const g = u.geometry.streamIndex;
1170
- if (!Number.isInteger(g))
1171
- throw new Error(`USD scene geometry is missing a stream index for ${u.path}`);
1172
- const l = JSON.parse(e.ccall(
1173
- "usd_probe_scene_geometry",
1174
- "string",
1175
- ["number", "number"],
1176
- [t, g]
1177
- ));
1178
- if (!l.ok) throw new Error(l.error ?? `Failed to stream USD geometry for ${u.path}`);
1179
- u.geometry = Object.fromEntries(
1180
- Object.entries(l.geometry ?? {}).map(([f, p]) => [f, qt(e, p)])
1181
- ), (c = a.onProgress) == null || c.call(a, o + 1, s.elements.length, u.path), (o + 1) % r === 0 && await Jt();
1182
- }
1183
- } finally {
1184
- e.ccall("usd_probe_scene_geometry_end", "string", ["number"], [t]);
1185
- }
1186
- return s;
1187
- }
1188
- function Jt() {
1189
- return new Promise((e) => setTimeout(e, 0));
1190
- }
1191
- function qt(e, t) {
1192
- if (!t || typeof t != "object") return t ?? null;
1193
- const { ptr: n, length: a, kind: i } = t;
1194
- return typeof n != "number" ? t : a ? (i === "i32" ? new Int32Array(e.HEAP32.buffer, n, a) : new Float32Array(e.HEAPF32.buffer, n, a)).slice() : i === "i32" ? new Int32Array() : new Float32Array();
1195
- }
1196
- async function Zt(e, t, n, a, i, s, r, c, o, u, h, g, l, f, p, _, y) {
1197
- const d = {}, m = [...f];
1198
- let S = [
1199
- { url: t, depth: 0, recurse: !0, absolute: !1 }
1200
- ];
1201
- const E = /* @__PURE__ */ new Set(), N = /* @__PURE__ */ new Set();
1202
- for (; S.length; ) {
1203
- const G = S;
1204
- S = [];
1205
- const T = [];
1206
- for (const b of G) {
1207
- const P = b.absolute ? b.url.href : Pe(b.url.href, t);
1208
- if (!E.has(P)) {
1209
- if (b.depth > h) throw new Error(`USD dependency depth limit exceeded (${h}): ${P}`);
1210
- if (E.size >= u) throw new Error(`USD dependency limit exceeded (${u}).`);
1211
- E.add(P), T.push({ item: b, identifier: P });
1212
- }
1213
- }
1214
- S = (await Yt(
1215
- T,
1216
- Math.max(1, g),
1217
- async ({ item: b, identifier: P }) => {
1218
- const U = J(b.url.href, n);
1219
- if (!s.has(U) || b.absolute && !f.has(U)) {
1220
- let I;
1221
- try {
1222
- I = await a(b.url, P);
1223
- } catch (A) {
1224
- if (!b.owner || !qe(P) || !Ke(A)) throw A;
1225
- const O = `${n}/__unavailable__/${encodeURIComponent(P)}`;
1226
- return d[b.owner.path][b.owner.reference] = O, r.set(O, P), y == null || y(P, A), [];
1227
- }
1228
- o.set(U, Te(I)), de(e, U, I, s);
1229
- }
1230
- if (r.set(U, P), !b.recurse) return [];
1231
- if (d[U] ?? (d[U] = {}), o.get(U) === !1) return [];
1232
- const F = i("usd_probe_external_references", ["string"], [U]).paths ?? [], D = [];
1233
- for (const I of F) {
1234
- if (!I || /^(?:data|blob):/i.test(I) || /\.mdl(?:[?#].*)?$/i.test(I)) continue;
1235
- let A;
1236
- try {
1237
- A = new URL(I, b.url);
1238
- } catch {
1239
- continue;
1240
- }
1241
- const O = /^(?:[a-z][a-z\d+.-]*:|\/)/i.test(I), z = J(A.href, n), L = nt(z, m), C = (L == null ? void 0 : L.paths.length) === 1 ? L.paths[0] : null, H = C ?? z, q = b.absolute || O, M = q ? A.href : Pe(A.href, t), x = Kt(A.pathname);
1242
- if (C && r.set(C, M), l === "package" && L && L.paths.length > 1) {
1243
- const $ = `${n}/__deferred_udim__/${encodeURIComponent(M)}`;
1244
- d[U][I] = $, r.set($, M);
1245
- continue;
1246
- }
1247
- if (l === "package" && !f.has(H) && !Ne(A, t)) {
1248
- const $ = `${n}/__skipped__/${encodeURIComponent(M)}`;
1249
- d[U][I] = $, r.set($, M), N.has(M) || (N.add(M), _ == null || _(M));
1250
- continue;
1251
- }
1252
- if (!x && c && (c.set(M, A.href), c.set(I, A.href)), !x && !p) {
1253
- d[U][I] = M;
1254
- continue;
1255
- }
1256
- d[U][I] = H, !C && !E.has(M) && D.push({
1257
- url: A,
1258
- depth: b.depth + 1,
1259
- recurse: x,
1260
- absolute: q,
1261
- owner: { path: U, reference: I }
1262
- });
1263
- }
1264
- return D;
1265
- }
1266
- )).flat();
1267
- }
1268
- return d;
1269
- }
1270
- async function Yt(e, t, n) {
1271
- const a = new Array(e.length);
1272
- let i = 0;
1273
- const s = Array.from({ length: Math.min(t, e.length) }, async () => {
1274
- for (; i < e.length; ) {
1275
- const r = i++;
1276
- a[r] = await n(e[r]);
1277
- }
1278
- });
1279
- return await Promise.all(s), a;
1280
- }
1281
- function Kt(e) {
1282
- var n, a;
1283
- const t = (a = (n = e.split(/[?#]/, 1)[0]) == null ? void 0 : n.split(".").pop()) == null ? void 0 : a.toLowerCase();
1284
- return t != null && Ht.has(t);
1285
- }
1286
- function Te(e) {
1287
- return Oe(e) ? e.includes(64) : !0;
1288
- }
1289
- function Qt(e) {
1290
- return Oe(e) ? en(e, [
1291
- "subLayers",
1292
- "references",
1293
- "payload",
1294
- "payloads",
1295
- "clipAssetPaths"
1296
- ]) : !0;
1297
- }
1298
- function Oe(e) {
1299
- let t = e[0] === 239 && e[1] === 187 && e[2] === 191 ? 3 : 0;
1300
- for (; t < e.length && t < 64 && /\s/.test(String.fromCharCode(e[t])); ) t += 1;
1301
- return e[t] === 35 && e[t + 1] === 117 && e[t + 2] === 115 && e[t + 3] === 100 && e[t + 4] === 97;
1302
- }
1303
- function en(e, t) {
1304
- const n = /* @__PURE__ */ new Map();
1305
- let a = 1;
1306
- for (const s of t) {
1307
- const r = s.charCodeAt(0);
1308
- n.set(r, [...n.get(r) ?? [], s]), a = Math.max(a, s.length);
1309
- }
1310
- const i = e.length - a;
1311
- for (let s = 0; s <= i; ++s) {
1312
- const r = n.get(e[s]);
1313
- if (r)
1314
- for (const c of r) {
1315
- let o = !0;
1316
- for (let u = 1; u < c.length; ++u)
1317
- if (e[s + u] !== c.charCodeAt(u)) {
1318
- o = !1;
1319
- break;
1320
- }
1321
- if (o) return !0;
1322
- }
1323
- }
1324
- return !1;
1325
- }
1326
- function Pe(e, t) {
1327
- const n = new URL(e);
1328
- if (n.protocol !== t.protocol || n.host !== t.host) return n.href;
1329
- const a = new URL(".", t).pathname.split("/").filter(Boolean), i = n.pathname.split("/").filter(Boolean);
1330
- let s = 0;
1331
- for (; s < a.length && a[s] === i[s]; ) s++;
1332
- const r = [...a.slice(s).map(() => ".."), ...i.slice(s)].join("/");
1333
- return decodeURIComponent(r) + n.search + n.hash;
1334
- }
1335
- function J(e, t) {
1336
- const n = new URL(e), a = encodeURIComponent(`${n.protocol}//${n.host}`);
1337
- let i = n.pathname.split("/").map((s) => decodeURIComponent(s).replaceAll("/", "%2F").replaceAll("\\", "%5C")).join("/");
1338
- if (n.search || n.hash) {
1339
- const s = i.lastIndexOf("."), r = s > i.lastIndexOf("/") ? s : i.length;
1340
- i = `${i.slice(0, r)}.__url_${encodeURIComponent(n.search + n.hash)}${i.slice(r)}`;
1341
- }
1342
- return `${t}/${a}${i}`;
1343
- }
1344
- function $e(e, t) {
1345
- if (!e || typeof e != "object" || ArrayBuffer.isView(e)) return;
1346
- const n = e;
1347
- if (typeof n.path == "string" && typeof n.resolvedPath == "string") {
1348
- for (const a of ["path", "resolvedPath"]) {
1349
- const i = n[a];
1350
- n[a] = t.get(i) ?? i;
1351
- }
1352
- return;
1353
- }
1354
- for (const a of Object.values(e)) $e(a, t);
1355
- }
1356
- function Le(e, t) {
1357
- if (e.analyzePath(t).exists) {
1358
- for (const n of e.readdir(t)) {
1359
- if (n === "." || n === "..") continue;
1360
- const a = `${t}/${n}`;
1361
- e.isDir(e.stat(a).mode) ? Le(e, a) : e.unlink(a);
1362
- }
1363
- e.rmdir(t);
1364
- }
1365
- }
1366
- function de(e, t, n, a) {
1367
- a.has(t) || (e.FS.mkdirTree(t.split("/").slice(0, -1).join("/") || "/"), e.FS.writeFile(t, n), a.add(t));
1368
- }
1369
- function ue(e) {
1370
- return `${e.primPath}\0${e.setName}`;
1371
- }
1372
- async function Ae(e) {
1373
- 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());
1374
- }
1375
- async function tn(e) {
1376
- if (!e) throw new Error("createSingleThreadUsd needs wasmUrl or wasmBinary.");
1377
- return (await fetch(e)).arrayBuffer();
1378
- }
1379
- function nn(e) {
1380
- if (e.length < 30) return null;
1381
- const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (a, i) => {
1382
- for (let s = 0; s < i.length; s += 1)
1383
- if (e[a + s] !== i.charCodeAt(s)) return !1;
1384
- return !0;
1385
- };
1386
- if (e[0] === 137 && n(1, "PNG") && n(12, "IHDR"))
1387
- return Z(t.getUint32(16), t.getUint32(20));
1388
- if (e[0] === 255 && e[1] === 216) {
1389
- let a = 2;
1390
- for (; a + 9 < e.length; ) {
1391
- if (e[a] !== 255) return null;
1392
- const i = e[a + 1], s = e[a + 2] << 8 | e[a + 3];
1393
- if (i >= 192 && i <= 207 && i !== 196 && i !== 200 && i !== 204)
1394
- return Z(
1395
- e[a + 7] << 8 | e[a + 8],
1396
- e[a + 5] << 8 | e[a + 6]
1397
- );
1398
- if (s < 2) return null;
1399
- a += 2 + s;
1400
- }
1401
- return null;
1402
- }
1403
- if (n(0, "RIFF") && n(8, "WEBP")) {
1404
- if (n(12, "VP8 "))
1405
- return Z(
1406
- t.getUint16(26, !0) & 16383,
1407
- t.getUint16(28, !0) & 16383
1408
- );
1409
- if (n(12, "VP8L")) {
1410
- const a = t.getUint32(21, !0);
1411
- return Z((a & 16383) + 1, (a >>> 14 & 16383) + 1);
1412
- }
1413
- if (n(12, "VP8X")) {
1414
- const a = (i) => e[i] | e[i + 1] << 8 | e[i + 2] << 16;
1415
- return Z(a(24) + 1, a(27) + 1);
1416
- }
1417
- }
1418
- return null;
1419
- }
1420
- function rn(e, t) {
1421
- const n = Math.max(e.width, e.height);
1422
- if (t <= 0 || n <= t) return e;
1423
- const a = t / n;
1424
- return {
1425
- width: Math.max(1, Math.round(e.width * a)),
1426
- height: Math.max(1, Math.round(e.height * a))
1427
- };
1428
- }
1429
- function Z(e, t) {
1430
- return e > 0 && t > 0 ? { width: e, height: t } : null;
1431
- }
1432
- function X(e) {
1433
- return e instanceof Error ? {
1434
- name: e.name,
1435
- message: e.message,
1436
- ...typeof e.code == "string" ? { code: e.code } : {},
1437
- ...e.stack ? { stack: e.stack } : {}
1438
- } : { name: "Error", message: String(e) };
1439
- }
1440
- const K = globalThis;
1441
- let ee = null, Y = null, te = null, oe = null, le = !1, sn = 1;
1442
- const Q = /* @__PURE__ */ new Map();
1443
- function k(e, t) {
1444
- K.postMessage(e, t);
1445
- }
1446
- function on(e, t) {
1447
- const n = sn++;
1448
- return new Promise((a, i) => {
1449
- Q.set(n, { resolve: a, reject: i }), k({ type: "resource-request", id: n, url: e.href, identifier: t });
1450
- });
1451
- }
1452
- function an(e) {
1453
- return ee ?? (ee = Wt(e)), ee;
1454
- }
1455
- function cn(e) {
1456
- const t = /* @__PURE__ */ new Set();
1457
- for (const n of e.elements)
1458
- for (const a of Object.values(n.geometry ?? {}))
1459
- ArrayBuffer.isView(a) && t.add(a.buffer);
1460
- return [...t];
1461
- }
1462
- async function un(e) {
1463
- if (!te) throw new Error("USD worker has no live stage");
1464
- const t = te[e.method];
1465
- return { type: "query-result", id: e.id, value: await t.apply(te, e.args) };
1466
- }
1467
- async function ln(e, t) {
1468
- if (typeof createImageBitmap != "function")
1469
- throw new Error("This browser cannot decode USD textures in a worker.");
1470
- const n = await fetch(e);
1471
- if (!n.ok) throw new Error(`HTTP ${n.status} for ${e}`);
1472
- const a = new Uint8Array(await n.arrayBuffer()), i = nn(a), s = {
1473
- imageOrientation: "flipY",
1474
- premultiplyAlpha: "none",
1475
- colorSpaceConversion: "none"
1476
- };
1477
- if (i) {
1478
- const r = t > 0 ? rn(i, t) : i;
1479
- (r.width !== i.width || r.height !== i.height) && (s.resizeWidth = r.width, s.resizeHeight = r.height, s.resizeQuality = "high");
1480
- }
1481
- return createImageBitmap(new Blob([a]), s);
1482
- }
1483
- K.onmessage = async (e) => {
1484
- const t = e.data;
1485
- if (t.type === "resource-result") {
1486
- const n = Q.get(t.id);
1487
- if (!n) return;
1488
- Q.delete(t.id), t.error ? n.reject(Object.assign(new Error(t.error.message), {
1489
- name: t.error.name,
1490
- ...t.error.code ? { code: t.error.code } : {}
1491
- })) : n.resolve(t.bytes ?? new Uint8Array());
1492
- return;
1493
- }
1494
- if (t.type === "query") {
1495
- try {
1496
- k(await un(t));
1497
- } catch (n) {
1498
- k({ type: "error", id: t.id, error: X(n) });
1499
- }
1500
- return;
1501
- }
1502
- if (t.type === "decode-texture") {
1503
- try {
1504
- const n = await ln(t.url, t.maxDimension);
1505
- k({
1506
- type: "texture-decoded",
1507
- id: t.id,
1508
- bitmap: n,
1509
- width: n.width,
1510
- height: n.height
1511
- }, [n]);
1512
- } catch (n) {
1513
- k({ type: "error", id: t.id, error: X(n) });
1514
- }
1515
- return;
1516
- }
1517
- if (t.type === "dispose") {
1518
- for (const n of Q.values()) n.reject(new Error("USD worker disposed"));
1519
- Q.clear(), Y == null || Y(), te = null, oe = null, le = !1, ee = null, Y = null, K.close();
1520
- return;
1521
- }
1522
- if (t.type === "extract-physics") {
1523
- if (le || !oe) return;
1524
- le = !0;
1525
- try {
1526
- k({ type: "physics-ready", phase: await oe() });
1527
- } catch (n) {
1528
- k({ type: "physics-failed", error: X(n) });
1529
- }
1530
- return;
1531
- }
1532
- if (t.type === "prepare") {
1533
- try {
1534
- const n = await an(t.runtime);
1535
- t.warmup && await n.warmup(), k({ type: "worker-ready" });
1536
- } catch (n) {
1537
- k({ type: "error", error: X(n) }), K.close();
1538
- }
1539
- return;
1540
- }
1541
- try {
1542
- if (!ee) throw new Error("USD worker was not prepared before load");
1543
- const a = await (await ee).parseVisualSceneAsync(t.input, {
1544
- ...t.options,
1545
- packagePaths: t.options.packagePaths,
1546
- readTextureBytes: t.options.readTextureBytes ?? !1,
1547
- loadTextures: !1,
1548
- convertZUp: !1,
1549
- loadLights: !1,
1550
- resolveBytes: on,
1551
- onReferenceSkipped: (r) => k({ type: "event", event: "reference-skipped", identifier: r }),
1552
- onResourceFailed: (r, c) => k({ type: "event", event: "resource-failed", identifier: r, error: X(c) })
1553
- });
1554
- Y = a.release, te = ke(a.stage, a.pxr), oe = a.readPhysics;
1555
- const i = a.data, s = cn(i);
1556
- k({
1557
- type: "visual-ready",
1558
- data: i,
1559
- textureURLs: [...a.textureURLs ?? []]
1560
- }, s);
1561
- } catch (n) {
1562
- k({ type: "error", error: X(n) }), K.close();
1563
- }
1564
- };