[Bf-blender-cvs] [54967955bc9] blender2.8: Empty Image: use draw size instead of object scale

Campbell Barton noreply at git.blender.org
Wed Oct 10 00:13:01 CEST 2018


Commit: 54967955bc9034a642fbd0cdad4a56a7897aefda
Author: Campbell Barton
Date:   Wed Oct 10 08:55:23 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB54967955bc9034a642fbd0cdad4a56a7897aefda

Empty Image: use draw size instead of object scale

Object scale has implications for parenting, use draw size instead.

Also use add-empty view_align option instead of a separate operator.

===================================================================

M	release/scripts/startup/bl_operators/object.py
M	source/blender/editors/object/object_add.c

===================================================================

diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py
index d5175d31cf9..c5801b5a4e6 100644
--- a/release/scripts/startup/bl_operators/object.py
+++ b/release/scripts/startup/bl_operators/object.py
@@ -19,7 +19,6 @@
 # <pep8-80 compliant>
 
 import bpy
-from mathutils import Euler
 from bpy.types import Operator
 from bpy.props import (
     BoolProperty,
@@ -29,8 +28,6 @@ from bpy.props import (
     StringProperty,
 )
 
-from math import radians
-
 
 class SelectPattern(Operator):
     """Select objects matching a naming pattern"""
@@ -886,7 +883,7 @@ class LoadImageAsEmpty(Operator):
     filter_image: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
     filter_folder: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
 
-    align_view: BoolProperty(
+    view_align: BoolProperty(
         name="Align to view",
         default=True
     )
@@ -905,31 +902,31 @@ class LoadImageAsEmpty(Operator):
             self.report({"ERROR"}, str(ex))
             return {"CANCELLED"}
 
-        bpy.ops.object.empty_add(type='IMAGE', location=cursor)
-        context.active_object.data = image
-        context.active_object.scale = (5, 5, 5)
-        if self.align_view:
-            bpy.ops.object.align_to_view()
+        bpy.ops.object.empty_add(
+            'INVOKE_REGION_WIN',
+            type='IMAGE',
+            location=cursor,
+            view_align=self.view_align,
+        )
+        obj = context.active_object
+        obj.data = image
+        obj.empty_display_size = 5.0
         return {'FINISHED'}
 
+
 class AlignObjectsToView(bpy.types.Operator):
     bl_idname = "object.align_to_view"
     bl_label = "Align Objects to View"
     bl_options = {"REGISTER", "UNDO"}
 
-    axis_data = {
-         "X": Euler((0, radians(-90), 0)),
-        "-X": Euler((0, radians(90), 0)),
-         "Y": Euler((radians(90), 0, 0)),
-        "-Y": Euler((radians(-90), 0, 0)),
-         "Z": Euler((0, 0, 0)),
-        "-Z": Euler((0, radians(180), 0))
-    }
-
     front_axis: EnumProperty(
         name="Front Axis",
-        default="Z",
-        items=[(name, name, "") for name in axis_data.keys()]
+        default='POS_Z',
+        items=(
+            (sign + axis, sign_sym + axis, "")
+            for sign, sign_sym in (('POS_', '+'), ('NEG_', "-"))
+            for axis in ('X', 'Y', 'Z')
+        )
     )
 
     @classmethod
@@ -937,12 +934,24 @@ class AlignObjectsToView(bpy.types.Operator):
         return context.space_data.type == "VIEW_3D"
 
     def execute(self, context):
-        base = self.axis_data[self.front_axis].to_matrix()
+        from math import radians
+        from mathutils import Euler
+
+        axis_data = {
+            'POS_X': Euler((0.0, radians(-90.0), 0.0)),
+            'NEG_X': Euler((0.0, radians(90.0), 0.0)),
+            'POS_Y': Euler((radians(90.0), 0.0, 0.0)),
+            'NEG_Y': Euler((radians(-90.0), 0.0, 0.0)),
+            'POS_Z': Euler((0.0, 0.0, 0.0)),
+            'NEG_Z': Euler((0.0, radians(180.0), 0.0))
+        }
+
+        base = axis_data[self.front_axis].to_matrix()
 
         view = context.space_data.region_3d.view_matrix
         rotation = (view.to_3x3().inverted() @ base).to_euler()
-        for object in context.selected_objects:
-            object.rotation_euler = rotation
+        for obj in context.selected_objects:
+            obj.rotation_euler = rotation
 
         return {"FINISHED"}
 
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 4963b304483..4f4dfd544aa 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -893,9 +893,7 @@ static int empty_drop_named_image_invoke(bContext *C, wmOperator *op, const wmEv
 		ED_object_location_from_view(C, ob->loc);
 		ED_view3d_cursor3d_position(C, event->mval, false, ob->loc);
 		ED_object_rotation_from_view(C, ob->rot, 'Z');
-		ob->size[0] = 5;
-		ob->size[1] = 5;
-		ob->size[2] = 5;
+		ob->empty_drawsize = 5.0f;
 	}
 
 	BKE_object_empty_draw_type_set(ob, OB_EMPTY_IMAGE);



More information about the Bf-blender-cvs mailing list