Commit Graph

104 Commits

Author SHA1 Message Date
Yuval Tassa df6942eb39 Support float32 precision for mjtNum in Python bindings.
PiperOrigin-RevId: 922959317
Change-Id: I384b3bdeabdc4d3f66c71cae41dabfaf51387be7
2026-05-28 13:56:58 -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 bdf00966f9 Add compiler timing diagnostics to mjsCompiler, printed by compile.cc
For example, `compile mujoco_menagerie/robotis_op3/scene.xml` now outputs

```
Compile 1 (cold cache):
  total:      317.2 ms
  assets:     284.8 ms (wall clock)
    load:     616.1 ms
    hull:      26.4 ms
    poly:     137.8 ms
    inert:    177.8 ms
    bvh:      568.2 ms
    octr:       1.6 ms
    tex:       25.3 ms
  other:       32.4 ms

Compile 2 (warm cache):
  total:       79.9 ms
  assets:      54.5 ms (wall clock)
    load:     888.5 ms
    hull:       0.0 ms
    poly:       0.0 ms
    inert:      0.0 ms
    bvh:        0.0 ms
    octr:       0.0 ms
    tex:       21.4 ms
  other:       25.3 ms
```

PiperOrigin-RevId: 917850214
Change-Id: Iaec86230bec0faf2e47820e20cbff61de5b2621e
2026-05-19 08:28:47 -07:00
Sam Haves 723b8b1ea6 Introduce explicit VFS in Python MjVfs
This change introduces MjVFS, an explicit object to mirror the C mjVFS. This is meant to replace the MjSpec.assets dict. This latter while convenient guides users towards harmful authoring patterns with respect to data duplication and spec attachment workflows. Making VFS management explicit should encourage better memory usage and allow us to make better compile time optimizations.

From this change, `spec.assets` is deprecated. However we will temporarily support backwards compatibility due to the wide spread usage. An error will be thrown if calling code tries to use a spec that uses both the assets dict and the new MjVfs.

PiperOrigin-RevId: 908772050
Change-Id: I77c6d0369307fc300c954768fed17401261e18da
2026-05-01 09:34:17 -07:00
Sam Haves d92fe0810c Add MjSpec.encode method.
PiperOrigin-RevId: 907177387
Change-Id: I65800298798037c4a0c0cd79ec86706be67db51e
2026-04-28 14:22:41 -07:00
Alessio Quaglino 6b724616c0 Prevent deletion from an attached mjSpec.
This change disallows calling `mjs_delete` on an mjSpec that has been attached to another mjSpec via `mjs_attach`. Attempting to delete an element from an attached spec will now result in an error. The Python bindings for `mjSpec.delete` have been updated to raise a ValueError when this occurs.

PiperOrigin-RevId: 897266695
Change-Id: Ic0670125a3028191ec50eca890f02b5910ec8b03
2026-04-09 13:14:00 -07:00
Yuval Tassa 81720071b8 Changes to dcmotor:
- Remove `lugre:viscous`, should now be added directly to actuator `damping`. Trying to do this for the user was incompatible with default inheritance (compounding instead of overriding).
- Move voltage limiting from the `saturation` to the `controller` attribute.
- Fix indexing issues in default inheritance.

PiperOrigin-RevId: 897087642
Change-Id: I5388c2633e15c7e223992e7eb5d6a28db75a6438
2026-04-09 06:52:45 -07:00
Yuval Tassa 70a7647ad9 Add <dcmotor> actuator and related docs and tests.
PiperOrigin-RevId: 892927987
Change-Id: I38ed6412801341ba03ddf5fe7b93a6081df24d37
2026-04-01 07:50:23 -07:00
Matija Kecman 3c19b63ed3 Refactor texture.data to be handled using py::bytes
PiperOrigin-RevId: 843226742
Change-Id: I7ab920da3c387467b1fced27f557c6edd1af4bce
2025-12-11 08:06:12 -08:00
Matija Kecman bf49fe3daa Enable reading textures from spec in Python
PiperOrigin-RevId: 842151742
Change-Id: I477d118cc7e2385d29b395b192fa89e9facb9c3e
2025-12-09 03:08:32 -08:00
Sam Haves 57f7145806 Create mjpDecoder, mj_parse, and mju_decodeResource
- plugin system similar to mjpResourceProvider, but instead of loading a resource it converts an existing mjResource into an mjSpec.
  - The returned spec is then composed into the referencing spec.
  - This enables different file types to generate arbitrary specs, and allows us to separate format parsing from compilation code.

