4

To fix precision issues with objects in Blender when receiving files from clients, I'm trying to select only the objects which origins are not "inside" of their mesh bounding boxes to re-center their origins. Is there a way to accomplish it?

I was thinking on getting the vertex info of the selected object and comparing it with the location of the origin, but I don't think that is the right approach.

pekkuskär
  • 307
  • 2
  • 11

1 Answers1

9

Origin in bbox.

Get Blender X,Y,Z and Bounding Box with script

Here is a quick numpy & python all, since the bottom left front (all mins) and top, back, right is all maxes and at indices (0 and 6 IIRC) could prob simply hard code that instead. Have kept min and max in case more than one bbox is involved.

How do I get the bounding box of all objects in a scene

import numpy as np
import bpy
context = bpy.context

def pt_in_bbox(pt, ob): ''' test method to see if local pt in bbox bounds '''
bbox = np.array(ob.bound_box) return all(a.min() <= p <= a.max() for p, a in zip(pt, bbox.T))

test run

scene = context.scene

for o in scene.objects: print(f"{o.name} {pt_in_bbox((0, 0, 0), o)}") # select only mesh objects with origin outside o.select_set( o.type == 'MESH' and not pt_in_bbox((0, 0, 0), o) )

batFINGER
  • 84,216
  • 10
  • 108
  • 233