Commit Graph

21 Commits

Author SHA1 Message Date
Haroon Qureshi 4b8a8fae92 Move code_builder.py to a common location.
PiperOrigin-RevId: 937332995
Change-Id: I2f03581cc47d96337bb637f30c678060207333fd
2026-06-24 07:44:40 -07:00
Yuval Tassa 58f6d52491 Introduce new logging API, fixes #858
PiperOrigin-RevId: 930744288
Change-Id: I6ec1203b55c031390f3eef23192e2337508ce886
2026-06-11 14:36:57 -07:00
Alessio Quaglino 4c381635e1 Add mjs_makeFlex to the MuJoCo C and Python APIs.
- Add mjs_makeFlex C API that wraps mjCFlexcomp::Make(), creating
  a flex with auto-generated bodies, joints, and equality constraints
  from parameters (type, dim, dof, count, cellcount, spacing, scale,
  radius, mass, inertiabox, equality, rigid, flatskin, elastic2d,
  pos, quat, origin, file, vfs).
- Add Python binding body.make_flex() in specs.cc with keyword args.
- Refactor flex_spec_provision.py to use make_flex() instead of XML
  string templating + separate spec + attach. Eliminates textwrap
  dependency.
- Merge user_flexcomp into user_model BUILD target to resolve
  circular dependency.

PiperOrigin-RevId: 922725304
Change-Id: Ice13787c45f3173407fec659f9590a6453bc65dd
2026-05-28 05:59:20 -07:00
Yuval Tassa 7667e7110e Introduce mjtBool for boolean types.
PiperOrigin-RevId: 920201340
Change-Id: I3b19c11a00357e06a1df08b8819832955c37f9ff
2026-05-23 09:13:54 -07:00
Google DeepMind 37762e3f70 Add support for vfs assets in mj_compile function to MuJoCo WASM.
Regarding mj_compile VFS argument:
I was encountering a memory error when using `std::optional<MjVFS>` with `mj_compile` (because vfs should be an optional argument of the function). This is likely because `MjVFS` doesn't have copy/move constructors, which are required for types used with `std::optional`, causing issues with memory management when std::optional copies the MjVFS object.
To solve this and to make vfs an optional argument to `mj_compile`, I replaced `mj_compile_wrapper` with two overloaded functions. This avoids using `std::optional<MjVFS>` and resolves the memory issue, while still allowing mj_compile to be called with or without the vfs argument from JavaScript.

But what if we instead add those copy/move constructors so it works with `std::optional`?:
While making `MjVFS` copyable or movable would theoretically allow it to work with std::optional, it's not a feasible approach in this case.
The MjVFS struct manages file data in memory, allocating buffers when files are added and freeing them when `mj_deleteVFS` is called in its destructor. A copy would require a deep copy of the entire virtual filesystem, but MuJoCo does not provide a public API function (like a  "mj_copyVFS") to do this. Implementing a deep copy manually would be complex and fragile. A shallow copy would result in multiple MjVFS objects pointing to the same memory, leading to double-free errors when their destructors run.
Given these constraints, MjVFS cannot safely be made copyable. The approach of providing two overloaded C++ functions is better.

PiperOrigin-RevId: 855740541
Change-Id: Ia08b6db8868ad245f07145db3fb0322cb9f737cb
2026-01-13 08:36:48 -08:00
Google DeepMind 8a5c52d395 Use a dedicated function for wrapper struct names
This change introduces a `wrapper_struct_name` function in `structs.py` to consistently generate the name of the C++ wrapper struct from a C struct name. All call sites in `functions.py` and `structs.py` that previously used `common.capitalize` for this purpose now call `wrapper_struct_name`.

PiperOrigin-RevId: 837544242
Change-Id: Ibe5fea8294283dae63bb8d064fd8beb8cfd3f2fe
2025-11-27 08:42:33 -08:00
Google DeepMind 6e59f61c70 Make WASM codegen output to be alphabetically ordered.
PiperOrigin-RevId: 836680575
Change-Id: I7ddb7267c0db4911b2e84528f948dee6fccdf81d
2025-11-25 08:29:30 -08:00
Google DeepMind 217317ccba Change WASM generators from classes to functions.
PiperOrigin-RevId: 836257289
Change-Id: I7a3c1d7bb545353a3d278330582e33c0551792cb
2025-11-24 09:36:36 -08:00
Matija Kecman a0d49ade1b More simplification to functions.py in WASM bindings
PiperOrigin-RevId: 834643175
Change-Id: Iff873f6f0916e0039ff6a44468afd9b4d8f98f37
2025-11-20 01:06:29 -08:00
Matija Kecman 102f382c9d Rename uppercase_first_letter to capitalize
Also rename `lowercase_first_letter` to `decapitalize`

