0
$\begingroup$

Blender Version 3.3.0 (3.3.0 2022-09-07)

I have a camera and a 3D model (airplane). I only want to render the aircraft and the content within its bounds. Render border seems perfect for this, but for some reason, my renders always come out cropped. Here is an example output:

enter image description here

As you can see, the airplane wing is cropped out at the top. I have tried two different methods, both of which have the same issue.

  1. https://blenderartists.org/t/&setting-a-render-border-for-each-frame-of-an-animation/1160748
  2. https://www.programcreek.com/python/example/114955/bpy_extras.object_utils.world_to_camera_view

Here is my modified version of number 2, because it was written for an older version of Blender:

def autoCrop(ob):
    # ob is the bpy.context.object

    sc = bpy.context.scene
    sc.render.use_border = True
    x, y = [], []

    if ob.type in ["MESH"]:
        nmesh = ob.data.vertices
        for vertex in nmesh:
            vertex_coords = ob.matrix_world @ vertex.co
            cc = bpy_extras.object_utils.world_to_camera_view(sc, sc.camera, vertex_coords)
            x.append(cc[0])
            y.append(cc[1])

    x.sort()
    y.sort()
    sc.render.border_min_x = x[0]
    sc.render.border_max_x = x[-1]
    sc.render.border_min_y = y[0]
    sc.render.border_max_y = y[-1]
    del x
    del y

Note: automatic_render_border_margin does not exist in the documentation - I have no idea where number 2 got it from.

I am certain the object is properly centered in the camera. Here is my code to do that:

def track_object(camera, object):
    camera.constraints.new(type='TRACK_TO')
    camera.constraints['Track To'].target = bpy.data.objects[object.name]
    bpy.context.view_layer.update()

So, why is my render border too small/cropping the object and how to fix it?

$\endgroup$

1 Answer 1

0
$\begingroup$

There can be two issues (hypothetically speaking), but lets first agree that your code is correct for capturing/cropping a square in your camera view, fitting the targeted Geometry.

a) The distance of your camera is not sufficient in order to firstly frame your targeted object in the Camera View b) The pivot point of your object is not in a convenient place in the volume of your mesh (targeted object)

From what I can see in your image above it is probably the first case, since the wing on the back is reaching perfectly the bottom edge of your Rendered Image, same goes for the Tail and the Tip of the airplane. So my conclusion is that the distance of your object from your camera must be bigger.

enter image description here

in this example above the pivot has an offset which is affecting the the target constraint.

enter image description here

on that one, you have the correct pivot (somewhere in the center of your mass) but the distance of the camera from the object is not sufficient to fit it in your View.

enter image description here

And lastly, this is a "correct" distance from your targeting object with "proper" cropping.

A way to resolve this automatically would be to take in account the bounding box of the object and adjust the distance of your camera by treating it as a projection on a plane.

Apparently, my math knowledge is limited and I can't point out how to face this problem literally. But this is the direction where I would look to.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .