@nebula-spatial/studio 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +2 -0
  2. package/dist/assets/openusd_three_loader-DLiqJWUM.js +13769 -0
  3. package/dist/assets/usd-export-worker-BRxTLqer.js +182 -0
  4. package/dist/assets/usd-worker-DekqMsQv.js +1392 -0
  5. package/dist/{builders-BAXRR5o5.js → builders-lydx4-Rh.js} +1 -1
  6. package/dist/core/session-persistence-controller.d.ts +55 -0
  7. package/dist/doc/placement-policy.d.ts +4 -0
  8. package/dist/editor/editor.d.ts +3 -1
  9. package/dist/editor/index.d.ts +2 -0
  10. package/dist/editor/session-persistence.d.ts +54 -0
  11. package/dist/editor.js +727 -490
  12. package/dist/export-evidence-z2Ne7Trf.js +2387 -0
  13. package/dist/generalization.js +2 -2
  14. package/dist/index.d.ts +4 -2
  15. package/dist/index.js +314 -306
  16. package/dist/mjcf-visual-IOy-ucto.js +72 -0
  17. package/dist/mujoco-runtime-BYZnrvbR.js +467 -0
  18. package/dist/persist/indexeddb-store.d.ts +22 -2
  19. package/dist/persist/session.d.ts +22 -0
  20. package/dist/persist/snapshot.d.ts +24 -0
  21. package/dist/{physics-facts-tfQYyNTD.js → physics-facts-D-URIBrt.js} +8 -7
  22. package/dist/{placement-policy-DY_FNRDu.js → placement-policy-C6dV6Tf-.js} +161 -141
  23. package/dist/ports/persistence.d.ts +45 -1
  24. package/dist/project/contracts.d.ts +3 -0
  25. package/dist/remote-asset-resolver-D-UeyDMD.js +311 -0
  26. package/dist/{scene-graph-DBLKAhxa.js → scene-graph-DVOXjMmp.js} +2 -2
  27. package/dist/scene-session-PhoFXFCY.js +22006 -0
  28. package/dist/scene.js +2 -2
  29. package/dist/session-2bp8YOA4.js +963 -0
  30. package/dist/session-B3WbC7Y2.js +296 -0
  31. package/dist/session-B9kEf4xN.js +915 -0
  32. package/dist/session-DYThdzLZ.js +825 -0
  33. package/dist/studio/index.d.ts +5 -0
  34. package/dist/studio/indexeddb-persistence.d.ts +2 -0
  35. package/dist/studio/indexeddb-session-persistence.d.ts +11 -0
  36. package/dist/studio/scene-package-asset-sources.d.ts +14 -0
  37. package/dist/studio.js +1423 -1220
  38. package/dist/urdf-session-CRXL4bHf.js +1230 -0
  39. package/dist/usd-session-CTzInpNy.js +7385 -0
  40. package/dist/version.d.ts +1 -1
  41. package/dist/view/scene-session.d.ts +5 -1
  42. package/dist/wasm-module-DZn2AM1W.js +13 -0
  43. package/dist/xacro-IpPHTMYs.js +76 -0
  44. package/package.json +1 -1
  45. package/dist/asset-source-BExlEcRt.js +0 -444
  46. package/dist/assets/usd-export-worker-BsGubtAE.js +0 -1
  47. package/dist/editorial-BkAFWfbg.js +0 -83
  48. package/dist/export-evidence-B_0zRmb8.js +0 -5027
  49. package/dist/remote-asset-resolver-Cb8cfNmw.js +0 -136
  50. package/dist/scene-session-BV1HnxNh.js +0 -3506
