@nebula-spatial/viewer 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/README.md +97 -56
- package/USD-VISUAL-MATERIAL-SUPPORT.md +29 -2
- package/dist/assets/types.d.ts +3 -0
- package/dist/{index-DmGuwbBM.js → index-bTlVsOHA.js} +918 -797
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -8
- package/dist/{mjcf-visual-CFXIhVyT.js → mjcf-visual-zWaLqVqd.js} +7 -7
- package/dist/mujoco-runtime-DTxVmIzc.js +349 -0
- package/dist/session-CZghJvw6.js +883 -0
- package/dist/{session-BzIziNzg.js → session-DVCZX72J.js} +79 -75
- package/dist/stage-DGMYxyAS.js +597 -0
- package/dist/ui/types.d.ts +1 -0
- package/dist/{urdf-session-BleSrYNu.js → urdf-session-CF8xOenk.js} +737 -731
- package/dist/usd-session-DkwOFmds.js +4254 -0
- package/dist/version.d.ts +1 -1
- package/dist/{xacro-D1hcJ9kB.js → xacro-DidnrxXF.js} +1 -1
- package/openusd/openusd_probe.js +1 -1
- package/openusd/openusd_probe.wasm +0 -0
- package/package.json +1 -1
- package/dist/mujoco-runtime-7xiBQNJm.js +0 -324
- package/dist/session-Boljcc3d.js +0 -844
- package/dist/stage-C7B1_qJ0.js +0 -502
- package/dist/usd-session-DFbFB8bP.js +0 -2392
package/package.json
CHANGED
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
var G = Object.defineProperty;
|
|
2
|
-
var M = (h, t, i) => t in h ? G(h, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : h[t] = i;
|
|
3
|
-
var p = (h, t, i) => M(h, typeof t != "symbol" ? t + "" : t, i);
|
|
4
|
-
import O from "@mujoco/mujoco";
|
|
5
|
-
import T from "@mujoco/mujoco/mujoco.wasm?url";
|
|
6
|
-
import { Quaternion as b, Vector3 as j } from "three";
|
|
7
|
-
let I = 0;
|
|
8
|
-
function x(h, t) {
|
|
9
|
-
const i = `/viewer-simulation-${++I}`;
|
|
10
|
-
h.mkdir(i);
|
|
11
|
-
const e = /* @__PURE__ */ new Set([i]), o = /* @__PURE__ */ new Set(), n = (s, r) => {
|
|
12
|
-
const l = s.replaceAll("\\", "/").split("/");
|
|
13
|
-
if (l[0] === "" || l.some((u) => u === ".." || u.includes(":"))) throw q(`Invalid package path: ${s}`, "E_SIMULATION_PATH");
|
|
14
|
-
const c = l.filter((u) => u && u !== ".");
|
|
15
|
-
if (!c.length) throw q("Package path is empty.", "E_SIMULATION_PATH");
|
|
16
|
-
let m = i;
|
|
17
|
-
for (const u of c.slice(0, -1))
|
|
18
|
-
m += `/${u}`, e.has(m) || (h.mkdir(m), e.add(m));
|
|
19
|
-
const d = `${i}/${c.join("/")}`;
|
|
20
|
-
return h.writeFile(d, r), o.add(d), d;
|
|
21
|
-
}, a = () => {
|
|
22
|
-
for (const s of o) h.unlink(s);
|
|
23
|
-
o.clear();
|
|
24
|
-
for (const s of [...e].reverse()) h.rmdir(s);
|
|
25
|
-
e.clear();
|
|
26
|
-
};
|
|
27
|
-
try {
|
|
28
|
-
for (const [s, r] of t) n(s, r);
|
|
29
|
-
return { writeEntry: (s) => n("__viewer_entry.xml", s), dispose: a };
|
|
30
|
-
} catch (s) {
|
|
31
|
-
throw a(), s;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function q(h, t) {
|
|
35
|
-
return Object.assign(new Error(h), { code: t });
|
|
36
|
-
}
|
|
37
|
-
function F({
|
|
38
|
-
target: h,
|
|
39
|
-
point: t,
|
|
40
|
-
velocity: i,
|
|
41
|
-
stiffness: e,
|
|
42
|
-
damping: o,
|
|
43
|
-
maxForce: n,
|
|
44
|
-
strength: a
|
|
45
|
-
}) {
|
|
46
|
-
const s = [
|
|
47
|
-
e * (h[0] - t[0]) - o * i[0],
|
|
48
|
-
e * (h[1] - t[1]) - o * i[1],
|
|
49
|
-
e * (h[2] - t[2]) - o * i[2]
|
|
50
|
-
], r = Math.hypot(s[0], s[1], s[2]), l = n * a;
|
|
51
|
-
if (r > l && r > 0) {
|
|
52
|
-
const c = l / r;
|
|
53
|
-
s[0] *= c, s[1] *= c, s[2] *= c;
|
|
54
|
-
}
|
|
55
|
-
return s;
|
|
56
|
-
}
|
|
57
|
-
const f = 1 / 240, J = 0.05, N = 80, A = 1.15, v = 3.5, w = 14;
|
|
58
|
-
class R {
|
|
59
|
-
constructor() {
|
|
60
|
-
p(this, "mujoco", null);
|
|
61
|
-
p(this, "model", null);
|
|
62
|
-
p(this, "data", null);
|
|
63
|
-
p(this, "grab", null);
|
|
64
|
-
p(this, "lastGrabForce", [0, 0, 0]);
|
|
65
|
-
p(this, "velocityBuffer", new Float64Array(6));
|
|
66
|
-
p(this, "initialControls", []);
|
|
67
|
-
p(this, "accumulator", 0);
|
|
68
|
-
/** Authored ground pose, captured before any seating. Re-seats start here. */
|
|
69
|
-
p(this, "initialGround", null);
|
|
70
|
-
/** Ground pose currently in the model; restored verbatim by reset(). */
|
|
71
|
-
p(this, "seatedGround", null);
|
|
72
|
-
p(this, "worldRotation", new b());
|
|
73
|
-
p(this, "topLevelBodies", []);
|
|
74
|
-
p(this, "initialVelocities", []);
|
|
75
|
-
}
|
|
76
|
-
async initialize(t, i) {
|
|
77
|
-
var r;
|
|
78
|
-
this.mujoco ?? (this.mujoco = await O({ locateFile: (l) => l.endsWith(".wasm") ? i ? new URL(l, i).href : T : l }));
|
|
79
|
-
const e = x(this.mujoco.FS, t.files);
|
|
80
|
-
let o = null, n = null, a = null, s = null;
|
|
81
|
-
try {
|
|
82
|
-
o = this.mujoco.MjModel.from_xml_path(e.writeEntry(t.xml));
|
|
83
|
-
for (const c of t.massOverrides ?? []) {
|
|
84
|
-
const m = this.mujoco.mj_name2id(o, this.mujoco.mjtObj.mjOBJ_BODY.value, c.body);
|
|
85
|
-
if (m <= 0 || !Number.isFinite(c.mass) || c.mass <= 0 || !(o.body_mass[m] > 0)) throw new Error(`Invalid mass override: ${c.body}`);
|
|
86
|
-
const d = c.mass / o.body_mass[m];
|
|
87
|
-
o.body_mass[m] = c.mass;
|
|
88
|
-
for (let u = 0; u < 3; u++) o.body_inertia[m * 3 + u] *= d;
|
|
89
|
-
}
|
|
90
|
-
n = new this.mujoco.MjData(o), (r = t.massOverrides) != null && r.length && this.mujoco.mj_setConst(o, n), o.opt.timestep = f, this.worldRotation.identity(), this.applyInitialControls(n, t.initialControls), this.applyInitialVelocities(o, n, t.initialVelocities), this.mujoco.mj_forward(o, n);
|
|
91
|
-
const l = this.mujoco.mj_name2id(o, this.mujoco.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
|
|
92
|
-
a = l < 0 ? null : { id: l, height: o.geom_pos[l * 3 + 2], sameFrame: o.geom_sameframe[l] }, s = this.seatDefaultGround(o, n);
|
|
93
|
-
} catch (l) {
|
|
94
|
-
throw n == null || n.delete(), o == null || o.delete(), g(l, "E_MUJOCO_INITIALIZE");
|
|
95
|
-
} finally {
|
|
96
|
-
e.dispose();
|
|
97
|
-
}
|
|
98
|
-
this.disposeModel(), this.model = o, this.data = n, this.initialControls = t.initialControls ?? [], this.initialVelocities = t.initialVelocities ?? [], this.accumulator = 0, this.initialGround = a, this.seatedGround = s, this.topLevelBodies = this.captureTopLevelBodies(o);
|
|
99
|
-
}
|
|
100
|
-
get defaultGroundHeight() {
|
|
101
|
-
if (!this.mujoco || !this.model) return;
|
|
102
|
-
const t = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
|
|
103
|
-
return t < 0 ? void 0 : this.model.geom_pos[t * 3 + 2];
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Re-orients the compiled physics to the given authored up axis by rotating
|
|
107
|
-
* every top-level body about the world origin. Gravity stays -Z and the
|
|
108
|
-
* viewer ground stays the authored horizontal plane, so a cup that was
|
|
109
|
-
* standing now genuinely topples and settles on its side — the alternative,
|
|
110
|
-
* rotating only the rendered scene graph, would leave the visuals and the
|
|
111
|
-
* simulation in different frames.
|
|
112
|
-
*
|
|
113
|
-
* The full current state (free-joint positions, orientations and velocities)
|
|
114
|
-
* is rotated by the same delta, so a paused or running simulation is carried
|
|
115
|
-
* over instead of being re-seeded.
|
|
116
|
-
*/
|
|
117
|
-
setWorldRotation(t) {
|
|
118
|
-
var n;
|
|
119
|
-
if (!this.mujoco || !this.model || !this.data) return;
|
|
120
|
-
const i = this.model, e = this.data;
|
|
121
|
-
if (t.equals(this.worldRotation)) return;
|
|
122
|
-
const o = t.clone().multiply(this.worldRotation.clone().invert());
|
|
123
|
-
this.rotateReferenceFrames(this.topLevelBodies, t), this.rotateState(this.topLevelBodies, i, e, o), this.worldRotation.copy(t), this.mujoco.mj_forward(i, e), this.seatedGround = this.seatDefaultGround(i, e, (n = this.initialGround) == null ? void 0 : n.height), this.accumulator = 0;
|
|
124
|
-
}
|
|
125
|
-
captureTopLevelBodies(t) {
|
|
126
|
-
const i = this.mujoco, e = [];
|
|
127
|
-
for (let o = 1; o < t.nbody; o++) {
|
|
128
|
-
if (t.body_parentid[o] !== 0) continue;
|
|
129
|
-
const n = t.body_jntadr[o], a = t.body_jntnum[o] === 1 && n >= 0 && t.jnt_type[n] === i.mjtJoint.mjJNT_FREE.value ? n : -1, s = o * 3, r = o * 4;
|
|
130
|
-
e.push({
|
|
131
|
-
id: o,
|
|
132
|
-
position: new j(t.body_pos[s], t.body_pos[s + 1], t.body_pos[s + 2]),
|
|
133
|
-
quaternion: new b(t.body_quat[r + 1], t.body_quat[r + 2], t.body_quat[r + 3], t.body_quat[r]),
|
|
134
|
-
freeJoint: a
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
return e;
|
|
138
|
-
}
|
|
139
|
-
/** Writes the rotated reference pose, which reset() and fixed bases follow. */
|
|
140
|
-
rotateReferenceFrames(t, i) {
|
|
141
|
-
const e = this.model;
|
|
142
|
-
for (const o of t) {
|
|
143
|
-
const n = o.position.clone().applyQuaternion(i), a = i.clone().multiply(o.quaternion), s = o.id * 3, r = o.id * 4;
|
|
144
|
-
if (e.body_pos[s] = n.x, e.body_pos[s + 1] = n.y, e.body_pos[s + 2] = n.z, e.body_quat[r] = a.w, e.body_quat[r + 1] = a.x, e.body_quat[r + 2] = a.y, e.body_quat[r + 3] = a.z, e.body_sameframe[o.id] && (e.body_sameframe[o.id] = 0), o.freeJoint < 0) continue;
|
|
145
|
-
const l = e.jnt_qposadr[o.freeJoint];
|
|
146
|
-
e.qpos0[l] = n.x, e.qpos0[l + 1] = n.y, e.qpos0[l + 2] = n.z, e.qpos0[l + 3] = a.w, e.qpos0[l + 4] = a.x, e.qpos0[l + 5] = a.y, e.qpos0[l + 6] = a.z;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/** Rotates the live free-joint state so the simulation keeps its progress. */
|
|
150
|
-
rotateState(t, i, e, o) {
|
|
151
|
-
for (const n of t) {
|
|
152
|
-
if (n.freeJoint < 0) continue;
|
|
153
|
-
const a = i.jnt_qposadr[n.freeJoint], s = i.jnt_dofadr[n.freeJoint], r = new j(e.qpos[a], e.qpos[a + 1], e.qpos[a + 2]).applyQuaternion(o);
|
|
154
|
-
e.qpos[a] = r.x, e.qpos[a + 1] = r.y, e.qpos[a + 2] = r.z;
|
|
155
|
-
const l = new b(e.qpos[a + 4], e.qpos[a + 5], e.qpos[a + 6], e.qpos[a + 3]).premultiply(o);
|
|
156
|
-
e.qpos[a + 3] = l.w, e.qpos[a + 4] = l.x, e.qpos[a + 5] = l.y, e.qpos[a + 6] = l.z;
|
|
157
|
-
const c = new j(e.qvel[s], e.qvel[s + 1], e.qvel[s + 2]).applyQuaternion(o);
|
|
158
|
-
e.qvel[s] = c.x, e.qvel[s + 1] = c.y, e.qvel[s + 2] = c.z;
|
|
159
|
-
const m = new j(e.qvel[s + 3], e.qvel[s + 4], e.qvel[s + 5]).applyQuaternion(o);
|
|
160
|
-
e.qvel[s + 3] = m.x, e.qvel[s + 4] = m.y, e.qvel[s + 5] = m.z;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/** Lower only the viewer-owned plane, never authored bodies or authored floors.
|
|
164
|
-
* Run after forward kinematics, not during stepping (the floor must not follow falling bodies).
|
|
165
|
-
* `baseHeight` re-seats from a stable reference; omitting it lowers from the current pose.
|
|
166
|
-
*/
|
|
167
|
-
seatDefaultGround(t, i, e) {
|
|
168
|
-
const o = this.mujoco, n = o.mj_name2id(t, o.mjtObj.mjOBJ_GEOM.value, "__viewer_default_ground__");
|
|
169
|
-
if (n < 0 || t.geom_bodyid[n] !== 0 || t.geom_type[n] !== o.mjtGeom.mjGEOM_PLANE.value) return null;
|
|
170
|
-
let a = e ?? t.geom_pos[n * 3 + 2];
|
|
171
|
-
for (let s = 0; s < t.ngeom; s++) {
|
|
172
|
-
if (s === n || t.geom_type[s] === o.mjtGeom.mjGEOM_PLANE.value || !(t.geom_contype[s] & t.geom_conaffinity[n]) && !(t.geom_conaffinity[s] & t.geom_contype[n])) continue;
|
|
173
|
-
const r = s * 6, l = s * 9, c = i.geom_xmat[l + 6], m = i.geom_xmat[l + 7], d = i.geom_xmat[l + 8], u = i.geom_xpos[s * 3 + 2] + c * t.geom_aabb[r] + m * t.geom_aabb[r + 1] + d * t.geom_aabb[r + 2], _ = Math.abs(c) * t.geom_aabb[r + 3] + Math.abs(m) * t.geom_aabb[r + 4] + Math.abs(d) * t.geom_aabb[r + 5], y = u - _, E = Math.max(1e-3, t.geom_margin[s] + t.geom_margin[n]);
|
|
174
|
-
Number.isFinite(y) && y < a && (a = Math.min(a, y - E));
|
|
175
|
-
}
|
|
176
|
-
return a !== t.geom_pos[n * 3 + 2] && (t.geom_pos[n * 3 + 2] = a, t.geom_sameframe[n] = 0, o.mj_forward(t, i)), { id: n, height: a, sameFrame: t.geom_sameframe[n] };
|
|
177
|
-
}
|
|
178
|
-
beginGrab({
|
|
179
|
-
bodyId: t,
|
|
180
|
-
localPoint: i,
|
|
181
|
-
target: e,
|
|
182
|
-
stiffness: o = N,
|
|
183
|
-
damping: n,
|
|
184
|
-
maxForce: a,
|
|
185
|
-
dampingRatio: s = A,
|
|
186
|
-
maxTargetSpeed: r = v,
|
|
187
|
-
targetResponse: l = w
|
|
188
|
-
}) {
|
|
189
|
-
var _;
|
|
190
|
-
const c = Math.max(((_ = this.model) == null ? void 0 : _.body_mass[t]) ?? 1, 1e-3), m = n ?? 2 * Math.sqrt(o * c) * s, d = a ?? Math.max(120, c * 60), u = [e[0], e[1], e[2]];
|
|
191
|
-
this.grab = {
|
|
192
|
-
bodyId: t,
|
|
193
|
-
localPoint: [i[0], i[1], i[2]],
|
|
194
|
-
target: [...u],
|
|
195
|
-
requestedTarget: u,
|
|
196
|
-
stiffness: o,
|
|
197
|
-
damping: m,
|
|
198
|
-
maxForce: d,
|
|
199
|
-
strength: 1,
|
|
200
|
-
maxTargetSpeed: r,
|
|
201
|
-
targetResponse: l
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
updateGrabTarget(t) {
|
|
205
|
-
this.grab && (this.grab.requestedTarget = [t[0], t[1], t[2]]);
|
|
206
|
-
}
|
|
207
|
-
updateGrabStrength(t) {
|
|
208
|
-
this.grab && (this.grab.strength = t);
|
|
209
|
-
}
|
|
210
|
-
applyGrabForce() {
|
|
211
|
-
if (!this.grab || !this.model || !this.data || !this.mujoco) return;
|
|
212
|
-
const { bodyId: t, localPoint: i, target: e, stiffness: o, damping: n, maxForce: a, strength: s } = this.grab, r = this.data.xmat.subarray(t * 9, t * 9 + 9), l = this.data.xpos.subarray(t * 3, t * 3 + 3), c = [
|
|
213
|
-
l[0] + r[0] * i[0] + r[1] * i[1] + r[2] * i[2],
|
|
214
|
-
l[1] + r[3] * i[0] + r[4] * i[1] + r[5] * i[2],
|
|
215
|
-
l[2] + r[6] * i[0] + r[7] * i[1] + r[8] * i[2]
|
|
216
|
-
];
|
|
217
|
-
this.mujoco.mj_objectVelocity(
|
|
218
|
-
this.model,
|
|
219
|
-
this.data,
|
|
220
|
-
this.mujoco.mjtObj.mjOBJ_BODY.value,
|
|
221
|
-
t,
|
|
222
|
-
this.velocityBuffer,
|
|
223
|
-
0
|
|
224
|
-
);
|
|
225
|
-
const m = this.velocityBuffer, d = [
|
|
226
|
-
c[0] - l[0],
|
|
227
|
-
c[1] - l[1],
|
|
228
|
-
c[2] - l[2]
|
|
229
|
-
], u = [
|
|
230
|
-
m[3] + m[1] * d[2] - m[2] * d[1],
|
|
231
|
-
m[4] + m[2] * d[0] - m[0] * d[2],
|
|
232
|
-
m[5] + m[0] * d[1] - m[1] * d[0]
|
|
233
|
-
], _ = F({ target: e, point: c, velocity: u, stiffness: o, damping: n, maxForce: a, strength: s });
|
|
234
|
-
this.lastGrabForce = [..._], this.data.qfrc_applied.fill(0), this.mujoco.mj_applyFT(
|
|
235
|
-
this.model,
|
|
236
|
-
this.data,
|
|
237
|
-
_,
|
|
238
|
-
[0, 0, 0],
|
|
239
|
-
c,
|
|
240
|
-
t,
|
|
241
|
-
this.data.qfrc_applied
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
endGrab() {
|
|
245
|
-
this.data && this.data.qfrc_applied.fill(0), this.lastGrabForce = [0, 0, 0], this.grab = null;
|
|
246
|
-
}
|
|
247
|
-
step(t) {
|
|
248
|
-
if (!this.mujoco || !this.model || !this.data || t <= 0) return !1;
|
|
249
|
-
this.accumulator += Math.min(t, J);
|
|
250
|
-
let i = !1;
|
|
251
|
-
for (; this.accumulator >= f; )
|
|
252
|
-
this.updateGrabTargetForStep(), this.applyGrabForce(), this.mujoco.mj_step(this.model, this.data), this.accumulator -= f, i = !0;
|
|
253
|
-
return i;
|
|
254
|
-
}
|
|
255
|
-
updateGrabTargetForStep() {
|
|
256
|
-
const t = this.grab;
|
|
257
|
-
if (!t) return;
|
|
258
|
-
const i = t.requestedTarget ?? t.target, e = (t.maxTargetSpeed ?? v) * Math.max(1, Math.sqrt(t.strength)), o = t.targetResponse ?? w, n = 1 - Math.exp(-o * f), a = e * f;
|
|
259
|
-
for (let s = 0; s < 3; s++) {
|
|
260
|
-
const r = i[s] - t.target[s], l = Math.sign(r) * Math.min(Math.abs(r) * n, a);
|
|
261
|
-
t.target[s] += l;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
setJointValues(t) {
|
|
265
|
-
if (!(!this.mujoco || !this.model || !this.data)) {
|
|
266
|
-
for (const [i, e] of Object.entries(t)) {
|
|
267
|
-
const o = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_JOINT.value, i);
|
|
268
|
-
if (o < 0 || !Number.isFinite(e)) continue;
|
|
269
|
-
const n = this.model.jnt_type[o], a = this.mujoco.mjtJoint.mjJNT_HINGE.value, s = this.mujoco.mjtJoint.mjJNT_SLIDE.value;
|
|
270
|
-
n !== a && n !== s || (this.data.qpos[this.model.jnt_qposadr[o]] = e);
|
|
271
|
-
}
|
|
272
|
-
this.mujoco.mj_forward(this.model, this.data), this.seatDefaultGround(this.model, this.data), this.accumulator = 0;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
getJointValues(t) {
|
|
276
|
-
const i = {};
|
|
277
|
-
if (!this.mujoco || !this.model || !this.data) return i;
|
|
278
|
-
for (const e of t) {
|
|
279
|
-
const o = this.mujoco.mj_name2id(this.model, this.mujoco.mjtObj.mjOBJ_JOINT.value, e);
|
|
280
|
-
if (o < 0) continue;
|
|
281
|
-
const n = this.model.jnt_type[o], a = this.mujoco.mjtJoint.mjJNT_HINGE.value, s = this.mujoco.mjtJoint.mjJNT_SLIDE.value;
|
|
282
|
-
(n === a || n === s) && (i[e] = this.data.qpos[this.model.jnt_qposadr[o]]);
|
|
283
|
-
}
|
|
284
|
-
return i;
|
|
285
|
-
}
|
|
286
|
-
reset() {
|
|
287
|
-
if (!(!this.mujoco || !this.model || !this.data)) {
|
|
288
|
-
if (this.endGrab(), this.seatedGround) {
|
|
289
|
-
const { id: t, height: i, sameFrame: e } = this.seatedGround;
|
|
290
|
-
this.model.geom_pos[t * 3 + 2] = i, this.model.geom_sameframe[t] = e;
|
|
291
|
-
}
|
|
292
|
-
this.mujoco.mj_resetData(this.model, this.data), this.applyInitialControls(this.data, this.initialControls), this.applyInitialVelocities(this.model, this.data, this.initialVelocities), this.mujoco.mj_forward(this.model, this.data), this.accumulator = 0;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
dispose() {
|
|
296
|
-
this.disposeModel(), this.mujoco = null;
|
|
297
|
-
}
|
|
298
|
-
applyInitialControls(t, i) {
|
|
299
|
-
if (i != null && i.length) {
|
|
300
|
-
if (i.length !== t.ctrl.length) throw g(new Error(`Initial control count ${i.length} does not match MuJoCo actuator count ${t.ctrl.length}.`), "E_MUJOCO_INITIALIZE");
|
|
301
|
-
t.ctrl.set(i);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
applyInitialVelocities(t, i, e) {
|
|
305
|
-
for (const o of e ?? []) {
|
|
306
|
-
const n = this.mujoco.mj_name2id(t, this.mujoco.mjtObj.mjOBJ_BODY.value, o.body), a = n >= 0 ? t.body_jntadr[n] : -1;
|
|
307
|
-
if (a < 0 || t.jnt_type[a] !== this.mujoco.mjtJoint.mjJNT_FREE.value || o.velocity.length !== 6 || !o.velocity.every(Number.isFinite))
|
|
308
|
-
throw g(new Error(`Invalid free-body initial velocity: ${o.body}`), "E_MUJOCO_INITIALIZE");
|
|
309
|
-
const { worldRotation: s } = this, r = new j(o.velocity[0], o.velocity[1], o.velocity[2]).applyQuaternion(s), l = new j(o.velocity[3], o.velocity[4], o.velocity[5]).applyQuaternion(s);
|
|
310
|
-
i.qvel.set([r.x, r.y, r.z, l.x, l.y, l.z], t.jnt_dofadr[a]);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
disposeModel() {
|
|
314
|
-
var t, i;
|
|
315
|
-
this.endGrab(), (t = this.data) == null || t.delete(), (i = this.model) == null || i.delete(), this.data = null, this.model = null, this.initialGround = null, this.seatedGround = null, this.topLevelBodies = [], this.initialControls = [], this.initialVelocities = [], this.accumulator = 0;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
function g(h, t) {
|
|
319
|
-
const i = h instanceof Error ? h : new Error(String(h));
|
|
320
|
-
return Object.assign(i, { code: t });
|
|
321
|
-
}
|
|
322
|
-
export {
|
|
323
|
-
R as MujocoRuntime
|
|
324
|
-
};
|