From f1db8e35ce6971f97407ff64e04ace039c579a09 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Sun, 18 May 2025 11:08:46 -0700 Subject: [PATCH 1/2] 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. --- cadquery/vis.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/cadquery/vis.py b/cadquery/vis.py index 5fbedb12f..5966b06d2 100644 --- a/cadquery/vis.py +++ b/cadquery/vis.py @@ -391,8 +391,11 @@ def show( zoom: float = 1.0, roll: float = -35, elevation: float = -45, + azimuth: float = 0, position: Optional[Tuple[float, float, float]] = None, focus: Optional[Tuple[float, float, float]] = None, + viewup: Optional[Tuple[float, float, float]] = None, + clipping_range: Optional[Tuple[float, float]] = None, width: Union[int, float] = 0.5, height: Union[int, float] = 0.5, trihedron: bool = True, @@ -491,17 +494,27 @@ def show( # set camera camera = renderer.GetActiveCamera() + + # Reset orientation to known state + renderer.ResetCamera() + + # Update camera position with user provided absolute positions + if viewup: + camera.SetViewUp(*viewup) + if position: + camera.SetPosition(*position) + if focus: + camera.SetFocalPoint(*focus) + + # Update camera position with user defined relative positions camera.Roll(roll) camera.Elevation(elevation) - camera.Zoom(zoom) + camera.Azimuth(azimuth) - if position or focus: - if position: - camera.SetPosition(*position) - if focus: - camera.SetFocalPoint(*focus) - else: - renderer.ResetCamera() + # Update camera view frustum + camera.Zoom(zoom) + if clipping_range: + camera.SetClippingRange(*clipping_range) # initialize and set size inter.Initialize() From 58e52a1f0abc55b22577ae426eae90aa45b0f16f Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Tue, 3 Jun 2025 15:22:37 -0700 Subject: [PATCH 2/2] test: Add testing of viewup and clipping_range --- tests/test_vis.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_vis.py b/tests/test_vis.py index 513ec2671..92b98c462 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -218,3 +218,14 @@ def test_camera_position(wp, patch_vtk): show(wp, position=(0, 0, 1), focus=(0, 0.1, 0)) show(wp, focus=(0, 0.1, 0)) show(wp, position=(0, 0, 1)) + + # Specify Z up + show(wp, viewup=(0, 0, 1), position=(0, -1, 0), focus=(0, 0.1, 0)) + show(wp, focus=(0, 0.1, 0)) + show(wp, position=(0, -1, 0)) + show(wp, viewup=(0, 0, 1)) + + +def test_frustrum_clipping_range(wp, patch_vtk): + + show(wp, zoom=2.0, clipping_range=(1, 100))