@@ -0,0 +1,825 @@
1
+ var Me = Object.defineProperty;
2
+ var Le = (t, e, s) => e in t ? Me(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
+ var k = (t, e, s) => Le(t, typeof e != "symbol" ? e + "" : e, s);
4
+ import { D as ke, S as re, b as Fe, e as be, f as _e } from "./scene-session-PhoFXFCY.js";
5
+ const ie = "E_ASSET_RESOURCE_NOT_FOUND", Ue = "E_ASSET_RESOURCE_INVALID", Ie = "E_ASSET_FETCH", $e = "E_ASSET_EXTERNAL_DENIED", Re = "E_ASSET_AUTH", Ge = /* @__PURE__ */ new Set([
6
+ "png",
7
+ "jpg",
8
+ "jpeg",
9
+ "webp",
10
+ "avif",
11
+ "gif",
12
+ "bmp",
13
+ "tga",
14
+ "dds",
15
+ "hdr",
16
+ "exr",
17
+ "ktx2"
18
+ ]), Ve = /* @__PURE__ */ new Set(["usd", "usda", "usdc", "usdz"]);
19
+ function ze(t) {
20
+ var s;
21
+ return ((s = (t.split(/[?#]/, 1)[0] ?? t).split(".").pop()) == null ? void 0 : s.toLowerCase()) ?? "";
22
+ }
23
+ function yt(t) {
24
+ const e = ze(t);
25
+ return Ge.has(e) && !Ve.has(e);
26
+ }
27
+ function Et(t, e) {
28
+ return Object.assign(new Error(t), { code: e });
29
+ }
30
+ function De(t) {
31
+ var n;
32
+ if (t instanceof Error && t.name === "AbortError") return "aborted";
33
+ const e = t == null ? void 0 : t.code;
34
+ if (e === ie) return "missing";
35
+ if (e === Ue) return "invalid";
36
+ if (e === Ie) return "unavailable";
37
+ if (e === Re || e === $e) return "denied";
38
+ const s = (n = /\((\d{3})\)/.exec(t instanceof Error ? t.message : "")) == null ? void 0 : n[1];
39
+ return s === "404" || s === "410" ? "missing" : s === "401" || s === "403" ? "denied" : s != null && s.startsWith("5") ? "unavailable" : "unknown";
40
+ }
41
+ function St(t) {
42
+ const e = De(t);
43
+ return e === "missing" || e === "invalid" || e === "unavailable";
44
+ }
45
+ function Ce(t, e) {
46
+ return t && /\bhtml\b/i.test(t) ? `返回 HTML 页面(${t})` : t && !/^text\//i.test(t) ? null : /^\uFEFF?\s*(?:<!doctype\s+html|<html|<\?xml[^>]*\bhtml)/i.test(e) ? "返回 HTML 兜底页" : null;
47
+ }
48
+ function bt(t, e) {
49
+ return e.byteLength ? Ce(t, new TextDecoder().decode(e.subarray(0, 512))) : "响应内容为空";
50
+ }
51
+ async function qe(t) {
52
+ return t.size ? Ce(t.type, await t.slice(0, 512).text()) : "响应内容为空";
53
+ }
54
+ const We = /* @__PURE__ */ new Set([
55
+ "E_MJCF_INCLUDE_CYCLE",
56
+ "E_MJCF_PARSE",
57
+ "E_URDF_COMPILE",
58
+ "E_URDF_INERTIA",
59
+ "E_USD_INVALID_COLLISION_GEOMETRY",
60
+ "E_USD_INVALID_COLLISION_GROUP",
61
+ "E_USD_INVALID_EQUALITY_CONNECT",
62
+ "E_USD_INVALID_JOINT_REFERENCE",
63
+ "E_USD_INVALID_MASS",
64
+ "E_USD_INVALID_MIMIC",
65
+ "E_USD_INVALID_UNITS",
66
+ "E_USD_MISSING_COLLISION_GEOMETRY",
67
+ "E_USD_MULTIPLE_PHYSICS_SCENES",
68
+ "E_USD_PARTIAL_INERTIA",
69
+ "E_USD_UNREACHABLE_BODIES"
70
+ ]), Be = /* @__PURE__ */ new Set(["step", "reset", "grab", "up-axis"]), Je = Object.freeze({
71
+ kind: "visual-adaptation",
72
+ title: "视觉适配信息",
73
+ summary: "部分材质细节采用近似表示,不影响资产结构与模型查看。",
74
+ tone: "info"
75
+ }), He = Object.freeze({
76
+ kind: "unsupported-by-viewer",
77
+ title: "视觉预览模式",
78
+ summary: "当前仿真链路未能建立物理模型,资产视觉内容仍可正常查看。",
79
+ tone: "info"
80
+ });
81
+ function oe(t, e) {
82
+ return t === "E_URDF_INERTIA" ? {
83
+ kind: "invalid-asset",
84
+ title: "物理定义无效",
85
+ summary: "该 URDF 未声明动力学仿真所需的有效惯性数据,动力学模型无法建立。",
86
+ tone: "warning"
87
+ } : {
88
+ kind: "invalid-asset",
89
+ title: "物理定义无效",
90
+ summary: e === "usd-physics" ? "该 USD 资产的物理参数或关节定义无效,物理模型无法建立。" : "该资产的物理参数缺失或无效,物理模型无法建立。",
91
+ tone: "warning"
92
+ };
93
+ }
94
+ function Ye(t) {
95
+ return t === "visual-material" ? {
96
+ kind: "visual-adaptation",
97
+ title: "视觉材质近似",
98
+ summary: "部分材质信息未完整转换,当前显示使用近似材质。",
99
+ tone: "info"
100
+ } : Je;
101
+ }
102
+ function Oe(t, e) {
103
+ const s = e.split(":").at(-1);
104
+ if (s && Be.has(s))
105
+ return {
106
+ kind: "runtime-failure",
107
+ title: "仿真运行异常",
108
+ summary: "仿真初始化或运行过程中发生异常,物理仿真已停止;资产视觉内容仍可正常查看。",
109
+ tone: "warning"
110
+ };
111
+ if (t === "E_MUJOCO_INITIALIZE") {
112
+ if (e === "mjcf-physics")
113
+ return {
114
+ kind: "runtime-failure",
115
+ title: "物理模型初始化失败",
116
+ summary: "MuJoCo 物理模型初始化失败,资产仍可进行视觉预览。",
117
+ tone: "warning"
118
+ };
119
+ if (e === "urdf-physics")
120
+ return {
121
+ kind: "runtime-failure",
122
+ title: "动力学初始化失败",
123
+ summary: "URDF 动力学初始化失败,当前保留运动学预览。",
124
+ tone: "warning"
125
+ };
126
+ if (e === "usd-physics")
127
+ return {
128
+ kind: "runtime-failure",
129
+ title: "物理模型初始化失败",
130
+ summary: "当前 USD 物理模型未能完成 MuJoCo 初始化,资产视觉内容仍可正常查看。",
131
+ tone: "warning"
132
+ };
133
+ }
134
+ return We.has(t) ? oe(t, e) : e === "usd-physics" || t.startsWith("E_USD_") ? {
135
+ kind: "unsupported-by-viewer",
136
+ title: "视觉预览模式",
137
+ summary: "当前 Viewer 未覆盖该 USD 资产使用的部分物理语义,视觉与结构信息可正常查看,物理仿真未启动。",
138
+ tone: "info"
139
+ } : t.startsWith("E_MJCF_") || t.startsWith("E_URDF_") ? oe(t, e) : He;
140
+ }
141
+ function Xe(t, e) {
142
+ const s = t.notice ?? (e === "physics-validation" ? oe(t.code, t.source) : e === "visual-adaptation" || e === "visual-material" ? Ye(e) : Oe(t.code, t.source ?? e));
143
+ return { ...t, stage: e, notice: s };
144
+ }
145
+ function ne(t, e, s) {
146
+ if (e.throwIfAborted(), t instanceof Error && (t.name === "AbortError" || ["E_ABORTED", "E_SUPERSEDED"].includes(String(t.code)))) throw t;
147
+ const n = t && typeof t == "object" && "code" in t && typeof t.code == "string" ? t.code : "E_PHYSICS_INITIALIZE", r = t instanceof Error ? t.message : String(t);
148
+ return { code: n, source: s, message: r, notice: Oe(n, s) };
149
+ }
150
+ const Ke = /<UDIM>/i;
151
+ function Ze(t, e) {
152
+ const s = we(t).replaceAll("\\", "/");
153
+ if (!Ke.test(s)) return null;
154
+ const n = Ae(s), r = n.split("/").at(-1);
155
+ if (!r) return { paths: [], tiles: [] };
156
+ const a = xe(r);
157
+ if (!a) return { paths: [], tiles: [] };
158
+ const l = [];
159
+ for (const u of new Set(e)) {
160
+ const y = we(u).replaceAll("\\", "/"), m = Ae(y), U = m.split("/").at(-1);
161
+ if (!U) continue;
162
+ const A = a.exec(U);
163
+ if (!A) continue;
164
+ const C = Number(A[1]);
165
+ !Number.isInteger(C) || C < 1001 || C > 9999 || l.push({
166
+ path: u,
167
+ tile: C,
168
+ score: et(n, m)
169
+ });
170
+ }
171
+ if (!l.length) return { paths: [], tiles: [] };
172
+ const h = Math.max(...l.map((u) => u.score)), d = l.filter((u) => u.score === h).sort((u, y) => u.tile - y.tile || u.path.localeCompare(y.path));
173
+ return {
174
+ paths: d.map((u) => u.path),
175
+ tiles: d.map((u) => u.tile)
176
+ };
177
+ }
178
+ function _t(t) {
179
+ if (!t.tiles.length) return null;
180
+ const e = t.tiles.map(Qe), s = Math.min(...e.map(({ column: l }) => l)), n = Math.max(...e.map(({ column: l }) => l)), r = Math.min(...e.map(({ row: l }) => l)), a = Math.max(...e.map(({ row: l }) => l));
181
+ return {
182
+ minColumn: s,
183
+ maxColumn: n,
184
+ minRow: r,
185
+ maxRow: a,
186
+ columns: n - s + 1,
187
+ rows: a - r + 1
188
+ };
189
+ }
190
+ function Qe(t) {
191
+ const e = t - 1001;
192
+ return {
193
+ column: (e % 10 + 10) % 10,
194
+ row: Math.floor(e / 10)
195
+ };
196
+ }
197
+ function xe(t) {
198
+ const e = t.split(/<UDIM>/i);
199
+ return e.length !== 2 ? null : new RegExp(`^${ge(e[0])}(\\d{4})${ge(e[1])}$`, "i");
200
+ }
201
+ function et(t, e) {
202
+ const s = t.split("/").slice(0, -1).filter(Boolean), n = e.split("/").slice(0, -1).filter(Boolean);
203
+ let r = 0;
204
+ for (; r < s.length && r < n.length; ) {
205
+ const a = s.at(-1 - r), l = n.at(-1 - r);
206
+ if ((a == null ? void 0 : a.toLowerCase()) !== (l == null ? void 0 : l.toLowerCase())) break;
207
+ r += 1;
208
+ }
209
+ return r;
210
+ }
211
+ function we(t) {
212
+ const e = t.replace(/%3CUDIM%3E/gi, "<UDIM>");
213
+ try {
214
+ return decodeURIComponent(e);
215
+ } catch {
216
+ return e;
217
+ }
218
+ }
219
+ function Ae(t) {
220
+ const e = t.search(/[?#]/);
221
+ return e < 0 ? t : t.slice(0, e);
222
+ }
223
+ function ge(t) {
224
+ return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
225
+ }
226
+ class tt {
227
+ constructor(e) {
228
+ k(this, "entries", /* @__PURE__ */ new Map());
229
+ k(this, "objectUrls", /* @__PURE__ */ new Map());
230
+ k(this, "objectUrlPaths", /* @__PURE__ */ new Map());
231
+ /**
232
+ * Reads that already failed, so a missing resource is not requested again by
233
+ * the visual adapter after the reference prefetch has recorded it.
234
+ */
235
+ k(this, "failures", /* @__PURE__ */ new Map());
236
+ k(this, "localPackage");
237
+ this.source = e;
238
+ const s = e.original;
239
+ if (this.localPackage = ve(s) || typeof Blob < "u" && s instanceof Blob || s instanceof ArrayBuffer || typeof s == "object" && s !== null && "kind" in s && s.kind === "buffer", ve(s))
240
+ for (const n of s.files) this.entries.set(R(n.path), n.file);
241
+ else e.entryBlob && typeof s == "object" && s !== null && "kind" in s && s.kind === "remote-entry" ? this.entries.set(e.entryPath ?? s.entryPath, e.entryBlob) : typeof Blob < "u" && s instanceof Blob ? this.entries.set(e.entryPath ?? e.filename ?? "asset", s) : s instanceof ArrayBuffer ? this.entries.set(e.entryPath ?? e.filename ?? "asset", new Blob([s])) : typeof s == "object" && s !== null && "kind" in s && s.kind === "buffer" && this.entries.set(e.entryPath ?? e.filename ?? "asset", new Blob([s.buffer]));
242
+ }
243
+ paths() {
244
+ return [...this.entries.keys()];
245
+ }
246
+ hasLocalFiles() {
247
+ return this.localPackage;
248
+ }
249
+ put(e, s) {
250
+ this.entries.set(R(e), s);
251
+ }
252
+ relativePaths(e = "", s = !1) {
253
+ return [...this.relativeEntries(e, s)].map(([n]) => n);
254
+ }
255
+ asSourceRecord(e = "", s = !1) {
256
+ return Object.fromEntries(this.relativeEntries(e, s));
257
+ }
258
+ *relativeEntries(e = "", s = !1) {
259
+ const n = R(e), r = n ? `${n}/` : "";
260
+ for (const [a, l] of this.entries)
261
+ if (!r || a.startsWith(r)) yield [r ? a.slice(r.length) : a, l];
262
+ else if (s) {
263
+ const h = n.split("/"), d = a.split("/");
264
+ let u = 0;
265
+ for (; u < h.length && h[u] === d[u]; ) u++;
266
+ yield [[...h.slice(u).map(() => ".."), ...d.slice(u)].join("/"), l];
267
+ }
268
+ }
269
+ resolve(e, s = "") {
270
+ const n = this.find(e, s);
271
+ if (n) return n;
272
+ const r = R(s).split("/").slice(0, -1).join("/");
273
+ if (this.source.url) return R(`${r}/${e.replace(/^package:\/\//, "")}`);
274
+ throw T(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
275
+ }
276
+ find(e, s = "") {
277
+ const n = R(e.replace(/^package:\/\//, ""));
278
+ if (x(n)) return this.entries.has(n) ? n : null;
279
+ const r = R(s).split("/").slice(0, -1).join("/");
280
+ for (const l of [R(`${r}/${e.replace(/^package:\/\//, "")}`), n])
281
+ if (this.entries.has(l)) return l;
282
+ const a = this.paths().filter(
283
+ (l) => !x(l) && (l === n || l.endsWith(`/${n}`) || n.endsWith(`/${l}`))
284
+ );
285
+ return a.length === 1 ? a[0] : null;
286
+ }
287
+ async text(e) {
288
+ await this.ensure(e);
289
+ const s = this.entries.get(this.resolve(e));
290
+ if (!s) throw T(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
291
+ return s.text();
292
+ }
293
+ async bytes(e) {
294
+ await this.ensure(e);
295
+ const s = this.entries.get(this.resolve(e));
296
+ if (!s) throw T(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
297
+ return new Uint8Array(await s.arrayBuffer());
298
+ }
299
+ getBlob(e) {
300
+ const s = this.resolve(e), n = this.entries.get(s);
301
+ if (!n) throw T(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
302
+ return n;
303
+ }
304
+ async ensure(e, s) {
305
+ const n = R(e);
306
+ if (this.entries.has(n)) return;
307
+ const r = this.failures.get(n);
308
+ if (r) throw r;
309
+ try {
310
+ const a = await this.source.resolve(n, s);
311
+ if (!/^https?:\/\//i.test(a) && !/^blob:/i.test(a))
312
+ throw T(`Simulation resource not found: ${e}. Upload the complete asset folder or provide a resourceResolver/baseUrl.`, ie);
313
+ const l = await fetch(a, { signal: this.source.signal });
314
+ if (!l.ok) {
315
+ const u = l.status === 401 || l.status === 403 ? Re : l.status === 404 || l.status === 410 ? ie : Ie;
316
+ throw T(`Simulation resource request failed (${l.status}): ${a}`, u);
317
+ }
318
+ const h = await l.blob();
319
+ this.source.signal.throwIfAborted();
320
+ const d = await qe(h);
321
+ if (d) throw T(`Simulation resource is not usable (${d}): ${a}`, Ue);
322
+ this.entries.set(n, h);
323
+ } catch (a) {
324
+ throw De(a) === "aborted" || this.failures.set(n, a instanceof Error ? a : new Error(String(a))), a;
325
+ }
326
+ }
327
+ /** The recorded failure for a resource, if a previous read already failed. */
328
+ failureOf(e) {
329
+ return this.failures.get(R(e));
330
+ }
331
+ objectUrl(e) {
332
+ const s = this.resolve(e);
333
+ let n = this.objectUrls.get(s);
334
+ return n || (n = URL.createObjectURL(this.getBlob(s)), this.objectUrls.set(s, n), this.objectUrlPaths.set(n, s)), n;
335
+ }
336
+ pathForObjectUrl(e) {
337
+ return this.objectUrlPaths.get(e) ?? null;
338
+ }
339
+ /**
340
+ * Resolve a texture relative to the directory containing the entry layer.
341
+ * Pass the entry directory, not the entry file path.
342
+ */
343
+ findTexture(e, s = "") {
344
+ const n = this.findPresent(e, s);
345
+ if (n) return n;
346
+ const r = this.udimTextureSet(e);
347
+ return (r == null ? void 0 : r.paths.length) === 1 ? r.paths[0] : null;
348
+ }
349
+ udimTextureSet(e) {
350
+ return Ze(e, this.paths());
351
+ }
352
+ objectUrlIfPresent(e, s = "") {
353
+ const n = this.findTexture(e, s);
354
+ return n ? this.objectUrl(n) : null;
355
+ }
356
+ findPresent(e, s = "") {
357
+ if (x(e)) return this.entries.has(e) ? e : null;
358
+ const n = R(s), r = n ? `${n}/` : "", a = R(e), l = r ? this.paths().filter((h) => {
359
+ if (!h.startsWith(r)) return !1;
360
+ const d = h.slice(r.length);
361
+ return d === a || a.endsWith(`/${d}`);
362
+ }) : [];
363
+ return l.length === 1 ? l[0] : this.find(e);
364
+ }
365
+ dispose() {
366
+ for (const e of this.objectUrls.values()) URL.revokeObjectURL(e);
367
+ this.objectUrls.clear(), this.objectUrlPaths.clear(), this.entries.clear(), this.failures.clear();
368
+ }
369
+ }
370
+ async function st(t, e) {
371
+ if (e.hasLocalFiles()) return e.text(t.entryPath ?? t.filename ?? e.paths()[0]);
372
+ const s = await fetch(t.url ?? await t.resolve(t.entryPath ?? ""), { signal: t.signal });
373
+ if (!s.ok) throw T(`Simulation asset request failed: ${s.status}`, "E_ASSET_FETCH");
374
+ return s.text();
375
+ }
376
+ function wt(t) {
377
+ return R(t);
378
+ }
379
+ function R(t) {
380
+ if (x(t)) return t;
381
+ const e = [];
382
+ for (const s of t.replaceAll("\\", "/").split("/"))
383
+ !s || s === "." || (s === ".." && e.length && e.at(-1) !== ".." ? e.pop() : e.push(s));
384
+ return e.join("/");
385
+ }
386
+ function x(t) {
387
+ return /^[a-z][a-z\d+.-]*:/i.test(t) && !/^package:\/\//i.test(t);
388
+ }
389
+ function ve(t) {
390
+ return typeof t == "object" && t !== null && "kind" in t && t.kind === "files";
391
+ }
392
+ function T(t, e) {
393
+ return Object.assign(new Error(t), { code: e });
394
+ }
395
+ function rt() {
396
+ return { errors: [], warnings: [], approximations: [], droppedFeatures: [] };
397
+ }
398
+ function nt(t, e = {}) {
399
+ const s = Object.freeze({ schemaVersion: 1, ...t });
400
+ return it(s, e), s;
401
+ }
402
+ function it(t, e = {}) {
403
+ if (!t.id.trim() || !t.name.trim()) throw Z("Asset IR id and name are required.", "E_ASSET_IR_INVALID");
404
+ if (t.source.format !== "usd" && t.links.length === 0) throw Z("Asset IR requires at least one link.", "E_ASSET_IR_INVALID");
405
+ const s = /* @__PURE__ */ new Set();
406
+ for (const r of t.links) {
407
+ if (!r.id || s.has(r.id)) throw Z(`Invalid or duplicate link: ${r.id}`, "E_ASSET_IR_INVALID");
408
+ s.add(r.id);
409
+ }
410
+ const n = /* @__PURE__ */ new Set();
411
+ for (const r of t.joints) {
412
+ if (!r.id || n.has(r.id) || !e.allowInvalidGraph && (!s.has(r.parent) || !s.has(r.child)))
413
+ throw Z(`Invalid joint: ${r.id}`, "E_ASSET_IR_INVALID");
414
+ n.add(r.id);
415
+ }
416
+ }
417
+ function Z(t, e) {
418
+ return Object.assign(new Error(t), { code: e });
419
+ }
420
+ async function ot(t, e, s) {
421
+ var d;
422
+ const n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), l = async (u, y) => {
423
+ if (a.has(u)) throw ae(`MJCF include cycle: ${u}`, "E_MJCF_INCLUDE_CYCLE");
424
+ a.add(u);
425
+ const m = ft(y, u);
426
+ n.set(u, m);
427
+ for (const U of m.querySelectorAll("worldbody body[name]")) r.add(U.getAttribute("name"));
428
+ for (const U of m.querySelectorAll("include[file]")) {
429
+ const A = s.resolve(U.getAttribute("file"), u);
430
+ await l(A, await s.text(A));
431
+ }
432
+ a.delete(u);
433
+ };
434
+ await l(e, t);
435
+ const h = (d = n.get(e)) == null ? void 0 : d.querySelector("mujoco");
436
+ if (!h || r.size === 0) throw ae("MJCF requires a mujoco root and at least one named body.", "E_MJCF_PARSE");
437
+ return nt({
438
+ id: h.getAttribute("model") || e,
439
+ name: h.getAttribute("model") || e,
440
+ source: { format: "mjcf", uri: e },
441
+ links: [...r].map((u) => ({ id: u, name: u, visuals: [], collisions: [] })),
442
+ joints: [],
443
+ diagnostics: rt(),
444
+ extension: { files: s, xml: t, documents: n }
445
+ });
446
+ }
447
+ async function at(t) {
448
+ const e = t.extension.files, s = t.source.uri, n = s.split("/").slice(0, -1).join("/"), r = /* @__PURE__ */ new Map(), a = t.extension.documents;
449
+ for (const [d, u] of a) {
450
+ const y = u.querySelector("compiler");
451
+ for (const m of u.querySelectorAll("asset [file]")) {
452
+ const U = (y == null ? void 0 : y.getAttribute(m.tagName === "texture" ? "texturedir" : "meshdir")) ?? (y == null ? void 0 : y.getAttribute("assetdir")) ?? "", A = e.resolve(`${U}/${m.getAttribute("file")}`, d);
453
+ await e.bytes(A);
454
+ }
455
+ }
456
+ for (const d of ct(e.paths(), a)) {
457
+ if (d === s) continue;
458
+ const u = n && d.startsWith(`${n}/`) ? d.slice(n.length + 1) : d;
459
+ r.set(u, await e.bytes(d));
460
+ }
461
+ const l = t.extension.xml;
462
+ return { format: "mjcf", xml: lt(a) ? ut(l) : l, files: r };
463
+ }
464
+ function lt(t) {
465
+ return t.size === 0 || ![...t.values()].some((s) => s.querySelector("freejoint, actuator") ? !0 : [...s.querySelectorAll("joint")].some(
466
+ (n) => (n.getAttribute("type") ?? "hinge").toLowerCase() !== "fixed"
467
+ )) ? !1 : ![...t.values()].some(
468
+ (s) => [...s.querySelectorAll("worldbody geom")].some((n) => {
469
+ var r;
470
+ return ((r = n.getAttribute("type")) == null ? void 0 : r.toLowerCase()) === "plane";
471
+ })
472
+ );
473
+ }
474
+ function ut(t) {
475
+ const e = '<geom name="__viewer_default_ground__" type="plane" size="5 5 0.1" contype="1" conaffinity="1" friction="0.8 0.01 0.0002"/>';
476
+ return /<worldbody\b[^>]*>/i.test(t) ? t.replace(/(<worldbody\b[^>]*>)/i, `$1${e}`) : t.replace(/<\/mujoco\s*>/i, `<worldbody>${e}</worldbody></mujoco>`);
477
+ }
478
+ function ct(t, e) {
479
+ const s = (h) => h.replaceAll("\\", "/").split("/").pop() ?? "", n = /* @__PURE__ */ new Map();
480
+ for (const h of t) {
481
+ const d = s(h), u = n.get(d) ?? [];
482
+ u.push(h), n.set(d, u);
483
+ }
484
+ const r = new Set(e.keys()), a = /* @__PURE__ */ new Set(["include", "mesh", "texture", "hfield", "skin"]), l = /* @__PURE__ */ new Set(["fileleft", "fileright", "fileup", "filedown", "filefront", "fileback"]);
485
+ for (const h of e.values()) {
486
+ if (h.querySelector("plugin, extension, model, attach")) return t;
487
+ for (const d of h.querySelectorAll("*"))
488
+ for (const u of d.attributes) {
489
+ if (!u.name.startsWith("file")) continue;
490
+ if (u.name === "file") {
491
+ if (!a.has(d.tagName)) return t;
492
+ } else if (!(d.tagName === "texture" && l.has(u.name)))
493
+ return t;
494
+ if (!u.value) continue;
495
+ const y = n.get(s(u.value));
496
+ if (!y) return t;
497
+ for (const m of y) r.add(m);
498
+ }
499
+ }
500
+ return t.filter((h) => r.has(h));
501
+ }
502
+ function ft(t, e) {
503
+ const s = new DOMParser().parseFromString(t, "application/xml"), n = s.querySelector("parsererror");
504
+ if (n) throw ae(`MJCF XML parse failed (${e}): ${n.textContent ?? ""}`, "E_MJCF_PARSE");
505
+ return s;
506
+ }
507
+ function ae(t, e) {
508
+ return Object.assign(new Error(t), { code: e });
509
+ }
510
+ function dt(t, e) {
511
+ const s = new tt(t), n = e.format === "usd" || e.format === "usda" || e.format === "usdc" || e.format === "usdz";
512
+ let r = null, a = null, l = null, h = null, d = null, u = null, y = null, m = null, U = null, A = null, C = null, E = !1, v = !1, _ = !1, I = !1, g = null, N = null, ue, w = null, F = null, i = null, c = null, L = null, b = null, B = null, $ = !1, G = null, J = "z", ee = !1;
513
+ const V = () => {
514
+ i && (J = e.options.upAxis ?? "z", ee = !0, i.setUpAxis(J) && (a == null || a.sync(), c == null || c.sync()));
515
+ }, z = (o, f) => {
516
+ var O;
517
+ const S = ne(o, e.signal, `${e.format}:${f}`);
518
+ v = !1, _ = !1, N = { ...S, stage: f };
519
+ try {
520
+ i == null || i.endGrab();
521
+ } catch {
522
+ }
523
+ (O = e.reportSessionState) == null || O.call(e), e.reportError(o, { fatal: !1, stage: f, code: S.code });
524
+ }, je = (o) => {
525
+ var f;
526
+ if (E) {
527
+ o.dispose();
528
+ return;
529
+ }
530
+ b = null, $ = !1, w = o.asset, l = o.dispose, I = o.hasAnimation === !0, h = o.hasPhysics || I ? o.step : null, d = o.reset, v = !o.hasPhysics && o.hasAnimation === !0, _ = o.hasPhysics, g = o.fallback ? { ...o.fallback, stage: "physics-fallback" } : o.visualWarning ? { ...o.visualWarning, stage: "visual-adaptation" } : null, a = o.binding, r = o.runtime ?? null, F = o.physics ?? null, G = o.inspect ?? null, c = o.collision ?? null, L = o.createCollision ?? null, i == null || i.setRuntime(o.runtime), i == null || i.replaceModel(o.binding.root), c && (c.root.visible = !1, i == null || i.attachAuxiliary(c.root), c.sync()), V(), (f = e.reportSessionState) == null || f.call(e), e.requestRender();
531
+ }, Ne = (o) => {
532
+ var S;
533
+ if (E) return;
534
+ const f = ne(o, e.signal, "usd-physics");
535
+ $ = !1, N = { ...f, stage: "usd-physics" }, _ = !1, I = (b == null ? void 0 : b.visual.hasAnimation) ?? I, h = b != null && b.visual.hasAnimation ? b.visual.step : null, d = b != null && b.visual.hasAnimation ? b.visual.reset : null, v = !!(b != null && b.visual.hasAnimation), (S = e.reportSessionState) == null || S.call(e), e.reportError(o, { fatal: !1, stage: "usd-physics", code: f.code });
536
+ }, ce = () => {
537
+ E = !0, v = !1;
538
+ }, fe = () => {
539
+ if (c) return !0;
540
+ const o = L;
541
+ return L = null, !o || !i || (c = o() ?? null, !c) ? !1 : (c.root.visible = !1, i.attachAuxiliary(c.root), c.sync(), !0);
542
+ };
543
+ let de = () => {
544
+ }, he = () => {
545
+ }, pe = !1;
546
+ const te = new Promise((o, f) => {
547
+ de = o, he = f;
548
+ }), H = () => {
549
+ pe || (pe = !0, de());
550
+ };
551
+ return (async () => {
552
+ var o, f, S, O, Y, D, q, W, me, ye;
553
+ try {
554
+ const P = e.format;
555
+ if (P === "usd" || P === "usda" || P === "usdc" || P === "usdz") {
556
+ (o = e.reportProgress) == null || o.call(e, "usd-visual", "正在解析 USD 视觉场景...");
557
+ const p = await (await import("./usd-session-CTzInpNy.js")).loadUsdSimulation(t, e, s);
558
+ if (E || e.signal.aborted)
559
+ throw p.dispose(), le();
560
+ b = p, a = { root: p.visual.root, sync() {
561
+ }, dispose() {
562
+ } }, l = p.dispose, I = p.visual.hasAnimation, h = I ? p.visual.step : null, d = p.visual.reset, v = !1, $ = !0, g = p.visual.warning ? { ...p.visual.warning, stage: "visual-adaptation" } : null, (f = e.reportProgress) == null || f.call(e, "stage", "正在构建三维场景与环境光影..."), i = new re(
563
+ p.visual.root,
564
+ e.options.simulationTheme,
565
+ void 0,
566
+ "simulation",
567
+ "visual"
568
+ ), V(), H(), (S = e.reportProgress) == null || S.call(e, "usd-physics", "视觉场景已就绪,正在准备物理..."), B = p.completePhysics().then(je).catch(Ne);
569
+ return;
570
+ }
571
+ if (P === "urdf" || P === "xacro") {
572
+ (O = e.reportProgress) == null || O.call(e, "urdf", "正在解析 URDF 场景与运动学结构...");
573
+ const p = await (await import("./urdf-session-CRXL4bHf.js")).loadUrdfSimulation(t, e, s);
574
+ if (E || e.signal.aborted)
575
+ throw p.dispose(), le();
576
+ w = p.asset, i = p.stage, U = p.inspection, l = p.dispose, h = p.step, d = p.reset, u = p.play, y = p.pause, m = p.isPlaying, A = () => p.capabilities, C = () => p.physics, v = !1, _ = !1, g = p.warning ?? null, V(), H();
577
+ return;
578
+ }
579
+ let X = t.entryPath ?? t.filename;
580
+ if (!X && P === "mjcf") {
581
+ const j = s.paths().filter((p) => p.toLowerCase().endsWith(".xml"));
582
+ for (const p of ["scene.xml", "model.xml", "main.xml"]) {
583
+ const K = j.find((M) => M.toLowerCase().endsWith(`/${p}`) || M.toLowerCase() === p);
584
+ if (K) {
585
+ X = K;
586
+ break;
587
+ }
588
+ }
589
+ }
590
+ X ?? (X = "asset.xml"), (Y = e.reportProgress) == null || Y.call(e, "fetch", "正在读取模型描述与依赖资源...");
591
+ const Pe = await st(t, s);
592
+ Q(E, e.signal), (D = e.reportProgress) == null || D.call(e, "parse", "正在解析 MJCF 场景与连杆..."), w = await ot(Pe, X, s);
593
+ try {
594
+ (q = e.reportProgress) == null || q.call(e, "compile", "正在编译物理模型与参数...");
595
+ const j = await at(w);
596
+ F = j, Q(E, e.signal), (W = e.reportProgress) == null || W.call(e, "runtime", "正在初始化物理内核...");
597
+ const { MujocoRuntime: p } = await import("./mujoco-runtime-BYZnrvbR.js");
598
+ r = new p(), await r.initialize(j, {
599
+ baseUrl: e.options.mujocoBaseUrl,
600
+ wasmModule: e.options.mujocoWasmModule
601
+ });
602
+ } catch (j) {
603
+ const p = ne(j, e.signal, "mjcf-physics");
604
+ r == null || r.dispose(), r = null;
605
+ const { compileMjcfPreview: K } = await import("./mjcf-visual-IOy-ucto.js");
606
+ let M;
607
+ try {
608
+ M = K(w);
609
+ } catch (se) {
610
+ throw new Error(`${p.message};独立视觉预览也不可用:${se instanceof Error ? se.message : String(se)}`);
611
+ }
612
+ a = { root: M, sync() {
613
+ }, dispose() {
614
+ Fe(M);
615
+ } }, g = { ...p, stage: "physics-fallback" }, i = new re(M, e.options.simulationTheme, void 0, "simulation", "visual"), v = !1, V(), H();
616
+ return;
617
+ }
618
+ _ = !0, Q(E, e.signal), (me = e.reportProgress) == null || me.call(e, "visual", "正在构建视觉渲染网格...");
619
+ const Te = be(r, !1, w.diagnostics), Ee = w.diagnostics.droppedFeatures.find((j) => j.code.startsWith("MJCF_"));
620
+ Ee && (g = { ...Ee, stage: "visual-material" }), Q(E, e.signal), (ye = e.reportProgress) == null || ye.call(e, "stage", "正在构建三维场景与环境光影..."), a = new _e(r, Te), i = new re(a.root, e.options.simulationTheme, r);
621
+ const Se = be(r, !0, w.diagnostics);
622
+ Se.root.children.length > 0 ? (c = new _e(r, Se), c.root.visible = !1) : c = null, c && i.attachAuxiliary(c.root), V(), H();
623
+ } catch (P) {
624
+ throw i == null || i.dispose(), i = null, l ? (l(), l = null) : (c == null || c.dispose(), a == null || a.dispose(), r == null || r.dispose()), c = null, a = null, r = null, s.dispose(), F = null, b = null, P;
625
+ }
626
+ })().catch(he), te.catch(() => {
627
+ }), {
628
+ id: `simulation-${Math.random().toString(36).slice(2)}`,
629
+ get autoPlay() {
630
+ return !$ && !_ && I;
631
+ },
632
+ get inspection() {
633
+ return U;
634
+ },
635
+ isPlaying() {
636
+ return (m == null ? void 0 : m()) ?? v;
637
+ },
638
+ opened: te,
639
+ get root() {
640
+ return (i == null ? void 0 : i.root) ?? null;
641
+ },
642
+ getFitBounds() {
643
+ return (i == null ? void 0 : i.getModelBounds()) ?? null;
644
+ },
645
+ beforeRender(o, f, S) {
646
+ return i == null ? void 0 : i.beforeRender(o, f, S);
647
+ },
648
+ get capabilities() {
649
+ const o = c !== null || L !== null;
650
+ return N ? { canPlay: !1, canPause: !1, canReset: !1, hasPhysics: !1, hasAnimation: !1, canToggleGround: !0, canToggleCollision: o, canReorientUpAxis: !0 } : (A == null ? void 0 : A()) ?? { canPlay: _ || I, canPause: _ || I, canReset: _ || I, hasPhysics: _, hasAnimation: I, canToggleGround: !0, canToggleCollision: o, canReorientUpAxis: !0 };
651
+ },
652
+ get warning() {
653
+ return g && !g.notice ? Xe(g, g.stage) : g;
654
+ },
655
+ get physics() {
656
+ return N ? { status: "unavailable", issue: N } : C ? C() : $ ? { status: "initializing" } : _ ? { status: "ready" } : (g == null ? void 0 : g.stage) === "physics-fallback" ? { status: "unavailable", issue: g } : { status: "not-authored" };
657
+ },
658
+ setTheme(o) {
659
+ i == null || i.setTheme(o);
660
+ },
661
+ setGroundVisible(o) {
662
+ i == null || i.setGroundVisible(o);
663
+ },
664
+ getGroundVisible() {
665
+ return (i == null ? void 0 : i.getGroundVisible()) ?? !0;
666
+ },
667
+ getGroundGridScale() {
668
+ return (i == null ? void 0 : i.getGroundGridScale()) ?? ke;
669
+ },
670
+ getUpAxis() {
671
+ return i && ee ? J : null;
672
+ },
673
+ setUpAxis(o) {
674
+ if (!(E || !i))
675
+ try {
676
+ if (!i.setUpAxis(o)) return;
677
+ J = o, a == null || a.sync(), c == null || c.sync(), e.requestRender();
678
+ } catch (f) {
679
+ z(f, "up-axis");
680
+ }
681
+ },
682
+ presentation: { preferredViewMode: "3d", interactionMode: "simulation", uiProfile: "simulation", fitPolicy: "fit-on-ready" },
683
+ beginDispose: ce,
684
+ setCollisionVisible(o) {
685
+ if (!E) {
686
+ if (A) {
687
+ const f = U;
688
+ f == null || f.setOverlay("collision", o);
689
+ return;
690
+ }
691
+ if (o && !fe()) throw new Error("This asset has no collision display.");
692
+ c && (c.root.visible = o), e.requestRender();
693
+ }
694
+ },
695
+ getCollisionRoot() {
696
+ return E || A || !fe() ? null : (c == null || c.sync(), (c == null ? void 0 : c.root) ?? null);
697
+ },
698
+ getVisualDiagnostics() {
699
+ return E || !w || w.source.format !== "usd" ? null : structuredClone({
700
+ report: w.extension.visualAdaptation,
701
+ diagnostics: w.diagnostics,
702
+ usd: (G == null ? void 0 : G()) ?? null
703
+ });
704
+ },
705
+ getPhysicsProperties() {
706
+ const o = r;
707
+ if (E || !_ || !(o != null && o.model) || !o.mujoco) return null;
708
+ const f = o.model, S = o.mujoco;
709
+ return structuredClone({
710
+ units: { length: "m", mass: "kg", time: "s" },
711
+ timestep: f.opt.timestep,
712
+ gravity: Array.from(f.opt.gravity),
713
+ bodyCount: f.nbody - 1,
714
+ jointCount: f.njnt,
715
+ geomCount: f.ngeom,
716
+ bodies: Array.from({ length: f.nbody - 1 }, (O, Y) => {
717
+ var q, W;
718
+ const D = Y + 1;
719
+ return {
720
+ id: D,
721
+ name: S.mj_id2name(f, S.mjtObj.mjOBJ_BODY.value, D),
722
+ mass: f.body_mass[D],
723
+ inertia: Array.from(f.body_inertia.slice(D * 3, D * 3 + 3)),
724
+ position: Array.from(((q = o.data) == null ? void 0 : q.xpos.slice(D * 3, D * 3 + 3)) ?? []),
725
+ quaternion: Array.from(((W = o.data) == null ? void 0 : W.xquat.slice(D * 4, D * 4 + 4)) ?? [])
726
+ };
727
+ }),
728
+ diagnostics: w == null ? void 0 : w.diagnostics
729
+ });
730
+ },
731
+ get update() {
732
+ return r != null && r.model || h || n ? (o) => {
733
+ if (N || E || !((m == null ? void 0 : m()) ?? v) || !a && !h || !h && !(r != null && r.model)) return !1;
734
+ try {
735
+ if (h) {
736
+ const S = h(o);
737
+ return S && (c == null || c.sync()), S;
738
+ }
739
+ const f = r.step(o);
740
+ return f && (a.sync(), c == null || c.sync(), i == null || i.updateForceLine()), f;
741
+ } catch (f) {
742
+ return z(f, "step"), !1;
743
+ }
744
+ } : void 0;
745
+ },
746
+ play() {
747
+ E || N || (u ? (u(), v = (m == null ? void 0 : m()) ?? !1) : (_ || I) && (v = !0));
748
+ },
749
+ pause() {
750
+ N || (y && y(), v = !1);
751
+ },
752
+ reset() {
753
+ if (!(N || E || !a && !d))
754
+ try {
755
+ i == null || i.endGrab(), d ? d() : (r == null || r.reset(), a.sync()), c == null || c.sync(), i == null || i.resetGround(), i == null || i.updateForceLine();
756
+ } catch (o) {
757
+ z(o, "reset");
758
+ }
759
+ },
760
+ beginGrab(o, f, S) {
761
+ if (E || !((m == null ? void 0 : m()) ?? v) || !_ && !C) return !1;
762
+ try {
763
+ return (i == null ? void 0 : i.beginGrab(o, f, S)) ?? !1;
764
+ } catch (O) {
765
+ return z(O, "grab"), !1;
766
+ }
767
+ },
768
+ moveGrab(o, f, S) {
769
+ if (!(E || !((m == null ? void 0 : m()) ?? v) || !_ && !C))
770
+ try {
771
+ i == null || i.moveGrab(o, f, S);
772
+ } catch (O) {
773
+ z(O, "grab");
774
+ }
775
+ },
776
+ endGrab() {
777
+ i == null || i.endGrab();
778
+ },
779
+ getScenePhysics() {
780
+ if (E || !_ || !F || !a) return null;
781
+ const o = /* @__PURE__ */ new Map();
782
+ return a.root.traverse((f) => {
783
+ typeof f.userData.bodyId == "number" && f.name && o.set(f.name, f);
784
+ }), {
785
+ ...F,
786
+ visualBindings: o
787
+ };
788
+ },
789
+ dispose() {
790
+ return ce(), ue ?? (ue = te.catch(() => {
791
+ }).then(async () => {
792
+ i == null || i.dispose(), i = null, l ? (l(), l = null, i = null, a = null, c = null, L = null) : (c == null || c.root.removeFromParent(), c == null || c.dispose(), c = null, L = null, a == null || a.dispose(), a = null, r == null || r.dispose()), await (B == null ? void 0 : B.catch(() => {
793
+ })), b = null, s.dispose(), w = null, U = null, G = null, h = null, d = null, u = null, y = null, m = null, A = null, C = null, _ = !1, I = !1, g = null, ee = !1;
794
+ })), ue;
795
+ }
796
+ };
797
+ }
798
+ function Q(t, e) {
799
+ if (t || e.aborted) throw le();
800
+ }
801
+ function le() {
802
+ return Object.assign(new Error("Simulation load aborted."), { name: "AbortError", code: "E_ABORTED" });
803
+ }
804
+ const At = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
805
+ __proto__: null,
806
+ createSimulationSession: dt
807
+ }, Symbol.toStringTag, { value: "Module" }));
808
+ export {
809
+ Ue as U,
810
+ yt as a,
811
+ St as b,
812
+ Et as c,
813
+ nt as d,
814
+ De as e,
815
+ rt as f,
816
+ st as g,
817
+ oe as h,
818
+ bt as i,
819
+ wt as n,
820
+ ne as p,
821
+ Ze as r,
822
+ At as s,
823
+ _t as u,
824
+ Xe as w
825
+ };