Commit Graph

898 Commits

Author SHA1 Message Date
Yuval Tassa d507e92198 Preparation for MIMO actuators: split actuator counts: nu (inputs), nactuator (objects), nout (outputs).
An actuator now owns a block of consecutive controls
(actuator_ctrladr/ctrlnum, width defined by the actuator type) and a block
of consecutive force outputs (actuator_outadr/outnum, width defined by the
transmission type). Force outputs are the scalars of actuation space: one
force, length, velocity and moment row each. nout = dim(actuator_force) is
derived from transmission types; all current types have width 1, so all
three counts coincide for every existing model and behavior is bit-exact.

Array re-keying: ctrlrange/ctrllimited by nu; forcerange/forcelimited/gear/
acc0/length0/lengthrange and the moment row structure by nout; everything
else per actuator. The mjModel actuator block is re-sorted by size key.

Layout-breaking, not behavior-breaking: saved .mjb files are invalidated
(size list changed) and recompilation is required.

PiperOrigin-RevId: 948351772
Change-Id: Icbc196ffa083cb1eaa6f1a3710869c89d8f62540
2026-07-15 08:30:20 -07:00
Haroon Qureshi 52317058ba Add pan/tilt motions to mjv_moveCamera.
PiperOrigin-RevId: 948308546
Change-Id: I2724b889759e652ed50d03bf97f3c7125cd0eb56
2026-07-15 06:50:15 -07:00
Haroon Qureshi fa36015bae Remove unneeded mjvScene argument from mjv_moveCamera.
PiperOrigin-RevId: 948204736
Change-Id: Ic9b116ce439b3153764af67c449a824aec1994dc
2026-07-15 02:26:04 -07:00
Copybara-Service 6c78c8664e Merge pull request #3340 from devshahofficial:devshahofficial/mjr-renderer-info
PiperOrigin-RevId: 948183711
Change-Id: I28b256eca22e86ec0ba05a4fa26458d678aca130
2026-07-15 01:37:11 -07:00
Kyle Bayes 2444defc63 Support arbitrary large meshes in multiccd by reusing EPA memory.
PiperOrigin-RevId: 947709621
Change-Id: Idc4f168434b9d0a8555c0bed989adb0e99770a78
2026-07-14 08:48:25 -07:00
Yuval Tassa 0ce8f7b06b Replace functionally opaque Viscous Pause with functionally transparent "Viscous posing mode" toggle.
PiperOrigin-RevId: 947527204
Change-Id: I122a9730fa22ac9e8809762046a89fb0a774d827
2026-07-14 01:50:13 -07:00
Yuval Tassa dddb2767c6 Include gap in body_margin, fixing mid-phase pruning of in-gap contacts.
The mid-phase BVH descent filter prunes body pairs using body_margin,
which was compiled as the max over geom margins, excluding gap. Broadphase
and the leaf-level test both use margin+gap, so any multi-geom body relying
on gap could silently lose its in-gap contacts when raw AABBs don't
overlap. Single-geom bodies take the leaf-leaf path and were unaffected.

PiperOrigin-RevId: 946967548
Change-Id: I6d92baa296f1a83be68b4dbfd64a96d1c7efd3c4
2026-07-13 05:04:55 -07:00
Google DeepMind fbf031a7d5 Replace functionally opaque Viscous Pause with functionally transparent "Viscous posing mode" toggle.
PiperOrigin-RevId: 946298154
Change-Id: Ia06dd6346ac1002000f2d0b1cf9498ffb0d5f8bd
2026-07-11 13:47:48 -07:00
Yuval Tassa 724a6c6623 Replace functionally opaque Viscous Pause with functionally transparent "Viscous posing mode" toggle.
PiperOrigin-RevId: 946286636
Change-Id: I3e542b12bb57c67f3f194d7bcfdffe39de4f2b94
2026-07-11 13:00:59 -07:00
Sam Haves dc7581acfa Add pluggable resource writing to MuJoCo
Extend mjpResourceProvider with an optional write callback (write)
so that mj_encode, mj_saveXML, and mj_saveModel can write to any
registered provider.

