@nebula-spatial/viewer 0.4.2 → 0.4.3

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,439 @@
1
+ import { d as at, c as lt, a as Z, b as ut, r as ct, p as pt, S as V } from "./session-DhZXy40-.js";
2
+ import { d as I } from "./stage-BKqg5vNe.js";
3
+ import { Group as x, MeshStandardMaterial as K, Mesh as M, MathUtils as ft, Matrix3 as X, Matrix4 as P, Quaternion as S, Euler as G, Vector3 as v, BoxGeometry as H, SphereGeometry as Y, CylinderGeometry as tt, CapsuleGeometry as et, LoadingManager as dt } from "three";
4
+ import { GLTFLoader as mt } from "three/examples/jsm/loaders/GLTFLoader.js";
5
+ import { OBJLoader as yt } from "three/examples/jsm/loaders/OBJLoader.js";
6
+ import { STLLoader as ht } from "three/examples/jsm/loaders/STLLoader.js";
7
+ function _(t, e) {
8
+ if (!t) return [...e];
9
+ const r = t.trim().split(/\s+/).map(Number);
10
+ if (r.some((o) => !Number.isFinite(o))) throw R(`Invalid numeric value: ${t}`, "E_URDF_PARSE");
11
+ return r;
12
+ }
13
+ function N(t) {
14
+ const e = (t == null ? void 0 : t.querySelector("origin")) ?? null, r = _((e == null ? void 0 : e.getAttribute("quat_xyzw")) ?? null, []);
15
+ if (r.length !== 0 && r.length !== 4) throw R("URDF origin quat_xyzw requires four values.", "E_URDF_PARSE");
16
+ if (r.length && (e != null && e.hasAttribute("rpy"))) throw R("URDF origin cannot declare both rpy and quat_xyzw.", "E_URDF_PARSE");
17
+ return {
18
+ position: _((e == null ? void 0 : e.getAttribute("xyz")) ?? null, [0, 0, 0]),
19
+ rotationRpy: _((e == null ? void 0 : e.getAttribute("rpy")) ?? null, [0, 0, 0]),
20
+ ...r.length ? { rotationQuaternion: r } : {}
21
+ };
22
+ }
23
+ function W(t, e, r) {
24
+ const o = t.querySelector("geometry"), a = o == null ? void 0 : o.querySelector("box");
25
+ if (a) return { type: "box", size: _(a.getAttribute("size"), [1, 1, 1]) };
26
+ const n = o == null ? void 0 : o.querySelector("sphere");
27
+ if (n) return { type: "sphere", radius: E(n.getAttribute("radius"), 1) };
28
+ const i = o == null ? void 0 : o.querySelector("cylinder");
29
+ if (i) return { type: "cylinder", radius: E(i.getAttribute("radius"), 1), length: E(i.getAttribute("length"), 1) };
30
+ const f = o == null ? void 0 : o.querySelector("capsule");
31
+ if (f) return { type: "capsule", radius: E(f.getAttribute("radius"), 1), length: E(f.getAttribute("length"), 1) };
32
+ const s = o == null ? void 0 : o.querySelector("mesh"), u = s == null ? void 0 : s.getAttribute("filename");
33
+ return u ? { type: "mesh", resourcePath: r.resolve(u, e), scale: _(s.getAttribute("scale"), [1, 1, 1]) } : null;
34
+ }
35
+ function wt(t, e, r) {
36
+ const a = Ut(t, "URDF").querySelector("robot");
37
+ if (!a) throw R("URDF requires a robot root element.", "E_URDF_PARSE");
38
+ const n = ut(), i = [...a.querySelectorAll("link")].map((s) => ({
39
+ id: z(s, "name"),
40
+ name: z(s, "name"),
41
+ inertial: (() => {
42
+ try {
43
+ return _t(s);
44
+ } catch (u) {
45
+ n.errors.push({ code: "E_URDF_INERTIA", message: `连杆 ${s.getAttribute("name")}:${u instanceof Error ? u.message : String(u)}` });
46
+ return;
47
+ }
48
+ })(),
49
+ visuals: [...s.querySelectorAll("visual")].map((u) => {
50
+ var m;
51
+ const p = W(u, e, r), d = _(((m = u.querySelector("color")) == null ? void 0 : m.getAttribute("rgba")) ?? null, [0.68, 0.72, 0.7, 1]);
52
+ return p ? { origin: N(u), geometry: p, color: d } : null;
53
+ }).filter((u) => !!u),
54
+ collisions: [...s.querySelectorAll("collision")].map((u) => {
55
+ const p = W(u, e, r);
56
+ return p ? { origin: N(u), geometry: p } : null;
57
+ }).filter((u) => !!u)
58
+ })), f = [...a.querySelectorAll("joint")].map((s) => {
59
+ var A;
60
+ const u = s.querySelector("limit"), p = s.querySelector("dynamics"), d = p ? E(p.getAttribute("damping"), 0) : 0, m = p ? E(p.getAttribute("friction"), 0) : 0, g = p && (d > 0 || m > 0) ? { damping: d, friction: m } : void 0;
61
+ return {
62
+ id: z(s, "name"),
63
+ type: s.getAttribute("type") ?? "fixed",
64
+ parent: z(s.querySelector("parent"), "link"),
65
+ child: z(s.querySelector("child"), "link"),
66
+ origin: N(s),
67
+ axis: _(((A = s.querySelector("axis")) == null ? void 0 : A.getAttribute("xyz")) ?? null, [1, 0, 0]),
68
+ ...u ? { limits: { lower: E(u.getAttribute("lower"), 0), upper: E(u.getAttribute("upper"), 0) } } : {},
69
+ ...g ? { dynamics: g } : {}
70
+ };
71
+ });
72
+ return a.querySelector("transmission, gazebo") && n.droppedFeatures.push({ code: "UNSUPPORTED_URDF_EXTENSION", message: "URDF transmission/gazebo extensions are not compiled." }), at({ id: a.getAttribute("name") || e, name: a.getAttribute("name") || e, source: { format: "urdf", uri: e }, links: i, joints: f, diagnostics: n, extension: { files: r } });
73
+ }
74
+ function C(t) {
75
+ return t.rotationQuaternion ? new S(t.rotationQuaternion[0], t.rotationQuaternion[1], t.rotationQuaternion[2], t.rotationQuaternion[3]).normalize() : new S().setFromEuler(new G(...t.rotationRpy, "XYZ"));
76
+ }
77
+ function bt(t) {
78
+ if (t.rotationQuaternion) {
79
+ const [e, r, o, a] = t.rotationQuaternion;
80
+ return `quat="${a} ${e} ${r} ${o}"`;
81
+ }
82
+ return `euler="${t.rotationRpy.join(" ")}"`;
83
+ }
84
+ function T(t) {
85
+ const e = new P(), r = C(t);
86
+ return e.compose(new v().fromArray(t.position), r, new v(1, 1, 1));
87
+ }
88
+ function L(t) {
89
+ if (t.type === "continuous" || !t.limits) return 0;
90
+ const { lower: e, upper: r } = t.limits;
91
+ return !Number.isFinite(e) || !Number.isFinite(r) ? 0 : ft.clamp(0, e, r);
92
+ }
93
+ function gt(t) {
94
+ let e;
95
+ if (t.type === "box")
96
+ e = [t.size[0] / 2, t.size[1] / 2, t.size[2] / 2];
97
+ else if (t.type === "sphere")
98
+ e = [t.radius, t.radius, t.radius];
99
+ else if (t.type === "cylinder")
100
+ e = [t.radius, t.radius, t.length / 2];
101
+ else
102
+ return null;
103
+ const r = [];
104
+ for (const o of [-e[0], e[0]])
105
+ for (const a of [-e[1], e[1]])
106
+ for (const n of [-e[2], e[2]])
107
+ r.push(new v(o, a, n));
108
+ return r;
109
+ }
110
+ function rt(t, e, r) {
111
+ let o = 0;
112
+ const a = new Map(t.links.map((u) => [u.id, u])), n = (u) => {
113
+ let p = 1 / 0;
114
+ const d = (m, g) => {
115
+ const A = a.get(m);
116
+ if (A) {
117
+ for (const l of A.collisions) {
118
+ const c = gt(l.geometry);
119
+ if (!c) {
120
+ u && (o += 1);
121
+ continue;
122
+ }
123
+ const w = g.clone().multiply(T(l.origin));
124
+ for (const $ of c)
125
+ p = Math.min(p, $.applyMatrix4(w).z);
126
+ }
127
+ for (const l of r.get(m) ?? []) {
128
+ const c = g.clone().multiply(T(l.origin)), w = u ? L(l) : 0;
129
+ w && l.type === "revolute" ? c.multiply(new P().makeRotationAxis(new v().fromArray(l.axis).normalize(), w)) : w && l.type === "prismatic" && c.multiply(new P().makeTranslation(l.axis[0] * w, l.axis[1] * w, l.axis[2] * w)), d(l.child, c);
130
+ }
131
+ }
132
+ };
133
+ return d(e, new P()), p;
134
+ }, i = n(!0), f = n(!1), s = Math.min(i, f);
135
+ return o && t.diagnostics.warnings.push({
136
+ code: "GROUNDING_IGNORED_MESH_COLLIDERS",
137
+ message: `自动落地忽略了 ${o} 个网格碰撞体`
138
+ }), Number.isFinite(s) ? Math.max(0, 0.015 - s) : 0;
139
+ }
140
+ async function At(t) {
141
+ const e = t.extension.files, r = /* @__PURE__ */ new Map(), o = new Set(t.joints.map((l) => l.child));
142
+ for (const l of t.joints) r.set(l.parent, [...r.get(l.parent) ?? [], l]);
143
+ const a = t.links.filter((l) => !o.has(l.id));
144
+ if (a.length !== 1) throw R(`URDF requires exactly one root link; found ${a.length}.`, "E_URDF_COMPILE");
145
+ const n = rt(t, a[0].id, r);
146
+ n > 0 && t.diagnostics.approximations.push({
147
+ code: "AUTO_GROUNDED_FREE_ROOT",
148
+ message: `自由根初始高度自动抬升 ${n.toFixed(4)} m`
149
+ });
150
+ const i = t.joints.filter((l) => L(l) !== 0);
151
+ i.length && t.diagnostics.approximations.push({
152
+ code: "JOINT_REFERENCE_CLAMPED",
153
+ message: `${i.length} 个关节的默认参考值已夹到合法限位`
154
+ });
155
+ const f = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), u = [], p = async (l) => {
156
+ var q;
157
+ if (l.type === "box") return `type="box" size="${l.size.map((y) => y / 2).join(" ")}"`;
158
+ if (l.type === "sphere") return `type="sphere" size="${l.radius}"`;
159
+ if (l.type === "cylinder") return `type="cylinder" size="${l.radius} ${l.length / 2}"`;
160
+ if (l.type === "capsule") return `type="capsule" size="${l.radius} ${l.length / 2}"`;
161
+ const c = (q = l.resourcePath.split(".").pop()) == null ? void 0 : q.toLowerCase();
162
+ if (c !== "stl" && c !== "obj") return null;
163
+ const w = `${l.resourcePath}|${l.scale.join(" ")}`;
164
+ let $ = s.get(w);
165
+ if (!$) {
166
+ const y = { name: `mesh_${s.size}`, path: l.resourcePath, scale: l.scale };
167
+ s.set(w, y);
168
+ const F = await e.bytes(l.resourcePath);
169
+ f.set(`${y.name}.${c}`, F), $ = y;
170
+ }
171
+ return `type="mesh" mesh="${$.name}"`;
172
+ }, d = async (l, c) => {
173
+ var F, U;
174
+ const w = t.links.find((h) => h.id === l), $ = [...(c == null ? void 0 : c.origin.position) ?? [0, 0, 0]];
175
+ c || ($[2] += n);
176
+ const q = (c == null ? void 0 : c.origin) ?? { rotationRpy: [0, 0, 0] }, y = [`<body name="${Q(l)}" pos="${$.join(" ")}" ${bt(q)}>`];
177
+ if (w.inertial) {
178
+ const { origin: h, mass: D, tensor: b } = w.inertial, k = new X().setFromMatrix4(new P().makeRotationFromQuaternion(C(h))), O = new X().set(b[0], b[3], b[4], b[3], b[1], b[5], b[4], b[5], b[2]);
179
+ O.premultiply(k).multiply(k.clone().transpose());
180
+ const j = O.elements;
181
+ y.push(`<inertial pos="${h.position.join(" ")}" mass="${D}" fullinertia="${[j[0], j[4], j[8], j[3], j[6], j[7]].join(" ")}"/>`);
182
+ }
183
+ if (!c) y.push("<freejoint/>");
184
+ else if (["fixed", "planar", "floating"].includes(c.type))
185
+ (c == null ? void 0 : c.type) === "floating" && (y.push("<freejoint/>"), u.push(0, 0, 0, 1, 0, 0, 0));
186
+ else {
187
+ const h = c.type === "prismatic" ? "slide" : "hinge", D = c.type !== "continuous" && !!c.limits && Number.isFinite(c.limits.lower) && Number.isFinite(c.limits.upper), b = L(c);
188
+ u.push(b);
189
+ const k = ((F = c.dynamics) == null ? void 0 : F.damping) ?? 0, O = ((U = c.dynamics) == null ? void 0 : U.friction) ?? 0;
190
+ y.push(`<joint name="${Q(c.id)}" type="${h}" axis="${c.axis.join(" ")}"${D ? ` limited="true" range="${c.limits.lower} ${c.limits.upper}" ref="${b}"` : ""} damping="${k}" frictionloss="${O}"/>`);
191
+ }
192
+ for (const h of w.collisions) {
193
+ const D = await p(h.geometry);
194
+ if (D) {
195
+ const b = h.origin.rotationQuaternion ? ` quat="${[h.origin.rotationQuaternion[3], h.origin.rotationQuaternion[0], h.origin.rotationQuaternion[1], h.origin.rotationQuaternion[2]].join(" ")}"` : ` euler="${h.origin.rotationRpy.join(" ")}"`;
196
+ y.push(`<geom ${D} pos="${h.origin.position.join(" ")}"${b} rgba="0.55 0.62 0.59 1"/>`);
197
+ }
198
+ }
199
+ for (const h of r.get(l) ?? []) y.push(await d(h.child, h));
200
+ return y.push("</body>"), y.join("");
201
+ }, m = await d(a[0].id), g = [...s.values()].map((l) => {
202
+ var c;
203
+ return `<mesh name="${l.name}" file="${l.name}.${(c = l.path.split(".").pop()) == null ? void 0 : c.toLowerCase()}" scale="${l.scale.join(" ")}"/>`;
204
+ }).join(""), A = `<keyframe><key name="home" qpos="0 0 ${n} 1 0 0 0 ${u.join(" ")}"/></keyframe>`;
205
+ return {
206
+ format: "mjcf",
207
+ files: f,
208
+ xml: `<mujoco model="${Q(t.name)}"><compiler angle="radian" autolimits="true"/><option gravity="0 0 -9.81"/><asset>${g}</asset><worldbody><geom name="__viewer_default_ground__" type="plane" size="5 5 0.1" contype="1" conaffinity="1" friction="0.8 0.01 0.0002"/>${m}</worldbody>${A}</mujoco>`
209
+ };
210
+ }
211
+ async function $t(t) {
212
+ const e = await it(t), r = new Set(t.joints.map((s) => s.child)), o = t.links.filter((s) => !r.has(s.id));
213
+ if (o.length !== 1) throw R(`URDF requires exactly one root link; found ${o.length}.`, "E_URDF_COMPILE");
214
+ const a = /* @__PURE__ */ new Map();
215
+ for (const s of t.joints) a.set(s.parent, [...a.get(s.parent) ?? [], s]);
216
+ const n = e.bindings.get(o[0].id);
217
+ e.root.add(n);
218
+ const i = (s) => {
219
+ const u = e.bindings.get(s);
220
+ for (const p of a.get(s) ?? []) {
221
+ const d = e.bindings.get(p.child);
222
+ u.add(d), d.position.fromArray(p.origin.position), d.quaternion.copy(C(p.origin));
223
+ const m = L(p), g = new v().fromArray(p.axis).normalize();
224
+ m && (p.type === "revolute" || p.type === "continuous") ? d.quaternion.multiply(new S().setFromAxisAngle(g, m)) : m && p.type === "prismatic" && d.position.addScaledVector(g, m), i(p.child);
225
+ }
226
+ };
227
+ i(o[0].id);
228
+ const f = rt(t, o[0].id, a);
229
+ return f > 0 && (n.position.z += f), e.root.updateMatrixWorld(!0), e;
230
+ }
231
+ async function ot(t) {
232
+ const e = t.extension.files, r = new x();
233
+ r.name = "URDF authored collisions";
234
+ const o = /* @__PURE__ */ new Map(), a = lt();
235
+ let n = 0;
236
+ for (const i of t.links) {
237
+ const f = new x();
238
+ f.name = i.id, o.set(i.id, f), r.add(f);
239
+ for (const s of i.collisions) {
240
+ const u = new x();
241
+ if (u.matrixAutoUpdate = !1, u.matrix.copy(T(s.origin)), f.add(u), s.geometry.type === "mesh") {
242
+ const p = await nt(s.geometry, e, new K());
243
+ p.updateMatrixWorld(!0), p.traverse((d) => {
244
+ if (!(d instanceof M)) return;
245
+ const m = Z(d.geometry, a, "mesh");
246
+ m.matrixAutoUpdate = !1, m.matrix.copy(d.matrixWorld), m.name = `Collision:${i.id}`, m.userData.urdfLink = i.id, u.add(m), n += 1;
247
+ }), I(p);
248
+ } else {
249
+ const p = Et(s.geometry);
250
+ if (!p) continue;
251
+ const d = Z(p, a, "feature");
252
+ p.dispose(), d.name = `Collision:${i.id}`, d.userData.urdfLink = i.id, u.add(d), n += 1;
253
+ }
254
+ }
255
+ }
256
+ if (n === 0) {
257
+ a.dispose(), I(r);
258
+ return;
259
+ }
260
+ return { root: r, bindings: o, expectedLinkCount: o.size };
261
+ }
262
+ async function Rt(t, e) {
263
+ const r = await ot(t);
264
+ if (!r) return;
265
+ const o = () => {
266
+ e.root.updateMatrixWorld(!0);
267
+ for (const [a, n] of r.bindings) {
268
+ const i = e.bindings.get(a);
269
+ i && (n.matrixAutoUpdate = !1, n.matrix.copy(i.matrixWorld));
270
+ }
271
+ r.root.updateMatrixWorld(!0);
272
+ };
273
+ return o(), r.root.visible = !1, { root: r.root, sync: o, dispose() {
274
+ I(r.root);
275
+ } };
276
+ }
277
+ function Et(t) {
278
+ if (t.type === "box") return new H(...t.size);
279
+ if (t.type === "sphere") return new Y(t.radius, 24, 16);
280
+ if (t.type === "cylinder") {
281
+ const e = new tt(t.radius, t.radius, t.length, 24);
282
+ return e.rotateX(Math.PI / 2), e;
283
+ }
284
+ if (t.type === "capsule") {
285
+ const e = new et(t.radius, t.length, 8, 24);
286
+ return e.rotateX(Math.PI / 2), e;
287
+ }
288
+ return null;
289
+ }
290
+ async function it(t) {
291
+ const e = t.extension.files, r = new x();
292
+ r.name = t.name;
293
+ const o = /* @__PURE__ */ new Map();
294
+ for (const a of t.links) {
295
+ const n = new x();
296
+ n.name = a.id, o.set(a.id, n), r.add(n);
297
+ for (const i of a.visuals) {
298
+ const f = await Ft(i, e), s = new x();
299
+ s.position.fromArray(i.origin.position), s.quaternion.copy(C(i.origin)), s.add(f), n.add(s);
300
+ }
301
+ }
302
+ return { root: r, bindings: o, expectedLinkCount: t.links.length };
303
+ }
304
+ async function Ft(t, e) {
305
+ var o, a;
306
+ const r = new K({ color: t.color ? 16777215 : 11385011, opacity: ((o = t.color) == null ? void 0 : o[3]) ?? 1, transparent: (((a = t.color) == null ? void 0 : a[3]) ?? 1) < 1 });
307
+ return t.color && r.color.setRGB(t.color[0], t.color[1], t.color[2]), nt(t.geometry, e, r);
308
+ }
309
+ async function nt(t, e, r) {
310
+ var n;
311
+ if (t.type === "box") return new M(new H(...t.size), r);
312
+ if (t.type === "sphere") return new M(new Y(t.radius, 24, 16), r);
313
+ if (t.type === "cylinder") {
314
+ const i = new M(new tt(t.radius, t.radius, t.length, 24), r);
315
+ return i.quaternion.copy(new S().setFromEuler(new G(Math.PI / 2, 0, 0))), i;
316
+ }
317
+ if (t.type === "capsule") {
318
+ const i = new M(new et(t.radius, t.length, 8, 24), r);
319
+ return i.quaternion.copy(new S().setFromEuler(new G(Math.PI / 2, 0, 0))), i;
320
+ }
321
+ const o = (n = t.resourcePath.split(".").pop()) == null ? void 0 : n.toLowerCase();
322
+ await e.ensure(t.resourcePath);
323
+ let a;
324
+ if (o === "stl") a = new M(new ht().parse(await e.getBlob(t.resourcePath).arrayBuffer()), r);
325
+ else if (o === "obj")
326
+ a = new yt().parse(await e.getBlob(t.resourcePath).text()), a.traverse((i) => {
327
+ "material" in i && (i.material = r);
328
+ });
329
+ else if (o === "gltf" || o === "glb") {
330
+ const i = new dt();
331
+ i.setURLModifier((f) => {
332
+ try {
333
+ return e.objectUrl(e.resolve(f, t.resourcePath));
334
+ } catch {
335
+ return f;
336
+ }
337
+ }), a = (await new mt(i).parseAsync(await e.getBlob(t.resourcePath).arrayBuffer(), "")).scene;
338
+ } else throw R(`Unsupported URDF visual mesh: .${o ?? ""}`, "E_URDF_VISUAL");
339
+ return a.scale.fromArray(t.scale), a;
340
+ }
341
+ function Ut(t, e) {
342
+ const r = new DOMParser().parseFromString(t, "application/xml"), o = r.querySelector("parsererror");
343
+ if (o) throw R(`${e} XML parse failed: ${o.textContent ?? ""}`, `E_${e}_PARSE`);
344
+ return r;
345
+ }
346
+ function z(t, e) {
347
+ const r = t == null ? void 0 : t.getAttribute(e);
348
+ if (!r) throw R(`Missing ${e}.`, "E_URDF_PARSE");
349
+ return r;
350
+ }
351
+ function E(t, e) {
352
+ const r = Number(t);
353
+ return Number.isFinite(r) ? r : e;
354
+ }
355
+ function Q(t) {
356
+ return t.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
357
+ }
358
+ function R(t, e) {
359
+ return Object.assign(new Error(t), { code: e });
360
+ }
361
+ function _t(t) {
362
+ var n;
363
+ const e = t.querySelector("inertial");
364
+ if (!e) return;
365
+ const r = e.querySelector("inertia"), o = Number((n = e.querySelector("mass")) == null ? void 0 : n.getAttribute("value")), a = ["ixx", "iyy", "izz", "ixy", "ixz", "iyz"].map((i) => Number(r == null ? void 0 : r.getAttribute(i)));
366
+ if (!(o > 0) || a.some((i) => !Number.isFinite(i))) throw R("Invalid URDF inertia.", "E_URDF_PARSE");
367
+ return { origin: N(e), mass: o, tensor: a };
368
+ }
369
+ async function Pt(t, e, r) {
370
+ var s, u, p, d, m, g, A;
371
+ const o = t.entryPath ?? t.filename ?? "asset.urdf";
372
+ (s = e.reportProgress) == null || s.call(e, "fetch", "正在读取模型描述与依赖资源...");
373
+ const a = await ct(t, r);
374
+ if (e.signal.aborted) throw B();
375
+ (u = e.reportProgress) == null || u.call(e, "parse", "正在解析 URDF 结构与连杆...");
376
+ const n = wt(a, o, r);
377
+ let i = null, f = null;
378
+ try {
379
+ if (!n.links.some((y) => y.inertial) && !n.diagnostics.errors.some((y) => y.code === "E_URDF_INERTIA"))
380
+ return (p = e.reportProgress) == null || p.call(e, "visual", "URDF 未声明动力学参数,正在构建运动学预览..."), await J(n);
381
+ try {
382
+ (d = e.reportProgress) == null || d.call(e, "compile", "正在编译物理碰撞体与惯性矩阵...");
383
+ const y = n.diagnostics.errors.find((h) => h.code === "E_URDF_INERTIA");
384
+ if (y) throw Object.assign(new Error(y.message), { code: y.code });
385
+ const F = await At(n);
386
+ if (e.signal.aborted) throw B();
387
+ (m = e.reportProgress) == null || m.call(e, "runtime", "正在初始化物理内核...");
388
+ const U = await import("./mujoco-runtime-s85kwjo7.js");
389
+ if (i = new U.MujocoRuntime(), await i.initialize(F, e.options.mujocoBaseUrl), e.signal.aborted) throw B();
390
+ } catch (y) {
391
+ const F = pt(y, e.signal, "urdf-physics");
392
+ i == null || i.dispose(), i = null;
393
+ const U = F;
394
+ return n.diagnostics.droppedFeatures.push(U), (g = e.reportProgress) == null || g.call(e, "visual", "URDF 物理仿真不可用,正在构建运动学视觉预览..."), await J(n, U);
395
+ }
396
+ (A = e.reportProgress) == null || A.call(e, "visual", "正在构建视觉渲染网格...");
397
+ const l = await it(n);
398
+ f = new V(i, l);
399
+ const c = await ot(n), w = c ? new V(i, c) : void 0, $ = i, q = f;
400
+ return i = null, f = null, st(n, q, !0, $, void 0, w);
401
+ } catch (l) {
402
+ throw f == null || f.dispose(), i == null || i.dispose(), l;
403
+ }
404
+ }
405
+ async function J(t, e) {
406
+ const r = await $t(t), o = r.root, a = { root: o, sync() {
407
+ }, dispose() {
408
+ I(o);
409
+ } }, n = await Rt(t, r);
410
+ return st(t, a, !1, void 0, e, n);
411
+ }
412
+ function st(t, e, r, o, a, n) {
413
+ let i = !1;
414
+ return {
415
+ asset: t,
416
+ binding: e,
417
+ hasPhysics: r,
418
+ runtime: o,
419
+ fallback: a,
420
+ collision: n,
421
+ step(f) {
422
+ if (!o) return !1;
423
+ const s = o.step(f);
424
+ return s && e.sync(), s;
425
+ },
426
+ reset() {
427
+ o == null || o.reset(), e.sync();
428
+ },
429
+ dispose() {
430
+ i || (i = !0, n == null || n.dispose(), e.dispose(), o == null || o.dispose());
431
+ }
432
+ };
433
+ }
434
+ function B() {
435
+ return Object.assign(new Error("Simulation load aborted."), { name: "AbortError", code: "E_ABORTED" });
436
+ }
437
+ export {
438
+ Pt as loadUrdfSimulation
439
+ };