2009-12-01 00:44:53 +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-12-01 00:44:53 +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 00:44:53 +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 = ("body", "head")
|
2009-12-01 00:44:53 +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('body')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0276, -0.1328
|
|
|
|
bone.tail[:] = 0.0000, -0.0170, -0.0197
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = 0.0000
|
|
|
|
bone.connected = False
|
|
|
|
bone = arm.edit_bones.new('head')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0170, -0.0197
|
|
|
|
bone.tail[:] = 0.0000, 0.0726, 0.1354
|
2009-12-08 17:00:53 +00:00
|
|
|
bone.roll = 0.0000
|
|
|
|
bone.connected = True
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.parent = arm.edit_bones['body']
|
|
|
|
bone = arm.edit_bones.new('neck.01')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0170, -0.0197
|
|
|
|
bone.tail[:] = 0.0000, -0.0099, 0.0146
|
|
|
|
bone.roll = 0.0000
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.connected = False
|
|
|
|
bone.parent = arm.edit_bones['head']
|
|
|
|
bone = arm.edit_bones.new('neck.02')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0099, 0.0146
|
|
|
|
bone.tail[:] = 0.0000, -0.0242, 0.0514
|
|
|
|
bone.roll = 0.0000
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['neck.01']
|
|
|
|
bone = arm.edit_bones.new('neck.03')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0242, 0.0514
|
|
|
|
bone.tail[:] = 0.0000, -0.0417, 0.0868
|
|
|
|
bone.roll = 0.0000
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['neck.02']
|
|
|
|
bone = arm.edit_bones.new('neck.04')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0417, 0.0868
|
|
|
|
bone.tail[:] = 0.0000, -0.0509, 0.1190
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = 0.0000
|
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['neck.03']
|
|
|
|
bone = arm.edit_bones.new('neck.05')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0509, 0.1190
|
|
|
|
bone.tail[:] = 0.0000, -0.0537, 0.1600
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = 0.0000
|
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['neck.04']
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
|
|
|
pbone = obj.pose.bones['head']
|
2009-12-10 13:45:16 +00:00
|
|
|
pbone['type'] = 'neck_flex'
|
2009-12-02 11:55:47 +00:00
|
|
|
|
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
def metarig_definition(obj, orig_bone_name):
|
|
|
|
'''
|
|
|
|
The bone given is the head, its parent is the body,
|
|
|
|
# its only child the first of a chain with matching basenames.
|
|
|
|
eg.
|
|
|
|
body -> head -> neck_01 -> neck_02 -> neck_03.... etc
|
|
|
|
'''
|
|
|
|
arm = obj.data
|
|
|
|
head = arm.bones[orig_bone_name]
|
|
|
|
body = head.parent
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
children = head.children
|
|
|
|
if len(children) != 1:
|
2009-12-10 18:28:22 +00:00
|
|
|
raise RigifyError("expected the head bone '%s' to have only 1 child." % orig_bone_name)
|
2009-12-05 19:26:28 +00:00
|
|
|
|
|
|
|
child = children[0]
|
|
|
|
bone_definition = [body.name, head.name, child.name]
|
|
|
|
bone_definition.extend([child.name for child in child.children_recursive_basename])
|
|
|
|
return bone_definition
|
|
|
|
|
|
|
|
|
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-01 00:44:53 +00:00
|
|
|
from Mathutils import Vector
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
arm = obj.data
|
|
|
|
|
|
|
|
# Initialize container classes for convenience
|
|
|
|
mt = bone_class_instance(obj, ["body", "head"]) # meta
|
2009-12-05 19:26:28 +00:00
|
|
|
mt.body = bone_definition[0]
|
|
|
|
mt.head = bone_definition[1]
|
2009-12-01 00:44:53 +00:00
|
|
|
mt.update()
|
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
neck_chain = bone_definition[2:]
|
2009-12-01 00:44:53 +00:00
|
|
|
|
|
|
|
mt_chain = bone_class_instance(obj, [("neck_%.2d" % (i + 1)) for i in range(len(neck_chain))]) # 99 bones enough eh?
|
2009-12-05 19:26:28 +00:00
|
|
|
for i, attr in enumerate(mt_chain.attr_names):
|
|
|
|
setattr(mt_chain, attr, neck_chain[i])
|
2009-12-01 00:44:53 +00:00
|
|
|
mt_chain.update()
|
|
|
|
|
2009-12-08 17:00:53 +00:00
|
|
|
neck_chain_basename = base_names[mt_chain.neck_01_e.name].split(".")[0]
|
2009-12-01 00:44:53 +00:00
|
|
|
neck_chain_segment_length = mt_chain.neck_01_e.length
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-14 14:21:06 +00:00
|
|
|
ex = bone_class_instance(obj, ["head", "head_hinge", "neck_socket", "head_ctrl"]) # hinge & extras
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# Add the head hinge at the bodys location, becomes the parent of the original head
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-10 22:23:09 +00:00
|
|
|
# apply everything to this copy of the chain
|
|
|
|
ex_chain = mt_chain.copy(base_names=base_names)
|
|
|
|
ex_chain.neck_01_e.parent = mt_chain.neck_01_e.parent
|
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# Copy the head bone and offset
|
2010-01-10 18:53:15 +00:00
|
|
|
ex.head_e = copy_bone_simple(arm, mt.head, "MCH-%s" % base_names[mt.head], parent=True)
|
2009-12-08 17:00:53 +00:00
|
|
|
ex.head_e.connected = False
|
2009-12-01 00:44:53 +00:00
|
|
|
ex.head = ex.head_e.name
|
|
|
|
# offset
|
|
|
|
head_length = ex.head_e.length
|
|
|
|
ex.head_e.head.y += head_length / 2.0
|
|
|
|
ex.head_e.tail.y += head_length / 2.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# Yes, use the body bone but call it a head hinge
|
2010-01-10 18:53:15 +00:00
|
|
|
ex.head_hinge_e = copy_bone_simple(arm, mt.body, "MCH-%s_hinge" % base_names[mt.head], parent=False)
|
2009-12-08 17:00:53 +00:00
|
|
|
ex.head_hinge_e.connected = False
|
2009-12-01 00:44:53 +00:00
|
|
|
ex.head_hinge = ex.head_hinge_e.name
|
|
|
|
ex.head_hinge_e.head.y += head_length / 4.0
|
|
|
|
ex.head_hinge_e.tail.y += head_length / 4.0
|
|
|
|
|
|
|
|
# Insert the neck socket, the head copys this loation
|
|
|
|
ex.neck_socket_e = arm.edit_bones.new("MCH-%s_socked" % neck_chain_basename)
|
|
|
|
ex.neck_socket = ex.neck_socket_e.name
|
2009-12-08 17:00:53 +00:00
|
|
|
ex.neck_socket_e.connected = False
|
2009-12-01 00:44:53 +00:00
|
|
|
ex.neck_socket_e.parent = mt.body_e
|
|
|
|
ex.neck_socket_e.head = mt.head_e.head
|
|
|
|
ex.neck_socket_e.tail = mt.head_e.head - Vector(0.0, neck_chain_segment_length / 2.0, 0.0)
|
|
|
|
ex.neck_socket_e.roll = 0.0
|
2009-12-13 13:59:16 +00:00
|
|
|
|
|
|
|
|
2009-12-10 22:23:09 +00:00
|
|
|
# copy of the head for controling
|
|
|
|
ex.head_ctrl_e = copy_bone_simple(arm, mt.head, base_names[mt.head])
|
|
|
|
ex.head_ctrl = ex.head_ctrl_e.name
|
|
|
|
ex.head_ctrl_e.parent = ex.head_hinge_e
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-10 22:23:09 +00:00
|
|
|
for i, attr in enumerate(ex_chain.attr_names):
|
|
|
|
neck_e = getattr(ex_chain, attr + "_e")
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# dont store parent names, re-reference as each chain bones parent.
|
2009-12-10 22:23:09 +00:00
|
|
|
neck_e_parent = arm.edit_bones.new("MCH-rot_%s" % base_names[getattr(mt_chain, attr)])
|
2009-12-01 00:44:53 +00:00
|
|
|
neck_e_parent.head = neck_e.head
|
2009-12-14 20:56:19 +00:00
|
|
|
neck_e_parent.tail = neck_e.head + (mt.head_e.vector.normalize() * neck_chain_segment_length / 2.0)
|
2009-12-08 09:40:30 +00:00
|
|
|
neck_e_parent.roll = mt.head_e.roll
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
orig_parent = neck_e.parent
|
|
|
|
neck_e.connected = False
|
|
|
|
neck_e.parent = neck_e_parent
|
|
|
|
neck_e_parent.connected = False
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
if i == 0:
|
|
|
|
neck_e_parent.parent = mt.body_e
|
|
|
|
else:
|
|
|
|
neck_e_parent.parent = orig_parent
|
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-01 00:44:53 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
mt.update()
|
|
|
|
mt_chain.update()
|
2009-12-10 22:23:09 +00:00
|
|
|
ex_chain.update()
|
2009-12-01 00:44:53 +00:00
|
|
|
ex.update()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Axis locks
|
|
|
|
ex.head_ctrl_p.lock_location = True, True, True
|
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# Simple one off constraints, no drivers
|
2009-12-10 22:23:09 +00:00
|
|
|
con = ex.head_ctrl_p.constraints.new('COPY_LOCATION')
|
2009-12-01 00:44:53 +00:00
|
|
|
con.target = obj
|
|
|
|
con.subtarget = ex.neck_socket
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
con = ex.head_p.constraints.new('COPY_ROTATION')
|
|
|
|
con.target = obj
|
2009-12-10 22:23:09 +00:00
|
|
|
con.subtarget = ex.head_ctrl
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# driven hinge
|
2009-12-10 22:23:09 +00:00
|
|
|
prop = rna_idprop_ui_prop_get(ex.head_ctrl_p, "hinge", create=True)
|
|
|
|
ex.head_ctrl_p["hinge"] = 0.0
|
2009-12-01 00:44:53 +00:00
|
|
|
prop["soft_min"] = 0.0
|
|
|
|
prop["soft_max"] = 1.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
con = ex.head_hinge_p.constraints.new('COPY_ROTATION')
|
|
|
|
con.name = "hinge"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = mt.body
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# add driver
|
2009-12-10 22:23:09 +00:00
|
|
|
hinge_driver_path = ex.head_ctrl_p.path_to_id() + '["hinge"]'
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
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-01 00:44:53 +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 = hinge_driver_path
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
#mod = fcurve_driver.modifiers.new('GENERATOR')
|
|
|
|
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-10 22:23:09 +00:00
|
|
|
head_driver_path = ex.head_ctrl_p.path_to_id()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
target_names = [("b%.2d" % (i + 1)) for i in range(len(neck_chain))]
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-10 22:23:09 +00:00
|
|
|
ex.head_ctrl_p["bend_tot"] = 0.0
|
|
|
|
fcurve = ex.head_ctrl_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-05 22:03:07 +00:00
|
|
|
|
2009-12-07 20:49:12 +00:00
|
|
|
for i in range(len(neck_chain)):
|
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 = head_driver_path + ('["bend_%.2d"]' % (i + 1))
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
|
2009-12-10 22:23:09 +00:00
|
|
|
for i, attr in enumerate(ex_chain.attr_names):
|
|
|
|
neck_p = getattr(ex_chain, attr + "_p")
|
2009-12-01 00:44:53 +00:00
|
|
|
neck_p.lock_location = True, True, True
|
|
|
|
neck_p.lock_location = True, True, True
|
|
|
|
neck_p.lock_rotations_4d = True
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# Add bend prop
|
|
|
|
prop_name = "bend_%.2d" % (i + 1)
|
2009-12-10 22:23:09 +00:00
|
|
|
prop = rna_idprop_ui_prop_get(ex.head_ctrl_p, prop_name, create=True)
|
|
|
|
ex.head_ctrl_p[prop_name] = 1.0
|
2009-12-01 00:44:53 +00:00
|
|
|
prop["soft_min"] = 0.0
|
|
|
|
prop["soft_max"] = 1.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# add parent constraint
|
|
|
|
neck_p_parent = neck_p.parent
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
# add constraint
|
|
|
|
con = neck_p_parent.constraints.new('COPY_ROTATION')
|
|
|
|
con.name = "Copy Rotation"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = ex.head
|
|
|
|
con.owner_space = 'LOCAL'
|
|
|
|
con.target_space = 'LOCAL'
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
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-13 13:59:16 +00:00
|
|
|
|
2009-12-01 00:44:53 +00:00
|
|
|
fcurve.modifiers.remove(0) # grr dont need a modifier
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-01 00:44:53 +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 = head_driver_path + ('["bend_tot"]')
|
|
|
|
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.name = "bend"
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = head_driver_path + ('["%s"]' % prop_name)
|
2009-12-13 13:59:16 +00:00
|
|
|
|
|
|
|
|
2009-12-10 22:23:09 +00:00
|
|
|
# finally constrain the original bone to this one
|
|
|
|
orig_neck_p = getattr(mt_chain, attr + "_p")
|
|
|
|
con = orig_neck_p.constraints.new('COPY_ROTATION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = neck_p.name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
|
|
|
|
2010-01-10 18:53:15 +00:00
|
|
|
# Set the head control's custom shape to use the last
|
|
|
|
# org neck bone for its transform
|
|
|
|
ex.head_ctrl_p.custom_shape_transform = obj.pose.bones[bone_definition[len(bone_definition)-1]]
|
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:
|
|
|
|
layer = [n==options["ex_layer"] for n in range(0,32)]
|
|
|
|
else:
|
|
|
|
layer = list(arm.bones[bone_definition[1]].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 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
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 18:53:15 +00:00
|
|
|
layer = list(arm.bones[bone_definition[1]].layer)
|
|
|
|
ex.head_ctrl_b.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
|
2010-01-31 14:30:21 +00:00
|
|
|
|