@hackbuild/humanoid 0.2.2 → 0.4.0

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Run a physics humanoid in the page: MuJoCo simulates a robot from its MJCF files, NVIDIA's GEAR-SONIC policy balances the Unitree G1, and you pose it, shove it and draw it.
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@hackbuild/humanoid)](https://www.npmjs.com/package/@hackbuild/humanoid) [![licence MIT](https://img.shields.io/badge/licence-MIT-blue)](../../LICENSE) ![gzip 6.6 kB measured](https://img.shields.io/badge/gzip-6.6%20kB-blue) ![types included](https://img.shields.io/badge/types-included-blue)
5
+ [![npm](https://img.shields.io/npm/v/@hackbuild/humanoid)](https://www.npmjs.com/package/@hackbuild/humanoid) [![licence MIT](https://img.shields.io/badge/licence-MIT-blue)](../../LICENSE) ![gzip 7.5 kB measured](https://img.shields.io/badge/gzip-7.5%20kB-blue) ![types included](https://img.shields.io/badge/types-included-blue)
6
6
 
7
7
  ## What it does
8
8
 
@@ -71,10 +71,31 @@ An MJCF names other files relative to its compiler's directories: `meshdir` or `
71
71
 
72
72
  GEAR-SONIC turns a reference motion into a token (the encoder) and the token plus ten ticks of the robot's state into 29 joint actions (the decoder), 50 times a second; `SonicDriver` turns actions into joint targets (default angle plus action times the joint's action scale) and a PD loop into motor torques at every timestep. It needs the deploy model, `G1_SONIC`, whose joints are on motors; the menagerie G1's position actuators do not take it. `reference` is the pose it tracks, absolute angles in the model's joint order: the standing angles by default, or a crouch, or an arm raised. The code is written from NVIDIA's published deployment description and parameters; the details it leaves open (joint positions relative to the defaults, the reference absolute, histories oldest first, rotations read row by row, the anchor as the base's tilt against an upright reference) were settled by trial on the deploy model, where only that combination stands.
73
73
 
74
+ A reference can move: `play(motion)` takes a function from seconds to absolute angles, and each tick the encoder reads its next second as ten frames 0.1 s apart with their velocities; setting `reference` or calling `stop()` ends it, holding where it got to. `squat()` and `wave()` are two such motions for the G1, and `referenceFrames` shows what the encoder reads. Fed this way the reference arrives with no lag. A squat tracks closely and survives a shove; a wave's elbow covers most of its range, and a raised arm sags, since the arm joints are soft. The numbers are under What is verified.
75
+
74
76
  ### the robot
75
77
 
76
78
  `Humanoid.open` compiles the files in MuJoCo's virtual file system. `targets` is the actuators' control array, a live view: for a position actuator it is the joint's target angle. `moveTo` eases the targets it names in over simulated time and leaves the others alone; a sudden jump can topple a robot that a ramp of half a second leaves standing. After writing `qpos` by hand, call `forward()` before reading poses; after `dispose()` the data's arrays must not be read (`disposed` says so). `step(seconds)` runs whole timesteps and carries the remainder, at most 0.1 s a call, so a slow frame does not run away. Poses come back in MuJoCo's frame: z up, meters, quaternions w x y z.
77
79
 
80
+ ### a body that follows
81
+
82
+ `BodyFollow` in `/three` drives a humanoid body (a VRM or a GLB person with VRM 1.0 bone names, as `@hackbuild/avatar` loads one) from the robot. Once, it turns the body's limbs to the robot's zero pose, worked out from the model's body offsets without touching the running robot: a T pose's arms come down to the sides and the forearms point forward, as the G1's do at zero. Then each frame it gives every mapped bone the turn its robot body has made since that pose, and moves the hips with the pelvis, scaled to the body's hip height (`travel: false` keeps them in place). `G1_FOLLOW` maps the G1's bodies to the bones; another robot passes its own `map`. Bones the body lacks, bodies the robot lacks and segments that could not be posed are listed in `missing` and left as they are; `reset()` puts the body back as it was.
83
+
84
+ ```ts
85
+ import { load } from "@hackbuild/avatar";
86
+ import { loadAvatar } from "@hackbuild/avatar/three";
87
+ import { BodyFollow } from "@hackbuild/humanoid/three";
88
+
89
+ await load(); // the bone mapper's wasm
90
+ const person = await loadAvatar("person.glb");
91
+ person.root.position.x = 0.9; // beside the robot
92
+ scene.add(person.root);
93
+ const follow = new BodyFollow(robot, person);
94
+ // each frame, after the robot steps
95
+ follow.update();
96
+ person.update(dt);
97
+ ```
98
+
78
99
  ## API overview
79
100
 
80
101
  | export | what it does |
@@ -86,8 +107,13 @@ GEAR-SONIC turns a reference motion into a token (the encoder) and the token plu
86
107
  | [`Humanoid`](../../docs/api/humanoid/index.md#humanoid) | step, reset, targets, moveTo, hold, push, poses, dispose |
87
108
  | [`G1`](../../docs/api/humanoid/index.md#g1) | the Unitree G1 from MuJoCo Menagerie: url, joints, keyframe, licence |
88
109
  | [`HumanoidView`](../../docs/api/humanoid/three.md#humanoidview) | the robot in three.js, from `@hackbuild/humanoid/three` |
110
+ | [`BodyFollow`](../../docs/api/humanoid/three.md#bodyfollow) | a humanoid body that follows the robot, from `@hackbuild/humanoid/three` |
111
+ | [`G1_FOLLOW`](../../docs/api/humanoid/index.md#g1_follow) | the G1's bodies mapped to humanoid bones, and the segments posed to its zero pose |
112
+ | [`restPoses`](../../docs/api/humanoid/index.md#restposes) | every body's world pose at qpos0, from the model alone |
89
113
  | [`Sonic`](../../docs/api/humanoid/sonic.md#sonic) | load the GEAR-SONIC policy, from `@hackbuild/humanoid/sonic` |
90
- | [`SonicDriver`](../../docs/api/humanoid/sonic.md#sonicdriver) | run it on a G1: advance, reference, reset |
114
+ | [`SonicDriver`](../../docs/api/humanoid/sonic.md#sonicdriver) | run it on a G1: advance, reference, play, stop, reset |
115
+ | [`squat`](../../docs/api/humanoid/sonic.md#squat), [`wave`](../../docs/api/humanoid/sonic.md#wave) | moving references for the G1, from `@hackbuild/humanoid/sonic` |
116
+ | [`referenceFrames`](../../docs/api/humanoid/sonic.md#referenceframes) | the ten frames the encoder reads from a motion at a time |
91
117
  | [`G1_SONIC`](../../docs/api/humanoid/sonic.md#g1_sonic) | the G1 deploy model the policy runs on: url, asset host, licence |
92
118
  | [`SONIC_JOINTS`](../../docs/api/humanoid/sonic.md#sonic_joints) | standing angles, gains, torque limits, action scale and policy order per joint |
93
119
  | [`HumanoidError`](../../docs/api/humanoid/index.md#humanoiderror) | a model or runtime this package cannot open, with the reason |
@@ -130,19 +156,23 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
130
156
 
131
157
  | check | result |
132
158
  |---|---|
133
- | `npx vitest run packages/humanoid` | 18 of 18 tests pass: the 7 below; unnamed parts named by kind and index, a tendon actuator kept out of the joints, an ease leaving other targets and a controller's output alone, a NaN frame, quoted and commented references and cube faces, a mesh folder reached with `..`, a view after dispose; and for the policy the gains and action scale from motor armature, the policy joint order, gravity in the body frame, the anchor ignoring heading, the encoder and decoder layouts, ten ticks oldest first, a driver on a 29 joint model with a stand in runtime, the refusal of a robot without the G1's joints or with them on servos, and a reset or dispose landing while a tick awaits inference (counted) |
159
+ | `npx vitest run packages/humanoid` | 32 of 32 tests pass: squat and wave start at the standing angles, move only their joints and stay continuous; reference frames 0.1 s apart with velocities, one sided at 0; a playing motion feeding the encoder its next second, advancing a tick a tick, held by stop and ended by a new reference; play again, stop and reset while a tick awaits inference; a bad period or rate refused, the swing inside the elbow's range; the 7 below; rest poses equal MuJoCo's at qpos0 through turned body frames; a T pose body posed to the robot's zero pose, then every follower segment pointing as the robot's does after hip, knee, shoulder, elbow, wrist, ankle and waist turns and a moved, turned pelvis, the hips, spine, a foot and a hand turned by their robot bodies' turns, the hips travelling at the body's scale, travel off, reset, missing bones and bodies listed, nothing after dispose; unnamed parts named by kind and index, a tendon actuator kept out of the joints, an ease leaving other targets and a controller's output alone, a NaN frame, quoted and commented references and cube faces, a mesh folder reached with `..`, a view after dispose; and for the policy the gains and action scale from motor armature, the policy joint order, gravity in the body frame, the anchor ignoring heading, the encoder and decoder layouts, ten ticks oldest first, a driver on a 29 joint model with a stand in runtime, the refusal of a robot without the G1's joints or with them on servos, and a reset or dispose landing while a tick awaits inference (counted) |
134
160
  | the 7 runtime and view tests | 7 of 7 tests pass on MuJoCo 4.0.1 in node: references and compiler directories, a dropped folder with an include and a missing mesh, compiling through the virtual files, names, uneven frames stepped at the timestep, a fall under gravity, a keyframe's pose and controls, an actuator reaching its target, an eased move, hold, a push, the compile error naming missing files, the three.js view's meshes and their motion (counted) |
135
161
  | the G1 from MuJoCo Menagerie in headless Chrome on an Apple M1 | MuJoCo loads in 206 ms, the G1's 36 files (19.7 MB) arrive in 886 ms with none missing, it compiles with 29 actuated joints and draws 35 meshes; on its stand keyframe the pelvis holds 0.792 m for 5 s; 0.084 ms per step (measured) |
136
162
  | the demo page's own check, headless, MuJoCo from jsDelivr | loads in 362 ms, the G1's files in 528 ms; it stands at 0.792 m and eases into a crouch at 0.671 m at 59.9 frames a second (measured) |
137
163
  | GEAR-SONIC on the deploy G1 in node, MuJoCo 4.0.1 and onnxruntime-web 1.23.2 | of seven guesses at the open layout details only one stands; with the tilt anchor it stands 30 s at 0.766 m within 1.1 degrees, steps 0.5 m to catch a 1.0 m/s shove and catches 1.5 m/s, where the position actuators alone fall at 0.3 m/s; it holds a crouch at 0.680 m and a raised arm; 2.6 to 4.5 ms a tick, 15 s simulated in 4.5 s (measured) |
138
164
  | the demo page's policy check, headless Chrome | MuJoCo in 332 ms, the deploy G1 in 527 ms, the policy in 3,368 ms; it stands at 0.766 m and is at 0.766 m 4 s after a 1 m/s shove, at 59.9 frames a second, 5.7 ms a tick (measured) |
165
+ | `BodyFollow` on both real G1 models in node | after a crouch every follower segment points within 0.00 degrees of the robot's; the G1's thigh and upper arm segments start at the roll joint while their bones copy the yaw link a few centimetres away, so a hip yaw of 0.6 rad leaves the thigh 2.75 degrees off and a shoulder yaw of 1.0 rad the upper arm 1.85 degrees off (measured, research probe and review) |
166
+ | `BodyFollow` with the dog simulator's person on the docs page, headless Chrome | the person stands beside the G1 and crouches, raises an arm, steps after a shove under the policy and falls with it on its actuators (frame strips looked at; the hips drop 0.918 to 0.774 m in the crouch, measured) |
167
+ | moving references on the deploy G1 in node, real weights | ten frames 0.1 s apart reach the robot with no lag, a pose changed each tick 0.08 s late, and spacings from 0.02 to 0.2 s track alike; squat 2.8 degrees mean error over all joints, knee 34 of 36 degrees; an elbow asked for 29 degrees of bend in a raised arm holds about 14; wave elbow 45 to 49 of 69 degrees, hand sway 14 cm; a 1 m/s shove mid squat caught; four ways to fill the frames and four spacings compared (research probes sonic-motion-trial and sonic-motion-run, measured) |
168
+ | squat and wave on the docs page with the policy, headless Chrome | frame strips looked at: the robot squats over 3 s and waves beside its head, and the person follows both |
139
169
  | crouches and shoves on the G1 in node | eased over 0.5 s or more, crouches from hips -0.2 to -0.6 radians all hold (pelvis 0.778 to 0.671 m); the same targets set at once topple it at two depths of five; a 0.3 m/s shove topples it (measured) |
140
170
 
141
171
  ### Not verified by anything
142
172
 
143
- - The policy tracks static poses only: no reference motion, walking command or the 774 MB planner runs, and the low latency and v1.1 variants are untried.
173
+ - Moving references are procedural (squat, wave): no recorded human motion has been converted to the G1's joints, no walking command or the 774 MB planner runs, and the low latency and v1.1 variants are untried.
144
174
  - On its actuators alone (no policy) the robot holds targets but does not balance; a shove topples it.
145
- - No VRM follows the robot yet.
175
+ - A follower copies rotations, so a body with other proportions keeps its own limb lengths: its feet may slide or sink a little against the robot's; no foot contact is enforced. Only the dog simulator's GLB person has been looked at, no VRM.
146
176
  - Robots other than the G1 and the test model are untried, and so are textures in MJCF.
147
177
  - Nobody has watched it at real frame rate in a visible browser; the checks are headless.
148
178
 
@@ -150,8 +180,8 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
150
180
 
151
181
  | file | gzip (measured) | ceiling |
152
182
  |---|---|---|
153
- | `dist/index.js` (main entry, imports external) | 6,576 bytes | 6,904 bytes |
154
- | `dist/humanoid.iife.js` (single file build) | 12,862 bytes | 13,505 bytes |
183
+ | `dist/index.js` (main entry, imports external) | 7,502 bytes | 7,877 bytes |
184
+ | `dist/humanoid.iife.js` (single file build) | 17,011 bytes | 17,861 bytes |
155
185
 
156
186
  Measured 2026-11-30 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
157
187
  tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
@@ -0,0 +1,61 @@
1
+ /**
2
+ * A humanoid body (a VRM, a GLB person, any rig with VRM 1.0 bone names)
3
+ * that follows a robot in MuJoCo. Once, it turns the body's limbs to the
4
+ * robot's zero pose (a T pose's arms come down to the sides, the forearms
5
+ * forward); then each frame it gives every mapped bone the rotation its
6
+ * robot body has made since that pose, and moves the hips with the pelvis,
7
+ * scaled to the body's height. Rotations are worked in the body's root
8
+ * space, so the body may stand anywhere, turned any way.
9
+ */
10
+ import { type Object3D } from "three";
11
+ import { type FollowMap } from "./follow.js";
12
+ import { type Forward } from "./frame.js";
13
+ import type { Humanoid } from "./sim.js";
14
+ /** A body to drive: its root and its bones by VRM 1.0 name, as `@hackbuild/avatar` loads one. */
15
+ export interface FollowBody {
16
+ root: Object3D;
17
+ bones: Partial<Record<string, Object3D>>;
18
+ }
19
+ /** Options for {@link BodyFollow}. */
20
+ export interface BodyFollowOptions {
21
+ /** Robot bodies to humanoid bones. Default {@link G1_FOLLOW}. */
22
+ map?: FollowMap;
23
+ /** The axis the robot faces in its model, as {@link HumanoidView} takes it. Default "x". */
24
+ forward?: Forward;
25
+ /** Move the hips with the robot's root body, scaled to the body's hip height. Default true; false turns the body in place. */
26
+ travel?: boolean;
27
+ }
28
+ /** Drives a humanoid body from a {@link Humanoid}: call `update` after each step. */
29
+ export declare class BodyFollow {
30
+ private sim;
31
+ private body;
32
+ /** Bones of the map the body lacks, robot bodies the robot lacks, and segments that could not be posed for want of either; those are left as they are. */
33
+ readonly missing: string[];
34
+ private entries;
35
+ private saved;
36
+ private turn;
37
+ private turnInv;
38
+ private rootEntry;
39
+ private hipsRest;
40
+ private bodyRest;
41
+ private scale;
42
+ private travel;
43
+ private _q;
44
+ private _r;
45
+ private _p;
46
+ private _root;
47
+ private _v;
48
+ private _w;
49
+ constructor(sim: Humanoid, body: FollowBody, o?: BodyFollowOptions);
50
+ /** Poses the body from the robot's last step; does nothing once the robot is disposed. */
51
+ update(): void;
52
+ /** Puts every bone this follower touched back as it found it. */
53
+ reset(): void;
54
+ private keep;
55
+ /** A node's world rotation in the body's root space. */
56
+ private rootQuat;
57
+ private rootPos;
58
+ /** Gives a node a rotation in root space, through its parent's. */
59
+ private setRootQuat;
60
+ private setRootPos;
61
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * A humanoid body (a VRM, a GLB person, any rig with VRM 1.0 bone names)
3
+ * that follows a robot in MuJoCo. Once, it turns the body's limbs to the
4
+ * robot's zero pose (a T pose's arms come down to the sides, the forearms
5
+ * forward); then each frame it gives every mapped bone the rotation its
6
+ * robot body has made since that pose, and moves the hips with the pelvis,
7
+ * scaled to the body's height. Rotations are worked in the body's root
8
+ * space, so the body may stand anywhere, turned any way.
9
+ */
10
+ import { Quaternion, Vector3 } from "three";
11
+ import { G1_FOLLOW } from "./follow.js";
12
+ import { frameTurn } from "./frame.js";
13
+ import { restPoses } from "./rest.js";
14
+ /** Drives a humanoid body from a {@link Humanoid}: call `update` after each step. */
15
+ export class BodyFollow {
16
+ sim;
17
+ body;
18
+ /** Bones of the map the body lacks, robot bodies the robot lacks, and segments that could not be posed for want of either; those are left as they are. */
19
+ missing = [];
20
+ entries = [];
21
+ saved = new Map();
22
+ turn;
23
+ turnInv;
24
+ rootEntry = null;
25
+ hipsRest = new Vector3();
26
+ bodyRest = new Vector3();
27
+ scale = 1;
28
+ travel;
29
+ // this follower's own scratch
30
+ _q = new Quaternion();
31
+ _r = new Quaternion();
32
+ _p = new Quaternion();
33
+ _root = new Quaternion();
34
+ _v = new Vector3();
35
+ _w = new Vector3();
36
+ constructor(sim, body, o = {}) {
37
+ this.sim = sim;
38
+ this.body = body;
39
+ const map = o.map ?? G1_FOLLOW;
40
+ this.travel = o.travel ?? true;
41
+ this.turn = frameTurn(o.forward);
42
+ this.turnInv = this.turn.clone().invert();
43
+ const rest = restPoses(sim.model);
44
+ const id = (name) => sim.bodies.indexOf(name);
45
+ for (const [bone, link] of Object.entries(map.bones)) {
46
+ const node = body.bones[bone], i = id(link);
47
+ if (!node)
48
+ this.missing.push(bone);
49
+ if (i < 0)
50
+ this.missing.push(link);
51
+ if (!node || i < 0)
52
+ continue;
53
+ const [w, x, y, z] = rest[i].quat;
54
+ this.entries.push({ bone, node, body: i, restInv: new Quaternion(x, y, z, w).invert(), posed: new Quaternion() });
55
+ }
56
+ for (const s of map.segments)
57
+ for (const b of [s.bone, s.child])
58
+ if (body.bones[b])
59
+ this.keep(body.bones[b]);
60
+ for (const e of this.entries)
61
+ this.keep(e.node);
62
+ // pose the limbs to the robot's zero pose, parents first
63
+ body.root.updateMatrixWorld(true);
64
+ for (const s of map.segments) {
65
+ const node = body.bones[s.bone], child = body.bones[s.child], a = id(s.from), b = id(s.to);
66
+ if (!node || !child || a < 0 || b < 0) {
67
+ if (node)
68
+ this.missing.push(`${s.bone} to ${s.child} segment`); // the bone keeps its own rest pose
69
+ continue;
70
+ }
71
+ const pa = rest[a].pos, pb = rest[b].pos;
72
+ const want = this._w.set(pb[0] - pa[0], pb[1] - pa[1], pb[2] - pa[2]).applyQuaternion(this.turn).normalize();
73
+ const have = this.rootPos(child, this._v).sub(this.rootPos(node, new Vector3())).normalize();
74
+ if (have.lengthSq() === 0 || want.lengthSq() === 0)
75
+ continue;
76
+ this.setRootQuat(node, this._q.setFromUnitVectors(have, want).multiply(this.rootQuat(node, this._r)));
77
+ }
78
+ for (const e of this.entries)
79
+ this.rootQuat(e.node, e.posed);
80
+ this.rootEntry = this.entries.find((e) => e.bone === map.root) ?? null;
81
+ if (this.rootEntry) {
82
+ this.rootPos(this.rootEntry.node, this.hipsRest);
83
+ const p = rest[this.rootEntry.body].pos;
84
+ this.bodyRest.set(p[0], p[1], p[2]).applyQuaternion(this.turn);
85
+ this.scale = this.bodyRest.y > 0 ? this.hipsRest.y / this.bodyRest.y : 1;
86
+ }
87
+ }
88
+ /** Poses the body from the robot's last step; does nothing once the robot is disposed. */
89
+ update() {
90
+ if (this.sim.disposed)
91
+ return;
92
+ this.body.root.updateMatrixWorld(true);
93
+ const q = this.sim.data.xquat;
94
+ for (const e of this.entries) {
95
+ const k = e.body * 4;
96
+ // the robot body's turn since qpos0, carried into root space: T q q0^-1 T^-1
97
+ this._q.set(q[k + 1], q[k + 2], q[k + 3], q[k]);
98
+ this._q.premultiply(this.turn).multiply(e.restInv).multiply(this.turnInv);
99
+ this.setRootQuat(e.node, this._q.multiply(e.posed));
100
+ if (e === this.rootEntry && this.travel) {
101
+ const x = this.sim.data.xpos, b = e.body * 3;
102
+ this._v.set(x[b], x[b + 1], x[b + 2]).applyQuaternion(this.turn).sub(this.bodyRest).multiplyScalar(this.scale).add(this.hipsRest);
103
+ this.setRootPos(e.node, this._v);
104
+ }
105
+ }
106
+ }
107
+ /** Puts every bone this follower touched back as it found it. */
108
+ reset() {
109
+ for (const [node, s] of this.saved)
110
+ node.quaternion.copy(s.q), node.position.copy(s.p);
111
+ this.body.root.updateMatrixWorld(true);
112
+ }
113
+ keep(node) {
114
+ if (!this.saved.has(node))
115
+ this.saved.set(node, { q: node.quaternion.clone(), p: node.position.clone() });
116
+ }
117
+ /** A node's world rotation in the body's root space. */
118
+ rootQuat(node, out) {
119
+ return node.getWorldQuaternion(out).premultiply(this.body.root.getWorldQuaternion(this._root).invert());
120
+ }
121
+ rootPos(node, out) {
122
+ return this.body.root.worldToLocal(node.getWorldPosition(out));
123
+ }
124
+ /** Gives a node a rotation in root space, through its parent's. */
125
+ setRootQuat(node, q) {
126
+ const parent = node.parent ? this.rootQuat(node.parent, this._p) : this._p.identity();
127
+ node.quaternion.copy(parent.invert().multiply(q));
128
+ node.updateMatrixWorld(true);
129
+ }
130
+ setRootPos(node, p) {
131
+ const world = this.body.root.localToWorld(this._w.copy(p));
132
+ node.position.copy(node.parent ? node.parent.worldToLocal(world) : world);
133
+ node.updateMatrixWorld(true);
134
+ }
135
+ }
@@ -0,0 +1,24 @@
1
+ /** Robot bodies to humanoid bones (VRM 1.0 names), and the segments posed to the robot's zero pose first. */
2
+ export interface FollowMap {
3
+ /** Humanoid bone to the robot body whose rotation it copies, parents before children. */
4
+ bones: Record<string, string>;
5
+ /** The bone that travels with the robot; it must be in `bones`. */
6
+ root: string;
7
+ /**
8
+ * Bones turned once, before following, so the segment from `bone` to `child` points as the
9
+ * robot's segment from body `from` to body `to` does at qpos0: a T pose's arms come down
10
+ * to a robot's arms at its sides. Parents before children.
11
+ */
12
+ segments: {
13
+ bone: string;
14
+ child: string;
15
+ from: string;
16
+ to: string;
17
+ }[];
18
+ }
19
+ /**
20
+ * The Unitree G1, both models (MuJoCo Menagerie's and the gear-sonic deploy model share
21
+ * these body names). At its zero pose the legs hang straight, the arms hang at the sides and
22
+ * the forearms point forward, elbows at a right angle (measured).
23
+ */
24
+ export declare const G1_FOLLOW: FollowMap;
package/dist/follow.js ADDED
@@ -0,0 +1,32 @@
1
+ // Which robot body turns which humanoid bone, for a body that follows the
2
+ // robot (BodyFollow in ./three). Plain data, so another robot brings its own.
3
+ const side = (s) => {
4
+ const S = s === "left" ? "left" : "right";
5
+ return {
6
+ bones: {
7
+ [`${s}UpperLeg`]: `${S}_hip_yaw_link`,
8
+ [`${s}LowerLeg`]: `${S}_knee_link`,
9
+ [`${s}Foot`]: `${S}_ankle_roll_link`,
10
+ [`${s}UpperArm`]: `${S}_shoulder_yaw_link`,
11
+ [`${s}LowerArm`]: `${S}_elbow_link`,
12
+ [`${s}Hand`]: `${S}_wrist_yaw_link`,
13
+ },
14
+ segments: [
15
+ { bone: `${s}UpperLeg`, child: `${s}LowerLeg`, from: `${S}_hip_roll_link`, to: `${S}_knee_link` },
16
+ { bone: `${s}LowerLeg`, child: `${s}Foot`, from: `${S}_knee_link`, to: `${S}_ankle_pitch_link` },
17
+ { bone: `${s}UpperArm`, child: `${s}LowerArm`, from: `${S}_shoulder_roll_link`, to: `${S}_elbow_link` },
18
+ { bone: `${s}LowerArm`, child: `${s}Hand`, from: `${S}_elbow_link`, to: `${S}_wrist_roll_link` },
19
+ ],
20
+ };
21
+ };
22
+ const L = side("left"), R = side("right");
23
+ /**
24
+ * The Unitree G1, both models (MuJoCo Menagerie's and the gear-sonic deploy model share
25
+ * these body names). At its zero pose the legs hang straight, the arms hang at the sides and
26
+ * the forearms point forward, elbows at a right angle (measured).
27
+ */
28
+ export const G1_FOLLOW = {
29
+ bones: { hips: "pelvis", spine: "torso_link", ...L.bones, ...R.bones },
30
+ root: "hips",
31
+ segments: [...L.segments, ...R.segments],
32
+ };
@@ -0,0 +1,12 @@
1
+ import { Quaternion } from "three";
2
+ /** The axis a robot faces in its model. */
3
+ export type Forward = "x" | "-x" | "y" | "-y";
4
+ /** Turn about +Y that brings each forward axis to +Z, after z up becomes y up. */
5
+ export declare const TURN: {
6
+ readonly x: number;
7
+ readonly "-x": number;
8
+ readonly y: number;
9
+ readonly "-y": 0;
10
+ };
11
+ /** MuJoCo world to humanoid space as one rotation: z up to y up, then the forward axis to +Z. */
12
+ export declare function frameTurn(forward?: Forward): Quaternion;
package/dist/frame.js ADDED
@@ -0,0 +1,10 @@
1
+ // The turn from MuJoCo's frame (z up, the robot facing its forward axis) to
2
+ // the family's humanoid space (y up, facing +Z), shared by the view and the
3
+ // body follower so both put the robot the same way round.
4
+ import { Euler, Quaternion } from "three";
5
+ /** Turn about +Y that brings each forward axis to +Z, after z up becomes y up. */
6
+ export const TURN = { x: -Math.PI / 2, "-x": Math.PI / 2, y: Math.PI, "-y": 0 };
7
+ /** MuJoCo world to humanoid space as one rotation: z up to y up, then the forward axis to +Z. */
8
+ export function frameTurn(forward = "x") {
9
+ return new Quaternion().setFromEuler(new Euler(0, TURN[forward], 0)).multiply(new Quaternion().setFromEuler(new Euler(-Math.PI / 2, 0, 0)));
10
+ }