PiperOrigin-RevId: 945202741
Change-Id: I37903425260932e555f4a8c2392c4ff8c2e6cc06
2026-07-09 10:47:48 -07:00
devshahofficial d23ff84c59 Add renderer info query API 2026-07-07 11:44:46 -07:00
Matija Kecman ee28b334ef Add a Studio example for rendering time-delayed ghost overlays.
This example demonstrates how to use Studio's `extra_geoms` feature to render semi-transparent, time-delayed copies of the model's geoms, creating a "ghost" effect.

PiperOrigin-RevId: 943672439
Change-Id: I8ae640672945b55dd25dd3d444f52d0b2fa7f0f8
2026-07-06 22:25:04 -07:00
Matija Kecman 8079ab3d4d Refactor Viewer to be a base class owning the communication with the simulation, handler registry, core visualization objects and the render function
ViewerApp is simplified, interacting with the endpoint and handlers through the Viewer instance. This change makes it possible to write simulation viewers without using the UI/UX provided by ViewerApp (which should be renamed StudioApp)

PiperOrigin-RevId: 943642660
Change-Id: Id8eb3d4e6a27ceda93833367fec4699fa6bc838e
2026-07-06 20:50:29 -07:00
Matija Kecman 4cb14bef47 Resolve string-based type annotations in message handlers.
When `from __future__ import annotations` is active or forward references are used as strings, type annotations are not directly class objects. This change uses `get_type_hints` to resolve these string annotations to their actual types, ensuring correct validation of message handler signatures.

PiperOrigin-RevId: 942608060
Change-Id: Ic2b214ee85e835616cc3a18ec2699eba6deebb6a
2026-07-04 16:03:26 -07:00
Yuval Tassa 11f1da0c44 Migrate types in mjs structs.
PiperOrigin-RevId: 942546629
Change-Id: I46f2b24b53a43361fdc67dc32f2af1c0ce8b1de8
2026-07-04 11:27:27 -07:00
Yuval Tassa 315bcfbf3a Remove mjData.qM
PiperOrigin-RevId: 942520660
Change-Id: I422358e299ca0fcfe4c49cd0ee90c014a4c319d7
2026-07-04 09:38:45 -07:00
Matija Kecman bdc9e9cce3 Fix bug where backspace intended for an imgui widget reset the environment
PiperOrigin-RevId: 942496281
Change-Id: I8c5d315d22a7c01dbe69f19833964f25141e9663
2026-07-04 07:40:27 -07:00
Matija Kecman 7c0d527005 Support extra_geoms argument
PiperOrigin-RevId: 942283363
Change-Id: I7e0c3aa845c0d2ae1c4390fd5cc01d6ff2741720
2026-07-03 16:39:22 -07:00
Matija Kecman 16f2276fe2 Increase priority of ViewerApp ModelEvent handler
PiperOrigin-RevId: 942274710
Change-Id: Ib894420e2d8f1e57a1da2d953c944316a1ff42ae
2026-07-03 16:02:14 -07:00
Yuval Tassa 7e9ac58ff9 Migrate mjd_inverseFD mass Jacobian from qM to M
PiperOrigin-RevId: 942268237
Change-Id: I0ecfe161867ce9930cd6366d778077df2cd3197f
2026-07-03 15:35:52 -07:00
Saran Tunyasuvunakool 4b345457a8 Add a test to check that GIL remains disabled under free-threaded Python.
Also add manual `Py_GIL_DISABLED` macro definition in CMakeLists as well, since there are some STATIC libraries that aren't getting it automatically through pybind11. As originally proposed in PR #3259.

