Commit Graph

252 Commits

Author SHA1 Message Date
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 d2501eff68 Use procedural model creation in plugin tests.
This will be useful for simplifying the mjSpec API for plugins.

PiperOrigin-RevId: 772505558
Change-Id: I8eb57d7e129e0f6430fb4c610a543e0dc0f3b295
2025-06-17 09:30:54 -07:00
Alessio Quaglino b8768aa1cd Allow to fusestatic a body if it doesn't generate a referencing error.
PiperOrigin-RevId: 769189929
Change-Id: I62f512813ea330da088b28d39373df39be10a602
2025-06-09 10:05:57 -07:00
Alessio Quaglino 7932b4b202 Accumulate inertial in mjs_bodyToFrame.
PiperOrigin-RevId: 765129145
Change-Id: Ib7caca42ef4272ebe762655eee9380dae471be7f
2025-05-30 04:10:38 -07:00
Google DeepMind 568620dd2f Add texture attribute to lights.
PiperOrigin-RevId: 763739805
Change-Id: I333ed2ac68f30f79f688ca01d7b5fd6bf2d836c9
2025-05-27 05:04:01 -07:00
Sam Haves 924ee3070a Modify user values in mujoco to allow users to provide cleanup functions to avoid memory leaks.
For the MJCF -> USD plugin, and I suspect other usecases for user values, it's necessary to give ownership of the object to Mujoco. However since they get type erased, we can't clean up the data automatically for the user. Instead this allows c++ clients to provide a cleanup function with their data.

PiperOrigin-RevId: 756832010
Change-Id: I80b8e7822e1a0e399a0d19dcaa57ee69b3ccc16a
2025-05-09 11:03:06 -07:00
Alessio Quaglino ad80a4625b Always generate a BVH in flex.
The BVH is used also for computing normalized vertex coordinates in the trilinear interpolation, so we need to compute it also when the flex cannot collide.

PiperOrigin-RevId: 756349244
Change-Id: Ib397c472e31251df5a7ea85850d83a62f3b2c949
2025-05-08 09:46:47 -07:00
Kyle Bayes f4774a5449 Fix bug in cached meshes where convex hull was missing. Previously if a mesh was copied from the cache it would not have its convex hull if the original mesh that was cached didn't previously compute it.
Fixes #2609

PiperOrigin-RevId: 756223337
Change-Id: I54705456636c270607a17340b249047e0df75d0b
2025-05-08 02:42:15 -07:00
Mohammad Hamid 3429a4881a Detect mismatch between maxNodes and Nodes in a gmsh block. Fixes #2342
PiperOrigin-RevId: 745967745
Change-Id: If1b5fcd71079a0e6a6def9b442758678e31a5828
2025-04-10 04:15:21 -07:00
Taylor Howell 96dda6ea75 Add tendon actuator force limits and tendon actuator force sensor.
PiperOrigin-RevId: 745096883
Change-Id: Ib9acb727fbbfc6b0b0323ee6a889053a7a878056
2025-04-08 05:16:35 -07:00
Alessio Quaglino d7027fb1c0 Do not skip mjSpec's with repeated model names when attaching a new mjSpec.
PiperOrigin-RevId: 744705838
Change-Id: Ie47a3c029f443910629619b7f9ff43ab07646725
2025-04-07 06:52:12 -07:00
Alessio Quaglino cc2f57d820 Change mjSpec and mjModel signature mechanism.
The signature now contains the necessary information to safely perform `bind`. The private UIDs are now removed.

Fixes an issue of changing signature when compiling a copy of an mjSpec.

PiperOrigin-RevId: 744670626
Change-Id: Id3c66419cf2afbe78e91bc4b37d2299f5ec00ab1
2025-04-07 04:21:27 -07:00
Alessio Quaglino 8941f56e86 Copy UIDs during mj_copySpec.
This will produce the same mjSpec signature after a deep copy.

