Orthographic cameras in Blender have the shift_x, shift_y
settings:
But these are limited to the value range [-10., 10.]
. How can I achieve the same effect as orthographic shift when I need the shift to have magnitude >10
?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityOrthographic cameras in Blender have the shift_x, shift_y
settings:
But these are limited to the value range [-10., 10.]
. How can I achieve the same effect as orthographic shift when I need the shift to have magnitude >10
?
I eventually solved this by directly computing a basis for the orthographic plane myself, and moving the camera along the basis vectors as desired. This was relatively easy, thanks to https://docs.blender.org/api/current/bpy.types.Camera.html?highlight=view_frame#bpy.types.Camera.view_frame. For a given camera object cam
, I did this by identifying the pair of top-most and left-most vertices in Camera.data.view_frame()
, converting these back to world coordinates with Camera.matrix_world
, and taking differences to get two orthogonal vectors which correspond to the local X/Y directions in the orthographic plane, but can be manipulated in world-space:
top_frame_verts = sorted(cam.data.view_frame(), key=lambda v: v.y)[2:]
left_frame_verts = sorted(cam.data.view_frame(), key=lambda v: v.x)[2:]
x_axis = cam.matrix_world @ top_frame_verts[1] - cam.matrix_world @ top_frame_verts[0]
y_axis = cam.matrix_world @ left_frame_verts[1] - cam.matrix_world @ left_frame_verts[0]
I then moved the camera like:
cam.location -= x_axis * MagnitudeToShiftInX
cam.location -= y_axis * MagnitudeToShiftInY
These vectors have the further property that setting MagnitudeToShiftInX = 1.0
makes an orthographic camera moved like cam.location -= x_axis * MagnitudeToShiftInX
shift a single "camera box" in the indicated direction, so that the new camera frame will just barely border the old camera frame after this translation. That is, they are normalized to the size of the orthographic camera bounding box.