Commit Graph

55 Commits

Author SHA1 Message Date
Alessio Quaglino 157b074116 Add signature to mjSpec and mjModel and use it to perform safe bind to mjModel and mjData.
PiperOrigin-RevId: 740378879
Change-Id: If14b326942529494f172e7aedcae30195798b458
2025-03-25 09:37:49 -07:00
Alessio Quaglino da04688071 Automatically compile mjSpec in to_xml().
Also, move mj_compile from MjModelWrapper to MjSpec.

PiperOrigin-RevId: 737640210
Change-Id: I93d2a31c33eb359452b0d966a29939183b4c5198
2025-03-17 09:21:10 -07:00
Copybara-Service a7a8a68be5 Merge pull request #2496 from jjyyxx:patch-1
PiperOrigin-RevId: 736457846
Change-Id: I3b4b1554dd15e9ca73abee5c31d4758f694f5b44
2025-03-13 04:33:45 -07:00
Yuxuan Jiang 3884c86a14 Fix broken model.vis repr 2025-03-12 00:28:38 +08:00
Alessio Quaglino 5b924fec98 Add support for binding to arrays of mjs element.
Fixes #2402.

PiperOrigin-RevId: 726449592
Change-Id: I0cde44889837a71a222b20cf91fa56568b4af689
2025-02-13 06:01:30 -08:00
Yuval Tassa 2409a6e537 Add mjData.nA the number of non-zeros in the constraint inverse inertia matrix.
PiperOrigin-RevId: 714076988
Change-Id: I4c323a6e81dfb23f7972b662719bbcb688bacf4a
2025-01-10 09:23:55 -08:00
Alessio Quaglino c6ba8f27fd Add bind() method to MjModel and MjData.
This method allows users to bind a spec to a model or data object, making it less verbose to access its arrays.

PiperOrigin-RevId: 699952211
Change-Id: I6b71a88d5a6968bc0f902bd49db7c568b46a4dfb
2024-11-25 05:53:58 -08:00
Yuval Tassa c9f78ad8a8 Rename nnzJ to nJ in mjData.
This naming is more consistent.

PiperOrigin-RevId: 691858223
Change-Id: Ife3db822afa0b51b30d0792548b35b3742da388a
2024-10-31 10:43:10 -07:00
Yuval Tassa ee7b994021 Remove Newton Cholesky factor from mjData arena, rollback of b66da3d369.
PiperOrigin-RevId: 685726867
Change-Id: Ic2afd0dd35e38f403164d2cbe4618286abfa51ab
2024-10-14 09:07:22 -07:00
Yuval Tassa 9a0dc20821 Move Newton Hessian memory allocation from stack to arena.
PiperOrigin-RevId: 684054446
Change-Id: I4be0b216810ebbd9d7fa119c6a84eb08d3c16b83
2024-10-09 08:54:54 -07:00
Yuval Tassa b66da3d369 Add mjData.L, sparse Cholesky factor of Newton solver Hessian.
PiperOrigin-RevId: 683669555
Change-Id: I18d7530b5d68d1d48cb95d4faa0150c434109638
2024-10-08 10:13:08 -07:00
Alessio Quaglino 5bca7876c4 Update spec.from_string() and spec.from_file() to match the respective mjModel functions.
PiperOrigin-RevId: 678230403
Change-Id: I7f3d8c5fd44d30b5695eee1f8513cc27f4158d94
2024-09-24 06:57:20 -07:00
Nimrod Gileadi 9a27fc14c2 Raise appropriate errors for mj_addBufferVFS in Python bindings.
When loading models in the XML bindings, different issues with the asset dictionary were all reported as "assets dict is too big".

PiperOrigin-RevId: 670960339
Change-Id: I2e47d91a6b433fd90ebdf9960a9b5b47413af410
2024-09-04 07:20:25 -07:00
Alessio Quaglino 505d01a1c1 Add error handling to mj_recompile.
This CL adds error handling to the mj_recompile function. If the recompile fails, the function will return -1 and set the error message in the spec. The Python wrapper for mj_recompile will catch the error and raise a ValueError exception.

