Commit Graph

967 Commits

Author SHA1 Message Date
Kevin Zakka 77ce80bc63 Fix swapped vertical frustum bounds for cameras with principal point offset.
The frustum_top and frustum_bottom assignments in mjv_updateCamera used
the wrong elements of the zver array, causing the principal point cy
offset to be applied with an inverted sign. This shifted the rendered
image vertically by 2*cy pixels.
2026-03-04 01:03:55 -08:00
Kyle Bayes a06c091157 Fix repeated call to restrict pointer.
PiperOrigin-RevId: 877451707
Change-Id: I4849ccb8562ea1926173209da9934c11de64a109
2026-03-02 10:03:19 -08:00
Kyle Bayes d00ddea269 Merge mjc_ccdIteration into mjc_penetration.
PiperOrigin-RevId: 877432442
Change-Id: I6bffb36522f9e4f0e7b1023003e70df064e1ebb7
2026-03-02 09:17:56 -08:00
Alessio Quaglino bf74d01d93 Add collisions between flexes and SDF geoms.
The flex-SDF algorithm uses the same logic as mesh-SDF. Previous to this change, the flex was instead colliding with the convex hull of the mesh generated automatically with marching cubes from the SDF.

PiperOrigin-RevId: 876420302
Change-Id: I3bf6552b6b8e108ba4c4209bbcf10fe5f2b2fd90
2026-02-27 14:35:27 -08:00
Alessio Quaglino c2e67ab507 Refactor Mesh-SDF collision to use farthest point sampling and mjMAXCONPAIR.
Deleted MAXMESHPNT farthest point sampling instead of sorting by penetration distance is now used to select the best contact points, up to mjMAXCONPAIR. Deleted MAXSDFFACE, the BVH traversal now directly calls a function to process each leaf face against the SDF, instead of collecting face indices and processing them in a separate loop. This reduces memory by removing the need to store all intersecting face indices.

PiperOrigin-RevId: 876296914
Change-Id: I8068d634e2a01ffa9357d0c5381219d097e97abe
2026-02-27 09:42:16 -08:00
Alessio Quaglino 47a750d4a6 Restore mesh-SDF collisions.
This CL rolls back the change from changelist 794576123 since the previous version was more robust and stable. Compared to the original algorithm, this changes handles degenerate and very large triangles as well.

BEGIN_PUBLIC
Restore mesh-SDF collisions.
END_PUBIC

PiperOrigin-RevId: 875716983
Change-Id: If0de41dc7bbd60460779821d2338cf2d661f40d5
2026-02-26 07:39:34 -08:00
Copybara-Service 19b583a421 Merge pull request #3134 from kevinzakka:sensoracc-rnepost
PiperOrigin-RevId: 875703097
Change-Id: I564c1afa1cc1f88a712984c6714611056f6e26eb
2026-02-26 06:58:48 -08:00
Yuval Tassa 7232ec3b47 Refactor constraint tree iteration and island assignment.
- Simplified constraint tree discovery with a unified iterator.
- Filling in a new `efc_tree` array to avoid calling tree discovery again in the constraint phase.
- Implemented dof skipping in the dense case for efficiency.

PiperOrigin-RevId: 875440387
Change-Id: Id44a5a6fe2a80edaaf30935506a023a307e21303
2026-02-25 18:48:59 -08:00
Kevin Zakka 43cde9716c Fix mj_sensorAcc returning zero after mj_step1 by clearing flg_rnepost in mj_step2.
Fixes #3133.
2026-02-25 14:04:33 -08:00
Taylor Howell 53fadd9d63 Improve nJmom by counting number of dofs for slidercrank and site transmissions
PiperOrigin-RevId: 875233737
Change-Id: I2cf3afad7e29e176a4f5a917dd35cfad99b2b0a3
2026-02-25 10:41:24 -08:00
Yuval Tassa 0c66585e39 Fix typos and minor corrections in MuJoCo documentation and comments.
PiperOrigin-RevId: 875163889
Change-Id: Ic604d6235bf9cb999058f191e3ee41e47ec1a567
2026-02-25 07:56:31 -08:00
Taylor Howell 52ed96bc3a Move tendon sparsity fields from mjData to mjModel
PiperOrigin-RevId: 875087590
Change-Id: I1a5489d2d2011795ee38b09d547e68acd72e3cc7
2026-02-25 04:32:11 -08:00
Kyle Bayes 84205f7dd0 Isolate libccd logic in mjc_penetration.
PiperOrigin-RevId: 875073780
Change-Id: I71bd39695aa667110fffff47f34cd98faa562cc6
2026-02-25 03:53:34 -08:00
Alessio Quaglino f9a39413cf Fix: Include ancestor DOFs in flex interpolation factorization.
The reduced dense factorization for flex interpolation now considers all DOFs in the kinematic chain of the body containing the flex, using mj_bodyChain, instead of only the DOFs directly associated with that body. This is necessary for correctly handling pinned flexes when their parent body is part of a larger kinematic structure.

