[Bf-extensions-cvs] [0068e69d] master: Add camera rigs: Add camera offset bone to the 3D rig

Wayne Dixon noreply at git.blender.org
Sun Jun 14 16:22:43 CEST 2020


Commit: 0068e69d3ab33851303ad128d664c51a543878bb
Author: Wayne Dixon
Date:   Sat Jun 13 13:21:29 2020 +1000
Branches: master
https://developer.blender.org/rBA0068e69d3ab33851303ad128d664c51a543878bb

Add camera rigs: Add camera offset bone to the 3D rig

===================================================================

M	add_camera_rigs/__init__.py
M	add_camera_rigs/build_rigs.py
M	add_camera_rigs/create_widgets.py

===================================================================

diff --git a/add_camera_rigs/__init__.py b/add_camera_rigs/__init__.py
index 6f9f9eeb..7f4accee 100644
--- a/add_camera_rigs/__init__.py
+++ b/add_camera_rigs/__init__.py
@@ -19,7 +19,7 @@
 bl_info = {
     "name": "Add Camera Rigs",
     "author": "Wayne Dixon, Brian Raschko, Kris Wittig, Damien Picard, Flavio Perez",
-    "version": (1, 4, 3),
+    "version": (1, 4, 4),
     "blender": (2, 80, 0),
     "location": "View3D > Add > Camera > Dolly or Crane Rig",
     "description": "Adds a Camera Rig with UI",
diff --git a/add_camera_rigs/build_rigs.py b/add_camera_rigs/build_rigs.py
index 5a23cf21..6b47fef8 100644
--- a/add_camera_rigs/build_rigs.py
+++ b/add_camera_rigs/build_rigs.py
@@ -24,8 +24,9 @@ from rna_prop_ui import rna_idprop_ui_prop_get
 from math import pi
 
 from .create_widgets import (create_root_widget,
-                             create_camera_widget, create_aim_widget,
-                             create_circle_widget, create_corner_widget)
+                             create_camera_widget, create_camera_offset_widget,
+                             create_aim_widget, create_circle_widget,
+                             create_corner_widget)
 
 
 def create_prop_driver(rig, cam, prop_from, prop_to):
@@ -66,11 +67,23 @@ def create_dolly_bones(rig):
     ctrl.tail = (0.0, 1.0, 1.7)
     ctrl.show_wire = True
 
+    ctrl_offset = bones.new("Camera_offset")
+    ctrl_offset.head = (0.0, 0.0, 1.7)
+    ctrl_offset.tail = (0.0, 1.0, 1.7)
+    ctrl_offset.show_wire = True
+
     # Setup hierarchy
     ctrl.parent = root
+    ctrl_offset.parent = ctrl
     ctrl_aim.parent = root
     ctrl_aim_child.parent = ctrl_aim
 
+    # Jump into object mode
+    bpy.ops.object.mode_set(mode='OBJECT')
+    pose_bones = rig.pose.bones
+    # Lock the relevant scale channels of the Camera_offset bone
+    pose_bones["Camera_offset"].lock_scale = (True,) * 3
+
 
 def create_crane_bones(rig):
     """Create bones for the crane camera rig"""
@@ -95,6 +108,10 @@ def create_crane_bones(rig):
     ctrl.head = (0.0, 1.0, 1.7)
     ctrl.tail = (0.0, 2.0, 1.7)
 
+    ctrl_offset = bones.new("Camera_offset")
+    ctrl_offset.head = (0.0, 1.0, 1.7)
+    ctrl_offset.tail = (0.0, 2.0, 1.7)
+
     arm = bones.new("Crane_arm")
     arm.head = (0.0, 0.0, 1.7)
     arm.tail = (0.0, 1.0, 1.7)
@@ -105,6 +122,7 @@ def create_crane_bones(rig):
 
     # Setup hierarchy
     ctrl.parent = arm
+    ctrl_offset.parent = ctrl
     ctrl.use_inherit_rotation = False
     ctrl.use_inherit_scale = False
     ctrl.show_wire = True
@@ -123,9 +141,10 @@ def create_crane_bones(rig):
     # Lock the relevant loc, rot and scale
     pose_bones["Crane_arm"].lock_rotation = (False, True, False)
     pose_bones["Crane_arm"].lock_scale = (True, False, True)
