Skip to content

Commit

Permalink
Add reset scene and stop rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyDing committed Dec 28, 2024
1 parent 6caca76 commit 8362bc7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
17 changes: 7 additions & 10 deletions genesis/ext/pyrender/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Viewer(pyglet.window.Window):
(scene default, flip wireframes, all wireframe, or all solid).
- ``z``: Resets the camera to the initial view.
- ``x``: Resets simulation to initial state.
- ``Space``: Pause simulation util pressing Space again
- ``Space``: Pause rendering util pressing Space again
Note
----
Expand Down Expand Up @@ -187,7 +187,6 @@ def __init__(
self,
scene,
context,
viewer,
viewport_size=None,
render_flags=None,
viewer_flags=None,
Expand All @@ -206,7 +205,6 @@ def __init__(
viewport_size = (640, 480)
self.gs_context = context
self.render_scene = scene
self._viewer = viewer
self._scene = context._scene
self._viewport_size = viewport_size
self._render_lock = RLock()
Expand All @@ -217,8 +215,9 @@ def __init__(
self._should_close = False
self._run_in_thread = run_in_thread
self._seg_node_map = context.seg_node_map
self._pause_draw = False

self._video_saver = None

self._default_render_flags = {
"flip_wireframe": False,
"all_wireframe": False,
Expand Down Expand Up @@ -299,7 +298,7 @@ def __init__(
" [x]: reset simulation",
" [d]: wireframe",
" [c]: camera & frustrum",
" [Space]: pause simulation",
" [Space]: pause rendering",
" [F11]: full-screen mode",
],
]
Expand Down Expand Up @@ -632,7 +631,7 @@ def draw_offscreen(self):

def on_draw(self):
"""Redraw the scene into the viewing window."""
if self._renderer is None or self._pause_draw:
if self._renderer is None:
return

if self.run_in_thread or not self.auto_start:
Expand Down Expand Up @@ -862,14 +861,12 @@ def on_key_press(self, symbol, modifiers):
self._save_image()
elif symbol == pyglet.window.key.SPACE:
if not self.gs_context.pause_rendering_shown:
self._pause_draw = True
self.render_lock.acquire(blocking=False)
self.gs_context.pause_rendering_shown = True
self._viewer._pause_render_flag = True
# gs.logger.info("pause_rendering......")
else:
self._pause_draw = False
self.render_lock.release()
self.gs_context.pause_rendering_shown = False
self._viewer._pause_render_flag = False
# gs.logger.info("start_rendering......")
elif symbol == pyglet.window.key.X:
self.render_scene.reset()
Expand Down
2 changes: 1 addition & 1 deletion genesis/vis/rasterizer_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def init_meshes(self):
self.world_frame_shown = False
self.link_frame_shown = False
self.camera_frustum_shown = False
self.pause_rendering_shown = False

self.world_frame_mesh = mu.create_frame(
origin_radius=0.012,
axis_radius=0.005,
Expand Down
10 changes: 4 additions & 6 deletions genesis/vis/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ def __init__(self, options, context):
self._camera_init_lookat = options.camera_lookat
self._camera_up = options.camera_up
self._camera_fov = options.camera_fov
self._pause_render_flag = False

self.context = context

if self._max_FPS is not None:
self.rate = Rate(self._max_FPS)

def build(self, scene, viewer):
def build(self, scene):
self.scene = scene

# set viewer camera
self.setup_camera()
self.viewer = viewer

# viewer
if gs.platform == "Linux":
run_in_thread = True
Expand All @@ -67,15 +68,13 @@ def build(self, scene, viewer):

self._pyrender_viewer = pyrender.Viewer(
scene=self.scene,
viewer=self.viewer,
context=self.context,
viewport_size=self._res,
run_in_thread=run_in_thread,
auto_start=auto_start,
view_center=self._camera_init_lookat,
shadow=self.context.shadow,
plane_reflection=self.context.plane_reflection,
update_flag=self._pause_render_flag,
viewer_flags={
"window_title": f"Genesis {gs.__version__}",
"refresh_rate": self._refresh_rate,
Expand Down Expand Up @@ -113,7 +112,6 @@ def setup_camera(self):
def update(self):
with self.lock:
buffer_updates = self.context.update()
# gs.logger.info(f"Updating viewer....")
for buffer_id, buffer_data in buffer_updates.items():
self._pyrender_viewer.pending_buffer_updates[buffer_id] = buffer_data

Expand Down
8 changes: 3 additions & 5 deletions genesis/vis/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def build(self):
self._context.build(self._scene)

if self._viewer is not None:
self._viewer.build(self._scene, self._viewer)
self._viewer.build(self._scene)
self.viewer_lock = self._viewer.lock
else:
self.viewer_lock = DummyViewerLock()
Expand Down Expand Up @@ -129,14 +129,12 @@ def build(self):
def update(self, force=True):
if force: # force update
self.reset()
if self._viewer is not None and not self._viewer._pause_render_flag:
# gs.logger.info("Updating viewer in visualizer.....")

if self._viewer is not None:
if self._viewer.is_alive():
self._viewer.update()
else:
gs.raise_exception("Viewer closed.")
# else:
# gs.logger.info("Skip updating viewer in visualizer.....")

def update_visual_states(self):
"""
Expand Down

0 comments on commit 8362bc7

Please sign in to comment.