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