PiperOrigin-RevId: 872854468
Change-Id: Idbe9fb459084dde9e8eb1076c70dbb685c1b0bdb
2026-02-20 05:30:54 -08:00
Alessio Quaglino 8ba68cee3e Limit the number of flex contacts per collision pair.
This change introduces a filter for flex-related contacts, ensuring that no more than mjMAXCONPAIR contacts are kept for each geom-flex, flex-flex, flex internal, and flex self-collision pair. The contacts are sorted using farthest-point sampling:

- Starts with the deepest penetrating contact
- Iteratively selects the contact farthest from already-selected contacts
- Produces a spatially distributed set of contacts

PiperOrigin-RevId: 872593388
Change-Id: I50b233a0dc66da6a297852c258ba514f131c8f23
2026-02-19 15:32:17 -08:00
Taylor Howell 9efe41c0c1 Remove dense code path for tendon Jacobian
PiperOrigin-RevId: 872444531
Change-Id: I6180101abc49469a72aee8bec5726e1e94f142ec
2026-02-19 09:53:49 -08:00
Alessio Quaglino 8024124572 Use stack allocation for temporary flex rigidity storage in mj_setConst. Fixes #3081
PiperOrigin-RevId: 871200819
Change-Id: Ifbc1c0bd62261325a06a246cb2adb1106c02f829
2026-02-17 02:16:07 -08:00
Copybara-Service 160e601ba1 Merge pull request #3085 from Ashutosh0x:fix/windows-zero-alloc
PiperOrigin-RevId: 870765044
Change-Id: I91b6a6096fe58200f8b36fda62838046a9ee08fe
2026-02-16 01:47:04 -08:00
Saran Tunyasuvunakool 5274e5f720 Clean up X macros and usages for mjOption, mjStatistic, and mjVisual.
* Replace various MJOPTION_ macros with a single MJOPTION_FIELDS.
* Use XVEC macro to denote vector members where there is a mixture of
  vector and scalar members in a given struct type.
* Split up MJVISUAL_FIELDS into separate macros for each substruct.
* Modify engine_print.c and Python bindings struct.h/cc to use the
  new X macros.

PiperOrigin-RevId: 869760513
Change-Id: Idac4fe9aa99f0258e7c79802ca9023a0d4486e2d
2026-02-13 09:10:36 -08:00
Taylor Howell 5903d4826f Sparse ten_J and ten_J_colind
PiperOrigin-RevId: 869712136
Change-Id: Id2979684aa0c39552cb8453852483cbac55f0ea3
2026-02-13 06:57:22 -08:00
ashutosh0x 04e5df08a9 Update mju_malloc to return NULL for zero-sized allocations 2026-02-13 19:22:05 +05:30
Michael Moss 42958aab81 Update MuJoCo version from 3.5.0 to 3.5.1 following the 3.5.0 release
PiperOrigin-RevId: 869654894
Change-Id: I9cacaf4cbb70ad17faa24c3c30ec38ffe91b5deb
2026-02-13 03:54:25 -08:00
Yuval Tassa c54f1fe380 Use semantic versioning.
PiperOrigin-RevId: 869102767
Change-Id: I8b01b9343289d4ad7d15bcc3634a28e661308a90
2026-02-12 02:11:20 -08:00
Yuval Tassa 6af0d4c823 Replace margin/gap max with sum.
PiperOrigin-RevId: 868842521
Change-Id: Ia4a4ca5c6821c5a7b3ba7b0af7f71d981c2866c1
2026-02-11 14:22:27 -08:00
Google DeepMind 336e1026a4 Sparse ten_J and ten_J_colind memory
PiperOrigin-RevId: 868834376
Change-Id: Iec92d9e09e3134666895e54a78cb02439d74a4de
2026-02-11 14:05:43 -08:00
Yuval Tassa b466829482 Fix implicit integrator derivatives when actuator force is clamped.
The derivatives of actuator velocity with respect to generalized velocities were incorrectly computed when the actuator force was limited by `forcerange`. This CL adds a check to zero out these derivatives when the actuator force is at its upper or lower limit, as the force is no longer a function of velocity in this clamped state.

