@hackbuild/humanoid 0.1.0 → 0.2.1
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 +28 -9
- package/dist/files.d.ts +12 -3
- package/dist/files.js +39 -13
- package/dist/humanoid.iife.js +566 -29
- package/dist/runtime.d.ts +10 -0
- package/dist/runtime.js +3 -2
- package/dist/sim.d.ts +13 -2
- package/dist/sim.js +54 -16
- package/dist/single.d.ts +1 -0
- package/dist/single.js +2 -1
- package/dist/sonic.d.ts +178 -0
- package/dist/sonic.js +349 -0
- package/dist/three.d.ts +1 -1
- package/dist/three.js +7 -2
- package/how.ts +1 -0
- package/llms.md +158 -7
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @hackbuild/humanoid
|
|
2
2
|
|
|
3
|
-
Run a physics humanoid in the page: MuJoCo simulates a robot from its MJCF files,
|
|
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
|
-
[](https://www.npmjs.com/package/@hackbuild/humanoid) [](../../LICENSE) ](https://www.npmjs.com/package/@hackbuild/humanoid) [](../../LICENSE)  
|
|
6
6
|
|
|
7
7
|
## What it does
|
|
8
8
|
|
|
@@ -11,6 +11,7 @@ Run a physics humanoid in the page: MuJoCo simulates a robot from its MJCF files
|
|
|
11
11
|
- Steps the robot at the model's own timestep however the page's frames fall, resets it to a keyframe, writes joint targets to its position actuators, holds its current pose, shoves it, and reads any body's world pose.
|
|
12
12
|
- Draws it in three.js from the `./three` subpath: one mesh per visible geom, MuJoCo's meshes shared, turned from MuJoCo's z up into y up with the robot facing +Z.
|
|
13
13
|
- Names the Unitree G1 (29 joints) from MuJoCo Menagerie, pinned to one commit, as a ready robot; its files load from GitHub at run time.
|
|
14
|
+
- Runs GEAR-SONIC, NVIDIA's whole body controller for the G1, from the `./sonic` subpath: an encoder and a decoder 50 times a second through onnxruntime-web and a PD loop at every MuJoCo step, so the G1 stands, holds a crouch or a raised arm, and steps to catch a shove. The weights load from Hugging Face at run time.
|
|
14
15
|
|
|
15
16
|
## Install
|
|
16
17
|
|
|
@@ -18,12 +19,15 @@ Run a physics humanoid in the page: MuJoCo simulates a robot from its MJCF files
|
|
|
18
19
|
npm install @hackbuild/humanoid
|
|
19
20
|
```
|
|
20
21
|
|
|
21
|
-
It has no dependencies. MuJoCo and three.js are optional peers: install `@mujoco/mujoco` to import its factory, or let `loadMujoco` load it from `https://cdn.jsdelivr.net/npm/@mujoco/mujoco@4.0.1/mujoco.js`, with `mujoco.wasm` read beside it. `onLicence` receives the line to show. The G1's files come from GitHub when you load it.
|
|
22
|
+
It has no dependencies. MuJoCo, onnxruntime-web and three.js are optional peers: install `@mujoco/mujoco` to import its factory, or let `loadMujoco` load it from `https://cdn.jsdelivr.net/npm/@mujoco/mujoco@4.0.1/mujoco.js`, with `mujoco.wasm` read beside it. `onLicence` receives the line to show. The G1's files come from GitHub when you load it.
|
|
22
23
|
|
|
23
24
|
| download | size |
|
|
24
25
|
|---|---|
|
|
25
26
|
| mujoco.wasm | 11.2 MB, 2.8 MB gzip (measured) |
|
|
26
27
|
| the G1's meshes | 19.7 MB (vendor) |
|
|
28
|
+
| GEAR-SONIC encoder and decoder | 91.0 MB (vendor), from Hugging Face, pinned to one revision |
|
|
29
|
+
|
|
30
|
+
`Sonic.load` loads onnxruntime-web from jsDelivr when you pass no `ort` module, and the policy files from their pinned URLs when you pass no bytes.
|
|
27
31
|
|
|
28
32
|
## Quick start
|
|
29
33
|
|
|
@@ -63,9 +67,13 @@ MuJoCo is Google DeepMind's physics engine, compiled to WebAssembly and publishe
|
|
|
63
67
|
|
|
64
68
|
An MJCF names other files relative to its compiler's directories: `meshdir` or `assetdir` for meshes, `texturedir` for textures, and includes by their own path. `fetchModel` reads the main file, follows includes, then fetches every named file beside the main one; `filesFrom` does the same over a dropped folder, taking the MJCF with a worldbody that no other file includes as the main one.
|
|
65
69
|
|
|
70
|
+
### the policy
|
|
71
|
+
|
|
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
|
+
|
|
66
74
|
### the robot
|
|
67
75
|
|
|
68
|
-
`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 targets in over simulated time; a sudden jump can topple a robot that a ramp of half a second leaves standing. `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.
|
|
76
|
+
`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.
|
|
69
77
|
|
|
70
78
|
## API overview
|
|
71
79
|
|
|
@@ -78,6 +86,10 @@ An MJCF names other files relative to its compiler's directories: `meshdir` or `
|
|
|
78
86
|
| [`Humanoid`](../../docs/api/humanoid/index.md#humanoid) | step, reset, targets, moveTo, hold, push, poses, dispose |
|
|
79
87
|
| [`G1`](../../docs/api/humanoid/index.md#g1) | the Unitree G1 from MuJoCo Menagerie: url, joints, keyframe, licence |
|
|
80
88
|
| [`HumanoidView`](../../docs/api/humanoid/three.md#humanoidview) | the robot in three.js, from `@hackbuild/humanoid/three` |
|
|
89
|
+
| [`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 |
|
|
91
|
+
| [`G1_SONIC`](../../docs/api/humanoid/sonic.md#g1_sonic) | the G1 deploy model the policy runs on: url, asset host, licence |
|
|
92
|
+
| [`SONIC_JOINTS`](../../docs/api/humanoid/sonic.md#sonic_joints) | standing angles, gains, torque limits, action scale and policy order per joint |
|
|
81
93
|
| [`HumanoidError`](../../docs/api/humanoid/index.md#humanoiderror) | a model or runtime this package cannot open, with the reason |
|
|
82
94
|
|
|
83
95
|
The full reference is in [docs/api/humanoid](../../docs/api/humanoid/README.md).
|
|
@@ -88,6 +100,7 @@ The full reference is in [docs/api/humanoid](../../docs/api/humanoid/README.md).
|
|
|
88
100
|
|---|---|---|
|
|
89
101
|
| MuJoCo | WebAssembly, a network fetch or the installed package | 206 ms to load from a local copy in headless Chrome on an Apple M1 (measured) |
|
|
90
102
|
| stepping | nothing more | 0.084 ms per 2 ms step for the G1, about 24 times real time (measured) |
|
|
103
|
+
| the policy | onnxruntime-web on wasm, one thread | 5.7 ms a 20 ms tick in headless Chrome on an Apple M1 (measured) |
|
|
91
104
|
| drawing | three.js 0.186 or later, WebGL | the G1 draws 35 meshes |
|
|
92
105
|
| single file build | `dist/humanoid.iife.js` | `HackbuildHumanoid` global with `THREE` from the page; MuJoCo still loads from its URL |
|
|
93
106
|
|
|
@@ -96,6 +109,8 @@ The full reference is in [docs/api/humanoid](../../docs/api/humanoid/README.md).
|
|
|
96
109
|
| message | cause | what to do |
|
|
97
110
|
|---|---|---|
|
|
98
111
|
| `mujoco did not load from ...` | offline, or the URL is blocked | install `@mujoco/mujoco` and pass its factory, or serve it and pass `url` |
|
|
112
|
+
| `no actuator drives ... load the g1 deploy model` | the policy was given the menagerie G1 | load `G1_SONIC.url` with `assetBase: G1_SONIC.assetBase` |
|
|
113
|
+
| `onnxruntime-web did not load from ...` | offline, or jsDelivr is blocked | install `onnxruntime-web` and pass the module as `ort` |
|
|
99
114
|
| `mujoco could not compile the model: ...` | a named file is missing or the MJCF is invalid | keep the robot's folder structure; the message names files that did not arrive |
|
|
100
115
|
| `the model has no keyframe ...` | a keyframe name the model lacks | use one from `keyframes` |
|
|
101
116
|
| `no mjcf here` | the drop holds no MJCF with a worldbody | drop the robot's whole folder |
|
|
@@ -107,7 +122,7 @@ The full reference is in [docs/api/humanoid](../../docs/api/humanoid/README.md).
|
|
|
107
122
|
|
|
108
123
|
## Changelog and licences
|
|
109
124
|
|
|
110
|
-
Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LICENSE](../../LICENSE)); this README is CC-BY-4.0 with its code samples also MIT. MuJoCo is Google DeepMind's, Apache-2.0, and loads at run time. The G1 model and meshes are from MuJoCo Menagerie under BSD-3-Clause, copyright Unitree Robotics, and load at run time;
|
|
125
|
+
Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LICENSE](../../LICENSE)); this README is CC-BY-4.0 with its code samples also MIT. MuJoCo is Google DeepMind's, Apache-2.0, and loads at run time. The G1 model and meshes are from MuJoCo Menagerie under BSD-3-Clause, copyright Unitree Robotics, and load at run time; the deploy model is from NVIDIA's GR00T-WholeBodyControl (Apache-2.0) with Unitree's meshes. The GEAR-SONIC weights are NVIDIA's: licensed by NVIDIA Corporation under the NVIDIA Open Model License; they load from Hugging Face at run time and are not part of this package. Robots you bring carry their own licences.
|
|
111
126
|
|
|
112
127
|
## What is verified, and what is not
|
|
113
128
|
|
|
@@ -115,14 +130,18 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
115
130
|
|
|
116
131
|
| check | result |
|
|
117
132
|
|---|---|
|
|
118
|
-
| `npx vitest run packages/humanoid` |
|
|
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) |
|
|
134
|
+
| 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) |
|
|
119
135
|
| 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) |
|
|
120
136
|
| 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
|
+
| 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
|
+
| 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) |
|
|
121
139
|
| 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) |
|
|
122
140
|
|
|
123
141
|
### Not verified by anything
|
|
124
142
|
|
|
125
|
-
-
|
|
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.
|
|
144
|
+
- On its actuators alone (no policy) the robot holds targets but does not balance; a shove topples it.
|
|
126
145
|
- No VRM follows the robot yet.
|
|
127
146
|
- Robots other than the G1 and the test model are untried, and so are textures in MJCF.
|
|
128
147
|
- Nobody has watched it at real frame rate in a visible browser; the checks are headless.
|
|
@@ -131,8 +150,8 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
131
150
|
|
|
132
151
|
| file | gzip (measured) | ceiling |
|
|
133
152
|
|---|---|---|
|
|
134
|
-
| `dist/index.js` (main entry, imports external) |
|
|
135
|
-
| `dist/humanoid.iife.js` (single file build) |
|
|
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 |
|
|
136
155
|
|
|
137
156
|
Measured 2026-11-30 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
138
157
|
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
package/dist/files.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface ModelFiles {
|
|
|
16
16
|
missing: string[];
|
|
17
17
|
}
|
|
18
18
|
/** The files one MJCF names, split into includes and the rest, joined onto its compiler's directories. */
|
|
19
|
-
export declare function referencedFiles(
|
|
19
|
+
export declare function referencedFiles(text: string, dirs?: {
|
|
20
20
|
meshdir?: string;
|
|
21
21
|
texturedir?: string;
|
|
22
22
|
assetdir?: string;
|
|
@@ -24,10 +24,19 @@ export declare function referencedFiles(xml: string, dirs?: {
|
|
|
24
24
|
includes: string[];
|
|
25
25
|
files: string[];
|
|
26
26
|
};
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* A robot from the URL of its main MJCF; every file it names is fetched beside it, or for files that
|
|
29
|
+
* are not MJCF beside `assetBase` when given (a repository whose meshes live on another host, such as
|
|
30
|
+
* Git LFS).
|
|
31
|
+
*/
|
|
28
32
|
export declare function fetchModel(url: string, o?: {
|
|
29
33
|
fetch?: typeof fetch;
|
|
34
|
+
assetBase?: string;
|
|
30
35
|
onFile?: (path: string, done: number, of: number) => void;
|
|
31
36
|
}): Promise<ModelFiles>;
|
|
32
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* A robot from a file list: an `<input type="file" webkitdirectory>` keeps each file's path in the folder;
|
|
39
|
+
* loose files are keyed by name only, so a model whose meshes sit in a folder needs the folder picked. The
|
|
40
|
+
* main MJCF is the one with a worldbody that no other file includes.
|
|
41
|
+
*/
|
|
33
42
|
export declare function filesFrom(list: Iterable<File>): Promise<ModelFiles>;
|
package/dist/files.js
CHANGED
|
@@ -7,10 +7,27 @@
|
|
|
7
7
|
* arrive is listed in `missing`.
|
|
8
8
|
*/
|
|
9
9
|
import { HumanoidError } from "./runtime.js";
|
|
10
|
-
|
|
11
|
-
const
|
|
10
|
+
// attributes in single or double quotes
|
|
11
|
+
const attrs = (tag) => Object.fromEntries([...tag.matchAll(/([A-Za-z_]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)].map((m) => [m[1], m[2] ?? m[3] ?? ""]));
|
|
12
|
+
// a path with "." and ".." segments resolved, as MuJoCo and a URL would
|
|
13
|
+
const tidy = (path) => {
|
|
14
|
+
const out = [];
|
|
15
|
+
for (const part of path.replace(/\\/g, "/").split("/")) {
|
|
16
|
+
if (part === "..")
|
|
17
|
+
out.length && out[out.length - 1] !== ".." ? out.pop() : out.push("..");
|
|
18
|
+
else if (part && part !== ".")
|
|
19
|
+
out.push(part);
|
|
20
|
+
}
|
|
21
|
+
return out.join("/");
|
|
22
|
+
};
|
|
23
|
+
const join = (dir, file) => tidy(dir ? `${dir}/${file}` : file);
|
|
24
|
+
// XML comments hide tags: a commented out compiler or mesh must not count
|
|
25
|
+
const uncomment = (xml) => xml.replace(/<!--[\s\S]*?-->/g, "");
|
|
26
|
+
// a texture names one file, or six for a cube's faces
|
|
27
|
+
const FILE_ATTRS = ["file", "fileright", "fileleft", "fileup", "filedown", "filefront", "fileback"];
|
|
12
28
|
/** The files one MJCF names, split into includes and the rest, joined onto its compiler's directories. */
|
|
13
|
-
export function referencedFiles(
|
|
29
|
+
export function referencedFiles(text, dirs = {}) {
|
|
30
|
+
const xml = uncomment(text);
|
|
14
31
|
const d = { ...dirs };
|
|
15
32
|
for (const m of xml.matchAll(/<compiler\b[^>]*>/g)) {
|
|
16
33
|
const a = attrs(m[0]);
|
|
@@ -24,11 +41,11 @@ export function referencedFiles(xml, dirs = {}) {
|
|
|
24
41
|
const includes = [...xml.matchAll(/<include\b[^>]*>/g)].map((m) => attrs(m[0]).file).filter((f) => !!f);
|
|
25
42
|
const files = [];
|
|
26
43
|
for (const m of xml.matchAll(/<(mesh|skin|hfield|texture)\b[^>]*>/g)) {
|
|
27
|
-
const
|
|
28
|
-
if (!f)
|
|
29
|
-
continue;
|
|
44
|
+
const a = attrs(m[0]);
|
|
30
45
|
const dir = m[1] === "texture" ? (d.texturedir ?? d.assetdir) : (d.meshdir ?? d.assetdir);
|
|
31
|
-
|
|
46
|
+
for (const k of FILE_ATTRS)
|
|
47
|
+
if (a[k])
|
|
48
|
+
files.push(join(dir, a[k]));
|
|
32
49
|
}
|
|
33
50
|
return { includes, files: [...new Set(files)] };
|
|
34
51
|
}
|
|
@@ -36,7 +53,7 @@ export function referencedFiles(xml, dirs = {}) {
|
|
|
36
53
|
function dirsOf(xmls) {
|
|
37
54
|
const d = {};
|
|
38
55
|
for (const x of xmls)
|
|
39
|
-
for (const m of x.matchAll(/<compiler\b[^>]*>/g)) {
|
|
56
|
+
for (const m of uncomment(x).matchAll(/<compiler\b[^>]*>/g)) {
|
|
40
57
|
const a = attrs(m[0]);
|
|
41
58
|
if (a.meshdir !== undefined)
|
|
42
59
|
d.meshdir = a.meshdir;
|
|
@@ -86,14 +103,19 @@ async function gather(main, read, onFile) {
|
|
|
86
103
|
}));
|
|
87
104
|
return { xml, assets, missing };
|
|
88
105
|
}
|
|
89
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* A robot from the URL of its main MJCF; every file it names is fetched beside it, or for files that
|
|
108
|
+
* are not MJCF beside `assetBase` when given (a repository whose meshes live on another host, such as
|
|
109
|
+
* Git LFS).
|
|
110
|
+
*/
|
|
90
111
|
export function fetchModel(url, o = {}) {
|
|
91
112
|
const f = o.fetch ?? globalThis.fetch.bind(globalThis);
|
|
92
113
|
const here = globalThis.location?.href;
|
|
93
114
|
const base = new URL(url, here);
|
|
115
|
+
const assets = o.assetBase ? new URL(o.assetBase.endsWith("/") ? o.assetBase : `${o.assetBase}/`, here) : base;
|
|
94
116
|
const read = async (path) => {
|
|
95
117
|
try {
|
|
96
|
-
const r = await f(path === url ? base.href : new URL(path, base).href);
|
|
118
|
+
const r = await f(path === url ? base.href : new URL(path, /\.xml$/i.test(path) ? base : assets).href);
|
|
97
119
|
return r.ok ? new Uint8Array(await r.arrayBuffer()) : null;
|
|
98
120
|
}
|
|
99
121
|
catch {
|
|
@@ -102,18 +124,22 @@ export function fetchModel(url, o = {}) {
|
|
|
102
124
|
};
|
|
103
125
|
return gather(url, read, o.onFile);
|
|
104
126
|
}
|
|
105
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* A robot from a file list: an `<input type="file" webkitdirectory>` keeps each file's path in the folder;
|
|
129
|
+
* loose files are keyed by name only, so a model whose meshes sit in a folder needs the folder picked. The
|
|
130
|
+
* main MJCF is the one with a worldbody that no other file includes.
|
|
131
|
+
*/
|
|
106
132
|
export async function filesFrom(list) {
|
|
107
133
|
const files = new Map();
|
|
108
134
|
for (const f of list)
|
|
109
|
-
files.set((f.webkitRelativePath || f.name)
|
|
135
|
+
files.set(tidy(f.webkitRelativePath || f.name), f);
|
|
110
136
|
// paths relative to the folder that holds the main file
|
|
111
137
|
const xmls = [...files.keys()].filter((p) => /\.xml$/i.test(p));
|
|
112
138
|
const texts = new Map();
|
|
113
139
|
for (const p of xmls)
|
|
114
140
|
texts.set(p, await files.get(p).text());
|
|
115
141
|
const included = new Set([...texts].flatMap(([p, t]) => referencedFiles(t).includes.map((i) => join(p.split("/").slice(0, -1).join("/"), i))));
|
|
116
|
-
const main = xmls.filter((p) => !included.has(p) && /<worldbody/.test(texts.get(p))).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length)[0];
|
|
142
|
+
const main = xmls.filter((p) => !included.has(p) && /<worldbody/.test(uncomment(texts.get(p)))).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length)[0];
|
|
117
143
|
if (!main)
|
|
118
144
|
throw new HumanoidError("no mjcf here: drop the robot's folder, with an .xml that has a worldbody.");
|
|
119
145
|
const root = main.split("/").slice(0, -1).join("/");
|