Images: "Image" submenu in "Add" menu

The submenu has two entries currently: "Reference" and "Background".
Both operators produce an image empty with different settings.
This commit is contained in:
Jacques Lucke 2018-11-20 12:44:42 +01:00
parent 76d602f38d
commit 86e0d13218
2 changed files with 45 additions and 8 deletions

View File

@ -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,

View File

@ -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,
)