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