Co-authored-by: Devansh Raulo <151062727+devansh0703@users.noreply.github.com>
PiperOrigin-RevId: 942216446
Change-Id: I9ef5f457491ae776c452912fbfa8617b8509d47c
2026-07-03 12:11:58 -07:00
Yuval Tassa 5618666a7d Add body/simple attribute to control simple body optimization.
PiperOrigin-RevId: 942164766
Change-Id: I1e83bb99b6a1955917eb9b2e9bed0dc7b8e6a161
2026-07-03 09:09:30 -07:00
Haroon Qureshi 4ecfe5c1f3 Add FontGlobalScale binding.
PiperOrigin-RevId: 942113414
Change-Id: Id87ce552e717d118574befd00dac65ca71e3ba0d
2026-07-03 06:24:40 -07:00
Matija Kecman 0dfa4b509a Refactor Studio customization and message dispatch to use decorator-based handlers
This change replaces fixed callback protocols (e.g., ViewerGuiHook, ViewerUpdateHook, SimEventHandler) with a general-purpose, priority-based message and event handling mechanism.

Key changes:
- Handler decorator and registry: Introduced the `@messages.handler(priority=...)` decorator and `HandlerRegistry` (`handler_registry.py`). Methods marked as handlers are automatically discovered and dispatched by priority (CRITICAL, USER, LIBRARY, INTERNAL) or method resolution order.
- Local lifecycle events: Added `ViewerAppInitEvent`, `BuildGuiEvent`, and `UpdateEvent` to `messages.py`. Custom GUI rendering and per-frame update logic can now be implemented as standard event handlers without needing separate interface protocols.
- Streamlined launch and app APIs: Replaced individual hook and handler arguments in `launch_passive`, `ViewerApp`, and `ViewerHandle` with unified `viewer_handlers` and `sim_handlers` lists.
- Module restructuring: Extracted simulation-side message handling and `ViewerHandle` from `sim_app.py` into a dedicated `viewer_handle.py` module, removing `sim_app.py`.
- Sample updates: Migrated existing examples (such as `implot.py`) to use the new handler pattern and lifecycle events.

PiperOrigin-RevId: 941729322
Change-Id: I93e7c0edf0a13a8dc854f9e2083451f7c25a1825
2026-07-02 09:14:41 -07:00
Haroon Qureshi 1ca64b441b Add binding for DockSpaceOverMainViewport.
PiperOrigin-RevId: 941727670
Change-Id: Idfecadf5a44b237f8c72493a7294bddfcd948ae5
2026-07-02 09:09:51 -07:00
Taylor Howell c3adb50898 _realloc_island
PiperOrigin-RevId: 941618362
Change-Id: Idef1deb0ff4976de42aa585993988ae3363cd1fc
2026-07-02 04:21:43 -07:00
Matija Kecman 6e8a79c657 Refactor Studio implot sample to use a new message passing and launch APIs
Deleted async examples since they add noise and are not particularly useful

PiperOrigin-RevId: 941117641
Change-Id: I4f621801f652e0b410a7acf905cda58143dc3fb0
2026-07-01 08:42:30 -07:00
Saran Tunyasuvunakool a07ae6f849 Make MuJoCo Python bindings compatible with free-threading.
Introduce a new header `gil.h` defining `MutexLockIfGilDisabled` to support thread-safety in both standard and free-threaded CPython builds.

Protect critical shared states and registries:
- Guard global Python callback pointers in `callbacks.cc` using a mutex. Move `gil_scoped_acquire` into local blocks around refcount modifications to prevent `longjmp` from bypassing destructors.
- Protect raw pointer maps in `structs_wrappers.cc` with static mutexes.
- Replace TOCTOU race in `mjcb_time` initialization with thread-safe `std::call_once`.
- Add synchronization to lazy indexer array cache initialization in `indexers.cc` and `indexer_xmacro.h`.
- Protect vector mutations in `StructListBase::PopulateUpTo` in `structs.h` with a mutex.
- Revert unnecessary atomic changes to threadpool counters.
- Declare free-threading compatibility by passing `pybind11::mod_gil_not_used()` to all extension modules.

Fixes #3259
Fixes #3256
Fixes #2978

