0
$\begingroup$

I am programmatically (via the Python BPY module) creating a render border. See this SO post for working code.

I use the bounding box (object.bound_box) and project it to camera view, so that I can construct the render border. The issue is that because 3D objects can be irregular in shape, the Blender-generated bounding box (object.bound_box) is often rectangular, rather than square, which means that depending on the angel of the model to the camera, the 'padding' around the resulting render border can be quite large...

My idea is this: if we ensure that the bounding box around the model is always a cube, the angel will not impact the resulting render border.

How can I reshape the bounding box to be a square?

I tried, but I think my code is wrong because it works on the 2D coordinates of the render border, rather than the 3D coordinates (of which there are 8) of the bound_box:

print('minX: {}, minY: {}, maxX: {}, maxY: {}'.format(minX, minY, maxX, maxY))

dx = maxX-minX
dy = maxY-minY
if dx>dy:
    minY = minY - abs(dx-dy)*0.5
    maxY = maxY + abs(dx-dy)*0.5
else:
    minX = minX - abs(dx-dy)*0.5
    maxX = maxX + abs(dx-dy)*0.5

dx = maxX-minX
dy = maxY-minY
print('minX: {}, minY: {}, maxX: {}, maxY: {}, dx: {}, dy: {}'.format(minX, minY, maxX, maxY, dx, dy))
$\endgroup$
2
  • $\begingroup$ Hello ! I don't understand how forcing the bbox to be square would optimise the border surface ? If anything it will increase the gaps ? $\endgroup$
    – Gorgious
    Dec 7, 2022 at 8:43
  • $\begingroup$ @Gorgious It does not need to optimize/shrink the gaps - the gap sizes between the model and the border/bounding box just need to be the same. $\endgroup$
    – pookie
    Dec 7, 2022 at 14:57

0

You must log in to answer this question.

Browse other questions tagged .