SideFX Houdini customization package
git clone https://git.lucas.co/hou-control.git
python3.13libs/hc/hcframing.py (591B)
1 import math
2
3
4 def perspective_frame_distance(bbox_size, aperture, focal, aspect_ratio, margin=1.2):
5 aspect_ratio = max(aspect_ratio, 1e-6)
6 fov_h = 2.0 * math.atan(aperture / (2.0 * focal))
7 fov_v = 2.0 * math.atan((aperture / aspect_ratio) / (2.0 * focal))
8
9 radius = math.sqrt(sum(axis * axis for axis in bbox_size)) * 0.5
10 dist_h = (radius * margin) / max(math.sin(fov_h * 0.5), 1e-6)
11 dist_v = (radius * margin) / max(math.sin(fov_v * 0.5), 1e-6)
12 return max(dist_h, dist_v)
13
14
15 def orthographic_frame_width(bbox_size, margin=1.8):
16 return max(bbox_size) * margin