Follow up CLs will move some of the logic in src/engine for PNG, USD, KTX, OBJ loading into decoders.

The mj_parse function MjSpec from a given file, it's a more generic version of mj_parseXML.

In it's implementation, mj_parse as opposed to mj_parseXML will look for any registered decoder and
not assume we are striclty dealing with MJCF.

PiperOrigin-RevId: 826149497
Change-Id: I0ece26904280cb94bd5ded6dd5a565c539d60254
2025-10-30 12:54:40 -07:00
Alessio Quaglino 2bdea1a0aa Use "/" as default prefix during attach if not specified.
The user can recover the old behavior by passing prefix="".

This enables to attach children with default and save a valid result to XML.

PiperOrigin-RevId: 825011185
Change-Id: Id20c2589da928bf92b77bdb01cfba73dfc1d2f52
2025-10-28 06:40:34 -07:00
Sam Haves ac2cd5dfd6 Add support for querying of MjsTendon path from Python.
Fixes #2670

PiperOrigin-RevId: 822215254
Change-Id: Ice5a264e54f963776093511c6e4ac830aae6d4f8
2025-10-21 11:51:24 -07:00
Google DeepMind 0e1104768a No public description
PiperOrigin-RevId: 809083979
Change-Id: I5c6641b73c76153c15f5cdf858b788e1433acc81
2025-09-19 10:10:45 -07:00
Google DeepMind 26ea20a21f No public description
PiperOrigin-RevId: 809074980
Change-Id: Ib3e3522addceddba6a057cfef80fcbd30a420b3d
2025-09-19 09:49:07 -07:00
Alessio Quaglino 77e025ea98 Move meshdir and texturedir to mjsCompiler.
For backwards compatibility in the Python bindings, both `spec.compiler.meshdir` and `spec.meshdir` are now allowed.

Fixes #2834.

PiperOrigin-RevId: 809060113
Change-Id: Ie23f1c5dd57de43568312a8e062906f4013bb474
2025-09-19 09:05:44 -07:00
Alessio Quaglino 07e7417d26 Add prefix to asset paths when appending specs.
PiperOrigin-RevId: 794966246
Change-Id: I4825a11cc3234e6f403340dd997742cea0e2183b
2025-08-14 03:48:56 -07:00
Alessio Quaglino eff4dda189 Suffix asset names when attaching specs.
PiperOrigin-RevId: 794717786
Change-Id: I02abe06ca3c43138e91e61f4acf87a26b3faf7fc
2025-08-13 13:43:16 -07:00
Yuval Tassa 784c7a419b Improve builtin hemisphere docs
PiperOrigin-RevId: 791271829
Change-Id: I391215b5388f4e9e2a17198dbcdbd0c605fda4b4
2025-08-05 10:25:45 -07:00
Yuval Tassa 705ec6d7fb Adds built-in superellipsoid mesh.
PiperOrigin-RevId: 791196831
Change-Id: I1d864f6e620870f016377a4d9e2e26d1a23fd77e
2025-08-05 07:02:52 -07:00
Yuval Tassa a5d4d1000e Add built-in supertoroid mesh.
PiperOrigin-RevId: 791180080
Change-Id: I3a70f50ff4a52a1bd4b88fc30334a574895145b4
2025-08-05 06:06:43 -07:00
Yuval Tassa 996f0040fd Add built-in sphere mesh.
PiperOrigin-RevId: 791162850
Change-Id: I573a414727e79f1a495e0f2282b2faff48ab3443
2025-08-05 05:05:05 -07:00
Yuval Tassa 5220767457 Add built-in hemisphere mesh.
PiperOrigin-RevId: 791148546
Change-Id: Ic9ff0c9b0f5fa4fd22d5f7f848f150cf74d378ba
2025-08-05 04:16:24 -07:00
Yuval Tassa a5a6379f83 Add built-in cone mesh type.
Also delete `prism` type since it is subsumed by cone.

