Put the camera in front of an object?

Hi,

Is it possible to put the camera in front of an object in orthographic view, so that the angle is exactly 90° and the plane is maximized in the render view?

I think I should search for the local normal vector of the plane I am interested in, convert that local into world space, and align the camera to that vector.

As for the maximization… no idea…
Not sure how to do it through the blender API…

The object is always a flat plane.

Any help?

This script doesn’t, “automatically,” calculate the active scene camera’s aspect ratio, but it is setup to accept custom size values. The script below will rotate and align a camera to an object.

Before

  • Active camera is set to random location & rotation - has default camera FOV / aspect ratio
  • Plane can be arbitrarily placed; its world scale can be any value as well, I chose default 1.0 for all axises
  • If you don’t tweak the object size, whether via the Python script or in the 3D viewport UI, the aspect ratio won’t be correct. e.g.

After

  • Camera rotation is set to 90 degrees + aligns view to object location
  • [Plane] Object size automatically sets to [X=2, Y=1.125, Z=1], which can be manually tweaked in the script variables

Script

import bpy, math

# DESLECTS ALL OBJECTS
bpy.ops.object.select_all(action="DESELECT")

# SELECTS A CERTAIN OBJECT
VAR_OBJ = bpy.data.objects["Plane"]
VAR_OBJ.select_set(True)

# SETS A CERTAIN OBJECT'S SIZE TO DEFAULT CAMERA ASPECT RATIO
VAR_OBJ.scale[0] = 2
VAR_OBJ.scale[1] = 1.125
VAR_OBJ.scale[2] = 1

# SETS CAMERA ROTATION TO 90 DEGREES
bpy.context.scene.camera.rotation_euler[0] = math.radians(90)
bpy.context.scene.camera.rotation_euler[1] = math.radians(0)
bpy.context.scene.camera.rotation_euler[2] = math.radians(0)

# ALIGNS CAMERA LOCATION TO DESIRED OBJECT
bpy.ops.view3d.camera_to_view_selected()

# DESLECTS ALL OBJECTS AGAIN
bpy.ops.object.select_all(action="DESELECT")

Cool! it works!

May I ask you how you came to the value 2, 1.125 and 1 please? Where could I have found these values?
Thanks a lot

As for 1.125:
I guess it is because 2 * 9/16 = 1.125… :slightly_smiling_face:

I literally just zoomed while in the active camera is in focus and attempted to scale the plane’s size to the camera’s aspect ratio. :sweat_smile: Other’s have created some scripts that actually automatically calculate the correct sizing to match visually, and I tried to implement some, but it’s a bit too complicated for me at the moment. I am by no means a begineer at Python, but I am rather new to Blender’s BPY modules so to speak.

:grinning: well done