Bounds center is the middle of the bounding box.
The local positions of the axis oriented bounding box of a mesh are generated for us and available in the object's bounding box property in local coordinates.
The average of the bounding boxes 8 corner coordinates give the local center, which can be converted to global by multiplying by matrix world of owner.
Pros, only summing 8 coordinates per object and matrix multiplying once Using the object's vertices is unnecessary overhead.
import bpy
from mathutils import Vector
# mesh objects in scene
scene = bpy.context.scene
mesh_obs = [o for o in scene.objects if o.type == 'MESH']
for ob in mesh_obs:
bbox_local_center = sum((Vector(b) for b in ob.bound_box), Vector()) / 8
center = ob.matrix_world @ bbox_local_center
print(f"{ob.name} {center}")
Thought this rang a bell, possible duplicate and source of question code. Get center of geometry of an object If you source code from elsewhere, providing a link gives context.
Note.
If instead you wish to get the "global bounding box" of all recommend using numpy.
import bpy
import numpy as np
mesh objects in scene
scene = bpy.context.scene
mesh_obs = [o for o in scene.objects if o.type == 'MESH']
stack global coords of bboxes of all objects in scene
coords = np.vstack(
(np.dot(
np.hstack(
(np.array(ob.bound_box),
np.ones(8).reshape(8, 1))
),
ob.matrix_world.transposed()
)
for ob in mesh_obs)
)
#bottom front left corner, top, right back corner
print(coords.min(), coords.max())
bpy.context.selected_objects– Gorgious Sep 09 '20 at 13:48