PiperOrigin-RevId: 790992343
Change-Id: I7a9c6f2a4377489173acd64b23086c748d2cee8e
2025-08-04 19:35:32 -07:00
Alessio Quaglino 51babec9c5 Move tactile sensor to the engine.
PiperOrigin-RevId: 788863133
Change-Id: I3172ebb7641fa8146469da25cba7db794760e7b1
2025-07-30 05:27:44 -07:00
Alessio Quaglino 89f4789085 Add mjs_makeMesh to create a builtin mesh.
PiperOrigin-RevId: 788538127
Change-Id: I999733399a1a0da07b0f915f34d31364ab8b3b52
2025-07-29 11:31:18 -07:00
Yuval Tassa 46dc67b7eb Add function mjs_sensorDim to user API.
Note: change to (unreleased) contact sensor mjSpec API
PiperOrigin-RevId: 788507423
Change-Id: Ie639afb7ed01dc3f7bab43a3e812e8e0b0c67d07
2025-07-29 10:20:27 -07:00
Alessio Quaglino fc13995dd4 Yield ownership of vector<double>, vector<float>, and vector<int> to mjSpec in Python bindings.
Fixes #2756

PiperOrigin-RevId: 785417251
Change-Id: Ib399c46ee59585258ace7d9583c68b7d06d0a9e4
2025-07-21 06:44:17 -07:00
Alessio Quaglino 594e17074a Replace name attribute with setters and getters in the C API of mjSpec.
PiperOrigin-RevId: 778816015
Change-Id: Ieffb7a5bce37e887ff009f9a02d2434435e79ca1
2025-07-03 02:30:56 -07:00
Alessio Quaglino a2acd2d4ed Rename detach_default and detach_body to delete in the mjSpec bindings.
PiperOrigin-RevId: 773674361
Change-Id: I3977060e19e9ff0afc65ad91693c017958576b78
2025-06-20 06:23:30 -07:00
Alessio Quaglino 0488d9f4eb Replace mjs_detachBody and mjs_detachDefault with mjs_detach.
In a follow-up, mjs_detach will be changed to only remove without deleting an element.

PiperOrigin-RevId: 773637351
Change-Id: I9ee4d3584ba88ccc225591337cf036bab806e25c
2025-06-20 04:12:27 -07:00
Alessio Quaglino f75772587a Add functions for setting an mjsActuator to a specific shortcut type.
PiperOrigin-RevId: 769049331
Change-Id: If5bb04966bd29a57569a2c17d712b9ae3d33324d
2025-06-09 02:17:02 -07:00
Alessio Quaglino 1fbbfd8079 Correct frame property in MjsBody from method to read-only attribute.
PiperOrigin-RevId: 764188923
Change-Id: I7c753f7f431b79aa320681c45b7614f68b63852c
2025-05-28 03:48:07 -07:00
Alessio Quaglino 7a5b55f57e Expose mjs_resolveOrientation to the Python API.
PiperOrigin-RevId: 762571376
Change-Id: I08d8394b24670c7f102356da4234b17f1ba4e05f
2025-05-23 14:36:47 -07:00
Alessio Quaglino e389872c7d Add frame property to python bindings.
PiperOrigin-RevId: 762452877
Change-Id: I555cec650d04700f6718b4d77a866c821b90685c
2025-05-23 09:24:24 -07:00
Alessio Quaglino 3e9d130092 Add mjs_getPluginAttributes.
PiperOrigin-RevId: 752691116
Change-Id: Ib503a99f8d10661b8bf92410ccf471420f924986
2025-04-29 05:19:09 -07:00
Alessio Quaglino ec186430ef Add setting plugin config properties via Python bindings.
PiperOrigin-RevId: 747421357
Change-Id: Ie80f1a889f2f6ec457c1e16193fa0694e07d3fe9
2025-04-14 08:07:14 -07:00
Alessio Quaglino a209134315 Enable procedural plugin activation in Python bindings.
PiperOrigin-RevId: 746055614
Change-Id: Idcc2f62fdfeccdca356e3d1acadf168b46a98881
2025-04-10 09:13:21 -07:00
Sam Haves 5c12ea871f Split MjSpec out into header to allow use by other pybind modules.
This should enable other pybind modules to accept arguments of type MjSpec.

