Commit Graph

113 Commits

Author SHA1 Message Date
Kyle Bayes 8cbfc42767 Fix issue with zero size cache.
PiperOrigin-RevId: 819773517
Change-Id: Iff1523e17ffbd1dff02bee71db896c64bd8b565c
2025-10-15 08:46:00 -07:00
Sam Haves 2dc533b63b Allow flipping textures with any number of channels and user provided pixel data.
PiperOrigin-RevId: 813256285
Change-Id: I0d49885dc483ab8f093b2566ec4bef355575505e
2025-09-30 07:28:13 -07:00
Google DeepMind 0e1104768a No public description
PiperOrigin-RevId: 809083979
Change-Id: I5c6641b73c76153c15f5cdf858b788e1433acc81
2025-09-19 10:10:45 -07:00
Google DeepMind 26ea20a21f No public description
PiperOrigin-RevId: 809074980
Change-Id: Ib3e3522addceddba6a057cfef80fcbd30a420b3d
2025-09-19 09:49:07 -07:00
Alessio Quaglino 77e025ea98 Move meshdir and texturedir to mjsCompiler.
For backwards compatibility in the Python bindings, both `spec.compiler.meshdir` and `spec.meshdir` are now allowed.

Fixes #2834.

PiperOrigin-RevId: 809060113
Change-Id: Ie23f1c5dd57de43568312a8e062906f4013bb474
2025-09-19 09:05:44 -07:00
Alessio Quaglino 6e7aaacb85 Do not rely on global object lists in mjCBody::NextChild().
PiperOrigin-RevId: 782963753
Change-Id: I0afecbab4b7796f077963ba66eb7140d8f83ad89
2025-07-14 10:47:45 -07:00
Alessio Quaglino af7d20c035 Change mjs_nextChild to be DFS to match XML parsing.
PiperOrigin-RevId: 778915232
Change-Id: I5e290f47b7d2530597bb6c85b66ff2ae807e5510
2025-07-03 10:07:13 -07:00
Alessio Quaglino 69ce5dbd05 Consolidate tree traversal tests in the C and Python APIs.
PiperOrigin-RevId: 778883024
Change-Id: I0d30ed011e60a6da7148cebc1f715895fd0c6fd6
2025-07-03 07:25:23 -07:00
Alessio Quaglino 594e17074a Replace name attribute with setters and getters in the C API of mjSpec.
PiperOrigin-RevId: 778816015
Change-Id: Ieffb7a5bce37e887ff009f9a02d2434435e79ca1
2025-07-03 02:30:56 -07:00
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 7932b4b202 Accumulate inertial in mjs_bodyToFrame.
PiperOrigin-RevId: 765129145
Change-Id: Ib7caca42ef4272ebe762655eee9380dae471be7f
2025-05-30 04:10:38 -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 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
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 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
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 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
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
Alessio Quaglino 821f1d3f98 Do not namespace empty actuator strings during attach.
Fixes #2233.

PiperOrigin-RevId: 698070772
Change-Id: I19613acfd407ba6a8ede40dad85324a70db480a8
2024-11-19 10:42:24 -08:00
Alessio Quaglino 45f908c165 Enable attaching plugins not instantiated in the extension section.
Fixes #2217.

PiperOrigin-RevId: 695766524
Change-Id: I534b63400810bd6ef888f39f6665213280fd93ac
2024-11-12 09:36:06 -08:00
Alessio Quaglino b941e994d9 Move keyframe resizing from compilation to attach (mjCModel::operator+=).
This allows to resize parent keyframes also when the child has no keyframes.

PiperOrigin-RevId: 691045299
Change-Id: I3ab6509b13b5754e937ec77daf9efe697cabf1bc
2024-10-29 09:17:55 -07:00
Alessio Quaglino 159f23e6b4 Remember compiler options during attach.
Note:
- Move compiler options into `mjsCompiler` struct.
- The compiler options from the attached model are not written by mj_SaveXML.
PiperOrigin-RevId: 689391440
Change-Id: I1d63c146a32f87c737b7a55b64a54b0ffe3aecc9
2024-10-24 08:31:15 -07:00
Alessio Quaglino ed7655cf97 Store a copy of the attached specs in the destination spec.
PiperOrigin-RevId: 689013340
Change-Id: I2cb7a1f3850f0e3592834b355d35dcc2cd8f150f
2024-10-23 10:20:42 -07:00
Alessio Quaglino d17d9e835c Do not delete attached specs after compilation.
Also, copy them when copying the spec.

PiperOrigin-RevId: 688998464
Change-Id: I7229fd8032eafede582194ccf73ab4160fe06768
2024-10-23 09:42:05 -07:00
Alessio Quaglino 9e1aa37b55 Do not self-attach custom tags.
Fixes #2162.

PiperOrigin-RevId: 688518165
Change-Id: Iad90e159514c96635676a8dd53fca41e3998d8fc
2024-10-22 06:04:07 -07:00
Alessio Quaglino a70aea918c Prevent duplicated pairs in active_pugins vector.
Fixes #2150

PiperOrigin-RevId: 688164615
Change-Id: I9a5434a9dda28a399ffccfe0c4b31fa64400b85f
2024-10-21 09:30:27 -07:00
Alessio Quaglino 11af1e2a95 Fix a bug in mj_recompile.
The qposadr_ and dofadr_ variables of the joints were not being reset to -1 when a joint is copied. This could lead to errors when calling mj_recompile after attaching a compiled spec.

PiperOrigin-RevId: 686152004
Change-Id: I9e058089ce87ea0d8e51a7f43475bc48c6527a26
2024-10-15 10:24:32 -07:00
Alessio Quaglino 1e7c109887 Raise warning when attaching a spec with pending keyframes to a different spec.
PiperOrigin-RevId: 685677622
Change-Id: Iba522c523ebd2afe64d6ab28c6b6b4b3cd399cf8
2024-10-14 05:54:18 -07:00