feat: standalone Microduck RL playground (MuJoCo WASM + ONNX policies)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
tfrere
2026-08-20 09:55:45 +02:00
parent df95ff0a28
commit db84791e5b
50 changed files with 3848 additions and 49 deletions
+1
View File
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
*.stl filter=lfs diff=lfs merge=lfs -text
+39 -4
View File
@@ -1,10 +1,45 @@
---
title: Microduck Sandbox
emoji: 🏆
colorFrom: gray
colorTo: indigo
emoji: 🐤
colorFrom: yellow
colorTo: gray
sdk: static
pinned: false
---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
# Microduck RL playground
Real trained RL policies for the Microduck robot, running fully in the
browser: MuJoCo compiled to WebAssembly steps the physics, onnxruntime-web
runs the policy network at 50 Hz. No server, no backend.
## Policies
| Button | Checkpoint | What it does |
|--------|-----------|--------------|
| Run | `BEST_alpha_walking.onnx` | Velocity-tracking locomotion (arrows / WASD to steer) |
| Sit | `BEST_alpha_sitstand.onnx` | Sits down on its hull, stands back up |
| Roulade | `roulade.onnx` | Rolls over and recovers |
Policies and MJCF model from
[apirrone/microduck_runtime](https://github.com/apirrone/microduck_runtime)
and [apirrone/mjlab_microduck](https://github.com/apirrone/mjlab_microduck).
## Controls
- Arrow up / down: forward / back
- Arrow left / right: turn
- A / E: strafe
- R: reset
- Drag to orbit, scroll to zoom
- Colour dots: repaint the duck (it quacks)
## How it works
- `rl.js` fetches the MJCF (`robot_allcollisions.xml`), strips the visual
geoms, injects a floor and a STAND keyframe, and compiles it with the
official `@mujoco/mujoco` WASM bindings.
- The 61D observation (gyro, projected gravity, joint pos/vel, last action,
command) matches `mjlab_microduck/scripts/infer_policy.py`.
- Rendering is a three.js rig built from `kinematics.json` + decimated STL
meshes, driven directly from MuJoCo `qpos`.
+335
View File
@@ -0,0 +1,335 @@
// Standalone JS port of microduck_app's src/duck/kinematics.ts.
// Loads kinematics.json (built from the MJCF by build_kinematics.py) and
// builds an Object3D tree with one Group per body. Joints become per-body
// local rotations driven by setJointAngles / setJoint.
import * as THREE from "three";
import { STLLoader } from "three/addons/loaders/STLLoader.js";
import { mergeVertices, toCreasedNormals } from "three/addons/utils/BufferGeometryUtils.js";
// Cache-busting version appended to every STL request. python http.server
// sends no Cache-Control, so browsers apply heuristic caching keyed on
// Last-Modified and can keep serving stale mesh bytes even after the files
// change on disk. Bump this whenever the mesh files are regenerated.
export const MESH_VERSION = "8";
// Default model directory: the complete mjlab export (converted from
// robot_walk.xml by tools/mjcf_to_kinematics.py). robot/v1.5/ and
// robot/alpha/ stay on disk for reference but the code no longer
// targets them.
export const MODEL_DIR = "./robot/mjlab";
// Meshes fully occluded inside the shells at every demo camera angle,
// verified empirically by per-mesh pixel-diff (front 3/4, back, low
// front close-up): hiding each changes exactly 0 pixels. Skipped at
// load time so their bytes are never fetched. Load everything with
// `?all=1` for debugging.
const HIDDEN_MESHES = new Set([]);
export async function loadKinematics(url) {
// Same cache-buster as the STLs: force-cache would otherwise keep
// serving a stale kinematics.json after the mesh list changes.
const r = await fetch(`${url}?v=${MESH_VERSION}`, { cache: "force-cache" });
if (!r.ok) throw new Error(`kinematics fetch ${r.status}`);
const k = await r.json();
// Full-resolution meshes by default (the reduction will be redone
// interactively in Blender later). `?lite=1` opts into a decimated
// meshes-lite/ sibling if present.
if (new URLSearchParams(location.search).get("lite") === "1") {
k.mesh_dir = k.mesh_dir.replace(/\/meshes$/, "/meshes-lite");
}
return k;
}
// Materials are PBR (MeshStandardMaterial), same family as the Reachy
// mobile app's glb viewer. Optional silhouette outlines via three's
// OutlineEffect - see main.js.
export async function buildRig(k, opts = {}) {
// placer holds world-space position + yaw (no axis-conversion).
const placer = new THREE.Group();
placer.name = "duck_placer";
// root applies the MJCF +Z up -> three.js +Y up convention fix.
const root = new THREE.Group();
root.name = "duck_root";
root.rotation.x = -Math.PI / 2;
placer.add(root);
const bodies = new Map();
const joints = new Map();
const loader = new STLLoader();
// STL files carry per-facet normals, which shade as a faceted mess.
// Weld vertices, then rebuild normals with a crease angle: curved
// surfaces smooth out, machined edges stay hard - the cel look needs
// both. Two scale/attribute pitfalls here:
// - mergeVertices hashes ALL attributes, so the per-facet STL normals
// must be dropped first or coincident vertices never merge.
// - toCreasedNormals groups vertices on a fixed 0.01-unit hash grid.
// Our meshes are in meters, so that grid is 1 cm: normals of vertices
// up to a centimeter apart get averaged together, which shades like a
// heavily decimated mesh. Scaling to mm makes the grid 10 um.
const CREASE = Math.PI / 5; // 36 deg
const meshCache = new Map();
const loadMesh = (name) => {
if (!meshCache.has(name)) {
meshCache.set(
name,
loader.loadAsync(`${k.mesh_dir}/${name}?v=${MESH_VERSION}`).then((raw) => {
raw.deleteAttribute("normal");
const welded = mergeVertices(raw, 1e-4);
welded.scale(1000, 1000, 1000);
const display = toCreasedNormals(welded, CREASE);
display.scale(1e-3, 1e-3, 1e-3);
welded.scale(1e-3, 1e-3, 1e-3);
return { display, welded };
}),
);
}
return meshCache.get(name);
};
for (const b of k.bodies) {
const g = new THREE.Group();
g.name = b.name;
g.position.set(b.pos[0], b.pos[1], b.pos[2]);
g.quaternion.set(b.quat[1], b.quat[2], b.quat[3], b.quat[0]);
bodies.set(b.name, g);
}
for (const b of k.bodies) {
const g = bodies.get(b.name);
if (b.parent && bodies.has(b.parent)) bodies.get(b.parent).add(g);
else root.add(g);
}
for (const b of k.bodies) {
if (!b.joint || (b.joint.type && b.joint.type !== "hinge")) continue;
const g = bodies.get(b.name);
joints.set(b.joint.name, {
body: g,
axis: new THREE.Vector3(...b.joint.axis).normalize(),
baseQuat: g.quaternion.clone(),
range: b.joint.range ?? null,
});
}
// Cache materials by their resolved PBR props so identical parts share
// one GPU material instance.
const matCache = new Map();
// Optional (meshName, bodyName, rgba) -> material spec hook. A spec is
// { color: [r,g,b], roughness, metalness, opacity? }; plain rgba arrays
// are also accepted for backwards compat.
const materialForMesh = opts.materialForMesh ?? null;
const matFor = (spec) => {
const color = spec.color;
const roughness = spec.roughness ?? 0.5;
const metalness = spec.metalness ?? 0.0;
const opacity = spec.opacity ?? 1;
const key = `${color.join(",")}|${roughness}|${metalness}|${opacity}`;
const cached = matCache.get(key);
if (cached) return cached;
const m = new THREE.MeshStandardMaterial({
color: new THREE.Color(...color),
roughness,
metalness,
transparent: opacity < 1,
opacity,
});
matCache.set(key, m);
return m;
};
const toSpec = (v, fallbackRgba) => {
if (!v) return { color: fallbackRgba.slice(0, 3), opacity: fallbackRgba[3] ?? 1 };
if (Array.isArray(v)) return { color: v.slice(0, 3), opacity: v[3] ?? 1 };
return v;
};
// Optional interior ink lines: hard edges above the threshold angle
// drawn as line segments, comic style. Cached per mesh file.
const inkOpts = opts.inkEdges ?? null;
const inkMat = inkOpts
? new THREE.LineBasicMaterial({
color: inkOpts.color ?? 0x0a0a0e,
transparent: true,
opacity: inkOpts.opacity ?? 0.55,
})
: null;
const edgeCache = new Map();
const edgesFor = (name, welded) => {
if (!edgeCache.has(name)) {
edgeCache.set(name, new THREE.EdgesGeometry(welded, inkOpts.threshold ?? 40));
}
return edgeCache.get(name);
};
const pending = [];
const loadAll = new URLSearchParams(location.search).get("all") === "1";
// The MJCF lists a few geoms twice with identical transforms (visual +
// collision copies of power_support, soles, legs); drawing both would
// only z-fight, so exact duplicates are skipped.
const seenGeoms = new Set();
for (const b of k.bodies) {
const g = bodies.get(b.name);
if (!g) continue;
for (const geom of b.geoms) {
if (geom.type && geom.type !== "mesh") continue;
if (!geom.mesh) continue;
if (!loadAll && HIDDEN_MESHES.has(geom.mesh)) continue;
const dupKey = `${b.name}|${geom.mesh}|${geom.pos}|${geom.quat}`;
if (seenGeoms.has(dupKey)) continue;
seenGeoms.add(dupKey);
pending.push(
loadMesh(geom.mesh).then(({ display, welded }) => {
const rgba = geom.color
? [geom.color[0], geom.color[1], geom.color[2], geom.color[3] ?? 1]
: [0.85, 0.85, 0.85, 1];
const spec = toSpec(materialForMesh?.(geom.mesh, b.name, rgba), rgba);
const m = new THREE.Mesh(display, matFor(spec));
// Mesh filename tag so callers can re-skin materials in place
// (survives cloneRig: Object3D.copy deep-copies userData).
m.userData.meshName = geom.mesh;
if (geom.pos) m.position.set(...geom.pos);
if (geom.quat) m.quaternion.set(geom.quat[1], geom.quat[2], geom.quat[3], geom.quat[0]);
g.add(m);
if (inkMat) {
const lines = new THREE.LineSegments(edgesFor(geom.mesh, welded), inkMat);
lines.position.copy(m.position);
lines.quaternion.copy(m.quaternion);
g.add(lines);
}
}),
);
}
}
await Promise.all(pending);
const rig = { placer, root, bodies, joints };
setupJawPivot(rig);
return rig;
}
// ── Jaw hinge ───────────────────────────────────────────────────────────
// The mjlab model has no passive jaw joints: jaw.stl / jaw_soft.stl are
// rigid geoms of the head body (named "jaw_soft" in the MJCF, it carries
// the head_roll joint). The quack re-creates the hinge in JS: both jaw
// meshes are reparented into a "jaw_pivot" group
// whose origin sits on the rear top edge of their combined bounding box
// (the physical hinge line), and setJawOpen rotates that pivot about the
// robot's left-right axis so the beak tip swings down.
const JAW_MESH_NAMES = new Set(["jaw.stl", "jaw_soft.stl"]);
export const JAW_MAX_OPEN = 0.32; // rad at openness 1
function setupJawPivot(rig) {
const meshes = [];
rig.root.traverse((o) => {
if (o.isMesh && JAW_MESH_NAMES.has(o.userData.meshName)) meshes.push(o);
});
if (!meshes.length) return;
const body = meshes[0].parent;
// The placer is still untransformed right after buildRig, so world
// coords == placer coords here: robot forward is +X, up is +Y.
rig.placer.updateWorldMatrix(true, true);
const box = new THREE.Box3();
for (const m of meshes) box.expandByObject(m);
const hingeW = new THREE.Vector3(box.min.x, box.max.y, (box.min.z + box.max.z) / 2);
// +angle about -Z rotates the +X beak tip toward -Y (down).
const axisW = new THREE.Vector3(0, 0, -1);
const bodyQuatInv = body.getWorldQuaternion(new THREE.Quaternion()).invert();
const hingeL = body.worldToLocal(hingeW.clone());
const axisL = axisW.applyQuaternion(bodyQuatInv).normalize();
const pivot = new THREE.Group();
pivot.name = "jaw_pivot";
pivot.position.copy(hingeL);
// Plain array so Object3D.copy's JSON userData clone preserves it.
pivot.userData.jawAxis = axisL.toArray();
body.add(pivot);
for (const m of meshes) {
m.position.sub(hingeL);
pivot.add(m);
}
}
// Open the beak: 0 = closed, 1 = fully open (JAW_MAX_OPEN rad). The pivot
// is resolved lazily by name so clones from cloneRig work transparently.
const _jawAxis = new THREE.Vector3();
export function setJawOpen(rig, open) {
if (rig._jawPivot === undefined) {
rig._jawPivot = rig.placer.getObjectByName("jaw_pivot") ?? null;
}
const pivot = rig._jawPivot;
if (!pivot) return;
_jawAxis.fromArray(pivot.userData.jawAxis);
pivot.quaternion.setFromAxisAngle(_jawAxis, JAW_MAX_OPEN * open);
}
// Set one named joint, clamped to its MJCF range when known.
export function setJoint(rig, name, angle) {
const j = rig.joints.get(name);
if (!j) return;
let a = angle;
if (j.range) a = Math.min(j.range[1], Math.max(j.range[0], a));
const rot = _q.setFromAxisAngle(j.axis, a);
j.body.quaternion.copy(j.baseQuat).multiply(rot);
}
const _q = new THREE.Quaternion();
export function applyPose(rig, pose) {
for (const [name, ang] of Object.entries(pose)) setJoint(rig, name, ang);
}
// Deep-clone a built rig without re-parsing the STL files: Object3D.clone
// shares geometry and materials, so N clones cost almost nothing on top of
// the first buildRig. The bodies/joints maps are rebuilt by looking up the
// cloned nodes by name (body names are unique in the MJCF).
export function cloneRig(rig) {
const placer = rig.placer.clone(true);
const root = placer.getObjectByName("duck_root");
const bodies = new Map();
for (const name of rig.bodies.keys()) {
bodies.set(name, placer.getObjectByName(name));
}
const joints = new Map();
for (const [name, j] of rig.joints) {
joints.set(name, {
body: placer.getObjectByName(j.body.name),
axis: j.axis, // read-only, safe to share
baseQuat: j.baseQuat.clone(),
range: j.range,
});
}
return { placer, root, bodies, joints };
}
// Ground using the whole rig's bounding box (sitting pose folds the legs
// under the trunk, so the feet are not the lowest point).
const _box = new THREE.Box3();
export function groundFullBody(rig, floorY = 0) {
rig.placer.updateWorldMatrix(true, true);
_box.setFromObject(rig.placer);
if (!Number.isFinite(_box.min.y)) return 0;
rig.placer.position.y += floorY - _box.min.y;
return floorY - _box.min.y;
}
// "SIT" keyframe. The mjlab model shares alpha's conventions (same
// onshape-to-robot pipeline): neck_pitch range max is 1.0472, so
// neck_pitch sits just under it (headroom for the breathing oscillation,
// +-0.025) and head_pitch compensates to keep the head level-ish with a
// slight upward tilt toward the camera. NOTE: head_pitch sign is
// inverted vs v1.5 (positive = head down), so the compensation is
// positive here (verified visually).
export const SITTING_POSE = {
left_hip_yaw: 0.0,
left_hip_roll: 0.0,
left_hip_pitch: -0.5236,
left_knee: 1.0472,
left_ankle: 0.0,
neck_pitch: 1.02,
head_pitch: 0.9,
head_yaw: 0.0,
head_roll: 0.0,
right_hip_yaw: 0.0,
right_hip_roll: 0.0,
right_hip_pitch: 0.5236,
right_knee: -1.0472,
right_ankle: 0.0,
};
+173 -17
View File
@@ -1,19 +1,175 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>My static Space</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="card">
<h1>Welcome to your static Space!</h1>
<p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
<p>
Also don't forget to check the
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
</p>
</div>
</body>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Microduck RL playground</title>
<style>
:root {
--ink: #08080c;
--yellow: #ffd23f;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
background: var(--ink);
color: rgba(255, 255, 255, 0.85);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
overflow: hidden;
}
#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }
.halftone {
position: fixed;
inset: 0;
pointer-events: none;
background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1.5px);
background-size: 21px 21px;
mask-image: linear-gradient(to bottom, transparent 30%, black 100%);
-webkit-mask-image: linear-gradient(to bottom, transparent 30%, black 100%);
}
header {
position: fixed;
top: 2.6rem;
left: 0;
right: 0;
text-align: center;
pointer-events: none;
}
header .facts {
font-size: 0.72rem;
font-weight: 600;
letter-spacing: 0.14em;
text-transform: uppercase;
color: rgba(255, 255, 255, 0.55);
}
header .facts b { color: var(--yellow); font-weight: 600; }
header h1 {
margin-top: 0.5rem;
font-size: clamp(1.6rem, 4vw, 2.6rem);
font-weight: 700;
letter-spacing: -0.03em;
color: #fff;
}
header h1 #verb { color: var(--yellow); }
#loading {
position: fixed;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.8rem;
letter-spacing: 0.14em;
text-transform: uppercase;
color: rgba(255, 255, 255, 0.45);
text-align: center;
padding: 0 2rem;
z-index: 20;
}
/* Bottom control bar */
#hud {
position: fixed;
bottom: 1.4rem;
left: 0;
right: 0;
display: flex;
flex-direction: column;
align-items: center;
gap: 0.7rem;
z-index: 10;
}
#hud .row {
display: flex;
align-items: center;
gap: 0.5rem;
}
#hud button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.14);
background: rgba(255, 255, 255, 0.04);
color: rgba(255, 255, 255, 0.8);
font: inherit;
font-size: 0.72rem;
font-weight: 600;
letter-spacing: 0.1em;
text-transform: uppercase;
padding: 0.5rem 1rem;
border-radius: 999px;
cursor: pointer;
transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
#hud button:hover { background: rgba(255, 255, 255, 0.1); }
#hud button.on {
background: #ffc61e;
border-color: #ffc61e;
color: #08080c;
}
/* Colour swatches */
#swatches { gap: 0.6rem; }
#swatches button {
width: 1.5rem;
height: 1.5rem;
padding: 0;
border-radius: 50%;
border: 2px solid rgba(255, 255, 255, 0.18);
}
#swatches button:hover { transform: scale(1.15); }
#swatches button.on {
border-color: #fff;
transform: scale(1.15);
}
#hud .keys {
font-size: 0.7rem;
letter-spacing: 0.08em;
color: rgba(255, 255, 255, 0.4);
}
#hud .keys b { color: rgba(255, 255, 255, 0.75); font-weight: 600; }
#stats {
position: fixed;
top: 1.4rem;
right: 1.6rem;
z-index: 10;
font-size: 0.68rem;
letter-spacing: 0.08em;
text-align: right;
color: rgba(255, 255, 255, 0.4);
line-height: 1.7;
font-variant-numeric: tabular-nums;
}
#stats b { color: var(--yellow); font-weight: 600; }
</style>
</head>
<body>
<div id="scene"></div>
<div class="halftone"></div>
<header>
<div class="facts"><b>Microduck</b> &middot; real trained policies &middot; MuJoCo + ONNX, live in your browser</div>
<h1>This one actually learned to <span id="verb">run</span></h1>
</header>
<div id="stats"></div>
<div id="hud" hidden>
<div class="row">
<button id="btn-walk" class="on">Run</button>
<button id="btn-sit">Sit</button>
<button id="btn-roulade">Roulade</button>
<button id="btn-reset">Reset</button>
</div>
<div class="row" id="swatches"></div>
<div class="keys">
<b>&uarr;/&darr;</b> forward / back &nbsp; <b>&larr;/&rarr;</b> turn &nbsp;
<b>A/E</b> strafe &nbsp; <b>R</b> reset &nbsp; drag to orbit
</div>
</div>
<div id="loading">Compiling physics&hellip;</div>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/"
}
}
</script>
<script type="module" src="./rl.js"></script>
</body>
</html>
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+518
View File
@@ -0,0 +1,518 @@
// Microduck RL playground: the REAL trained policies, not a procedural waddle.
//
// Physics runs in MuJoCo compiled to WebAssembly (the official
// @mujoco/mujoco bindings), stepping the same MJCF the policies were
// trained on (apirrone/mjlab_microduck). The controller is one of the
// exported ONNX checkpoints from apirrone/microduck_runtime, executed with
// onnxruntime-web at 50 Hz (timestep 0.005 s, decimation 4) - exactly the
// loop from mjlab_microduck/scripts/infer_policy.py.
//
// Obs layout (61D, "new-cmd-obs" flavor, from the ONNX metadata):
// [base_ang_vel(3), projected_gravity(3), joint_pos(14), joint_vel(14),
// last_action(14), command(13)]
// command = [vx, vy, wz, head_pose(4), body_pose(6)]; for the sitstand
// policy, command[0] is the posture flag (1 = sit, 0 = stand).
// Action (14) = joint position targets relative to the default pose.
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
import { buildRig, loadKinematics, setJoint, setJawOpen, MODEL_DIR, MESH_VERSION } from "./duck.js";
import { VARIANTS, VARIANT_NAMES, materialHookFor, randomVariantName, applyVariant, specToHex } from "./variants.js";
import loadMujoco from "https://cdn.jsdelivr.net/npm/@mujoco/mujoco@3.11.0/mujoco.js";
import * as ort from "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.27.0/dist/ort.min.mjs";
ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.27.0/dist/";
ort.env.wasm.numThreads = 1; // static hosting sends no COOP/COEP headers
const POLICY_DIR = "./policies";
const POLICIES = {
walk: `${POLICY_DIR}/BEST_alpha_walking.onnx`,
sitstand: `${POLICY_DIR}/BEST_alpha_sitstand.onnx`,
roulade: `${POLICY_DIR}/roulade.onnx`,
};
// From the ONNX metadata (identical for all alpha policies) and the STAND
// keyframe in mjlab's scene_walk.xml. Order matches the actuators in
// the MJCF.
const JOINT_NAMES = [
"left_hip_yaw", "left_hip_roll", "left_hip_pitch", "left_knee", "left_ankle",
"neck_pitch", "head_pitch", "head_yaw", "head_roll",
"right_hip_yaw", "right_hip_roll", "right_hip_pitch", "right_knee", "right_ankle",
];
const DEFAULT_POSE = new Float32Array([
0, -0.08726646259971647, -0.457924, -0.004940, 0.452984,
0.3490658503988659, 0.3490658503988659, 0, 0,
0, 0.08726646259971647, 0.457924, 0.004940, -0.452984,
]);
const NUM_JOINTS = 14;
const OBS_SIZE = 61;
const CMD_SIZE = 13;
const ACTION_SCALE = 1.0;
const TIMESTEP = 0.005;
const DECIMATION = 4;
const CTRL_DT = TIMESTEP * DECIMATION; // 50 Hz
// Velocity command limits, same as infer_policy.py's keyboard mapping.
const VEL_FWD = 0.25, VEL_BACK = -0.2, VEL_LAT = 0.2, VEL_ANG = 1.0;
const mount = document.getElementById("scene");
const loadingEl = document.getElementById("loading");
const hudEl = document.getElementById("hud");
const statsEl = document.getElementById("stats");
const verbEl = document.getElementById("verb");
const setLoading = (msg) => { loadingEl.textContent = msg; };
// Surface boot failures on the page itself: a rejected top-level await
// otherwise leaves the loading screen up with no visible error.
window.addEventListener("unhandledrejection", (e) => {
const msg = e.reason?.stack || e.reason?.message || String(e.reason);
setLoading(`Boot failed: ${msg}`);
console.error("[rl] unhandled rejection", e.reason);
});
window.addEventListener("error", (e) => {
setLoading(`Boot failed: ${e.message}`);
});
const bootSteps = [];
const traced = (label, p) => {
bootSteps.push(label);
return p.then(
(v) => {
bootSteps.splice(bootSteps.indexOf(label), 1);
if (bootSteps.length) setLoading(`Loading ${bootSteps.join(", ")}\u2026`);
return v;
},
(err) => { console.error(`[rl] ${label} FAILED`, err); throw err; },
);
};
// ── MJCF preparation ────────────────────────────────────────────────────
// robot_allcollisions.xml is what infer_policy.py's scene.xml includes: it
// carries body/shell collision geoms that robot_walk.xml lacks, which the
// sitstand policy needs (a sit rests the trunk on the ground).
// The visual meshes are irrelevant to the dynamics: every body carries an
// explicit <inertial>, and visual geoms have contype=0 conaffinity=0.
// Stripping them means the MuJoCo VFS only needs the ~10 meshes referenced
// by collision geoms.
async function buildPhysicsXml() {
const src = await (await fetch(`${MODEL_DIR}/robot_allcollisions.xml`)).text();
const doc = new DOMParser().parseFromString(src, "text/xml");
for (const g of [...doc.querySelectorAll('geom[class="visual"]')]) g.remove();
const usedMeshes = new Set(
[...doc.querySelectorAll("geom[mesh]")].map((g) => g.getAttribute("mesh")),
);
for (const m of [...doc.querySelectorAll("asset > mesh")]) {
const name = m.getAttribute("name") ?? m.getAttribute("file").replace(/\.stl$/i, "");
if (!usedMeshes.has(name)) m.remove();
}
const root = doc.documentElement;
const el = (tag, attrs) => {
const e = doc.createElement(tag);
for (const [k, v] of Object.entries(attrs)) e.setAttribute(k, v);
return e;
};
root.appendChild(el("option", { timestep: String(TIMESTEP) }));
doc.querySelector("worldbody").appendChild(
el("geom", { name: "floor", type: "plane", size: "0 0 0.05", pos: "0 0 0" }),
);
// STAND keyframe from mjlab's scene_walk.xml (STAND2 pose).
const qposFree = "0 0 0.12 1 0 0 0";
const pose14 = Array.from(DEFAULT_POSE).join(" ");
const kf = doc.createElement("keyframe");
kf.appendChild(el("key", { name: "STAND", qpos: `${qposFree} ${pose14}`, ctrl: pose14 }));
root.appendChild(kf);
const meshFiles = [...doc.querySelectorAll("asset > mesh")].map((m) => m.getAttribute("file"));
return { xml: new XMLSerializer().serializeToString(doc), meshFiles };
}
// ── Boot physics + policy in parallel with the render rig ──────────────
setLoading("Loading MuJoCo WASM, policies and meshes\u2026");
const [mujoco, { xml, meshFiles }, k] = await Promise.all([
traced("mujoco wasm", loadMujoco()),
traced("physics xml", buildPhysicsXml()),
traced("kinematics", loadKinematics(`${MODEL_DIR}/kinematics.json`)),
]);
const vfs = new mujoco.MjVFS();
await Promise.all(
meshFiles.map(async (f) => {
// Same cache-busted URL as duck.js so the browser reuses the render
// meshes instead of downloading the collision subset a second time.
const buf = await (await fetch(`${MODEL_DIR}/meshes/${f}?v=${MESH_VERSION}`, { cache: "force-cache" })).arrayBuffer();
// meshdir="assets" in the MJCF, so the compiler looks up "assets/<f>".
vfs.addBuffer(`assets/${f}`, new Uint8Array(buf));
}),
);
const sessions = {};
let currentVariant = randomVariantName();
const rigPromise = (async () => {
return buildRig(k, { materialForMesh: materialHookFor(VARIANTS[currentVariant]) });
})();
const sessionOpts = { executionProviders: ["wasm"] };
[sessions.walk, sessions.sitstand, sessions.roulade] = await Promise.all([
ort.InferenceSession.create(POLICIES.walk, sessionOpts),
ort.InferenceSession.create(POLICIES.sitstand, sessionOpts),
ort.InferenceSession.create(POLICIES.roulade, sessionOpts),
]);
setLoading("Compiling physics\u2026");
const model = mujoco.MjModel.from_xml_string(xml, vfs);
const data = new mujoco.MjData(model);
// Addresses resolved once. qpos/qvel/sensordata views are re-read at each
// use: the WASM heap can grow and detach earlier TypedArray views.
// NOTE: unlike the Python bindings, these accessor fields are plain numbers.
const qposAdr = JOINT_NAMES.map((n) => model.jnt(n).qposadr);
const dofAdr = JOINT_NAMES.map((n) => model.jnt(n).dofadr);
const gyroAdr = model.sensor("imu_ang_vel").adr;
const trunkId = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_BODY.value, "trunk_base");
const standKeyId = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_KEY.value, "STAND");
let uiReady = false;
const lastAction = new Float32Array(NUM_JOINTS);
const obs = new Float32Array(OBS_SIZE);
const cmd = new Float32Array(CMD_SIZE); // [vx, vy, wz, head(4), body(6)]
const velCmd = new Float32Array(3); // twist command, driven by held keys
// Declared before the control loop starts: buildObs checks it to decide
// between the auto-run default and manual key control.
const held = new Set();
let mode = "walk"; // "walk" | "sitstand" | "roulade"
let sitFlag = 0;
function resetSim() {
mujoco.mj_resetDataKeyframe(model, data, standKeyId);
mujoco.mj_forward(model, data);
lastAction.fill(0);
sitFlag = 0;
// Buttons reflect sitFlag; keep them honest after auto-resets.
if (uiReady) syncButtons();
}
resetSim();
// ── Observation ─────────────────────────────────────────────────────────
const _q = new THREE.Quaternion();
const _g = new THREE.Vector3();
function buildObs() {
const qpos = data.qpos, qvel = data.qvel, sens = data.sensordata;
let i = 0;
// base_ang_vel: gyro sensor at the IMU site
for (let a = 0; a < 3; a++) obs[i++] = sens[gyroAdr + a];
// projected gravity: world -z rotated into the trunk frame
const xq = data.body(trunkId).xquat; // [w, x, y, z]
_q.set(xq[1], xq[2], xq[3], xq[0]).conjugate();
_g.set(0, 0, -1).applyQuaternion(_q);
obs[i++] = _g.x; obs[i++] = _g.y; obs[i++] = _g.z;
for (let j = 0; j < NUM_JOINTS; j++) obs[i++] = qpos[qposAdr[j]] - DEFAULT_POSE[j];
for (let j = 0; j < NUM_JOINTS; j++) obs[i++] = qvel[dofAdr[j]];
for (let j = 0; j < NUM_JOINTS; j++) obs[i++] = lastAction[j];
// command: walking/roulade use the twist; sitstand uses cmd[0] as the
// posture flag. "Run" means run: with no keys held the walking policy
// gets a forward velocity by default, keys override it.
cmd.fill(0, 0, 3);
if (mode === "walk") {
cmd[0] = held.size ? velCmd[0] : VEL_FWD;
cmd[1] = velCmd[1]; cmd[2] = velCmd[2];
} else if (mode === "roulade") {
cmd[0] = velCmd[0]; cmd[1] = velCmd[1]; cmd[2] = velCmd[2];
} else {
cmd[0] = sitFlag;
}
for (let c = 0; c < CMD_SIZE; c++) obs[i++] = cmd[c];
return obs;
}
// ── Control loop (50 Hz, async because ONNX inference is async) ────────
let ctrlHz = 0;
let fallenSince = null;
async function controlStep() {
const feeds = { obs: new ort.Tensor("float32", buildObs(), [1, OBS_SIZE]) };
const out = await sessions[mode].run(feeds);
const act = out.actions.data;
lastAction.set(act);
const ctrl = data.ctrl;
for (let j = 0; j < NUM_JOINTS; j++) ctrl[j] = DEFAULT_POSE[j] + act[j] * ACTION_SCALE;
for (let s = 0; s < DECIMATION; s++) mujoco.mj_step(model, data);
// Fall detection: walk/sitstand have no get-up skill, so auto-reset when
// down for good. Height alone would false-positive on a deep sit, so
// "fallen" = trunk tilted past ~60 deg (projected gravity z above -0.5)
// or sunk below the floor, sustained for over a second. The roulade rolls
// the trunk on purpose and recovers on its own, so it gets a much longer
// grace window before we call it stuck.
const z = data.qpos[2];
const now = performance.now();
const tipped = obs[5] > -0.5; // projected gravity z, from the last obs
const graceMs = mode === "roulade" ? 5000 : 1000;
if (tipped || z < 0.02) {
fallenSince ??= now;
if (now - fallenSince > graceMs) { resetSim(); fallenSince = null; }
} else {
fallenSince = null;
}
}
let running = true;
(async function controlLoop() {
let next = performance.now();
let count = 0, hzT0 = next;
while (running) {
await controlStep();
count++;
const now = performance.now();
if (now - hzT0 > 500) {
ctrlHz = (count * 1000) / (now - hzT0);
count = 0; hzT0 = now;
}
next += CTRL_DT * 1000;
const wait = next - performance.now();
if (wait > 0) await new Promise((r) => setTimeout(r, wait));
else next = performance.now(); // fell behind: don't spiral
}
})();
// ── Rendering (three.js rig driven by qpos) ─────────────────────────────
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08080c);
const camera = new THREE.PerspectiveCamera(40, 1, 0.02, 30);
camera.position.set(0.55, 0.35, 0.7);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(2, window.devicePixelRatio));
renderer.toneMapping = THREE.ACESFilmicToneMapping;
mount.appendChild(renderer.domElement);
const pmrem = new THREE.PMREMGenerator(renderer);
scene.environment = pmrem.fromScene(new RoomEnvironment()).texture;
scene.environmentIntensity = 0.45;
scene.add(new THREE.AmbientLight(0xffffff, 0.6));
const keyLight = new THREE.DirectionalLight(0xffffff, 1.6);
keyLight.position.set(2, 4, 2);
scene.add(keyLight);
const fill = new THREE.DirectionalLight(0xffffff, 0.4);
fill.position.set(-2, 2, 1.5);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffb366, 0.7);
rim.position.set(0, 3, -2);
scene.add(rim);
function makeFloorTexture() {
const N = 256;
const c = document.createElement("canvas");
c.width = c.height = N;
const g = c.getContext("2d");
g.fillStyle = "#131009";
g.fillRect(0, 0, N, N);
g.strokeStyle = "rgba(255, 179, 102, 0.05)";
g.lineWidth = 2;
g.strokeRect(1, 1, N - 2, N - 2);
g.fillStyle = "rgba(255, 198, 30, 0.10)";
for (const x of [0, N]) {
for (const y of [0, N]) {
g.beginPath();
g.arc(x, y, 5, 0, Math.PI * 2);
g.fill();
}
}
const tex = new THREE.CanvasTexture(c);
tex.colorSpace = THREE.SRGBColorSpace;
tex.wrapS = tex.wrapT = THREE.RepeatWrapping;
tex.repeat.set(48, 48);
return tex;
}
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(12, 12),
new THREE.MeshStandardMaterial({ map: makeFloorTexture(), roughness: 0.9, metalness: 0.0 }),
);
floor.rotation.x = -Math.PI / 2;
scene.add(floor);
const rig = await rigPromise;
scene.add(rig.placer);
const trunkGroup = rig.bodies.get("trunk_base");
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.08;
controls.minDistance = 0.25;
controls.maxDistance = 3;
controls.maxPolarAngle = Math.PI / 2 - 0.03;
function resize() {
const w = mount.clientWidth, h = mount.clientHeight;
camera.aspect = w / h;
camera.updateProjectionMatrix();
renderer.setSize(w, h);
}
new ResizeObserver(resize).observe(mount);
resize();
// The rig's root already applies the MJCF Z-up -> three Y-up fix, so the
// trunk group can take the freejoint pose in raw MJCF coordinates.
const _target = new THREE.Vector3();
function syncRig() {
const qpos = data.qpos;
trunkGroup.position.set(qpos[0], qpos[1], qpos[2]);
trunkGroup.quaternion.set(qpos[4], qpos[5], qpos[6], qpos[3]);
for (let j = 0; j < NUM_JOINTS; j++) setJoint(rig, JOINT_NAMES[j], qpos[qposAdr[j]]);
// Camera target eases toward the trunk so the duck stays framed while
// it walks away.
_target.set(qpos[0], qpos[2], -qpos[1]);
controls.target.lerp(_target, 0.06);
}
// Quack: a quick jaw flap on every mode/colour change. The jaw isn't a
// MuJoCo joint (duck.js re-creates the hinge in JS), so this is purely
// cosmetic and can't upset the policy.
const QUACK_MS = 480;
let quackAt = -Infinity;
const quack = () => { quackAt = performance.now(); };
function syncJaw() {
const t = (performance.now() - quackAt) / QUACK_MS;
setJawOpen(rig, t >= 0 && t < 1 ? Math.sin(Math.PI * t) : 0);
}
function renderStats() {
const [vx, vy, wz] = velCmd;
const posture = mode === "walk"
? `running policy`
: mode === "roulade"
? `roulade policy`
: `sitstand policy \u00b7 ${sitFlag ? "sit" : "stand"}`;
statsEl.innerHTML =
`<b>${posture}</b><br>` +
`cmd vx ${vx.toFixed(2)} \u00b7 vy ${vy.toFixed(2)} \u00b7 wz ${wz.toFixed(2)}<br>` +
`ctrl ${ctrlHz.toFixed(0)} Hz \u00b7 sim t ${data.time.toFixed(1)} s`;
}
function loop() {
requestAnimationFrame(loop);
syncRig();
syncJaw();
controls.update();
renderStats();
renderer.render(scene, camera);
}
loadingEl.style.display = "none";
hudEl.hidden = false;
loop();
// ── Input: hold-to-command keys + HUD buttons ───────────────────────────
function refreshVelCmd() {
velCmd[0] = held.has("fwd") ? VEL_FWD : held.has("back") ? VEL_BACK : 0;
velCmd[1] = held.has("left") ? VEL_LAT : held.has("right") ? -VEL_LAT : 0;
velCmd[2] = held.has("turnl") ? VEL_ANG : held.has("turnr") ? -VEL_ANG : 0;
}
const KEYMAP = {
ArrowUp: "fwd", KeyW: "fwd", KeyZ: "fwd",
ArrowDown: "back", KeyS: "back",
ArrowLeft: "turnl", ArrowRight: "turnr",
KeyA: "left", KeyQ: "left", KeyE: "right", KeyD: "right",
};
window.addEventListener("keydown", (e) => {
if (e.repeat) return;
if (e.code === "KeyR") { resetSim(); return; }
const act = KEYMAP[e.code];
if (!act) return;
e.preventDefault();
held.add(act);
refreshVelCmd();
});
window.addEventListener("keyup", (e) => {
const act = KEYMAP[e.code];
if (!act) return;
held.delete(act);
refreshVelCmd();
});
window.addEventListener("blur", () => { held.clear(); refreshVelCmd(); });
const btnWalk = document.getElementById("btn-walk");
const btnSit = document.getElementById("btn-sit");
const btnRoulade = document.getElementById("btn-roulade");
document.getElementById("btn-reset").addEventListener("click", resetSim);
// The headline verb tracks the active policy.
const VERBS = { walk: "run", sitstand: "sit", roulade: "roll over" };
function setMode(next) {
quack();
if (next !== "sit") {
// Leaving a sit: let the sitstand policy stand the duck back up first.
if (mode === "sitstand" && sitFlag === 1) {
sitFlag = 0;
setTimeout(() => { mode = next; lastAction.fill(0); syncButtons(); }, 2000);
syncButtons();
return;
}
mode = next;
lastAction.fill(0);
} else {
// Hand over gently: hold the stand under the sitstand policy for a
// moment before commanding the sit, or the abrupt session switch
// (walking's action history + instant flag) knocks the duck over.
mode = "sitstand";
sitFlag = 0;
lastAction.fill(0);
setTimeout(() => {
if (mode === "sitstand") { sitFlag = 1; syncButtons(); }
}, 800);
}
syncButtons();
}
function syncButtons() {
const sitting = mode === "sitstand" && sitFlag === 1;
btnWalk.classList.toggle("on", mode === "walk" || (mode === "sitstand" && !sitting));
btnSit.classList.toggle("on", sitting);
btnRoulade.classList.toggle("on", mode === "roulade");
verbEl.textContent = VERBS[mode];
}
btnWalk.addEventListener("click", () => setMode("walk"));
btnSit.addEventListener("click", () => setMode("sit"));
btnRoulade.addEventListener("click", () => setMode("roulade"));
// ── Colour swatches: re-skin the rig live, with a quack ─────────────────
// One representative colour per variant so the dots read at a glance.
const SWATCH_SLOT = { classic: "feet", charcoal: "headDome", purple: "feet", blue: "facePlate" };
const swatchesEl = document.getElementById("swatches");
const swatchBtns = new Map();
for (const name of VARIANT_NAMES) {
const v = VARIANTS[name];
const b = document.createElement("button");
b.style.background = specToHex(v[SWATCH_SLOT[name] ?? "bodyShell"]);
b.setAttribute("aria-label", `${name} colours`);
b.addEventListener("click", () => {
if (name === currentVariant) return;
currentVariant = name;
applyVariant(rig, name);
quack();
syncSwatches();
});
swatchesEl.appendChild(b);
swatchBtns.set(name, b);
}
function syncSwatches() {
for (const [name, b] of swatchBtns) b.classList.toggle("on", name === currentVariant);
}
syncSwatches();
syncButtons();
uiReady = true;
// Deterministic hooks for automated verification (rAF pauses in
// background tabs, and the control loop is async).
window.rl = {
model, data, mujoco,
get mode() { return mode; },
get sitFlag() { return sitFlag; },
buildObs, cmd,
velCmd, lastAction, resetSim,
step: async (n = 1) => { for (let i = 0; i < n; i++) await controlStep(); },
render: () => { syncRig(); renderer.render(scene, camera); },
};
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+434
View File
@@ -0,0 +1,434 @@
<?xml version="1.0" ?>
<!-- Generated using onshape-to-robot -->
<!-- Onshape https://cad.onshape.com/documents/804927696f06d877f3f1803e/w/5b75db19292e71970de02dee/e/ef6e972847fec8d82570b35e -->
<mujoco model="microduck">
<compiler angle="radian" meshdir="assets" autolimits="true"/>
<default>
<default class="microduck">
<joint frictionloss="0.1" armature="0.005"/>
<position kp="50" dampratio="1"/>
<default class="visual">
<geom type="mesh" contype="0" conaffinity="0" group="2"/>
</default>
<default class="collision">
<geom group="3"/>
</default>
</default>
</default>
<!-- Additional joints_properties.xml -->
<default>
<default class="perfect_actuator">
<geom contype="0" conaffinity="0"/>
<joint damping="0.15" frictionloss="0.1" armature="0.001"/>
<position kp="10.0" kv="0.1" forcerange="-20.0 20.0"/>
</default>
<default class="chosen_actuator_old">
<geom contype="0" conaffinity="0"/>
<joint damping="0.048" frictionloss="0.006" armature="0.002"/>
<position kp="0.52" kv="0.0" forcerange="-0.91 0.91" ctrlrange="-10.0 10.0"/>
</default>
<default class="chosen_actuator_new">
<!-- removing contaminated data -->
<geom contype="0" conaffinity="0"/>
<joint damping="0.041" frictionloss="0.032" armature="0.002"/>
<position kp="0.386" kv="0.0" forcerange="-0.67 0.67" ctrlrange="-10.0 10.0"/>
</default>
<default class="chosen_actuator_antoine">
<geom contype="0" conaffinity="0"/>
<joint damping="0.044" frictionloss="0.013" armature="0.0017"/>
<position kp="0.43" kv="0.0" forcerange="-0.75 0.75" ctrlrange="-10.0 10.0"/>
</default>
<default class="chosen_actuator">
<!-- marc -->
<geom contype="0" conaffinity="0"/>
<joint damping="0.053" frictionloss="0.0048" armature="0.0018"/>
<!-- 200 kp -->
<position kp="0.55" kv="0.0" forcerange="-0.96 0.96" ctrlrange="-10.0 10.0"/>
<!-- 125 kp -->
<!-- <position kp="0.35" kv="0.0" forcerange="-0.96 0.96" ctrlrange="-10.0 10.0"/> -->
</default>
<default class="passive_wheel">
<geom contype="0" conaffinity="0"/>
<joint damping="0.0" frictionloss="0.0" armature="0.0001"/>
</default>
<default class="passive_joint">
<geom contype="0" conaffinity="0"/>
<joint damping="0.0" frictionloss="0.0" armature="0.0001"/>
</default>
</default>
<!-- Additional sensors.xml -->
<sensor>
<framequat name="orientation" objtype="site" noise="0.001" objname="imu"/>
<gyro name="angular-velocity" site="imu" noise="0.005"/>
<gyro name="imu_ang_vel" site="imu"/>
<velocimeter name="imu_lin_vel" site="imu"/>
<accelerometer name="imu_accel" site="imu"/>
<subtreeangmom name="root_angmom" body="trunk_base"/>
</sensor>
<!-- Additional additional.xml -->
<default>
<default class="self_collision_only">
<geom group="3" contype="2" conaffinity="2"/>
</default>
<equality solref="0.002 1" solimp="0.99 0.999 0.0005 0.5 2"/>
</default>
<!-- <contact> -->
<!-- Jaw collision mesh overlaps the bottom head shell by ~2cm because the closed -->
<!-- loop linkage positions it inside the head. Without these excludes the -->
<!-- self-collision sensor reports a constant 2 contacts, giving a -->
<!-- permanent ~-2.0 reward penalty in the standup env. -->
<!-- <exclude body1="jaw" body2="bottom_head_shell"/> -->
<!-- </contact> -->
<worldbody>
<!-- Link trunk_base -->
<body name="trunk_base" pos="0 0 0.12" quat="1 0 0 0" childclass="microduck">
<freejoint name="trunk_base_freejoint"/>
<inertial pos="-0.0226332 -2.70828e-05 0.00280064" mass="0.199224" fullinertia="0.000123975 0.000145931 0.000115351 7.1651e-08 -2.06915e-05 1.32429e-07"/>
<!-- Part seeed_bearing__configuration__22x16x4 -->
<geom type="mesh" class="visual" pos="0.006 0.0175 -0.005" quat="1 -0 -0 0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part right_shell -->
<geom type="mesh" class="visual" pos="0.004 -0.0005 -0.0175" quat="0.707107 -0 -0 0.707107" mesh="right_shell" material="right_shell_material"/>
<!-- Part banana_pcb_locker -->
<geom type="mesh" class="visual" pos="0.0042 -0 -0.0175215" quat="0.707107 -0 0 0.707107" mesh="banana_pcb_locker" material="banana_pcb_locker_material"/>
<!-- Part trunk_base -->
<geom type="mesh" class="visual" pos="0.004 -0 -0.0175" quat="0.707107 -0 -0 0.707107" mesh="trunk_base" material="trunk_base_material"/>
<!-- Part xl330 -->
<geom type="mesh" class="visual" pos="0.006 0.0175 0.0115" quat="0 0.707107 -0 0.707107" mesh="xl330" material="xl330_material"/>
<!-- Part power_support -->
<geom type="mesh" class="visual" pos="0.004 -0 -0.0175215" quat="0.707107 -0 0 0.707107" mesh="power_support" material="power_support_material"/>
<geom type="mesh" class="self_collision_only" pos="0.004 -0 -0.0175215" quat="0.707107 -0 0 0.707107" mesh="power_support" material="power_support_material"/>
<!-- Part np_f970 -->
<geom type="mesh" class="visual" pos="-0.0359693 0 -0.00385049" quat="0.00617059 0.70708 -0.70708 -0.00617059" mesh="np_f970" material="np_f970_material"/>
<geom type="mesh" class="collision" pos="-0.0359693 0 -0.00385049" quat="0.00617059 0.70708 -0.70708 -0.00617059" mesh="np_f970" material="np_f970_material"/>
<!-- Part xl330_2 -->
<geom type="mesh" class="visual" pos="0.006 -0.0175 0.0115" quat="0 0.707107 -0 0.707107" mesh="xl330" material="xl330_material"/>
<!-- Part left_shell -->
<geom type="mesh" class="visual" pos="0.004 -0 -0.0175785" quat="0.707107 0 -0 0.707107" mesh="left_shell" material="left_shell_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_2 -->
<geom type="mesh" class="visual" pos="0.006 -0.0175 -0.005" quat="1 -0 -0 0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Frame imu -->
<site group="3" name="imu" pos="-0.021 6.64098e-05 -0.0146984" quat="1 -0 -0 0"/>
<!-- Link yaw2roll -->
<body name="yaw2roll" pos="0.006 0.0175 -0.005" quat="0 -0.707107 -0.707107 -0">
<!-- Joint from trunk_base to yaw2roll -->
<joint axis="0 0 1" name="left_hip_yaw" type="hinge" range="-0.4363323129985824 0.5235987755982988" class="chosen_actuator"/>
<inertial pos="-8.8e-11 0.00099414 0.0168917" mass="0.0230406" fullinertia="4.1964e-06 3.41752e-06 2.3265e-06 -0 -0 -5.0881e-08"/>
<!-- Part yaw2roll -->
<geom type="mesh" class="visual" pos="-0.0175 -0.002 0.0125" quat="0 1 0 0" mesh="yaw2roll" material="yaw2roll_material"/>
<!-- Part xl330_3 -->
<geom type="mesh" class="visual" pos="-0 0 0.0125" quat="0 -0.707107 0.707107 -0" mesh="xl330" material="xl330_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_3 -->
<geom type="mesh" class="visual" pos="-0 0.0165 0.0125" quat="0.5 0.5 0.5 -0.5" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part bearing_roll -->
<geom type="mesh" class="visual" pos="-0.0175 -0.002 0.0125" quat="0 -1 -0 -0" mesh="bearing_roll" material="bearing_roll_material"/>
<!-- Link hip_l -->
<body name="hip_l" pos="0 0.0165 0.0125" quat="0.707107 -0.707107 -0 -0">
<!-- Joint from yaw2roll to hip_l -->
<joint axis="0 0 1" name="left_hip_roll" type="hinge" range="-0.3839724354387525 0.3839724354387525" class="chosen_actuator"/>
<inertial pos="0.014815 1.6179e-08 -0.00829992" mass="0.00618934" fullinertia="8.60626e-07 1.15753e-06 6.51588e-07 1e-12 3.89882e-07 -1e-12"/>
<!-- Part seeed_bearing__configuration__22x16x4_4 -->
<geom type="mesh" class="visual" pos="0.021 0 -0.0185" quat="0.5 0.5 0.5 0.5" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part hip_l -->
<geom type="mesh" class="visual" pos="-0.0175 0 -0.0185" quat="0.707107 -0.707107 0 -0" mesh="hip_l" material="hip_l_material"/>
<geom type="mesh" class="collision" pos="-0.0175 0 -0.0185" quat="0.707107 -0.707107 0 -0" mesh="hip_l" material="hip_l_material"/>
<!-- Link upper_leg_left -->
<body name="upper_leg_left" pos="0.025 0 -0.0185" quat="0.5 -0.5 0.5 -0.5">
<!-- Joint from hip_l to upper_leg_left -->
<joint axis="0 0 1" name="left_hip_pitch" type="hinge" range="-1.570796326795005 1.5707963267947882" class="chosen_actuator"/>
<inertial pos="0.006766 0.0228838 0.0134531" mass="0.0482067" fullinertia="1.68753e-05 1.03691e-05 1.98269e-05 -4.41852e-06 2.27982e-07 3.89298e-07"/>
<!-- Part upper_leg_left -->
<geom type="mesh" class="visual" pos="-0 -0 -0.0425" quat="0.5 -0.5 -0.5 -0.5" mesh="upper_leg_left" material="upper_leg_left_material"/>
<!-- Part xl330_4 -->
<geom type="mesh" class="visual" pos="0.022 0.0357771 0.0125" quat="0 -0.707107 -0 -0.707107" mesh="xl330" material="xl330_material"/>
<!-- Part upper_leg_rigidity_plate -->
<geom type="mesh" class="visual" pos="0 -0 -0.0425" quat="0.5 -0.5 -0.5 -0.5" mesh="upper_leg_rigidity_plate" material="upper_leg_rigidity_plate_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_5 -->
<geom type="mesh" class="visual" pos="0.022 0.0357771 -0.004" quat="0 0 0 1" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part xl330_5 -->
<geom type="mesh" class="visual" pos="-0 -0 0.0125" quat="0.5 0.5 -0.5 0.5" mesh="xl330" material="xl330_material"/>
<!-- Link leg -->
<body name="leg" pos="0.022 0.0357771 -0.004" quat="0 0.707107 0.707107 0">
<!-- Joint from upper_leg_left to leg -->
<joint axis="0 0 1" name="left_knee" type="hinge" range="-1.570796326795012 1.570796326794781" class="chosen_actuator"/>
<inertial pos="-1.52e-10 0.0318937 -0.00953505" mass="0.0215844" fullinertia="5.25056e-06 2.15507e-06 4.33925e-06 -1e-12 0 7.65005e-07"/>
<!-- Part leg -->
<geom type="mesh" class="visual" pos="-0.022 0.0357771 0.0385" quat="0.5 0.5 0.5 -0.5" mesh="leg" material="leg_material"/>
<geom type="mesh" class="collision" pos="-0.022 0.0357771 0.0385" quat="0.5 0.5 0.5 -0.5" mesh="leg" material="leg_material"/>
<!-- Part xl330_6 -->
<geom type="mesh" class="visual" pos="0 0.042 -0.0115" quat="0.5 -0.5 -0.5 -0.5" mesh="xl330" material="xl330_material"/>
<!-- Link ankle_left -->
<body name="ankle_left" pos="0 0.042 -0.026" quat="0 1 -0 0">
<!-- Joint from leg to ankle_left -->
<joint axis="0 0 1" name="left_ankle" type="hinge" range="-1.5707963267949019 1.5707963267948912" class="chosen_actuator"/>
<inertial pos="-0.00615738 -0.0137483 -0.0156586" mass="0.0300246" fullinertia="5.91525e-06 1.11534e-05 7.74015e-06 -2.0535e-07 8.2152e-08 5.6714e-08"/>
<!-- Part sole_left -->
<geom type="mesh" class="visual" pos="-0.022 0.00622291 -0.0647" quat="0.5 -0.5 -0.5 -0.5" mesh="sole_left" material="sole_left_material"/>
<geom type="mesh" name="left_foot_collision" class="collision" pos="-0.022 0.00622291 -0.0647" quat="0.5 -0.5 -0.5 -0.5" mesh="sole_left" material="sole_left_material"/>
<!-- Part foot_left -->
<geom type="mesh" class="visual" pos="-0.022 0.00622291 -0.0647" quat="0.5 -0.5 -0.5 -0.5" mesh="foot_left" material="foot_left_material"/>
<!-- Part seeed_bearing__configuration_default -->
<geom type="mesh" class="visual" pos="0 0 -0.0322" quat="0 0 -0 1" mesh="seeed_bearing__configuration_default" material="seeed_bearing__configuration_default_material"/>
<!-- Part ankle_left -->
<geom type="mesh" class="visual" pos="-0.022 0.00622291 -0.0647" quat="0.5 -0.5 -0.5 -0.5" mesh="ankle_left" material="ankle_left_material"/>
<!-- Frame left_foot -->
<site group="3" name="left_foot" pos="-0 -0.0238146 -0.0140852" quat="0 0 0.707107 0.707107"/>
</body>
</body>
</body>
</body>
</body>
<!-- Link neck -->
<body name="neck" pos="0.026 0.0145 0.0324215" quat="0 0 0.707107 -0.707107">
<!-- Joint from trunk_base to neck -->
<joint axis="0 0 1" name="neck_pitch" type="hinge" range="-1.5707963267948966 1.0471975511965976" class="chosen_actuator"/>
<inertial pos="0 -0.025 0.0141665" mass="0.0368414" fullinertia="1.72925e-05 3.12694e-06 1.63707e-05 0 0 0"/>
<!-- Part neck -->
<geom type="mesh" class="visual" pos="0.022 0.05 0.028" quat="0.5 0.5 0.5 -0.5" mesh="neck" material="neck_material"/>
<!-- Part xl330_7 -->
<geom type="mesh" class="visual" pos="0 0 0.0145" quat="0.5 -0.5 -0.5 -0.5" mesh="xl330" material="xl330_material"/>
<!-- Part xl330_8 -->
<geom type="mesh" class="visual" pos="0 -0.05 0.0145" quat="0.5 0.5 -0.5 0.5" mesh="xl330" material="xl330_material"/>
<!-- Part neck_2 -->
<geom type="mesh" class="visual" pos="0.022 0.05 0.003" quat="0.5 0.5 0.5 -0.5" mesh="neck" material="neck_material"/>
<!-- Link neck_pitch -->
<body name="neck_pitch" pos="0 -0.05 -0" quat="0 1 0 0">
<!-- Joint from neck to neck_pitch -->
<joint axis="0 0 1" name="head_pitch" type="hinge" range="-1.5707963267948974 1.5707963267948957" class="chosen_actuator"/>
<inertial pos="-6.533e-09 0.0116641 -0.0145" mass="0.00572" fullinertia="1.09186e-06 9.66855e-07 5.12111e-07 0 0 0"/>
<!-- Part neck_pitch -->
<geom type="mesh" class="visual" pos="-0 0.0287931 -0.0145" quat="0.5 -0.5 -0.5 -0.5" mesh="neck_pitch" material="neck_pitch_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_6 -->
<geom type="mesh" class="visual" pos="-0 0.0207931 -0.0145" quat="0.707107 0.707107 0 0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Link yaw_roll_motion -->
<body name="yaw_roll_motion" pos="-0 0.0186931 -0.0145" quat="0 0 -0.707107 -0.707107">
<!-- Joint from neck_pitch to yaw_roll_motion -->
<joint axis="0 0 1" name="head_yaw" type="hinge" range="-2.967059728390373 2.967059728390348" class="chosen_actuator"/>
<inertial pos="-0.000166657 -0.00500964 0.0178065" mass="0.0486" fullinertia="6.97903e-06 8.10293e-06 9.57884e-06 3.21657e-07 -3.4797e-08 3.4295e-07"/>
<!-- Part yaw_roll_motion -->
<geom type="mesh" class="visual" pos="0 0 0.01" quat="0.707107 0 -0 0.707107" mesh="yaw_roll_motion" material="yaw_roll_motion_material"/>
<!-- Part xl330_9 -->
<geom type="mesh" class="visual" pos="0 0 0.0145" quat="0.5 -0.5 -0.5 -0.5" mesh="xl330" material="xl330_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_7 -->
<geom type="mesh" class="visual" pos="-0.016 0 0.0145" quat="0.707107 -0 -0.707107 -0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_8 -->
<geom type="mesh" class="visual" pos="0.018 0 0.0145" quat="0.707107 -0 -0.707107 -0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Link jaw_soft -->
<body name="jaw_soft" pos="-0.0179 0 0.0145" quat="0.707107 -0 -0.707107 -0">
<!-- Joint from yaw_roll_motion to jaw_soft -->
<joint axis="0 0 1" name="head_roll" type="hinge" range="-0.43633231299859127 0.4363323129985735" class="chosen_actuator"/>
<inertial pos="0.00460523 0.00120047 -0.0324761" mass="0.188766" fullinertia="0.000320812 0.0002541 0.000149882 -6.32292e-07 6.57154e-06 4.18476e-06"/>
<!-- Part lens -->
<geom type="mesh" class="visual" pos="0.0155 -9.13778e-05 -0.05548" quat="0.5 -0.5 0.5 -0.5" mesh="lens" material="lens_material"/>
<!-- Part face_part -->
<geom type="mesh" class="visual" pos="-0.0045 -9.13778e-05 -0.0178" quat="0.5 0.5 0.5 0.5" mesh="face_part" material="face_part_material"/>
<!-- Part xl330_10 -->
<geom type="mesh" class="visual" pos="0.003 0.0255 -0.018" quat="0.707107 0 -0 -0.707107" mesh="xl330" material="xl330_material"/>
<!-- Part jaw_soft -->
<geom type="mesh" class="visual" pos="-0.0046 0 -0.0179996" quat="0.5 0.5 0.5 0.5" mesh="jaw_soft" material="jaw_soft_material"/>
<!-- Part motor_support -->
<geom type="mesh" class="visual" pos="-0.0045 0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="motor_support" material="motor_support_material"/>
<!-- Part top_head_shell -->
<geom type="mesh" class="visual" pos="-0.0045 -0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="top_head_shell" material="top_head_shell_material"/>
<geom type="mesh" class="collision" pos="-0.0045 -0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="top_head_shell" material="top_head_shell_material"/>
<!-- Part xl330_11 -->
<geom type="mesh" class="visual" pos="0 0 0.0145" quat="0.5 -0.5 -0.5 -0.5" mesh="xl330" material="xl330_material"/>
<!-- Part seeed_bearing__configuration_default_2 -->
<geom type="mesh" class="visual" pos="0.0032 -0.04 -0.018" quat="0.5 -0.5 0.5 0.5" mesh="seeed_bearing__configuration_default" material="seeed_bearing__configuration_default_material"/>
<!-- Part elec_rpi_robot_hat_pcb -->
<geom type="mesh" class="visual" pos="0.02694 0.0289936 -0.0519" quat="0.707107 0 0 -0.707107" mesh="elec_rpi_robot_hat_pcb" material="elec_rpi_robot_hat_pcb_material"/>
<!-- Part soft_mouth_top -->
<geom type="mesh" class="visual" pos="-0.00420071 1.7776e-08 -0.0180814" quat="0.5 0.5 0.5 0.5" mesh="soft_mouth_top" material="soft_mouth_top_material"/>
<!-- Part noenoeil -->
<geom type="mesh" class="visual" pos="-0.0045 -9.13778e-05 -0.0178" quat="0.5 0.5 0.5 0.5" mesh="noenoeil" material="noenoeil_material"/>
<!-- Part jaw -->
<geom type="mesh" class="visual" pos="-0.0045 0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="jaw" material="jaw_material"/>
<geom type="mesh" class="collision" pos="-0.0045 0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="jaw" material="jaw_material"/>
<!-- Part bottom_head_shell -->
<geom type="mesh" class="visual" pos="-0.0043 -0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="bottom_head_shell" material="bottom_head_shell_material"/>
<geom type="mesh" class="collision" pos="-0.0043 -0 -0.018" quat="0.5 0.5 0.5 0.5" mesh="bottom_head_shell" material="bottom_head_shell_material"/>
<!-- Part m12_lens_holder -->
<geom type="mesh" class="visual" pos="0.0155 -9.13778e-05 -0.05558" quat="0.5 -0.5 0.5 -0.5" mesh="m12_lens_holder" material="m12_lens_holder_material"/>
<!-- Part pcb__raspberry_pi_zero_2_w -->
<geom type="mesh" class="visual" pos="0.015435 -1.13778e-05 -0.06001" quat="0.5 -0.5 -0.5 0.5" mesh="pcb__raspberry_pi_zero_2_w" material="pcb__raspberry_pi_zero_2_w_material"/>
<!-- Part speaker -->
<geom type="mesh" class="visual" pos="0.01 -0.016786 0.0260226" quat="0.5 0.5 0.5 0.5" mesh="speaker" material="speaker_material"/>
<!-- Frame head_camera -->
<site group="3" name="head_camera" pos="0.0155 -9.13778e-05 -0.0733" quat="0.707107 0 0.707107 -0"/>
<camera name="head_camera" pos="0.0155 -9.13778e-05 -0.0733" quat="0 0 -1 0"/>
<!-- Frame tof -->
<site group="3" name="tof" pos="0.0135 0.0224086 -0.0733" quat="0.707107 0 0.707107 -0"/>
<!-- Frame head_imu -->
<site group="3" name="head_imu" pos="0.0152323 0.000111069 -0.05106" quat="1 0 0 -0"/>
<!-- Frame mouth_tip -->
<site group="3" name="mouth_tip" pos="-0.00809334 -0 -0.0777383" quat="0.704015 0 0.710185 -0"/>
</body>
</body>
</body>
</body>
<!-- Link bearing_roll -->
<body name="bearing_roll" pos="0.006 -0.0175 -0.005" quat="0 0.707107 0.707107 0">
<!-- Joint from trunk_base to bearing_roll -->
<joint axis="0 0 1" name="right_hip_yaw" type="hinge" range="-0.5235987755982988 0.4363323129985824" class="chosen_actuator"/>
<inertial pos="-8.8e-11 0.00099414 0.0168917" mass="0.0230406" fullinertia="4.1964e-06 3.41752e-06 2.3265e-06 -0 -0 -5.0881e-08"/>
<!-- Part yaw2roll_2 -->
<geom type="mesh" class="visual" pos="-0.0175 -0.002 0.0125" quat="0 1 0 0" mesh="yaw2roll" material="yaw2roll_material"/>
<!-- Part xl330_12 -->
<geom type="mesh" class="visual" pos="-0 0 0.0125" quat="0 -0.707107 0.707107 -0" mesh="xl330" material="xl330_material"/>
<!-- Part bearing_roll_2 -->
<geom type="mesh" class="visual" pos="-0.0175 -0.002 0.0125" quat="0 -1 -0 -0" mesh="bearing_roll" material="bearing_roll_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_9 -->
<geom type="mesh" class="visual" pos="-0 0.0165 0.0125" quat="0.5 0.5 0.5 -0.5" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Link hip_l_2 -->
<body name="hip_l_2" pos="-0 0.0165 0.0125" quat="0 -0 0.707107 0.707107">
<!-- Joint from bearing_roll to hip_l_2 -->
<joint axis="0 0 1" name="right_hip_roll" type="hinge" range="-0.3839724354387525 0.3839724354387525" class="chosen_actuator"/>
<inertial pos="0.014815 1.6212e-08 -0.00829992" mass="0.00618934" fullinertia="8.60626e-07 1.15753e-06 6.51588e-07 1e-12 3.89882e-07 -1e-12"/>
<!-- Part hip_l_2 -->
<geom type="mesh" class="visual" pos="-0.0175 0 -0.0185" quat="0.707107 -0.707107 -0 -0" mesh="hip_l" material="hip_l_material"/>
<geom type="mesh" class="collision" pos="-0.0175 0 -0.0185" quat="0.707107 -0.707107 -0 -0" mesh="hip_l" material="hip_l_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_10 -->
<geom type="mesh" class="visual" pos="0.025 0 -0.0185" quat="0.5 0.5 -0.5 -0.5" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Link upper_leg_right -->
<body name="upper_leg_right" pos="0.025 0 -0.0185" quat="0.5 -0.5 0.5 -0.5">
<!-- Joint from hip_l_2 to upper_leg_right -->
<joint axis="0 0 1" name="right_hip_pitch" type="hinge" range="-1.5707963267949268 1.5707963267948664" class="chosen_actuator"/>
<inertial pos="-0.006766 0.0228838 0.0134531" mass="0.0482067" fullinertia="1.68753e-05 1.03691e-05 1.98269e-05 4.41852e-06 -2.27982e-07 3.89298e-07"/>
<!-- Part xl330_13 -->
<geom type="mesh" class="visual" pos="-0.022 0.0357771 0.0125" quat="0.707107 -0 -0.707107 -0" mesh="xl330" material="xl330_material"/>
<!-- Part seeed_bearing__configuration__22x16x4_11 -->
<geom type="mesh" class="visual" pos="-0.022 0.0357771 0" quat="0 1 -0 -0" mesh="seeed_bearing__configuration__22x16x4" material="seeed_bearing__configuration__22x16x4_material"/>
<!-- Part upper_leg_rigidity_plate_2 -->
<geom type="mesh" class="visual" pos="0 0 0.0435" quat="0.5 -0.5 0.5 0.5" mesh="upper_leg_rigidity_plate" material="upper_leg_rigidity_plate_material"/>
<!-- Part upper_leg_right -->
<geom type="mesh" class="visual" pos="-0 0 -0.0425" quat="0.5 -0.5 0.5 0.5" mesh="upper_leg_right" material="upper_leg_right_material"/>
<!-- Part xl330_14 -->
<geom type="mesh" class="visual" pos="0 0 0.0125" quat="0.5 0.5 -0.5 0.5" mesh="xl330" material="xl330_material"/>
<!-- Link leg_2 -->
<body name="leg_2" pos="-0.022 0.0357771 -0.004" quat="0 1 -0 -0">
<!-- Joint from upper_leg_right to leg_2 -->
<joint axis="0 0 1" name="right_knee" type="hinge" range="-1.570796326794932 1.570796326794861" class="chosen_actuator"/>
<inertial pos="-0.0318937 -1.52e-10 -0.00953505" mass="0.0215844" fullinertia="2.15507e-06 5.25056e-06 4.33925e-06 1e-12 -7.65005e-07 0"/>
<!-- Part xl330_15 -->
<geom type="mesh" class="visual" pos="-0.042 0 -0.0115" quat="0.707107 -0 -0.707107 -0" mesh="xl330" material="xl330_material"/>
<!-- Part leg_2 -->
<geom type="mesh" class="visual" pos="-0.0357771 -0.022 0.0385" quat="0.707107 0 0.707107 -0" mesh="leg" material="leg_material"/>
<geom type="mesh" class="collision" pos="-0.0357771 -0.022 0.0385" quat="0.707107 0 0.707107 -0" mesh="leg" material="leg_material"/>
<!-- Link ankle_right -->
<body name="ankle_right" pos="-0.042 0 -0.026" quat="0 -0.707107 -0.707107 0">
<!-- Joint from leg_2 to ankle_right -->
<joint axis="0 0 1" name="right_ankle" type="hinge" range="-1.5707963267949054 1.5707963267948877" class="chosen_actuator"/>
<inertial pos="0.00615539 -0.0137482 -0.0156566" mass="0.0300251" fullinertia="5.91534e-06 1.11534e-05 7.74016e-06 2.04877e-07 -8.247e-08 5.7017e-08"/>
<!-- Part ankle_right -->
<geom type="mesh" class="visual" pos="0.022 0.00622291 -0.0647" quat="0.5 -0.5 0.5 0.5" mesh="ankle_right" material="ankle_right_material"/>
<!-- Part sole_right -->
<geom type="mesh" class="visual" pos="0.022 0.00622291 -0.0647" quat="0.5 -0.5 0.5 0.5" mesh="sole_right" material="sole_right_material"/>
<geom type="mesh" name="right_foot_collision" class="collision" pos="0.022 0.00622291 -0.0647" quat="0.5 -0.5 0.5 0.5" mesh="sole_right" material="sole_right_material"/>
<!-- Part seeed_bearing__configuration_default_3 -->
<geom type="mesh" class="visual" pos="-0 0 -0.0292" quat="0 1 -0 -0" mesh="seeed_bearing__configuration_default" material="seeed_bearing__configuration_default_material"/>
<!-- Part foot_right -->
<geom type="mesh" class="visual" pos="0.022 0.00622291 -0.0647" quat="0.5 -0.5 0.5 0.5" mesh="foot_right" material="foot_right_material"/>
<!-- Frame right_foot -->
<site group="3" name="right_foot" pos="0 -0.0238146 -0.0140852" quat="0.707107 -0.707107 0 0"/>
</body>
</body>
</body>
</body>
</body>
</body>
</worldbody>
<asset>
<mesh file="seeed_bearing__configuration__22x16x4.stl"/>
<mesh file="sole_left.stl"/>
<mesh file="yaw2roll.stl"/>
<mesh file="sole_right.stl"/>
<mesh file="leg.stl"/>
<mesh file="xl330.stl"/>
<mesh file="noenoeil.stl"/>
<mesh file="pcb__raspberry_pi_zero_2_w.stl"/>
<mesh file="neck_pitch.stl"/>
<mesh file="foot_left.stl"/>
<mesh file="ankle_left.stl"/>
<mesh file="yaw_roll_motion.stl"/>
<mesh file="left_shell.stl"/>
<mesh file="m12_lens_holder.stl"/>
<mesh file="jaw_soft.stl"/>
<mesh file="elec_rpi_robot_hat_pcb.stl"/>
<mesh file="top_head_shell.stl"/>
<mesh file="lens.stl"/>
<mesh file="bottom_head_shell.stl"/>
<mesh file="motor_support.stl"/>
<mesh file="neck.stl"/>
<mesh file="np_f970.stl"/>
<mesh file="upper_leg_rigidity_plate.stl"/>
<mesh file="seeed_bearing__configuration_default.stl"/>
<mesh file="soft_mouth_top.stl"/>
<mesh file="trunk_base.stl"/>
<mesh file="hip_l.stl"/>
<mesh file="bearing_roll.stl"/>
<mesh file="banana_pcb_locker.stl"/>
<mesh file="speaker.stl"/>
<mesh file="ankle_right.stl"/>
<mesh file="upper_leg_right.stl"/>
<mesh file="right_shell.stl"/>
<mesh file="face_part.stl"/>
<mesh file="foot_right.stl"/>
<mesh file="power_support.stl"/>
<mesh file="upper_leg_left.stl"/>
<mesh file="jaw.stl"/>
<material name="seeed_bearing__configuration__22x16x4_material" rgba="0.713725 0.760784 0.8 1"/>
<material name="right_shell_material" rgba="0.8 0.8 0.8 1"/>
<material name="banana_pcb_locker_material" rgba="0.647059 0.647059 0.647059 1"/>
<material name="trunk_base_material" rgba="0.34902 0.376471 0.4 1"/>
<material name="xl330_material" rgba="0.286275 0.286275 0.286275 1"/>
<material name="power_support_material" rgba="0.901961 0.901961 0.901961 1"/>
<material name="np_f970_material" rgba="0.901961 0.901961 0.901961 1"/>
<material name="left_shell_material" rgba="0.8 0.8 0.8 1"/>
<material name="yaw2roll_material" rgba="0.647059 0.647059 0.647059 1"/>
<material name="bearing_roll_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="hip_l_material" rgba="0.901961 0.901961 0.901961 1"/>
<material name="upper_leg_left_material" rgba="0.866667 0.866667 0.866667 1"/>
<material name="upper_leg_rigidity_plate_material" rgba="0.537255 0.854902 0.827451 1"/>
<material name="leg_material" rgba="0.811765 0.858824 0.898039 1"/>
<material name="sole_left_material" rgba="0.537255 0.854902 0.827451 1"/>
<material name="foot_left_material" rgba="0.980392 0.713725 0.00392157 1"/>
<material name="seeed_bearing__configuration_default_material" rgba="0.713725 0.760784 0.8 1"/>
<material name="ankle_left_material" rgba="0.980392 0.713725 0.00392157 1"/>
<material name="neck_material" rgba="0.8 0.8 0.8 1"/>
<material name="neck_pitch_material" rgba="0.34902 0.376471 0.4 1"/>
<material name="yaw_roll_motion_material" rgba="0.768627 0.886275 0.952941 1"/>
<material name="lens_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="face_part_material" rgba="0.34902 0.376471 0.4 1"/>
<material name="jaw_soft_material" rgba="0.85098 0.756863 0.866667 1"/>
<material name="motor_support_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="top_head_shell_material" rgba="0.901961 0.901961 0.901961 1"/>
<material name="elec_rpi_robot_hat_pcb_material" rgba="0.313725 0.486275 0.411765 1"/>
<material name="soft_mouth_top_material" rgba="0.85098 0.756863 0.866667 1"/>
<material name="noenoeil_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="jaw_material" rgba="0.980392 0.713725 0.00392157 1"/>
<material name="bottom_head_shell_material" rgba="0.980392 0.713725 0.00392157 1"/>
<material name="m12_lens_holder_material" rgba="0.262745 0.282353 0.301961 1"/>
<material name="pcb__raspberry_pi_zero_2_w_material" rgba="0.498039 0.498039 0.498039 1"/>
<material name="speaker_material" rgba="0.294118 0.290196 0.290196 1"/>
<material name="upper_leg_right_material" rgba="0.866667 0.866667 0.866667 1"/>
<material name="ankle_right_material" rgba="0.980392 0.713725 0.00392157 1"/>
<material name="sole_right_material" rgba="0.537255 0.854902 0.827451 1"/>
<material name="foot_right_material" rgba="0.980392 0.713725 0.00392157 1"/>
</asset>
<actuator>
<position class="chosen_actuator" name="left_hip_yaw" joint="left_hip_yaw"/>
<position class="chosen_actuator" name="left_hip_roll" joint="left_hip_roll"/>
<position class="chosen_actuator" name="left_hip_pitch" joint="left_hip_pitch"/>
<position class="chosen_actuator" name="left_knee" joint="left_knee"/>
<position class="chosen_actuator" name="left_ankle" joint="left_ankle"/>
<position class="chosen_actuator" name="neck_pitch" joint="neck_pitch"/>
<position class="chosen_actuator" name="head_pitch" joint="head_pitch"/>
<position class="chosen_actuator" name="head_yaw" joint="head_yaw"/>
<position class="chosen_actuator" name="head_roll" joint="head_roll"/>
<position class="chosen_actuator" name="right_hip_yaw" joint="right_hip_yaw"/>
<position class="chosen_actuator" name="right_hip_roll" joint="right_hip_roll"/>
<position class="chosen_actuator" name="right_hip_pitch" joint="right_hip_pitch"/>
<position class="chosen_actuator" name="right_knee" joint="right_knee"/>
<position class="chosen_actuator" name="right_ankle" joint="right_ankle"/>
</actuator>
<equality/>
</mujoco>
-28
View File
@@ -1,28 +0,0 @@
body {
padding: 2rem;
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
}
h1 {
font-size: 16px;
margin-top: 0;
}
p {
color: rgb(107, 114, 128);
font-size: 15px;
margin-bottom: 10px;
margin-top: 5px;
}
.card {
max-width: 620px;
margin: 0 auto;
padding: 16px;
border: 1px solid lightgray;
border-radius: 16px;
}
.card p:last-child {
margin-bottom: 0;
}
+212
View File
@@ -0,0 +1,212 @@
// Colour variants of the real Microduck robots (see the reference photo of
// the four printed units). Each variant fills the same semantic slots; the
// mesh-filename -> slot mapping lives in meshMaterialsFor(). All colours are
// linear-space RGB and slightly oversaturated: the renderer tone-maps with
// ACESFilmicToneMapping under warm key/rim lights, which desaturates and
// shifts hues toward gold, so the base colours lean past the target to land
// right on screen.
import * as THREE from "three";
// ── Shared slot specs (identical on all four robots) ───────────────────
// sRGB targets from the reference photo, converted to linear with a
// slight saturation boost (x1.12) so ACES lands on the clean tint.
const AMBER_YELLOW = { color: [1.0, 0.413, 0.007], roughness: 0.4, metalness: 0.0 }; // #ffb52e
const BRIGHT_ORANGE = { color: [1.0, 0.144, 0.008], roughness: 0.45, metalness: 0.0 }; // #ff7a2f
const AMBER = { color: [0.847, 0.339, 0.022], roughness: 0.45, metalness: 0.0 }; // #eda63e
const CLEAN_YELLOW = { color: [1.0, 0.608, 0.021], roughness: 0.4, metalness: 0.0 }; // #ffd23f
const CREAM = { color: [0.888, 0.86, 0.798], roughness: 0.35, metalness: 0.0 }; // #f2efe8
const DARK = { color: [0.012, 0.012, 0.014], roughness: 0.55, metalness: 0.3 }; // #1d1d1f
const GRAY = { color: [0.256, 0.256, 0.279], roughness: 0.5, metalness: 0.35 }; // #8b8b90
// Camera-lens eye: very dark blue-black, glossy like coated glass.
const LENS = { color: [0.01, 0.012, 0.02], roughness: 0.05, metalness: 0.0 };
// Per-variant colours.
const WARM_GRAY = { color: [0.328, 0.312, 0.283], roughness: 0.35, metalness: 0.0 }; // #9b9892
const AMBER_ORANGE = { color: [0.815, 0.321, 0.019], roughness: 0.5, metalness: 0.0 }; // #e9a23b
const CHARCOAL = { color: [0.028, 0.028, 0.033], roughness: 0.5, metalness: 0.0 }; // #2f2f33
const CHARCOAL_FACE = { color: [0.044, 0.044, 0.051], roughness: 0.5, metalness: 0.0 }; // #3c3c40
const CHARCOAL_BODY = { color: [0.017, 0.017, 0.019], roughness: 0.5, metalness: 0.0 }; // #232326
const LIGHT_WARM_GRAY = { color: [0.485, 0.459, 0.416], roughness: 0.35, metalness: 0.0 };// #b9b5ae
const PURPLE_RING = { color: [0.114, 0.058, 0.578], roughness: 0.4, metalness: 0.0 }; // #6a52c8
const PURPLE_FEET = { color: [0.164, 0.085, 0.584], roughness: 0.45, metalness: 0.0 }; // #7a5fc9
const PALE_BLUE = { color: [0.441, 0.613, 0.723], roughness: 0.35, metalness: 0.0 }; // #b6cfdd
const MEDIUM_BLUE = { color: [0.13, 0.321, 0.552], roughness: 0.35, metalness: 0.0 }; // #6f9ec4
const BLUE_GRAY = { color: [0.183, 0.379, 0.565], roughness: 0.35, metalness: 0.0 }; // #7fa9c6
const FEET_YELLOW = { color: [0.784, 0.455, 0.023], roughness: 0.5, metalness: 0.0 }; // #e5b93e
// Slots (validated against the four-robot reference photo): headDome
// (top shell), facePlate (around the eye), trim (band under the shell +
// upper beak base), beakUpper (mouth-roof plate), beakLower (jaw plates),
// eyeRing, lens, bodyShell (trunk shells), legShells (upper-leg shells),
// feet (foot blocks + ankle brackets), soles, mechDark, mechGray.
export const VARIANTS = {
// Front-center robot: warm gray head, cream body, amber eye, orange
// trim/upper beak over a lighter amber lower beak, amber-orange feet.
classic: {
headDome: WARM_GRAY,
facePlate: WARM_GRAY,
trim: BRIGHT_ORANGE,
beakUpper: BRIGHT_ORANGE,
beakLower: AMBER,
eyeRing: AMBER_YELLOW,
lens: LENS,
bodyShell: CREAM,
legShells: CREAM,
feet: AMBER_ORANGE,
soles: AMBER_ORANGE,
mechDark: DARK,
mechGray: GRAY,
},
// Front-left robot: charcoal shells, slightly lighter face plate,
// amber eye, orange/amber beak, yellow soles peeking under black feet.
charcoal: {
headDome: CHARCOAL,
facePlate: CHARCOAL_FACE,
trim: BRIGHT_ORANGE,
beakUpper: BRIGHT_ORANGE,
beakLower: AMBER,
eyeRing: AMBER_YELLOW,
lens: LENS,
bodyShell: CHARCOAL_BODY,
legShells: CHARCOAL_BODY,
feet: CHARCOAL_BODY,
soles: CLEAN_YELLOW,
mechDark: DARK,
mechGray: GRAY,
},
// Back-center robot: light warm gray head, purple eye, YELLOW trim and
// beak (both plates), cream body, purple feet.
purple: {
headDome: LIGHT_WARM_GRAY,
facePlate: LIGHT_WARM_GRAY,
trim: CLEAN_YELLOW,
beakUpper: CLEAN_YELLOW,
beakLower: CLEAN_YELLOW,
eyeRing: PURPLE_RING,
lens: LENS,
bodyShell: CREAM,
legShells: CREAM,
feet: PURPLE_FEET,
soles: PURPLE_FEET,
mechDark: DARK,
mechGray: GRAY,
},
// Right robot: pale blue dome over a medium blue face plate (two
// different blues), amber eye, orange/amber beak, blue-gray body,
// clean yellow feet.
blue: {
headDome: PALE_BLUE,
facePlate: MEDIUM_BLUE,
trim: BRIGHT_ORANGE,
beakUpper: BRIGHT_ORANGE,
beakLower: AMBER,
eyeRing: AMBER_YELLOW,
lens: LENS,
bodyShell: BLUE_GRAY,
legShells: BLUE_GRAY,
feet: FEET_YELLOW,
soles: FEET_YELLOW,
mechDark: DARK,
mechGray: GRAY,
},
};
export const VARIANT_NAMES = Object.keys(VARIANTS);
export const DEFAULT_VARIANT = "classic";
export const randomVariantName = () =>
VARIANT_NAMES[Math.floor(Math.random() * VARIANT_NAMES.length)];
// Mesh filename -> material spec for one variant (mjlab model meshes).
// Anything not listed is small mechanical hardware and falls back to
// mechGray. Verified visually against the four-robot reference photo.
export function meshMaterialsFor(v) {
return {
// Head: dome, band under it, face plate around the eye.
"top_head_shell.stl": v.headDome,
"bottom_head_shell.stl": v.trim,
"face_part.stl": v.facePlate,
// The eye: printed ring + camera lens behind it.
"noenoeil.stl": v.eyeRing,
"lens.stl": v.lens,
"m12_lens_holder.stl": v.mechDark,
// Beak: mouth-roof plate on top, rigid jaw + soft pad below.
"soft_mouth_top.stl": v.beakUpper,
"jaw.stl": v.beakLower,
"jaw_soft.stl": v.beakLower,
// Body shells
"trunk_base.stl": v.bodyShell,
"left_shell.stl": v.bodyShell,
"right_shell.stl": v.bodyShell,
"upper_leg_left.stl": v.legShells,
"upper_leg_right.stl": v.legShells,
"hip_l.stl": v.trim,
// Feet: foot block + ankle bracket, soft sole pad below.
"foot_left.stl": v.feet,
"foot_right.stl": v.feet,
"ankle_left.stl": v.feet,
"ankle_right.stl": v.feet,
"sole_left.stl": v.soles,
"sole_right.stl": v.soles,
// Dark mechanics
"xl330.stl": v.mechDark,
"neck.stl": v.mechDark,
"np_f970.stl": v.mechDark,
"pcb__raspberry_pi_zero_2_w.stl": v.mechDark,
"elec_rpi_robot_hat_pcb.stl": v.mechDark,
"banana_pcb_locker.stl": v.mechDark,
"speaker.stl": v.mechDark,
// Gray mechanics
"upper_leg_rigidity_plate.stl": v.mechGray,
"leg.stl": v.mechGray,
"yaw2roll.stl": v.mechGray,
"yaw_roll_motion.stl": v.mechGray,
"neck_pitch.stl": v.mechGray,
"bearing_roll.stl": v.mechGray,
"motor_support.stl": v.mechGray,
"power_support.stl": v.mechGray,
"seeed_bearing__configuration__22x16x4.stl": v.mechGray,
"seeed_bearing__configuration_default.stl": v.mechGray,
};
}
// buildRig materialForMesh hook for one variant.
export const materialHookFor = (v) => {
const map = meshMaterialsFor(v);
return (mesh) => map[mesh] ?? v.mechGray;
};
// ── Live re-skin ────────────────────────────────────────────────────────
// Swap materials on an already-built rig without reloading any STL.
// Meshes are identified via userData.meshName (set by duck.js buildRig and
// preserved by cloneRig). Materials are cached per resolved spec so clones
// and repeated switches share GPU material instances.
const matCache = new Map();
function matFor(spec) {
const key = `${spec.color.join(",")}|${spec.roughness ?? 0.5}|${spec.metalness ?? 0}`;
let m = matCache.get(key);
if (!m) {
m = new THREE.MeshStandardMaterial({
color: new THREE.Color(...spec.color),
roughness: spec.roughness ?? 0.5,
metalness: spec.metalness ?? 0.0,
});
matCache.set(key, m);
}
return m;
}
export function applyVariant(rig, variant) {
const v = typeof variant === "string" ? VARIANTS[variant] : variant;
const map = meshMaterialsFor(v);
rig.root.traverse((o) => {
if (!o.isMesh || !o.userData.meshName) return;
o.material = matFor(map[o.userData.meshName] ?? v.mechGray);
});
}
// Linear-space spec colour -> sRGB CSS hex, for swatch UI elements.
export function specToHex(spec) {
return `#${new THREE.Color(...spec.color).getHexString()}`;
}