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-25 14:19:12 +00:00
|
|
|
from math import radians, pi
|
2010-01-31 14:33:27 +00:00
|
|
|
from rigify import RigifyError, ORG_PREFIX
|
2009-12-10 12:58:03 +00:00
|
|
|
from rigify_utils import bone_class_instance, copy_bone_simple, add_pole_target_bone, add_stretch_to, blend_bone_list, get_side_name, get_base_name
|
2009-12-05 22:03:07 +00:00
|
|
|
from rna_prop_ui import rna_idprop_ui_prop_get
|
2009-12-09 12:00:28 +00:00
|
|
|
from Mathutils import Vector
|
2009-11-30 12:31:11 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
METARIG_NAMES = "shoulder", "arm", "forearm", "hand"
|
2009-11-30 12:31:11 +00:00
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-02 11:55:47 +00:00
|
|
|
def metarig_template():
|
2009-12-09 12:00:28 +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('shoulder')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.0000, -0.0425, 0.0000
|
|
|
|
bone.tail[:] = 0.0942, -0.0075, 0.0333
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -0.2227
|
|
|
|
bone.connected = False
|
|
|
|
bone = arm.edit_bones.new('upper_arm')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.1066, -0.0076, -0.0010
|
|
|
|
bone.tail[:] = 0.2855, 0.0206, -0.0104
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = 1.6152
|
|
|
|
bone.connected = False
|
|
|
|
bone.parent = arm.edit_bones['shoulder']
|
|
|
|
bone = arm.edit_bones.new('forearm')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.2855, 0.0206, -0.0104
|
|
|
|
bone.tail[:] = 0.4550, -0.0076, -0.0023
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = 1.5153
|
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['upper_arm']
|
|
|
|
bone = arm.edit_bones.new('hand')
|
2009-12-17 13:17:24 +00:00
|
|
|
bone.head[:] = 0.4550, -0.0076, -0.0023
|
|
|
|
bone.tail[:] = 0.5423, -0.0146, -0.0131
|
2009-12-02 11:55:47 +00:00
|
|
|
bone.roll = -3.0083
|
|
|
|
bone.connected = True
|
|
|
|
bone.parent = arm.edit_bones['forearm']
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
|
|
|
pbone = obj.pose.bones['upper_arm']
|
2010-01-10 18:59:32 +00:00
|
|
|
pbone['type'] = 'arm_biped'
|
2009-12-02 11:55:47 +00:00
|
|
|
|
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
def metarig_definition(obj, orig_bone_name):
|
|
|
|
mt = bone_class_instance(obj, METARIG_NAMES) # meta
|
|
|
|
mt.arm = orig_bone_name
|
|
|
|
mt.update()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
mt.shoulder_p = mt.arm_p.parent
|
2009-12-08 07:11:43 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
if not mt.shoulder_p:
|
2009-12-10 18:28:22 +00:00
|
|
|
raise RigifyError("could not find '%s' parent, skipping:" % orig_bone_name)
|
2009-12-09 12:00:28 +00:00
|
|
|
|
2009-12-07 17:21:30 +00:00
|
|
|
mt.shoulder = mt.shoulder_p.name
|
2009-12-05 19:26:28 +00:00
|
|
|
|
|
|
|
# We could have some bones attached, find the bone that has this as its 2nd parent
|
|
|
|
hands = []
|
|
|
|
for pbone in obj.pose.bones:
|
|
|
|
index = pbone.parent_index(mt.arm_p)
|
2009-12-09 22:44:26 +00:00
|
|
|
if index == 2 and pbone.bone.connected and pbone.bone.parent.connected:
|
2009-12-05 19:26:28 +00:00
|
|
|
hands.append(pbone)
|
|
|
|
|
2009-12-08 17:00:53 +00:00
|
|
|
if len(hands) != 1:
|
2009-12-10 18:28:22 +00:00
|
|
|
raise RigifyError("Found %s possible hands attached to this arm, expected 1 from bone: %s" % ([pbone.name for pbone in hands], orig_bone_name))
|
2009-12-05 19:26:28 +00:00
|
|
|
|
|
|
|
# first add the 2 new bones
|
|
|
|
mt.hand_p = hands[0]
|
|
|
|
mt.hand = mt.hand_p.name
|
|
|
|
|
|
|
|
mt.forearm_p = mt.hand_p.parent
|
|
|
|
mt.forearm = mt.forearm_p.name
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
return mt.names()
|
|
|
|
|
|
|
|
|
2009-12-11 16:30:27 +00:00
|
|
|
def ik(obj, definitions, base_names, options):
|
2009-12-13 12:26:19 +00:00
|
|
|
|
2009-12-11 16:30:27 +00:00
|
|
|
arm = obj.data
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
mt = bone_class_instance(obj, METARIG_NAMES)
|
2009-12-05 19:26:28 +00:00
|
|
|
mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions
|
2009-12-09 12:00:28 +00:00
|
|
|
mt.update()
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
ik = bone_class_instance(obj, ["pole", "pole_vis", "hand_vis"])
|
|
|
|
ik_chain = mt.copy(to_fmt="MCH-%s_ik", base_names=base_names, exclude_attrs=["shoulder"])
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
# IK needs no parent_index
|
|
|
|
ik_chain.hand_e.connected = False
|
|
|
|
ik_chain.hand_e.parent = None
|
2009-12-09 22:44:26 +00:00
|
|
|
ik_chain.hand_e.local_location = False
|
|
|
|
ik_chain.rename("hand", get_base_name(base_names[mt.hand]) + "_ik" + get_side_name(mt.hand))
|
2009-12-09 12:00:28 +00:00
|
|
|
|
|
|
|
ik_chain.arm_e.connected = False
|
|
|
|
ik_chain.arm_e.parent = mt.shoulder_e
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
# Add the bone used for the arms poll target
|
2009-12-09 22:44:26 +00:00
|
|
|
#ik.pole = add_pole_target_bone(obj, mt.forearm, get_base_name(base_names[mt.forearm]) + "_target" + get_side_name(mt.forearm), mode='ZAVERAGE')
|
|
|
|
ik.pole = add_pole_target_bone(obj, mt.forearm, "elbow_target" + get_side_name(mt.forearm), mode='ZAVERAGE')
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 22:44:26 +00:00
|
|
|
ik.update()
|
|
|
|
ik.pole_e.local_location = False
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-11 16:30:27 +00:00
|
|
|
# option: elbow_parent
|
|
|
|
elbow_parent_name = options.get("elbow_parent", "")
|
|
|
|
|
|
|
|
if elbow_parent_name:
|
|
|
|
try:
|
2010-01-10 18:53:15 +00:00
|
|
|
elbow_parent_e = arm.edit_bones[ORG_PREFIX + elbow_parent_name]
|
2009-12-11 16:30:27 +00:00
|
|
|
except:
|
|
|
|
# TODO, old/new parent mapping
|
|
|
|
raise RigifyError("parent bone from property 'arm_biped_generic.elbow_parent' not found '%s'" % elbow_parent_name)
|
|
|
|
ik.pole_e.parent = elbow_parent_e
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
# update bones after this!
|
|
|
|
ik.hand_vis = add_stretch_to(obj, mt.hand, ik_chain.hand, "VIS-%s_ik" % base_names[mt.hand])
|
|
|
|
ik.pole_vis = add_stretch_to(obj, mt.forearm, ik.pole, "VIS-%s_ik" % base_names[mt.forearm])
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
ik.update()
|
|
|
|
ik.hand_vis_e.restrict_select = True
|
|
|
|
ik.pole_vis_e.restrict_select = True
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
mt.update()
|
|
|
|
ik.update()
|
|
|
|
ik_chain.update()
|
2009-12-09 14:29:55 +00:00
|
|
|
|
|
|
|
# Set IK dof
|
|
|
|
ik_chain.forearm_p.ik_dof_x = True
|
|
|
|
ik_chain.forearm_p.ik_dof_y = False
|
|
|
|
ik_chain.forearm_p.ik_dof_z = False
|
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
con = ik_chain.forearm_p.constraints.new('IK')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = ik_chain.hand
|
|
|
|
con.pole_target = obj
|
|
|
|
con.pole_subtarget = ik.pole
|
|
|
|
|
|
|
|
con.use_tail = True
|
|
|
|
con.use_stretch = True
|
|
|
|
con.use_target = True
|
|
|
|
con.use_rotation = False
|
|
|
|
con.chain_length = 2
|
2010-01-25 14:19:12 +00:00
|
|
|
con.pole_angle = -pi/2
|
2009-12-09 12:00:28 +00:00
|
|
|
|
2009-12-14 14:21:06 +00:00
|
|
|
# last step setup layers
|
2010-01-10 18:53:15 +00:00
|
|
|
if "ik_layer" in options:
|
|
|
|
layer = [n==options["ik_layer"] for n in range(0,32)]
|
|
|
|
else:
|
|
|
|
layer = list(mt.arm_b.layer)
|
|
|
|
ik_chain.hand_b.layer = layer
|
|
|
|
ik.hand_vis_b.layer = layer
|
|
|
|
ik.pole_b.layer = layer
|
|
|
|
ik.pole_vis_b.layer = layer
|
2009-12-14 14:21:06 +00:00
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2009-12-09 12:00:28 +00:00
|
|
|
# don't blend the shoulder
|
|
|
|
return [None] + ik_chain.names()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
|
|
|
|
2009-12-11 16:30:27 +00:00
|
|
|
def fk(obj, definitions, base_names, options):
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
arm = obj.data
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
mt = bone_class_instance(obj, METARIG_NAMES)
|
|
|
|
mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions
|
|
|
|
mt.update()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-14 14:21:06 +00:00
|
|
|
ex = bone_class_instance(obj, ["socket", "hand_delta"])
|
2009-12-09 12:00:28 +00:00
|
|
|
fk_chain = mt.copy(base_names=base_names)
|
|
|
|
|
|
|
|
# shoulder is used as a hinge
|
|
|
|
fk_chain.rename("shoulder", "MCH-%s_hinge" % base_names[mt.arm])
|
|
|
|
fk_chain.shoulder_e.translate(Vector(0.0, fk_chain.shoulder_e.length / 2, 0.0))
|
|
|
|
|
|
|
|
# upper arm constrains to this.
|
|
|
|
ex.socket_e = copy_bone_simple(arm, mt.arm, "MCH-%s_socket" % base_names[mt.arm])
|
|
|
|
ex.socket = ex.socket_e.name
|
|
|
|
ex.socket_e.connected = False
|
|
|
|
ex.socket_e.parent = mt.shoulder_e
|
2009-12-09 22:44:26 +00:00
|
|
|
ex.socket_e.length *= 0.5
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2010-01-10 18:53:15 +00:00
|
|
|
# insert the 'MCH-delta_hand', between the forearm and the hand
|
2009-12-09 12:00:28 +00:00
|
|
|
# copies forarm rotation
|
2010-01-10 18:53:15 +00:00
|
|
|
ex.hand_delta_e = copy_bone_simple(arm, fk_chain.hand, "MCH-delta_%s" % base_names[mt.hand], parent=True)
|
2009-12-09 12:00:28 +00:00
|
|
|
ex.hand_delta = ex.hand_delta_e.name
|
|
|
|
ex.hand_delta_e.length *= 0.5
|
|
|
|
ex.hand_delta_e.connected = False
|
2009-12-14 20:56:19 +00:00
|
|
|
if "hand_roll" in options:
|
|
|
|
ex.hand_delta_e.roll += radians(options["hand_roll"])
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
fk_chain.hand_e.connected = False
|
|
|
|
fk_chain.hand_e.parent = ex.hand_delta_e
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
mt.update()
|
|
|
|
ex.update()
|
|
|
|
fk_chain.update()
|
|
|
|
|
2009-12-09 14:29:55 +00:00
|
|
|
# Set rotation modes and axis locks
|
|
|
|
fk_chain.forearm_p.rotation_mode = 'XYZ'
|
|
|
|
fk_chain.forearm_p.lock_rotation = (False, True, True)
|
|
|
|
fk_chain.hand_p.rotation_mode = 'ZXY'
|
2010-01-19 19:07:09 +00:00
|
|
|
fk_chain.arm_p.lock_location = True, True, True
|
2009-12-09 14:29:55 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
con = fk_chain.arm_p.constraints.new('COPY_LOCATION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = ex.socket
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
fk_chain.hand_p.lock_location = True, True, True
|
|
|
|
con = ex.hand_delta_p.constraints.new('COPY_ROTATION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = fk_chain.forearm
|
|
|
|
|
|
|
|
def hinge_setup():
|
2009-11-30 12:31:11 +00:00
|
|
|
# Hinge constraint & driver
|
2009-12-09 12:00:28 +00:00
|
|
|
con = fk_chain.shoulder_p.constraints.new('COPY_ROTATION')
|
2009-11-30 12:31:11 +00:00
|
|
|
con.name = "hinge"
|
|
|
|
con.target = obj
|
2009-12-09 12:00:28 +00:00
|
|
|
con.subtarget = mt.shoulder
|
2009-11-30 12:31:11 +00:00
|
|
|
driver_fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = driver_fcurve.driver
|
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
controller_path = fk_chain.arm_p.path_to_id()
|
2009-11-30 12:31:11 +00:00
|
|
|
# add custom prop
|
2009-12-09 12:00:28 +00:00
|
|
|
fk_chain.arm_p["hinge"] = 0.0
|
|
|
|
prop = rna_idprop_ui_prop_get(fk_chain.arm_p, "hinge", create=True)
|
2009-11-30 12:31:11 +00:00
|
|
|
prop["soft_min"] = 0.0
|
|
|
|
prop["soft_max"] = 1.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
# *****
|
|
|
|
driver = driver_fcurve.driver
|
|
|
|
driver.type = 'AVERAGE'
|
2009-12-05 22:03:07 +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 = "hinge"
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = controller_path + '["hinge"]'
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
mod = driver_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-09 12:00:28 +00:00
|
|
|
hinge_setup()
|
2009-12-13 13:59:16 +00:00
|
|
|
|
2009-12-14 14:21:06 +00:00
|
|
|
# last step setup layers
|
2010-01-10 18:53:15 +00:00
|
|
|
if "fk_layer" in options:
|
|
|
|
layer = [n==options["fk_layer"] for n in range(0,32)]
|
|
|
|
else:
|
|
|
|
layer = list(mt.arm_b.layer)
|
|
|
|
fk_chain.arm_b.layer = layer
|
|
|
|
fk_chain.forearm_b.layer = layer
|
|
|
|
fk_chain.hand_b.layer = layer
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Forearm was getting wrong roll somehow. Hack to fix that.
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
fk_chain.update()
|
|
|
|
mt.update()
|
|
|
|
fk_chain.forearm_e.roll = mt.forearm_e.roll
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-14 14:21:06 +00:00
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2009-12-09 12:00:28 +00:00
|
|
|
return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand
|
2009-12-05 20:45:51 +00:00
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
def deform(obj, definitions, base_names, options):
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
|
|
|
|
# Create upper arm bones: two bones, each half of the upper arm.
|
|
|
|
uarm1 = copy_bone_simple(obj.data, definitions[1], "DEF-%s.01" % base_names[definitions[1]], parent=True)
|
|
|
|
uarm2 = copy_bone_simple(obj.data, definitions[1], "DEF-%s.02" % base_names[definitions[1]], parent=True)
|
|
|
|
uarm1.connected = False
|
|
|
|
uarm2.connected = False
|
|
|
|
uarm2.parent = uarm1
|
|
|
|
center = uarm1.center
|
|
|
|
uarm1.tail = center
|
|
|
|
uarm2.head = center
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
# Create forearm bones: two bones, each half of the forearm.
|
|
|
|
farm1 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.01" % base_names[definitions[2]], parent=True)
|
|
|
|
farm2 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.02" % base_names[definitions[2]], parent=True)
|
|
|
|
farm1.connected = False
|
|
|
|
farm2.connected = False
|
|
|
|
farm2.parent = farm1
|
|
|
|
center = farm1.center
|
|
|
|
farm1.tail = center
|
|
|
|
farm2.head = center
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-02 23:43:46 +00:00
|
|
|
# Create twist bone
|
|
|
|
twist = copy_bone_simple(obj.data, definitions[2], "MCH-arm_twist")
|
|
|
|
twist.connected = False
|
|
|
|
twist.parent = obj.data.edit_bones[definitions[3]]
|
|
|
|
twist.length /= 2
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
# Create hand bone
|
|
|
|
hand = copy_bone_simple(obj.data, definitions[3], "DEF-%s" % base_names[definitions[3]], parent=True)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
# Store names before leaving edit mode
|
|
|
|
uarm1_name = uarm1.name
|
|
|
|
uarm2_name = uarm2.name
|
|
|
|
farm1_name = farm1.name
|
|
|
|
farm2_name = farm2.name
|
2010-01-02 23:43:46 +00:00
|
|
|
twist_name = twist.name
|
2009-12-30 18:39:02 +00:00
|
|
|
hand_name = hand.name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
# Leave edit mode
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
# Get the pose bones
|
|
|
|
uarm1 = obj.pose.bones[uarm1_name]
|
|
|
|
uarm2 = obj.pose.bones[uarm2_name]
|
|
|
|
farm1 = obj.pose.bones[farm1_name]
|
|
|
|
farm2 = obj.pose.bones[farm2_name]
|
2010-01-02 23:43:46 +00:00
|
|
|
twist = obj.pose.bones[twist_name]
|
2009-12-30 18:39:02 +00:00
|
|
|
hand = obj.pose.bones[hand_name]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
# Upper arm constraints
|
|
|
|
con = uarm1.constraints.new('DAMPED_TRACK')
|
|
|
|
con.name = "trackto"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[2]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = uarm1.constraints.new('COPY_SCALE')
|
|
|
|
con.name = "trackto"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[1]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
con = uarm2.constraints.new('COPY_ROTATION')
|
|
|
|
con.name = "copy_rot"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[1]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
# Forearm constraints
|
|
|
|
con = farm1.constraints.new('COPY_ROTATION')
|
|
|
|
con.name = "copy_rot"
|
2010-01-19 19:07:09 +00:00
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[2]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = farm1.constraints.new('COPY_SCALE')
|
|
|
|
con.name = "copy_rot"
|
2009-12-30 18:39:02 +00:00
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[2]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
con = farm2.constraints.new('COPY_ROTATION')
|
|
|
|
con.name = "copy_rot"
|
|
|
|
con.target = obj
|
2010-01-02 23:43:46 +00:00
|
|
|
con.subtarget = twist.name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
con = farm2.constraints.new('DAMPED_TRACK')
|
|
|
|
con.name = "trackto"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[3]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
# Hand constraint
|
|
|
|
con = hand.constraints.new('COPY_ROTATION')
|
|
|
|
con.name = "copy_rot"
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[3]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2009-12-30 18:39:02 +00:00
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
return (uarm1_name, uarm2_name, farm1_name, farm2_name, hand_name)
|
|
|
|
|
|
|
|
|
2009-12-13 13:59:16 +00:00
|
|
|
def main(obj, bone_definition, base_names, options):
|
2009-12-11 16:30:27 +00:00
|
|
|
bones_fk = fk(obj, bone_definition, base_names, options)
|
2009-12-17 19:48:30 +00:00
|
|
|
bones_ik = ik(obj, bone_definition, base_names, options)
|
2009-12-30 18:39:02 +00:00
|
|
|
bones_deform = deform(obj, bone_definition, base_names, options)
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-09 12:00:28 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2009-12-30 18:39:02 +00:00
|
|
|
blend_bone_list(obj, bone_definition, bones_fk, bones_ik, target_bone=bones_ik[3], target_prop="ik", blend_default=0.0)
|