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
+7 -2
View File
@@ -1,11 +1,16 @@
# 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 = (
manage_objects,
manage_planes,
convert_planes
convert_planes,
# fit_plane_to_camera_frame,
)
# if 'bpy' in locals():
+69
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)
+1 -1
View File
@@ -168,7 +168,7 @@ class BPM_OT_set_distance(Operator):
context.window_manager.modal_handler_add(self)
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']
else:
# o.visible_get() << if not get_view_layer_col(o.users_collection[0]).exclude