Fix prop name

Add an unloaded operator (for potential later use) to adjust scale custom prop of the plane to fit camera frame.
This commit is contained in:
pullusb 2025-07-15 15:05:10 +02:00
parent d1ea1b7c86
commit 51a4e78482
6 changed files with 80 additions and 6 deletions

View File

@ -4,7 +4,7 @@ bl_info = {
"name": "Background plane manager", "name": "Background plane manager",
"description": "Manage the background image planes and grease pencil object relative to a camera", "description": "Manage the background image planes and grease pencil object relative to a camera",
"author": "Samuel Bernou", "author": "Samuel Bernou",
"version": (0, 7, 0), "version": (0, 7, 1),
"blender": (4, 3, 0), "blender": (4, 3, 0),
"location": "View3D", "location": "View3D",
"warning": "", "warning": "",

View File

@ -1,11 +1,16 @@
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
from . import (manage_objects, manage_planes, convert_planes) from . import (manage_objects,
manage_planes,
convert_planes,
# fit_plane_to_camera_frame,
)
modules = ( modules = (
manage_objects, manage_objects,
manage_planes, manage_planes,
convert_planes convert_planes,
# fit_plane_to_camera_frame,
) )
# if 'bpy' in locals(): # if 'bpy' in locals():

View File

@ -0,0 +1,69 @@
import bpy
from .. import core
## Unexposed operator:
## Adjust individual "scale" custom property to fit camera frame
## Note: usually we do not want ot touch the custom prop "scale" of the plane and only adjust the focal of the BGcam
class BPM_OT_fit_plane_to_camera_frame(bpy.types.Operator):
bl_idname = "bpm.fit_plane_to_camera_frame"
bl_label = "Fit Plane To Camera Frame"
bl_description = "Adjust selected planes 'scale' custom property to fit width in camera frame\
\nCtrl + clic to adjust all planes instead of selection only"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
return True
def invoke(self, context, event):
self.active = context.scene.bg_props.planes[context.scene.bg_props.index].plane
# self.plane_list = [self.active]
# if event.ctrl: # affect all
if context.scene.bg_props.move_hidden:
self.plane_list = [i.plane for i in context.scene.bg_props.planes if i.type == 'bg']
else:
# o.visible_get() << if not get_view_layer_col(o.users_collection[0]).exclude
self.plane_list = [i.plane for i in context.scene.bg_props.planes if i.type == 'bg' and i.plane.visible_get()]
if not self.plane_list:
self.report({'ERROR'}, f'No plane found in list with current filter')
return {"CANCELLED"}
if not event.ctrl:
self.plane_list = [p for p in self.plane_list if p.select_get()]
#self.active_index = self.plane_list.index(self.active)
#self.init_dist = [o.get('distance') for o in self.plane_list]
return self.execute(context)
def execute(self, context):
# print(self.active.name, '<<-')
scn_res_x = context.scene.render.resolution_x
for plane in self.plane_list:
plane_scale = plane["scale"]
old_scale = plane['scale']
## get Image resolution to calculate offset
im_data, transparency = core.get_image_infos_from_object(plane.children[0])
plane['scale'] = plane_scale * (scn_res_x / im_data.size[0])
print(f"{plane.name}: scale {old_scale} -> {plane['scale']}")
plane.update_tag()
plane.data.update()
return {'FINISHED'}
classes=(
BPM_OT_fit_plane_to_camera_frame,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)

View File

@ -168,7 +168,7 @@ class BPM_OT_set_distance(Operator):
context.window_manager.modal_handler_add(self) context.window_manager.modal_handler_add(self)
self.active = context.scene.bg_props.planes[context.scene.bg_props.index].plane self.active = context.scene.bg_props.planes[context.scene.bg_props.index].plane
if context.scene.bg_props.move_hided: if context.scene.bg_props.move_hidden:
self.plane_list = [i.plane for i in context.scene.bg_props.planes if i.type == 'bg'] self.plane_list = [i.plane for i in context.scene.bg_props.planes if i.type == 'bg']
else: else:
# o.visible_get() << if not get_view_layer_col(o.users_collection[0]).exclude # o.visible_get() << if not get_view_layer_col(o.users_collection[0]).exclude

View File

@ -138,7 +138,7 @@ class BPM_PT_bg_manager_panel(Panel):
row.label(text='Move:') row.label(text='Move:')
if active_item.type == 'bg': if active_item.type == 'bg':
row.operator("bpm.set_distance", text=f"Distance {ob['distance']:.1f}m") row.operator("bpm.set_distance", text=f"Distance {ob['distance']:.1f}m")
row.prop(scn.bg_props, 'move_hided', text='Hided') row.prop(scn.bg_props, 'move_hidden', text='Hidden')
elif active_item.type == 'obj': elif active_item.type == 'obj':
cam = context.scene.objects.get('bg_cam') or context.scene.camera cam = context.scene.objects.get('bg_cam') or context.scene.camera

View File

@ -330,7 +330,7 @@ class BPM_bg_settings(PropertyGroup):
planes : bpy.props.CollectionProperty(type=BPM_bg_list_prop) planes : bpy.props.CollectionProperty(type=BPM_bg_list_prop)
show_distance : BoolProperty(name='Show Distance', default=False) show_distance : BoolProperty(name='Show Distance', default=False)
opacity : FloatProperty(name='Opacity', default=1.0, min=0.0, max=1.0, update=update_opacity) opacity : FloatProperty(name='Opacity', default=1.0, min=0.0, max=1.0, update=update_opacity)
move_hided : BoolProperty(name='Move hided', default=True) move_hidden : BoolProperty(name='Move Hidden', default=True)
ui_list_scale : FloatProperty(name='UI Item Y Scale', default=1.6, min=0.6, soft_min=1.0, max=2.0) ui_list_scale : FloatProperty(name='UI Item Y Scale', default=1.6, min=0.6, soft_min=1.0, max=2.0)
# distance : FloatProperty(name='Distance', default=0.0, update=update_distance) # distance : FloatProperty(name='Distance', default=0.0, update=update_distance)