[Bf-extensions-cvs] [0509ef6] blender-v2.78-release: Fix on fk/ik snap operators and functions. In rig_ui_pitchipoy_template, operators did not have the "pole" property and snap functions did not address the "basic" and "pitchipoy" cases separately.

Lucio Rossi noreply at git.blender.org
Wed Oct 19 14:43:07 CEST 2016


Commit: 0509ef6d8eff45042db7fb965f95b2f816ceffb4
Author: Lucio Rossi
Date:   Sun Oct 16 20:17:22 2016 +0200
Branches: blender-v2.78-release
https://developer.blender.org/rBA0509ef6d8eff45042db7fb965f95b2f816ceffb4

Fix on fk/ik snap operators and functions. In rig_ui_pitchipoy_template, operators did not have the "pole" property and snap functions did not address the "basic" and "pitchipoy" cases separately.

===================================================================

M	rigify/rig_ui_pitchipoy_template.py
M	rigify/rigs/pitchipoy/limbs/ui.py

===================================================================

diff --git a/rigify/rig_ui_pitchipoy_template.py b/rigify/rig_ui_pitchipoy_template.py
index 082016d..5817f9c 100755
--- a/rigify/rig_ui_pitchipoy_template.py
+++ b/rigify/rig_ui_pitchipoy_template.py
@@ -309,27 +309,40 @@ def fk2ik_arm(obj, fk, ik):
     farmi = obj.pose.bones[ik[1]]
     handi = obj.pose.bones[ik[2]]
 
-    # Stretch
-    #if handi['auto_stretch'] == 0.0:
-    #    uarm['stretch_length'] = handi['stretch_length']
-    #else:
-    #    diff = (uarmi.vector.length + farmi.vector.length) / (uarm.vector.length + farm.vector.length)
-    #    uarm['stretch_length'] *= diff
+    if 'auto_stretch' in handi.keys():
+        # Stretch
+        if handi['auto_stretch'] == 0.0:
+            uarm['stretch_length'] = handi['stretch_length']
+        else:
+            diff = (uarmi.vector.length + farmi.vector.length) / (uarm.vector.length + farm.vector.length)
+            uarm['stretch_length'] *= diff
+
+        # Upper arm position
+        match_pose_rotation(uarm, uarmi)
+        match_pose_scale(uarm, uarmi)
 
-    # Upper arm position
-    match_pose_translation(uarm, uarmi)
-    match_pose_rotation(uarm, uarmi)
-    match_pose_scale(uarm, uarmi)
+        # Forearm position
+        match_pose_rotation(farm, farmi)
+        match_pose_scale(farm, farmi)
+
+        # Hand position
+        match_pose_rotation(hand, handi)
+        match_pose_scale(hand, handi)
+    else:
+        # Upper arm position
+        match_pose_translation(uarm, uarmi)
+        match_pose_rotation(uarm, uarmi)
+        match_pose_scale(uarm, uarmi)
 
-    # Forearm position
-    #match_pose_translation(hand, handi)
-    match_pose_rotation(farm, farmi)
-    match_pose_scale(farm, farmi)
+        # Forearm position
+        #match_pose_translation(hand, handi)
+        match_pose_rotation(farm, farmi)
+        match_pose_scale(farm, farmi)
 
-    # Hand position
-    match_pose_translation(hand, handi)
-    match_pose_rotation(hand, handi)
-    match_pose_scale(hand, handi)
+        # Hand position
+        match_pose_translation(hand, handi)
+        match_pose_rotation(hand, handi)
+        match_pose_scale(hand, handi)
 
 
 def ik2fk_arm(obj, fk, ik):
@@ -344,38 +357,37 @@ def ik2fk_arm(obj, fk, ik):
     uarmi = obj.pose.bones[ik[0]]
     farmi = obj.pose.bones[ik[1]]
     handi = obj.pose.bones[ik[2]]
-    #pole  = obj.pose.bones[ik[3]]
-
-    # Stretch
-    #handi['stretch_length'] = uarm['stretch_length']
+    if ik[3] != "":
+        pole  = obj.pose.bones[ik[3]]
+    else:
+        pole = None
 
-    # Hand position
-    match_pose_translation(handi, hand)
-    match_pose_rotation(handi, hand)
-    match_pose_scale(handi, hand)
 
-    # Upper Arm position
-    match_pose_translation(uarmi, uarm)
-    match_pose_rotation(uarmi, uarm)
-    match_pose_scale(uarmi, uarm)
+    if pole:
+        # Stretch
+        handi['stretch_length'] = uarm['stretch_length']
 
