From b3eb9c918a2a7c43bd240b29bfe0bf7b55c9165d Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Tue, 18 Jan 2022 19:07:24 +0100 Subject: [PATCH 1/3] Add support for setting 'flat=true' in pyrender.Viewer It will OR `RenderFlags.FLAT` into the Viewer._renderer.render flags --- pyrender/viewer.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyrender/viewer.py b/pyrender/viewer.py index 228cc3c..a895142 100644 --- a/pyrender/viewer.py +++ b/pyrender/viewer.py @@ -126,6 +126,8 @@ class Viewer(pyglet.window.Window): blue lines. Defaults to `False`. - ``cull_faces``: `bool`, If `True`, backfaces will be culled. Defaults to `True`. + - ``flat``: `bool`, If `True`, render the color buffer flat, + with no lighting computations. Defaults to `True`. - ``point_size`` : float, The point size in pixels. Defaults to 1px. Note @@ -198,6 +200,7 @@ def __init__(self, scene, viewport_size=None, 'face_normals': False, 'cull_faces': True, 'point_size': 1.0, + 'flat': False, } self._default_viewer_flags = { 'mouse_pressed': False, @@ -985,6 +988,8 @@ def _render(self): flags |= RenderFlags.FACE_NORMALS if not self.render_flags['cull_faces']: flags |= RenderFlags.SKIP_CULL_FACES + if self.render_flags['flat']: + flags |= RenderFlags.FLAT self._renderer.render(self.scene, flags) From db1388bf12fae93f8d3725be522523e699a91de9 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Tue, 18 Jan 2022 19:24:11 +0100 Subject: [PATCH 2/3] Make it show you can enable flat lighting with SHIFT+L Pressing L without shift disables the flat lighting without cycling the previous lighting mode --- README.md | 1 + pyrender/viewer.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ae88ed1..1b3a9ce 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ The available keyboard commands are as follows: * `h`: Toggles shadow rendering. * `i`: Toggles axis display mode (no axes, world axis, mesh axes, all axes). * `l`: Toggles lighting mode (scene lighting, Raymond lighting, or direct lighting). +* `L`: Uses flat lighting mode. * `m`: Toggles face normal visualization. * `n`: Toggles vertex normal visualization. * `o`: Toggles orthographic camera mode. diff --git a/pyrender/viewer.py b/pyrender/viewer.py index a895142..3b4af02 100644 --- a/pyrender/viewer.py +++ b/pyrender/viewer.py @@ -96,6 +96,7 @@ class Viewer(pyglet.window.Window): (no axes, world axis, mesh axes, all axes). - ``l``: Toggles lighting mode (scene lighting, Raymond lighting, or direct lighting). + - ``L``: Uses flat lighting mode. - ``m``: Toggles face normal visualization. - ``n``: Toggles vertex normal visualization. - ``o``: Toggles orthographic mode. @@ -751,7 +752,23 @@ def on_key_press(self, symbol, modifiers): # L toggles the lighting mode elif symbol == pyglet.window.key.L: - if self.viewer_flags['use_raymond_lighting']: + # SHIFT+L sets flat lighting + if modifiers & pyglet.window.key.MOD_SHIFT: + self.render_flags['flat'] = True + self._message_text = 'Flat Lighting' + + # L unsets flat lighting if set + elif self.render_flags['flat']: + self.render_flags['flat'] = False + if self.viewer_flags['use_raymond_lighting']: + self._message_text = 'Raymond Lighting' + elif self.viewer_flags['use_direct_lighting']: + self._message_text = 'Direct Lighting' + else: + self._message_text = 'Default Lighting' + + # otherwise cycles lighting mode + elif self.viewer_flags['use_raymond_lighting']: self.viewer_flags['use_raymond_lighting'] = False self.viewer_flags['use_direct_lighting'] = True self._message_text = 'Direct Lighting' From 227bebcdb138053be636d5d8ceb06383da6b7f14 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Tue, 18 Jan 2022 19:25:15 +0100 Subject: [PATCH 3/3] Reword "Toggle" to "Cycle" for certain Viewer keybindings. Some of the keybinds are documented to "toggle" between more that two states. "Cycle" is more specific in these cases. --- README.md | 6 +++--- pyrender/viewer.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1b3a9ce..8d48a9a 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,8 @@ The available keyboard commands are as follows: * `c`: Toggles backface culling. * `f`: Toggles fullscreen mode. * `h`: Toggles shadow rendering. -* `i`: Toggles axis display mode (no axes, world axis, mesh axes, all axes). -* `l`: Toggles lighting mode (scene lighting, Raymond lighting, or direct lighting). +* `i`: Cycles axis display mode (no axes, world axis, mesh axes, all axes). +* `l`: Cycles lighting mode (scene lighting, Raymond lighting, or direct lighting). * `L`: Uses flat lighting mode. * `m`: Toggles face normal visualization. * `n`: Toggles vertex normal visualization. @@ -85,7 +85,7 @@ The available keyboard commands are as follows: * `q`: Quits the viewer. * `r`: Starts recording a GIF, and pressing again stops recording and opens a file dialog. * `s`: Opens a file dialog to save the current view as an image. -* `w`: Toggles wireframe mode (scene default, flip wireframes, all wireframe, or all solid). +* `w`: Cycles wireframe mode (scene default, flip wireframes, all wireframe, or all solid). * `z`: Resets the camera to the default view. As a note, displaying shadows significantly slows down rendering, so if you're diff --git a/pyrender/viewer.py b/pyrender/viewer.py index 3b4af02..ccb6e33 100644 --- a/pyrender/viewer.py +++ b/pyrender/viewer.py @@ -92,9 +92,9 @@ class Viewer(pyglet.window.Window): - ``c``: Toggles backface culling. - ``f``: Toggles fullscreen mode. - ``h``: Toggles shadow rendering. - - ``i``: Toggles axis display mode + - ``i``: Cycles axis display mode (no axes, world axis, mesh axes, all axes). - - ``l``: Toggles lighting mode + - ``l``: Cycles lighting mode (scene lighting, Raymond lighting, or direct lighting). - ``L``: Uses flat lighting mode. - ``m``: Toggles face normal visualization. @@ -104,7 +104,7 @@ class Viewer(pyglet.window.Window): - ``r``: Starts recording a GIF, and pressing again stops recording and opens a file dialog. - ``s``: Opens a file dialog to save the current view as an image. - - ``w``: Toggles wireframe mode + - ``w``: Cycles wireframe mode (scene default, flip wireframes, all wireframe, or all solid). - ``z``: Resets the camera to the initial view. @@ -750,7 +750,7 @@ def on_key_press(self, symbol, modifiers): self._set_axes(True, False) self._message_text = 'World Axis On' - # L toggles the lighting mode + # L cycles the lighting mode elif symbol == pyglet.window.key.L: # SHIFT+L sets flat lighting if modifiers & pyglet.window.key.MOD_SHIFT: