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