Files
chenlin fc5ee4f2c6 feat: release v0.2 multi-robot simulator
Add declarative robot packages, shared simulation lifecycle and Microban ONNX/PD walking with independent head control.

Unify comic UI and chase camera; default robot packages to a 4.5m arena with real collision walls. Include regression tests, asset provenance/licenses and verification evidence.
2026-10-28 14:00:26 +08:00

76 lines
3.4 KiB
HTML

<!doctype html>
<html>
<body>
<script type="module">
import { loadRuntimes } from "../../src/platform/runtime/runtimes.js";
import { RigRenderer } from "../../src/platform/render/RigRenderer.js";
import { resolveAddresses } from "../../src/platform/sim/SimCore.js";
import * as THREE from "three";
try {
const { mujoco } = await loadRuntimes();
const xml = `<mujoco><asset><mesh name="tetra" scale="2 1 1" vertex="0 0 0 .04 0 0 0 .04 0 0 0 .04" face="0 2 1 0 1 3 0 3 2 1 2 3"/></asset><worldbody><geom type="plane" size="1 1 .01"/><body pos="0 0 .4"><freejoint/><geom group="2" type="box" size=".02 .03 .04" rgba=".1 .2 .3 1"/><geom group="2" type="sphere" pos=".1 0 0" size=".02"/><geom group="2" type="mesh" pos=".2 0 0" mesh="tetra"/><geom group="2" type="capsule" pos=".3 0 0" size=".01 .03"/><geom group="2" type="cylinder" pos=".4 0 0" size=".02 .04"/><body pos="0 .1 0"><joint name="a"/><geom group="2" type="sphere" size=".01"/><body pos="0 .1 0"><joint name="b"/><geom group="2" type="sphere" size=".01"/></body></body></body></worldbody><actuator><motor name="motor_b" joint="b"/><motor name="motor_a" joint="a"/></actuator></mujoco>`;
const model = mujoco.MjModel.from_xml_string(xml),
data = new mujoco.MjData(model);
data.qpos.set([1, 2, 3, Math.cos(0.3), 0, 0, Math.sin(0.3)], 0);
mujoco.mj_forward(model, data);
const rig = new RigRenderer(model, data, { groups: [2] });
rig.root.updateMatrixWorld(true);
let maxError = 0;
for (const { id, mesh } of rig.items) {
const p = new THREE.Vector3();
mesh.getWorldPosition(p);
const expected = new THREE.Vector3(
data.geom_xpos[id * 3],
data.geom_xpos[id * 3 + 2],
-data.geom_xpos[id * 3 + 1],
);
maxError = Math.max(maxError, p.distanceTo(expected));
if (model.geom_type[id] === 7) {
const attr = mesh.geometry.getAttribute("position"),
v = new THREE.Vector3(attr.getX(0), attr.getY(0), attr.getZ(0)),
r = data.geom_xmat,
a = id * 9,
b = id * 3;
const raw = new THREE.Vector3(
r[a] * v.x + r[a + 1] * v.y + r[a + 2] * v.z + data.geom_xpos[b],
r[a + 3] * v.x +
r[a + 4] * v.y +
r[a + 5] * v.z +
data.geom_xpos[b + 1],
r[a + 6] * v.x +
r[a + 7] * v.y +
r[a + 8] * v.z +
data.geom_xpos[b + 2],
);
const actual = mesh.localToWorld(v);
maxError = Math.max(
maxError,
actual.distanceTo(new THREE.Vector3(raw.x, raw.z, -raw.y)),
);
}
}
const addresses = resolveAddresses(mujoco, model, ["a", "b"]);
let missing = "";
try {
resolveAddresses(mujoco, model, ["absent"]);
} catch (e) {
missing = e.message;
}
window.renderResult = {
maxError,
count: rig.items.length,
a: addresses.get("a").actuator,
b: addresses.get("b").actuator,
missing,
color: rig.items[1].mesh.material.color.toArray(),
};
rig.dispose();
data.delete();
model.delete();
} catch (e) {
window.renderError = e.stack;
}
</script>
</body>
</html>