PiperOrigin-RevId: 834622292
Change-Id: I1cfbda1be782ff40dd3fc0726601cc6b1f427345
2025-11-19 23:54:02 -08:00
Matija Kecman 48ecddbe3b Simplify functions.py in WASM bindings generation
PiperOrigin-RevId: 834470193
Change-Id: I3c26d65ea8812fd6a4c78264fbce8353bac6fb2f
2025-11-19 15:35:45 -08:00
Matias Manevi a36f452250 Refactor MuJoCo WASM bindings functions code generation and auto-generate functions requiring argument boundchecks.
PiperOrigin-RevId: 832333773
Change-Id: Id2e1a59e8d366baa2ee044d693f76aadcd1dfd32
2025-11-14 08:51:18 -08:00
Matias Manevi 54661ab140 Fully generate Emscripten bindings for MuJoCo functions.
PiperOrigin-RevId: 830975595
Change-Id: Ie4d0d16c80f490abaa5ae8218628ac1b3d32c0ef
2025-11-11 10:32:04 -08:00
Matija Kecman 4e46db8903 Refactor WASM binding directory structure
* All tests moved into wasm/codegen/tests folder
* Merged wasm/codegen/helpers/ into wasm/codegen/generators/

PiperOrigin-RevId: 829471173
Change-Id: I2dbc5d9351771817ec260c7ddf87c31e66a9eabe
2025-11-07 09:37:26 -08:00
Matija Kecman 44220fcc51 Refactor WASM bindings in preparation for codegen directory structure update
PiperOrigin-RevId: 829459535
Change-Id: I4045e163a6e7fcee9d9585131d1e5e30f0b50b89
2025-11-07 09:02:43 -08:00
Matija Kecman 29c1a3a0a5 Cleanup WASM bindings generators so they all have a similar interface
PiperOrigin-RevId: 827965451
Change-Id: I657fc4d3a480fbc62124c84fe9ddc0900a91183f
2025-11-04 07:32:32 -08:00
Matija Kecman f808632cf8 Rename WASM bindings function helper file
PiperOrigin-RevId: 827897836
Change-Id: Ifb13ebaf54dacabc2a3ed8a8ea4244ecea2a8f41
2025-11-04 03:57:03 -08:00
Matija Kecman c22d94e470 Various minor cleanups to WASM code generation
* Add newline function to code_builder
* Remove type aliases which made jump to definition less ergonomic
* Add types to constants

PiperOrigin-RevId: 827863199
Change-Id: Ib4390d398926466ecce491a3d0ebe308ed5e0cbe
2025-11-04 02:07:27 -08:00
Matias Manevi 4086261714 Add JavaScript bindings and WASM support
Co-authored-by: Matija Kecman <matijak@google.com>
Co-authored-by: Sebastian Noreña Rendón <sebas.norena@creativa77.com.ar>
Co-authored-by: Kyle Bayes <kylebayes@google.com>
PiperOrigin-RevId: 826479070
Change-Id: I25acf36e6c20b091d8492e10798d028ae66f6733
2025-10-31 07:21:18 -07:00
Matija Kecman f2badc05ac Add JavaScript bindings and WASM support
Co-authored-by: Matija Kecman <matijak@google.com>
Co-authored-by: Sebastian Noreña Rendón <sebas.norena@creativa77.com.ar>
Co-authored-by: Kyle Bayes <kylebayes@google.com>
PiperOrigin-RevId: 826109484
Change-Id: I327fd54122762bd2e239cc31c602a3eb73051c26
2025-10-30 11:11:52 -07:00
Matias Manevi 76e64d96bb Add JavaScript bindings and WASM support
Co-authored-by: Matija Kecman <matijak@google.com>
Co-authored-by: Sebastian Noreña Rendón <sebas.norena@creativa77.com.ar>
Co-authored-by: Kyle Bayes <kylebayes@google.com>
PiperOrigin-RevId: 826094938
Change-Id: Id2658a187bc078056f4410c71202696753319e64
2025-10-30 10:38:16 -07:00