PiperOrigin-RevId: 941101502
Change-Id: Iec4ce58afcbc75d4b0be6a9a21fc8a47854242e3
2026-07-01 08:08:42 -07:00
Matija Kecman cab191755a Add MuJoCo Studio threaded/passive launch function
PiperOrigin-RevId: 941043766
Change-Id: I5b75d0a2b183d402e8ce221883c2734255e87f0f
2026-07-01 05:50:32 -07:00
Matija Kecman f73e1b6865 Add sim_app.py and viewer_app.py to Studio.
- `sim_app.py` provides a SimEventHook and a Handle class for the simulation process to interact with the viewer, including sending state snapshots and processing viewer events.

- `viewer_app.py` implements the main viewer application logic, handling user input, building the Dear ImGui GUI, and managing communication with the simulation process. It also includes hooks for custom viewer behavior.

PiperOrigin-RevId: 940994701
Change-Id: I82786872cd885b15454843b3a4d1160ff0b4be2b
2026-07-01 03:50:55 -07:00
Matija Kecman a1b0d2c933 Add a Viewer-to-Sim Snapshot channel and convert relevant messages.
The ViewerEndpoint can now send Snapshot messages to the SimEndpoint. The SimEndpoint has a new method, `get_viewer_snapshots`, to retrieve these. Thsi channel will be used for UI state needed for the simulation (e.g., `MjOption` and `StepControl`).

PiperOrigin-RevId: 940981799
Change-Id: Ib9bd6ad848cd5479bc49492a34fddd82569cb09f
2026-07-01 03:21:17 -07:00
Matija Kecman 58d6910afa Refactor StepControl and GUI to return change status.
StepControl methods SetSpeed, SetNoiseParameters, and SetPauseState now return a boolean indicating whether the state was actually changed. The GUI functions NoiseGui and StepControlGui also return a boolean reflecting if any parameters were modified. Noise parameters are now directly managed by StepControl rather than being stored in UxState. The StepControlEvent message has been expanded to include all step control parameters. Keyboard event handling has been slightly refactored to better align with event-based updates.

PiperOrigin-RevId: 940656342
Change-Id: I3701623a2fdcfc4c084b5db0ae19048669040de4
2026-06-30 14:21:00 -07:00
Matija Kecman f4b2f76def Updates NativeViewer instantiations in sample scripts to pass a ViewerConfig object
PiperOrigin-RevId: 940654165
Change-Id: I984cb296593e992dd0d99ca44b43c54de4c3e96d
2026-06-30 14:17:02 -07:00
Matija Kecman 3a623aaf33 Internal change.
PiperOrigin-RevId: 940601733
Change-Id: I83855569f85012173c3edf167eca78d236f6cdea
2026-06-30 12:38:11 -07:00
Haroon Qureshi e2d7955437 Enable status bar by default for python studio.
PiperOrigin-RevId: 940557724
Change-Id: I0a4c96a53a0bcfcb5677515705c874d12bfd300d
2026-06-30 11:18:24 -07:00
Matija Kecman 7a84022092 Add ImGui bindings for Docking and window size constraints
PiperOrigin-RevId: 940470346
Change-Id: I731eedd0bd04afbd0c526ed8b27e6fb804596d20
2026-06-30 08:32:46 -07:00
Sam Haves d83ef0b6b9 Change mj_encode return type to 64-bit (mjtSize)
This supports encoding files larger than 2GB.

PiperOrigin-RevId: 939828697
Change-Id: If60d36c61475ced20b4eb58408ffb37e25bf3db7
2026-06-29 07:41:52 -07:00
Yuval Tassa 7c706b273a Report nnz(J) for CG solver.
PiperOrigin-RevId: 939806054
Change-Id: Icb2955511e33be046a4665fb39bce2546d6d4e3d
2026-06-29 06:49:23 -07:00
Matija Kecman e0bb2b0665 Introduce message and endpoint abstractions for MuJoCo Studio communication.
-   `messages.py`: Defines base classes for `Message`, `Snapshot`, and `Event`, along with `SnapshotChannel` and `EventChannel` protocols. It also includes concrete message types for state, reset, model, perturbation, pause state, and exit events.
-   `endpoints.py`: Provides `ViewerEndpoint` and `SimEndpoint` classes to manage message routing between the simulation and the viewer via the defined channels. A `make_endpoints` function is included to create both endpoints.

