[Bf-blender-cvs] [86e0d13218d] blender2.8: Images: "Image" submenu in "Add" menu

Jacques Lucke noreply at git.blender.org
Tue Nov 20 12:45:01 CET 2018


Commit: 86e0d13218d6e9f918ca857890ee1c0aa681091b
Author: Jacques Lucke
Date:   Tue Nov 20 12:44:42 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB86e0d13218d6e9f918ca857890ee1c0aa681091b

Images: "Image" submenu in "Add" menu

The submenu has two entries currently: "Reference" and "Background".
Both operators produce an image empty with different settings.

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

M	release/scripts/startup/bl_operators/object.py
M	release/scripts/startup/bl_ui/space_view3d.py

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

diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py
index fddf15155fc..46aa343868a 100644
--- a/release/scripts/startup/bl_operators/object.py
+++ b/release/scripts/startup/bl_operators/object.py
@@ -870,10 +870,7 @@ class DupliOffsetFromCursor(Operator):
         return {'FINISHED'}
 
 
-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"
+class LoadImageAsEmpty:
     bl_options = {'REGISTER', 'UNDO'}
 
     filepath: StringProperty(
@@ -896,6 +893,7 @@ class LoadImageAsEmpty(Operator):
         scene = context.scene
         space = context.space_data
         cursor = (space if space and space.type == 'VIEW_3D' else scene).cursor_location
+
         try:
             image = bpy.data.images.load(self.filepath, check_existing=True)
         except RuntimeError as ex:
@@ -908,18 +906,49 @@ class LoadImageAsEmpty(Operator):
             location=cursor,
             view_align=self.view_align,
         )
+
         obj = context.active_object
         obj.data = image
         obj.empty_display_size = 5.0
+        self.set_settings(context, obj)
         return {'FINISHED'}
 
+    def set_settings(self, context, obj):
+        pass
+
+
+class LoadBackgroundImage(LoadImageAsEmpty, Operator):
+    """Add a reference image into the background behind objects"""
+    bl_idname = "object.load_background_image"
+    bl_label = "Load Background Image"
+
+    def set_settings(self, context, obj):
+        obj.empty_image_depth = "BACK"
+        obj.show_empty_image_backside = False
+
+        if context.space_data.type == "VIEW_3D":
+            if context.space_data.region_3d.is_perspective:
+                obj.show_empty_image_orthographic = False
+            else:
+                obj.show_empty_image_perspective = False
+
+
+class LoadReferenceImage(LoadImageAsEmpty, Operator):
+    """Add a reference image into the scene between objects"""
+    bl_idname = "object.load_reference_image"
+    bl_label = "Load Reference Image"
+
+    def set_settings(self, context, obj):
+        pass
+
 
 classes = (
     ClearAllRestrictRender,
     DupliOffsetFromCursor,
     IsolateTypeRender,
     JoinUVs,
-    LoadImageAsEmpty,
+    LoadBackgroundImage,
+    LoadReferenceImage,
     MakeDupliFace,
     SelectCamera,
     SelectHierarchy,
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 0d96e11cb72..53008311a2b 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1534,10 +1534,8 @@ class VIEW3D_MT_add(Menu):
         layout.menu("VIEW3D_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
         layout.operator_menu_enum("object.empty_add", "type", text="Empty", icon='OUTLINER_OB_EMPTY')
+        layout.menu("VIEW3D_MT_image_add", text="Image", icon='OUTLINER_OB_IMAGE')
 
-        sublayout = layout.column()
-        sublayout.operator_context = 'INVOKE_DEFAULT'
-        sublayout.operator("object.load_image_as_empty", text="Image", icon="OUTLINER_OB_IMAGE")
         layout.separator()
 
         layout.operator("object.speaker_add", text="Speaker", icon='OUTLINER_OB_SPEAKER')
@@ -1576,6 +1574,15 @@ class VIEW3D_MT_add(Menu):
             )
 
 
+class VIEW3D_MT_image_add(Menu):
+    bl_label = "Add Image"
+
+    def draw(self, context):
+        layout = self.layout
+        layout.operator("object.load_reference_image", text="Reference")
+        layout.operator("object.load_background_image", text="Background")
+
+
 class VIEW3D_MT_object_relations(Menu):
     bl_label = "Relations"
 
@@ -5475,6 +5482,7 @@ classes = (
     VIEW3D_PT_transform_orientations,
     VIEW3D_PT_overlay_gpencil_options,
     VIEW3D_PT_context_properties,
+    VIEW3D_MT_image_add,
 )



More information about the Bf-blender-cvs mailing list