-    # Rotation Correction
-    correct_rotation(uarmi, uarm)
+        # Hand position
+        match_pose_translation(handi, hand)
+        match_pose_rotation(handi, hand)
+        match_pose_scale(handi, hand)
 
+        # Pole target position
+        match_pole_target(uarmi, farmi, pole, uarm, (uarmi.length + farmi.length))
 
-#     farmi.constraints["IK"].pole_target = obj
-#     farmi.constraints["IK"].pole_subtarget = farm.name
-#     farmi.constraints["IK"].pole_angle = -1.74533
-#
-#     bpy.ops.object.mode_set(mode='POSE')
-#     bpy.ops.pose.select_all(action='DESELECT')
-#     uarmi.bone.select = True
-#     bpy.ops.pose.visual_transform_apply()
-#     farmi.constraints["IK"].pole_target = None
+    else:
+        # Hand position
+        match_pose_translation(handi, hand)
+        match_pose_rotation(handi, hand)
+        match_pose_scale(handi, hand)
 
-    # Pole target position
-    #match_pole_target(uarmi, farmi, pole, uarm, (uarmi.length + farmi.length))
+        # Upper Arm position
+        match_pose_translation(uarmi, uarm)
+        match_pose_rotation(uarmi, uarm)
+        match_pose_scale(uarmi, uarm)
 