PiperOrigin-RevId: 743538018
Change-Id: Ic0f5b06a00e8883cb92dc98159db3bea02cb7a36
2025-04-03 06:29:07 -07:00
Yuval Tassa e5912c3ce4 Use tolerance to compare quaternion components in UserObjectsTest.Inertial
Fixes #2515

PiperOrigin-RevId: 742704324
Change-Id: Ib26891e43128e66d2ac1840ed574285781fb12a5
2025-04-01 08:12:01 -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
Alessio Quaglino 648a03c2cf Override inertia of body with visual geoms if discardvisual is true.
Fixes #2546.

PiperOrigin-RevId: 742650702
Change-Id: I753c1e1c89da732ece100676644bbecf9d6373bb
2025-04-01 05:21:48 -07:00
Alessio Quaglino 01d4c46753 Store the mjsCompiler -> appended mjSpec map when appending an mjSpec.
Previously, we stored the source `mjSpec` during a copy as a hack for having access to the compiler options, but this is not robust since we cannot guarantee that 1) the source `mjSpec` is not destroyed before we need to look up the compiler options nor 2) that the `mjSpec` was appended without a copy.

While 2) could be solved by simply handling an additional case in `mjCModel::FindSpec`, using a map also solves 1) and it is easier to understand.

PiperOrigin-RevId: 741504264
Change-Id: Iab1bfd9e61299a94fa8caf3a244c067b09d54384
2025-03-28 06:27:22 -07:00
Alessio Quaglino dc96ed6bdb Remove plugins that are not referenced after detaching a body.
Fixes #2497.

Also, use `Release()` instead of `delete` for removing elements when detaching a body in order to preserve correct reference count.

PiperOrigin-RevId: 739133888
Change-Id: I7ccfad84446fb15259bad30c4ba1e6f7fa601518
2025-03-21 04:34:05 -07:00
Tom Power 8d92a0fbe6 Clear body subtreedofs when compiling. Fixes issue when attaching previously compiled model.
PiperOrigin-RevId: 738906593
Change-Id: I74875b4d07c422e397358dff5daf6682ec1bd655
2025-03-20 12:52:36 -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 209d2bd2c5 Added functionality for user payload data in mjSpec.
PiperOrigin-RevId: 738343134
Change-Id: I6217362ced9993afcd5a2914c78718ffe3bf753a
2025-03-19 04:36:00 -07:00
Alessio Quaglino 35774706ee Set parent frame of new frames after copying all frames.
PiperOrigin-RevId: 737620918
Change-Id: I8f49570cab39bd84b2da908d3683dddc3b29cb3c
2025-03-17 08:19:04 -07:00
Alessio Quaglino 775c45c60e Do not lookup compiler options by name when attaching.
Also, fix a pre-existing bug that caused incorrect compiler option propagation with nested attachments.

Fixes #2480.

PiperOrigin-RevId: 736156202
Change-Id: Ib430493e8c60556c2312603198587b39de9b8a4a
2025-03-12 09:18:47 -07:00
Alessio Quaglino 019e0a806c Throw an error if a child attached by reference to a parent is compiled.
Fixes #2482.

PiperOrigin-RevId: 735665098
Change-Id: Ia3436fdd2ff572f8f0c1ded434742a4a9186f2f7
2025-03-11 01:24:17 -07:00
Alessio Quaglino 14dc6fd33b Do not use inertia during mesh compilation.
Fixes #2479.

PiperOrigin-RevId: 735387473
Change-Id: Ib241f2a0efc100bbe2cec24e0399bfcc87268094
2025-03-10 08:35:33 -07:00
Alessio Quaglino adc3cc06fa Change private->public spec for error checking in mjCSkin recompilation.
Fixes #2485.

