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.
This commit is contained in:
parent
10a8786054
commit
54967955bc
|
@ -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"}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue