mujoco 3.2.3 → 3.2.4

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.
Files changed (2) hide show
  1. package/README.md +217 -15
  2. package/package.json +3 -2
package/README.md CHANGED
@@ -1,15 +1,131 @@
1
- # MuJoCo WASM bindings
1
+ # MuJoCo JavaScript Bindings
2
+
3
+ These are the canonical JavaScript and TypeScript bindings for the MuJoCo
4
+ physics engine.
5
+
6
+ This package provides a high-level API that allows you to interact with the core
7
+ MuJoCo engine compiled into a high-performance WebAssembly (WASM) module. These
8
+ bindings are developed and maintained by Google DeepMind and are always up to
9
+ date with the latest developments in MuJoCo. For brevity, the documentation
10
+ below will often refer to “JavaScript” but the concepts apply equally to
11
+ TypeScript.
12
+
13
+ > [!IMPORTANT]
14
+ > _These bindings are still a WIP. For details, see the [Future Work](#future-work)
15
+ > section. Also note that development has primarily taken place on Linux using
16
+ > Google Chrome. If you're working on a different OS or browser, you may
17
+ > encounter some rough edges. We have successfully tested the bindings on MacOS
18
+ > in CI but as of November 13th 2025 Windows in untested (the instructions here
19
+ > have worked on one Windows 11 machine but have failed on other machines)._
20
+
21
+ ## Prerequisites
22
+
23
+ > [!NOTE]
24
+ > Run all the commands in this README from the top-level directory.
25
+
26
+ - To compile the [`bindings.cc`](codegen/generated/bindings.cc) file, which
27
+ generates the `.wasm` WebAssembly file, `.js` JavaScript import, and `.d.ts`
28
+ TypeScript declaration file, you will need Emscripten SDK version `4.0.10`.
29
+ Later versions may work but are untested. To set up the SDK, do the
30
+ following, you can run this anywhere but the rest of the commands in this
31
+ README only work in the shell where you source the `emsdk_env.sh` script.
32
+
33
+ ```sh
34
+ git clone https://github.com/emscripten-core/emsdk.git
35
+ ./emsdk/emsdk install 4.0.10
36
+ ./emsdk/emsdk activate 4.0.10
37
+ source ./emsdk/emsdk_env.sh
38
+ ```
39
+
40
+ - To easily run the JavaScript tests and the demo application, `node` and `npm`
41
+ are required. We recommend managing these using
42
+ [nvm](https://github.com/nvm-sh/nvm). There are also various JavaScript
43
+ dependencies needed for the tests, demo, and bindings build process. These
44
+ dependencies are expected to be located in the `wasm` folder. To install
45
+ them and ensure they can be found by later commands, run the following:
46
+
47
+ ```sh
48
+ npm install --prefix ./wasm
49
+ export PATH="$(pwd)/wasm/node_modules/.bin:$PATH"
50
+ ```
51
+
52
+ - To modify the bindings `python3` is required because the [`bindings.cc`](codegen/generated/bindings.cc)
53
+ file is generated by a Python script. To run the bindings generator tests,
54
+ `absl` is required and `pytest` will be helpful. Set up a Python environment
55
+ with these dependencies as follows:
56
+
57
+ ```sh
58
+ python3 -m venv .venv
59
+ source .venv/bin/activate
60
+ pip install -r python/build_requirements.txt
61
+ ```
62
+
63
+ > [!TIP]
64
+ > _Emscripten is well-documented. We recommend reading the sections covering the
65
+ > [Emscripten Compiler Settings](https://emscripten.org/docs/tools_reference/settings_reference.html),
66
+ > the [Emscripten SDK](https://emscripten.org/docs/tools_reference/emsdk.html),
67
+ > and the [Embind](https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html)
68
+ > library. To understand the limitations and caveats related to using the
69
+ > browser as a platform, see the
70
+ > [Porting](https://emscripten.org/docs/porting/index.html#porting) section._
71
+
72
+ ## User Guide
73
+
74
+ ### Bindings Generation
75
+
76
+ The [`bindings.cc`](codegen/generated/bindings.cc) file is compiled to generate
77
+ to `.wasm` WebAssembly file, `.js` JavaScript import, and `.d.ts` TypeScript
78
+ declaration file. These are the files you'll use to call MuJoCo from JavaScript.
79
+ To generate them ensure the npm and Emscripten SDK prerequisites are set up and
80
+ then run the following:
2
81
 
3
- Official WebAssembly (WASM) bindings for the MuJoCo physics engine, compiled from the MuJoCo C/C++ sources into WASM with JS glue (Emscripten + Embind). The package ships prebuilt ESM-ready JS/WASM artifacts and TypeScript types for immediate use.
82
+ ```sh
83
+ emcmake cmake -B build && cmake --build build
84
+ ```
85
+
86
+ This command will generate the following folders under the project root:
87
+
88
+ - `build`: contains MuJoCo compiled using Emscripten.
89
+ - `wasm/dist`: contains the WebAssembly module, `.js` and `.d.ts` files.
90
+
91
+ ### Example Application
4
92
 
5
- **Important**:_These bindings are still a WIP_.
93
+ After generating the bindings you will be ready to write web applications using
94
+ MuJoCo. We have provided a basic web application that uses Three.js to render a
95
+ simple simulation, to try it run this command:
6
96
 
7
- ## Install
8
97
  ```sh
9
- npm install mujoco
98
+ npm run dev:demo --prefix ./wasm
10
99
  ```
11
100
 
12
- ## Quick start (ESM / TypeScript)
101
+ You may prefer to write your entire app in C++ and compile it using Emscripten.
102
+ If you do this, you won’t need to use these bindings, since you’ll be writing
103
+ minimal JavaScript, and the granularity of these bindings may be inappropriate
104
+ (e.g., you might want to call multiple MuJoCo functions in the C++ callback
105
+ invoked by `requestAnimationFrame`).
106
+
107
+ We have also found that a hybrid approach can be helpful, as it is often more
108
+ convenient to work with browser APIs directly in JavaScript. If you choose to
109
+ write your application in C++ and compile it using Emscripten, you may want to
110
+ copy a subset of the `EMSCRIPTEN_BINDINGS` from `bindings.cc` into your
111
+ application’s source file.
112
+
113
+ ### Named Access
114
+
115
+ The bindings support named access methods, similar to the Python bindings,
116
+ allowing convenient access to model and data elements by name or index. For
117
+ example, you can access a geometry by name using `model.geom('mygeom')` or a
118
+ joint using `data.jnt('myjoint')`.
119
+
120
+ For more details and examples of how to use named access, please refer to the [named access tests](tests/bindings_test.ts#L1876-L2378) and [documentation](https://mujoco.readthedocs.io/en/stable/python.html#named-access).
121
+
122
+ ## Usage Guide
123
+ When interacting with MuJoCo objects through the WASM bindings, it's important to understand how data is accessed. Properties on objects like `MjModel` and `MjData` can expose data in two ways: by copy or by reference.
124
+
125
+ ### Install
126
+ ```sh
127
+ npm install mujoco
128
+ ```
13
129
 
14
130
  ```ts
15
131
  import loadMujoco from 'mujoco';
@@ -28,9 +144,6 @@ const data = new mujoco.MjData(model);
28
144
  mujoco.mj_step(model, data);
29
145
  ```
30
146
 
31
- ## Usage Guide
32
- When interacting with MuJoCo objects through the WASM bindings, it's important to understand how data is accessed. Properties on objects like `MjModel` and `MjData` can expose data in two ways: by copy or by reference.
33
-
34
147
  ### Copy vs. Reference
35
148
 
36
149
  #### 1. By Copy (Value-based access)
@@ -187,13 +300,74 @@ mujoco.get_mjFRAMESTRING()
187
300
 
188
301
  This will return a javascript array representation of the values in MuJoCo `mjFRAMESTRING`.
189
302
 
190
- ## Notes
303
+ ### About assets
191
304
  The package is ESM (`type: module`) and ships TypeScript types.
192
305
 
193
306
  Ensure your bundler or dev server serves the `.wasm` asset at runtime.
194
307
 
195
- ### Development
196
- For detailed build instructions see the repository [README](https://github.com/google-deepmind/mujoco/tree/main/wasm#mujoco-javascript-bindings) (Emscripten toolchain, Embind bindings, producing the .wasm artifact, and targets for Node and browser).
308
+ ## Development
309
+
310
+ In order to change the bindings you will need to change the [`bindings.cc`](codegen/generated/bindings.cc)
311
+ file but this should not be done manually. The file is generated using the
312
+ Python scripts and template files in the [`codegen`](codegen) folder, to edit
313
+ the bindings you will need to change those files and re-generate [`bindings.cc`](codegen/generated/bindings.cc)
314
+ using this command:
315
+
316
+ ```sh
317
+ PYTHONPATH=python/mujoco python3 -m wasm.codegen.update
318
+ ```
319
+
320
+ The codegen scripts use MuJoCo’s Python introspect library to generate the
321
+ Embind `EMSCRIPTEN_BINDINGS` block that binds C++ functions and classes to
322
+ JavaScript. The functions and classes that are bound are wrappers around
323
+ MuJoCo's C API. These wrappers provide a convenient place to add features like
324
+ bounds checking and nice error reporting.
325
+
326
+ ### Testing
327
+
328
+ 1. **JavaScript API tests.**
329
+ These verify that a wide variety of MuJoCo functions and classes work
330
+ correctly when called from JavaScript. Run the tests as follows:
331
+
332
+ ```sh
333
+ npm run test --prefix ./wasm
334
+ ```
335
+
336
+ 2. **JavaScript API benchmark tests.**
337
+ The current benchmark tests check JavaScript/C++ shared memory buffers
338
+ performance. We will increase the coverage of the benchmarks overtime. Run
339
+ the benchmarks using this command:
340
+
341
+ ```sh
342
+ npm run benchmark --prefix ./wasm
343
+ ```
344
+
345
+ 3. **Bindings generator tests.**
346
+ These are relevant when developing or extending the bindings. The following
347
+ command finds and runs all `test_*.py` or `*_test.py` files in the `wasm`
348
+ folder:
349
+
350
+ ```sh
351
+ PYTHONPATH=python/mujoco python3 -m pytest ./wasm
352
+ ```
353
+
354
+ ### Debugging
355
+
356
+ We provide a “sandbox” app where you can quickly write code to run in your
357
+ browser. Write your code in the [`main.ts`](tests/sandbox/main.ts) file and use
358
+ the following command to execute it in your browser:
359
+
360
+ ```sh
361
+ npm run dev:sandbox --prefix ./wasm
362
+ ```
363
+
364
+ The page will be blank since the script only logs to the console output. You
365
+ can add your code at the indicated placeholder and use Chrome DevTools for
366
+ debugging. It is possible to set up a debug workflow where stack traces and
367
+ stepping through code across language boundaries work correctly. Our current
368
+ method to do this only works internally at Google, but it should be possible to
369
+ replicate the experience with open-source tooling — community suggestions are
370
+ welcome!
197
371
 
198
372
  ## Versioning
199
373
  Package versions follow the official MuJoCo release versions.
@@ -203,6 +377,34 @@ For example:
203
377
  |-------------|----------------|
204
378
  | 3.5.0 | 3.5.0 |
205
379
 
206
- ---
207
-
208
- For full engine documentation, see: https://mujoco.readthedocs.io
380
+ ## Future Work
381
+
382
+ 1. **Bind all useful APIs.**
383
+ These bindings are not yet complete. While the main MuJoCo APIs (`mj_step`,
384
+ `mj_loadXML`, etc.) are well tested, other APIs (e.g., functions from
385
+ `mjspec.h`) remain untested in real web applications (though test code for
386
+ the `mjspec` bindings does exist).
387
+
388
+ 2. **Improve the developer experience.**
389
+ There is still work to be done to improve the developer experience when
390
+ developing the WASM bindings. The most obvious issue is that bindings
391
+ generation is not yet fully automated. As a result, it is currently less
392
+ convenient than we'd like to identify and apply the changes needed to update
393
+ the bindings. The goal is to eventually automate all binding code generation
394
+ and clearly communicate what changes are required in the WASM bindings as a
395
+ result of C++ updates. This problem should only affect developers working on
396
+ the MuJoCo engine in C++, not end users writing JavaScript.
397
+
398
+ 3. **Improve the documentation.**
399
+ The documentation in this README will eventually be merged into the main
400
+ MuJoCo documentation once the bindings are complete and named access is
401
+ implemented. We also intend to review the bindings APIs and make adjustments
402
+ to minimize differences with the Python bindings (while respecting language
403
+ idioms) to reduce the amount of additional documentation required.
404
+
405
+ 4. **Improve the [example](#example-application).**
406
+ We aim to provide an example application that can be easily modified and
407
+ embedded into a paper project page (see [this example](https://kzakka.com/robopianist/)).
408
+ This could be achieved by extending the Three.js example or by compiling the
409
+ MuJoCo platform C++ code using the Emscripten toolchain. Community
410
+ suggestions and contributions are welcome!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mujoco",
3
- "version": "3.2.3",
3
+ "version": "3.2.4",
4
4
  "description": "MuJoCo WASM bindings",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,8 +15,9 @@
15
15
  "mujoco",
16
16
  "physics",
17
17
  "wasm",
18
+ "google",
19
+ "deepmind",
18
20
  "webassembly",
19
- "bindings",
20
21
  "simulation",
21
22
  "robotics",
22
23
  "emscripten",