PiperOrigin-RevId: 745580987
Change-Id: I435a8d264149369e3fbee14c5d2c628ef74b2541
2025-04-09 07:31:23 -07:00
Alessio Quaglino b839fe79e1 Allow to attach an entire mjSpec in mjs_attach.
PiperOrigin-RevId: 742737713
Change-Id: Ie172568b8c35232e1f13d75aebee20346e76e95b
2025-04-01 09:51:52 -07:00
Alessio Quaglino a02a27d4a4 Combine all mjs_attach functions into one.
PiperOrigin-RevId: 742702092
Change-Id: I89e35c59ada017cd061e2031584eeea71776743d
2025-04-01 08:05:58 -07:00
Yuval Tassa 305b68ecbf Add tests for body.find_all() of joints and geoms, fix error message.
Fixes #2525

PiperOrigin-RevId: 742685596
Change-Id: I5f0969967f2490d32e5691983e8d0c363d48a6bd
2025-04-01 07:14:59 -07:00
Alessio Quaglino 86c970bc23 Add error checking in mjs_setFrame.
Also raise error if the frame is not found in the mjCBody copy constructor.

Fixes #2543.

PiperOrigin-RevId: 742624013
Change-Id: I4999b3165c97f8d079412214d027ca7a8dae8cb3
2025-04-01 03:34:48 -07:00
Tom Power be64747166 add mjs_detachDefault to delete a default class from mjSpec
PiperOrigin-RevId: 738452369
Change-Id: I5a53a6dc8f89e1e8136aeefc09d7d9b7b7204e1f
2025-03-19 10:31:04 -07:00
Alessio Quaglino 1bf24e9f67 Do not overwrite existing parent frames for worldbody elements when attaching an mjSpec to a frame or a site.
PiperOrigin-RevId: 737662046
Change-Id: I7028c21c803c01845ae1d53cb476f7b3df172313
2025-03-17 10:21:38 -07:00
Alessio Quaglino da04688071 Automatically compile mjSpec in to_xml().
Also, move mj_compile from MjModelWrapper to MjSpec.

PiperOrigin-RevId: 737640210
Change-Id: I93d2a31c33eb359452b0d966a29939183b4c5198
2025-03-17 09:21:10 -07:00
Yuxuan Jiang 2039629457 Expose MjSpec raw pointer via _address 2025-02-26 10:25:55 +08:00
Alessio Quaglino d1d61925da Do not delete the world child when doing spec.attach.
PiperOrigin-RevId: 730976077
Change-Id: I9aa8133241b45883e605ec80d64ae28af2962680
2025-02-25 12:02:13 -08:00
Alessio Quaglino 441b5c6082 Change MjSpec.default from method to attribute.
PiperOrigin-RevId: 730912407
Change-Id: I0147acbd257ecc8b72752a2992a7d4ea6e1b4c07
2025-02-25 09:17:45 -08:00
Alessio Quaglino 1b4258d274 Change set_default and default to classname in the bindings.
Having defaults in the names of the attribute or function names is confusing for the users since the defaults are not re-applied but are only used for writing to XML. The alternative would be to change mjs_setDefault to re-apply them, but this would overwrite any other attribute set by the user so far.

PiperOrigin-RevId: 726431090
Change-Id: I41f4a23e1722e278b0ecc0a00b07db9b384fe994
2025-02-13 04:52:02 -08:00