PiperOrigin-RevId: 666784579
Change-Id: I225eca1769ea839c782be3c03fc4ff1ea5885a48
2024-08-23 07:18:28 -07:00
Kyle Bayes 5ac5cfb618 Support directories in VFS via mj_addBufferVFS.
PiperOrigin-RevId: 655286683
Change-Id: I846376a0571d8df28d979beb5981a0cbccd7a04f
2024-07-23 13:39:18 -07:00
Saran Tunyasuvunakool db1d51a1f5 Add more fields to mjx.Option and mjx.Statistic for MuJoCo compatibility.
Also add metadata fields to the Python bindings of mjModel and mjOption,
and fix dtype of a number of fields.

PiperOrigin-RevId: 654138876
Change-Id: If2bbe41bf3dfdb350d60b5289afc65fffb397ce9
2024-07-19 15:13:01 -07:00
Alessio Quaglino 70ac76bb4b Add assets to MjSpec.compile()
PiperOrigin-RevId: 653965318
Change-Id: Ib9ec1c70a7241f7ee547b799a08cc58e7d4bace7
2024-07-19 04:34:38 -07:00
Kyle Bayes 57e6760ec9 Re-implement VFS internals in C++, removing the constraints of the previous implementation.
PiperOrigin-RevId: 649433087
Change-Id: Icaa3e6b7f2ef14f56b04fef2f4360b46d8b5f022
2024-07-04 09:22:23 -07:00
Tom Erez 3b73dfe33b Add textured materials to render context, and refactor mjvGeom to refer to those textures.
PiperOrigin-RevId: 648719103
Change-Id: Idb4425bdeea3cbc1133cda3e4366574ed3bb5ccc
2024-07-02 08:01:40 -07:00
Alessio Quaglino 9106f40e2b Add mjSpec bindings.
Co-authored-by: Saran Tunyasuvunakool <stunya@google.com>
PiperOrigin-RevId: 648444641
Change-Id: I08ee1d3f4fae1efbc7934ba94702b1c06d8cb92a
2024-07-01 12:05:50 -07:00
Nimrod Gileadi 2188cba4cd Fix a memory leak when copy.deepcopy(data) is called.
In MjDataWrapper.__deepcopy__ use the Python implementation of MjModelWrapper.__deepcopy__ to make an object that Python knows about and can release later.

Fixes google-deepmind/mujoco#1572.

PiperOrigin-RevId: 644967999
Change-Id: I95d093c672e136122e1939f69463a4d29dad82e8
2024-06-20 03:46:16 -07:00
Yuval Tassa 07fc95ca9a Add orthographic cameras.
Orthographic cameras are specified by setting the `orthographic` attribute of the `<camera>` element. The `fovy` attribute is still used to specify the field-of-view, but its semantic is different for orthographic cameras. For orthographic cameras, the field-of-view is expressed in units of length, rather than degrees.

Other related changes:

* Fix bug in the ordering of `cam_xxx` elements in `mjModel`.
* Make camera visualization translucent only when the frustum is visualized.
* Added a button to `simulate` to toggle between perspective and orthographic free cameras.

https://youtu.be/ZXBTEIDWHhs

PiperOrigin-RevId: 642293435
Change-Id: Id090a421ad88ab404b5b27ddbbd6bfc81ad49bc5
2024-06-11 09:23:18 -07:00
Yuval Tassa caf215e342 Add metallic and roughness scalar attributes to materials.
Rename `light_radius` -> `light_bulbradius`, make the default value 0.02.

PiperOrigin-RevId: 627032170
Change-Id: I1e01e2eca028c0aefc2e7dc384e8b34abac184aa
2024-04-22 07:39:06 -07:00
Kyle Bayes 109f2d7119 Replace mj_makeEmptyFileVFS in Python bindings with mj_addBufferVFS.
PiperOrigin-RevId: 609383859
Change-Id: Ib23ee49e803630a2895a471e9a3ed8b33551cbb9
2024-02-22 08:36:42 -08:00
Yuval Tassa fea7c10b95 Add bvhactive flag to visual/global. Fixes #1279.
PiperOrigin-RevId: 599778272
Change-Id: If5530629035cc68b198447503388f59a04041b13
2024-01-19 02:59:56 -08:00
Nimrod Gileadi 084facc9ab Python bindings: Store a reference to MjModel in MjDataWrapper.
Before this change, MjDataWrapper contained a custom data structure called MjDataMetadata, which contained the sizes of various arrays needed to create MjData. This was used for serialization and deserialization, as well as copying MjData instances.

