@nebula-spatial/viewer 0.5.6 → 0.5.8

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