From 2c11dcde23451d4cc41c7f6b4d1dade530c1243d Mon Sep 17 00:00:00 2001 From: Damien Picard Date: Wed, 20 Mar 2024 11:44:03 +0100 Subject: [PATCH 1/2] Import images: add file handler Allow drag and drop of images to the 3D viewport to import them as planes. This change is made easy by blender/blender!117728 and blender/blender!119774. --- io_import_images_as_planes.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/io_import_images_as_planes.py b/io_import_images_as_planes.py index 434fd5b58..fb85327e1 100644 --- a/io_import_images_as_planes.py +++ b/io_import_images_as_planes.py @@ -45,6 +45,7 @@ from bpy_extras.object_utils import ( ) from bpy_extras.image_utils import load_image +from bpy_extras.io_utils import ImportHelper # ----------------------------------------------------------------------------- # Module-level Shared State @@ -594,7 +595,7 @@ def setup_compositing(context, plane, img_spec): # ----------------------------------------------------------------------------- # Operator -class IMPORT_IMAGE_OT_to_plane(Operator, AddObjectHelper): +class IMPORT_IMAGE_OT_to_plane(Operator, AddObjectHelper, ImportHelper): """Create mesh plane(s) from image files with the appropriate aspect ratio""" bl_idname = "import_image.to_plane" @@ -919,9 +920,7 @@ class IMPORT_IMAGE_OT_to_plane(Operator, AddObjectHelper): self.report({'WARNING'}, tip_("Generating Cycles/EEVEE compatible material, but won't be visible with %s engine") % engine) - # Open file browser - context.window_manager.fileselect_add(self) - return {'RUNNING_MODAL'} + return self.invoke_popup(context) def execute(self, context): if not bpy.data.is_saved: @@ -1225,6 +1224,18 @@ class IMPORT_IMAGE_OT_to_plane(Operator, AddObjectHelper): constraint.lock_axis = 'LOCK_Y' +class IMPORT_IMAGE_FH_to_plane(bpy.types.FileHandler): + bl_idname = "IMPORT_IMAGE_FH_to_plane" + bl_label = "File handler for images as planes import" + bl_import_operator = "import_image.to_plane" + bl_file_extensions = ";".join(bpy.path.extensions_image.union(bpy.path.extensions_movie)) + + @classmethod + def poll_drop(cls, context): + return (context.region and context.region.type == 'WINDOW' + and context.area and context.area.ui_type == 'VIEW_3D') + + # ----------------------------------------------------------------------------- # Register @@ -1234,6 +1245,7 @@ def import_images_button(self, context): classes = ( IMPORT_IMAGE_OT_to_plane, + IMPORT_IMAGE_FH_to_plane, ) -- 2.30.2 From 7707abb79ad2e80997bf70ac97d1fd9cdb264ae9 Mon Sep 17 00:00:00 2001 From: Damien Picard Date: Tue, 9 Apr 2024 22:31:36 +0200 Subject: [PATCH 2/2] Bump add-on and minimum Blender versions --- io_import_images_as_planes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_import_images_as_planes.py b/io_import_images_as_planes.py index fb85327e1..029853446 100644 --- a/io_import_images_as_planes.py +++ b/io_import_images_as_planes.py @@ -5,8 +5,8 @@ bl_info = { "name": "Import Images as Planes", "author": "Florian Meyer (tstscr), mont29, matali, Ted Schundler (SpkyElctrc), mrbimax", - "version": (3, 5, 1), - "blender": (4, 0, 0), + "version": (3, 6, 0), + "blender": (4, 2, 0), "location": "File > Import > Images as Planes or Add > Image > Images as Planes", "description": "Imports images and creates planes with the appropriate aspect ratio. " "The images are mapped to the planes.", -- 2.30.2