2009-11-30 12:31:11 +00:00
|
|
|
# ##### 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
# <pep8 compliant>
|
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
import bpy
|
2010-01-31 14:33:27 +00:00
|
|
|
from rigify import RigifyError
|
2009-12-13 22:48:11 +00:00
|
|
|
from rigify_utils import copy_bone_simple, get_side_name
|
2009-12-05 22:03:07 +00:00
|
|
|
from rna_prop_ui import rna_idprop_ui_prop_get
|
2009-11-30 12:31:11 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
METARIG_NAMES = "finger_01", "finger_02", "finger_03"
|
2009-12-02 11:55:47 +00:00
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 11:55:47 +00:00
|
|
|
def metarig_template():
|
2009-12-17 13:17:24 +00:00
|
|
|
# generated by rigify.write_meta_rig
|
2009-12-02 11:55:47 +00:00
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2009-12-10 11:56:31 +00:00
|
|
|
obj = bpy.context.active_object
|
2009-12-02 11:55:47 +00:00
|
|
|
arm = obj.data
|
|
|
|
bone = arm.edit_bones.new('finger.01')
|
|
|
|
bone.head[:] = 0.0000, 0.0000, 0.0000
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.tail[:] = 0.0353, -0.0184, -0.0053
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -2.8722
|
|
|
|
bone.connected = False
|
|
|
|
bone = arm.edit_bones.new('finger.02')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0353, -0.0184, -0.0053
|
|
|
|
bone.tail[:] = 0.0702, -0.0364, -0.0146
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -2.7099
|
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['finger.01']
|
|
|
|
bone = arm.edit_bones.new('finger.03')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0702, -0.0364, -0.0146
|
|
|
|
bone.tail[:] = 0.0903, -0.0461, -0.0298
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -2.1709
|
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['finger.02']
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
|
|
|
pbone = obj.pose.bones['finger.01']
|
2009-12-10 13:45:16 +00:00
|
|
|
pbone['type'] = 'finger_curl'
|
2009-12-02 11:55:47 +00:00
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
def metarig_definition(obj, orig_bone_name):
|
|
|
|
'''
|
|
|
|
The bone given is the first in a chain
|
|
|
|
Expects a chain of at least 2 children.
|
|
|
|
eg.
|
|
|
|
finger -> finger_01 -> finger_02
|
|
|
|
'''
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
bone_definition = []
|
|
|
|
|
|
|
|
orig_bone = obj.data.bones[orig_bone_name]
|
|
|
|
|
|
|
|
bone_definition.append(orig_bone.name)
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
bone = orig_bone
|
|
|
|
chain = 0
|
|
|
|
while chain < 2: # first 2 bones only have 1 child
|
|
|
|
children = bone.children
|
|
|
|
|
|
|
|
if len(children) != 1:
|
2009-12-10 18:28:22 +00:00
|
|
|
raise RigifyError("expected the chain to have 2 children from bone '%s' without a fork" % orig_bone_name)
|
2009-12-05 19:26:28 +00:00
|
|
|
bone = children[0]
|
|
|
|
bone_definition.append(bone.name) # finger_02, finger_03
|
|
|
|
chain += 1
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
if len(bone_definition) != len(METARIG_NAMES):
|
2009-12-10 18:28:22 +00:00
|
|
|
raise RigifyError("internal problem, expected %d bones" % len(METARIG_NAMES))
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
return bone_definition
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 11:55:47 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
def deform(obj, definitions, base_names, options):
|
|
|
|
""" Creates the deform rig.
|
|
|
|
"""
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
|
|
|
|
# Create base digit bones: two bones, each half of the base digit.
|
|
|
|
f1a = copy_bone_simple(obj.data, definitions[0], "DEF-%s.01" % base_names[definitions[0]], parent=True)
|
|
|
|
f1b = copy_bone_simple(obj.data, definitions[0], "DEF-%s.02" % base_names[definitions[0]], parent=True)
|
|
|
|
f1a.connected = False
|
|
|
|
f1b.connected = False
|
|
|
|
f1b.parent = f1a
|
|
|
|
center = f1a.center
|
|
|
|
f1a.tail = center
|
|
|
|
f1b.head = center
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
# Create the other deform bones.
|
|
|
|
f2 = copy_bone_simple(obj.data, definitions[1], "DEF-%s" % base_names[definitions[1]], parent=True)
|
|
|
|
f3 = copy_bone_simple(obj.data, definitions[2], "DEF-%s" % base_names[definitions[2]], parent=True)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
# Store names before leaving edit mode
|
|
|
|
f1a_name = f1a.name
|
|
|
|
f1b_name = f1b.name
|
|
|
|
f2_name = f2.name
|
|
|
|
f3_name = f3.name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
# Leave edit mode
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
# Get the pose bones
|
|
|
|
f1a = obj.pose.bones[f1a_name]
|
|
|
|
f1b = obj.pose.bones[f1b_name]
|
|
|
|
f2 = obj.pose.bones[f2_name]
|
|
|
|
f3 = obj.pose.bones[f3_name]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
# Constrain the base digit's bones
|
|
|
|
con = f1a.constraints.new('DAMPED_TRACK')
|
|
|
|
con.name = "trackto"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[1]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
con = f1a.constraints.new('COPY_SCALE')
|
|
|
|
con.name = "copy_scale"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[0]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
con = f1b.constraints.new('COPY_ROTATION')
|
|
|
|
con.name = "copy_rot"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[0]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
# Constrain the other digit's bones
|
|
|
|
con = f2.constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.name = "copy_transforms"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[1]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
con = f3.constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.name = "copy_transforms"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[2]
|
|
|
|
|
|
|
|
|
2009-12-11 16:30:27 +00:00
|
|
|
def main(obj, bone_definition, base_names, options):
|
2009-11-30 12:31:11 +00:00
|
|
|
# *** EDITMODE
|
2010-01-19 19:07:09 +00:00
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
# get assosiated data
|
2009-12-10 14:32:37 +00:00
|
|
|
arm = obj.data
|
2010-01-19 19:07:09 +00:00
|
|
|
bb = obj.data.bones
|
|
|
|
eb = obj.data.edit_bones
|
|
|
|
pb = obj.pose.bones
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
org_f1 = bone_definition[0] # Original finger bone 01
|
|
|
|
org_f2 = bone_definition[1] # Original finger bone 02
|
|
|
|
org_f3 = bone_definition[2] # Original finger bone 03
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Check options
|
|
|
|
if "bend_ratio" in options:
|
|
|
|
bend_ratio = options["bend_ratio"]
|
|
|
|
else:
|
|
|
|
bend_ratio = 0.4
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
yes = [1, 1.0, True, "True", "true", "Yes", "yes"]
|
|
|
|
make_hinge = False
|
|
|
|
if ("hinge" in options) and (eb[org_f1].parent is not None):
|
|
|
|
if options["hinge"] in yes:
|
|
|
|
make_hinge = True
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Needed if its a new armature with no keys
|
2010-01-31 14:30:21 +00:00
|
|
|
obj.animation_data_create()
|
2010-01-19 19:07:09 +00:00
|
|
|
|
|
|
|
# Create the control bone
|
|
|
|
base_name = base_names[bone_definition[0]].split(".", 1)[0]
|
|
|
|
tot_len = eb[org_f1].length + eb[org_f2].length + eb[org_f3].length
|
|
|
|
control = copy_bone_simple(arm, bone_definition[0], base_name + get_side_name(base_names[bone_definition[0]]), parent=True).name
|
|
|
|
eb[control].connected = eb[org_f1].connected
|
|
|
|
eb[control].parent = eb[org_f1].parent
|
|
|
|
eb[control].length = tot_len
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Create secondary control bones
|
|
|
|
f1 = copy_bone_simple(arm, bone_definition[0], base_names[bone_definition[0]]).name
|
|
|
|
f2 = copy_bone_simple(arm, bone_definition[1], base_names[bone_definition[1]]).name
|
|
|
|
f3 = copy_bone_simple(arm, bone_definition[2], base_names[bone_definition[2]]).name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Create driver bones
|
|
|
|
df1 = copy_bone_simple(arm, bone_definition[0], "MCH-" + base_names[bone_definition[0]]).name
|
|
|
|
eb[df1].length /= 2
|
|
|
|
df2 = copy_bone_simple(arm, bone_definition[1], "MCH-" + base_names[bone_definition[1]]).name
|
|
|
|
eb[df2].length /= 2
|
|
|
|
df3 = copy_bone_simple(arm, bone_definition[2], "MCH-" + base_names[bone_definition[2]]).name
|
|
|
|
eb[df3].length /= 2
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Set parents of the bones, interleaving the driver bones with the secondary control bones
|
|
|
|
eb[f3].connected = False
|
|
|
|
eb[df3].connected = False
|
|
|
|
eb[f2].connected = False
|
|
|
|
eb[df2].connected = False
|
|
|
|
eb[f1].connected = False
|
|
|
|
eb[df1].connected = eb[org_f1].connected
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
eb[f3].parent = eb[df3]
|
|
|
|
eb[df3].parent = eb[f2]
|
|
|
|
eb[f2].parent = eb[df2]
|
|
|
|
eb[df2].parent = eb[f1]
|
|
|
|
eb[f1].parent = eb[df1]
|
|
|
|
eb[df1].parent = eb[org_f1].parent
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Set up bones for hinge
|
|
|
|
if make_hinge:
|
|
|
|
socket = copy_bone_simple(arm, org_f1, "MCH-socket_"+control, parent=True).name
|
|
|
|
hinge = copy_bone_simple(arm, eb[org_f1].parent.name, "MCH-hinge_"+control).name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
eb[control].connected = False
|
|
|
|
eb[control].parent = eb[hinge]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Create the deform rig while we're still in edit mode
|
2010-01-02 23:43:46 +00:00
|
|
|
deform(obj, bone_definition, base_names, options)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
# *** POSEMODE
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Set rotation modes and axis locks
|
|
|
|
pb[control].rotation_mode = obj.pose.bones[bone_definition[0]].rotation_mode
|
|
|
|
pb[control].lock_location = True, True, True
|
|
|
|
pb[control].lock_scale = True, False, True
|
|
|
|
pb[f1].rotation_mode = 'YZX'
|
|
|
|
pb[f2].rotation_mode = 'YZX'
|
|
|
|
pb[f3].rotation_mode = 'YZX'
|
|
|
|
pb[f1].lock_location = True, True, True
|
|
|
|
pb[f2].lock_location = True, True, True
|
|
|
|
pb[f3].lock_location = True, True, True
|
|
|
|
pb[df2].rotation_mode = 'YZX'
|
|
|
|
pb[df3].rotation_mode = 'YZX'
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Add the bend_ratio property to the control bone
|
|
|
|
pb[control]["bend_ratio"] = bend_ratio
|
|
|
|
prop = rna_idprop_ui_prop_get(pb[control], "bend_ratio", create=True)
|
2009-11-30 12:31:11 +00:00
|
|
|
prop["soft_min"] = 0.0
|
|
|
|
prop["soft_max"] = 1.0
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Add hinge property to the control bone
|
|
|
|
if make_hinge:
|
|
|
|
pb[control]["hinge"] = 0.0
|
|
|
|
prop = rna_idprop_ui_prop_get(pb[control], "hinge", create=True)
|
|
|
|
prop["soft_min"] = 0.0
|
|
|
|
prop["soft_max"] = 1.0
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Constraints
|
|
|
|
con = pb[df1].constraints.new('COPY_LOCATION')
|
2009-11-30 12:31:11 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = control
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[df1].constraints.new('COPY_ROTATION')
|
2009-11-30 12:31:11 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = control
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[org_f1].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = f1
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[org_f2].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = f2
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[org_f3].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = f3
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
if make_hinge:
|
|
|
|
con = pb[hinge].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = bb[org_f1].parent.name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
hinge_driver_path = pb[control].path_to_id() + '["hinge"]'
|
|
|
|
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
var = driver.variables.new()
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
var.name = "var"
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = hinge_driver_path
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
mod = fcurve.modifiers[0]
|
|
|
|
mod.poly_order = 1
|
|
|
|
mod.coefficients[0] = 1.0
|
|
|
|
mod.coefficients[1] = -1.0
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[control].constraints.new('COPY_LOCATION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = socket
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Create the drivers for the driver bones (control bone scale rotates driver bones)
|
|
|
|
controller_path = pb[control].path_to_id() # 'pose.bones["%s"]' % control_bone_name
|
2009-11-30 12:31:11 +00:00
|
|
|
|
|
|
|
i = 0
|
2010-01-19 19:07:09 +00:00
|
|
|
for bone in [df2, df3]:
|
2009-11-30 12:31:11 +00:00
|
|
|
|
|
|
|
# XXX - todo, any number
|
2009-12-05 22:03:07 +00:00
|
|
|
if i == 2:
|
2009-11-30 12:31:11 +00:00
|
|
|
break
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
pbone = pb[bone]
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
pbone.rotation_mode = 'YZX'
|
|
|
|
fcurve_driver = pbone.driver_add("rotation_euler", 0)
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
#obj.driver_add('pose.bones["%s"].scale', 1)
|
|
|
|
#obj.animation_data.drivers[-1] # XXX, WATCH THIS
|
|
|
|
driver = fcurve_driver.driver
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
# scale target
|
Durian Request: Drivers Recode
Highlights:
* Support for Multi-Target Variables
This was the main reason for this recode. Previously, variables could only be used to give some RNA property used as an input source to the driver a name. However, this meant that effects such as Rotational Difference couldn't be used in conjunction with other effects and/or settings to achieve the powerful results. Now, a variable can take several input targets, perform some interesting operations on them, and spit out a representative value based on that.
* New Variable Types
With the introduction of multi-target variables, there are now 3 types of variable that can be used: single property (i.e. the only type previously), Rotational Difference (angle between two bones), and Distance (distance between two objects or bones).
* New Driver Types
In addition to the existing 'Average', 'Sum', and 'Expression' types, there is now the additional options of 'Minimum' and 'Maximum'. These take the smallest/largest value that one of the variables evaluates to.
* Fix for Driver F-Curve colouring bug
Newly added drivers did not get automatically coloured in the Graph Editor properly. Was caused by inappropriate notifiers being used.
Notes:
* This commit breaks existing 2.5 files with drivers (in other words, they are lost forever).
* Rigify has been corrected to work with the new system. The PyAPI for accessing targets used for the variables could still be made nicer (using subclassing to directly access?), but that is left for later.
* Version patching for 2.49 files still needs to be put back in place.
2010-01-04 21:15:45 +00:00
|
|
|
var = driver.variables.new()
|
|
|
|
var.name = "scale"
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = controller_path + '.scale[1]'
|
2009-11-30 12:31:11 +00:00
|
|
|
|
|
|
|
# bend target
|
Durian Request: Drivers Recode
Highlights:
* Support for Multi-Target Variables
This was the main reason for this recode. Previously, variables could only be used to give some RNA property used as an input source to the driver a name. However, this meant that effects such as Rotational Difference couldn't be used in conjunction with other effects and/or settings to achieve the powerful results. Now, a variable can take several input targets, perform some interesting operations on them, and spit out a representative value based on that.
* New Variable Types
With the introduction of multi-target variables, there are now 3 types of variable that can be used: single property (i.e. the only type previously), Rotational Difference (angle between two bones), and Distance (distance between two objects or bones).
* New Driver Types
In addition to the existing 'Average', 'Sum', and 'Expression' types, there is now the additional options of 'Minimum' and 'Maximum'. These take the smallest/largest value that one of the variables evaluates to.
* Fix for Driver F-Curve colouring bug
Newly added drivers did not get automatically coloured in the Graph Editor properly. Was caused by inappropriate notifiers being used.
Notes:
* This commit breaks existing 2.5 files with drivers (in other words, they are lost forever).
* Rigify has been corrected to work with the new system. The PyAPI for accessing targets used for the variables could still be made nicer (using subclassing to directly access?), but that is left for later.
* Version patching for 2.49 files still needs to be put back in place.
2010-01-04 21:15:45 +00:00
|
|
|
var = driver.variables.new()
|
|
|
|
var.name = "br"
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = controller_path + '["bend_ratio"]'
|
2009-11-30 12:31:11 +00:00
|
|
|
|
|
|
|
# XXX - todo, any number
|
2009-12-05 22:03:07 +00:00
|
|
|
if i == 0:
|
2009-11-30 12:31:11 +00:00
|
|
|
driver.expression = '(-scale+1.0)*pi*2.0*(1.0-br)'
|
2009-12-05 22:03:07 +00:00
|
|
|
elif i == 1:
|
2009-11-30 12:31:11 +00:00
|
|
|
driver.expression = '(-scale+1.0)*pi*2.0*br'
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
i += 1
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Last step setup layers
|
2010-01-10 18:53:15 +00:00
|
|
|
if "ex_layer" in options:
|
|
|
|
layer = [n==options["ex_layer"] for n in range(0,32)]
|
|
|
|
else:
|
|
|
|
layer = list(arm.bones[bone_definition[0]].layer)
|
2010-01-19 19:07:09 +00:00
|
|
|
for bone_name in [f1, f2, f3]:
|
|
|
|
arm.bones[bone_name].layer = layer
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 18:53:15 +00:00
|
|
|
layer = list(arm.bones[bone_definition[0]].layer)
|
2010-01-19 19:07:09 +00:00
|
|
|
bb[control].layer = layer
|
2009-12-14 14:21:06 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
# no blending the result of this
|
|
|
|
return None
|