PiperOrigin-RevId: 939659912
Change-Id: I61a52a7d25431bc4ed38a184813882145eb421d1
2026-06-29 00:24:15 -07:00
Matija Kecman f594778813 Refactor viewer initialization and protocol.
Introduced a ViewerConfig dataclass to encapsulate common viewer window parameters. The NativeViewer now accepts a ViewerConfig and no longer requires a model at initialization. The Viewer protocol has been updated to include a close method (renamed from stop) and an upload_image method. Added checks for None models/data in studio event handling.

PiperOrigin-RevId: 939631378
Change-Id: Ibc07d0e775efa0d79ce5552ee52102e943a9b290
2026-06-28 23:07:02 -07:00
Haroon Qureshi 2a5345ba8c Add type attributes to help codegen.
PiperOrigin-RevId: 937935655
Change-Id: I14883a98b7b9b4bcc3dea8b60d839138c14ea444
2026-06-25 06:00:33 -07:00
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
Matija Kecman 38956ed95c Handle None values for model and data in StepControl.advance.
The `StepControl.advance` method now checks if the provided `model` or `data` Python objects are `None` before attempting to cast them to `MjModelWrapper` or `MjDataWrapper`, passing `nullptr` to the underlying C++ function if they are `None`.

This fixes an oversight in the python bindings, C++ code already supported null models.

PiperOrigin-RevId: 937243996
Change-Id: Ie67b8603517e7390fb54bfefbfed79ccf7b2bc5e
2026-06-24 04:18:29 -07:00
Haroon Qureshi 5cef2472d5 Remove custom step_fn for StepControl::Advance.
PiperOrigin-RevId: 936609234
Change-Id: I606cf4d71d856cbd260900d63b22c719974c977d
2026-06-23 05:49:20 -07:00
Haroon Qureshi 7a00c1f3e0 Factor out AstProcessor into its own library.
PiperOrigin-RevId: 936518263
Change-Id: I597ef4382e7ddc953f8daedd4f5123d71f0e8a42
2026-06-23 02:08:57 -07:00
Kyle Bayes 0fd7bea973 Modernize struct and enum style in MuJoCo headers.
PiperOrigin-RevId: 936485706
Change-Id: I31864acc4bd44573127d3d04c6b1a23f9d9c4cbc
2026-06-23 00:48:11 -07:00
Michael Moss 5700829122 Update MuJoCo version to 3.10.1 following the 3.10.0 release
PiperOrigin-RevId: 936044969
Change-Id: If0ebcc192419302da01741ebabb2b7dd3d7f7baf
2026-06-22 07:25:02 -07:00
Yuval Tassa e2528cbd93 Rename "Stats" window to "Info" and remove "Stats" dock.
PiperOrigin-RevId: 936026479
Change-Id: I72e4f2cba6df255d5446faedc81727b39ef735bc
2026-06-22 06:38:03 -07:00
Michael Moss 3b08f39747 Update dependencies ahead of the 3.10.0 release.
PiperOrigin-RevId: 935674769
Change-Id: I4ad9c7494f499bc1016b99df78053337db439309
2026-06-21 11:02:27 -07:00
Kevin Zakka a8eaccd2b6 Copybara import of the project:
--
6ab68a057443f038a3d844807f205b1c99cab944 by Kevin Zakka <kevinarmandzakka@gmail.com>:

Fix pickle code-execution vulnerability in sysid loaders

Serialize signal_mapping as JSON so the trajectory and time series loaders can use allow_pickle=False, preventing arbitrary code execution from untrusted .npz files.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google-deepmind/mujoco/pull/3353 from kevinzakka:sysid-disable-pickle-load 6ab68a057443f038a3d844807f205b1c99cab944
PiperOrigin-RevId: 935400242
Change-Id: Iecd907174441fbcfd02c106b912a7ff375c9098c
2026-06-20 15:10:54 -07:00