Bounding box coords of all meshes in scene.
Pretty sure this has been answered before, but finding it is another matter.
Here is some numpy code I use to create a bounding box for all mesh objects in a scene
Basically, list coordinates of all bounding box coordinates of all mesh objects in the scene.
Use the minima / maxima of each axis produce an axis aligned bounding box encompassing all others.
import bpy
from mathutils import Vector
from bpy import context
import numpy as np
import itertools
multiply 3d coord list by matrix
def np_matmul_coords(coords, matrix, space=None):
M = (space @ matrix @ space.inverted()
if space else matrix).transposed()
ones = np.ones((coords.shape[0], 1))
coords4d = np.hstack((coords, ones))
return np.dot(coords4d, M)[:,:-1]
return coords4d[:,:-1]
get the global coordinates of all object bounding box corners
coords = np.vstack(
tuple(np_matmul_coords(np.array(o.bound_box), o.matrix_world.copy())
for o in
context.scene.objects
if o.type == 'MESH'
)
)
print("#" * 72)
bottom front left (all the mins)
bfl = coords.min(axis=0)
top back right
tbr = coords.max(axis=0)
G = np.array((bfl, tbr)).T
bound box coords ie the 8 combinations of bfl tbr.
bbc = [i for i in itertools.product(*G)]
print(np.array(bbc))