-    pose_bones["Crane_height"].lock_location = (True, True, True)
-    pose_bones["Crane_height"].lock_rotation = (True, True, True)
+    pose_bones["Crane_height"].lock_location = (True,) * 3
+    pose_bones["Crane_height"].lock_rotation = (True,) * 3
     pose_bones["Crane_height"].lock_scale = (True, False, True)
+    pose_bones["Camera_offset"].lock_scale = (True,) * 3
 
 
 def setup_3d_rig(rig, cam):
@@ -148,14 +167,16 @@ def setup_3d_rig(rig, cam):
     # Build the widgets
     root_widget = create_root_widget("Camera_Root")
     camera_widget = create_camera_widget("Camera")
+    camera_offset_widget = create_camera_offset_widget("Camera_offset")
     aim_widget = create_aim_widget("Aim")
 
     # Add the custom bone shapes
     pose_bones["Root"].custom_shape = root_widget
     pose_bones["Aim"].custom_shape = aim_widget
     pose_bones["Camera"].custom_shape = camera_widget
+    pose_bones["Camera_offset"].custom_shape = camera_offset_widget
 
-    # Set the "At" field to the shape mecanism
+    # Set the "Override Transform" field to the mechanism position
     pose_bones["Aim"].custom_shape_transform = pose_bones["Aim_shape_rotation-MCH"]
 
     # Add constraints to bones
@@ -243,7 +264,8 @@ def create_2d_bones(context, rig, cam):
     driver = center_drivers[1].driver
     driver.type = 'SCRIPTED'
 
-    driver.expression = '({distance_x} - (left_x-right_x))*(res_y/res_x)/2 + (left_y + right_y)/2'.format(distance_x=corner_distance_x)
+    driver.expression = '({distance_x} - (left_x-right_x))*(res_y/res_x)/2 + (left_y + right_y)/2'.format(
+        distance_x=corner_distance_x)
 
     for direction in ('x', 'y'):
         for corner in ('left', 'right'):
@@ -324,7 +346,8 @@ def create_2d_bones(context, rig, cam):
 
     # Focal length driver
     driver = cam.data.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)
+    driver.expression = 'abs({distance_z} - (left_z + right_z)/2 + cam_z) * 36 / frame_width'.format(
+        distance_z=corner_distance_z)
 
     var = driver.variables.new()
     var.name = 'frame_width'
@@ -369,7 +392,8 @@ def create_2d_bones(context, rig, cam):
     # Shift driver X
     driver = cam.data.driver_add('shift_x').driver
 
-    driver.expression = 'rotation_shift * (((left_x + right_x)/2 - cam_x) * lens / abs({distance_z} - (left_z + right_z)/2 + cam_z) / 36)'.format(distance_z=corner_distance_z)
+    driver.expression = 'rotation_shift * (((left_x + right_x)/2 - cam_x) * lens / abs({distance_z} - (left_z + right_z)/2 + cam_z) / 36)'.format(
+        distance_z=corner_distance_z)
 
     var = driver.variables.new()
     var.name = 'rotation_shift'
@@ -405,7 +429,8 @@ def create_2d_bones(context, rig, cam):
     # Shift driver Y
     driver = cam.data.driver_add('shift_y').driver
 
-    driver.expression = 'rotation_shift * -(({distance_y} - (left_y + right_y)/2 + cam_y) * lens / abs({distance_z} - (left_z + right_z)/2 + cam_z) / 36 - (res_y/res_x)/2)'.format(distance_y=corner_distance_y, distance_z=corner_distance_z)
+    driver.expression = 'rotation_shift * -(({distance_y} - (left_y + right_y)/2 + cam_y) * lens / abs({distance_z} - (left_z + right_z)/2 + cam_z) / 36 - (res_y/res_x)/2)'.format(
+        distance_y=corner_distance_y, distance_z=corner_distance_z)
 
     var = driver.variables.new()
     var.name = 'rotation_shift'
@@ -478,7 +503,10 @@ def build_camera_rig(context, mode):
     cam.location = (0.0, -1.0, 0.0)  # Move the camera to the correct position
     cam.parent = rig
     cam.parent_type = "BONE"
