@nebula-spatial/viewer 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,883 @@
1
+ var Ue = Object.defineProperty;
2
+ var Le = (s, e, o) => e in s ? Ue(s, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : s[e] = o;
3
+ var $ = (s, e, o) => Le(s, typeof e != "symbol" ? e + "" : e, o);
4
+ import { b as X, S as Q } from "./stage-DGMYxyAS.js";
5
+ import { U as de, a as Pe, b as De, i as Te, c as Fe, d as Ie, D as Ne } from "./index-bTlVsOHA.js";
6
+ import { LineBasicMaterial as $e, MeshBasicMaterial as Be, DoubleSide as ze, WireframeGeometry as ke, LineSegments as xe, Mesh as te, EdgesGeometry as ee, Vector3 as pe, Color as qe, LinearSRGBColorSpace as Ve, SRGBColorSpace as je, MeshPhysicalMaterial as Je, Float32BufferAttribute as H, DataTexture as He, RGBAFormat as We, UnsignedByteType as Xe, NoColorSpace as Ye, RepeatWrapping as Ke, LinearFilter as Ze, LinearMipmapLinearFilter as Qe, BufferGeometry as ie, Group as he, PlaneGeometry as Se, BoxGeometry as Me, SphereGeometry as se, Matrix4 as et, CylinderGeometry as Oe, CapsuleGeometry as ve, BufferAttribute as oe } from "three";
7
+ function _e(s, e, o) {
8
+ if (e.throwIfAborted(), s instanceof Error && (s.name === "AbortError" || ["E_ABORTED", "E_SUPERSEDED"].includes(String(s.code)))) throw s;
9
+ const t = s && typeof s == "object" && "code" in s && typeof s.code == "string" ? s.code : "E_PHYSICS_INITIALIZE", r = s instanceof Error ? s.message : String(s);
10
+ return { code: t, source: o, message: `无法启用物理仿真(${o}):${r}` };
11
+ }
12
+ class ge {
13
+ constructor(e, o) {
14
+ $(this, "root");
15
+ $(this, "bodies", /* @__PURE__ */ new Map());
16
+ $(this, "links", /* @__PURE__ */ new Map());
17
+ $(this, "disposed", !1);
18
+ this.runtime = e, this.root = o.root;
19
+ const t = e.mujoco, r = e.model;
20
+ for (const [l, n] of o.bindings) {
21
+ const c = t.mj_name2id(r, t.mjtObj.mjOBJ_BODY.value, l);
22
+ if (c < 0) throw ye(`Physics body missing for visual link: ${l}`, "E_SIMULATION_BIND");
23
+ this.links.set(l, n), n.userData.bodyId = c, this.bodies.set(c, n);
24
+ }
25
+ if (this.bodies.size !== o.expectedLinkCount) throw ye("Visual body binding count mismatch.", "E_SIMULATION_BIND");
26
+ this.sync();
27
+ }
28
+ objectForLink(e) {
29
+ return this.links.get(e) ?? null;
30
+ }
31
+ bodyPoses() {
32
+ return new Map([...this.bodies.values()].map((e) => [e.name, { position: e.position.clone(), quaternion: e.quaternion.clone() }]));
33
+ }
34
+ sync() {
35
+ if (this.disposed || !this.runtime.data) return;
36
+ const { xpos: e, xquat: o } = this.runtime.data;
37
+ for (const [t, r] of this.bodies) {
38
+ const l = t * 3, n = t * 4;
39
+ r.position.set(e[l], e[l + 1], e[l + 2]), r.quaternion.set(o[n + 1], o[n + 2], o[n + 3], o[n]);
40
+ }
41
+ this.root.updateMatrixWorld(!0);
42
+ }
43
+ dispose() {
44
+ this.disposed || (this.disposed = !0, this.bodies.clear(), this.links.clear(), X(this.root));
45
+ }
46
+ }
47
+ function ye(s, e) {
48
+ return Object.assign(new Error(s), { code: e });
49
+ }
50
+ class tt {
51
+ constructor(e) {
52
+ $(this, "entries", /* @__PURE__ */ new Map());
53
+ $(this, "objectUrls", /* @__PURE__ */ new Map());
54
+ /**
55
+ * Reads that already failed, so a missing resource is not requested again by
56
+ * the visual adapter after the reference prefetch has recorded it.
57
+ */
58
+ $(this, "failures", /* @__PURE__ */ new Map());
59
+ this.source = e;
60
+ const o = e.original;
61
+ if (ot(o))
62
+ for (const t of o.files) this.entries.set(P(t.path), t.file);
63
+ else typeof Blob < "u" && o instanceof Blob ? this.entries.set(e.entryPath ?? e.filename ?? "asset", o) : o instanceof ArrayBuffer ? this.entries.set(e.entryPath ?? e.filename ?? "asset", new Blob([o])) : typeof o == "object" && o !== null && "kind" in o && o.kind === "buffer" && this.entries.set(e.entryPath ?? e.filename ?? "asset", new Blob([o.buffer]));
64
+ }
65
+ paths() {
66
+ return [...this.entries.keys()];
67
+ }
68
+ hasLocalFiles() {
69
+ return this.entries.size > 0;
70
+ }
71
+ put(e, o) {
72
+ this.entries.set(P(e), o);
73
+ }
74
+ asSourceRecord(e = "", o = !1) {
75
+ const t = P(e), r = t ? `${t}/` : "", l = {};
76
+ for (const [n, c] of this.entries)
77
+ if (!r || n.startsWith(r)) l[r ? n.slice(r.length) : n] = c;
78
+ else if (o) {
79
+ const i = t.split("/"), a = n.split("/");
80
+ let d = 0;
81
+ for (; d < i.length && i[d] === a[d]; ) d++;
82
+ l[[...i.slice(d).map(() => ".."), ...a.slice(d)].join("/")] = c;
83
+ }
84
+ return l;
85
+ }
86
+ resolve(e, o = "") {
87
+ const t = this.find(e, o);
88
+ if (t) return t;
89
+ const r = P(o).split("/").slice(0, -1).join("/");
90
+ if (this.source.url) return P(`${r}/${e.replace(/^package:\/\//, "")}`);
91
+ throw B(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
92
+ }
93
+ find(e, o = "") {
94
+ const t = P(e.replace(/^package:\/\//, ""));
95
+ if (W(t)) return this.entries.has(t) ? t : null;
96
+ const r = P(o).split("/").slice(0, -1).join("/");
97
+ for (const n of [P(`${r}/${e.replace(/^package:\/\//, "")}`), t])
98
+ if (this.entries.has(n)) return n;
99
+ const l = this.paths().filter(
100
+ (n) => !W(n) && (n === t || n.endsWith(`/${t}`) || t.endsWith(`/${n}`))
101
+ );
102
+ return l.length === 1 ? l[0] : null;
103
+ }
104
+ async text(e) {
105
+ await this.ensure(e);
106
+ const o = this.entries.get(this.resolve(e));
107
+ if (!o) throw B(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
108
+ return o.text();
109
+ }
110
+ async bytes(e) {
111
+ await this.ensure(e);
112
+ const o = this.entries.get(this.resolve(e));
113
+ if (!o) throw B(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
114
+ return new Uint8Array(await o.arrayBuffer());
115
+ }
116
+ getBlob(e) {
117
+ const o = this.resolve(e), t = this.entries.get(o);
118
+ if (!t) throw B(`Simulation resource not found: ${e}`, "E_ASSET_RESOURCE_NOT_FOUND");
119
+ return t;
120
+ }
121
+ async ensure(e) {
122
+ const o = P(e);
123
+ if (this.entries.has(o)) return;
124
+ const t = this.failures.get(o);
125
+ if (t) throw t;
126
+ try {
127
+ const r = await this.source.resolve(o);
128
+ if (!/^https?:\/\//i.test(r) && !/^blob:/i.test(r))
129
+ throw B(`Simulation resource not found: ${e}. Upload the complete asset folder or provide a resourceResolver/baseUrl.`, de);
130
+ const l = await fetch(r, { signal: this.source.signal });
131
+ if (!l.ok) {
132
+ const i = l.status === 401 || l.status === 403 ? Pe : l.status === 404 || l.status === 410 ? de : De;
133
+ throw B(`Simulation resource request failed (${l.status}): ${r}`, i);
134
+ }
135
+ const n = await l.blob();
136
+ this.source.signal.throwIfAborted();
137
+ const c = await Te(n);
138
+ if (c) throw B(`Simulation resource is not usable (${c}): ${r}`, Fe);
139
+ this.entries.set(o, n);
140
+ } catch (r) {
141
+ throw Ie(r) === "aborted" || this.failures.set(o, r instanceof Error ? r : new Error(String(r))), r;
142
+ }
143
+ }
144
+ /** The recorded failure for a resource, if a previous read already failed. */
145
+ failureOf(e) {
146
+ return this.failures.get(P(e));
147
+ }
148
+ objectUrl(e) {
149
+ const o = this.resolve(e);
150
+ let t = this.objectUrls.get(o);
151
+ return t || (t = URL.createObjectURL(this.getBlob(o)), this.objectUrls.set(o, t)), t;
152
+ }
153
+ objectUrlIfPresent(e, o = "") {
154
+ if (W(e)) return this.entries.has(e) ? this.objectUrl(e) : null;
155
+ const t = P(o), r = t ? `${t}/` : "", l = P(e), n = r ? this.paths().filter((i) => {
156
+ if (!i.startsWith(r)) return !1;
157
+ const a = i.slice(r.length);
158
+ return a === l || l.endsWith(`/${a}`);
159
+ }) : [], c = n.length === 1 ? n[0] : this.find(e);
160
+ return c ? this.objectUrl(c) : null;
161
+ }
162
+ dispose() {
163
+ for (const e of this.objectUrls.values()) URL.revokeObjectURL(e);
164
+ this.objectUrls.clear(), this.entries.clear(), this.failures.clear();
165
+ }
166
+ }
167
+ async function st(s, e) {
168
+ if (e.hasLocalFiles()) return e.text(s.entryPath ?? s.filename ?? e.paths()[0]);
169
+ const o = await fetch(s.url ?? await s.resolve(s.entryPath ?? ""), { signal: s.signal });
170
+ if (!o.ok) throw B(`Simulation asset request failed: ${o.status}`, "E_ASSET_FETCH");
171
+ return o.text();
172
+ }
173
+ function Bt(s) {
174
+ return P(s);
175
+ }
176
+ function P(s) {
177
+ if (W(s)) return s;
178
+ const e = [];
179
+ for (const o of s.replaceAll("\\", "/").split("/"))
180
+ !o || o === "." || (o === ".." && e.length && e.at(-1) !== ".." ? e.pop() : e.push(o));
181
+ return e.join("/");
182
+ }
183
+ function W(s) {
184
+ return /^[a-z][a-z\d+.-]*:/i.test(s) && !/^package:\/\//i.test(s);
185
+ }
186
+ function ot(s) {
187
+ return typeof s == "object" && s !== null && "kind" in s && s.kind === "files";
188
+ }
189
+ function B(s, e) {
190
+ return Object.assign(new Error(s), { code: e });
191
+ }
192
+ function rt() {
193
+ return { errors: [], warnings: [], approximations: [], droppedFeatures: [] };
194
+ }
195
+ function nt(s, e = {}) {
196
+ const o = Object.freeze({ schemaVersion: 1, ...s });
197
+ return it(o, e), o;
198
+ }
199
+ function it(s, e = {}) {
200
+ if (!s.id.trim() || !s.name.trim()) throw V("Asset IR id and name are required.", "E_ASSET_IR_INVALID");
201
+ if (s.source.format !== "usd" && s.links.length === 0) throw V("Asset IR requires at least one link.", "E_ASSET_IR_INVALID");
202
+ const o = /* @__PURE__ */ new Set();
203
+ for (const r of s.links) {
204
+ if (!r.id || o.has(r.id)) throw V(`Invalid or duplicate link: ${r.id}`, "E_ASSET_IR_INVALID");
205
+ o.add(r.id);
206
+ }
207
+ const t = /* @__PURE__ */ new Set();
208
+ for (const r of s.joints) {
209
+ if (!r.id || t.has(r.id) || !e.allowInvalidGraph && (!o.has(r.parent) || !o.has(r.child)))
210
+ throw V(`Invalid joint: ${r.id}`, "E_ASSET_IR_INVALID");
211
+ t.add(r.id);
212
+ }
213
+ }
214
+ function V(s, e) {
215
+ return Object.assign(new Error(s), { code: e });
216
+ }
217
+ async function at(s, e, o) {
218
+ var i;
219
+ const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), n = async (a, d) => {
220
+ if (l.has(a)) throw re(`MJCF include cycle: ${a}`, "E_MJCF_INCLUDE_CYCLE");
221
+ l.add(a);
222
+ const h = mt(d, a);
223
+ t.set(a, h);
224
+ for (const S of h.querySelectorAll("worldbody body[name]")) r.add(S.getAttribute("name"));
225
+ for (const S of h.querySelectorAll("include[file]")) {
226
+ const E = o.resolve(S.getAttribute("file"), a);
227
+ await n(E, await o.text(E));
228
+ }
229
+ l.delete(a);
230
+ };
231
+ await n(e, s);
232
+ const c = (i = t.get(e)) == null ? void 0 : i.querySelector("mujoco");
233
+ if (!c || r.size === 0) throw re("MJCF requires a mujoco root and at least one named body.", "E_MJCF_PARSE");
234
+ return nt({
235
+ id: c.getAttribute("model") || e,
236
+ name: c.getAttribute("model") || e,
237
+ source: { format: "mjcf", uri: e },
238
+ links: [...r].map((a) => ({ id: a, name: a, visuals: [], collisions: [] })),
239
+ joints: [],
240
+ diagnostics: rt(),
241
+ extension: { files: o, xml: s, documents: t }
242
+ });
243
+ }
244
+ async function lt(s) {
245
+ const e = s.extension.files, o = s.source.uri, t = o.split("/").slice(0, -1).join("/"), r = /* @__PURE__ */ new Map(), l = s.extension.documents;
246
+ for (const [i, a] of l) {
247
+ const d = a.querySelector("compiler");
248
+ for (const h of a.querySelectorAll("asset [file]")) {
249
+ const S = (d == null ? void 0 : d.getAttribute(h.tagName === "texture" ? "texturedir" : "meshdir")) ?? (d == null ? void 0 : d.getAttribute("assetdir")) ?? "", E = e.resolve(`${S}/${h.getAttribute("file")}`, i);
250
+ await e.bytes(E);
251
+ }
252
+ }
253
+ for (const i of ft(e.paths(), l)) {
254
+ if (i === o) continue;
255
+ const a = t && i.startsWith(`${t}/`) ? i.slice(t.length + 1) : i;
256
+ r.set(a, await e.bytes(i));
257
+ }
258
+ const n = s.extension.xml;
259
+ return { format: "mjcf", xml: ut(l) ? ct(n) : n, files: r };
260
+ }
261
+ function ut(s) {
262
+ return s.size === 0 || ![...s.values()].some((o) => o.querySelector("freejoint, actuator") ? !0 : [...o.querySelectorAll("joint")].some(
263
+ (t) => (t.getAttribute("type") ?? "hinge").toLowerCase() !== "fixed"
264
+ )) ? !1 : ![...s.values()].some(
265
+ (o) => [...o.querySelectorAll("worldbody geom")].some((t) => {
266
+ var r;
267
+ return ((r = t.getAttribute("type")) == null ? void 0 : r.toLowerCase()) === "plane";
268
+ })
269
+ );
270
+ }
271
+ function ct(s) {
272
+ 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"/>';
273
+ return /<worldbody\b[^>]*>/i.test(s) ? s.replace(/(<worldbody\b[^>]*>)/i, `$1${e}`) : s.replace(/<\/mujoco\s*>/i, `<worldbody>${e}</worldbody></mujoco>`);
274
+ }
275
+ function ft(s, e) {
276
+ const o = (c) => c.replaceAll("\\", "/").split("/").pop() ?? "", t = /* @__PURE__ */ new Map();
277
+ for (const c of s) {
278
+ const i = o(c), a = t.get(i) ?? [];
279
+ a.push(c), t.set(i, a);
280
+ }
281
+ const r = new Set(e.keys()), l = /* @__PURE__ */ new Set(["include", "mesh", "texture", "hfield", "skin"]), n = /* @__PURE__ */ new Set(["fileleft", "fileright", "fileup", "filedown", "filefront", "fileback"]);
282
+ for (const c of e.values()) {
283
+ if (c.querySelector("plugin, extension, model, attach")) return s;
284
+ for (const i of c.querySelectorAll("*"))
285
+ for (const a of i.attributes) {
286
+ if (!a.name.startsWith("file")) continue;
287
+ if (a.name === "file") {
288
+ if (!l.has(i.tagName)) return s;
289
+ } else if (!(i.tagName === "texture" && n.has(a.name)))
290
+ return s;
291
+ if (!a.value) continue;
292
+ const d = t.get(o(a.value));
293
+ if (!d) return s;
294
+ for (const h of d) r.add(h);
295
+ }
296
+ }
297
+ return s.filter((c) => r.has(c));
298
+ }
299
+ function mt(s, e) {
300
+ const o = new DOMParser().parseFromString(s, "application/xml"), t = o.querySelector("parsererror");
301
+ if (t) throw re(`MJCF XML parse failed (${e}): ${t.textContent ?? ""}`, "E_MJCF_PARSE");
302
+ return o;
303
+ }
304
+ function re(s, e) {
305
+ return Object.assign(new Error(s), { code: e });
306
+ }
307
+ const Ae = 3073715, zt = 16758861, dt = 0.96, pt = 0.1, ht = 20, _t = 1;
308
+ function gt(s = Ae) {
309
+ return new $e({
310
+ color: s,
311
+ transparent: !0,
312
+ opacity: dt,
313
+ depthTest: !1,
314
+ depthWrite: !1,
315
+ linewidth: 2,
316
+ toneMapped: !1,
317
+ fog: !1
318
+ });
319
+ }
320
+ function yt(s = Ae) {
321
+ return new Be({
322
+ color: s,
323
+ transparent: !0,
324
+ opacity: pt,
325
+ depthTest: !0,
326
+ depthWrite: !1,
327
+ side: ze,
328
+ polygonOffset: !0,
329
+ polygonOffsetFactor: -1,
330
+ polygonOffsetUnits: -1,
331
+ toneMapped: !1,
332
+ fog: !1
333
+ });
334
+ }
335
+ function bt(s, e, o = "feature", t) {
336
+ const r = o === "mesh" ? new ke(s) : Et(s), l = new xe(r, e);
337
+ if (l.renderOrder = 9, t) {
338
+ const n = new te(s.clone(), t);
339
+ n.name = "collision-volume", n.renderOrder = 8, n.userData.collisionDebugRole = "volume", l.add(n), l.userData.collisionDebugRole = "outline";
340
+ }
341
+ return l;
342
+ }
343
+ function Et(s) {
344
+ let e = new ee(s, ht);
345
+ return be(s, e) || (e.dispose(), e = new ee(s, _t)), be(s, e) || (e.dispose(), e = new ee(s, 0)), e;
346
+ }
347
+ const wt = 256, jt = 0.5;
348
+ function be(s, e) {
349
+ var c, i;
350
+ const o = e.getAttribute("position");
351
+ if (!o || o.count === 0) return !1;
352
+ const t = s.getAttribute("position");
353
+ if (!t || t.count < wt) return !0;
354
+ s.computeBoundingBox(), e.computeBoundingBox();
355
+ const r = (c = s.boundingBox) == null ? void 0 : c.getSize(new pe()), l = (i = e.boundingBox) == null ? void 0 : i.getSize(new pe());
356
+ if (!r || !l) return !1;
357
+ const n = r.length();
358
+ return !Number.isFinite(n) || n <= 0 ? !0 : l.length() / n >= jt;
359
+ }
360
+ const Y = 0.5, k = (s, e) => Number.isFinite(s) ? Math.min(1, Math.max(0, s)) : e;
361
+ function Ee(s, e) {
362
+ return s !== void 0 && Number.isFinite(s) && s >= 0 ? k(s, Y) : e !== void 0 && Number.isFinite(e) && e >= 0 ? 1 - k(e, 0.5) : Y;
363
+ }
364
+ function St(s = {}) {
365
+ const e = s.color ?? [0.68, 0.72, 0.7, 1], o = new qe().setRGB(e[0], e[1], e[2], s.colorSpace === "linear" ? Ve : je), t = k(e[3] ?? 1, 1), r = k(s.specular ?? 0.5, 0.5), l = Math.sqrt(0.08 * r);
366
+ return new Je({
367
+ color: o,
368
+ opacity: t,
369
+ transparent: t < 1,
370
+ depthWrite: t === 1,
371
+ roughness: k(s.roughness ?? Y, Y),
372
+ metalness: k(s.metalness ?? 0, 0),
373
+ // Legacy specular 0.5 corresponds to the standard dielectric response.
374
+ specularIntensity: r <= 0.5 ? r * 2 : 1,
375
+ ior: r <= 0.5 ? 1.5 : (1 + l) / (1 - l),
376
+ emissive: o.clone().multiplyScalar(Math.max(0, s.emission ?? 0)),
377
+ map: s.map ?? null
378
+ });
379
+ }
380
+ function Mt(s, e) {
381
+ var S, E;
382
+ const o = [], t = [], r = [], l = s.mesh_vertadr[e], n = s.mesh_faceadr[e], c = s.mesh_normaladr[e], i = s.mesh_texcoordadr[e];
383
+ let a = c >= 0, d = i >= 0;
384
+ for (let g = 0; g < s.mesh_facenum[e]; g++) for (let w = 0; w < 3; w++) {
385
+ const m = (n + g) * 3 + w, b = (l + s.mesh_face[m]) * 3;
386
+ o.push(...s.mesh_vert.slice(b, b + 3));
387
+ const y = ((S = s.mesh_facenormal) == null ? void 0 : S[m]) ?? -1;
388
+ c >= 0 && y >= 0 ? t.push(...s.mesh_normal.slice((c + y) * 3, (c + y) * 3 + 3)) : a = !1;
389
+ const j = ((E = s.mesh_facetexcoord) == null ? void 0 : E[m]) ?? -1;
390
+ i >= 0 && j >= 0 ? r.push(...s.mesh_texcoord.slice((i + j) * 2, (i + j) * 2 + 2)) : d = !1;
391
+ }
392
+ const h = new ie();
393
+ return h.setAttribute("position", new H(o, 3)), a && t.length === o.length ? h.setAttribute("normal", new H(t, 3)) : h.computeVertexNormals(), d && r.length === o.length / 3 * 2 && h.setAttribute("uv", new H(r, 2)), h;
394
+ }
395
+ function Ot(s) {
396
+ const e = /* @__PURE__ */ new Map();
397
+ if (!s.model.ntex) return e;
398
+ const o = s.mujoco, t = s.model, r = new o.MjvScene(t, Math.max(1e3, t.ngeom * 2)), l = new o.MjvOption(), n = new o.MjvPerturb(), c = new o.MjvCamera();
399
+ try {
400
+ l.geomgroup.fill(1), o.mjv_updateScene(t, s.data, l, n, c, o.mjtCatBit.mjCAT_ALL.value, r);
401
+ for (let i = 0; i < r.ngeom; i++) {
402
+ const a = r.geoms.get(i);
403
+ try {
404
+ a.objtype === o.mjtObj.mjOBJ_GEOM.value && e.set(a.objid, a.texuniform !== 0);
405
+ } finally {
406
+ a.delete();
407
+ }
408
+ }
409
+ return e;
410
+ } finally {
411
+ r.delete(), l.delete(), n.delete(), c.delete();
412
+ }
413
+ }
414
+ function vt(s, e, o, t, r, l = /* @__PURE__ */ new Map()) {
415
+ var w;
416
+ const n = s.model, c = s.mujoco, i = n.geom_matid[e];
417
+ if (i < 0) return;
418
+ const a = (m, b) => {
419
+ r != null && r.droppedFeatures.some((y) => y.code === m && y.source === `material:${i}`) || r == null || r.droppedFeatures.push({ code: m, message: b, source: `material:${i}` });
420
+ };
421
+ n.mat_reflectance[i] > 0 && a("MJCF_REFLECTANCE_UNSUPPORTED", "Legacy planar reflection is not reproduced by the PBR material.");
422
+ const d = c.mjtTextureRole.mjNTEXROLE.value;
423
+ if (!Array.from(n.mat_texid.slice(i * d, (i + 1) * d)).some((m) => Number(m) >= 0)) return;
424
+ const E = !(n.geom_type[e] === c.mjtGeom.mjGEOM_MESH.value) || !o.getAttribute("uv"), g = l.get(e);
425
+ if (g === void 0) throw new Error(`Missing compiled texture projection for geom ${e}`);
426
+ if (E) {
427
+ const m = o.getAttribute("position"), b = [], y = n.geom_size[e * 3] || 1, j = n.geom_size[e * 3 + 1] || y;
428
+ for (let v = 0; v < m.count; v++) b.push(m.getX(v) / (2 * (g ? 1 : y)), -m.getY(v) / (2 * (g ? 1 : j)));
429
+ o.setAttribute("uv", new H(b, 2));
430
+ }
431
+ for (let m = 0; m < d; m++) {
432
+ const b = n.mat_texid[i * d + m];
433
+ if (b < 0) continue;
434
+ if (n.tex_type[b] !== c.mjtTexture.mjTEXTURE_2D.value) {
435
+ a("MJCF_TEXTURE_PROJECTION_UNSUPPORTED", "Cube/skybox surface textures require a dedicated projection and are not substituted with a 2D map.");
436
+ continue;
437
+ }
438
+ if (m === 0) {
439
+ a("MJCF_USER_TEXTURE_UNSUPPORTED", "User texture role has no defined PBR material slot.");
440
+ continue;
441
+ }
442
+ const y = n.tex_width[b], j = n.tex_height[b], v = n.tex_nchannel[b];
443
+ if (![1, 2, 3, 4].includes(v)) {
444
+ a("MJCF_TEXTURE_CHANNELS_UNSUPPORTED", "Unsupported texture channel count.");
445
+ continue;
446
+ }
447
+ const O = Number(n.tex_adr[b]), u = new Uint8Array(y * j * 4);
448
+ for (let R = 0; R < y * j; R++) {
449
+ const L = O + R * v, G = R * 4, T = n.tex_data[L];
450
+ u[G] = T, u[G + 1] = v >= 3 ? n.tex_data[L + 1] : T, u[G + 2] = v >= 3 ? n.tex_data[L + 2] : T, u[G + 3] = v === 4 ? n.tex_data[L + 3] : v === 2 ? n.tex_data[L + 1] : 255, [2, 3, 4, 6].includes(m) && (u[G] = u[G + 1] = u[G + 2] = T);
451
+ }
452
+ const f = new He(u, y, j, We, Xe);
453
+ f.colorSpace = [1, 7, 8].includes(m) && n.tex_colorspace[b] === c.mjtColorSpace.mjCOLORSPACE_SRGB.value ? je : Ye, f.wrapS = f.wrapT = Ke, f.magFilter = Ze, f.minFilter = Qe, f.generateMipmaps = !0;
454
+ const A = n.mat_texrepeat[i * 2], C = n.mat_texrepeat[i * 2 + 1];
455
+ if (f.repeat.set(A, C), E ? f.offset.set(-0.5, -0.5) : g && f.repeat.set(A * (n.geom_size[e * 3] || 1), C * (n.geom_size[e * 3 + 1] || 1)), f.needsUpdate = !0, m === 1 || m === 8)
456
+ (w = t.map) == null || w.dispose(), t.map = f, m === 8 && (t.transparent = !0, t.depthWrite = !1);
457
+ else if (m === 2) t.aoMap = f;
458
+ else if (m === 3)
459
+ t.roughnessMap = f, t.roughness = n.mat_roughness[i] >= 0 ? t.roughness : 1;
460
+ else if (m === 4)
461
+ t.metalnessMap = f, t.metalness = n.mat_metallic[i] >= 0 ? t.metalness : 1;
462
+ else if (m === 5) t.normalMap = f;
463
+ else if (m === 6)
464
+ t.alphaMap = f, t.transparent = !0, t.depthWrite = !1;
465
+ else if (m === 7)
466
+ t.emissiveMap = f, t.emissive.setRGB(1, 1, 1), v === 4 && a("MJCF_EMISSIVE_EXPOSURE_UNSUPPORTED", "Emissive RGB is preserved; per-pixel exposure weight is not supported.");
467
+ else if (m === 9) {
468
+ for (const R of /* @__PURE__ */ new Set([t.aoMap, t.roughnessMap, t.metalnessMap])) R == null || R.dispose();
469
+ t.aoMap = t.roughnessMap = t.metalnessMap = f, t.roughness = n.mat_roughness[i] >= 0 ? t.roughness : 1, t.metalness = n.mat_metallic[i] >= 0 ? t.metalness : 1;
470
+ }
471
+ }
472
+ }
473
+ function At(s, e) {
474
+ return e < 0 ? Ee() : Ee(s.mat_roughness[e], s.mat_shininess[e]);
475
+ }
476
+ function Gt(s, e) {
477
+ if (e < 0) return 0;
478
+ const o = s.mat_metallic[e];
479
+ return Number.isFinite(o) && o >= 0 ? o : 0;
480
+ }
481
+ function we(s, e = !1, o) {
482
+ const t = s.model, r = s.mujoco, l = new he();
483
+ l.name = "MuJoCo scene";
484
+ const n = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
485
+ for (let i = 1; i < t.nbody; i += 1) {
486
+ const a = r.mj_id2name(t, r.mjtObj.mjOBJ_BODY.value, i);
487
+ if (!a) continue;
488
+ const d = new he();
489
+ d.name = a, d.userData.bodyId = i, n.set(i, d), c.set(a, d), l.add(d);
490
+ }
491
+ try {
492
+ if (n.set(0, l), e) {
493
+ const i = gt(), a = yt();
494
+ let d = 0;
495
+ for (let h = 0; h < t.ngeom; h += 1) {
496
+ const S = r.mj_id2name(t, r.mjtObj.mjOBJ_GEOM.value, h);
497
+ if (S === "__viewer_default_ground__" || !Ut(t, h)) continue;
498
+ const E = n.get(t.geom_bodyid[h]), g = Ct(s, h);
499
+ if (!E) continue;
500
+ if (!g) {
501
+ o == null || o.droppedFeatures.push({
502
+ code: "E_MJCF_COLLISION_DEBUG_GEOMETRY_UNAVAILABLE",
503
+ message: `MJCF geom ${S ?? `#${h}`} 的 compiled type=${t.geom_type[h]} 无法准确还原为碰撞线框。`,
504
+ source: "mjcf-collision-debug"
505
+ });
506
+ continue;
507
+ }
508
+ const w = Rt(s, h) ? "mesh" : "feature", m = bt(g, i, w, a);
509
+ g.dispose(), m.userData.geomId = h, d += 1;
510
+ const b = h * 3, y = h * 4;
511
+ m.position.fromArray(t.geom_pos, b), m.quaternion.set(t.geom_quat[y + 1], t.geom_quat[y + 2], t.geom_quat[y + 3], t.geom_quat[y]), E.add(m);
512
+ }
513
+ d === 0 && (i.dispose(), a.dispose());
514
+ } else {
515
+ const i = Ot(s);
516
+ for (let a = 0; a < t.ngeom; a += 1) {
517
+ if (t.geom_group[a] > 2 || r.mj_id2name(t, r.mjtObj.mjOBJ_GEOM.value, a) === "__viewer_default_ground__") continue;
518
+ const d = n.get(t.geom_bodyid[a]), h = Dt(s, a);
519
+ if (!d || !h) continue;
520
+ const S = a * 4, E = t.geom_matid[a], g = Array.from(t.geom_rgba.slice(S, S + 4));
521
+ E >= 0 && [0.5, 0.5, 0.5, 1].every((j, v) => g[v] === j) && g.splice(0, 4, ...Array.from(t.mat_rgba.slice(E * 4, E * 4 + 4)));
522
+ const w = St({
523
+ color: g,
524
+ roughness: At(t, E),
525
+ metalness: Gt(t, E),
526
+ specular: E >= 0 ? t.mat_specular[E] : void 0,
527
+ emission: E >= 0 ? t.mat_emission[E] : void 0
528
+ });
529
+ try {
530
+ vt(s, a, h, w, o, i);
531
+ } catch (j) {
532
+ throw X(new te(h, w)), j;
533
+ }
534
+ const m = new te(h, w), b = a * 3, y = a * 4;
535
+ t.geom_bodyid[a] === 0 && t.geom_type[a] === r.mjtGeom.mjGEOM_PLANE.value && (m.userData.excludeFromSimulationFit = !0), m.position.fromArray(t.geom_pos, b), m.quaternion.set(t.geom_quat[y + 1], t.geom_quat[y + 2], t.geom_quat[y + 3], t.geom_quat[y]), d.add(m);
536
+ }
537
+ }
538
+ return { root: l, bindings: c, expectedLinkCount: c.size };
539
+ } catch (i) {
540
+ throw X(l), i;
541
+ }
542
+ }
543
+ function Ct(s, e) {
544
+ const o = s.model, t = s.mujoco, r = e * 3, l = o.geom_size[r], n = o.geom_size[r + 1], c = o.geom_size[r + 2], i = o.geom_type[e];
545
+ if (i === t.mjtGeom.mjGEOM_PLANE.value) return new Se(Math.max(l * 2, 2), Math.max(n * 2, 2), 10, 10);
546
+ if (i === t.mjtGeom.mjGEOM_BOX.value) return new Me(l * 2, n * 2, c * 2);
547
+ if (i === t.mjtGeom.mjGEOM_SPHERE.value) return new se(l, 20, 12);
548
+ if (i === t.mjtGeom.mjGEOM_ELLIPSOID.value) {
549
+ const a = new se(1, 24, 16);
550
+ return a.applyMatrix4(new et().makeScale(l, n, c)), a;
551
+ }
552
+ if (i === t.mjtGeom.mjGEOM_CYLINDER.value) {
553
+ const a = new Oe(l, l, n * 2, 24);
554
+ return a.rotateX(Math.PI / 2), a;
555
+ }
556
+ if (i === t.mjtGeom.mjGEOM_CAPSULE.value) {
557
+ const a = new ve(l, n * 2, 6, 16);
558
+ return a.rotateX(Math.PI / 2), a;
559
+ }
560
+ return i === t.mjtGeom.mjGEOM_MESH.value ? Lt(s, o.geom_dataid[e]) : i === t.mjtGeom.mjGEOM_HFIELD.value ? Pt(s, o.geom_dataid[e]) : null;
561
+ }
562
+ function Rt(s, e) {
563
+ const o = s.model.geom_type[e];
564
+ return o === s.mujoco.mjtGeom.mjGEOM_MESH.value || o === s.mujoco.mjtGeom.mjGEOM_HFIELD.value;
565
+ }
566
+ function Ut(s, e) {
567
+ if (s.geom_contype[e] !== 0 || s.geom_conaffinity[e] !== 0) return !0;
568
+ for (let o = 0; o < s.npair; o += 1) if (s.pair_geom1[o] === e || s.pair_geom2[o] === e) return !0;
569
+ return !1;
570
+ }
571
+ function Lt(s, e) {
572
+ const o = s.model, t = o.mesh_graphadr[e];
573
+ if (t < 0) return null;
574
+ const r = o.mesh_vertadr[e], l = o.mesh_vertnum[e], n = o.mesh_graph[t], c = o.mesh_graph[t + 1];
575
+ if (n < 4 || c < 4) return null;
576
+ const i = t + 2 + 3 * n + 3 * c, a = new ie();
577
+ return a.setAttribute("position", new oe(Float32Array.from(o.mesh_vert.subarray(r * 3, (r + l) * 3)), 3)), a.setIndex(new oe(Uint32Array.from(o.mesh_graph.subarray(i, i + c * 3)), 1)), a.computeVertexNormals(), a;
578
+ }
579
+ function Pt(s, e) {
580
+ const o = s.model, t = o.hfield_nrow[e], r = o.hfield_ncol[e];
581
+ if (t < 2 || r < 2) return null;
582
+ const l = o.hfield_adr[e], n = e * 4, c = o.hfield_size[n], i = o.hfield_size[n + 1], a = o.hfield_size[n + 2], d = o.hfield_size[n + 3], h = t * r, S = [];
583
+ for (let A = 0; A < t; A += 1) for (let C = 0; C < r; C += 1)
584
+ S.push(
585
+ -c + 2 * c * C / (r - 1),
586
+ -i + 2 * i * A / (t - 1),
587
+ o.hfield_data[l + A * r + C] * a
588
+ );
589
+ const E = [
590
+ [-c, -i, -d],
591
+ [c, -i, -d],
592
+ [-c, i, -d],
593
+ [c, i, -d]
594
+ ];
595
+ for (const A of E) S.push(...A);
596
+ const g = [];
597
+ for (let A = 0; A < t - 1; A += 1) for (let C = 0; C < r - 1; C += 1) {
598
+ const R = A * r + C, L = R + 1, G = R + r, T = G + 1;
599
+ g.push(R, G, L, L, G, T);
600
+ }
601
+ const w = h, m = h + 1, b = h + 2, y = h + 3;
602
+ g.push(w, m, b, m, y, b);
603
+ const j = 0, v = r - 1, O = (t - 1) * r, u = t * r - 1;
604
+ g.push(w, j, m, m, j, v), g.push(b, y, O, y, u, O), g.push(w, b, j, b, O, j), g.push(m, v, y, y, v, u);
605
+ const f = new ie();
606
+ return f.setAttribute("position", new oe(Float32Array.from(S), 3)), f.setIndex(g), f.computeVertexNormals(), f;
607
+ }
608
+ function Dt(s, e) {
609
+ const o = s.model, t = s.mujoco, r = e * 3, l = o.geom_size[r], n = o.geom_size[r + 1], c = o.geom_size[r + 2], i = o.geom_type[e];
610
+ if (i === t.mjtGeom.mjGEOM_PLANE.value) return new Se((l || 5) * 2, (n || 5) * 2);
611
+ if (i === t.mjtGeom.mjGEOM_BOX.value) return new Me(l * 2, n * 2, c * 2);
612
+ if (i === t.mjtGeom.mjGEOM_SPHERE.value) return new se(l, 24, 16);
613
+ if (i === t.mjtGeom.mjGEOM_CYLINDER.value) {
614
+ const a = new Oe(l, l, n * 2, 24);
615
+ return a.rotateX(Math.PI / 2), a;
616
+ }
617
+ if (i === t.mjtGeom.mjGEOM_CAPSULE.value) {
618
+ const a = new ve(l, n * 2, 6, 16);
619
+ return a.rotateX(Math.PI / 2), a;
620
+ }
621
+ return i !== t.mjtGeom.mjGEOM_MESH.value ? null : Mt(o, o.geom_dataid[e]);
622
+ }
623
+ function Tt(s, e) {
624
+ const o = new tt(s);
625
+ let t = null, r = null, l = null, n = null, c = null, i = null, a = null, d = null, h = null, S = null, E = null, g = !1, w = !0, m = !1, b = !1, y = null, j = null, v, O = null, u = null, f = null, A = null, C = "z", R = !1;
626
+ const L = () => {
627
+ u && (C = e.options.upAxis ?? "z", R = !0, u.setUpAxis(C) && (r == null || r.sync(), f == null || f.sync()));
628
+ }, G = (_, M) => {
629
+ var D;
630
+ const U = _e(_, e.signal, `${e.format}:${M}`);
631
+ w = !1, m = !1, j = { ...U, stage: M };
632
+ try {
633
+ u == null || u.endGrab();
634
+ } catch {
635
+ }
636
+ (D = e.reportSessionState) == null || D.call(e), e.reportError(_, { fatal: !1, stage: M, code: U.code });
637
+ }, T = () => {
638
+ g = !0, w = !1;
639
+ }, Ge = () => {
640
+ if (f) return !0;
641
+ const _ = A;
642
+ return A = null, !_ || !u || (f = _() ?? null, !f) ? !1 : (f.root.visible = !1, u.attachAuxiliary(f.root), f.sync(), !0);
643
+ }, K = (async () => {
644
+ var _, M, U, D, N, ae, le, ue, ce;
645
+ try {
646
+ const F = e.format;
647
+ if (F === "usd" || F === "usda" || F === "usdc" || F === "usdz") {
648
+ (_ = e.reportProgress) == null || _.call(e, "usd", "正在解析 USD 场景与物理刚体...");
649
+ const p = await (await import("./usd-session-DkwOFmds.js")).loadUsdSimulation(s, e, o);
650
+ if (g || e.signal.aborted)
651
+ throw p.dispose(), ne();
652
+ O = p.asset, r = p.binding, l = p.dispose, b = p.hasAnimation === !0, n = p.hasPhysics || b ? p.step : null, c = p.reset, w = p.hasPhysics || b, m = p.hasPhysics, y = p.fallback ? { ...p.fallback, stage: "physics-fallback" } : p.visualWarning ? { ...p.visualWarning, stage: "visual-adaptation" } : null, (M = e.reportProgress) == null || M.call(e, "stage", "正在构建三维场景与环境光影..."), u = new Q(
653
+ r.root,
654
+ e.options.simulationTheme,
655
+ p.runtime,
656
+ "simulation",
657
+ p.hasPhysics ? "physics" : "visual"
658
+ ), p.runtime && (t = p.runtime), f = p.collision ?? null, A = p.createCollision ?? null, f && (f.root.visible = !1, u.attachAuxiliary(f.root)), L();
659
+ return;
660
+ }
661
+ if (F === "urdf" || F === "xacro") {
662
+ (U = e.reportProgress) == null || U.call(e, "urdf", "正在解析 URDF 场景与运动学结构...");
663
+ const p = await (await import("./urdf-session-CF8xOenk.js")).loadUrdfSimulation(s, e, o);
664
+ if (g || e.signal.aborted)
665
+ throw p.dispose(), ne();
666
+ O = p.asset, u = p.stage, h = p.inspection, l = p.dispose, n = p.step, c = p.reset, i = p.play, a = p.pause, d = p.isPlaying, S = () => p.capabilities, E = () => p.physics, w = !1, m = !1, y = p.warning ?? null, L();
667
+ return;
668
+ }
669
+ let x = s.entryPath ?? s.filename;
670
+ if (!x && F === "mjcf") {
671
+ const I = o.paths().filter((p) => p.toLowerCase().endsWith(".xml"));
672
+ for (const p of ["scene.xml", "model.xml", "main.xml"]) {
673
+ const q = I.find((z) => z.toLowerCase().endsWith(`/${p}`) || z.toLowerCase() === p);
674
+ if (q) {
675
+ x = q;
676
+ break;
677
+ }
678
+ }
679
+ }
680
+ x ?? (x = "asset.xml"), (D = e.reportProgress) == null || D.call(e, "fetch", "正在读取模型描述与依赖资源...");
681
+ const Ce = await st(s, o);
682
+ J(g, e.signal), (N = e.reportProgress) == null || N.call(e, "parse", "正在解析 MJCF 场景与连杆..."), O = await at(Ce, x, o);
683
+ try {
684
+ (ae = e.reportProgress) == null || ae.call(e, "compile", "正在编译物理模型与参数...");
685
+ const I = await lt(O);
686
+ J(g, e.signal), (le = e.reportProgress) == null || le.call(e, "runtime", "正在初始化物理内核...");
687
+ const { MujocoRuntime: p } = await import("./mujoco-runtime-DTxVmIzc.js");
688
+ t = new p(), await t.initialize(I, e.options.mujocoBaseUrl);
689
+ } catch (I) {
690
+ const p = _e(I, e.signal, "mjcf-physics");
691
+ t == null || t.dispose(), t = null;
692
+ const { compileMjcfPreview: q } = await import("./mjcf-visual-zWaLqVqd.js");
693
+ let z;
694
+ try {
695
+ z = q(O);
696
+ } catch (Z) {
697
+ throw new Error(`${p.message};独立视觉预览也不可用:${Z instanceof Error ? Z.message : String(Z)}`);
698
+ }
699
+ r = { root: z, sync() {
700
+ }, dispose() {
701
+ X(z);
702
+ } }, y = { ...p, stage: "physics-fallback" }, u = new Q(z, e.options.simulationTheme, void 0, "simulation", "visual"), w = !1, L();
703
+ return;
704
+ }
705
+ m = !0, J(g, e.signal), (ue = e.reportProgress) == null || ue.call(e, "visual", "正在构建视觉渲染网格...");
706
+ const Re = we(t, !1, O.diagnostics), fe = O.diagnostics.droppedFeatures.find((I) => I.code.startsWith("MJCF_"));
707
+ fe && (y = { ...fe, stage: "visual-material" }), J(g, e.signal), (ce = e.reportProgress) == null || ce.call(e, "stage", "正在构建三维场景与环境光影..."), r = new ge(t, Re), u = new Q(r.root, e.options.simulationTheme, t);
708
+ const me = we(t, !0, O.diagnostics);
709
+ me.root.children.length > 0 ? (f = new ge(t, me), f.root.visible = !1) : f = null, f && u.attachAuxiliary(f.root), L();
710
+ } catch (F) {
711
+ throw u == null || u.dispose(), u = null, l ? (l(), l = null) : (f == null || f.dispose(), r == null || r.dispose(), t == null || t.dispose()), f = null, r = null, t = null, o.dispose(), F;
712
+ }
713
+ })();
714
+ return K.catch(() => {
715
+ }), {
716
+ id: `simulation-${Math.random().toString(36).slice(2)}`,
717
+ get autoPlay() {
718
+ return e.format === "urdf" || e.format === "xacro" ? !1 : void 0;
719
+ },
720
+ get inspection() {
721
+ return h;
722
+ },
723
+ isPlaying() {
724
+ return (d == null ? void 0 : d()) ?? w;
725
+ },
726
+ opened: K,
727
+ get root() {
728
+ return (u == null ? void 0 : u.root) ?? null;
729
+ },
730
+ getFitBounds() {
731
+ return (u == null ? void 0 : u.getModelBounds()) ?? null;
732
+ },
733
+ beforeRender(_, M, U) {
734
+ return u == null ? void 0 : u.beforeRender(_, M, U);
735
+ },
736
+ get capabilities() {
737
+ const _ = f !== null || A !== null;
738
+ return j ? { canPlay: !1, canPause: !1, canReset: !1, hasPhysics: !1, hasAnimation: !1, canToggleGround: !0, canToggleCollision: _, canReorientUpAxis: !0 } : (S == null ? void 0 : S()) ?? { canPlay: m || b, canPause: m || b, canReset: m || b, hasPhysics: m, hasAnimation: b, canToggleGround: !0, canToggleCollision: _, canReorientUpAxis: !0 };
739
+ },
740
+ get warning() {
741
+ return y;
742
+ },
743
+ get physics() {
744
+ return j ? { status: "unavailable", issue: j } : E ? E() : m ? { status: "ready" } : (y == null ? void 0 : y.stage) === "physics-fallback" ? { status: "unavailable", issue: y } : { status: "not-authored" };
745
+ },
746
+ setTheme(_) {
747
+ u == null || u.setTheme(_);
748
+ },
749
+ setGroundVisible(_) {
750
+ u == null || u.setGroundVisible(_);
751
+ },
752
+ getGroundVisible() {
753
+ return (u == null ? void 0 : u.getGroundVisible()) ?? !0;
754
+ },
755
+ getGroundGridScale() {
756
+ return (u == null ? void 0 : u.getGroundGridScale()) ?? Ne;
757
+ },
758
+ getUpAxis() {
759
+ return u && R ? C : null;
760
+ },
761
+ setUpAxis(_) {
762
+ if (!(g || !u))
763
+ try {
764
+ if (!u.setUpAxis(_)) return;
765
+ C = _, r == null || r.sync(), f == null || f.sync(), e.requestRender();
766
+ } catch (M) {
767
+ G(M, "up-axis");
768
+ }
769
+ },
770
+ presentation: { preferredViewMode: "3d", interactionMode: "simulation", uiProfile: "simulation", fitPolicy: "fit-on-ready" },
771
+ beginDispose: T,
772
+ setCollisionVisible(_) {
773
+ if (!g) {
774
+ if (S) {
775
+ const M = h;
776
+ M == null || M.setOverlay("collision", _);
777
+ return;
778
+ }
779
+ if (_ && !Ge()) throw new Error("This asset has no collision display.");
780
+ f && (f.root.visible = _), e.requestRender();
781
+ }
782
+ },
783
+ getVisualDiagnostics() {
784
+ return g || !O || O.source.format !== "usd" ? null : structuredClone({ report: O.extension.visualAdaptation, diagnostics: O.diagnostics });
785
+ },
786
+ getPhysicsProperties() {
787
+ if (g || !m || !(t != null && t.model) || !t.mujoco) return null;
788
+ const _ = t.model, M = t.mujoco;
789
+ return structuredClone({
790
+ units: { length: "m", mass: "kg", time: "s" },
791
+ timestep: _.opt.timestep,
792
+ gravity: Array.from(_.opt.gravity),
793
+ bodyCount: _.nbody - 1,
794
+ jointCount: _.njnt,
795
+ geomCount: _.ngeom,
796
+ bodies: Array.from({ length: _.nbody - 1 }, (U, D) => {
797
+ const N = D + 1;
798
+ return { id: N, name: M.mj_id2name(_, M.mjtObj.mjOBJ_BODY.value, N), mass: _.body_mass[N], inertia: Array.from(_.body_inertia.slice(N * 3, N * 3 + 3)) };
799
+ }),
800
+ diagnostics: O == null ? void 0 : O.diagnostics
801
+ });
802
+ },
803
+ get update() {
804
+ return t != null && t.model || n ? (_) => {
805
+ if (j || g || !((d == null ? void 0 : d()) ?? w) || !r && !n) return !1;
806
+ try {
807
+ if (n) {
808
+ const U = n(_);
809
+ return U && (f == null || f.sync()), U;
810
+ }
811
+ const M = t.step(_);
812
+ return M && (r.sync(), f == null || f.sync(), u == null || u.updateForceLine()), M;
813
+ } catch (M) {
814
+ return G(M, "step"), !1;
815
+ }
816
+ } : void 0;
817
+ },
818
+ play() {
819
+ g || j || (i ? (i(), w = (d == null ? void 0 : d()) ?? !1) : (m || b) && (w = !0));
820
+ },
821
+ pause() {
822
+ j || (a && a(), w = !1);
823
+ },
824
+ reset() {
825
+ if (!(j || g || !r && !c))
826
+ try {
827
+ u == null || u.endGrab(), c ? c() : (t == null || t.reset(), r.sync()), f == null || f.sync(), u == null || u.resetGround(), u == null || u.updateForceLine();
828
+ } catch (_) {
829
+ G(_, "reset");
830
+ }
831
+ },
832
+ beginGrab(_, M, U) {
833
+ if (g || !m && !E) return !1;
834
+ try {
835
+ return (u == null ? void 0 : u.beginGrab(_, M, U)) ?? !1;
836
+ } catch (D) {
837
+ return G(D, "grab"), !1;
838
+ }
839
+ },
840
+ moveGrab(_, M, U) {
841
+ if (!(g || !m && !E))
842
+ try {
843
+ u == null || u.moveGrab(_, M, U);
844
+ } catch (D) {
845
+ G(D, "grab");
846
+ }
847
+ },
848
+ endGrab() {
849
+ u == null || u.endGrab();
850
+ },
851
+ dispose() {
852
+ return T(), v ?? (v = K.catch(() => {
853
+ }).then(() => {
854
+ l ? (l(), l = null, u = null, r = null, f = null, A = null) : (u == null || u.dispose(), u = null, f == null || f.root.removeFromParent(), f == null || f.dispose(), f = null, A = null, r == null || r.dispose(), r = null, t == null || t.dispose()), o.dispose(), O = null, h = null, n = null, c = null, i = null, a = null, d = null, S = null, E = null, m = !1, b = !1, y = null, R = !1;
855
+ })), v;
856
+ }
857
+ };
858
+ }
859
+ function J(s, e) {
860
+ if (s || e.aborted) throw ne();
861
+ }
862
+ function ne() {
863
+ return Object.assign(new Error("Simulation load aborted."), { name: "AbortError", code: "E_ABORTED" });
864
+ }
865
+ const kt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
866
+ __proto__: null,
867
+ createSimulationSession: Tt
868
+ }, Symbol.toStringTag, { value: "Module" }));
869
+ export {
870
+ zt as C,
871
+ ge as S,
872
+ yt as a,
873
+ bt as b,
874
+ gt as c,
875
+ nt as d,
876
+ rt as e,
877
+ St as f,
878
+ kt as g,
879
+ Bt as n,
880
+ _e as p,
881
+ st as r,
882
+ Ee as s
883
+ };