diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-02-15 03:33:47 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-02-15 03:33:47 +0300 |
commit | 58ba89b5bec5a2b7b74ef93fe18f0a3811cb48db (patch) | |
tree | c637d3314827ddc39e98aedd261c66e69ddf1549 /release/scripts/startup/bl_operators/object_align.py | |
parent | 70f1b8cc4061fac81413c723b973386050e2561e (diff) |
Fix T54075: Align Objects fails w/ empty mesh
Diffstat (limited to 'release/scripts/startup/bl_operators/object_align.py')
-rw-r--r-- | release/scripts/startup/bl_operators/object_align.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/release/scripts/startup/bl_operators/object_align.py b/release/scripts/startup/bl_operators/object_align.py index 8669c2ddbd6..03b0d4f04a2 100644 --- a/release/scripts/startup/bl_operators/object_align.py +++ b/release/scripts/startup/bl_operators/object_align.py @@ -24,7 +24,7 @@ from bpy.types import Operator from mathutils import Vector -def GlobalBB_LQ(bb_world): +def worldspace_bounds_from_object_bounds(bb_world): # Initialize the variables with the 8th vertex left, right, front, back, down, up = ( @@ -66,7 +66,7 @@ def GlobalBB_LQ(bb_world): return (Vector((left, front, up)), Vector((right, back, down))) -def GlobalBB_HQ(scene, obj): +def worldspace_bounds_from_object_data(scene, obj): matrix_world = obj.matrix_world.copy() @@ -75,20 +75,20 @@ def GlobalBB_HQ(scene, obj): me = obj.to_mesh(scene=scene, apply_modifiers=True, settings='PREVIEW') verts = me.vertices - val = matrix_world * verts[-1].co + val = matrix_world * (verts[-1].co if verts else Vector((0.0, 0.0, 0.0))) - left, right, front, back, down, up = (val[0], - val[0], - val[1], - val[1], - val[2], - val[2], - ) + left, right, front, back, down, up = ( + val[0], + val[0], + val[1], + val[1], + val[2], + val[2], + ) # Test against all other verts - for i in range(len(verts) - 1): - - vco = matrix_world * verts[i].co + for v in verts: + vco = matrix_world * v.co # X Range val = vco[0] @@ -155,9 +155,9 @@ def align_objects(context, for obj, bb_world in objects: if bb_quality and obj.type == 'MESH': - GBB = GlobalBB_HQ(scene, obj) + GBB = worldspace_bounds_from_object_data(scene, obj) else: - GBB = GlobalBB_LQ(bb_world) + GBB = worldspace_bounds_from_object_bounds(bb_world) Left_Front_Up = GBB[0] Right_Back_Down = GBB[1] @@ -219,9 +219,9 @@ def align_objects(context, bb_world = [matrix_world * Vector(v[:]) for v in obj.bound_box] if bb_quality and obj.type == 'MESH': - GBB = GlobalBB_HQ(scene, obj) + GBB = worldspace_bounds_from_object_data(scene, obj) else: - GBB = GlobalBB_LQ(bb_world) + GBB = worldspace_bounds_from_object_bounds(bb_world) Left_Front_Up = GBB[0] Right_Back_Down = GBB[1] |