Skip to content

Commit

Permalink
Blender 2.8 fixes + bump version number to 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
stuffmatic committed Nov 30, 2018
1 parent d50b0b7 commit 0911c5b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
18 changes: 14 additions & 4 deletions fspy_blender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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__":
Expand Down
15 changes: 11 additions & 4 deletions fspy_blender/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 0911c5b

Please sign in to comment.