Commit Graph

1618 Commits

Author SHA1 Message Date
Taylor Howell 883836848a Fix box-box distance computation.
PiperOrigin-RevId: 829431553
Change-Id: I9e28bc8eb7687c3c83e5ff68c65e93d8a07378a9
2025-11-07 07:37:03 -08:00
Matija Kecman 80a91cfbea Internal change
PiperOrigin-RevId: 829417225
Change-Id: Ib2304c6a40fb7a2a9fed900a587b9f7ed4b3103a
2025-11-07 06:49:00 -08:00
Yuval Tassa 769f37b653 Implement sleeping in engine
PiperOrigin-RevId: 829361787
Change-Id: I6f64d8e25c4248cf32c18cd94d37ff5def78946e
2025-11-07 03:33:07 -08:00
Yuval Tassa 252a0d73df Add sleep related data structures
PiperOrigin-RevId: 829055431
Change-Id: I1ccbd77a57044a754ae7db611b4c2c0010fbda53
2025-11-06 12:10:55 -08:00
Sam Haves 8051f40817 During mj_parse, if mju_openResource fails pass a resource with only the filename to decoders.
This enables decoders to leverage their own file resolution systems. For example: USD can compose a stage (scene) from memory, via a file on disk, or via custom asset resolver.

Passing it through to the decoder reduces the need for custom resource providers that wrap these other resolution systems.

This will also enable a fun, but likely niche usecase where the decoder does procedural generation and does not have to be backed by a resource. See the tests for an example of this.

PiperOrigin-RevId: 828939899
Change-Id: Ic319a685332d91198a4ae926867c834bf7f7f724
2025-11-06 07:06:06 -08:00
Haroon Qureshi 01b0ea5b7d Use webgl backend in emscripten builds.
(Also only display the model name if its a file.)

PiperOrigin-RevId: 828498906
Change-Id: I7def85992f413b321c115ea63db2af057f5fd372
2025-11-05 09:17:34 -08:00
Haroon Qureshi 8b7eb097db Remove Sync and Scene functions from Renderer.
PiperOrigin-RevId: 828481721
Change-Id: Id0399139653b0ec27f0d365437e62cadefadfe6c
2025-11-05 08:33:28 -08:00
Haroon Qureshi 30a99de3b9 Remove dependencies on mjvScene for interactions.
Interactions (like moving the camera or mouse picking) no longer depend
on needing an mjvScene. Instead, everything is done relative to the
camera directly.

This duplicates some code in engine_vis_visualize which we will try to
resolve and recombine at a future time.

PiperOrigin-RevId: 828461259
Change-Id: If26329c1a7c37516f0213b18056c3e31760f60ae
2025-11-05 07:33:42 -08:00
Adrian Collister 740afe22b3 Append warnings to model compile errors.
PiperOrigin-RevId: 827903480
Change-Id: I2ad17bf4cea0dae0ab803fbb7baa9bd70eef303d
2025-11-04 04:15:07 -08:00
Sam Haves 7d7648f7ed Update UsdWriter to write any parts of MjSpec that are not from USD to the EditTarget.
This enables two workflows:
1) Users that parsed some other format into MjSpec, or built it programmatically can export animated USD easily with as minimal as possible interaction with USD.

2) Creating a spec from USD, then modifying the spec, should not cause a duplication of data when writing to USD.

