Commit Graph

49 Commits

Author SHA1 Message Date
Saran Tunyasuvunakool 0ccfef7314 Add update_{hfield,mesh,texture} methods to the passive viewer.
Fixes #812.
Fixes #958.
Fixes #965.

PiperOrigin-RevId: 548181282
Change-Id: I6eb0cd2ce52c66083e83dd08d69e0cfb4178dbba
2023-07-14 11:43:36 -07:00
Yuval Tassa 906a8e8b27 Correct shortening of camera name in simulate.cc (for UI menu item)
Fixes #963

PiperOrigin-RevId: 545187656
Change-Id: Ib213d693569d884915fba99f150df4fd5f53984c
2023-07-03 04:32:27 -07:00
Yuval Tassa d40c395917 Add Visualization tab to simulate.
Also:
- Increased label width in mjUI tight theme spacing.
- Added `mjITEM_EDITFLOAT` for editing float values.
- Move mjUI numpad key codes to header file.
PiperOrigin-RevId: 535839953
Change-Id: Ibdc0a9a20be514caa5b487211212ed6f5b8a6ba9
2023-05-27 05:08:15 -07:00
Yuval Tassa bb8044e5f3 Set minimum tree slider depth to 0.
PiperOrigin-RevId: 534003561
Change-Id: I42ccd0eab15b5a3c9852f8944c6b191f7999c113
2023-05-22 02:39:58 -07:00
Yuval Tassa 20e06ba353 Add missing braces.
PiperOrigin-RevId: 533419351
Change-Id: Iad54f6cb6d63c05e6a2f81526b22a914e2a23ba2
2023-05-19 04:35:12 -07:00
Saran Tunyasuvunakool c2115a1f51 Fix a mjvSceneState leak in the passive viewer.
PiperOrigin-RevId: 526957248
Change-Id: I4f30faf097da64189607a4b98c6dff04fec773fa
2023-04-25 07:11:42 -07:00
Yuval Tassa a2a1ac9fc2 Pass mjvOption to plugin visualize callback.
PiperOrigin-RevId: 526047180
Change-Id: Ia63f02184f5c6a7e3b588298639fa0ab4a6da649
2023-04-21 08:44:20 -07:00
Saran Tunyasuvunakool 94779a722a Rename Differ to IsDifferent and tidy up its implementation.
Startblock:
   diffbase is submitted
PiperOrigin-RevId: 526024927
Change-Id: I718f3b98539f5c33a42f6254bc817a07459f694c
2023-04-21 07:14:26 -07:00
Saran Tunyasuvunakool da17fdfcfd Fix a macOS segfault in simulate.cc.
The segfault was caused by updating the UI outside the main thread.

PiperOrigin-RevId: 526019783
Change-Id: I3a211ce8a65f10716778bb3310bb568e00309a32
2023-04-21 06:46:09 -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 5646c905cd Rename a few functions and variables to be a bit more Googley.
PiperOrigin-RevId: 523963645
Change-Id: Ife7ed3f44aa83c64dfbdc3ca78ee6de2092b0d63
2023-04-13 04:24:31 -07:00
Alessio Quaglino 5f132af625 Add midphase and broadphase statistics to mjData.
PiperOrigin-RevId: 521387641
Change-Id: Id50f2549d119e364216491a23b107e04d9ebb5b6
2023-04-03 00:59:59 -07:00
Nimrod Gileadi 0e7e299bf6 Declare loop variables inside for loop in C++ files.
PiperOrigin-RevId: 518852339
Change-Id: I0174d873d89e48f11b816d337728f213c2798248
2023-03-23 07:22:36 -07:00
Nimrod Gileadi c6ab23d6b4 Add a missing mjITEM_END when creating the UI for the collision tree.
This fixes #774.