PiperOrigin-RevId: 868818281
Change-Id: I89742a3f04989dd11f9cfada107200015b1472a7
2026-02-11 13:31:07 -08:00
Taylor Howell d011285380 Sparse ten_J and ten_J_colind memory
PiperOrigin-RevId: 868800229
Change-Id: Id83f9fd40dd9bece06fd99753e4202eea17ca884
2026-02-11 12:45:50 -08:00
Yuval Tassa 2b5afce4aa Fix island graph construction for multi-tree constraints, fixes #3073
Replace dynamically-sized edge list with a dense ntree×ntree adjacency matrix for deduplication and a flat CSR representation.

PiperOrigin-RevId: 868728432
Change-Id: Iebe97a0870740e5465549b967bbde0c81e658269
2026-02-11 10:05:32 -08:00
ashutosh0x c962188655 Fix zero-sized allocation crash on Windows
On Windows, _aligned_malloc(0) returns NULL, which MuJoCo interprets as a fatal out-of-memory error. This causes crashes on models with empty arrays.

Ensure a minimum allocation of 64 bytes for any 0-sized request.

Fixes #2992
2026-02-11 22:33:28 +05:30
Copybara-Service e9de358bfc Merge pull request #3076 from yurekami:fix/plugin-symlink-loading
PiperOrigin-RevId: 868602117
Change-Id: Ice4d7991f46dad45736864baebd7378cc24e9d4f
2026-02-11 04:13:41 -08:00
Yuval Tassa 7f74487a26 Fix implicit integrator derivatives for actearly actuators.
The derivative calculation for actuator velocity in implicit integrators now correctly accounts for the `actearly` flag, using the next activation value when `actearly` is true.

PiperOrigin-RevId: 868598722
Change-Id: Ia180afb15b31a718170aeaf9d4ac514bb9e6073b
2026-02-11 04:03:46 -08:00
Yuval Tassa 4fa062c7e5 Update unreleased MuJoCo version from 3.4.1 to 3.5.0.
PiperOrigin-RevId: 868169291
Change-Id: I8041842811f5f664c80116993315f50d549b5575
2026-02-10 08:52:04 -08:00
Alessio Quaglino e16ee4fcb4 Fix flex-parent coupling in implicit integrator.
The implicit integrator was not correctly accounting for the off-diagonal coupling terms between flex and non-flex (parent) degrees of freedom in the mass matrix. This change extracts these coupling terms during the factorization step and applies a correction to the flex forces before solving for the flex accelerations, ensuring that the parent accelerations influence the flex dynamics. A new test verifies that the implicit integrator now matches Euler for small timesteps in a model with flex-parent coupling.

PiperOrigin-RevId: 868098126
Change-Id: Ia8cccd7dd428cd0c0898e1663a7e41017a2311b2
2026-02-10 05:35:48 -08:00
Alessio Quaglino 0041fdcbb0 Add implicit stiffness for flex_interp to mj_implicitSkip.
PiperOrigin-RevId: 867706885
Change-Id: Ic94c65b618a415609bffe3d69a86f9034f2d2400
2026-02-09 11:54:27 -08:00
Yuval Tassa c1b3b3063e Fix gravcomp being ignored for movable bodies without joints. Fixes #3066
PiperOrigin-RevId: 867679545
Change-Id: I8c16d3a4c93d121fcc30cab5179ba44fe49aaa19
2026-02-09 10:55:07 -08:00
Yuval Tassa d680b3d234 Rename "delay" buffer functions to "history" buffers.
The functions and associated tests related to managing time-stamped data buffers have been renamed from `mju_delay*` to `mju_history*` to better reflect their general purpose beyond just handling delays.

