Add camera rigs: workaround for the 2D rig dependency cycle #105293

Closed
Damien Picard wants to merge 3 commits from pioverfour/blender-addons:fix_cams into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 26 additions and 11 deletions

View File

@ -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",

View File

@ -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):

View File

@ -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")