Commit Graph

5034 Commits

Author SHA1 Message Date
Taylor Howell 17feb4a64e Update Studio to close window
PiperOrigin-RevId: 942216322
Change-Id: I96b4665016df0acb0c5dec9caae27eeb9a87f874
2026-07-03 12:11:01 -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
Yuval Tassa 14c0b0c92b Recompute sameframe flags in mj_setConst.
The `body_sameframe`, `geom_sameframe`, and `site_sameframe` flags are now recomputed within `mj_setConst` based on the current model geometry. This allows these flags to be updated if the model's body/geom/site frames are modified after the initial compilation. Tests are added to verify the correct recomputation and its effect on forward kinematics. The compiler also checks that its initial computation matches the result of `mj_setConst`.

Fixes #3029, #1628.

PiperOrigin-RevId: 941758649
Change-Id: I7b995f8c67ad305bca5b52732436ba578c905d73
2026-07-02 10:49:00 -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
Yuval Tassa 2d283b5e9d Allow self-attach in MJCF
PiperOrigin-RevId: 941676717
Change-Id: I9ff8fc89716bc14b438a41e2b4075bbe5fdb83cf
2026-07-02 06:51:46 -07:00
Yuval Tassa cdc35dec38 Reformat MJCF array in xml_native_reader.cc.
Undo mistaken auto-format of the schema table, revert it to be more human-readable.

PiperOrigin-RevId: 941628625
Change-Id: Ifc51996da9a7df9d1a03392a0ade256fb8b1c151
2026-07-02 04:45:46 -07:00
Taylor Howell c3adb50898 _realloc_island
PiperOrigin-RevId: 941618362
Change-Id: Idef1deb0ff4976de42aa585993988ae3363cd1fc
2026-07-02 04:21:43 -07:00
Yuval Tassa 0e58c48504 Clean up MJCF attach code.
PiperOrigin-RevId: 941603845
Change-Id: I94f275e2073b1eb81cfabdc0bed80021c6f15b1c
2026-07-02 03:45:39 -07:00
Yuval Tassa f8462a156d Refine line search convergence criteria.
The line search now requires a negative cost (improvement) in addition to a small derivative to declare convergence, preventing premature termination when no actual improvement has been made.

Follows the proposal in github.com/google-deepmind/mujoco_warp/pull/1471

PiperOrigin-RevId: 941579503
Change-Id: I8fcd20f7b959e50d77cd5d6de0a3c6d95f86b9e1
2026-07-02 02:56:24 -07:00
Haroon Qureshi fb259a5edd Implement RenderableManager.
Similar to LightManager, the RenderableManager manages
renderables based on an mjModel and its mjData.

PiperOrigin-RevId: 941510745
Change-Id: I97b44cc857f136aa7c90ceb85a42e299fc759b73
2026-07-02 00:03:05 -07:00
Yuval Tassa c6c3ec3149 Add "frame" attribute to <attach> element.
The `<attach>` element now supports a "frame" attribute, allowing users to specify either a "body" or a "frame" to attach to, but not both. The XML parser has been updated to handle this new attribute and the mutual exclusivity constraint.

PiperOrigin-RevId: 941245904
Change-Id: I4c0edeed5f3a9e456aed96c373b1647fe79841d9
2026-07-01 12:49:55 -07:00
Taylor Howell 1f6cf4035c Import google-deepmind/mujoco_warp from GitHub.
PiperOrigin-RevId: 941234486
Change-Id: Ie5d8cc0c9975e66f9a81bb6a86e33f640a5d19e3
2026-07-01 12:27:10 -07:00
Georg Ostrovski bb80b55ae1 Fix data race in mju_getLogConfigPtr lazy init
The lazy init of log_config used a single atomic flag (env_checked) with
a load-then-store pattern, allowing two threads to both enter the init
path and concurrently write to the non-atomic log_config.topics field.

Replace with a two-phase atomic init: an atomic exchange on
env_init_claimed ensures exactly one thread enters the init, while
env_init_done (with acquire/release semantics) signals completion and
provides the happens-before edge that makes log_config writes visible to
other threads.

Also adds mj_atomic_exchange_bool to engine_crossplatform.h (both MSVC
and GCC/Clang variants).

PiperOrigin-RevId: 941202181
Change-Id: I59b6801c7b4b8b0e1647d82d2aeb534a90fb66fb
2026-07-01 11:24:36 -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
Michael Moss 2012646711 Don't do a shallow clone, to avoid "fast-forward" push confusion.
PiperOrigin-RevId: 940727059
Change-Id: Id3c6c7c6a3fa1288ed091e49afc073b74f0bbd9c
2026-06-30 16:43:35 -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
Taylor Howell 1810051d16 MuJoCo Warp documentation: Large scenes
PiperOrigin-RevId: 940590426
Change-Id: I006e245b54cd4165928927bee76f44d730bdd895
2026-06-30 12:14:48 -07:00
Google DeepMind 095608ef5f Make a bindings.h header file with the declarations, so that other projects can reuse the declared structs.
Add parseXMLString overload that supports passing in an MjVFS.

