2009-12-01 22:45:56 +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,
|
2010-02-12 13:34:04 +00:00
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-12-01 22:45:56 +00:00
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
# <pep8 compliant>
|
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
import bpy
|
2010-01-31 14:33:27 +00:00
|
|
|
from rigify import RigifyError
|
2009-12-10 12:58:03 +00:00
|
|
|
from rigify_utils import bone_class_instance, copy_bone_simple
|
2009-12-01 22:45:56 +00:00
|
|
|
from rna_prop_ui import rna_idprop_ui_prop_get
|
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
# not used, defined for completeness
|
|
|
|
METARIG_NAMES = ("pelvis", "ribcage")
|
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-08 17:00:53 +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('pelvis')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0306, 0.1039
|
|
|
|
bone.tail[:] = 0.0000, -0.0306, -0.0159
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = 0.0000
|
|
|
|
bone.connected = False
|
|
|
|
bone = arm.edit_bones.new('rib_cage')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0306, 0.1039
|
|
|
|
bone.tail[:] = 0.0000, -0.0306, 0.2236
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -0.0000
|
|
|
|
bone.connected = False
|
|
|
|
bone.parent = arm.edit_bones['pelvis']
|
|
|
|
bone = arm.edit_bones.new('spine.01')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, 0.0000, -0.0000
|
|
|
|
bone.tail[:] = 0.0000, -0.0306, 0.1039
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -0.0000
|
|
|
|
bone.connected = False
|
|
|
|
bone.parent = arm.edit_bones['rib_cage']
|
|
|
|
bone = arm.edit_bones.new('spine.02')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0306, 0.1039
|
|
|
|
bone.tail[:] = -0.0000, -0.0398, 0.2045
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -0.0000
|
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['spine.01']
|
|
|
|
bone = arm.edit_bones.new('spine.03')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = -0.0000, -0.0398, 0.2045
|
|
|
|
bone.tail[:] = -0.0000, -0.0094, 0.2893
|
|
|
|
bone.roll = -0.0000
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['spine.02']
|
|
|
|
bone = arm.edit_bones.new('spine.04')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = -0.0000, -0.0094, 0.2893
|
|
|
|
bone.tail[:] = -0.0000, 0.0335, 0.3595
|
|
|
|
bone.roll = -0.0000
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['spine.03']
|
|
|
|
bone = arm.edit_bones.new('spine.05')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = -0.0000, 0.0335, 0.3595
|
|
|
|
bone.tail[:] = -0.0000, 0.0555, 0.4327
|
|
|
|
bone.roll = -0.0000
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['spine.04']
|
|
|
|
bone = arm.edit_bones.new('spine.06')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = -0.0000, 0.0555, 0.4327
|
|
|
|
bone.tail[:] = -0.0000, 0.0440, 0.5207
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -0.0000
|
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['spine.05']
|
|
|
|
bone = arm.edit_bones.new('spine.07')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = -0.0000, 0.0440, 0.5207
|
|
|
|
bone.tail[:] = -0.0000, 0.0021, 0.5992
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -0.0000
|
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['spine.06']
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
|
|
|
pbone = obj.pose.bones['rib_cage']
|
2009-12-10 13:45:16 +00:00
|
|
|
pbone['type'] = 'spine_pivot_flex'
|
2009-12-02 11:55:47 +00:00
|
|
|
|
2009-12-26 09:36:50 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
def metarig_definition(obj, orig_bone_name):
|
2009-12-01 22:45:56 +00:00
|
|
|
'''
|
|
|
|
The bone given is the second in a chain.
|
|
|
|
Expects at least 1 parent and a chain of children withe the same basename
|
|
|
|
eg.
|
|
|
|
pelvis -> rib_cage -> spine.01 -> spine.02 -> spine.03
|
2009-12-05 19:26:28 +00:00
|
|
|
|
|
|
|
note: same as neck.
|
2009-12-01 22:45:56 +00:00
|
|
|
'''
|
2009-12-05 19:26:28 +00:00
|
|
|
arm = obj.data
|
|
|
|
ribcage = arm.bones[orig_bone_name]
|
|
|
|
pelvis = ribcage.parent
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-07 17:21:30 +00:00
|
|
|
if pelvis is None:
|
2009-12-10 18:28:22 +00:00
|
|
|
raise RigifyError("expected the ribcage bone:'%s' to have a parent (ribcage)." % ribcage.name)
|
2009-12-07 17:21:30 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
children = ribcage.children
|
2009-12-01 22:45:56 +00:00
|
|
|
if len(children) != 1:
|
2009-12-10 18:28:22 +00:00
|
|
|
raise RigifyError("expected the ribcage to have only 1 child.")
|
2009-12-01 22:45:56 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
child = children[0]
|
2009-12-08 07:11:43 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
bone_definition = [pelvis.name, ribcage.name, child.name]
|
|
|
|
bone_definition.extend([child.name for child in child.children_recursive_basename])
|
|
|
|
return bone_definition
|
2009-12-01 22:45:56 +00:00
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
def fk(*args):
|
|
|
|
main(*args)
|
2009-12-01 22:45:56 +00:00
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
def deform(obj, definitions, base_names, options):
|
|
|
|
for org_bone_name in definitions[2:]:
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
|
|
|
|
# Create deform bone.
|
|
|
|
bone = copy_bone_simple(obj.data, org_bone_name, "DEF-%s" % base_names[org_bone_name], parent=True)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
# Store name before leaving edit mode
|
|
|
|
bone_name = bone.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 bone
|
|
|
|
bone = obj.pose.bones[bone_name]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
# Constrain to the original bone
|
|
|
|
# XXX. Todo, is this needed if the bone is connected to its parent?
|
|
|
|
con = bone.constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.name = "copy_loc"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = org_bone_name
|
|
|
|
|
|
|
|
|
2009-12-11 16:30:27 +00:00
|
|
|
def main(obj, bone_definition, base_names, options):
|
2009-12-05 22:03:07 +00:00
|
|
|
from Mathutils import Vector, RotationMatrix
|
2009-12-01 22:45:56 +00:00
|
|
|
from math import radians, pi
|
2009-12-05 19:26:28 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
arm = obj.data
|
|
|
|
|
|
|
|
# Initialize container classes for convenience
|
|
|
|
mt = bone_class_instance(obj, ["pelvis", "ribcage"]) # meta
|
2009-12-05 19:26:28 +00:00
|
|
|
mt.pelvis = bone_definition[0]
|
|
|
|
mt.ribcage = bone_definition[1]
|
2009-12-01 22:45:56 +00:00
|
|
|
mt.update()
|
|
|
|
|
2009-12-05 20:45:51 +00:00
|
|
|
spine_chain_orig = tuple(bone_definition[2:])
|
2009-12-05 19:26:28 +00:00
|
|
|
spine_chain = [arm.edit_bones[child_name] for child_name in spine_chain_orig]
|
2009-12-05 20:45:51 +00:00
|
|
|
spine_chain_basename = base_names[spine_chain[0].name].rsplit(".", 1)[0] # probably 'ORG-spine.01' -> 'spine'
|
2009-12-05 19:26:28 +00:00
|
|
|
spine_chain_len = len(spine_chain_orig)
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
child = spine_chain[0]
|
|
|
|
spine_chain_segment_length = child.length
|
2009-12-08 17:00:53 +00:00
|
|
|
#child.parent = mt.pelvis_e # was mt.ribcage
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
# The first bone in the chain happens to be the basis of others, create them now
|
2010-01-26 11:17:41 +00:00
|
|
|
ex = bone_class_instance(obj, ["pelvis_copy", "ribcage_hinge", "ribcage_copy", "spine_rotate"])
|
2009-12-01 22:45:56 +00:00
|
|
|
|
2009-12-08 17:00:53 +00:00
|
|
|
ex.pelvis_copy_e = copy_bone_simple(arm, mt.pelvis, base_names[mt.pelvis]) # no parent
|
|
|
|
ex.pelvis_copy = ex.pelvis_copy_e.name
|
2009-12-09 22:44:26 +00:00
|
|
|
ex.pelvis_copy_e.local_location = False
|
2009-12-01 22:45:56 +00:00
|
|
|
|
|
|
|
# copy the pelvis, offset to make MCH-spine_rotate and MCH-ribcage_hinge
|
2009-12-08 17:00:53 +00:00
|
|
|
ex.ribcage_hinge_e = copy_bone_simple(arm, mt.pelvis, "MCH-%s_hinge" % base_names[mt.ribcage])
|
2009-12-01 22:45:56 +00:00
|
|
|
ex.ribcage_hinge = ex.ribcage_hinge_e.name
|
|
|
|
ex.ribcage_hinge_e.translate(Vector(0.0, spine_chain_segment_length / 4.0, 0.0))
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-11 16:30:27 +00:00
|
|
|
ex.spine_rotate_e = copy_bone_simple(arm, mt.ribcage, "MCH-%s_rotate" % spine_chain_basename)
|
2009-12-01 22:45:56 +00:00
|
|
|
ex.spine_rotate = ex.spine_rotate_e.name
|
|
|
|
ex.spine_rotate_e.translate(Vector(0.0, spine_chain_segment_length / 2.0, 0.0))
|
2009-12-08 17:00:53 +00:00
|
|
|
ex.spine_rotate_e.connected = False
|
|
|
|
ex.spine_rotate_e.parent = ex.pelvis_copy_e
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
|
|
|
|
# Copy the last bone now
|
|
|
|
child = spine_chain[-1]
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-09 14:25:56 +00:00
|
|
|
ex.ribcage_copy_e = copy_bone_simple(arm, mt.ribcage, base_names[mt.ribcage])
|
|
|
|
ex.ribcage_copy = ex.ribcage_copy_e.name
|
|
|
|
ex.ribcage_copy_e.connected = False
|
|
|
|
ex.ribcage_copy_e.parent = ex.ribcage_hinge_e
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
spine_chain = [child.name for child in spine_chain]
|
|
|
|
|
|
|
|
# We have 3 spine chains
|
|
|
|
# - original (ORG_*)
|
|
|
|
# - copy (*use original name*)
|
|
|
|
# - reverse (MCH-rev_*)
|
2009-12-05 19:26:28 +00:00
|
|
|
spine_chain_attrs = [("spine_%.2d" % (i + 1)) for i in range(spine_chain_len)]
|
2009-12-02 02:56:22 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
mt_chain = bone_class_instance(obj, spine_chain_attrs) # ORG_*
|
|
|
|
rv_chain = bone_class_instance(obj, spine_chain_attrs) # *
|
|
|
|
ex_chain = bone_class_instance(obj, spine_chain_attrs) # MCH-rev_*
|
2009-12-05 19:26:28 +00:00
|
|
|
del spine_chain_attrs
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
for i, child_name in enumerate(spine_chain):
|
2009-12-05 20:45:51 +00:00
|
|
|
child_name_orig = base_names[spine_chain_orig[i]]
|
2009-12-01 22:45:56 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
attr = mt_chain.attr_names[i] # eg. spine_04
|
2009-12-01 22:45:56 +00:00
|
|
|
|
2009-12-05 20:45:51 +00:00
|
|
|
setattr(mt_chain, attr, spine_chain_orig[i]) # the original bone
|
2009-12-01 22:45:56 +00:00
|
|
|
|
|
|
|
ebone = copy_bone_simple(arm, child_name, child_name_orig) # use the original name
|
|
|
|
setattr(ex_chain, attr, ebone.name)
|
|
|
|
|
|
|
|
ebone = copy_bone_simple(arm, child_name, "MCH-rev_%s" % child_name_orig)
|
|
|
|
setattr(rv_chain, attr, ebone.name)
|
|
|
|
ebone.connected = False
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
mt_chain.update()
|
|
|
|
ex_chain.update()
|
|
|
|
rv_chain.update()
|
|
|
|
|
|
|
|
# Now we need to re-parent these chains
|
2009-12-05 22:03:07 +00:00
|
|
|
for i, child_name in enumerate(spine_chain_orig):
|
2009-12-05 19:26:28 +00:00
|
|
|
attr = ex_chain.attr_names[i] + "_e"
|
2009-12-08 17:00:53 +00:00
|
|
|
ebone = getattr(ex_chain, attr)
|
2009-12-01 22:45:56 +00:00
|
|
|
if i == 0:
|
2009-12-08 17:00:53 +00:00
|
|
|
ebone.connected = False
|
|
|
|
ebone.parent = ex.pelvis_copy_e
|
2009-12-01 22:45:56 +00:00
|
|
|
else:
|
2009-12-08 17:00:53 +00:00
|
|
|
attr_parent = ex_chain.attr_names[i - 1] + "_e"
|
|
|
|
ebone.parent = getattr(ex_chain, attr_parent)
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
# intentional! get the parent from the other paralelle chain member
|
2009-12-08 17:00:53 +00:00
|
|
|
getattr(rv_chain, attr).parent = ebone
|
2009-12-05 22:03:07 +00:00
|
|
|
|
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
# ex_chain needs to interlace bones!
|
|
|
|
# Note, skip the first bone
|
2009-12-05 19:26:28 +00:00
|
|
|
for i in range(1, spine_chain_len): # similar to neck
|
2009-12-08 17:00:53 +00:00
|
|
|
child_name_orig = base_names[spine_chain_orig[i]]
|
2009-12-05 19:26:28 +00:00
|
|
|
spine_e = getattr(mt_chain, mt_chain.attr_names[i] + "_e")
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
# dont store parent names, re-reference as each chain bones parent.
|
|
|
|
spine_e_parent = arm.edit_bones.new("MCH-rot_%s" % child_name_orig)
|
|
|
|
spine_e_parent.head = spine_e.head
|
2009-12-14 20:56:19 +00:00
|
|
|
spine_e_parent.tail = spine_e.head + (mt.ribcage_e.vector.normalize() * spine_chain_segment_length / 2.0)
|
2009-12-07 17:21:30 +00:00
|
|
|
spine_e_parent.roll = mt.ribcage_e.roll
|
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
spine_e = getattr(ex_chain, ex_chain.attr_names[i] + "_e")
|
2009-12-01 22:45:56 +00:00
|
|
|
orig_parent = spine_e.parent
|
|
|
|
spine_e.connected = False
|
|
|
|
spine_e.parent = spine_e_parent
|
|
|
|
spine_e_parent.connected = False
|
|
|
|
|
|
|
|
spine_e_parent.parent = orig_parent
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 22:45:56 +00:00
|
|
|
|
|
|
|
# Rotate the rev chain 180 about the by the first bones center point
|
|
|
|
pivot = (rv_chain.spine_01_e.head + rv_chain.spine_01_e.tail) * 0.5
|
|
|
|
matrix = RotationMatrix(radians(180), 3, 'X')
|
2009-12-05 19:26:28 +00:00
|
|
|
for i, attr in enumerate(rv_chain.attr_names): # similar to neck
|
|
|
|
spine_e = getattr(rv_chain, attr + "_e")
|
2009-12-01 22:45:56 +00:00
|
|
|
# use the first bone as the pivot
|
|
|
|
|
|
|
|
spine_e.head = ((spine_e.head - pivot) * matrix) + pivot
|
|
|
|
spine_e.tail = ((spine_e.tail - pivot) * matrix) + pivot
|
|
|
|
spine_e.roll += pi # 180d roll
|
2009-12-02 02:56:22 +00:00
|
|
|
del spine_e
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
deform(obj, bone_definition, base_names, options)
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
# refresh pose bones
|
|
|
|
mt.update()
|
|
|
|
ex.update()
|
|
|
|
mt_chain.update()
|
|
|
|
ex_chain.update()
|
|
|
|
rv_chain.update()
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Axis locks
|
|
|
|
ex.ribcage_copy_p.lock_location = True, True, True
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
con = ex.ribcage_hinge_p.constraints.new('COPY_ROTATION')
|
|
|
|
con.name = "hinge"
|
|
|
|
con.target = obj
|
2009-12-08 17:00:53 +00:00
|
|
|
con.subtarget = ex.pelvis_copy
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
# add driver
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
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()
|
2009-12-02 02:56:22 +00:00
|
|
|
driver.type = 'AVERAGE'
|
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.name = "var"
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = ex.ribcage_copy_p.path_to_id() + '["hinge"]'
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
mod = fcurve.modifiers[0]
|
|
|
|
mod.poly_order = 1
|
|
|
|
mod.coefficients[0] = 1.0
|
|
|
|
mod.coefficients[1] = -1.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
con = ex.spine_rotate_p.constraints.new('COPY_ROTATION')
|
|
|
|
con.target = obj
|
2009-12-09 14:25:56 +00:00
|
|
|
con.subtarget = ex.ribcage_copy
|
2009-12-02 02:56:22 +00:00
|
|
|
|
2009-12-08 17:00:53 +00:00
|
|
|
# ex.pelvis_copy_p / rib_cage
|
|
|
|
con = ex.ribcage_copy_p.constraints.new('COPY_LOCATION')
|
2009-12-02 02:56:22 +00:00
|
|
|
con.target = obj
|
2009-12-08 17:00:53 +00:00
|
|
|
con.subtarget = ex.pelvis_copy
|
2009-12-02 02:56:22 +00:00
|
|
|
con.head_tail = 0.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
# This stores all important ID props
|
2009-12-08 17:00:53 +00:00
|
|
|
prop = rna_idprop_ui_prop_get(ex.ribcage_copy_p, "hinge", create=True)
|
|
|
|
ex.ribcage_copy_p["hinge"] = 1.0
|
2009-12-02 02:56:22 +00:00
|
|
|
prop["soft_min"] = 0.0
|
|
|
|
prop["soft_max"] = 1.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-08 17:00:53 +00:00
|
|
|
prop = rna_idprop_ui_prop_get(ex.ribcage_copy_p, "pivot_slide", create=True)
|
|
|
|
ex.ribcage_copy_p["pivot_slide"] = 1.0 / spine_chain_len
|
2009-12-05 19:26:28 +00:00
|
|
|
prop["soft_min"] = 1.0 / spine_chain_len
|
2009-12-02 02:56:22 +00:00
|
|
|
prop["soft_max"] = 1.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
# Create a fake connected parent/child relationship with bone location constraints
|
|
|
|
# positioned at the tip.
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
# reverse bones / MCH-rev_spine.##
|
2009-12-05 19:26:28 +00:00
|
|
|
for i in range(1, spine_chain_len):
|
|
|
|
spine_p = getattr(rv_chain, rv_chain.attr_names[i] + "_p")
|
|
|
|
spine_fake_parent_name = getattr(rv_chain, rv_chain.attr_names[i - 1])
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
con = spine_p.constraints.new('COPY_LOCATION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = spine_fake_parent_name
|
|
|
|
con.head_tail = 1.0
|
|
|
|
del spine_p, spine_fake_parent_name, con
|
2009-12-05 22:03:07 +00:00
|
|
|
|
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
# Constrain 'inbetween' bones
|
2009-12-05 19:26:28 +00:00
|
|
|
target_names = [("b%.2d" % (i + 1)) for i in range(spine_chain_len - 1)]
|
2009-12-08 17:00:53 +00:00
|
|
|
rib_driver_path = ex.ribcage_copy_p.path_to_id()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-08 17:00:53 +00:00
|
|
|
ex.ribcage_copy_p["bend_tot"] = 0.0
|
|
|
|
fcurve = ex.ribcage_copy_p.driver_add('["bend_tot"]', 0)
|
2009-12-07 20:49:12 +00:00
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'SUM'
|
|
|
|
fcurve.modifiers.remove(0) # grr dont need a modifier
|
2009-12-08 07:11:43 +00:00
|
|
|
|
2009-12-07 20:49:12 +00:00
|
|
|
for i in range(spine_chain_len - 1):
|
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 = target_names[i]
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = rib_driver_path + ('["bend_%.2d"]' % (i + 1))
|
2009-12-07 20:49:12 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
for i in range(1, spine_chain_len):
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-07 20:49:12 +00:00
|
|
|
# Add bend prop
|
|
|
|
prop_name = "bend_%.2d" % i
|
2009-12-08 17:00:53 +00:00
|
|
|
prop = rna_idprop_ui_prop_get(ex.ribcage_copy_p, prop_name, create=True)
|
2010-01-19 19:07:09 +00:00
|
|
|
if ("bend_%.2d" % i) in options:
|
|
|
|
ex.ribcage_copy_p[prop_name] = options["bend_%.2d" % i]
|
|
|
|
else:
|
|
|
|
ex.ribcage_copy_p[prop_name] = 1.0
|
2009-12-07 20:49:12 +00:00
|
|
|
prop["soft_min"] = 0.0
|
|
|
|
prop["soft_max"] = 1.0
|
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
spine_p = getattr(ex_chain, ex_chain.attr_names[i] + "_p")
|
2009-12-02 02:56:22 +00:00
|
|
|
spine_p_parent = spine_p.parent # interlaced bone
|
|
|
|
|
|
|
|
con = spine_p_parent.constraints.new('COPY_ROTATION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = ex.spine_rotate
|
|
|
|
con.owner_space = 'LOCAL'
|
|
|
|
con.target_space = 'LOCAL'
|
|
|
|
del spine_p
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
# add driver
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'SCRIPTED'
|
2009-12-07 20:49:12 +00:00
|
|
|
driver.expression = "bend/bend_tot"
|
2009-12-08 07:11:43 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
fcurve.modifiers.remove(0) # grr dont need a modifier
|
2009-12-08 07:11:43 +00:00
|
|
|
|
2009-12-07 20:49:12 +00:00
|
|
|
|
|
|
|
# add 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 = "bend_tot"
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = rib_driver_path + ('["bend_tot"]')
|
2009-12-08 07:11:43 +00:00
|
|
|
|
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 = "bend"
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = rib_driver_path + ('["%s"]' % prop_name)
|
2009-12-08 07:11:43 +00:00
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
# original bone drivers
|
|
|
|
# note: the first bone has a lot more constraints, but also this simple one is first.
|
2009-12-05 20:45:51 +00:00
|
|
|
for i, attr in enumerate(mt_chain.attr_names):
|
2009-12-05 19:26:28 +00:00
|
|
|
spine_p = getattr(mt_chain, attr + "_p")
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
con = spine_p.constraints.new('COPY_ROTATION')
|
|
|
|
con.target = obj
|
2009-12-05 19:26:28 +00:00
|
|
|
con.subtarget = getattr(ex_chain, attr) # lock to the copy's rotation
|
2009-12-02 02:56:22 +00:00
|
|
|
del spine_p
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
# pivot slide: - lots of copy location constraints.
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
con = mt_chain.spine_01_p.constraints.new('COPY_LOCATION')
|
|
|
|
con.name = "base"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = rv_chain.spine_01 # lock to the reverse location
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
for i in range(1, spine_chain_len + 1):
|
2009-12-02 02:56:22 +00:00
|
|
|
con = mt_chain.spine_01_p.constraints.new('COPY_LOCATION')
|
|
|
|
con.name = "slide_%d" % i
|
|
|
|
con.target = obj
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
if i == spine_chain_len:
|
|
|
|
attr = mt_chain.attr_names[i - 1]
|
2009-12-02 02:56:22 +00:00
|
|
|
else:
|
2009-12-05 19:26:28 +00:00
|
|
|
attr = mt_chain.attr_names[i]
|
2009-12-02 02:56:22 +00:00
|
|
|
|
|
|
|
con.subtarget = getattr(rv_chain, attr) # lock to the reverse location
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
if i == spine_chain_len:
|
2009-12-02 02:56:22 +00:00
|
|
|
con.head_tail = 1.0
|
|
|
|
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
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()
|
2009-12-02 02:56:22 +00:00
|
|
|
driver.type = 'AVERAGE'
|
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.name = "var"
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = rib_driver_path + '["pivot_slide"]'
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 02:56:22 +00:00
|
|
|
mod = fcurve.modifiers[0]
|
|
|
|
mod.poly_order = 1
|
|
|
|
mod.coefficients[0] = - (i - 1)
|
2009-12-05 19:26:28 +00:00
|
|
|
mod.coefficients[1] = spine_chain_len
|
2010-01-31 14:30:21 +00:00
|
|
|
|
|
|
|
|
2010-01-10 18:53:15 +00:00
|
|
|
# Set pelvis and ribcage controls to use the first and last bone in the
|
|
|
|
# spine respectively for their custom shape transform
|
|
|
|
ex.ribcage_copy_p.custom_shape_transform = obj.pose.bones[bone_definition[len(bone_definition)-1]]
|
|
|
|
ex.pelvis_copy_p.custom_shape_transform = obj.pose.bones[bone_definition[2]]
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-14 14:21:06 +00:00
|
|
|
|
|
|
|
# last step setup layers
|
2010-01-10 18:53:15 +00:00
|
|
|
if "ex_layer" in options:
|
2010-03-06 01:40:29 +00:00
|
|
|
layer = [n == options["ex_layer"] for n in range(0, 32)]
|
2010-01-10 18:53:15 +00:00
|
|
|
else:
|
|
|
|
layer = list(arm.bones[bone_definition[1]].layer)
|
2009-12-14 14:21:06 +00:00
|
|
|
for attr in ex.attr_names:
|
2010-01-10 18:53:15 +00:00
|
|
|
getattr(ex, attr + "_b").layer = layer
|
2009-12-14 14:21:06 +00:00
|
|
|
for attr in ex_chain.attr_names:
|
2010-01-10 18:53:15 +00:00
|
|
|
getattr(ex_chain, attr + "_b").layer = layer
|
2009-12-14 20:56:19 +00:00
|
|
|
for attr in rv_chain.attr_names:
|
2010-01-10 18:53:15 +00:00
|
|
|
getattr(rv_chain, attr + "_b").layer = layer
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 18:53:15 +00:00
|
|
|
layer = list(arm.bones[bone_definition[1]].layer)
|
|
|
|
arm.bones[ex.pelvis_copy].layer = layer
|
|
|
|
arm.bones[ex.ribcage_copy].layer = layer
|
2009-12-14 14:21:06 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
# no support for blending chains
|
|
|
|
return None
|