2026-03-11_1

This commit is contained in:
2026-03-17 15:29:47 -06:00
parent dc97400d1e
commit 32d4247d4d
217 changed files with 2683 additions and 157239 deletions
@@ -1,9 +1,9 @@
schema_version = "1.0.0"
id = "add_camera_rigs"
name = "Add Camera Rigs"
version = "1.8.1"
version = "1.8.2"
tagline = "Adds a Camera Rig with UI"
maintainer = "Community"
maintainer = "Wayne Dixon <waylowinternet@gmail.com>"
type = "add-on"
tags = ["Camera"]
blender_version_min = "4.2.0"
@@ -20,6 +20,15 @@ from .create_widgets import (
)
def lock_mch_transforms(rig):
for bone in rig.pose.bones:
if bone.name.startswith("MCH-"):
bone.lock_location = (True, True, True)
bone.lock_rotation = (True, True, True)
bone.lock_rotation_w = True
bone.lock_scale = (True, True, True)
def create_prop_driver(rig, cam, prop_from, prop_to):
"""Create driver to a property on the rig"""
driver = cam.data.driver_add(prop_to)
@@ -52,7 +61,7 @@ def create_dolly_bones(rig):
root.color.palette = 'THEME02'
collection_controls.assign(root)
ctrl_aim_child = bones.new("MCH-Aim_shape_rotation")
ctrl_aim_child = bones.new("MCH-Aim_widget")
ctrl_aim_child.head = (0.0, 10.0, 1.7)
ctrl_aim_child.tail = (0.0, 11.0, 1.7)
collection_mch.assign(ctrl_aim_child)
@@ -107,7 +116,7 @@ def create_crane_bones(rig):
root.color.palette = 'THEME02'
collection_controls.assign(root)
ctrl_aim_child = bones.new("MCH-Aim_shape_rotation")
ctrl_aim_child = bones.new("MCH-Aim_widget")
ctrl_aim_child.head = (0.0, 10.0, 1.7)
ctrl_aim_child.tail = (0.0, 11.0, 1.7)
collection_mch.assign(ctrl_aim_child)
@@ -147,7 +156,6 @@ def create_crane_bones(rig):
height.color.palette = 'THEME07'
collection_controls.assign(height)
# Setup hierarchy
ctrl.parent = arm
ctrl_offset.parent = ctrl
@@ -187,13 +195,15 @@ def setup_3d_rig(rig, cam):
pb = pose_bones['Camera']
pb["lens"] = 50.0
ui_data = pb.id_properties_ui("lens")
ui_data.update(min=1.0, max=1000000.0, soft_max=5000.0, default=50.0, subtype="DISTANCE_CAMERA")
ui_data.update(min=1.0, max=1000000.0, soft_max=5000.0,
default=50.0, subtype="DISTANCE_CAMERA")
# lens offset property
pb = pose_bones['Camera']
pb["lens_offset"] = 0.0
ui_data = pb.id_properties_ui("lens_offset")
ui_data.update(min=-1000000.0, max=1000000.0, soft_max = 5000.0, soft_min = -5000.0,default=0.0)
ui_data.update(min=-1000000.0, max=1000000.0,
soft_max=5000.0, soft_min=-5000.0, default=0.0)
# Build the widgets
root_widget = create_root_widget("Camera_Root")
@@ -207,11 +217,13 @@ def setup_3d_rig(rig, cam):
pose_bones["Camera"].custom_shape = camera_widget
pose_bones["Camera_Offset"].custom_shape = camera_offset_widget
#
# Set the "Override Transform" field to the mechanism position
pose_bones["Aim"].custom_shape_transform = pose_bones["MCH-Aim_shape_rotation"]
pose_bones["Aim"].custom_shape_transform = pose_bones["MCH-Aim_widget"]
# Add constraints to bones
con = pose_bones['MCH-Aim_shape_rotation'].constraints.new('COPY_ROTATION')
con = pose_bones['MCH-Aim_widget'].constraints.new('COPY_ROTATION')
con.target = rig
con.subtarget = "Camera"
@@ -249,6 +261,9 @@ def setup_3d_rig(rig, cam):
var.targets[0].transform_type = 'SCALE_AVG'
var.targets[0].bone_target = 'Root'
# lock all transforms on MCH bones
lock_mch_transforms(rig)
def create_2d_bones(rig, cam):
"""Create bones for the 2D camera rig"""
@@ -476,8 +491,10 @@ def create_2d_bones(rig, cam):
pose_bones["Left_Corner"].lock_rotation = (True,) * 3
pose_bones["Right_Corner"].lock_rotation = (True,) * 3
# Camera settings
# lock all transforms on MCH bones
lock_mch_transforms(rig)
# Camera settings
cam.data.sensor_fit = "HORIZONTAL" # Avoids distortion in portrait format
cam.data.dof.focus_object = rig
cam.data.dof.focus_subtarget = "DOF"
@@ -539,7 +556,8 @@ def create_2d_bones(rig, cam):
# 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)
driver.expression = "abs({distance_x} - (left_x - right_x))".format(
distance_x=corner_distance_x)
for corner in ("left", "right"):
var = driver.variables.new()
@@ -694,6 +712,11 @@ def build_camera_rig(context, mode):
rig.data.display_type = 'BBONE'
# Change display to wire for object
rig.display_type = 'WIRE'
# Set the widgets to be 1.5 width (easier to see)
if bpy.app.version >= (4, 2, 0):
for bone in rig.pose.bones:
if bone.custom_shape:
bone.custom_shape_wire_width = 1.5
# Lock camera transforms
cam.lock_location = (True,) * 3
@@ -27,6 +27,7 @@ def get_rig_and_cam(obj):
return obj.parent, obj
return None, None
def calculate_aim_distance(obj):
'''This will return the distance of the camera and the aim bone at the time it is called.'''
camera_bone = obj.pose.bones['Camera'].matrix
@@ -53,10 +54,12 @@ def poll_perspective(cls, context):
rig, cam = get_rig_and_cam(context.active_object)
if cam.data.type == 'ORTHO':
cls.poll_message_set("This operator is not supported for orthographic cameras.")
cls.poll_message_set(
"This operator is not supported for orthographic cameras.")
return False
if rig["rig_id"].lower() == '2d_rig':
cls.poll_message_set("This operator is not supported for 2D camera rigs.")
cls.poll_message_set(
"This operator is not supported for 2D camera rigs.")
return False
return True
@@ -73,7 +76,8 @@ class ADD_CAMERA_RIGS_OT_set_scene_camera(Operator):
_rig, cam = get_rig_and_cam(context.active_object)
if cam is context.scene.camera:
cls.poll_message_set("Selected camera is already the scene camera.")
cls.poll_message_set(
"Selected camera is already the scene camera.")
return False
return True
@@ -120,7 +124,7 @@ class ADD_CAMERA_RIGS_OT_set_dof_bone(Operator):
cam.data.dof.focus_object = rig
cam.data.dof.focus_subtarget = (
'DOF' if rig["rig_id"].lower() == '2d_rig'
else 'MCH-Aim_shape_rotation')
else 'Aim')
return {'FINISHED'}
@@ -169,7 +173,7 @@ class ADD_CAMERA_RIGS_OT_remove_dolly_zoom(Operator):
# reset the offset back to zero
rig.pose.bones["Camera"]["lens_offset"] = 0.0
#set the bone color to default
# set the bone color to default
rig.pose.bones["Aim"].color.palette = 'DEFAULT'
return {'FINISHED'}
@@ -191,16 +195,20 @@ class ADD_CAMERA_RIGS_OT_shift_to_pivot(Operator):
aim_loc = rig.pose.bones["Aim"].matrix_basis.to_translation()
# create a transform matrix for the z loc of the aim bone
mat_trans = mathutils.Matrix.Translation( [0, 0, aim_loc[2] + 1.7 ]) # Hardcoded height of rest position
mat_trans = mathutils.Matrix.Translation(
[0, 0, aim_loc[2] + 1.7]) # Hardcoded height of rest position
# repostion the aim bone so it's above the root (using the original z value)
rig.pose.bones["Aim"].matrix = rig.pose.bones["Root"].matrix @ mat_trans
# offset the camera matrix relative to the new aim position
camera_offset_vector = (rig.pose.bones["Aim"].matrix_basis.to_translation() ) - aim_loc
camera_offset_matrix = mathutils.Matrix.Translation(camera_offset_vector)
camera_offset_vector = (
rig.pose.bones["Aim"].matrix_basis.to_translation()) - aim_loc
camera_offset_matrix = mathutils.Matrix.Translation(
camera_offset_vector)
rig.pose.bones["Camera"].matrix = rig.pose.bones["Camera"].matrix @ camera_offset_matrix
return {'FINISHED'}
class ADD_CAMERA_RIGS_OT_swap_lens(Operator):
bl_idname = "add_camera_rigs.swap_lens"
bl_label = "Swap Lens"