Fix: Remove duplicate image_add operators in the 3D view port

As part of #118623, we discovered that the operator used for adding images in the 3D viewport was not the same when drag and dropping as when adding it from the add menu. This lead to different and potentially confusing behaviour for the user when they use both.

This patch removes the python operator and unifies the functionality into one operator. It also renames the operator to be in line with the other "Add X" object operators.

Pull Request: https://projects.blender.org/blender/blender/pulls/118973
This commit is contained in:
Sebastian Parborg
2024-03-11 16:18:25 +01:00
committed by Sebastian Parborg
parent deb332601c
commit 013cd3d1ba
10 changed files with 153 additions and 180 deletions
-77
View File
@@ -904,81 +904,6 @@ class DupliOffsetFromObject(Operator):
return {'FINISHED'}
class LoadImageAsEmpty:
bl_options = {'REGISTER', 'UNDO'}
filepath: StringProperty(
subtype='FILE_PATH'
)
filter_image: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
filter_movie: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
filter_folder: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
view_align: BoolProperty(
name="Align to View",
default=True,
)
@classmethod
def poll(cls, context):
return context.mode == 'OBJECT'
def invoke(self, context, _event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def execute(self, context):
scene = context.scene
cursor = scene.cursor.location
try:
image = bpy.data.images.load(self.filepath, check_existing=True)
except RuntimeError as ex:
self.report({'ERROR'}, str(ex))
return {'CANCELLED'}
bpy.ops.object.empty_add(
'INVOKE_REGION_WIN',
type='IMAGE',
location=cursor,
align=('VIEW' if self.view_align else 'WORLD'),
)
view_layer = context.view_layer
obj = view_layer.objects.active
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.empty_image_side = 'FRONT'
if context.space_data.type == 'VIEW_3D':
if not context.space_data.region_3d.is_perspective:
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
class OBJECT_OT_assign_property_defaults(Operator):
"""Assign the current values of custom properties as their defaults, """ \
"""for use as part of the rest pose state in NLA track mixing"""
@@ -1030,8 +955,6 @@ classes = (
DupliOffsetFromObject,
IsolateTypeRender,
JoinUVs,
LoadBackgroundImage,
LoadReferenceImage,
MakeDupliFace,
SelectCamera,
SelectHierarchy,
@@ -307,7 +307,7 @@ class DATA_PT_camera_background_image(CameraButtonsPanel, Panel):
use_multiview = context.scene.render.use_multiview
col = layout.column()
col.operator("view3d.background_image_add", text="Add Image")
col.operator("view3d.camera_background_image_add", text="Add Image")
for i, bg in enumerate(cam.background_images):
layout.active = cam.show_background_images
@@ -331,7 +331,7 @@ class DATA_PT_camera_background_image(CameraButtonsPanel, Panel):
icon='RESTRICT_VIEW_OFF' if bg.show_background_image else 'RESTRICT_VIEW_ON',
)
row.operator("view3d.background_image_remove", text="", emboss=False, icon='X').index = i
row.operator("view3d.camera_background_image_remove", text="", emboss=False, icon='X').index = i
if bg.show_expanded:
row = box.row()
+4 -2
View File
@@ -2671,8 +2671,10 @@ class VIEW3D_MT_image_add(Menu):
def draw(self, _context):
layout = self.layout
layout.operator("object.load_reference_image", text="Reference", icon='IMAGE_REFERENCE')
layout.operator("object.load_background_image", text="Background", icon='IMAGE_BACKGROUND')
# Expliclitly set background mode on/off as operator will try to
# auto detect which mode to use otherwise.
layout.operator("object.empty_image_add", text="Reference", icon='IMAGE_REFERENCE').background = False
layout.operator("object.empty_image_add", text="Background", icon='IMAGE_BACKGROUND').background = True
class VIEW3D_MT_object_relations(Menu):