[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26908] trunk/blender/release/scripts/op/ object_align.py: Align Object op: Introducing Align Modes Negative Sides / Centers /
Daniel Salazar
zanqdo at gmail.com
Mon Feb 15 07:01:14 CET 2010
Revision: 26908
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26908
Author: zanqdo
Date: 2010-02-15 07:01:13 +0100 (Mon, 15 Feb 2010)
Log Message:
-----------
Align Object op: Introducing Align Modes Negative Sides / Centers /
Positive Sides. Not the most beautiful code ever but will beautify after everything is
implemented
Modified Paths:
--------------
trunk/blender/release/scripts/op/object_align.py
Modified: trunk/blender/release/scripts/op/object_align.py
===================================================================
--- trunk/blender/release/scripts/op/object_align.py 2010-02-15 03:29:51 UTC (rev 26907)
+++ trunk/blender/release/scripts/op/object_align.py 2010-02-15 06:01:13 UTC (rev 26908)
@@ -22,7 +22,7 @@
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 @@
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,13 +101,40 @@
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,8 +152,27 @@
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,8 +190,27 @@
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 @@
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 @@
),
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 @@
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 unregister():
bpy.types.unregister(AlignObjects)
- bpy.types.VIEW3D_MT_transform.remove(menu_func)
+ bpy.types.VIEW3D_MT_transform.remove(menu_func)
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list