[Bf-extensions-cvs] [81ed56cb] master: add_camera_rigs: refactor and cleanup

Damien Picard noreply at git.blender.org
Fri Jan 24 00:54:54 CET 2020


Commit: 81ed56cbce99c9991c989163c802b4cea42be58e
Author: Damien Picard
Date:   Tue Dec 17 11:11:37 2019 +0100
Branches: master
https://developer.blender.org/rBA81ed56cbce99c9991c989163c802b4cea42be58e

add_camera_rigs: refactor and cleanup

- Fix widgets’ names: they were hardcoded and didn’t follow the
  preferences, leading to crashes.
- The UI was put back into the Item category, instead of Create,
  because it is not related to object creation.
- Fix some strange topology in two widget shapes.
- UI and operators use a new poll method, so that they work when
  either the rig or the camera is selected.
- The composition guides UI was converted to a panel, so that they may
  be drag-selected.
- Marker binding and DOF object operators were converted to the
  `bpy.data` API, making them simpler.
- Bones were moved around so that they are more similar between rigs.
  - They were scaled down to be 1 unit long, a simpler length — for
    instance, widgets are the same size as modeled. Widgets were
    scaled up to compensate.
  - The camera and aim bones were placed at 1.7 unit high, to be
    approximately at a standing human’s eyes’ height if the scene is
    in meters.
- Much of the rig generation was refactored to deduplicate code
  between the two rig types.
- Automatic renaming to `.000` was removed, since Blender already
  handles duplicate names.
- Widget prefix and collection were renamed to `WGT-` and `Widgets`
  respectively. This is to be closer to Rigify, hopefully unifying
  them.
- The GPL license header was added to every file.
- Some cleanup was done to better respect Python’s PEP 8.

Reviewed By: Wayne Dixon

Differential Revision: https://developer.blender.org/D6543

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

M	add_camera_rigs/__init__.py
M	add_camera_rigs/build_rigs.py
M	add_camera_rigs/composition_guides_menu.py
M	add_camera_rigs/create_widgets.py
M	add_camera_rigs/operators.py
M	add_camera_rigs/prefs.py
M	add_camera_rigs/ui_panels.py

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

diff --git a/add_camera_rigs/__init__.py b/add_camera_rigs/__init__.py
index 9d296e6c..9c742e6a 100644
--- a/add_camera_rigs/__init__.py
+++ b/add_camera_rigs/__init__.py
@@ -16,11 +16,10 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
-
 bl_info = {
     "name": "Add Camera Rigs",
-    "author": "Wayne Dixon, Brian Raschko, Kris Wittig",
-    "version": (1, 4, 1),
+    "author": "Wayne Dixon, Brian Raschko, Kris Wittig, Damien Picard",
+    "version": (1, 4, 2),
     "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 c7303198..1a37bc6e 100644
--- a/add_camera_rigs/build_rigs.py
+++ b/add_camera_rigs/build_rigs.py
@@ -1,6 +1,25 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
 import bpy
+from bpy_extras import object_utils
 from bpy.types import Operator
-from math import radians
+from math import radians, pi
 from rna_prop_ui import rna_idprop_ui_prop_get
 from .create_widgets import (create_root_widget,
                              create_widget,
@@ -9,518 +28,254 @@ from .create_widgets import (create_root_widget,
                              )
 
 
-def build_dolly_rig(context):
-    """Operator to build the dolly rig"""
-    # Set the bone layers
-    boneLayer = (False, True, False, False, False, False, False, False,
-                 False, False, False, False, False, False, False, False,
-                 False, False, False, False, False, False, False, False,
-                 False, False, False, False, False, False, False, False)
-
-    # Add the new armature object:
-    bpy.ops.object.armature_add()
-    rig = context.active_object
-
-    # it will try to name the rig "Dolly_rig" but if that name exists it will
-    # add 000 to the name
-    if "Dolly_rig" not in context.scene.objects:
-        rig.name = "Dolly_rig"
-    else:
-        rig.name = "Dolly_rig.000"
-    rig["rig_id"] = "Dolly_rig"
-
-    bpy.ops.object.mode_set(mode='EDIT')
-
-    # Remove default bone:
+def create_dolly_bones(rig, bone_layers):
     bones = rig.data.edit_bones
-    bones.remove(bones[0])
 
-    # Add new bones:
+    # Add new bones
     root = bones.new("Root")
-    root.tail = (0.0, 3.0, 0.0)
+    root.tail = (0.0, 1.0, 0.0)
+    root.show_wire = True
 
-    bpy.ops.object.mode_set(mode='EDIT')
-    ctrlAimChild = bones.new("aim_MCH")
-    ctrlAimChild.head = (0.0, 5.0, 3.0)
-    ctrlAimChild.tail = (0.0, 7.0, 3.0)
-    ctrlAimChild.layers = boneLayer
+    ctrl_aim_child = bones.new("Aim_shape_rotation-MCH")
+    ctrl_aim_child.head = (0.0, 10.0, 1.7)
+    ctrl_aim_child.tail = (0.0, 11.0, 1.7)
+    ctrl_aim_child.layers = bone_layers
 
-    ctrlAim = bones.new("Aim")
-    ctrlAim.head = (0.0, 5.0, 3.0)
-    ctrlAim.tail = (0.0, 7.0, 3.0)
+    ctrl_aim = bones.new("Aim")
+    ctrl_aim.head = (0.0, 10.0, 1.7)
+    ctrl_aim.tail = (0.0, 11.0, 1.7)
+    ctrl_aim.show_wire = True
 
     ctrl = bones.new("Camera")
-    ctrl.head = (0.0, 0.0, 3.0)
-    ctrl.tail = (0.0, 2.0, 3.0)
+    ctrl.head = (0.0, 0.0, 1.7)
+    ctrl.tail = (0.0, 1.0, 1.7)
+    ctrl.show_wire = True
 
-    # Setup hierarchy:
+    # Setup hierarchy
     ctrl.parent = root
-    ctrlAim.parent = root
-    ctrlAimChild.parent = ctrlAim
-
-    # jump into pose mode and change bones to euler
-    bpy.ops.object.mode_set(mode='POSE')
-    for x in bpy.context.object.pose.bones:
-        x.rotation_mode = 'XYZ'
-
-    # jump into pose mode and add the custom bone shapes
-    bpy.ops.object.mode_set(mode='POSE')
-    bpy.context.object.pose.bones["Root"].custom_shape = bpy.data.objects[
-        "WDGT_Camera_root"]  # add the widget as custom shape
-    # set the wireframe checkbox to true
-    bpy.context.object.data.bones["Root"].show_wire = True
-    bpy.context.object.pose.bones[
-        "Aim"].custom_shape = bpy.data.objects["WDGT_Aim"]
-    bpy.context.object.data.bones["Aim"].show_wire = True
-    bpy.context.object.pose.bones["Aim"].custom_shape_transform = bpy.data.objects[
-        rig.name].pose.bones["aim_MCH"]  # sets the "At" field to the child
-    bpy.context.object.pose.bones[
-        "Camera"].custom_shape = bpy.data.objects["WDGT_Camera"]
-    bpy.context.object.data.bones["Camera"].show_wire = True
-
-    # jump into object mode
-    bpy.ops.object.mode_set(mode='OBJECT')
-
-    # Add constraints to bones:
-    con = rig.pose.bones['aim_MCH'].constraints.new('COPY_ROTATION')
-    con.target = rig
-    con.subtarget = "Camera"
-
-    con = rig.pose.bones['Camera'].constraints.new('TRACK_TO')
-    con.target = rig
-    con.subtarget = "Aim"
-    con.use_target_z = True
-
-    # Add custom Bone property to Camera bone
-    ob = bpy.context.object.pose.bones['Camera']
-    prop = rna_idprop_ui_prop_get(ob, "lock", create=True)
-    ob["lock"] = 1.0
-    prop["soft_min"] = prop["min"] = 0.0
-    prop["soft_max"] = prop["max"] = 1.0
-
-    # Add Driver to Lock/Unlock Camera from Aim Target
-    rig = bpy.context.view_layer.objects.active
-    pose_bone = bpy.data.objects[rig.name].pose.bones['Camera']
-
-    constraint = pose_bone.constraints["Track To"]
-    inf_driver = constraint.driver_add('influence')
-    inf_driver.driver.type = 'SCRIPTED'
-    var = inf_driver.driver.variables.new()
-    var.name = 'var'
-    var.type = 'SINGLE_PROP'
-
-    # Target the Custom bone property
-    var.targets[0].id = bpy.data.objects[rig.name]
-    var.targets[0].data_path = 'pose.bones["Camera"]["lock"]'
-    inf_driver.driver.expression = 'var'
-
-    # Add custom property for the lens / add the driver after the camera is created
-    ob = bpy.context.object.pose.bones['Camera']
-    prop = rna_idprop_ui_prop_get(ob, "focal_length", create=True)
-    ob["focal_length"] = 50.0
-    prop["soft_min"] = prop["min"] = 1.0
-    prop["default"] = 50.0
-    prop["soft_max"] = prop["max"] = 5000.0
-
-    # Add custom property for the focus distance / add the driver after the camera is created
-    ob = bpy.context.object.pose.bones['Camera']
-    prop = rna_idprop_ui_prop_get(ob, "focus_distance", create=True)
-    ob["focus_distance"] = 10.00
-    prop["soft_min"] = prop["min"] = 0.0
-    prop["soft_max"] = prop["max"] = 1000.0
-
-    # Add custom property for the f-stop / add the driver after the camera is created
-    ob = bpy.context.object.pose.bones['Camera']
-    prop = rna_idprop_ui_prop_get(ob, "f-stop", create=True)
-    ob["f-stop"] = 2.8
-    prop["soft_min"] = prop["min"] = 0.1
-    prop["soft_max"] = prop["max"] = 128.00
-
-    # Add the camera object:
-    bpy.ops.object.mode_set(mode='OBJECT')
-
-    bpy.ops.object.camera_add()
-    cam = bpy.context.active_object
-
-    # Name the Camera Object
-    if 'Dolly_camera' not in context.scene.objects:
-        cam.name = "Dolly_camera"
-    else:
-        cam.name = "Dolly_camera.000"
-
-    # this will name the camera data
-    cam.data.name = cam.name
-
-    cam_data_name = bpy.context.object.data.name
-    bpy.data.cameras[cam_data_name].display_size = 1.0
-    cam.rotation_euler = [radians(90), 0, 0]  # rotate the camera 90 degrees in x
-
-    cam.location = (0.0, -2.0, 0.0)  # move the camera to the correct postion
-    cam.parent = rig
-    cam.parent_type = "BONE"
-    cam.parent_bone = "Camera"
-
-    # Add Driver to link the camera lens to the custom property on the armature
-    pose_bone = bpy.data.objects[rig.name].pose.bones['Camera']
-    lens_driver = cam.data.driver_add("lens")
-    lens_driver.driver.type = 'SCRIPTED'
-    var = lens_driver.driver.variables.new()
-    var.name = 'var'
-    var.type = 'SINGLE_PROP'
-
-    # Target the Custom bone property
-    var.targets[0].id = bpy.data.objects[rig.name]
-    var.targets[0].data_path = 'pose.bones["Camera"]["focal_length"]'
-    lens_driver.driver.expression = 'var'
-
-    # Add Driver to link the camera focus distance to the custom property on the armature
-    pose_bone = bpy.data.objects[rig.name].pose.bones['Camera']
-    lens_driver = cam.data.driver_add("dof.focus_distance")
-    lens_driver.driver.type = 'SCRIPTED'
-    var = lens_driver.driver.variables.new()
-    var.name = 'var'
-    var.type = 'SINGLE_PROP'
-
-    # Target the Custom bone property
-    var.targets[0].id = bpy.data.objects[rig.name]
-    var.targets[0].data_path = 'pose.bones["Camera"]["focus_distance"]'
-    lens_driver.driver.expression = 'var'
-
-    # Add Driver to link the camera f-stop to the custom property on the armature
-    pose_bone = bpy.data.objects[rig.name].pose.bones['Camera']
-    lens_driver = cam.data.driver_add("dof.aperture_fstop")
-    lens_driver.driver.type = 'SCRIPTED'
-    var = lens_driver.driver.variables.new()
-    var.name = 'var'
-    var.type = 'SINGLE_PROP'
-
-    # Target the Custom bone property
-    var.targets[0].id = bpy.data.objects[rig.name]
-    var.targets[0].data_path = 'pose.bones["Camera"]["f-stop"]'
-    lens_driver.driver.expression = 'var'
-
-    # lock the location/rotation/scale of the camera
-    cam.lock_location = [True, True, True]
-    cam.lock_rotation = [True, True, True]
-    cam.lock_scale = [True, True, True]
-
-    # Set new camera as active camera
-    bpy.context.scene.camera = cam
-
-    # make sure the camera is selectable by default (this can be locked in the UI)
-    bpy.context.object.hide_select = False
-
-    # make the rig the active object before finishing
-    bpy.context.view_layer.objects.active = r

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list