4
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Still learning, so it is pretty basic :( $\endgroup$
    – pekkuskär
    Jul 6, 2021 at 8:16

1 Answer 1

9
$\begingroup$

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)
            )
$\endgroup$
2
  • $\begingroup$ Are bound_boxs ordered? Could you just test 2 corners? $\endgroup$
    – Robin Betts
    Jul 6, 2021 at 9:57
  • 1
    $\begingroup$ AFAIK yes. As mentioned 0 is mins, 6 is maxes. all(a <= p <= b for a, p, b in zip(bbox[0], pt, bbox[6])) $\endgroup$
    – batFINGER
    Jul 6, 2021 at 9:58

You must log in to answer this question.

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