-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[FEATURE] Add ImGui overlay for interactive joint control and visualization #2541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
YilingQiao
wants to merge
4
commits into
Genesis-Embodied-AI:main
Choose a base branch
from
YilingQiao:yiling/260313_imgui_only
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9f9eff8
Add ImGui overlay for interactive joint control and visualization
YilingQiao 6cb4ac2
Address PR #2541 review feedback: formatting, gs play entrypoint, CI …
YilingQiao 28ae671
Add real integration test for ImGuiOverlayPlugin
YilingQiao bbde2f4
Remove set_qpos test from imgui overlay test
YilingQiao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| """Interactive joint control example using ImGui overlay. | ||
|
|
||
| Demonstrates: | ||
| - Simulation controls (play/pause/step/reset) | ||
| - Entity browser with joint sliders | ||
| - Visualization toggles | ||
| - Camera controls | ||
| - Custom user panels via register_panel() | ||
| - Scene rebuild (add entities, change scale) | ||
| """ | ||
|
|
||
| import os | ||
| import time | ||
|
|
||
| import numpy as np | ||
|
|
||
| import genesis as gs | ||
| from genesis.ext.pyrender.imgui_overlay import ImGuiOverlayPlugin | ||
|
|
||
| gs.init() | ||
|
|
||
| # Store scene options for rebuild | ||
| scene_kwargs = dict( | ||
| viewer_options=gs.options.ViewerOptions( | ||
| camera_pos=(2.0, 2.0, 1.5), | ||
| camera_lookat=(0.0, 0.0, 0.5), | ||
| ), | ||
| show_viewer=True, | ||
| ) | ||
|
|
||
| scene = gs.Scene(**scene_kwargs) | ||
| scene.add_entity(gs.morphs.Plane()) | ||
| scene.add_entity(gs.morphs.MJCF(file="xml/franka_emika_panda/panda.xml")) | ||
| scene.add_entity(gs.morphs.Box(pos=(0, 0, 1.0), size=(0.2, 0.2, 0.2))) | ||
| scene.build() | ||
|
|
||
|
|
||
| def rebuild_scene(plugin): | ||
| """Rebuild scene from plugin's entity_specs.""" | ||
| global scene | ||
| specs = plugin.entity_specs | ||
|
|
||
| # Save camera state | ||
| cam_pos = scene.viewer.camera_pos.copy() | ||
| cam_lookat = np.array(scene.viewer._pyrender_viewer._trackball._n_target).copy() | ||
|
|
||
| scene.destroy() | ||
|
|
||
| scene = gs.Scene(**scene_kwargs) | ||
| for spec in specs: | ||
| scene.add_entity( | ||
| spec["morph"], | ||
| material=spec["material"], | ||
| surface=spec["surface"], | ||
| visualize_contact=spec["visualize_contact"], | ||
| ) | ||
| scene.build() | ||
|
|
||
| # Re-register plugin on new viewer | ||
| scene.viewer._pyrender_viewer.register_plugin(plugin) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not how plugins are being registered |
||
|
|
||
| # Restore camera | ||
| scene.viewer.set_camera_pose(pos=cam_pos, lookat=cam_lookat) | ||
|
|
||
|
|
||
| plugin = ImGuiOverlayPlugin(rebuild_fn=rebuild_scene) | ||
| scene.viewer._pyrender_viewer.register_plugin(plugin) | ||
|
Comment on lines
+66
to
+67
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not how plugins are being registered: |
||
|
|
||
|
|
||
| def custom_panel(imgui): | ||
| imgui.text("Custom Demo Panel") | ||
| imgui.text("This panel was registered via register_panel()") | ||
|
|
||
|
|
||
| plugin.register_panel(custom_panel) | ||
|
|
||
| is_test = "PYTEST_VERSION" in os.environ | ||
| horizon = 5 if is_test else None | ||
|
|
||
| frame = 0 | ||
| while scene.viewer.is_alive(): | ||
| if plugin.rebuild_requested: | ||
| rebuild_scene(plugin) | ||
| if plugin.should_step(): | ||
| scene.step() | ||
| frame += 1 | ||
| if horizon is not None and frame >= horizon: | ||
| break | ||
| time.sleep(0.01) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.