From d55bd19cc6db065aaf7e5a60f52db66d4300ccff Mon Sep 17 00:00:00 2001 From: Damien Picard Date: Wed, 24 Apr 2024 21:20:14 +0200 Subject: [PATCH 1/3] Add camera rigs: workaround dependency cycles on the 2D rig A dependency cycle occurs currently because the camera's properties depend on both the armature and itself, through the lens property. As far as I can tell this cycle does not cause any lag, but it's better to fix it anyway. This commit works around this cycle by introducing an intermediate lens property on the rig itself, and this is used to drive the actual camera lens. Reported and fixed by Beorn Leonard. --- add_camera_rigs/build_rigs.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/add_camera_rigs/build_rigs.py b/add_camera_rigs/build_rigs.py index 08016ae20..4f58124c6 100644 --- a/add_camera_rigs/build_rigs.py +++ b/add_camera_rigs/build_rigs.py @@ -337,7 +337,12 @@ def create_2d_bones(context, rig, cam): # Property to switch between rotation and switch mode pose_bones["Camera"]['rotation_shift'] = 0.0 ui_data = pose_bones["Camera"].id_properties_ui('rotation_shift') - ui_data.update(min=0.0, max=1.0, description="rotation_shift") + ui_data.update(min=0.0, max=1.0, description="Switch between rotating the camera, or using its shift to track the controllers") + + # Intermediate prop to avoid a dependency cycle in the lens driver + pose_bones["Camera"]['lens'] = 0.0 + ui_data = pose_bones["Camera"].id_properties_ui('lens') + ui_data.update(min=1.0, soft_max=5000.0, description="Intermediate lens property, should not be used") # Rotation / shift switch driver driver = con.driver_add('influence').driver @@ -349,8 +354,8 @@ def create_2d_bones(context, rig, cam): var.targets[0].id = rig var.targets[0].data_path = 'pose.bones["Camera"]["rotation_shift"]' - # Focal length driver - driver = cam.data.driver_add('lens').driver + # Intermediate focal length driver + driver = pose_bones["Camera"].driver_add('["lens"]').driver driver.expression = 'abs({distance_z} - (left_z + right_z)/2 + cam_z) * 36 / frame_width'.format( distance_z=corner_distance_z) @@ -381,6 +386,16 @@ def create_2d_bones(context, rig, cam): var.targets[0].transform_type = 'LOC_Z' var.targets[0].transform_space = 'TRANSFORM_SPACE' + # Actual focal length driver + driver = cam.data.driver_add('lens').driver + driver.type = 'AVERAGE' + + var = driver.variables.new() + var.name = 'lens' + var.type = 'SINGLE_PROP' + var.targets[0].id = rig + var.targets[0].data_path = 'pose.bones["Camera"]["lens"]' + # Orthographic scale driver driver = cam.data.driver_add('ortho_scale').driver driver.expression = 'abs({distance_x} - (left_x - right_x))'.format(distance_x=corner_distance_x) @@ -427,9 +442,8 @@ def create_2d_bones(context, rig, cam): var = driver.variables.new() var.name = 'lens' var.type = 'SINGLE_PROP' - var.targets[0].id_type = 'CAMERA' - var.targets[0].id = cam.data - var.targets[0].data_path = 'lens' + var.targets[0].id = rig + var.targets[0].data_path = 'pose.bones["Camera"]["lens"]' # Shift driver Y driver = cam.data.driver_add('shift_y').driver @@ -472,9 +486,8 @@ def create_2d_bones(context, rig, cam): var = driver.variables.new() var.name = 'lens' var.type = 'SINGLE_PROP' - var.targets[0].id_type = 'CAMERA' - var.targets[0].id = cam.data - var.targets[0].data_path = 'lens' + var.targets[0].id = rig + var.targets[0].data_path = 'pose.bones["Camera"]["lens"]' def build_camera_rig(context, mode): -- 2.30.2 From 01cbd13f48405105c5a11ef4648921aaa11494db Mon Sep 17 00:00:00 2001 From: Wayne Dixon Date: Wed, 6 Mar 2024 21:33:18 +1100 Subject: [PATCH 2/3] Add camera rigs: expose custom property in ui (2d camera rig) --- add_camera_rigs/ui_panels.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/add_camera_rigs/ui_panels.py b/add_camera_rigs/ui_panels.py index 14f7ef66a..8d6a6374e 100644 --- a/add_camera_rigs/ui_panels.py +++ b/add_camera_rigs/ui_panels.py @@ -104,6 +104,8 @@ class ADD_CAMERA_RIGS_PT_camera_rig_ui(Panel, CameraRigMixin): col.label(text="2D Rig:") col.prop(pose_bones["Camera"], '["rotation_shift"]', text="Rotation/Shift") + col.prop(pose_bones["Camera"], '["aperture_fstop"]', + text="F-Stop") if cam.data.sensor_width != 36: col.label(text="Please set Camera Sensor Width to 36", icon="ERROR") -- 2.30.2 From d811727a89cb9b17e70342d4b2ef09eccde2e063 Mon Sep 17 00:00:00 2001 From: Wayne Dixon Date: Wed, 6 Mar 2024 21:31:57 +1100 Subject: [PATCH 3/3] Add camera rigs: update version number --- add_camera_rigs/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/add_camera_rigs/__init__.py b/add_camera_rigs/__init__.py index 54da57ffc..57ecfcf1f 100644 --- a/add_camera_rigs/__init__.py +++ b/add_camera_rigs/__init__.py @@ -5,8 +5,8 @@ bl_info = { "name": "Add Camera Rigs", "author": "Wayne Dixon, Brian Raschko, Kris Wittig, Damien Picard, Flavio Perez", - "version": (1, 6, 0), - "blender": (4, 0, 0), + "version": (1, 7, 0), + "blender": (4, 1, 0), "location": "View3D > Add > Camera > Dolly or Crane Rig", "description": "Adds a Camera Rig with UI", "doc_url": "{BLENDER_MANUAL_URL}/addons/camera/camera_rigs.html", -- 2.30.2