Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'release/scripts/modules/rigify/leg.py')
-rw-r--r--release/scripts/modules/rigify/leg.py93
1 files changed, 48 insertions, 45 deletions
diff --git a/release/scripts/modules/rigify/leg.py b/release/scripts/modules/rigify/leg.py
index 1228e2ed78a..92bce0f3c2c 100644
--- a/release/scripts/modules/rigify/leg.py
+++ b/release/scripts/modules/rigify/leg.py
@@ -16,12 +16,15 @@
#
# ##### END GPL LICENSE BLOCK #####
+# <pep8 compliant>
+
import bpy
-from rigify import bone_class_instance, copy_bone_simple, copy_bone_simple_list, add_pole_target_bone, add_stretch_to, blend_bone_list
-from rna_prop_ui import rna_idprop_ui_get, rna_idprop_ui_prop_get
+from rigify import bone_class_instance, copy_bone_simple, blend_bone_list
+from rna_prop_ui import rna_idprop_ui_prop_get
METARIG_NAMES = "hips", "thigh", "shin", "foot", "toe", "heel"
+
def metarig_template():
# generated by rigify.write_meta_rig
bpy.ops.object.mode_set(mode='EDIT')
@@ -67,6 +70,7 @@ def metarig_template():
pbone = obj.pose.bones['thigh']
pbone['type'] = 'leg'
+
def metarig_definition(obj, orig_bone_name):
'''
The bone given is the first in a chain
@@ -74,7 +78,7 @@ def metarig_definition(obj, orig_bone_name):
eg.
thigh -> shin -> foot -> [toe, heel]
'''
-
+
bone_definition = []
orig_bone = obj.data.bones[orig_bone_name]
@@ -85,8 +89,8 @@ def metarig_definition(obj, orig_bone_name):
bone_definition.append(orig_bone_parent.name)
bone_definition.append(orig_bone.name)
-
-
+
+
bone = orig_bone
chain = 0
while chain < 2: # first 2 bones only have 1 child
@@ -97,7 +101,7 @@ def metarig_definition(obj, orig_bone_name):
bone = children[0]
bone_definition.append(bone.name) # shin, foot
chain += 1
-
+
children = bone.children
# Now there must be 2 children, only one connected
if len(children) != 2:
@@ -105,25 +109,24 @@ def metarig_definition(obj, orig_bone_name):
if children[0].connected == children[1].connected:
raise Exception("expected one bone to be connected")
-
+
toe, heel = children
if heel.connected:
toe, heel = heel, toe
-
-
+
+
bone_definition.append(toe.name)
bone_definition.append(heel.name)
-
+
if len(bone_definition) != len(METARIG_NAMES):
raise Exception("internal problem, expected %d bones" % len(METARIG_NAMES))
-
+
return bone_definition
def ik(obj, bone_definition, base_names):
- from Mathutils import Vector
arm = obj.data
-
+
# setup the existing bones
mt_chain = bone_class_instance(obj, ["thigh", "shin", "foot", "toe"])
mt = bone_class_instance(obj, ["hips", "heel"])
@@ -131,7 +134,7 @@ def ik(obj, bone_definition, base_names):
ex = bone_class_instance(obj, ["thigh_socket", "thigh_hinge", "foot_roll_1", "foot_roll_2", "foot_roll_3"])
# children of ik_foot
ik = bone_class_instance(obj, ["foot", "foot_roll", "foot_roll_01", "foot_roll_02", "knee_target"])
-
+
# XXX - duplicate below
for bone_class in (mt, mt_chain):
for attr in bone_class.attr_names:
@@ -155,13 +158,13 @@ def ik(obj, bone_definition, base_names):
ik.foot = ik.foot_e.name
ik.foot_e.tail.z = ik.foot_e.head.z
ik.foot_e.roll = 0.0
-
+
# heel pointing backwards, half length
ik.foot_roll_e = copy_bone_simple(arm, mt.heel, "%s_roll" % base_foot_name)
ik.foot_roll = ik.foot_roll_e.name
ik.foot_roll_e.tail = ik.foot_roll_e.head + (ik.foot_roll_e.head - ik.foot_roll_e.tail) / 2.0
ik.foot_roll_e.parent = ik.foot_e # heel is disconnected
-
+
# heel pointing forwards to the toe base, parent of the following 2 bones
ik.foot_roll_01_e = copy_bone_simple(arm, mt.heel, "MCH-%s_roll.01" % base_foot_name)
ik.foot_roll_01 = ik.foot_roll_01_e.name
@@ -174,20 +177,20 @@ def ik(obj, bone_definition, base_names):
ik.foot_roll_02_e.parent = ik.foot_roll_01_e # heel is disconnected
ik.foot_roll_02_e.head = mt_chain.foot_e.tail
ik.foot_roll_02_e.tail = mt.heel_e.head
-
+
del base_foot_name
-
+
# rename 'MCH-toe' --> to 'toe_ik' and make the child of ik.foot_roll_01
# ------------------ FK or IK?
ik_chain.rename("toe", base_names[mt_chain.toe] + "_ik")
ik_chain.toe_e.connected = False
ik_chain.toe_e.parent = ik.foot_roll_01_e
-
- # re-parent ik_chain.foot to the
+
+ # re-parent ik_chain.foot to the
ik_chain.foot_e.connected = False
ik_chain.foot_e.parent = ik.foot_roll_02_e
-
-
+
+
# knee target is the heel moved up and forward on its local axis
ik.knee_target_e = copy_bone_simple(arm, mt.heel, "knee_target")
ik.knee_target = ik.knee_target_e.name
@@ -209,7 +212,7 @@ def ik(obj, bone_definition, base_names):
ex.update()
mt_chain.update()
ik_chain.update()
-
+
# IK
con = ik_chain.shin_p.constraints.new('IK')
con.chain_length = 2
@@ -220,52 +223,51 @@ def ik(obj, bone_definition, base_names):
con.use_target = True
con.use_rotation = False
con.weight = 1.0
-
+
con.target = obj
con.subtarget = ik.foot
-
+
con.pole_target = obj
con.pole_subtarget = ik.knee_target
-
+
# foot roll
cons = [ \
(ik.foot_roll_01_p.constraints.new('COPY_ROTATION'), ik.foot_roll_01_p.constraints.new('LIMIT_ROTATION')), \
- (ik.foot_roll_02_p.constraints.new('COPY_ROTATION'), ik.foot_roll_02_p.constraints.new('LIMIT_ROTATION'))
- ]
-
+ (ik.foot_roll_02_p.constraints.new('COPY_ROTATION'), ik.foot_roll_02_p.constraints.new('LIMIT_ROTATION'))]
+
for con, con_l in cons:
con.target = obj
con.subtarget = ik.foot_roll
con.use_x, con.use_y, con.use_z = True, False, False
con.target_space = con.owner_space = 'LOCAL'
-
+
con = con_l
con.use_limit_x, con.use_limit_y, con.use_limit_z = True, False, False
con.owner_space = 'LOCAL'
-
+
if con_l is cons[-1][-1]:
con.minimum_x = 0.0
con.maximum_x = 180.0 # XXX -deg
else:
con.minimum_x = -180.0 # XXX -deg
con.maximum_x = 0.0
-
+
bpy.ops.object.mode_set(mode='EDIT')
-
+
return None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None
def fk(obj, bone_definition, base_names):
from Mathutils import Vector
arm = obj.data
-
+
# these account for all bones in METARIG_NAMES
mt_chain = bone_class_instance(obj, ["thigh", "shin", "foot", "toe"])
mt = bone_class_instance(obj, ["hips", "heel"])
-
+
# new bones
ex = bone_class_instance(obj, ["thigh_socket", "thigh_hinge"])
-
+
for bone_class in (mt, mt_chain):
for attr in bone_class.attr_names:
i = METARIG_NAMES.index(attr)
@@ -280,11 +282,11 @@ def fk(obj, bone_definition, base_names):
ex.thigh_hinge_e = copy_bone_simple(arm, mt_chain.thigh, "MCH-%s_hinge" % base_names[mt_chain.thigh], parent=True)
ex.thigh_hinge = ex.thigh_hinge_e.name
ex.thigh_hinge_e.tail = ex.thigh_hinge_e.head + Vector(0.0, 0.0, mt_chain.thigh_e.head.length)
- ex.thigh_hinge_e.translate(Vector(-(mt.hips_e.head.x - mt_chain.thigh_e.head.x), 0.0, 0.0))
+ ex.thigh_hinge_e.translate(Vector( - (mt.hips_e.head.x - mt_chain.thigh_e.head.x), 0.0, 0.0))
ex.thigh_hinge_e.length = mt.hips_e.length
-
+
fk_chain = mt_chain.copy() # fk has no prefix!
-
+
fk_chain.thigh_e.connected = False
fk_chain.thigh_e.parent = ex.thigh_hinge_e
@@ -303,14 +305,14 @@ def fk(obj, bone_definition, base_names):
fk_chain.thigh_p["hinge"] = 0.5
prop["soft_min"] = 0.0
prop["soft_max"] = 1.0
-
+
con = ex.thigh_hinge_p.constraints.new('COPY_ROTATION')
con.target = obj
con.subtarget = mt.hips
-
+
# add driver
hinge_driver_path = fk_chain.thigh_p.path_to_id() + '["hinge"]'
-
+
fcurve = con.driver_add("influence", 0)
driver = fcurve.driver
tar = driver.targets.new()
@@ -324,15 +326,16 @@ def fk(obj, bone_definition, base_names):
mod.poly_order = 1
mod.coefficients[0] = 1.0
mod.coefficients[1] = -1.0
-
+
bpy.ops.object.mode_set(mode='EDIT')
-
+
# dont blend the hips or heel
return None, fk_chain.thigh, fk_chain.shin, fk_chain.foot, fk_chain.toe, None
+
def main(obj, bone_definition, base_names):
bones_ik = ik(obj, bone_definition, base_names)
bones_fk = fk(obj, bone_definition, base_names)
-
+
bpy.ops.object.mode_set(mode='OBJECT')
blend_bone_list(obj, bone_definition, bones_ik, bones_fk)