Blender Cycles backend¶
quiltwright.cycles
¶
Blender Cycles Quilt Renderer¶
Drives Blender <https://www.blender.org/>_'s Cycles path tracer to produce
quilts for Looking Glass holographic displays. This is the
hardware-ray-tracing sibling of :mod:quiltwright.povray: on Apple Silicon,
Cycles' Metal backend runs ray/triangle intersection on the GPU's dedicated
ray-tracing cores (M3 and later; earlier chips run the same Metal path in GPU
software), and the equivalent applies on NVIDIA (OptiX), AMD (HIP) and Intel
(oneAPI) hardware elsewhere. POV-Ray can never use any of that -- it is a
CPU tracer with its own primitive intersectors -- so scenes that exist as
meshes rather than POV-Ray SDL come here instead.
The structural win over the POV-Ray backend is bigger than the hardware:
POV-Ray re-parses the scene and rebuilds its data structures once per view --
48 times for a Portrait quilt -- while this backend runs one Blender
process for the whole sweep. The scene imports once, Cycles builds its BVH
once (use_persistent_data), and only the camera moves between views.
Off-axis projection. The same shear as every other quiltwright backend,
expressed through Blender's camera shift. For an eye offset s along
the camera's unit right vector, with focal distance Z, vertical field of
view fov and view aspect a, the eye translates by s (the aim
point riding along, so the view direction never rotates) and the frustum is
sheared back with
.. code-block:: text
shift_x = -s / (2 * Z * tan(fov/2) * a)
which is the identical quantity VTK's SetWindowCenter receives in
:func:quiltwright.lfd._apply_off_axis_view, in Blender's units (fractions
of the frame width, under a horizontal sensor fit) instead of VTK's
half-widths. The original look-at point stays pinned to the centre of every
view; that point is the holographic focal plane.
Scene sources. A .blend file renders with its own materials, lights
and world; everything Blender can import -- glTF/GLB, OBJ, STL, PLY, USD,
FBX, Alembic -- is loaded into an empty scene. Imported meshes usually
arrive without lights, which in a path tracer means a black frame, so by
default a neutral world and a sun are added when the scene has no light of
its own. The lighting parameter picks the rig: a neutral
world-plus-sun ("soft", the default), a camera-relative three-point
studio rig ("studio"), Blender's physical sky ("sky"), an
equirectangular .hdr/.exr environment map, or None to add
nothing.
A .blend may also supply its own camera: pass camera=None and the
file's active camera becomes the centre view. The focal plane then comes
from the camera's depth-of-field focus distance (or focus object) -- that is
Blender's native "this distance matters" annotation, and setting it does not
blur anything unless DoF is actually enabled.
Requirements -- a blender binary (macOS: brew install --cask
blender; the standard /Applications install is found automatically),
plus pillow for quilt assembly. Blender 4.x or later.
Typical usage::
from quiltwright.quilt import QUILT_PRESETS, save_quilt
from quiltwright.cycles import CyclesCamera, render_cycles_quilt
camera = CyclesCamera(location=(0, -35, 8), look_at=(0, 0, 5), fov=14)
spec = QUILT_PRESETS["portrait"]
quilt = render_cycles_quilt("protein.glb", spec, camera, samples=128)
save_quilt(quilt, "protein", spec) # -> protein_qs8x6a0.75.png
Part of Quiltwright -- https://github.com/Flux-Frontiers/quiltwright Author: Eric G. Suchanek, PhD
CyclesCamera(location, look_at, up=(0.0, 0.0, 1.0), fov=14.0)
dataclass
¶
A Blender camera in look-at form, plus the quilt's focal geometry.
The look_at point defines the holographic focal plane, so aim it at whatever should sit on the surface of the glass. Geometry closer to the camera floats out of the display; geometry beyond it recedes.
Coordinates are Blender's own: right-handed, Z up. This is the same
convention most mesh interchange formats and :mod:pyvista use, so no
conversion applies -- unlike :class:~quiltwright.povray.PovCamera,
which speaks POV-Ray's left-handed world.
The fov/focal_distance pairing matches PovCamera, so
:func:~quiltwright.povray.depth_budget and
:func:~quiltwright.povray.format_depth_budget accept either camera:
run the depth budget before committing Cycles to a 48-view render,
exactly as you would for POV-Ray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
tuple[float, float, float]
|
Eye position |
required |
look_at
|
tuple[float, float, float]
|
Point the camera is aimed at. Becomes the focal plane. |
required |
up
|
tuple[float, float, float]
|
Up-hint used to build the camera basis. Must not be parallel
to the view direction. Defaults to |
(0.0, 0.0, 1.0)
|
fov
|
float
|
Vertical field of view in degrees. Looking Glass
recommends ~14° for object-centric content; see
:class: |
14.0
|
focal_distance
property
¶
Distance from the eye to the focal plane, in scene units.
aimed(location, aim, *, fov, focal_distance=None, lateral_shift=0.0, up=(0.0, 0.0, 1.0))
classmethod
¶
Adopt a scene's own viewpoint, re-aimed and re-centred for a sweep.
The mesh-world twin of :meth:.PovCamera.aimed, with the same
contract: the focal plane moves to focal_distance along the
original aim ray and the eye slides lateral_shift along the
camera's right vector, without touching the view direction or the
lens. Pair with :class:~quiltwright.povray.Clearance for enclosed
scenes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Sequence[float]
|
The scene's eye position. |
required |
aim
|
Sequence[float]
|
The scene's aim point. Used for direction only unless
focal_distance is |
required |
fov
|
float
|
Vertical field of view in degrees. |
required |
focal_distance
|
float | None
|
Distance along the aim ray to place the focal plane. Defaults to the scene's own aim distance. |
None
|
lateral_shift
|
float
|
Distance to slide the eye along the camera's right vector before re-aiming. |
0.0
|
up
|
tuple[float, float, float]
|
Up-hint, as on :class: |
(0.0, 0.0, 1.0)
|
Returns:
| Type | Description |
|---|---|
CyclesCamera
|
The centre-view camera. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the camera is degenerate (see :meth: |
Source code in src/quiltwright/cycles.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
basis()
¶
Orthonormal camera basis (forward, right, up).
Right-handed -- right = forward x up_hint -- so a camera looking
down +y with +z up gets right = +x. The driver rebuilds
the same basis inside Blender; the end-to-end test pins the two
against each other via the focal-plane invariant.
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray]
|
Three unit vectors as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the camera is degenerate (zero-length view direction, or up parallel to it). |
Source code in src/quiltwright/cycles.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
autoframe_camera(scene, *, fov=14.0, view_direction=(0.0, -1.0, 0.0), up=(0.0, 0.0, 1.0), margin=FRAME_MARGIN, binary=None)
¶
Probe a mesh file's bounds and return a :class:CyclesCamera framing it.
:func:mesh_bounds then :func:frame_camera -- the one call an
unfamiliar mesh file needs before :func:render_cycles_quilt, since the
file carries no camera of its own. The returned camera's look_at is
the bounds centre (the focal plane); run
:func:~quiltwright.povray.format_depth_budget on it before committing to
a full sweep, exactly as for any other :class:CyclesCamera.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
str | Path
|
Path to an importable mesh format in :data: |
required |
fov
|
float
|
Vertical field of view in degrees. |
14.0
|
view_direction
|
Sequence[float]
|
Direction from the bounds centre to the eye; see
:func: |
(0.0, -1.0, 0.0)
|
up
|
tuple[float, float, float]
|
Up-hint for the camera. |
(0.0, 0.0, 1.0)
|
margin
|
float
|
Framing headroom; see :func: |
FRAME_MARGIN
|
binary
|
str | None
|
Blender executable; see :func: |
None
|
Returns:
| Type | Description |
|---|---|
CyclesCamera
|
The centre-view :class: |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the bounds probe fails; see :func: |
Source code in src/quiltwright/cycles.py
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 | |
cycles_camera_from_plotter(plotter, *, fov=14.0, zoom=None)
¶
Build the :class:CyclesCamera matching a plotter's current view.
The plotter's camera defines the centre view and its focal point becomes
the holographic focal plane, exactly as in
:func:~quiltwright.lfd.render_quilt -- including its FOV convention:
the lens is narrowed to fov and the camera dollied back so the focal
plane stays the same size in frame. The result is expressed in
Blender's world under the glTF contract above, so it pairs with
:func:export_plotter_gltf and nothing else.
The plotter is read, never mutated: unlike render_quilt, whose
sweep must drive the live VTK camera, this backend renders from a copy
of the view, so the plotter remains exactly as composed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plotter
|
A |
required | |
fov
|
float | None
|
Vertical field of view in degrees for the quilt cameras;
the eye dollies back to compensate. |
14.0
|
zoom
|
float | None
|
Optional dolly factor applied after framing; values > 1 make the subject fill more of each tile, which is what drives perceived depth. |
None
|
Returns:
| Type | Description |
|---|---|
|
The centre-view :class: |
Source code in src/quiltwright/cycles.py
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 | |
export_plotter_gltf(plotter, path)
¶
Export a composed PyVista plotter scene as glTF for this backend.
A thin wrapper over plotter.export_gltf that pins the export
settings the coordinate contract above depends on -- most importantly
rotate_scene=False. Export works headless: no OpenGL context or
prior render is required, so it runs where plotter.show() cannot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plotter
|
A |
required | |
path
|
str | Path
|
Destination |
required |
Returns:
| Type | Description |
|---|---|
Path
|
path, as a :class: |
Source code in src/quiltwright/cycles.py
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 | |
frame_camera(lo, hi, *, fov=14.0, view_direction=(0.0, -1.0, 0.0), up=(0.0, 0.0, 1.0), margin=FRAME_MARGIN)
¶
A :class:CyclesCamera framing an axis-aligned box, aimed at its centre.
Places the eye along view_direction from the box centre at the distance
that makes the box's enclosing sphere fill fov (with margin
headroom), and aims back at the centre -- which becomes the holographic
focal plane. Uses the exact spherical relation sin(fov/2) = r / d
rather than the small-angle tangent, since object-centric FOVs (~14-30
deg) are not small angles; the enclosing sphere (half the box diagonal)
is used so the whole box stays framed from any view_direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lo
|
Sequence[float] | ndarray
|
Box minimum corner |
required |
hi
|
Sequence[float] | ndarray
|
Box maximum corner. |
required |
fov
|
float
|
Vertical field of view in degrees. |
14.0
|
view_direction
|
Sequence[float] | ndarray
|
Direction from the box centre to the eye; need not
be normalised. The default |
(0.0, -1.0, 0.0)
|
up
|
tuple[float, float, float]
|
Up-hint passed to the camera; must not be parallel to view_direction. |
(0.0, 0.0, 1.0)
|
margin
|
float
|
Framing headroom beyond a tight fit -- 1.0 is exactly tight, the default leaves a little air. |
FRAME_MARGIN
|
Returns:
| Type | Description |
|---|---|
CyclesCamera
|
The centre-view :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the box is degenerate (zero diagonal) or view_direction is the zero vector. |
Source code in src/quiltwright/cycles.py
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 | |
mesh_bounds(scene, *, binary=None, extra_args=())
¶
Import a mesh file headlessly and return its world-space bounds.
Runs one background Blender that imports scene through the same
importer :func:render_cycles_quilt uses -- so the returned box is
exactly what the render will see, with the file's transforms and
axis conversion applied -- and reports the combined bounding box of every
mesh object. Pair with :func:frame_camera (or call
:func:autoframe_camera, which does both) to give an imported mesh the
camera it doesn't carry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
str | Path
|
Path to an importable mesh format in :data: |
required |
binary
|
str | None
|
Blender executable; see :func: |
None
|
extra_args
|
Sequence[str]
|
Extra Blender command-line arguments. |
()
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the scene file does not exist. |
ValueError
|
If the format is unsupported, or is |
RuntimeError
|
If Blender fails, or the scene has no mesh object. |
Source code in src/quiltwright/cycles.py
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 | |
render_cycles_quilt(scene, spec, camera, *, view_cone=None, samples=64, denoise=True, view_transform='Standard', device='auto', lighting='soft', threads=None, binary=None, extra_args=(), keep_views=None, progress=True)
¶
Render a mesh scene with Cycles into a Looking Glass quilt.
Sweeps camera horizontally across the display's view cone using
off-axis projections (see the module docstring), path-traces one image
per view, and tiles them with :func:~quiltwright.lfd.assemble_quilt.
The whole sweep runs in one Blender process: the scene imports once
and Cycles keeps its BVH across views (use_persistent_data), so cost
per view is dominated by actual ray tracing -- on Apple Silicon, Metal
hardware ray tracing when a GPU device is available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
str | Path
|
Path to the scene -- |
required |
spec
|
QuiltSpec
|
Quilt specification (grid, size, aspect, cone). |
required |
camera
|
CyclesCamera | None
|
Base camera; its |
required |
view_cone
|
float | None
|
Override the spec's view cone in degrees. |
None
|
samples
|
int
|
Cycles samples per pixel. 64 previews cleanly with denoising; 128-256 for finals. |
64
|
denoise
|
bool
|
Run Cycles' denoiser on each view. |
True
|
view_transform
|
str
|
Color management applied to the render -- an OCIO
view transform name Blender recognises ( |
'Standard'
|
device
|
str
|
|
'auto'
|
lighting
|
str | Path | None
|
How to light an imported scene that has no lights of
its own -- without this a path tracer renders an unlit import black.
|
'soft'
|
threads
|
int | None
|
Blender |
None
|
binary
|
str | None
|
Blender executable; defaults to |
None
|
extra_args
|
Sequence[str]
|
Extra Blender command-line arguments, e.g. a
|
()
|
keep_views
|
str | Path | None
|
Directory to retain the per-view PNGs and the job
description in, for inspection. Discarded if |
None
|
progress
|
bool
|
Print a progress line while rendering. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in src/quiltwright/cycles.py
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 | |
render_cycles_quilt_from_plotter(plotter, spec, *, fov=14.0, zoom=None, gltf=None, **kwargs)
¶
Render a PyVista plotter's scene into a quilt with Cycles.
The hardware-ray-traced sibling of :func:~quiltwright.lfd.render_quilt:
same plotter in, same quilt out, but the views are path-traced by Cycles
-- with GPU ray tracing where the hardware offers it -- instead of
rasterised by VTK. Compose the scene and position the camera exactly as
you would for render_quilt, then swap the call.
The scene is exported to glTF once (see :func:export_plotter_gltf) and
the whole sweep renders in one Blender process. The export carries no
lights, so the backend's lighting rigs supply them -- the "soft"
default for a neutral look, lighting="studio" for a three-point
product shot, "sky" or an HDRI path for environments; pass
materials-appropriate samples for finals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plotter
|
An off-screen |
required | |
spec
|
QuiltSpec
|
Quilt specification (grid, size, aspect, cone). |
required |
fov
|
float | None
|
Vertical field of view in degrees, with the
|
14.0
|
zoom
|
float | None
|
Optional dolly factor applied after framing, as on
:func: |
None
|
gltf
|
str | Path | None
|
Also write the exported scene here, for inspection or
reuse. Exported to a temporary file if |
None
|
kwargs
|
Forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in src/quiltwright/cycles.py
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 | |
render_cycles_views(scene, spec, camera, out_dir, *, view_cone=None, samples=64, denoise=True, view_transform='Standard', device='auto', lighting='soft', threads=None, binary=None, extra_args=(), keep_job=False, progress=True)
¶
Render a mesh scene as a sweep of separate view images.
Identical camera geometry to :func:render_cycles_quilt -- the same
off-axis sheared frustum, the same focal plane -- but the frames are
written out individually instead of being tiled into a quilt, for
consumers like hologram printers and lenticular interlacers. Pair with
:func:~quiltwright.lfd.sweep_spec for view counts no quilt grid can
express.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
str | Path
|
Path to the scene, as for :func: |
required |
spec
|
QuiltSpec
|
Sweep or quilt specification supplying view count, view cone, and per-view pixel size. |
required |
camera
|
CyclesCamera | None
|
Base camera, or |
required |
out_dir
|
str | Path
|
Directory to write the frames into; created if absent. |
required |
view_cone
|
float | None
|
Override the spec's view cone in degrees. |
None
|
samples
|
int
|
Cycles samples per pixel. |
64
|
denoise
|
bool
|
Run Cycles' denoiser on each view. |
True
|
view_transform
|
str
|
Color management; see :func: |
'Standard'
|
device
|
str
|
|
'auto'
|
lighting
|
str | Path | None
|
Rig for an unlit imported scene -- |
'soft'
|
threads
|
int | None
|
Blender |
None
|
binary
|
str | None
|
Blender executable override. |
None
|
extra_args
|
Sequence[str]
|
Extra Blender command-line arguments. |
()
|
keep_job
|
bool
|
Also write the |
False
|
progress
|
bool
|
Print a progress line while rendering. |
True
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
Paths to the written frames, in view order -- view 0 leftmost. |
Source code in src/quiltwright/cycles.py
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
view_shift_x(offset, focal_distance, fov, aspect)
¶
Blender camera shift_x for one quilt view, under a horizontal
sensor fit.
The off-axis shear in Blender's units: the eye has translated offset
along the right vector, and this shift slides the frustum window back so
the original look-at point stays centred. It is the same quantity VTK's
SetWindowCenter receives in the PyVista backend, converted from
half-widths to Blender's fractions of the frame width (a factor of 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset
|
float
|
Lateral eye offset along the camera's right vector, in
scene units, from :func: |
required |
focal_distance
|
float
|
Camera-to-focal-plane distance, in scene units. |
required |
fov
|
float
|
Vertical field of view in degrees. |
required |
aspect
|
float
|
Width / height of the rendered view. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The |
Source code in src/quiltwright/cycles.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |