Skip to content
Snippets Groups Projects
Commit 51e18ead authored by Lucio Rossi's avatar Lucio Rossi
Browse files

Fix on fk/ik snap operators and functions. In rig_ui_pitchipoy_template,...

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.
parent f5401b5a
No related branches found
No related tags found
No related merge requests found
...@@ -309,27 +309,40 @@ def fk2ik_arm(obj, fk, ik): ...@@ -309,27 +309,40 @@ def fk2ik_arm(obj, fk, ik):
farmi = obj.pose.bones[ik[1]] farmi = obj.pose.bones[ik[1]]
handi = obj.pose.bones[ik[2]] handi = obj.pose.bones[ik[2]]
# Stretch if 'auto_stretch' in handi.keys():
#if handi['auto_stretch'] == 0.0: # Stretch
# uarm['stretch_length'] = handi['stretch_length'] if handi['auto_stretch'] == 0.0:
#else: uarm['stretch_length'] = handi['stretch_length']
# diff = (uarmi.vector.length + farmi.vector.length) / (uarm.vector.length + farm.vector.length) else:
# uarm['stretch_length'] *= diff 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 # Forearm position
match_pose_translation(uarm, uarmi) match_pose_rotation(farm, farmi)
match_pose_rotation(uarm, uarmi) match_pose_scale(farm, farmi)
match_pose_scale(uarm, uarmi)
# 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 # Forearm position
#match_pose_translation(hand, handi) #match_pose_translation(hand, handi)
match_pose_rotation(farm, farmi) match_pose_rotation(farm, farmi)
match_pose_scale(farm, farmi) match_pose_scale(farm, farmi)
# Hand position # Hand position
match_pose_translation(hand, handi) match_pose_translation(hand, handi)
match_pose_rotation(hand, handi) match_pose_rotation(hand, handi)
match_pose_scale(hand, handi) match_pose_scale(hand, handi)
def ik2fk_arm(obj, fk, ik): def ik2fk_arm(obj, fk, ik):
...@@ -344,38 +357,37 @@ def ik2fk_arm(obj, fk, ik): ...@@ -344,38 +357,37 @@ def ik2fk_arm(obj, fk, ik):
uarmi = obj.pose.bones[ik[0]] uarmi = obj.pose.bones[ik[0]]
farmi = obj.pose.bones[ik[1]] farmi = obj.pose.bones[ik[1]]
handi = obj.pose.bones[ik[2]] handi = obj.pose.bones[ik[2]]
#pole = obj.pose.bones[ik[3]] if ik[3] != "":
pole = obj.pose.bones[ik[3]]
# Stretch else:
#handi['stretch_length'] = uarm['stretch_length'] pole = None
# Hand position
match_pose_translation(handi, hand)
match_pose_rotation(handi, hand)
match_pose_scale(handi, hand)
# Upper Arm position if pole:
match_pose_translation(uarmi, uarm) # Stretch
match_pose_rotation(uarmi, uarm) handi['stretch_length'] = uarm['stretch_length']
match_pose_scale(uarmi, uarm)
# Rotation Correction # Hand position
correct_rotation(uarmi, uarm) 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 else:
# farmi.constraints["IK"].pole_subtarget = farm.name # Hand position
# farmi.constraints["IK"].pole_angle = -1.74533 match_pose_translation(handi, hand)
# match_pose_rotation(handi, hand)
# bpy.ops.object.mode_set(mode='POSE') match_pose_scale(handi, hand)
# bpy.ops.pose.select_all(action='DESELECT')
# uarmi.bone.select = True
# bpy.ops.pose.visual_transform_apply()
# farmi.constraints["IK"].pole_target = None
# Pole target position # Upper Arm position
#match_pole_target(uarmi, farmi, pole, uarm, (uarmi.length + farmi.length)) 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): def fk2ik_leg(obj, fk, ik):
""" Matches the fk bones in a leg rig to the ik bones. """ Matches the fk bones in a leg rig to the ik bones.
...@@ -392,29 +404,47 @@ def fk2ik_leg(obj, fk, ik): ...@@ -392,29 +404,47 @@ def fk2ik_leg(obj, fk, ik):
footi = obj.pose.bones[ik[2]] footi = obj.pose.bones[ik[2]]
mfooti = obj.pose.bones[ik[3]] mfooti = obj.pose.bones[ik[3]]
# Stretch if 'auto_stretch' in footi.keys():
#if footi['auto_stretch'] == 0.0: # Stretch
# thigh['stretch_length'] = footi['stretch_length'] if footi['auto_stretch'] == 0.0:
#else: thigh['stretch_length'] = footi['stretch_length']
# diff = (thighi.vector.length + shini.vector.length) / (thigh.vector.length + shin.vector.length) else:
# thigh['stretch_length'] *= diff diff = (thighi.vector.length + shini.vector.length) / (thigh.vector.length + shin.vector.length)
thigh['stretch_length'] *= diff
# Thigh position
match_pose_translation(thigh, thighi) # Thigh position
match_pose_rotation(thigh, thighi) match_pose_rotation(thigh, thighi)
match_pose_scale(thigh, thighi) match_pose_scale(thigh, thighi)
# Shin position # Shin position
match_pose_rotation(shin, shini) match_pose_rotation(shin, shini)
match_pose_scale(shin, shini) match_pose_scale(shin, shini)
# Foot position # Foot position
mat = mfoot.bone.matrix_local.inverted() * foot.bone.matrix_local mat = mfoot.bone.matrix_local.inverted() * foot.bone.matrix_local
footmat = get_pose_matrix_in_other_space(mfooti.matrix, foot) * mat footmat = get_pose_matrix_in_other_space(mfooti.matrix, foot) * mat
set_pose_rotation(foot, footmat) set_pose_rotation(foot, footmat)
set_pose_scale(foot, footmat) set_pose_scale(foot, footmat)
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='POSE') 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): def ik2fk_leg(obj, fk, ik):
...@@ -426,51 +456,65 @@ def ik2fk_leg(obj, fk, ik): ...@@ -426,51 +456,65 @@ def ik2fk_leg(obj, fk, ik):
thigh = obj.pose.bones[fk[0]] thigh = obj.pose.bones[fk[0]]
shin = obj.pose.bones[fk[1]] shin = obj.pose.bones[fk[1]]
mfoot = obj.pose.bones[fk[2]] mfoot = obj.pose.bones[fk[2]]
if fk[3] != "":
foot = obj.pose.bones[fk[3]]
else:
foot = None
thighi = obj.pose.bones[ik[0]] thighi = obj.pose.bones[ik[0]]
shini = obj.pose.bones[ik[1]] shini = obj.pose.bones[ik[1]]
footi = obj.pose.bones[ik[2]] footi = obj.pose.bones[ik[2]]
footroll = obj.pose.bones[ik[3]] footroll = obj.pose.bones[ik[3]]
#pole = obj.pose.bones[ik[4]] if ik[4] != "":
#mfooti = obj.pose.bones[ik[5]] pole = obj.pose.bones[ik[4]]
mfooti = obj.pose.bones[ik[4]] else:
foot = obj.pose.bones[fk[3]] pole = None
mfooti = obj.pose.bones[ik[5]]
# Stretch
#footi['stretch_length'] = thigh['stretch_length'] if (not pole) and (foot):
# Stretch
# Clear footroll #footi['stretch_length'] = thigh['stretch_length']
set_pose_rotation(footroll, Matrix())
# Clear footroll
# Foot position set_pose_rotation(footroll, Matrix())
mat = mfooti.bone.matrix_local.inverted() * footi.bone.matrix_local
footmat = get_pose_matrix_in_other_space(foot.matrix, footi) * mat # Foot position
set_pose_translation(footi, footmat) mat = mfooti.bone.matrix_local.inverted() * footi.bone.matrix_local
set_pose_rotation(footi, footmat) footmat = get_pose_matrix_in_other_space(foot.matrix, footi) * mat
set_pose_scale(footi, footmat) set_pose_translation(footi, footmat)
bpy.ops.object.mode_set(mode='OBJECT') set_pose_rotation(footi, footmat)
bpy.ops.object.mode_set(mode='POSE') set_pose_scale(footi, footmat)
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='POSE')
# Thigh position # Thigh position
match_pose_translation(thighi, thigh) match_pose_translation(thighi, thigh)
match_pose_rotation(thighi, thigh) match_pose_rotation(thighi, thigh)
match_pose_scale(thighi, thigh) match_pose_scale(thighi, thigh)
# Rotation Correction # Rotation Correction
correct_rotation(thighi,thigh) correct_rotation(thighi,thigh)
# Pole target position
#match_pole_target(thighi, shini, pole, thigh, (thighi.length + shini.length))
# shini.constraints["IK"].pole_target = obj else:
# shini.constraints["IK"].pole_subtarget = shin.name # Stretch
# shini.constraints["IK"].pole_angle = -1.74533 footi['stretch_length'] = thigh['stretch_length']
#
# bpy.ops.object.mode_set(mode='POSE') # Clear footroll
# bpy.ops.pose.select_all(action='DESELECT') set_pose_rotation(footroll, Matrix())
# thighi.bone.select = True
# bpy.ops.pose.visual_transform_apply() # Foot position
# shini.constraints["IK"].pole_target = None 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 # Pole target position
#match_pole_target(thighi, shini, pole, thigh, (thighi.length + shini.length)) match_pole_target(thighi, shini, pole, thigh, (thighi.length + shini.length))
############################## ##############################
...@@ -520,7 +564,7 @@ class Rigify_Arm_IK2FK(bpy.types.Operator): ...@@ -520,7 +564,7 @@ class Rigify_Arm_IK2FK(bpy.types.Operator):
uarm_ik = bpy.props.StringProperty(name="Upper Arm IK Name") uarm_ik = bpy.props.StringProperty(name="Upper Arm IK Name")
farm_ik = bpy.props.StringProperty(name="Forearm IK Name") farm_ik = bpy.props.StringProperty(name="Forearm IK Name")
hand_ik = bpy.props.StringProperty(name="Hand IK Name") hand_ik = bpy.props.StringProperty(name="Hand IK Name")
#pole = bpy.props.StringProperty(name="Pole IK Name") pole = bpy.props.StringProperty(name="Pole IK Name")
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
...@@ -530,8 +574,7 @@ class Rigify_Arm_IK2FK(bpy.types.Operator): ...@@ -530,8 +574,7 @@ class Rigify_Arm_IK2FK(bpy.types.Operator):
use_global_undo = context.user_preferences.edit.use_global_undo use_global_undo = context.user_preferences.edit.use_global_undo
context.user_preferences.edit.use_global_undo = False context.user_preferences.edit.use_global_undo = False
try: try:
#ik2fk_arm(context.active_object, fk=[self.uarm_fk, self.farm_fk, self.hand_fk], ik=[self.uarm_ik, self.farm_ik, self.hand_ik, self.pole]) ik2fk_arm(context.active_object, fk=[self.uarm_fk, self.farm_fk, self.hand_fk], ik=[self.uarm_ik, self.farm_ik, self.hand_ik, self.pole])
ik2fk_arm(context.active_object, fk=[self.uarm_fk, self.farm_fk, self.hand_fk], ik=[self.uarm_ik, self.farm_ik, self.hand_ik])
finally: finally:
context.user_preferences.edit.use_global_undo = use_global_undo context.user_preferences.edit.use_global_undo = use_global_undo
return {'FINISHED'} return {'FINISHED'}
...@@ -583,7 +626,7 @@ class Rigify_Leg_IK2FK(bpy.types.Operator): ...@@ -583,7 +626,7 @@ class Rigify_Leg_IK2FK(bpy.types.Operator):
shin_ik = bpy.props.StringProperty(name="Shin IK Name") shin_ik = bpy.props.StringProperty(name="Shin IK Name")
foot_ik = bpy.props.StringProperty(name="Foot IK Name") foot_ik = bpy.props.StringProperty(name="Foot IK Name")
footroll = bpy.props.StringProperty(name="Foot Roll Name") footroll = bpy.props.StringProperty(name="Foot Roll Name")
#pole = bpy.props.StringProperty(name="Pole IK Name") pole = bpy.props.StringProperty(name="Pole IK Name")
mfoot_ik = bpy.props.StringProperty(name="MFoot IK Name") mfoot_ik = bpy.props.StringProperty(name="MFoot IK Name")
...@@ -595,8 +638,7 @@ class Rigify_Leg_IK2FK(bpy.types.Operator): ...@@ -595,8 +638,7 @@ class Rigify_Leg_IK2FK(bpy.types.Operator):
use_global_undo = context.user_preferences.edit.use_global_undo use_global_undo = context.user_preferences.edit.use_global_undo
context.user_preferences.edit.use_global_undo = False context.user_preferences.edit.use_global_undo = False
try: try:
#ik2fk_leg(context.active_object, fk=[self.thigh_fk, self.shin_fk, self.mfoot_fk], ik=[self.thigh_ik, self.shin_ik, self.foot_ik, self.footroll, self.pole, self.mfoot_ik]) ik2fk_leg(context.active_object, fk=[self.thigh_fk, self.shin_fk, self.mfoot_fk, self.foot_fk], ik=[self.thigh_ik, self.shin_ik, self.foot_ik, self.footroll, self.pole, self.mfoot_ik])
ik2fk_leg(context.active_object, fk=[self.thigh_fk, self.shin_fk, self.mfoot_fk, self.foot_fk], ik=[self.thigh_ik, self.shin_ik, self.foot_ik, self.footroll, self.mfoot_ik])
finally: finally:
context.user_preferences.edit.use_global_undo = use_global_undo context.user_preferences.edit.use_global_undo = use_global_undo
return {'FINISHED'} return {'FINISHED'}
......
...@@ -22,7 +22,7 @@ if is_selected( controls ): ...@@ -22,7 +22,7 @@ if is_selected( controls ):
props.uarm_ik = controls[0] props.uarm_ik = controls[0]
props.farm_ik = ik_ctrl[1] props.farm_ik = ik_ctrl[1]
props.hand_ik = controls[4] props.hand_ik = controls[4]
#props.pole = ik_arm[3] props.pole = ""
# BBone rubber hose on each Respective Tweak # BBone rubber hose on each Respective Tweak
...@@ -66,7 +66,7 @@ if is_selected( controls ): ...@@ -66,7 +66,7 @@ if is_selected( controls ):
props.thigh_ik = controls[0] props.thigh_ik = controls[0]
props.shin_ik = ik_ctrl[1] props.shin_ik = ik_ctrl[1]
props.foot_ik = controls[6] props.foot_ik = controls[6]
#props.pole = ik_leg[3] props.pole = ""
props.footroll = controls[5] props.footroll = controls[5]
props.mfoot_ik = ik_ctrl[2] props.mfoot_ik = ik_ctrl[2]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment