diff options
author | Hans Goudey <h.goudey@me.com> | 2019-05-15 17:56:22 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-15 19:10:58 +0300 |
commit | 06fe2a5e0c5d6202864701cf7fd800e4906057c9 (patch) | |
tree | 020910555116b6f002e87e52bb1f50a49e5967ef /release/scripts | |
parent | ddae9c92326486c5c95613bc0b7bb46e2d9bc261 (diff) |
Objects: new 3D cursor alignment option when adding objects
The choices are now World, View and 3D Cursor.
This breaks Python API compatibility, add-ons that add objects with this
parameter will need to be updated.
Differential Revision: https://developer.blender.org/D4706
Diffstat (limited to 'release/scripts')
4 files changed, 43 insertions, 33 deletions
diff --git a/release/scripts/modules/bpy_extras/object_utils.py b/release/scripts/modules/bpy_extras/object_utils.py index a5d80fd7810..48cdbb41c50 100644 --- a/release/scripts/modules/bpy_extras/object_utils.py +++ b/release/scripts/modules/bpy_extras/object_utils.py @@ -34,6 +34,7 @@ import bpy from bpy.props import ( BoolProperty, FloatVectorProperty, + EnumProperty, ) @@ -66,36 +67,32 @@ def add_object_align_init(context, operator): properties.location = location.to_translation() # rotation - view_align = (context.preferences.edit.object_align == 'VIEW') - view_align_force = False + add_align_preference = context.preferences.edit.object_align if operator: - if properties.is_property_set("view_align"): - view_align = view_align_force = operator.view_align + if not properties.is_property_set("rotation"): + # So one of "align" and "rotation" will be set + properties.align = add_align_preference + + if properties.align == 'WORLD': + rotation = properties.rotation.to_matrix().to_4x4() + elif properties.align == 'VIEW': + rotation = space_data.region_3d.view_matrix.to_3x3().inverted() + rotation.resize_4x4() + properties.rotation = rotation.to_euler() + elif properties.align == 'CURSOR': + rotation = context.scene.cursor.rotation_euler.to_matrix().to_4x4() + properties.rotation = rotation.to_euler() else: - if properties.is_property_set("rotation"): - # ugh, 'view_align' callback resets - value = properties.rotation[:] - properties.view_align = view_align - properties.rotation = value - del value - else: - properties.view_align = view_align - - if operator and (properties.is_property_set("rotation") and - not view_align_force): - - rotation = Euler(properties.rotation).to_matrix().to_4x4() + rotation = properties.rotation.to_matrix().to_4x4() else: - if view_align and space_data: + if (add_align_preference == 'VIEW') and space_data: rotation = space_data.region_3d.view_matrix.to_3x3().inverted() rotation.resize_4x4() + elif add_align_preference == 'CURSOR': + rotation = context.scene.cursor.rotation_euler.to_matrix().to_4x4() else: rotation = Matrix() - # set the operator properties - if operator: - properties.rotation = rotation.to_euler() - return location @ rotation @@ -168,14 +165,20 @@ def object_data_add(context, obdata, operator=None, name=None): class AddObjectHelper: - def view_align_update_callback(self, _context): - if not self.view_align: + def align_update_callback(self, _context): + if self.align == 'WORLD': self.rotation.zero() - view_align: BoolProperty( - name="Align to View", - default=False, - update=view_align_update_callback, + align_items = ( + ('WORLD', "World", "Align the new object to the world"), + ('VIEW', "View", "Align the new object to the view"), + ('CURSOR', "3D Cursor", "Use the 3D cursor orientation for the new object") + ) + align: EnumProperty( + name="Align", + items=align_items, + default='WORLD', + update=align_update_callback, ) location: FloatVectorProperty( name="Location", diff --git a/release/scripts/startup/bl_operators/add_mesh_torus.py b/release/scripts/startup/bl_operators/add_mesh_torus.py index a22161fc1ae..bd727ec3e83 100644 --- a/release/scripts/startup/bl_operators/add_mesh_torus.py +++ b/release/scripts/startup/bl_operators/add_mesh_torus.py @@ -202,7 +202,7 @@ class AddTorus(Operator, object_utils.AddObjectHelper): col = layout.column(align=True) col.prop(self, "generate_uvs") col.separator() - col.prop(self, "view_align") + col.prop(self, "align") col = layout.column(align=True) col.label(text="Location") diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py index f68b59192b8..28324891c53 100644 --- a/release/scripts/startup/bl_operators/object.py +++ b/release/scripts/startup/bl_operators/object.py @@ -912,7 +912,7 @@ class LoadImageAsEmpty: 'INVOKE_REGION_WIN', type='IMAGE', location=cursor, - view_align=self.view_align, + align=('VIEW' if self.view_align else 'WORLD'), ) obj = context.active_object diff --git a/release/scripts/templates_py/operator_mesh_add.py b/release/scripts/templates_py/operator_mesh_add.py index 5a9acce3026..39402ab1c6b 100644 --- a/release/scripts/templates_py/operator_mesh_add.py +++ b/release/scripts/templates_py/operator_mesh_add.py @@ -75,10 +75,17 @@ class AddBox(bpy.types.Operator): ) # generic transform props - view_align: BoolProperty( - name="Align to View", - default=False, + align_items = ( + ('WORLD', "World", "Align the new object to the world"), + ('VIEW', "View", "Align the new object to the view"), + ('CURSOR', "3D Cursor", "Use the 3D cursor orientation for the new object") ) + align: EnumProperty( + name="Align", + items=align_items, + default='WORLD', + update=AddObjectHelper.align_update_callback, + ) location: FloatVectorProperty( name="Location", subtype='TRANSLATION', |