forked from stillonearth/MuJoCo-WASM
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathtest_load.mjs
More file actions
50 lines (46 loc) · 1.9 KB
/
Copy pathtest_load.mjs
File metadata and controls
50 lines (46 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Smoke test: compile every demo scene with the new @mujoco/mujoco WASM module.
import load_mujoco from './node_modules/@mujoco/mujoco/mujoco.js';
import { readFileSync, readdirSync, statSync } from 'fs';
import { join, relative } from 'path';
const mujoco = await load_mujoco();
mujoco.FS.mkdir('/working');
mujoco.FS.mount(mujoco.MEMFS, { root: '.' }, '/working');
// Copy the whole assets/scenes tree into the VFS.
function copyDir(dir) {
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
const rel = relative('assets/scenes', full);
if (statSync(full).isDirectory()) {
mujoco.FS.mkdir('/working/' + rel);
copyDir(full);
} else {
mujoco.FS.writeFile('/working/' + rel, readFileSync(full));
}
}
}
copyDir('assets/scenes');
const scenes = [
"22_humanoids.xml", "adhesion.xml", "agility_cassie/scene.xml", "arm26.xml",
"balloons.xml", "car.xml", "flex.xml", "hammock.xml", "humanoid.xml",
"model.xml", "mug.xml", "scene.xml", "shadow_hand/scene_right.xml",
"shadow_hand/scene_left.xml", "simple.xml", "slider_crank.xml",
"model_with_tendon.xml",
];
let failures = 0;
for (const scene of scenes) {
try {
const model = mujoco.MjModel.mj_loadXML('/working/' + scene);
const data = new mujoco.MjData(model);
for (let i = 0; i < 100; i++) mujoco.mj_step(model, data);
// Touch the fields the renderer reads.
const probes = [model.names, model.name_bodyadr, model.geom_rgba, model.mat_texid,
model.tex_data, data.xpos, data.xquat, data.ten_wrapadr, data.wrap_xpos];
if (probes.some(p => p === undefined)) throw new Error('missing field');
console.log(`OK ${scene} (nbody=${model.nbody} ngeom=${model.ngeom} nu=${model.nu} nkey=${model.nkey} time=${data.time.toFixed(3)})`);
data.delete(); model.delete();
} catch (e) {
failures++;
console.log(`FAIL ${scene}: ${e.message ?? e}`);
}
}
process.exit(failures ? 1 : 0);