Skip to content

Commit 773b7e6

Browse files
committed
Add a button in a panel to set up render dimensions
This is useful when using a multi-camera setup with reference images that have varying dimensions.
1 parent 6c860b3 commit 773b7e6

File tree

7 files changed

+104
-2
lines changed

7 files changed

+104
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ __Update existing import (if any)__ - If checked, any previously created camera
5050

5151
__Import background image__ - If checked, the image from the fSpy project file will be used as the background image for the Blender camera.
5252

53+
### Panel
54+
55+
If you are using multiple cameras with different reference image sizes, you can quickly switch from one render resolution to another using the `Set Render Dimensions` button in the fSpy panel:
56+
57+
![fSpy Panel](readme_images/panel.png)
58+
5359
# Support for Blender versions older than 2.80
5460

5561
Starting with version 1.0.3, the addon is only compatible with Blender 2.80 and up. If you are using an older Blender version, please [download version 1.0.2](https://github.com/stuffmatic/fSpy-Blender/releases/tag/v1.0.2) of the add-on.

build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
version_string = line.split("(")[1]
1212
version_string = version_string.split(")")[0]
1313
version_parts = version_string.split(",")
14-
version_parts = map(str.strip, version_parts)
14+
version_parts = list(map(str.strip, version_parts))
1515
break
1616
init_file.close()
1717

fspy_blender/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"name": "Import fSpy project",
2020
"author": "Per Gantelius",
2121
"description": "Imports the background image and camera parameters from an fSpy project.",
22-
"version": (1, 0, 3),
22+
"version": (1, 1, 0),
2323
"blender": (2, 80, 0),
2424
"location": "File > Import > fSpy",
2525
"url": "https://github.com/stuffmatic/fSpy-Blender",
@@ -36,8 +36,12 @@
3636
import importlib
3737
importlib.reload(fspy)
3838
importlib.reload(addon)
39+
importlib.reload(properties)
40+
importlib.reload(panel)
3941
else:
4042
from . import addon
43+
from . import panel
44+
from . import properties
4145
from . import fspy
4246

4347
import bpy
@@ -47,7 +51,10 @@ def menu_func_import(self, context):
4751
self.layout.operator(addon.ImportfSpyProject.bl_idname, text="fSpy (.fspy)")
4852

4953
def register():
54+
properties.register()
5055
bpy.utils.register_class(addon.ImportfSpyProject)
56+
bpy.utils.register_class(addon.SetRenderDimensions)
57+
panel.register()
5158
# Add import menu item
5259
if hasattr(bpy.types, 'TOPBAR_MT_file_import'):
5360
#2.8+
@@ -56,7 +63,10 @@ def register():
5663
bpy.types.INFO_MT_file_import.append(menu_func_import)
5764

5865
def unregister():
66+
panel.unregister()
5967
bpy.utils.unregister_class(addon.ImportfSpyProject)
68+
bpy.utils.unregister_class(addon.SetRenderDimensions)
69+
properties.unregister()
6070
# Remove import menu item
6171
if hasattr(bpy.types, 'TOPBAR_MT_file_import'):
6272
#2.8+

fspy_blender/addon.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ def set_up_camera(self, project, update_existing_camera):
121121
camera.data.shift_x = x_shift_scale * (0.5 - pp_rel[0])
122122
camera.data.shift_y = y_shift_scale * (-0.5 + pp_rel[1])
123123

124+
camera.data.fspy.use_fspy = True
125+
camera.data.fspy.reference_dimensions = (
126+
camera_parameters.image_width,
127+
camera_parameters.image_height
128+
)
129+
124130
# Return the configured camera
125131
return camera
126132

@@ -267,3 +273,22 @@ def import_fpsy_project(self, context, filepath, update_existing_camera, set_bac
267273
except fspy.ParsingError as e:
268274
self.report({ 'ERROR' }, 'fSpy import error: ' + str(e))
269275
return {'CANCELLED'}
276+
277+
278+
class SetRenderDimensions(Operator):
279+
"""Set the dimensions of the render to the dimensions of the
280+
reference image that was used for this camera"""
281+
bl_idname = "fspy_blender.set_render_dimensions"
282+
bl_label = "Set Render Dimensions"
283+
284+
@classmethod
285+
def poll(cls, context):
286+
return context.active_object.type == 'CAMERA'
287+
288+
def execute(self, context):
289+
scene = context.scene
290+
cam = context.active_object.data
291+
w, h = cam.fspy.reference_dimensions
292+
scene.render.resolution_x = w
293+
scene.render.resolution_y = h
294+
return {'FINISHED'}

fspy_blender/panel.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import bpy
2+
from bpy.types import Panel
3+
4+
from . import addon as ops
5+
6+
class FspyPanel(Panel):
7+
bl_label = "fSpy"
8+
bl_idname = "SCENE_PT_fSpy"
9+
bl_space_type = 'PROPERTIES'
10+
bl_region_type = 'WINDOW'
11+
bl_context = "data"
12+
13+
@classmethod
14+
def poll(cls, context):
15+
obj = context.active_object
16+
return (
17+
obj.type == 'CAMERA'
18+
and obj.data.fspy.use_fspy
19+
)
20+
21+
def draw(self, context):
22+
cam = context.active_object.data
23+
layout = self.layout
24+
#layout.prop(cam.fspy, "reference_dimensions")
25+
layout.operator(ops.SetRenderDimensions.bl_idname)
26+
27+
classes = (
28+
FspyPanel,
29+
)
30+
register, unregister = bpy.utils.register_classes_factory(classes)

fspy_blender/properties.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import bpy
2+
from bpy.props import IntVectorProperty, PointerProperty, BoolProperty
3+
from bpy.types import Camera, PropertyGroup
4+
5+
class FspyProperties(PropertyGroup):
6+
use_fspy: BoolProperty(
7+
name = "Use fSpy",
8+
description = "Turned true when the camera was imported using fSpy",
9+
default = False,
10+
)
11+
12+
reference_dimensions: IntVectorProperty(
13+
name = "Reference Dimension",
14+
description = "Width and height in pixels of the reference image that was used in fSpy",
15+
size = 2,
16+
default = (0,0),
17+
min = 0,
18+
)
19+
20+
classes = (
21+
FspyProperties,
22+
)
23+
register_cls, unregister_cls = bpy.utils.register_classes_factory(classes)
24+
25+
def register():
26+
register_cls()
27+
Camera.fspy = PointerProperty(type=FspyProperties)
28+
29+
def unregister():
30+
del Camera.fspy
31+
unregister_cls()

readme_images/panel.png

13.1 KB
Loading

0 commit comments

Comments
 (0)