Skip to content

Commit

Permalink
Viewer: add control parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegelp committed Apr 16, 2024
1 parent a9ede4d commit 15e2995
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions octarine/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class Viewer:
size : tuple, optional
Size of the viewer window.
camera : "ortho" | "perspective", optional
Type of camera to use. Defaults to "ortho". Note you can always
change the camera type by adjust the `Viewer.camera.fov` attribute
(0 = ortho, >0 = perspective).
control : "trackball" | "panzoom" | "fly" | "orbit"
Controller type to use. Defaults to "trackball".
show : bool, optional
Whether to immediately show the viewer. Note that this has no
effect in Jupyter. There you will have to call ``.show()`` manually
Expand All @@ -89,6 +94,7 @@ def __init__(
title="Octarine Viewer",
max_fps=30,
camera="ortho",
control="trackball",
size=None,
show=True,
**kwargs,
Expand Down Expand Up @@ -154,9 +160,16 @@ def __init__(
raise ValueError(f"Unknown camera type: {camera}")

# Add controller
self.controller = gfx.TrackballController(
self.camera, register_events=self.renderer
)
controller = {
"trackball": gfx.TrackballController,
"panzoom": gfx.PanZoomController,
"fly": gfx.FlyController,
"orbit": gfx.OrbitController,
}.get(control, None)
if controller is None:
raise ValueError(f"Unknown controller type: {control}")

self.controller = controller(self.camera, register_events=self.renderer)

# Stats
self.stats = gfx.Stats(self.renderer)
Expand Down

0 comments on commit 15e2995

Please sign in to comment.