Skip to content

Commit f1db8e3

Browse files
committed
feat: Enhance vis.py show routine
- Add parameters azimuth viewup and clipping_range to allow for improved control of the rendering. - Always call ResetCamera early so the camera is in a known state before applying user defined parameters, some of which are relative.
1 parent f07e7e0 commit f1db8e3

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

cadquery/vis.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,11 @@ def show(
391391
zoom: float = 1.0,
392392
roll: float = -35,
393393
elevation: float = -45,
394+
azimuth: float = 0,
394395
position: Optional[Tuple[float, float, float]] = None,
395396
focus: Optional[Tuple[float, float, float]] = None,
397+
viewup: Optional[Tuple[float, float, float]] = None,
398+
clipping_range: Optional[Tuple[float, float]] = None,
396399
width: Union[int, float] = 0.5,
397400
height: Union[int, float] = 0.5,
398401
trihedron: bool = True,
@@ -491,17 +494,27 @@ def show(
491494

492495
# set camera
493496
camera = renderer.GetActiveCamera()
497+
498+
# Reset orientation to known state
499+
renderer.ResetCamera()
500+
501+
# Update camera position with user provided absolute positions
502+
if viewup:
503+
camera.SetViewUp(*viewup)
504+
if position:
505+
camera.SetPosition(*position)
506+
if focus:
507+
camera.SetFocalPoint(*focus)
508+
509+
# Update camera position with user defined relative positions
494510
camera.Roll(roll)
495511
camera.Elevation(elevation)
496-
camera.Zoom(zoom)
512+
camera.Azimuth(azimuth)
497513

498-
if position or focus:
499-
if position:
500-
camera.SetPosition(*position)
501-
if focus:
502-
camera.SetFocalPoint(*focus)
503-
else:
504-
renderer.ResetCamera()
514+
# Update camera view frustum
515+
camera.Zoom(zoom)
516+
if clipping_range:
517+
camera.SetClippingRange(*clipping_range)
505518

506519
# initialize and set size
507520
inter.Initialize()

0 commit comments

Comments
 (0)