PiperOrigin-RevId: 827627520
Change-Id: I02c8c14a18569547710e54f3704d52ac0bf70ce6
2025-11-03 13:29:46 -08:00
Yuval Tassa abc02b736e Minor fixes to viewer diagnostics
- When `mjData.nefc` was 0 (solver not run at all), we were plotting the stale diagnostics from the last run; now fixed.
- In the case where islands were used, the semantic of the plotted diagnostic `sqrt_nnz` (square root of Hessian nonzeros) is changed. It used to be the sum of square roots of solver nonzeros per island, it is now the square root of the sum of all nonzeros in all islands. The semantic `sqrt(sum(nnz_i))` was found to be more consistent than `sum(sqrt(nnz_i))`, in the sense that switching islanding on/off leads to smaller changes and is more in line with the interpretation of islanding as [block-diagonalization](https://mujoco.readthedocs.io/en/3.3.7/computation/#constraint-islands).

PiperOrigin-RevId: 827624908
Change-Id: I5fc86364ead585a4752a6d44823fb75cf6c7c318
2025-11-03 13:23:05 -08:00
Sam Haves 9319956a16 Modify mujoco_to_usd to operate on SdfLayer intead of SdfAbstractData.
Since we don't do any on demand data loading for USD and always convert everything it should be safe to use the SdfLayer API instead of the SdfAbstractData API. This enables other codepaths such as the USD writer class to reuse the same logic to generate USD specification from an mjSpec.

PiperOrigin-RevId: 827431722
Change-Id: I60a581e0c9577164a4a66229ea9dcb8912afcf74
2025-11-03 04:16:37 -08:00
Alessio Quaglino 3a7aa84e53 Add quadratic stiffness to flex.
PiperOrigin-RevId: 827409919
Change-Id: I3dff8ea49fb1726fec4acf5b91138d6d52c4bfba
2025-11-03 03:01:38 -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
Haroon Qureshi 80eb511620 Remove dependency on Window, Physics, and Renderer classes.
PiperOrigin-RevId: 825137441
Change-Id: I099a518ca9618698401d0330a6ef08278168f88e
2025-10-28 11:42:17 -07:00
Haroon Qureshi 4620b9f23a Merge HandleMouseEvents and HandleKeyboardEvents back into app.cc.
PiperOrigin-RevId: 825081195
Change-Id: I36445b8c452b15ca26056a52fd1844cf77083c0a
2025-10-28 09:44:42 -07:00
Alessio Quaglino 1bfa8b6fa6 Do not add bodies at mesh points for quadratic flex interpolation.
PiperOrigin-RevId: 825001743
Change-Id: Ica085b947fb1c3f56251bceaa6a228f364535d3e
2025-10-28 06:13:27 -07:00
Haroon Qureshi 3b79d3f14b Set flags directly on Renderer class.
This removes a dependency on mjvScene from the App class.

PiperOrigin-RevId: 824983816
Change-Id: I20dd411e6359ee411f9b0b86d4442c090ba4bd5c
2025-10-28 05:24:05 -07:00
Haroon Qureshi 7ba0d96d77 Use mjvCamera directly for generating camera string.
PiperOrigin-RevId: 824982264
Change-Id: I0d8760bb27153849c8f4dacb10aa3162f29c2f6e
2025-10-28 05:18:58 -07:00
Yuval Tassa e1a73f9c4c Add early exit in mj_xfrcAccumulate using mju_isZeroByte
`xfrc_applied` mostly contains user perturbations which are rare. It is very often identically zero and for large arrays `mju_isZeroByte` is significantly faster than `mju_isZero`.

PiperOrigin-RevId: 824975356
Change-Id: Iadb1d300d68cf12de00c14a0665bd89924a2d7e0
2025-10-28 04:59:14 -07:00
Haroon Qureshi a16805f8ee Add CMakeLists.txt files for new (experimental) code.
This includes the filament, toolbox, and studio projects.

Adds a MUJOCO_BUILD_STUDIO option to enable building of the `studio` app (disabled by default).

Adds a MUJOCO_USE_FILAMENT to allow the studio app to use the filament rendering backend. A separate MUJOCO_USE_FILAMENT_VULKAN flag can be used to enable vulkan rendering.

PiperOrigin-RevId: 824602367
Change-Id: I26d46c16211ae2118f96c163c4194fea5b5a15a9
2025-10-27 11:26:14 -07:00
Taylor Howell 85e9cff0c1 Update mj_geomDistance: don't flip geoms for nativeccd.
PiperOrigin-RevId: 824463375
Change-Id: Ic9c4cac916129b88575e0366e1b95353ce716ca2
2025-10-27 04:48:36 -07:00
Saran Tunyasuvunakool 49a3caf84c Modify SimulationState proto to correspond to mj_getState.
PiperOrigin-RevId: 823494487
Change-Id: Ib284e3165ca691f5b690a376f7b28e51122e1bc4
2025-10-24 05:51:07 -07:00
Alessio Quaglino ec8ad21cb5 Normalize triangle coordinates such that their sum rather their norm is one.
This ensures that at e.g. the barycenter of the triangle each vertex has weight 1/3, as one would expect with barycentric coordinates, rather than 1/sqrt(3). This makes it consistent to the finite element interpolation used in the passive elastic forces.

PiperOrigin-RevId: 823458736
Change-Id: Ia5c02cba186a80612de38402f791695c33e991ab
2025-10-24 03:42:55 -07:00
Haroon Qureshi 99c18f07d3 Increase buffer size.
The smaller size is a warning/error on some targets:

```
error: ‘ bytes’ directive output may be truncated writing 6 bytes into a region of size between 0 and 15
```
PiperOrigin-RevId: 823047552
Change-Id: Id66b5828cf84a512dffc452753f1881deb685584
2025-10-23 08:16:54 -07:00
Haroon Qureshi 1fd9b47fea Prefix assets path with "assets/".
PiperOrigin-RevId: 823044312
Change-Id: I0bde4428bd1992d6d4356e107dac471fa7cdecc6
2025-10-23 08:07:33 -07:00
Sam Haves febe75d54b Add tendon.cpp to mjcPhysics CMake
PiperOrigin-RevId: 822694422
Change-Id: Ic2f7c7a3b85526d49eb98c19118e6936ccb4e0f7
2025-10-22 12:30:16 -07:00
Sam Haves ae33724de1 Set info string on wrap instead of tendon when wrapping a prim in the path.
PiperOrigin-RevId: 822688877
Change-Id: I04f5f5576cc0ed43e0ec77d5fccb19d2d23d7349
2025-10-22 12:13:53 -07:00
Sam Haves 160b9480f9 Add support for tendons to mjcPhysics.
PiperOrigin-RevId: 822230926
Change-Id: I232a9fbfb473186ac742d210458ff0221a561126
2025-10-21 12:30:12 -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
Saran Tunyasuvunakool 2f65e23779 Add mj_extractState as a public API function.
This function allows the caller to extract a subset of components of a state previously obtained via `mj_getState` without having to first write it back into `mjData`.

PiperOrigin-RevId: 822165077
Change-Id: I6433261f4f5ec2e8d024bb7dee8f7dbf1e62666c
2025-10-21 10:01:22 -07:00
Kyle Bayes 25f5be82ff Provide option to disable keyboard events for SDL.
PiperOrigin-RevId: 822154396
Change-Id: Ie4c8537de2c4b01437aae00ed6d6af1a8f419a73
2025-10-21 09:36:16 -07:00
Sam Haves 09682ade4b Fix mjcPhysics island flag default.
PiperOrigin-RevId: 822088739
Change-Id: If3a87976dd319502160fd886a1823c12d72bebf1
2025-10-21 06:27:28 -07:00
Alessio Quaglino 01d1ac34e0 Add quadratic interpolation to flex.
PiperOrigin-RevId: 822055781
Change-Id: Ibc252ac560de666b0b28f868e46b88d3ed92f67d
2025-10-21 04:36:36 -07:00
Sam Haves 59f14485e0 Move mjCWrap type to mjsWrap.
PiperOrigin-RevId: 821851540
Change-Id: I53382a8a21312a96aea46eec130f43e7cad70f92
2025-10-20 16:28:41 -07:00
Matija Kecman 88ac02dad3 Add UI to visualize the State
PiperOrigin-RevId: 821641514
Change-Id: I41fd5602d0d52162b374149fb0080f6c387d7847
2025-10-20 07:32:41 -07:00
Haroon Qureshi e75c5aa83c Fix various include paths.
PiperOrigin-RevId: 821564663
Change-Id: Ic84489b7f3e1ba97810f60049dcf2f4a4d31edcf
2025-10-20 02:55:22 -07:00
Alessio Quaglino ff7c94de8a Add quadratic interpolation to mju_interpolate3D.
PiperOrigin-RevId: 820252349
Change-Id: I983175eb51d7e1a81da06c0911326fcb8f5fe764
2025-10-16 08:48:20 -07:00
Haroon Qureshi 87adb7e5d6 Use the ImGui OpenGL3 backend.
PiperOrigin-RevId: 820249390
Change-Id: I43fc85bf75a2c01b76218a2ff67a1526ee9e2bdb
2025-10-16 08:39:51 -07:00
Alessio Quaglino ffdfe542cf Add mju_interpolate3D.
This is a more general API in preparation of a higher interpolation order

PiperOrigin-RevId: 820174741
Change-Id: I81bd52ab44e0485d72579e21d1c8a48a1b35ec3f
2025-10-16 04:39:24 -07:00
Gabe Oppenheimer 48f10bfcb6 Update MuJoCo to v3.3.8 following the 3.3.7 release.
PiperOrigin-RevId: 819919328
Change-Id: Ib34f959f6f8efd83362d49e784aa8e0594036899
2025-10-15 14:39:05 -07:00
Kyle Bayes 8cbfc42767 Fix issue with zero size cache.
PiperOrigin-RevId: 819773517
Change-Id: Iff1523e17ffbd1dff02bee71db896c64bd8b565c
2025-10-15 08:46:00 -07:00
Yuval Tassa 5715cebbb9 MSAN: Don't clear mjData.sensordata in mj_resetData
This is strictly an out array and should not be read before it is written to. This change improves MSAN coverage of engine code.

PiperOrigin-RevId: 819767673
Change-Id: I57500c8147f4774d326cf87ea3bac5420e4dd54d
2025-10-15 08:31:03 -07:00
Haroon Qureshi 9174c87203 Minor fixes.
PiperOrigin-RevId: 819680566
Change-Id: Ie2480eab3c974227268222190fdb84ed671303f2
2025-10-15 04:07:36 -07:00
Alessio Quaglino b6f25ca623 Check mjs_getName return value in XML parser. Fixes #2898.
PiperOrigin-RevId: 819351410
Change-Id: I0807d71328068f6388991ae15274c7d61b4d3e53
2025-10-14 12:40:28 -07:00
Haroon Qureshi f1d45bd542 Fix minor formatting issues and use nullptr consistently.
PiperOrigin-RevId: 819178621
Change-Id: I3f6bfb6888075188d49e32110af2074b07c6b918
2025-10-14 06:15:57 -07:00
Gabe Oppenheimer ae1febd83f Automated g4 rollback of changelist 818694877.
*** Reason for rollback ***

BEGIN_PUBLIC
Holding off on a minor version bump until the next release.

*** Original change description ***

#mujoco update the version to 3.4.0 ahead of the 3.4.0 release.

Bump the version to 3.4.0 ahead of the next release.

***

PiperOrigin-RevId: 818748143
Change-Id: I722e9beb80c61a48bd997da6a1840777a81d5036
2025-10-13 11:14:42 -07:00
Gabe Oppenheimer 02d2d4d49a Bump the version to 3.4.0 ahead of the next release.
PiperOrigin-RevId: 818694877
Change-Id: I42e261956a0219e549bec6a54cbf330a74f02f9f
2025-10-13 09:22:49 -07:00
Yuval Tassa bbeb0b95a7 Reset contact efc_address in mj_clearEfc, fixes #2869
The truth is that all these solver-related values should be moved out of `mjContact` altogether, but that can be done in a future followup.

PiperOrigin-RevId: 818624976
Change-Id: I5b9e63927098cdf26b9f8acfdd9d86e75d6ce331
2025-10-13 06:18:41 -07:00
Haroon Qureshi 9b7e7e471d Add line and linebox geom primitives.
PiperOrigin-RevId: 818570050
Change-Id: If02873dd878a23b442368ce69bc024e0310e9d02
2025-10-13 02:59:13 -07:00