This worked fine for native MuJoCo models, but as soon as plugins were used, there was information in the model that was needed and not available in MjDataMetadata. Since plugins are so general, keeping MjDataMetadata was untenable.

PiperOrigin-RevId: 578205355
Change-Id: I11b9ee797d1da5aaf1fecbbe170b3b0f1f1a3e6c
2023-10-31 09:16:40 -07:00
Alessio Quaglino 1a47a97040 Disable shadows for geoms of category mjCAT_DECOR. Fixes #1114.
Added `frustum` to `rgba` and `scale` in the `visual` section.

PiperOrigin-RevId: 576547599
Change-Id: I69bf528680e3d4a59d6e04f6db99a6d345001d1d
2023-10-25 09:08:20 -07:00
Alessio Quaglino 5a70ad08ab Add Flex component.
PiperOrigin-RevId: 572830650
Change-Id: I6908228087b7b9683be3506c8d9cdc725ed5dcd5
2023-10-12 10:49:35 +01:00
Saran Tunyasuvunakool 2e15574b58 Allow user-defined visualization geoms to be added to the passive viewer.
Fixes #1023, #1082

PiperOrigin-RevId: 572303635
Change-Id: Ia8399f816f311b38a7b137f5bd4f359f77a1da1c
2023-10-10 10:52:21 -07:00
Alessio Quaglino 36d2ffe4f2 Specify camera parameters using standard robotics conventions.
PiperOrigin-RevId: 569147555
Change-Id: I3443f95e5de56a17024f5e5c03f33888dd583edb
2023-09-28 05:19:19 -07:00
Matthew Bennice 7f8018a3f3 Update XML parsing to store asset path so that assets can be recovered and sent to external renderers
PiperOrigin-RevId: 567347908
Change-Id: I4d8e1abe35be3a67643ff925af709921280856f8
2023-09-21 10:27:52 -07:00
Yuval Tassa 9902b73502 Rename mj_stackAlloc to mj_stackAllocByte.
PiperOrigin-RevId: 566351365
Change-Id: I91541168e83b05a730113661cc9f07985ac9ff0c
2023-09-18 10:53:35 -07:00
Saran Tunyasuvunakool daa2ac7f8b Rename nstack to narena, change it and pstack to count bytes.
PiperOrigin-RevId: 561066311
Change-Id: I4d0e645e6c254dd906bfc42159e0e99149a7c6c8
2023-08-29 10:13:33 -07:00
Yuval Tassa 3e034e38b2 Add constraint island discovery
PiperOrigin-RevId: 557067599
Change-Id: Ic41e1d0efef02b7a79142518afe49cf9d4e74725
2023-08-15 02:30:05 -07:00
Yuval Tassa d82f5ce5a4 Add mjContact.solreffriction, mjModel.pair_solreffriction and related implementation, allowing contact reference acceleration to be different for normal and frictional contact directions. This is required for e.g. elastic frictional collisions.
PiperOrigin-RevId: 538513357
Change-Id: Id9eb910fe791cf898c712030cb2c0fc481389c91
2023-06-07 09:40:20 -07:00
Saran Tunyasuvunakool f887c1e928 Add ASAN and MSAN instrumentation for arena and mjData stack.
PiperOrigin-RevId: 535635490
Change-Id: Ia1e58771bae25bf72c861f57452fb8faa2b918fb
2023-05-26 09:17:26 -07:00
Saran Tunyasuvunakool b362cb4972 Expose a handle for the Python viewer.
This change also requires user scripts to explicitly synchronize changes to physics state to the viewer. The Simulate class was reconfigured so that certain UI events are handled during this sync operation, outside of the render loop on the main thread. These correspond to operations that require access to the full mjModel/mjData.

To support other, more interactive operations (e.g. camera movements), a new mjvSceneState struct is introduced which captures only the portion of the physics state required for scene re-rendering. The mjvSceneState is updated from mjModel/mjData during the viewer sync operation, and is significantly cheaper than a full mj_copyModel and mj_copyData.

Fixes https://github.com/deepmind/mujoco/issues/796

