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