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.
Showing only changes of commit d55bd19cc6 - Show all commits

View File

@ -337,7 +337,12 @@ def create_2d_bones(context, rig, cam):
# Property to switch between rotation and switch mode # Property to switch between rotation and switch mode
pose_bones["Camera"]['rotation_shift'] = 0.0 pose_bones["Camera"]['rotation_shift'] = 0.0
ui_data = pose_bones["Camera"].id_properties_ui('rotation_shift') 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 # Rotation / shift switch driver
driver = con.driver_add('influence').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].id = rig
var.targets[0].data_path = 'pose.bones["Camera"]["rotation_shift"]' var.targets[0].data_path = 'pose.bones["Camera"]["rotation_shift"]'
# Focal length driver # Intermediate focal length driver
driver = cam.data.driver_add('lens').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( driver.expression = 'abs({distance_z} - (left_z + right_z)/2 + cam_z) * 36 / frame_width'.format(
distance_z=corner_distance_z) 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_type = 'LOC_Z'
var.targets[0].transform_space = 'TRANSFORM_SPACE' 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 # Orthographic scale driver
driver = cam.data.driver_add('ortho_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) 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 = driver.variables.new()
var.name = 'lens' var.name = 'lens'
var.type = 'SINGLE_PROP' var.type = 'SINGLE_PROP'
var.targets[0].id_type = 'CAMERA' var.targets[0].id = rig
var.targets[0].id = cam.data var.targets[0].data_path = 'pose.bones["Camera"]["lens"]'
var.targets[0].data_path = 'lens'
# Shift driver Y # Shift driver Y
driver = cam.data.driver_add('shift_y').driver driver = cam.data.driver_add('shift_y').driver
@ -472,9 +486,8 @@ def create_2d_bones(context, rig, cam):
var = driver.variables.new() var = driver.variables.new()
var.name = 'lens' var.name = 'lens'
var.type = 'SINGLE_PROP' var.type = 'SINGLE_PROP'
var.targets[0].id_type = 'CAMERA' var.targets[0].id = rig
var.targets[0].id = cam.data var.targets[0].data_path = 'pose.bones["Camera"]["lens"]'
var.targets[0].data_path = 'lens'
def build_camera_rig(context, mode): def build_camera_rig(context, mode):