2
$\begingroup$

Scaling and centering generated objects to take up entire camera viewing width resolution using geometry nodes.

I have an output resolution set to 7000px (x) and 3900px (y). I would like to center and scale my object to fill the camera viewing width when it's rendered.

Example Setup:

img1

So it would fill up the width like this when rendered:

img2

My Logic:

  1. Use the Attribute Statistics node to get the dimensions of object.

  2. Calculate the dimensions needed to be centered and scaled to fit within camera view port when rendering (I'm missing this part. (Output resolution set to 7000px (x) and 3900px (y))

  3. Use a scale or transform node to make sure it fits within the camera view when rendering.

The reason for this is I'm testing a way to generate multiple objects that have different sizes and some of those objects won't fit within the camera output view resolution, so I would like to scale and center the object to make sure it fits within the camera view when it's batch rendered.

See Blend file below:

$\endgroup$
2
  • 1
    $\begingroup$ I don't think this would be possible with a perspective camera—even when you keep the focal length the same for ex, shapes of the objects will make a big difference for their visual boundaries: i.imgur.com/gN3wuwB.mp4 Is it enough that they're always contained within the frame, or do you need them to exactly fit inside (touching the frame)? Exact fit would be relatively easy with an orthographic camera. $\endgroup$
    – Kuboå
    Jan 15, 2023 at 23:26
  • $\begingroup$ @Kuboå Yes the orthographic camera would be fine. $\endgroup$
    – Rick T
    Jan 16, 2023 at 7:13

1 Answer 1

1
$\begingroup$

I don't think this is possible, at least in an easy way, with a perspective camera as there are too many things that go into it: camera's focal length, its position in 3D space, the less than immediately obvious relationship between Blender's camera sensor and the output resolution ratio... Even when you keep many of these settings the same for a certain setup and fit the objects into the same bounding box, shapes of the objects (their depth in perspective) will make a big difference for their visual boundaries:

However, things get much easier when you're OK with an orthographic camera. We can create a "container box" with dimensions that match the ratio of the output resolution, then scale our objects so they fit exactly inside that box:

enter image description here

In the setup above, I'm doing that by first checking if an object's front face ratio ($X\over Z$ dimensions of its Bounding Box) is smaller than our output resolution ratio (${7000\over3900} :1.7948$) to determine whether it is a vertical or horizontal object. If it is vertical, we scale it so the Z height of its bounding box is the same as the Container Box; if it is horizontal, we do that for its X length.

I expose the Container Box dimensions in the modifier window so I can copy the output resolution numbers as a driver to control them (purple color indicating that they are being controlled by a driver). If I set the orthographic camera's Sensor Fit to Horizontal, I can use the driver from output Resolution X to control its Orthographic Scale as well, so when I change the output resolution, the container box and the camera frame will automatically fit perfectly flush with each other:

enter image description here

$\endgroup$

You must log in to answer this question.

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