[Bf-extensions-cvs] [7cfd0414] master: add camera rigs: update, move to folder structure: T71763

meta-androcto noreply at git.blender.org
Mon Dec 2 00:54:28 CET 2019


Commit: 7cfd041403732d6913415eeda89769ea7d424cfe
Author: meta-androcto
Date:   Mon Dec 2 10:54:05 2019 +1100
Branches: master
https://developer.blender.org/rBA7cfd041403732d6913415eeda89769ea7d424cfe

add camera rigs: update, move to folder structure: T71763

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

A	add_camera_rigs/__init__.py
A	add_camera_rigs/build_rigs.py
A	add_camera_rigs/composition_guides_menu.py
A	add_camera_rigs/create_widgets.py
A	add_camera_rigs/operators.py
A	add_camera_rigs/prefs.py
A	add_camera_rigs/ui_panels.py
D	camera_dolly_crane_rigs.py

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

diff --git a/add_camera_rigs/__init__.py b/add_camera_rigs/__init__.py
new file mode 100644
index 00000000..9d296e6c
--- /dev/null
+++ b/add_camera_rigs/__init__.py
@@ -0,0 +1,63 @@
+# ##### 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 #####
+
+
+bl_info = {
+    "name": "Add Camera Rigs",
+    "author": "Wayne Dixon, Brian Raschko, Kris Wittig",
+    "version": (1, 4, 1),
+    "blender": (2, 80, 0),
+    "location": "View3D > Add > Camera > Dolly or Crane Rig",
+    "description": "Adds a Camera Rig with UI",
+    "wiki_url": "https://docs.blender.org/manual/en/dev/addons/"
+                "camera/camera_rigs.html",
+    "tracker_url": "https://github.com/waylow/add_camera_rigs/issues",
+    "category": "Camera",
+}
+
+import bpy
+import os
+
+from . import build_rigs
+from . import operators
+from . import ui_panels
+from . import prefs
+from . import composition_guides_menu
+
+# =========================================================================
+# Registration:
+# =========================================================================
+
+def register():
+    build_rigs.register()
+    operators.register()
+    ui_panels.register()
+    prefs.register()
+    composition_guides_menu.register()
+
+
+def unregister():
+    build_rigs.unregister()
+    operators.unregister()
+    ui_panels.unregister()
+    prefs.unregister()
+    composition_guides_menu.unregister()
+
+
+if __name__ == "__main__":
+    register()
diff --git a/add_camera_rigs/build_rigs.py b/add_camera_rigs/build_rigs.py
new file mode 100644
index 00000000..c7303198
--- /dev/null
+++ b/add_camera_rigs/build_rigs.py
@@ -0,0 +1,544 @@
+import bpy
+from bpy.types import Operator
+from math import radians
+from rna_prop_ui import rna_idprop_ui_prop_get
+from .create_widgets import (create_root_widget,
+                             create_widget,
+                             create_camera_widget,
+                             create_aim_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:
+    bones = rig.data.edit_bones
+    bones.remove(bones[0])
+
+    # Add new bones:
+    root = bones.new("Root")
+    root.tail = (0.0, 3.0, 0.0)
+
+    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
+
+    ctrlAim = bones.new("Aim")
+    ctrlAim.head = (0.0, 5.0, 3.0)
+    ctrlAim.tail = (0.0, 7.0, 3.0)
+
+    ctrl = bones.new("Camera")
+    ctrl.head = (0.0, 0.0, 3.0)
+    ctrl.tail = (0.0, 2.0, 3.0)
+
+    # 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

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list