Sub topic 3
Positioning and aiming the camera
This chapter assumes you can add objects, move them with G and R, and use the Properties editor. The Python sections assume you can read basic bpy code, which is Blender's Python interface.
Placing and aiming the camera
Place the camera by setting its location in the N sidebar, then point it at the subject. A Track To constraint keeps the camera aimed at a target object while you move the camera. Set the track axis to negative Z, because Blender cameras look down their local negative Z axis.
For a quick manual aim, select the camera, press Numpad 0 to look through it, and rotate it with R until the subject sits where you want it.
Lens shift and passepartout
Lens shift moves the frame without tilting the camera. This keeps vertical lines straight in architectural shots. Set Shift X and Shift Y in the Lens panel of the camera data. Passepartout darkens the area outside the frame in the viewport, so you can judge the framing. It does not change the rendered image.
Depth of field with a focus object and f-stop
Depth of field blurs objects that sit outside the focus range. Enable it in the Depth of Field panel, set a Focus Object so the camera stays sharp on that object, and lower the f-stop for a shallower blur. An f-stop of 2.8 gives a clear blur. Higher values keep more of the scene sharp.
Switching cameras with timeline markers
A timeline marker bound to a camera switches the active camera at its frame. This creates a cut during playback and rendering. Add a marker in the timeline with M, then set its camera in the marker settings.
Scripting cameras with bpy
The script below creates a camera, aims it at an object named "Subject", and sets up depth of field. The Subject object must exist in your scene.
import bpy
scene = bpy.context.scene
cam_data = bpy.data.cameras.new("ShotCamera")
cam_data.lens = 50
cam_data.shift_x = 0.0
cam_data.show_passepartout = True
cam_data.passepartout_alpha = 0.5
cam_obj = bpy.data.objects.new("ShotCamera", cam_data)
scene.collection.objects.link(cam_obj)
cam_obj.location = (7.0, -7.0, 5.0)
scene.camera = cam_obj
target = bpy.data.objects["Subject"]
con = cam_obj.constraints.new(type='TRACK_TO')
con.target = target
con.track_axis = 'TRACK_NEGATIVE_Z'
con.up_axis = 'UP_Y'
cam_data.dof.use_dof = True
cam_data.dof.focus_object = target
cam_data.dof.aperture_fstop = 2.8The next snippet adds a marker that cuts to a second camera at frame 48. The second camera, named "CameraB", must already exist.
import bpy
scene = bpy.context.scene
cam_b = bpy.data.objects["CameraB"]
marker = scene.timeline_markers.new("CutToB", frame=48)
marker.camera = cam_bExercise
Why does the Track To constraint use negative Z as the track axis?
Show answer
Blender cameras look down their local negative Z axis, so negative Z points the camera's view at the target.