Situation: On my scene, planes can be positioned anywhere and I should not move them - I move around only camera. After positioning a orthographic camera with a script, I am not sure if the whole plane is being rendered - I want to render one whole plane at a time (also areas that don't belong to a plane are not desired on a render).
My questions:
- Given a camera position and the plane in 3D space (where camera is orthogonally positioned to plane), how can I check if the whole surface of a plane is being rendered using orthographic camera?
- Is it possible to calculate the proportion of a plane's surface that's going go be visible on a render?
The reason I need this is because I cant figure out proper camera positioning function. What I did until now is I: find a center of mesh and calculate the plane's normal out of it, I position the orthographic camera on plane's normal some distance away. Now I don't know how to set the orthographic camera's rotation and scale to render only the plane.
Not finished camera positioning code:
import bpy
import bpy_extras
import mathutils
from mathutils import Vector
def get_global_plane_normal(plane):
normal_local = plane.data.vertices[0].normal.to_4d()
normal_local.w = 0
normal_global = (plane.matrix_world * normal_local).to_3d()
normal_global.normalize()
return normal_global
def main():
scene = bpy.context.scene
plane = scene.objects.active
coords = [(plane.matrix_world * v.co) for v in plane.data.vertices]
# Calculate the center of the mesh
local_bbox_center = 0.125 * sum((Vector(b) for b in plane.bound_box), Vector())
global_bbox_center = plane.matrix_world * local_bbox_center
plane_normal = get_global_plane_normal(plane)
# Set camera to distance from a plane
distance = 1
camera_position_vtx = global_bbox_center + distance * plane_normal
camera = bpy.context.scene.objects["Camera"]
camera.location = camera_position_vtx
bpy.context.scene.objects.active = camera
# TODO: Rotate and set orthographic scale to the right values,
# only the plane is visible.
main()
Thank you for your time!