PiperOrigin-RevId: 940579266
Change-Id: I8294988bc4279e80795fab21024f64562a9e6743
2026-06-30 11:57:50 -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
Yuval Tassa 584ccd73d5 Improve error/warning display in studio.
PiperOrigin-RevId: 940299502
Change-Id: I8b13e2f984627a638a01b52f7dadca43f2c2ca80
2026-06-30 01:12:22 -07:00
Martin Schuck 407be2fc0b Copybara import of the project:
--
83a17d2844770fc2bbff37eda73b82df56076414 by Martin Schuck <martin.schuck@tum.de>:

Fix overflow cast

--
d12211c6665e1d791f77338daf8c62fa2374e3c8 by Martin Schuck <martin.schuck@tum.de>:

Prevent skipping warnings from cached jax functions by clearning the cache before invokation

COPYBARA_INTEGRATE_REVIEW=https://github.com/google-deepmind/mujoco/pull/3369 from amacati:fix.overflow_cast d12211c6665e1d791f77338daf8c62fa2374e3c8
PiperOrigin-RevId: 939914544
Change-Id: I0ab6e9ad1e7c45f352d2f49642049ad930955f0b
2026-06-29 10:45:40 -07:00
Sam Haves 4e1795b9a4 Add special case support for MJB and TXT files to mj_encode.
PiperOrigin-RevId: 939875974
Change-Id: I57fc753871b348a7f6342aca0a892e74acb74173
2026-06-29 09:32:50 -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
Taylor Howell 1e04c568e8 Studio launcher
PiperOrigin-RevId: 939814201
Change-Id: If3fb1a1a9f9114835452fce63f39931db7818db3
2026-06-29 07:07:54 -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 79f6deac99 Update bounds when updating the mesh.
PiperOrigin-RevId: 938628053
Change-Id: Ibd3d952d62614fc1eb049893937e6fb2d661da56
2026-06-26 09:25:06 -07:00
Yuval Tassa c7b1171846 Improvements to studio profiler
PiperOrigin-RevId: 938503994
Change-Id: I3a12647feea4c761dd8f8ba239f92355ceccfba1
2026-06-26 03:49:08 -07:00
Taylor Howell 56a182e67c Import Warp v1.14.0
PiperOrigin-RevId: 938464395
Change-Id: Iac99c53566e2e62f6e75f5e0904100919043b463
2026-06-26 02:03:42 -07:00
Haroon Qureshi 07e292bc6b Make mjrf types opaque in header.
PiperOrigin-RevId: 938409081
Change-Id: I8b9680dcb04f56aadf9ffd601b08025fc624c656
2026-06-25 23:41:49 -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
Yuval Tassa 463b0fb27f Add ImGui overlay utility and PAUSE/realtime overlays to Studio.
PiperOrigin-RevId: 937834952
Change-Id: I3f3a0500a89b34e2e03b2fe88344b928edeafe8f
2026-06-25 01:45:01 -07:00
Yuval Tassa b6a0db7a17 Add Atkinson Hyperlegible Mono font support
PiperOrigin-RevId: 937799904
Change-Id: I89e4652cc45afdd9a55b3042395c4a56c70289fb
2026-06-25 00:16:39 -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
Yuval Tassa 0402bae176 Replicate the controls from the toolbar into the collapsible options sections and provides an option to hide the toolbar.
PiperOrigin-RevId: 937290592
Change-Id: I08f1f4880fd0b06123e817cb9ae7a3281daa8063
2026-06-24 06:09:24 -07:00
Haroon Qureshi 3d09a46d61 Use bulbradius as the vsm_blur_width as well.
PiperOrigin-RevId: 937286692
Change-Id: I03502da45951f90979b8f8d58915c80656a5eac7
2026-06-24 06:00:31 -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 a3039224ba Add attributes for codegen assistance.
PiperOrigin-RevId: 937219243
Change-Id: If3a0830b7020d52ef346d97886a90950941f4908
2026-06-24 03:17:03 -07:00
Haroon Qureshi 3e33f93ddc Remove unused material instances before rendering frame.
Also ensure material texture hashes are unique so that the material
cleanup works correctly.

PiperOrigin-RevId: 937206048
Change-Id: Ibed53457ee271f4faae3bcac5fb479b5ce9fc352
2026-06-24 02:46:33 -07:00
Haroon Qureshi 29b49991a2 Rename mjrf_getSamplerType to mjrf_getTextureSamplerType.
PiperOrigin-RevId: 937193469
Change-Id: I56f856e257fa1cf99b643f794139ef85817a0bb9
2026-06-24 02:18:07 -07:00