PiperOrigin-RevId: 525723636
Change-Id: Id08d0210a2c067d5afe85e2bf104f276aeddd75e
2023-04-20 05:59:19 -07:00
Saran Tunyasuvunakool 2e23594fe8 Add an introspect module for structs.
Also missing struct fields to the Python bindings that were discovered as a result of the new `introspect` metadata.

PiperOrigin-RevId: 523947396
Change-Id: I367fd2dc8d5fd7e5712a45b70a5c50da51d152e4
2023-04-13 02:50:23 -07:00
Kristian Hartikainen a611b7bf6d Fix typos 2023-04-04 19:58:43 +01:00
Kevin Zakka 3f14d97f6b Add equivalent inertia ellipsoid visualization.
PiperOrigin-RevId: 519154067
Change-Id: I35f1993c1493df9be752b7163385004649498070
2023-03-24 08:47:43 -07:00
Alessio Quaglino 70959c1a2c Added a collision midphase on geom pairs using rotated AABBs static trees.
PiperOrigin-RevId: 517357695
Change-Id: I068fee714d9638be2fb6d042d5d86f8ff970635b
2023-03-17 02:37:29 -07:00
Saran Tunyasuvunakool e20ab6c96f Add a number of missing struct fields to Python bindings.
It is quite possible that there are a few other fields still missing since we currently do not yet have automated testing of struct field existence.

Fixes #747.

PiperOrigin-RevId: 517189048
Change-Id: I7c1d95e700eaea05aaa3cde1fd05e1a259553117
2023-03-16 12:05:50 -07:00
Kyle Bayes 50bebcb4ee Precount number of non-zeros for constraint Jacobian sparse matrix.
PiperOrigin-RevId: 512947632
Change-Id: I9605e81b4e51fbc90854c13153e4fee38ad48fb9
2023-02-28 08:57:56 -08:00
Saran Tunyasuvunakool ace5b74f83 Rename inteval attribute in mjLROpt to interval.
PiperOrigin-RevId: 509275105
Change-Id: I0ffb9cf485a504843ed255f0b4f24e9285a1c273
2023-02-13 10:54:25 -08:00
Saran Tunyasuvunakool f1af86cf82 Fix msan failure in __repr__ when upgraded to NumPy 1.24.
PiperOrigin-RevId: 505661236
Change-Id: I37ea339679870d23886e3c95f51451349fa1de2c
2023-01-30 05:11:25 -08:00
Saran Tunyasuvunakool 725b45b577 Internal Python bindings cleanup.
PiperOrigin-RevId: 495868304
Change-Id: Ib9cfe5f7a1d49126659176207bd6b4a314f8516a
2022-12-16 07:22:48 -08:00
Saran Tunyasuvunakool 58fd72f53d Dynamically allocate contact and efc_ arrays on a new memory arena.
- Add private function `mj_arenaAlloc`. This is used internally to allocate memory from the arena.

- Add private function `mj_nefc` to count constraints. This function returns a tight upper bound on `d->nefc`. The number of counted constraints can be slightly bigger than exact `d->nefc` in the case of constraints with empty Jacobian, as when placing a frictional tendon between two world sites.

- Add new `memory` attribute to the `size` XML element for specification of arena memory size. This attribute is mutually exclusive with `nstack` and `njmax` specifications, which are now deprecated (but left around for the time being for legacy compatibility).

- Move `d->stack` to the end of the new arena space. The stack now grows in reverse from the end.

PiperOrigin-RevId: 479341539
Change-Id: Ie019c202e0908577ffc6f833a37920858116f667
2022-10-06 10:03:05 -07:00
Saran Tunyasuvunakool c13979cd17 Add id and name properties to MjModel and MjData indexers.
PiperOrigin-RevId: 476078133
Change-Id: I905cc8ec147ac595cd56f0a42e38013ae1ac6903
2022-09-22 06:19:03 -07:00
Alessio Quaglino 2d0995b47c Add visualisation groups to skins.
PiperOrigin-RevId: 458441645
Change-Id: I14324e8efda5142b2718a5cc9215228c7556dbf7
2022-07-01 04:57:34 -07:00
Nimrod Gileadi 41bcf2d621 Python bindings: Add __repr__ implementations to grouped views.
PiperOrigin-RevId: 457704673
Change-Id: Idf0d2132ce0872e6ae3eef319b4c3119ab769cd0
2022-06-28 05:23:16 -07:00