Skip to content

Commit

Permalink
fix black format
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyDing committed Dec 28, 2024
1 parent e21dc34 commit caffe3e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
17 changes: 10 additions & 7 deletions genesis/ext/pyrender/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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 rendering util pressing Space again
- ``Space``: Pause simulation util pressing Space again
Note
----
Expand Down Expand Up @@ -186,6 +186,7 @@ def __init__(
self,
scene,
context,
viewer,
viewport_size=None,
render_flags=None,
viewer_flags=None,
Expand All @@ -204,6 +205,7 @@ 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 @@ -214,9 +216,8 @@ 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 @@ -297,7 +298,7 @@ def __init__(
" [x]: reset simulation",
" [d]: wireframe",
" [c]: camera & frustrum",
" [Space]: pause rendering",
" [Space]: pause simulation",
" [F11]: full-screen mode",
],
]
Expand Down Expand Up @@ -630,7 +631,7 @@ def draw_offscreen(self):

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

if self.run_in_thread or not self.auto_start:
Expand Down Expand Up @@ -860,12 +861,14 @@ 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.render_lock.acquire(blocking=False)
self._pause_draw = True
self.gs_context.pause_rendering_shown = True
self._viewer._pause_render_flag = True
# gs.logger.info("pause_rendering......")
else:
self.render_lock.release()
self._pause_draw = False
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: 6 additions & 4 deletions genesis/vis/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ 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):
def build(self, scene, viewer):
self.scene = scene

# set viewer camera
self.setup_camera()

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

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 @@ -112,6 +113,7 @@ 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: 5 additions & 3 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.build(self._scene, self._viewer)
self.viewer_lock = self._viewer.lock
else:
self.viewer_lock = DummyViewerLock()
Expand Down Expand Up @@ -129,12 +129,14 @@ def build(self):
def update(self, force=True):
if force: # force update
self.reset()

if self._viewer is not None:
if self._viewer is not None and not self._viewer._pause_render_flag:
# gs.logger.info("Updating viewer in visualizer.....")
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 caffe3e

Please sign in to comment.