PiperOrigin-RevId: 517469175
Change-Id: I24a127c59f4a8dd7a5b306558425b90a80ec44f3
2023-03-17 11:51:06 -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
Yuval Tassa 8c7f6ce5a0 New implicitfast integrator and sparse RNE derivatives for implicit.
PiperOrigin-RevId: 516910733
Change-Id: I29a0465c0f0b1749a73e3d7e01925200d025ddd0
2023-03-15 13:17:41 -07:00
Saran Tunyasuvunakool 2f0fb1e4ef Workaround for broken VSync in Simulate on macOS.
OpenGL VSync became broken again in macOS 13 (https://github.com/glfw/glfw/issues/2249). This workaround is similar to https://github.com/glfw/glfw/pull/2277 but is implemented entirely outside of GLFW.

PiperOrigin-RevId: 516320722
Change-Id: Ib8a651a942f592c74e00ad3c7b22f2dfd156be5f
2023-03-13 14:19:17 -07:00
Alessio Quaglino 3abf2ae2cd Increase maximum number of geoms in simulate from 5000 to 20,000.
PiperOrigin-RevId: 516246198
Change-Id: I8a07a075b370ad0c212db8ed68b3d61389eba197
2023-03-13 10:16:12 -07:00
Yuval Tassa 2607e67f8d Add contact labels showing which geom pairs are in contact.
PiperOrigin-RevId: 510422404
Change-Id: Ia73570098752e7c7175e4b5a5f2a0f8b08a6c006
2023-02-17 07:03:19 -08:00
Yuval Tassa bc0184d67e Increase precision of simulate sensor plot y-axis by 1 digit.
- Before this change, the y-axis scale had only one digit, leading to user confusion. Small changes in senor values could appear as if the values remained at the nearest integer value, while in fact the y-axis itself was changing, but this was not evident in the GUI due to the reduced precision.
- Fixes #719.

PiperOrigin-RevId: 506841881
Change-Id: I583036bba389cef8d9ecf1c1bbcfb573ef2285e6
2023-02-03 01:48:18 -08:00
Saran Tunyasuvunakool 4b4ee27f64 Turn off reflection and shadow in simulate when a GPU is not present.
Note that The GLFW adapter currently assumes that a GPU is always present, so this new code path is never reached at the moment.

PiperOrigin-RevId: 504617048
Change-Id: I04a323c33d9cff73686d39e4a6676ca6a4484c98
2023-01-25 11:33:20 -08:00
Saran Tunyasuvunakool e40775fab3 Abstract out GLFW calls from Simulate.
PiperOrigin-RevId: 500129478
Change-Id: I7ba998e20439575ad9a3fe1a866c3db4c36b9328
2023-01-06 02:45:56 -08:00
Saran Tunyasuvunakool df25d7d602 Raise an informative error when running on macOS under Rosetta 2.
Current users only get a cryptic "Illegal instruction" crash.

Context: https://github.com/deepmind/mujoco/issues/611
PiperOrigin-RevId: 491705647
Change-Id: I1285897a36e858300ee3d125957e90754be9a7f7
2022-11-29 12:19:06 -08:00
Saran Tunyasuvunakool ecac5758e2 Replace NULL with nullptr.
PiperOrigin-RevId: 491385488
Change-Id: Iec34af99edb7ccd64834130a8cc6280a02b166c2
2022-11-28 10:44:30 -08:00
Yuval Tassa 062cb53a4a In simulate, move "pause" label to the top left rather than the top right.
PiperOrigin-RevId: 491035420
Change-Id: I94ad7ca2764716f9821df6009e5c4b50675a04be
2022-11-26 05:40:52 -08:00
Copybara-Service f7b256de91 Merge pull request #419 from aftersomemath:simulate-python
PiperOrigin-RevId: 487496285
Change-Id: I17d15bd2a3886e5ce1631f4eb78afa94830d08cc
2022-11-10 04:12:34 -08:00
Yuval Tassa 5004a4c8c5 Better memory setting and reporting, updated example models.
- Memory heuristic rounds up to the nearest MB.
- `simulate` reports total memory currently allocated in the info box.
- All example models use `<size memory/>` rather than legacy attributes.
- Regenerated `example_saved.xml` and reformatted original model in [overview chapter](https://mujoco.readthedocs.io/en/latest/overview.html?#examples).
- `<size>` top-level section does not get written if empty.

PiperOrigin-RevId: 486702670
Change-Id: I0306e335f32344c59562ba606664ec9d2101f8a8
2022-11-07 10:36:37 -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
Levi Burner 95a4b1c551 simulate python: fix cmake, glfw usage, update Python version of physics loop 2022-10-04 14:37:06 -04:00
Alessio Quaglino bc1490b7a8 Add realtime parameter to visual global.
PiperOrigin-RevId: 478775714
Change-Id: Ic2d178a5c57d298d005215219ce8470392c4651b
2022-10-04 07:09:15 -07:00
Kevin Zakka 7e89d8dab0 In simulate UI, clear shortcut string for flags with no shortcuts.
PiperOrigin-RevId: 478467279
Change-Id: Icc4317d9e35b41871143572275d03adf7e13d956
2022-10-03 04:31:17 -07:00
Yuval Tassa 0a0acb3419 Display real-time percentage in paused mode, if different than 100%
PiperOrigin-RevId: 474519561
Change-Id: I54eea97f305dc9b57b9513d6ab5cd75368c2cd45
2022-09-15 03:26:12 -07:00
Yuval Tassa 834e8dd506 Improvements to time synchronisation in simulate.
- Improved time-sync logic readability in `PhysicsLoop`.
- Fixed unattainable condition for breaking from stepping loop if data was reset.
- Added measurement of actual real-time tracking.
- Moved slowdown overlay to top left.
- Report slowdown as % of real-time, rather than fraction.
- Report actual slowdown if different than requested (very small timestep, PhysicsLoop cannot keep up) by more than 10%.
- Replaced slowdown increments of 2 with decimal-rounded increments of 10^(1/10). This is a finer-grained scale (approximately 3x as fine) and well suited for decimal percentage representation.
- Maximum slowdown increased to 1000.
- Added `Simulate.refreshrate` with a default of 60Hz, in case videomode refreshrate is 0 (can occur e.g. when forwarding over X11).
- Remove realtime reporting from regular info overlay.
- Various cleanups.

PiperOrigin-RevId: 471547481
Change-Id: Idd2514a4defb1dc431617f3a515cc747c4fd8971
2022-09-01 09:09:48 -07:00
Saran Tunyasuvunakool 3240596c3a Call GLFW functions via a dynamic dispatch table.
This allows us to use GLFW without needing to introduce a link-time dependency on the library, which in turn enables us to get GLFW through Python.

PiperOrigin-RevId: 470100999
Change-Id: I27c84ad3310afdbebd582ab0033b6a963ba6307e
2022-08-25 15:41:53 -07:00
Copybara-Service 396fdf00c3 Merge pull request #425 from aftersomemath:cull-face-flag
PiperOrigin-RevId: 466904386
Change-Id: Icd5515c2bbb8f8f3417501ea43c8e5ae22b32f91
2022-08-11 02:44:37 -07:00
Yuval Tassa 4d24d56c64 Fix simulate window title.
PiperOrigin-RevId: 465763279
Change-Id: I21405891071ae151c057c40725be645fc28cd748
2022-08-06 07:53:11 -07:00
Kevin Zakka 80b4ffdd6a Add screenshot button to simulate.
PiperOrigin-RevId: 465628684
Change-Id: I0eb86d6b18c25bb437f197229be6d1c57ccbc50a
2022-08-05 12:56:32 -07:00
Levi Burner 581f009c02 Cull face flag 2022-08-05 11:53:46 -04:00
Yuval Tassa b966a37855 Add optional azimuth and elevation to initial free camera.
- Add `azimuth` and `elevation` to `visual.global`.
- Add `mjv_defaultFreeCamera`.
- Use `mjv_defaultFreeCamera` in `simulate`.

PiperOrigin-RevId: 465505244
Change-Id: I61e60f14a990d4e2d220958adb75c325001978ee
2022-08-05 01:04:02 -07:00
Levi Burner 7fb1ffe712 Invert condition variable predicate 2022-08-03 15:59:14 -04:00
Saran Tunyasuvunakool e40b9da181 Merge pull request #201 from aftersomemath:refactor-simulate
PiperOrigin-RevId: 465044152
Change-Id: I54e65a30764a444dbd175260314d685fd7ffa6a1
2022-08-03 15:32:15 +01:00
Levi Burner 70ec29a722 Simulate: fix header includes 2022-07-08 16:04:12 -04:00
Levi Burner a526a6bd78 Simulate: move all glfw calls to main thread to fix MacOS 2022-07-08 16:04:12 -04:00
Levi Burner 95510a07d4 Simulate: fix MacOS build (still crashes due to GLFW misusage) 2022-07-08 16:04:12 -04:00
Levi Burner ed82f055e8 Simulate: fixes for windows version 2022-07-08 16:04:12 -04:00
Levi Burner 1d4461fce6 Simulate: Use new cmake system fix build errors introduced with rebase 2022-07-08 16:04:12 -04:00
Levi Burner 033ca81db6 Simulate: fix reload button causing segfault, make interface changes needed for Python bindings 2022-07-08 16:04:12 -04:00
Levi Burner 447877abef Simulate creates and maintains its own thread 2022-07-08 16:04:12 -04:00
Levi Burner 65d5ade426 Refactor simulate to split UI from application
Fix name of glew library

Move simulate to new directory and refactor to use C++ conventions

Wrap simulate in mujoco namespace

fix namespaces, convert struct to class, use std::lock_guard

use GetMutex to better handle destruction ordering

rename mjSimulate to Simulate

nit: space before public and typo

move startup print

use nullptr instead of NULL

use GetInstance() to get simulate object

convert init to default constructor
2022-07-08 16:04:07 -04:00