PiperOrigin-RevId: 735323174
Change-Id: Ifcc2055f6a74afaa18ad5228633f36f760adcffd
2025-03-10 04:19:40 -07:00
Kyle Bayes 4d024f9421 Convert internal representation of vertices to double. Also replace remove duplicate vertices with fast hash implementation.
PiperOrigin-RevId: 734516595
Change-Id: Ic78556688d5f2b75d69cd286b8d060e2cdeb7c48
2025-03-07 05:17:49 -08:00
Alessio Quaglino 7651cb1b33 Copy texture coordinates from OBJ into flex. Fixes #2464.
PiperOrigin-RevId: 732109960
Change-Id: I506b3540ab5d489ce8f10d0c473919611ccb654a
2025-02-28 06:04:19 -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 ed7adf3d17 Do not namespace the body that contains the frame during mjs_attachFrame.
PiperOrigin-RevId: 730912252
Change-Id: I026993af648766c09d569709d268430207d83169
2025-02-25 09:16:44 -08:00
Alessio Quaglino ce82b63155 Add mjs_attachFrameToSite.
This is required in preparation of changing the spec.attach behavior in the Python bindings.

PiperOrigin-RevId: 730810198
Change-Id: I095808f0afe62b5bbd27201ed5c75804e0e9c4bf
2025-02-25 03:21:05 -08:00
Alessio Quaglino c52d1b3941 Remove the particle composite (replaced by replicate).
PiperOrigin-RevId: 730089997
Change-Id: If8d18fb56ae01241e76f84dbf7951e034026d829
2025-02-23 03:14:11 -08:00
Alessio Quaglino 0fcd20f0da Remove grid from composite types.
Replaced it with flexcomp in the models.

PiperOrigin-RevId: 730070619
Change-Id: Icbc69e4c6784c6252743f689a1eafb6482d0c393
2025-02-23 01:31:41 -08:00
Tom Power 78a4d2f389 Fix mass/inertia checking for moving bodies with nested children.
Previously, we only checked immediate children of moving bodies.

PiperOrigin-RevId: 726999705
Change-Id: I133a557daf86223b8751c6d46e25809781e168a1
2025-02-14 11:26:28 -08:00
Tom Power 89253d957d Changes to inertia inference from meshes.
PiperOrigin-RevId: 726051033
Change-Id: I6edfc118280d103a2dd9d07f29f0094858769761
2025-02-12 07:43:13 -08:00
Alessio Quaglino c1ecc50081 Store joint damping and stiffness in the private spec when springdamper is used in the public spec.
PiperOrigin-RevId: 724288204
Change-Id: I7341d5d804e1ea73ded48b8b447addd4e124ab97
2025-02-07 03:55:24 -08:00
Alessio Quaglino fe16c27555 Always compute the convex hull if the mesh inertia is set to convex.
PiperOrigin-RevId: 723477903
Change-Id: Ibc50d62741f47a5b96a648efd8fb244810664c17
2025-02-05 05:52:10 -08:00
Alessio Quaglino 7cdf180641 Introduce trilinear flex parametrization.
These flexes use only 24 DOFs (3 per vertex of the bounding box), while colliding with the full high resolution mesh.

On an 8x8x8 cube, the performance using DOFs at all vertices is

```
 Simulation time      : 18.74 s
 Steps per second     : 533
 Realtime factor      : 0.53 x
 Time per step        : 1874.4 µs

 Contacts per step    : 114.88
 Constraints per step : 3322.51
 Degrees of freedom   : 1536
```

With the new implementation, it is the following:

```
 Simulation time      : 1.82 s
 Steps per second     : 5507
 Realtime factor      : 5.51 x
 Time per step        : 181.6 µs

 Contacts per step    : 38.84
 Constraints per step : 155.36
 Degrees of freedom   : 24
```

PiperOrigin-RevId: 721008829
Change-Id: I833df027527db578d86667cc4b24295bcf6f7d22
2025-01-29 09:38:22 -08:00
Alessio Quaglino 21d97902ee Check keyframe size before appending it during attach.
Fixes #2365.

PiperOrigin-RevId: 718455748
Change-Id: I20c56b7c6fbd868962d19682e72e6294edb6893e
2025-01-22 11:09:49 -08:00
Alessio Quaglino c2138c3fb0 Do not copy the spec during attach.
Use a reference count for managing the memory.

