From 0911c5b3eea1eab21bbdbe7ff3146e9404a0b6b3 Mon Sep 17 00:00:00 2001 From: per Date: Fri, 30 Nov 2018 08:49:20 +0100 Subject: [PATCH] Blender 2.8 fixes + bump version number to 1.0.1 --- fspy_blender/__init__.py | 18 ++++++++++++++---- fspy_blender/addon.py | 15 +++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/fspy_blender/__init__.py b/fspy_blender/__init__.py index 8a1e1b7..77b5ec2 100644 --- a/fspy_blender/__init__.py +++ b/fspy_blender/__init__.py @@ -19,8 +19,8 @@ "name": "Import fSpy project", "author": "Per Gantelius", "description": "Imports the background image and camera parameters from an fSpy project.", - "version": (1, 0, 0), - "blender": (2, 79, 0), + "version": (1, 0, 1), + "blender": (2, 80, 0), "location": "File > Import > fSpy", "url": "https://github.com/stuffmatic/fSpy-Blender", "wiki_url": "https://github.com/stuffmatic/fSpy-Blender", @@ -48,11 +48,21 @@ def menu_func_import(self, context): def register(): bpy.utils.register_class(addon.ImportfSpyProject) - bpy.types.INFO_MT_file_import.append(menu_func_import) + # Add import menu item + if hasattr(bpy.types, 'TOPBAR_MT_file_import'): + #2.8+ + bpy.types.TOPBAR_MT_file_import.append(menu_func_import) + else: + bpy.types.INFO_MT_file_import.append(menu_func_import) def unregister(): bpy.utils.unregister_class(addon.ImportfSpyProject) - bpy.types.INFO_MT_file_import.remove(menu_func_import) + # Remove import menu item + if hasattr(bpy.types, 'TOPBAR_MT_file_import'): + #2.8+ + bpy.types.TOPBAR_MT_file_import.remove(menu_func_import) + else: + bpy.types.INFO_MT_file_import.remove(menu_func_import) if __name__ == "__main__": diff --git a/fspy_blender/addon.py b/fspy_blender/addon.py index d976944..1c600ca 100644 --- a/fspy_blender/addon.py +++ b/fspy_blender/addon.py @@ -139,22 +139,29 @@ def set_up_3d_area(self, project, camera, update_existing_camera, set_background space_data = area.spaces.active # Show background images - space_data.show_background_images = True + if hasattr(space_data, 'show_background_image'): + space_data.show_background_images = True + else: + #2.8 + camera.data.show_background_images = True # Make the calibrated camera the active camera space_data.camera = camera space_data.region_3d.view_perspective = 'CAMERA' if set_background_image: + # In Blender 2.8+, the background images are associated with the camera and not the 3D view + background_images = camera.data.background_images if hasattr(camera.data, 'background_images') else space_data.background_images + # Setting background image has been requested. # First, hide all existing bg images - for bg_image in space_data.background_images: + for bg_image in background_images: bg_image.show_background_image = False bg = None if update_existing_camera: # Try to find an existing bg image slot matching the project name - for bg_image in space_data.background_images: + for bg_image in background_images: if bg_image.image: if bg_image.image.name == camera.name: bpy.data.images.remove(bg_image.image) @@ -163,7 +170,7 @@ def set_up_3d_area(self, project, camera, update_existing_camera, set_background break if not bg: # No existin background image slot. Create one - bg = space_data.background_images.new() + bg = background_images.new() # Make sure the background image slot is visible bg.show_background_image = True