Skip to content

Commit 98601bb

Browse files
committed
wip interaction keybindings
1 parent 322cc71 commit 98601bb

File tree

12 files changed

+610
-299
lines changed

12 files changed

+610
-299
lines changed
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
from .plugins.mesh_selector import MeshPointSelectorPlugin
2-
from .plugins.mouse_interaction import MouseSpringViewerPlugin
3-
from .viewer_plugin_base import (
1+
from .base_interaction import (
42
EVENT_HANDLE_STATE,
53
EVENT_HANDLED,
64
VIEWER_PLUGIN_MAP,
7-
ViewerPluginBase,
5+
BaseViewerInteraction,
86
register_viewer_plugin,
97
)
8+
from .plugins.mesh_selector import MeshPointSelectorPlugin
9+
from .plugins.mouse_interaction import MouseSpringViewerPlugin
10+
from .plugins.viewer_controls import ViewerControls
11+
from .ray import Plane, Ray, RayHit
12+
from .vec3 import Color, Pose, Quat, Vec3

genesis/ext/pyrender/interaction/viewer_plugin_base.py renamed to genesis/ext/pyrender/interaction/base_interaction.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
EVENT_HANDLED: Literal[True] = True
1616

1717
# Global map from options class to viewer plugin class
18-
VIEWER_PLUGIN_MAP: dict[Type["ViewerPluginOptions"], Type["ViewerPluginBase"]] = {}
18+
VIEWER_PLUGIN_MAP: dict[Type["ViewerPluginOptions"], Type["BaseViewerInteraction"]] = {}
1919

2020

2121
def register_viewer_plugin(options_cls: Type["ViewerPluginOptions"]):
@@ -38,25 +38,27 @@ def register_viewer_plugin(options_cls: Type["ViewerPluginOptions"]):
3838
class ViewerInteraction(ViewerInteractionBase):
3939
...
4040
"""
41-
def _impl(plugin_cls: Type["ViewerPluginBase"]):
41+
def _impl(plugin_cls: Type["BaseViewerInteraction"]):
4242
VIEWER_PLUGIN_MAP[options_cls] = plugin_cls
4343
return plugin_cls
4444
return _impl
4545

4646
# Note: Viewer window is based on pyglet.window.Window, mouse events are defined in pyglet.window.BaseWindow
4747

48-
class ViewerPluginBase():
48+
class BaseViewerInteraction():
4949
"""
5050
Base class for handling pyglet.window.Window events.
5151
"""
5252

5353
def __init__(
5454
self,
55+
viewer,
5556
options: "ViewerPluginOptions",
5657
camera: "Node",
5758
scene: "Scene",
5859
viewport_size: tuple[int, int],
5960
):
61+
self.viewer = viewer
6062
self.options: "ViewerPluginOptions" = options
6163
self.camera: 'Node' = camera
6264
self.scene: 'Scene' = scene
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from pyglet.window.key import symbol_string
2+
3+
4+
class Keybindings:
5+
def __init__(self, map: dict[str, int] = {}, **kwargs: dict[str, int]):
6+
self._map: dict[str, int] = {**map, **kwargs}
7+
8+
def __getattr__(self, name: str) -> int:
9+
if name in self._map:
10+
return self._map[name]
11+
raise AttributeError(f"'Keybindings' object has no attribute '{name}'")
12+
13+
def as_instruction_texts(self, padding, exclude: tuple[str]) -> list[str]:
14+
width = 4 + padding
15+
return [
16+
f"{'[' + symbol_string(self._map[action]).lower():>{width}}]: " +
17+
action.replace('_', ' ') for action in self._map.keys() if action not in exclude
18+
]
19+
20+
def apply_override_mapping(self, override_mapping: dict[str, int]) -> None:
21+
current_keys = self._map.keys()
22+
for action, key in override_mapping.items():
23+
if action not in self._map:
24+
raise KeyError(f"Action '{action}' not found. Available actions: {list(self._map.keys())}")
25+
if key in current_keys:
26+
raise ValueError(f"Key '{symbol_string(key)}' is already assigned to another action.")
27+
self._map[action] = key
28+
29+
def extend_mapping(self, additional_mapping: dict[str, int]) -> None:
30+
for action, key in additional_mapping.items():
31+
if action in self._map:
32+
raise KeyError(f"Action '{action}' already exists in keyboard mapping.")
33+
self._map[action] = key

genesis/ext/pyrender/interaction/mouse_spring.py

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .mesh_selector import MeshPointSelectorPlugin
2+
from .mouse_interaction import MouseSpringViewerPlugin
3+
from .viewer_controls import ViewerControls
4+
5+
__all__ = [
6+
"ViewerControls",
7+
"MeshPointSelectorPlugin",
8+
"MouseSpringViewerPlugin",
9+
]

0 commit comments

Comments
 (0)