PiperOrigin-RevId: 716169486
Change-Id: Id270c4858c17b9250115e9544d5ea143584e2d5f
2025-01-16 03:53:17 -08:00
Alessio Quaglino f7d38dac62 Add recursive call to FindSpec for handling nested attachments.
PiperOrigin-RevId: 713629578
Change-Id: I23efa5a86bac187fc42eb955d29cc03cbacfd9e0
2025-01-09 04:56:12 -08:00
Alessio Quaglino 6654d63438 Add spec lookup in the attached spec array using the compiler option pointer.
This enables to find the spec associated with the compiler option stored in the objects, which do not necessarily belong to the model that owns them.

PiperOrigin-RevId: 713259419
Change-Id: I579c770147ff07ed2a5edd20e7a795ee7cc27147
2025-01-08 05:44:00 -08:00
Alessio Quaglino f607d9554e Check that there are no pending keyframes while writing a spec.
This can happen when a body is detached without compiling or recompiling.

Also added error catching when trying to delete a body instead of detaching it.

Fixes #2327

PiperOrigin-RevId: 712526730
Change-Id: I4b48df83120fca12d475c85b3a54893841449653
2025-01-06 07:50:30 -08:00
Alessio Quaglino 65048d6b8f Do not use fast lookup for frames.
Fast lookup is not possible since mjOBJ_FRAME > mjNOBJECT, which is the size of the objects maps used for the search.

Fixes #2328.

PiperOrigin-RevId: 712479460
Change-Id: I7bcfa75ff8a1e288183d60ed4a44cab5bc6f4173
2025-01-06 04:17:41 -08:00
Silvio 756a8d716a Reduce cmake test boilerplate
All instances of mujoco_test in the code base were followed by
a call to  target_link_libraries(<testname> fixture gmock).

As anyhow mujoco_test already was calling target_link_libraries
to some predefined list of targets (mujoco and gtest_main),
this PR adds to the list of default linked targets also fixture
and gmock, to reduce the boilerplate.

Furthermore, to completly remove the need for calling
target_link_libraries after a call to mujoco_test, this PR also
add to the mujoco_test macro the ADDITIONAL_LINK_LIBRARIES
argument, that can be used if a given test needs to link some
additional targets beside the default ones.

To permit to use these new features also for mujoco benchmarks,
this PR adds a MAIN_TARGET parameter to mujoco_test, to select
if gtest_main or another target is used to provide the main
entry point to the test executable.
2024-12-07 17:14:20 +01:00
Alessio Quaglino 10239a673b Change from parent ID to parent pointer in mjCBody.
This is required to have parent body info during attach and during body to frame tranformation for uncompiled models.

PiperOrigin-RevId: 703038426
Change-Id: Ib482059ba419a020860c649d6ea1b1088045f2e1
2024-12-05 02:32:56 -08:00
Alessio Quaglino afc86ac1b3 Associate children of deleted body to the newly created frame in mjs_bodyToFrame.
Also associate all children that need a parent body to the parent of the deleted body.

This is a bug that was causing the former children of the body that gets transformed to a frame to not be children of the new frame.

PiperOrigin-RevId: 702702853
Change-Id: I36d48f0446bc87c665b18d34e0b0609d82c70f51
2024-12-04 06:30:21 -08:00
Alessio Quaglino 82b6dbeb40 Copy attached spec before attaching anything else.
Spec were copied after bodies are attached, so the reference to the source spec got lost during mj_copySpec().

PiperOrigin-RevId: 701287267
Change-Id: I55eff53c7ae9d42b03957be48ea506b80d274e03
2024-11-29 07:41:49 -08:00
Alessio Quaglino 13b6055098 Add material namespacing to sites.
Fixes #2243.

PiperOrigin-RevId: 699713625
Change-Id: I1b45e43f2a6ccfa64c46489c9426fcc2acdc94c3
2024-11-24 08:39:29 -08:00
Taylor Howell a1b18e707a Compress actuator_moment memory using nJmom <= nu x nv.
PiperOrigin-RevId: 698446692
Change-Id: I49c9633e12129a1e690724db82d1f11204e41d9c
2024-11-20 10:53:07 -08:00