Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2018-10-09 15:36:15 +0300
committerJacques Lucke <mail@jlucke.com>2018-10-09 15:36:15 +0300
commit85944a2d7e73d1ed070b19e50bc6927b47070091 (patch)
tree73c976ef37777b5569045fdb1e96ecd467ac6320 /release/scripts/startup/bl_operators/object.py
parent3e2422a9471b7fccdd1de57ed06f3a0b95f5bb0a (diff)
Image Empties: Usability improvements and fixes
- new "Align to View" option when loading a new image - automatically align to view when dropping an image into a viewport - larger default size for image empties - fix image empty gizmo in orthographic view - new "Align Objects to View" operator Reviewer: brecht Differential: https://developer.blender.org/D3778
Diffstat (limited to 'release/scripts/startup/bl_operators/object.py')
-rw-r--r--release/scripts/startup/bl_operators/object.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py
index f68ebfc4b94..d5175d31cf9 100644
--- a/release/scripts/startup/bl_operators/object.py
+++ b/release/scripts/startup/bl_operators/object.py
@@ -19,6 +19,7 @@
# <pep8-80 compliant>
import bpy
+from mathutils import Euler
from bpy.types import Operator
from bpy.props import (
BoolProperty,
@@ -28,6 +29,8 @@ from bpy.props import (
StringProperty,
)
+from math import radians
+
class SelectPattern(Operator):
"""Select objects matching a naming pattern"""
@@ -874,7 +877,7 @@ class LoadImageAsEmpty(Operator):
"""Select an image file and create a new image empty with it"""
bl_idname = "object.load_image_as_empty"
bl_label = "Load Image as Empty"
- bl_options = {'REGISTER'}
+ bl_options = {'REGISTER', 'UNDO'}
filepath: StringProperty(
subtype='FILE_PATH'
@@ -883,6 +886,11 @@ class LoadImageAsEmpty(Operator):
filter_image: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
filter_folder: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
+ align_view: BoolProperty(
+ name="Align to view",
+ default=True
+ )
+
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
@@ -899,10 +907,48 @@ class LoadImageAsEmpty(Operator):
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()
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()]
+ )
+
+ @classmethod
+ def poll(cls, context):
+ return context.space_data.type == "VIEW_3D"
+
+ def execute(self, context):
+ base = self.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
+
+ return {"FINISHED"}
+
classes = (
+ AlignObjectsToView,
ClearAllRestrictRender,
DupliOffsetFromCursor,
IsolateTypeRender,