Skip to content

Commit 7b072c4

Browse files
feat: Enhance vis.py show routine (#1855)
* 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. * test: Add testing of viewup and clipping_range * Fix the issue with not updated view Reset camera orientation if no explicit position is provided. * Use original logic --------- Co-authored-by: AU <adam-urbanczyk@users.noreply.github.com>
1 parent 4a5eff0 commit 7b072c4

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

cadquery/vis.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,11 @@ def show(
398398
zoom: float = 1.0,
399399
roll: float = -35,
400400
elevation: float = -45,
401+
azimuth: float = 0,
401402
position: Optional[Tuple[float, float, float]] = None,
402403
focus: Optional[Tuple[float, float, float]] = None,
404+
viewup: Optional[Tuple[float, float, float]] = None,
405+
clipping_range: Optional[Tuple[float, float]] = None,
403406
width: Union[int, float] = 0.5,
404407
height: Union[int, float] = 0.5,
405408
trihedron: bool = True,
@@ -503,17 +506,29 @@ def show(
503506

504507
# set camera
505508
camera = renderer.GetActiveCamera()
509+
510+
# Update camera position with user provided absolute positions
511+
if viewup:
512+
camera.SetViewUp(*viewup)
513+
514+
if focus:
515+
camera.SetFocalPoint(*focus)
516+
517+
if position:
518+
camera.SetPosition(*position)
519+
520+
if not (position or focus):
521+
renderer.ResetCamera() # fit all if no explicit position provided
522+
523+
# Update camera position with user defined relative positions
506524
camera.Roll(roll)
507525
camera.Elevation(elevation)
508-
camera.Zoom(zoom)
526+
camera.Azimuth(azimuth)
509527

510-
if position or focus:
511-
if position:
512-
camera.SetPosition(*position)
513-
if focus:
514-
camera.SetFocalPoint(*focus)
515-
else:
516-
renderer.ResetCamera()
528+
# Update camera view frustum
529+
camera.Zoom(zoom)
530+
if clipping_range:
531+
camera.SetClippingRange(*clipping_range)
517532

518533
# initialize and set size
519534
inter.Initialize()

tests/test_vis.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,14 @@ def test_camera_position(wp, patch_vtk):
222222
show(wp, position=(0, 0, 1), focus=(0, 0.1, 0))
223223
show(wp, focus=(0, 0.1, 0))
224224
show(wp, position=(0, 0, 1))
225+
226+
# Specify Z up
227+
show(wp, viewup=(0, 0, 1), position=(0, -1, 0), focus=(0, 0.1, 0))
228+
show(wp, focus=(0, 0.1, 0))
229+
show(wp, position=(0, -1, 0))
230+
show(wp, viewup=(0, 0, 1))
231+
232+
233+
def test_frustrum_clipping_range(wp, patch_vtk):
234+
235+
show(wp, zoom=2.0, clipping_range=(1, 100))

0 commit comments

Comments
 (0)