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