+        # Rotation Correction
+        correct_rotation(uarmi, uarm)
 
 def fk2ik_leg(obj, fk, ik):
     """ Matches the fk bones in a leg rig to the ik bones.
@@ -392,29 +404,47 @@ def fk2ik_leg(obj, fk, ik):
     footi  = obj.pose.bones[ik[2]]
     mfooti = obj.pose.bones[ik[3]]
 
-    # Stretch
-    #if footi['auto_stretch'] == 0.0:
-    #    thigh['stretch_length'] = footi['stretch_length']
-    #else:
-    #    diff = (thighi.vector.length + shini.vector.length) / (thigh.vector.length + shin.vector.length)
-    #    thigh['stretch_length'] *= diff
-
-    # Thigh position
-    match_pose_translation(thigh, thighi)
-    match_pose_rotation(thigh, thighi)
-    match_pose_scale(thigh, thighi)
-
-    # Shin position
-    match_pose_rotation(shin, shini)
-    match_pose_scale(shin, shini)
-
-    # Foot position
-    mat = mfoot.bone.matrix_local.inverted() * foot.bone.matrix_local
-    footmat = get_pose_matrix_in_other_space(mfooti.matrix, foot) * mat
-    set_pose_rotation(foot, footmat)
-    set_pose_scale(foot, footmat)
-    bpy.ops.object.mode_set(mode='OBJECT')
-    bpy.ops.object.mode_set(mode='POSE')
+    if 'auto_stretch' in footi.keys():
+        # Stretch
+        if footi['auto_stretch'] == 0.0:
+            thigh['stretch_length'] = footi['stretch_length']
+        else:
+            diff = (thighi.vector.length + shini.vector.length) / (thigh.vector.length + shin.vector.length)
+            thigh['stretch_length'] *= diff
+
+        # Thigh position
+        match_pose_rotation(thigh, thighi)
+        match_pose_scale(thigh, thighi)
+
+        # Shin position
+        match_pose_rotation(shin, shini)
+        match_pose_scale(shin, shini)
+
+        # Foot position
+        mat = mfoot.bone.matrix_local.inverted() * foot.bone.matrix_local
+        footmat = get_pose_matrix_in_other_space(mfooti.matrix, foot) * mat
+        set_pose_rotation(foot, footmat)
+        set_pose_scale(foot, footmat)
+        bpy.ops.object.mode_set(mode='OBJECT')
+        bpy.ops.object.mode_set(mode='POSE')
+
+    else:
+        # Thigh position
+        match_pose_translation(thigh, thighi)
+        match_pose_rotation(thigh, thighi)
+        match_pose_scale(thigh, thighi)
+
+        # Shin position
+        match_pose_rotation(shin, shini)
+        match_pose_scale(shin, shini)
+
+        # Foot position
+        mat = mfoot.bone.matrix_local.inverted() * foot.bone.matrix_local
+        footmat = get_pose_matrix_in_other_space(mfooti.matrix, foot) * mat
+        set_pose_rotation(foot, footmat)
+        set_pose_scale(foot, footmat)
+        bpy.ops.object.mode_set(mode='OBJECT')
+        bpy.ops.object.mode_set(mode='POSE')
 
 
 def ik2fk_leg(obj, fk, ik):
@@ -426,51 +456,65 @@ def ik2fk_leg(obj, fk, ik):
     thigh    = obj.pose.bones[fk[0]]
     shin     = obj.pose.bones[fk[1]]
     mfoot    = obj.pose.bones[fk[2]]
+    if fk[3] != "":
+        foot      = obj.pose.bones[fk[3]]
+    else:
+        foot = None
     thighi   = obj.pose.bones[ik[0]]
     shini    = obj.pose.bones[ik[1]]
     footi    = obj.pose.bones[ik[2]]
     footroll = obj.pose.bones[ik[3]]
-    #pole     = obj.pose.bones[ik[4]]
-    #mfooti   = obj.pose.bones[ik[5]]
-    mfooti   = obj.pose.bones[ik[4]]
-    foot      = obj.pose.bones[fk[3]]
-
-    # Stretch
-    #footi['stretch_length'] = thigh['stretch_length']
-
-    # Clear footroll
-    set_pose_rotation(footroll, Matrix())
-
-    # Foot position
-    mat = mfooti.bone.matrix_local.inverted() * footi.bone.matrix_local
-    footmat = get_pose_matrix_in_other_space(foot.matrix, footi) * mat
-    set_pose_translation(footi, footmat)
-    set_pose_rotation(footi, footmat)
-    set_pose_scale(footi, footmat)
-    bpy.ops.object.mode_set(mode='OBJECT')
-    bpy.ops.object.mode_set(mode='POSE')
+    if ik[4] != "":
+        pole     = obj.pose.bones[ik[4]]
+    else:
+        pole = None
+    mfooti   = obj.pose.bones[ik[5]]
+
+    if (not pole) and (foot):
+        # Stretch
+        #footi['stretch_length'] = thigh['stretch_length']
+
+        # Clear footroll
+        set_pose_rotation(footroll, Matrix())
+
+        # Foot position
+        mat = mfooti.bone.matrix_local.inverted() * footi.bone.matrix_local
+        footmat = get_pose_matrix_in_other_space(foot.matrix, footi) * mat
+        set_pose_translation(footi, footmat)
+        set_pose_rotation(footi, footmat)
+        set_pose_scale(footi, footmat)
+        bpy.ops.object.mode_set(mode='OBJECT')
+        bpy.ops.object.mode_set(mode='POSE')
 
-    # Thigh position
-    match_pose_translation(thighi, thigh)
-    match_pose_rotation(thighi, thigh)
-    match_pose_scale(thighi, thigh)
+        # Thigh position
+        match_pose_translation(thighi, thigh)
+        match_pose_rotation(thighi, thigh)
+        match_pose_scale(thighi, thigh)
 
-    # Rotation Correction
-    correct_rotation(thighi,thigh)
+        # Rotation Correction
+        correct_rotation(thighi,thigh)
 
+        # Pole target position
+        #match_pole_target(thighi, shini, pole, thigh, (thighi.length + shini.length))
 
-#     shini.constraints["IK"].pole_target = obj
-#     shini.constraints["IK"].pole_subtarget = shin.name
-#     shini.constraints["IK"].pole_angle = -1.74533
-#
-#     bpy.ops.object.mode_set(mode='POSE')
-#     bpy.ops.pose.select_all(action='DESELECT')
-#     thighi.bone.select = True
-#     bpy.ops.pose.visual_transform_apply()
-#     shini.constraints["IK"].pole_target = None
+    else:
+        # Stretch
+        footi['stretch_length'] = thigh['stretch_length']
+
+        # Clear footroll
+        set_pose_rotation(footroll, Matrix())
+
+        # Foot position
+        mat = mfooti.bone.matrix_local.inverted() * footi.bone.matrix_local
+        footmat = get_pose_matrix_in_other_space(mfoot.matrix, footi) * mat
+        set_pose_translation(footi, footmat)
+        set_pose_rotation(footi, footmat)
+        set_pose_scale(footi, footmat)
+        bpy.ops.object.mode_set(mode='OBJECT')
+        bpy.ops.object.mode_set(mode='POSE')
 
-    # Pole target position
-    #match_pole_target(thighi, shini, pole, thigh, (thighi.length + shini.length))
+        # Pole target position
+        match_pole_ta

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list