-    cam.parent_bone = "Camera"
+    if mode == "2D":
+        cam.parent_bone = "Camera"
+    else:
+        cam.parent_bone = "Camera_offset"
 
     # Change display to BBone: it just looks nicer
     rig.data.display_type = 'BBONE'
diff --git a/add_camera_rigs/create_widgets.py b/add_camera_rigs/create_widgets.py
index 72a8c70d..4aeea272 100644
--- a/add_camera_rigs/create_widgets.py
+++ b/add_camera_rigs/create_widgets.py
@@ -54,8 +54,8 @@ def create_corner_widget(name, reverse=False):
     obj = create_widget(name)
     if not obj.data.vertices:
         reverse = -1 if reverse else 1
-        verts = (Vector((reverse *  0.0, 0.0, 0.0)),
-                 Vector((reverse *  0.0, 1.0, 0.0)),
+        verts = (Vector((reverse * 0.0, 0.0, 0.0)),
+                 Vector((reverse * 0.0, 1.0, 0.0)),
                  Vector((reverse * -0.1, 1.0, 0.0)),
                  Vector((reverse * -0.1, 0.1, 0.0)),
                  Vector((reverse * -1.0, 0.1, 0.0)),
@@ -154,76 +154,59 @@ def create_camera_widget(name):
     """Create a camera control widget"""
     obj = create_widget(name)
     if not obj.data.vertices:
-        verts = [(0.27513638138771057, 0.0, -0.27513638138771057),
-                 (0.359483003616333, 0.0, -0.14890272915363312),
-                 (0.38910162448883057, 0.0, 0.0),
-                 (0.359483003616333, 0.0, 0.1489027738571167),
-                 (0.27513638138771057, 0.0, 0.27513638138771057),
-                 (0.1489027589559555, 0.0, 0.359483003616333),
-                 (-1.9481809943044937e-07, 0.0, 0.38910162448883057),
-                 (-1.175054293867106e-07, 0.0, -0.38910162448883057),
-                 (0.148903027176857, 0.0, -0.35948291420936584),
-                 (0.6635494828224182, 0.0, -0.09360162913799286),
-                 (0.6635494828224182, 0.0, 0.09360162913799286),
-                 (0.49765610694885254, 0.0, 0.09360162913799286),
-                 (0.49765610694885254, 0.0, -0.09360168874263763),
-                 (0.6635494828224182, 0.0, 0.17350149154663086),
-                 (0.6635494828224182, 0.0, -0.17350149154663086),
-                 (0.8751950263977051, 0.0, 0.0),
-                 (-0.14890296757221222, 0.0, 0.35948291420936584),
-                 (-0.14890283346176147, 0.0, -0.359483003616333),
-                 (-0.27513641119003296, 0.0, -0.2751363217830658),
-                 (-0.359483003616333, 0.0, -0.14890272915363312),
-                 (-0.38910162448883057, 0.0, 0.0),
-                 (-0.359483003616333, 0.0, 0.1489028036594391),
-                 (-0.2751363217830658, 0.0, 0.27513641119003296),
-                 (1.0342557033027333e-07, 0.0, 0.8751950263977051),
-                 (0.17350155115127563, 0.0, 0.6635494828224182),
-                 (-0.17350146174430847, 0.0, 0.6635494828224182),
-                 (0.09360174089670181, 0.0, 0.49765610694885254),
-                 (-0.09360159188508987, 0.0, 0.49765610694885254),
-                 (-0.09360159188508987, 0.0, 0.6635494828224182),
-                 (0.09360168874263763, 0.0, 0.6635494828224182),
-                 (-0.0936015248298645, 0.0, -0.6635494828224182),
-                 (0.09360174834728241, 0.0, -0.6635494828224182),
-                 (0.09360172599554062, 0.0, -0.49765610694885254),
-                 (-0.09360159933567047, 0.0, -0.49765610694885254),
-                 (0.1735016107559204, 0.0, -0.6635494828224182),
-                 (-0.1735014021396637, 0.0, -0.6635494828224182),
-                 (9.422691960025986e-08, 0.0, -0.8751950263977051),
-                 (-0.8751950263977051, 0.0, 0.0),
-                 (-0.6635494828224182, 0.0, 0.17350131273269653),
-                 (-0.6635494828224182, 0.0, -0.17350167036056519),
-                 (-0.49765610694885254, 0.0, 0.0936015397310257),
-                 (-0.4

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list