@nebula-spatial/viewer 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,559 +0,0 @@
1
- import { c as Ge, b as _e, S as De, w as Fe, d as qe, p as ae, a as Te } from "./asset-ir-BEDGD9CL.js";
2
- import { D as Je, B as le, d as Oe, E as Ae, S as Se } from "./index-DoxM1Msk.js";
3
- const H = 0.7, ie = 0.2, Ne = 110 * Math.PI / 180;
4
- function ke(l, e = {}) {
5
- const b = l.getSnapshot();
6
- if (b.controlMode !== "kinematic" || b.playing) return;
7
- const A = [], t = {};
8
- let i = H;
9
- for (const o of b.joints) {
10
- if (o.mimic || !["revolute", "prismatic"].includes(o.type) || !Number.isFinite(o.defaultValue)) continue;
11
- const u = o.controlLimits ?? o.limits;
12
- if (!u || !Number.isFinite(u.lower) || !Number.isFinite(u.upper) || u.lower >= u.upper) continue;
13
- const v = o.defaultValue;
14
- if (v < u.lower || v > u.upper) continue;
15
- const G = Math.abs(u.upper - v) >= Math.abs(u.lower - v) ? u.upper : u.lower, O = Math.abs(G - v), S = o.type === "revolute" ? Math.max(0.6, O / Ne) : Math.max(0.6, 0.8 * O / (u.upper - u.lower));
16
- if (!Number.isFinite(S) || S <= 0) continue;
17
- const D = i;
18
- i = D + 2 * S + ie, t[o.id] = v, A.push({ id: o.id, home: v, far: G, duration: S, start: D, end: i });
19
- }
20
- if (!A.length) return;
21
- const w = e.autoPlay !== !1;
22
- let p = w ? 0 : H, f = w, d = !1, C = !1, h = !1, j = !w, P = !1, T = !0, m = w ? !0 : null;
23
- const R = (o) => {
24
- var u;
25
- if (T) {
26
- m = o;
27
- return;
28
- }
29
- m = null, (u = e.onPlayingChange) == null || u.call(e, o);
30
- }, y = (o) => {
31
- if (f !== o) {
32
- if (f = o, o) {
33
- if (l.setPreviewing(!0), !f || P) return;
34
- l.setPlaying(!0);
35
- } else
36
- l.setPlaying(!1), l.setPreviewing(!1);
37
- f === o && R(o);
38
- }
39
- }, g = () => {
40
- P || (w && !C && (h = !0), j = !0, d = !1, y(!1));
41
- }, ee = l.onManualInput(g), $ = {
42
- get playing() {
43
- return f;
44
- },
45
- get finished() {
46
- return d;
47
- },
48
- cancel: g,
49
- play() {
50
- if (!(P || f)) {
51
- if (j || d) {
52
- if (l.resetPreviewPose(), P) return;
53
- p = H, d = !1, j = !1;
54
- }
55
- y(!0);
56
- }
57
- },
58
- pause() {
59
- P || (w && !C && (h = !0), y(!1));
60
- },
61
- reset() {
62
- P || (w && !C && (h = !0), y(!1), !P && (p = H, d = !1, j = !1, l.resetPreviewPose()));
63
- },
64
- dispose() {
65
- P || (P = !0, ee(), y(!1), m = null);
66
- },
67
- update(o) {
68
- var O, S;
69
- if (P) return !1;
70
- if (m !== null) {
71
- const D = m;
72
- m = null, (O = e.onPlayingChange) == null || O.call(e, D);
73
- }
74
- if (!f || P || !Number.isFinite(o) || o <= 0 || (p += o, p < H)) return !1;
75
- if (p >= i)
76
- return d = !0, j = !0, y(!1), P ? !1 : (l.resetPreviewPose(), w && !h && !C && (C = !0, (S = e.onFinished) == null || S.call(e)), !0);
77
- const u = A.find((D) => p < D.end), v = p - u.start;
78
- let G;
79
- if (v < u.duration)
80
- G = u.home + (u.far - u.home) * Me(v / u.duration);
81
- else if (v < u.duration + ie)
82
- G = u.far;
83
- else {
84
- const D = (v - u.duration - ie) / u.duration;
85
- G = u.far + (u.home - u.far) * Me(D);
86
- }
87
- return l.setPreviewPose({ ...t, [u.id]: G }), !0;
88
- }
89
- };
90
- return w && (l.setPreviewing(!0), f && !P && l.setPlaying(!0)), T = !1, $;
91
- }
92
- function Me(l) {
93
- return l * l * l * (l * (6 * l - 15) + 10);
94
- }
95
- async function Le(l, e, b) {
96
- var f;
97
- const A = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), w = async (d, C) => {
98
- if (i.has(d)) throw ne(`MJCF include cycle: ${d}`, "E_MJCF_INCLUDE_CYCLE");
99
- i.add(d);
100
- const h = ze(C, d);
101
- A.set(d, h);
102
- for (const j of h.querySelectorAll("worldbody body[name]")) t.add(j.getAttribute("name"));
103
- for (const j of h.querySelectorAll("include[file]")) {
104
- const P = b.resolve(j.getAttribute("file"), d);
105
- await w(P, await b.text(P));
106
- }
107
- i.delete(d);
108
- };
109
- await w(e, l);
110
- const p = (f = A.get(e)) == null ? void 0 : f.querySelector("mujoco");
111
- if (!p || t.size === 0) throw ne("MJCF requires a mujoco root and at least one named body.", "E_MJCF_PARSE");
112
- return Ge({
113
- id: p.getAttribute("model") || e,
114
- name: p.getAttribute("model") || e,
115
- source: { format: "mjcf", uri: e },
116
- links: [...t].map((d) => ({ id: d, name: d, visuals: [], collisions: [] })),
117
- joints: [],
118
- diagnostics: _e(),
119
- extension: { files: b, xml: l, documents: A }
120
- });
121
- }
122
- async function Ie(l) {
123
- const e = l.extension.files, b = l.source.uri, A = b.split("/").slice(0, -1).join("/"), t = /* @__PURE__ */ new Map(), i = l.extension.documents;
124
- for (const [f, d] of i) {
125
- const C = d.querySelector("compiler");
126
- for (const h of d.querySelectorAll("asset [file]")) {
127
- const j = (C == null ? void 0 : C.getAttribute(h.tagName === "texture" ? "texturedir" : "meshdir")) ?? (C == null ? void 0 : C.getAttribute("assetdir")) ?? "", P = e.resolve(`${j}/${h.getAttribute("file")}`, f);
128
- await e.bytes(P);
129
- }
130
- }
131
- for (const f of $e(e.paths(), i)) {
132
- if (f === b) continue;
133
- const d = A && f.startsWith(`${A}/`) ? f.slice(A.length + 1) : f;
134
- t.set(d, await e.bytes(f));
135
- }
136
- const w = l.extension.xml;
137
- return { format: "mjcf", xml: Ve(i) ? Ue(w) : w, files: t };
138
- }
139
- function Ve(l) {
140
- return l.size === 0 || ![...l.values()].some((b) => b.querySelector("freejoint, actuator") ? !0 : [...b.querySelectorAll("joint")].some(
141
- (A) => (A.getAttribute("type") ?? "hinge").toLowerCase() !== "fixed"
142
- )) ? !1 : ![...l.values()].some(
143
- (b) => [...b.querySelectorAll("worldbody geom")].some((A) => {
144
- var t;
145
- return ((t = A.getAttribute("type")) == null ? void 0 : t.toLowerCase()) === "plane";
146
- })
147
- );
148
- }
149
- function Ue(l) {
150
- 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"/>';
151
- return /<worldbody\b[^>]*>/i.test(l) ? l.replace(/(<worldbody\b[^>]*>)/i, `$1${e}`) : l.replace(/<\/mujoco\s*>/i, `<worldbody>${e}</worldbody></mujoco>`);
152
- }
153
- function $e(l, e) {
154
- const b = (p) => p.replaceAll("\\", "/").split("/").pop() ?? "", A = /* @__PURE__ */ new Map();
155
- for (const p of l) {
156
- const f = b(p), d = A.get(f) ?? [];
157
- d.push(p), A.set(f, d);
158
- }
159
- const t = new Set(e.keys()), i = /* @__PURE__ */ new Set(["include", "mesh", "texture", "hfield", "skin"]), w = /* @__PURE__ */ new Set(["fileleft", "fileright", "fileup", "filedown", "filefront", "fileback"]);
160
- for (const p of e.values()) {
161
- if (p.querySelector("plugin, extension, model, attach")) return l;
162
- for (const f of p.querySelectorAll("*"))
163
- for (const d of f.attributes) {
164
- if (!d.name.startsWith("file")) continue;
165
- if (d.name === "file") {
166
- if (!i.has(f.tagName)) return l;
167
- } else if (!(f.tagName === "texture" && w.has(d.name)))
168
- return l;
169
- if (!d.value) continue;
170
- const C = A.get(b(d.value));
171
- if (!C) return l;
172
- for (const h of C) t.add(h);
173
- }
174
- }
175
- return l.filter((p) => t.has(p));
176
- }
177
- function ze(l, e) {
178
- const b = new DOMParser().parseFromString(l, "application/xml"), A = b.querySelector("parsererror");
179
- if (A) throw ne(`MJCF XML parse failed (${e}): ${A.textContent ?? ""}`, "E_MJCF_PARSE");
180
- return b;
181
- }
182
- function ne(l, e) {
183
- return Object.assign(new Error(l), { code: e });
184
- }
185
- function He(l, e) {
186
- const b = new De(l), A = e.format === "usd" || e.format === "usda" || e.format === "usdc" || e.format === "usdz";
187
- let t = null, i = null, w = null, p = null, f = null, d = null, C = null, h = null, j = null, P = null, T = null, m = !1, R = !1, y, g;
188
- const ee = () => {
189
- g == null || g.cancel();
190
- }, $ = () => {
191
- const s = g;
192
- g = void 0, s == null || s.dispose();
193
- };
194
- let o = !1, u = !1, v = null, G = null, O, S = null, D = null, r = null, a = null, U = null, _ = null, K = null, N = !1, z = !1, q;
195
- const oe = {};
196
- let W = null, Q = "z", re = !1;
197
- const X = () => {
198
- r && (Q = e.options.upAxis ?? "z", re = !0, r.setUpAxis(Q) && (i == null || i.sync(), a == null || a.sync()));
199
- }, Y = (s = !1) => {
200
- if (!t || !y || typeof t.getJointValues != "function") return;
201
- const n = y.getSnapshot().joints.map((M) => M.id);
202
- y.syncValues(t.getJointValues(n), s);
203
- }, k = (s, n) => {
204
- var E;
205
- const M = ae(s, e.signal, `${e.format}:${n}`);
206
- R = !1, $(), y == null || y.dispose(), y = void 0, j = null, o = !1, G = { ...M, stage: n };
207
- try {
208
- r == null || r.endGrab();
209
- } catch {
210
- }
211
- (E = e.reportSessionState) == null || E.call(e), e.reportError(s, { fatal: !1, stage: n, code: M.code });
212
- }, Ce = (s) => {
213
- var n;
214
- if (m) {
215
- s.dispose();
216
- return;
217
- }
218
- _ = null, N = !1, S = s.asset, w = s.dispose, u = s.hasAnimation === !0, p = s.hasPhysics || u ? s.step : null, f = s.reset, R = !s.hasPhysics && s.hasAnimation === !0, o = s.hasPhysics, v = s.fallback ? { ...s.fallback, stage: "physics-fallback" } : s.visualWarning ? { ...s.visualWarning, stage: "visual-adaptation" } : null, i = s.binding, t = s.runtime ?? null, D = s.physics ?? null, W = s.inspect ?? null, y = s.inspection, j = y ?? null, q = s.overlays;
219
- for (const [M, E] of Object.entries(oe)) q == null || q.set(M, E);
220
- a = s.collision ?? null, U = s.createCollision ?? null, r == null || r.setRuntime(s.runtime), r == null || r.replaceModel(s.binding.root), a && (a.root.visible = !1, r == null || r.attachAuxiliary(a.root), a.sync()), y && (g = ke(y, {
221
- autoPlay: e.options.jointIntro !== !1 && !(typeof globalThis.matchMedia == "function" && globalThis.matchMedia("(prefers-reduced-motion: reduce)").matches),
222
- onPlayingChange(M) {
223
- var E;
224
- R = M, m || ((E = e.reportSessionState) == null || E.call(e), e.requestRender());
225
- },
226
- onFinished() {
227
- m || y == null || y.notifyIntroFinished();
228
- }
229
- }), g && (R = g.playing)), X(), (n = e.reportSessionState) == null || n.call(e), e.requestRender();
230
- }, je = (s) => {
231
- var M;
232
- if (m) return;
233
- const n = ae(s, e.signal, "usd-physics");
234
- N = !1, G = { ...n, stage: "usd-physics" }, o = !1, u = (_ == null ? void 0 : _.visual.hasAnimation) ?? u, p = _ != null && _.visual.hasAnimation ? _.visual.step : null, f = _ != null && _.visual.hasAnimation ? _.visual.reset : null, R = !!(_ != null && _.visual.hasAnimation), (M = e.reportSessionState) == null || M.call(e), e.reportError(s, { fatal: !1, stage: "usd-physics", code: n.code });
235
- }, fe = () => {
236
- var s;
237
- m || (m = !0, R = !1, $(), (s = e.reportSessionState) == null || s.call(e));
238
- }, ce = () => {
239
- if (a) return !0;
240
- const s = U;
241
- return U = null, !s || !r || (a = s() ?? null, !a) ? !1 : (a.root.visible = !1, r.attachAuxiliary(a.root), a.sync(), !0);
242
- };
243
- let de = () => {
244
- }, pe = () => {
245
- }, me = !1;
246
- const se = new Promise((s, n) => {
247
- de = s, pe = n;
248
- }), Z = () => {
249
- me || (me = !0, de());
250
- };
251
- return (async () => {
252
- var s, n, M, E, L, ye, he, be, ve, we;
253
- try {
254
- const J = e.format;
255
- if (J === "usd" || J === "usda" || J === "usdc" || J === "usdz") {
256
- (s = e.reportProgress) == null || s.call(e, "usd-visual", "正在解析 USD 视觉场景...");
257
- const c = await (await import("./usd-session-Cn6whyh4.js")).loadUsdSimulation(l, e, b);
258
- if (m || e.signal.aborted)
259
- throw c.dispose(), ue();
260
- _ = c, i = { root: c.visual.root, sync() {
261
- }, dispose() {
262
- } }, w = c.dispose, u = c.visual.hasAnimation, p = u ? c.visual.step : null, f = c.visual.reset, R = !1, N = !0, v = c.visual.warning ? { ...c.visual.warning, stage: "visual-adaptation" } : null, z = c.texturesPending, z && c.texturesReady.then(() => {
263
- var I;
264
- m || (z = !1, (I = e.reportSessionState) == null || I.call(e), e.requestRender());
265
- }), (n = e.reportProgress) == null || n.call(e, "stage", "正在构建三维场景与环境光影..."), r = new le(
266
- c.visual.root,
267
- e.options.simulationTheme,
268
- void 0,
269
- "simulation",
270
- "visual"
271
- ), r.setCacheInvalidationCallback(e.invalidateTransmissionCaches), X(), Z(), (M = e.reportProgress) == null || M.call(e, "usd-physics", "视觉场景已就绪,正在准备物理..."), K = c.completePhysics(r.root).then(Ce).catch(je);
272
- return;
273
- }
274
- if (J === "urdf" || J === "xacro") {
275
- (E = e.reportProgress) == null || E.call(e, "urdf", "正在解析 URDF 场景与运动学结构...");
276
- const c = await (await import("./urdf-session-HKelZnMM.js")).loadUrdfSimulation(l, e, b);
277
- if (m || e.signal.aborted)
278
- throw c.dispose(), ue();
279
- S = c.asset, r = c.stage, j = c.inspection, w = c.dispose, p = c.step, f = c.reset, d = c.play, C = c.pause, h = c.isPlaying, P = () => c.capabilities, T = () => c.physics, R = !1, o = !1, v = c.warning ?? null, X(), Z();
280
- return;
281
- }
282
- let B = l.entryPath ?? l.filename;
283
- if (!B && J === "mjcf") {
284
- const F = b.paths().filter((c) => c.toLowerCase().endsWith(".xml"));
285
- for (const c of ["scene.xml", "model.xml", "main.xml"]) {
286
- const I = F.find((V) => V.toLowerCase().endsWith(`/${c}`) || V.toLowerCase() === c);
287
- if (I) {
288
- B = I;
289
- break;
290
- }
291
- }
292
- }
293
- B ?? (B = "asset.xml"), (L = e.reportProgress) == null || L.call(e, "fetch", "正在读取模型描述与依赖资源...");
294
- const Re = await qe(l, b);
295
- x(m, e.signal), (ye = e.reportProgress) == null || ye.call(e, "parse", "正在解析 MJCF 场景与连杆..."), S = await Le(Re, B, b);
296
- try {
297
- (he = e.reportProgress) == null || he.call(e, "compile", "正在编译物理模型与参数...");
298
- const F = await Ie(S);
299
- D = F, x(m, e.signal), (be = e.reportProgress) == null || be.call(e, "runtime", "正在初始化物理内核...");
300
- const { MujocoRuntime: c } = await import("./mujoco-runtime-BmuEJ_ST.js");
301
- t = new c(), await t.initialize(F, {
302
- baseUrl: e.options.mujocoBaseUrl,
303
- wasmModule: e.options.mujocoWasmModule
304
- });
305
- } catch (F) {
306
- const c = ae(F, e.signal, "mjcf-physics");
307
- t == null || t.dispose(), t = null;
308
- const { compileMjcfPreview: I } = await import("./mjcf-visual-CQEeWkL_.js");
309
- let V;
310
- try {
311
- V = I(S);
312
- } catch (te) {
313
- throw new Error(`${c.message};独立视觉预览也不可用:${te instanceof Error ? te.message : String(te)}`);
314
- }
315
- i = { root: V, sync() {
316
- }, dispose() {
317
- Oe(V);
318
- } }, v = { ...c, stage: "physics-fallback" }, r = new le(V, e.options.simulationTheme, void 0, "simulation", "visual"), r.setCacheInvalidationCallback(e.invalidateTransmissionCaches), R = !1, X(), Z();
319
- return;
320
- }
321
- o = !0, x(m, e.signal), (ve = e.reportProgress) == null || ve.call(e, "visual", "正在构建视觉渲染网格...");
322
- const Ee = Ae(t, !1, S.diagnostics), ge = S.diagnostics.droppedFeatures.find((F) => F.code.startsWith("MJCF_"));
323
- ge && (v = { ...ge, stage: "visual-material" }), x(m, e.signal), (we = e.reportProgress) == null || we.call(e, "stage", "正在构建三维场景与环境光影..."), i = new Se(t, Ee), r = new le(i.root, e.options.simulationTheme, t), r.setCacheInvalidationCallback(e.invalidateTransmissionCaches);
324
- const Pe = Ae(t, !0, S.diagnostics);
325
- Pe.root.children.length > 0 ? (a = new Se(t, Pe, { accelerateRaycast: !1 }), a.root.visible = !1) : a = null, a && r.attachAuxiliary(a.root), X(), y = Te(
326
- t,
327
- "mjcf",
328
- () => {
329
- i == null || i.sync(), a == null || a.sync();
330
- },
331
- e.requestRender,
332
- (F) => e.reportError(F, { fatal: !1, stage: "joint-inspection", code: "E_MUJOCO_JOINT_INSPECTION" })
333
- ), j = y ?? null, Z();
334
- } catch (J) {
335
- throw r == null || r.dispose(), r = null, w ? (w(), w = null) : (a == null || a.dispose(), i == null || i.dispose(), t == null || t.dispose()), a = null, i = null, t = null, b.dispose(), D = null, _ = null, J;
336
- }
337
- })().catch(pe), se.catch(() => {
338
- }), {
339
- id: `simulation-${Math.random().toString(36).slice(2)}`,
340
- get autoPlay() {
341
- return g ? g.playing : !N && !o && u ? !0 : e.format === "urdf" || e.format === "xacro" || o ? !1 : void 0;
342
- },
343
- get inspection() {
344
- return j;
345
- },
346
- setInspectionOverlay(s, n) {
347
- if (!A || m) return !1;
348
- oe[s] = n;
349
- const M = q == null ? void 0 : q.set(s, n);
350
- return e.requestRender(), M ?? N;
351
- },
352
- getInspectionOverlayCapabilities() {
353
- return q ? { jointAxis: q.has("jointAxis"), centerOfMass: q.has("centerOfMass"), inertia: q.has("inertia") } : null;
354
- },
355
- isPlaying() {
356
- return (h == null ? void 0 : h()) ?? R;
357
- },
358
- opened: se,
359
- get root() {
360
- return (r == null ? void 0 : r.root) ?? null;
361
- },
362
- getFitBounds() {
363
- return (r == null ? void 0 : r.getModelBounds()) ?? null;
364
- },
365
- beforeRender(s, n, M) {
366
- return r == null ? void 0 : r.beforeRender(s, n, M);
367
- },
368
- get capabilities() {
369
- const s = a !== null || U !== null;
370
- return G ? { canPlay: !1, canPause: !1, canReset: !1, hasPhysics: !1, hasAnimation: !1, canToggleGround: !0, canToggleCollision: s, canReorientUpAxis: !0 } : (P == null ? void 0 : P()) ?? { canPlay: o || u || !!g, canPause: o || u || !!g, canReset: o || u || !!y, hasPhysics: o, hasAnimation: u || !!g, canToggleGround: !0, canToggleCollision: s, canReorientUpAxis: !0 };
371
- },
372
- get warning() {
373
- return v && !v.notice ? Fe(v, v.stage) : v;
374
- },
375
- get physics() {
376
- return G ? { status: "unavailable", issue: G } : T ? T() : N ? { status: "initializing" } : o ? { status: "ready" } : (v == null ? void 0 : v.stage) === "physics-fallback" ? { status: "unavailable", issue: v } : { status: "not-authored" };
377
- },
378
- get backgroundLoading() {
379
- return z && N ? {
380
- stage: "textures+physics",
381
- message: "正在加载纹理并准备物理..."
382
- } : z ? {
383
- stage: "textures",
384
- message: "正在加载纹理..."
385
- } : N ? {
386
- stage: "physics",
387
- message: "正在准备物理..."
388
- } : null;
389
- },
390
- setTheme(s) {
391
- r == null || r.setTheme(s);
392
- },
393
- setGroundVisible(s) {
394
- r == null || r.setGroundVisible(s);
395
- },
396
- getGroundVisible() {
397
- return (r == null ? void 0 : r.getGroundVisible()) ?? !0;
398
- },
399
- getGroundGridScale() {
400
- return (r == null ? void 0 : r.getGroundGridScale()) ?? Je;
401
- },
402
- getUpAxis() {
403
- return r && re ? Q : null;
404
- },
405
- setUpAxis(s) {
406
- if (!(m || !r))
407
- try {
408
- if (!r.setUpAxis(s)) return;
409
- Q = s, i == null || i.sync(), a == null || a.sync(), e.requestRender();
410
- } catch (n) {
411
- k(n, "up-axis");
412
- }
413
- },
414
- presentation: { preferredViewMode: "3d", interactionMode: "simulation", uiProfile: "simulation", fitPolicy: "fit-on-ready" },
415
- beginDispose: fe,
416
- setCollisionVisible(s) {
417
- if (!m) {
418
- if (P) {
419
- const n = j;
420
- n == null || n.setOverlay("collision", s);
421
- return;
422
- }
423
- if (s && !ce()) throw new Error("This asset has no collision display.");
424
- a && (a.root.visible = s), e.requestRender();
425
- }
426
- },
427
- getCollisionRoot() {
428
- return m || P || !ce() ? null : (a == null || a.sync(), (a == null ? void 0 : a.root) ?? null);
429
- },
430
- getVisualDiagnostics() {
431
- return m || !S || S.source.format !== "usd" ? null : structuredClone({
432
- report: S.extension.visualAdaptation,
433
- diagnostics: S.diagnostics,
434
- usd: (W == null ? void 0 : W()) ?? null
435
- });
436
- },
437
- getPhysicsProperties() {
438
- if (m || !o || !(t != null && t.model) || !t.mujoco) return null;
439
- const s = t.model, n = t.mujoco;
440
- return structuredClone({
441
- units: { length: "m", mass: "kg", time: "s" },
442
- timestep: s.opt.timestep,
443
- gravity: Array.from(s.opt.gravity),
444
- bodyCount: s.nbody - 1,
445
- jointCount: s.njnt,
446
- geomCount: s.ngeom,
447
- bodies: Array.from({ length: s.nbody - 1 }, (M, E) => {
448
- const L = E + 1;
449
- return { id: L, name: n.mj_id2name(s, n.mjtObj.mjOBJ_BODY.value, L), mass: s.body_mass[L], inertia: Array.from(s.body_inertia.slice(L * 3, L * 3 + 3)) };
450
- }),
451
- diagnostics: S == null ? void 0 : S.diagnostics
452
- });
453
- },
454
- get update() {
455
- return g || t != null && t.model || p || A ? (s) => {
456
- if (G || m || !((h == null ? void 0 : h()) ?? R) || !i && !p || !p && !(t != null && t.model)) return !1;
457
- try {
458
- if (g) return g.update(s);
459
- const n = p ? p(s) : t.step(s);
460
- return n && (p || i.sync(), a == null || a.sync(), r == null || r.updateForceLine(), Y()), n;
461
- } catch (n) {
462
- return k(n, "step"), !1;
463
- }
464
- } : void 0;
465
- },
466
- updatePaused(s) {
467
- if (G || m || ((h == null ? void 0 : h()) ?? R)) return !1;
468
- try {
469
- if (g || !o || !(t != null && t.isJointDriveActive) || !i) return !1;
470
- const n = t.stepJointDrive(s);
471
- return n && (i.sync(), a == null || a.sync(), r == null || r.updateForceLine()), Y(!t.isJointDriveActive), n;
472
- } catch (n) {
473
- return k(n, "joint-drive"), !1;
474
- }
475
- },
476
- play() {
477
- if (!(m || G || ((h == null ? void 0 : h()) ?? R)))
478
- try {
479
- if (g) {
480
- r == null || r.endGrab(), g.play(), e.requestRender();
481
- return;
482
- }
483
- d ? (d(), R = (h == null ? void 0 : h()) ?? !1) : o ? (r == null || r.endGrab(), f ? f() : (t == null || t.reset(), i == null || i.sync()), a == null || a.sync(), r == null || r.resetGround(), r == null || r.updateForceLine(), Y(!0), R = !0, y == null || y.setPlaying(!0), e.requestRender()) : u && (R = !0, e.requestRender());
484
- } catch (s) {
485
- k(s, "play");
486
- }
487
- },
488
- pause() {
489
- if (!(G || m))
490
- try {
491
- if (g) {
492
- g.pause();
493
- return;
494
- }
495
- C && C(), R = !1, r == null || r.endGrab(), o && (t == null || t.clearJointTargets({ freeze: !0 })), y == null || y.setPlaying(!1), Y(!0);
496
- } catch (s) {
497
- k(s, "pause");
498
- }
499
- },
500
- reset() {
501
- if (!(G || m || !i && !f))
502
- try {
503
- if (g) {
504
- g.reset(), r == null || r.resetGround(), e.requestRender();
505
- return;
506
- }
507
- r == null || r.endGrab(), f ? f() : (t == null || t.reset(), i.sync()), a == null || a.sync(), r == null || r.resetGround(), r == null || r.updateForceLine(), Y(!0);
508
- } catch (s) {
509
- k(s, "reset");
510
- }
511
- },
512
- beginGrab(s, n, M) {
513
- if (m || g || !o && !T) return !1;
514
- try {
515
- const E = (r == null ? void 0 : r.beginGrab(s, n, M)) ?? !1;
516
- return E && ee(), E;
517
- } catch (E) {
518
- return k(E, "grab"), !1;
519
- }
520
- },
521
- moveGrab(s, n, M) {
522
- if (!(m || !o && !T))
523
- try {
524
- r == null || r.moveGrab(s, n, M);
525
- } catch (E) {
526
- k(E, "grab");
527
- }
528
- },
529
- endGrab() {
530
- r == null || r.endGrab();
531
- },
532
- getScenePhysics() {
533
- if (m || !o || !D || !i) return null;
534
- const s = /* @__PURE__ */ new Map();
535
- return i.root.traverse((n) => {
536
- typeof n.userData.bodyId == "number" && n.name && s.set(n.name, n);
537
- }), {
538
- ...D,
539
- visualBindings: s
540
- };
541
- },
542
- dispose() {
543
- return fe(), O ?? (O = se.catch(() => {
544
- }).then(async () => {
545
- r == null || r.dispose(), r = null, w ? (w(), w = null, r = null, i = null, a = null, U = null) : (a == null || a.root.removeFromParent(), a == null || a.dispose(), a = null, U = null, i == null || i.dispose(), i = null, t == null || t.dispose()), await (K == null ? void 0 : K.catch(() => {
546
- })), _ = null, y == null || y.dispose(), y = void 0, $(), b.dispose(), S = null, j = null, D = null, W = null, p = null, f = null, d = null, C = null, h = null, P = null, T = null, o = !1, u = !1, v = null, re = !1;
547
- })), O;
548
- }
549
- };
550
- }
551
- function x(l, e) {
552
- if (l || e.aborted) throw ue();
553
- }
554
- function ue() {
555
- return Object.assign(new Error("Simulation load aborted."), { name: "AbortError", code: "E_ABORTED" });
556
- }
557
- export {
558
- He as createSimulationSession
559
- };