Align Object op: Introducing Align Modes Negative Sides / Centers /

Positive Sides. Not the most beautiful code ever but will beautify after everything is
implemented
This commit is contained in:
2010-02-15 06:01:13 +00:00
parent 1f3faf0591
commit d300c28e74

View File

@@ -22,7 +22,7 @@ import bpy
from Mathutils import Vector
def align_objects(align_x, align_y, align_z, relative_to):
def align_objects(align_x, align_y, align_z, align_mode, relative_to):
cursor = bpy.context.scene.cursor_location
@@ -46,6 +46,10 @@ def align_objects(align_x, align_y, align_z, relative_to):
center_active_y = ( Left_Up_Front[1] + Right_Down_Back[1] ) / 2
center_active_z = ( Left_Up_Front[2] + Right_Down_Back[2] ) / 2
size_active_x = ( Right_Down_Back[0] - Left_Up_Front[0] ) / 2
size_active_y = ( Right_Down_Back[1] - Left_Up_Front[1] ) / 2
size_active_z = ( Left_Up_Front[2] - Right_Down_Back[2] ) / 2
# Selection Center
if flag_first:
@@ -97,12 +101,39 @@ def align_objects(align_x, align_y, align_z, relative_to):
center_x = ( Left_Up_Front[0] + Right_Down_Back[0] ) / 2
center_y = ( Left_Up_Front[1] + Right_Down_Back[1] ) / 2
center_z = ( Left_Up_Front[2] + Right_Down_Back[2] ) / 2
positive_x = Right_Down_Back[0]
positive_y = Right_Down_Back[1]
positive_z = Left_Up_Front[2]
negative_x = Left_Up_Front[0]
negative_y = Left_Up_Front[1]
negative_z = Right_Down_Back[2]
obj_loc = obj.location
if align_x:
obj_x = obj_loc[0] - center_x
# Align Mode
if relative_to == 'OPT_4': # Active relative
if align_mode == 'OPT_1':
obj_x = obj_loc[0] - negative_x - size_active_x
elif align_mode == 'OPT_3':
obj_x = obj_loc[0] - positive_x + size_active_x
else: # Everything else relative
if align_mode == 'OPT_1':
obj_x = obj_loc[0] - negative_x
elif align_mode == 'OPT_3':
obj_x = obj_loc[0] - positive_x
if align_mode == 'OPT_2': # All relative
obj_x = obj_loc[0] - center_x
# Relative To
if relative_to == 'OPT_1':
loc_x = obj_x
@@ -121,7 +152,26 @@ def align_objects(align_x, align_y, align_z, relative_to):
if align_y:
obj_y = obj_loc[1] - center_y
# Align Mode
if relative_to == 'OPT_4': # Active relative
if align_mode == 'OPT_1':
obj_y = obj_loc[1] - negative_y - size_active_y
elif align_mode == 'OPT_3':
obj_y = obj_loc[1] - positive_y + size_active_y
else: # Everything else relative
if align_mode == 'OPT_1':
obj_y = obj_loc[1] - negative_y
elif align_mode == 'OPT_3':
obj_y = obj_loc[1] - positive_y
if align_mode == 'OPT_2': # All relative
obj_y = obj_loc[1] - center_y
# Relative To
if relative_to == 'OPT_1':
loc_y = obj_y
@@ -140,7 +190,26 @@ def align_objects(align_x, align_y, align_z, relative_to):
if align_z:
obj_z = obj_loc[2] - center_z
# Align Mode
if relative_to == 'OPT_4': # Active relative
if align_mode == 'OPT_1':
obj_z = obj_loc[2] - negative_z - size_active_z
elif align_mode == 'OPT_3':
obj_z = obj_loc[2] - positive_z + size_active_z
else: # Everything else relative
if align_mode == 'OPT_1':
obj_z = obj_loc[2] - negative_z
elif align_mode == 'OPT_3':
obj_z = obj_loc[2] - positive_z
if align_mode == 'OPT_2': # All relative
obj_z = obj_loc[2] - center_z
# Relative To
if relative_to == 'OPT_1':
loc_z = obj_z
@@ -166,6 +235,15 @@ class AlignObjects(bpy.types.Operator):
bl_register = True
bl_undo = True
align_mode = bpy.props.EnumProperty(items=(
('OPT_1', "Negative Sides", ""),
('OPT_2', "Centers", ""),
('OPT_3', "Positive Sides", "")
),
name="Align Mode:",
description="",
default='OPT_2')
relative_to = bpy.props.EnumProperty(items=(
('OPT_1', "Scene Origin", ""),
('OPT_2', "3D Cursor", ""),
@@ -174,8 +252,8 @@ class AlignObjects(bpy.types.Operator):
),
name="Relative To:",
description="",
default='OPT_1')
default='OPT_4')
align_x = BoolProperty(name="Align X",
description="Align in the X axis", default=False)
@@ -187,12 +265,13 @@ class AlignObjects(bpy.types.Operator):
def execute(self, context):
align_mode = self.properties.align_mode
relative_to = self.properties.relative_to
align_x = self.properties.align_x
align_y = self.properties.align_y
align_z = self.properties.align_z
align_objects(align_x, align_y, align_z, relative_to)
align_objects(align_x, align_y, align_z, align_mode, relative_to)
return {'FINISHED'}
@@ -209,4 +288,4 @@ def register():
def unregister():
bpy.types.unregister(AlignObjects)
bpy.types.VIEW3D_MT_transform.remove(menu_func)
bpy.types.VIEW3D_MT_transform.remove(menu_func)