PiperOrigin-RevId: 866978339
Change-Id: I8655e91bce783287ad2adc412d13a1c39aa2c322
2026-02-07 14:10:16 -08:00
yurekami 3497b7658c fix: resolve symlinks when loading plugin libraries
Use stat() instead of d_type to check if a file is a regular file
when scanning for plugin libraries. This allows symlinked plugins
to be loaded, which is common in ROS 2 workspaces built with
colcon build --symlink-install.

The stat() approach also handles filesystems that report DT_UNKNOWN
for d_type (e.g., NFS, XFS), making the code more robust.

Fixes #3072
2026-02-07 02:45:22 -08:00
Yuval Tassa 6419534bad Add actuator and sensor delays. Fixes #1004
PiperOrigin-RevId: 866478839
Change-Id: Id21a6da0f98454c8fa39ea5af8a5e213d6eae497
2026-02-06 08:47:36 -08:00
Yuval Tassa 84fa527723 Add delay buffer utilities to engine_util_misc.
PiperOrigin-RevId: 866450284
Change-Id: I86d6dd6a6f7519640f75ca405fb60a12e8619c86
2026-02-06 07:22:34 -08:00
Kyle Bayes 1a9ca3239a Replace comma operator with semi-colon.
PiperOrigin-RevId: 865353927
Change-Id: I3498d8dc17f96caf8fa1975613ed6a815d2f20e7
2026-02-04 05:14:17 -08:00
Alessio Quaglino a54c9f1d78 Specialized box and capsule collision primitives for stable 2D flex interactions.
PiperOrigin-RevId: 864500749
Change-Id: I52aed6e29569477a8a0b6b5eb55ad483f1077c0e
2026-02-02 13:36:42 -08:00
Yuval Tassa 815dbb996e Use body_weldid to find the first movable body in a chain.
PiperOrigin-RevId: 863774053
Change-Id: I8df96d5af7cc80d78a6f35560c3c31bed8be550e
2026-01-31 17:16:36 -08:00
Yuval Tassa 19ff06155a Refactor sensor computation into per-sensor functions.
PiperOrigin-RevId: 862180688
Change-Id: I9f3f4da8ca8abed778965fd3970171276ee4570d
2026-01-28 05:04:59 -08:00
Yuval Tassa 1d2d0b1c37 Remove batching optimization from GEOM* sensors
PiperOrigin-RevId: 861938606
Change-Id: Ibb135a4d99cab9ce23a04f844f7c730e8f3b31c8
2026-01-27 16:44:10 -08:00
Yuval Tassa 5fb47df197 Add mjData flags marking lazily evaluated pipeline stages
PiperOrigin-RevId: 861763477
Change-Id: Ib613c56949264573a16306800658f868d2aa7665
2026-01-27 09:45:06 -08:00
Alessio Quaglino ba32568138 Move flex vertex-edge adjacency to mjModel.
PiperOrigin-RevId: 861717037
Change-Id: I2ad8090b0318cb04b43d13966cb42260c82ef930
2026-01-27 07:41:47 -08:00
Yuval Tassa e787f8717d Change not required, issue was addressed in e48da1e38c
PiperOrigin-RevId: 861680071
Change-Id: I374f091cd2686737e53234ca0edc8703897fbd4a
2026-01-27 06:01:14 -08:00
Alessio Quaglino e933081ff1 Optimize flexvert Jacobian computation.
The dense Jacobian arrays `J0_dense` and `J1_dense` are now zeroed only once before the vertex loop. Inside the loop, only the entries that were actually used are zeroed out after being added to the sparse Jacobian, allowing for efficient reuse of the dense arrays across all vertices.

PiperOrigin-RevId: 860799056
Change-Id: Ia61daae5eeb2f4dbc0c5d8c0064622a881e92b7a
2026-01-25 05:22:44 -08:00
Alessio Quaglino e9c61694e1 Align flex_vert0 to the XY plane during model initialization if dim=2.
PiperOrigin-RevId: 860435368
Change-Id: Ida616e1e69c224f7c0dbad2a10dd59e64cbadf49
2026-01-24 00:50:01 -08:00
Alessio Quaglino 769109630f Move flexvert_J and flexedge_J sparsity pattern to mjModel.
PiperOrigin-RevId: 860392796
Change-Id: Ie1264f2df5bf04b5794a3c7d8ad1a92524a6a567
2026-01-23 22:00:14 -08:00