git.lucas.co / hou-control
SideFX Houdini customization package
git clone https://git.lucas.co/hou-control.git

commit8ccf0ea8235e8bcfa716cfe510a6eb653e77895a
parent3c686278f1
authorLucas Galante <[email protected]>
date2026-09-17 21:16
keycam: reset the camera aspect ratio on enter and exit

The /obj/keycam node kept whatever aspect the last session fitted, and
nothing outside keycam refits it when the pane resizes. Reset it to 1.0
on exit, and on enter reset before fitting to the current viewport.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

 viewer_states/keycam.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/viewer_states/keycam.py b/viewer_states/keycam.py
index 914bae1..441d853 100644
--- a/viewer_states/keycam.py
+++ b/viewer_states/keycam.py
@@ -31,6 +31,11 @@ class State(object):
 
         # Setup hc cam (this locks and resets to origin)
         self.cam = HCCam(self.cam_node, self.scene_viewer)
+        # Start from a square camera, then fit it to this viewport: the node
+        # keeps whatever aspect the last session fitted, which may be for a
+        # pane of a different size.
+        self.cam.resetAspectRatio()
+        self.cam.fitAspectRatio()
         # Restore captured viewport state so keycam starts where you were
         self.cam.initFromState(self._captured_state)
         units = HCSettings().keycam('units')
@@ -96,6 +101,9 @@ class State(object):
         self.scene_viewer.hou_tab.removeEventCallback(self._onViewerEvent)
         for viewport in self.scene_viewer.allViewports():
             viewport.lockCameraToView(False)
+        # Leave the camera square: outside keycam nothing refits it when the
+        # pane resizes, so a fitted aspect only distorts the next look-through.
+        self.cam.resetAspectRatio()
 
     def _onViewerEvent(self, **kwargs):
         event_type = kwargs.get('event_type')