From 6dad42d1edf7d19cc809e6afeb77944752ddd566 Mon Sep 17 00:00:00 2001
From: Benjy Cook <benjycook@hotmail.com>
Date: Mon, 17 Oct 2011 09:06:34 +0000
Subject: [PATCH] Bugfix for location retargeting and fixed some IK errors

---
 mocap/retarget.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mocap/retarget.py b/mocap/retarget.py
index 377d3f1c6..410ea0bed 100644
--- a/mocap/retarget.py
+++ b/mocap/retarget.py
@@ -263,7 +263,6 @@ def copyTranslation(performer_obj, enduser_obj, perfFeet, root, s_frame, e_frame
     # now find the plant frames, where perfFeet don't move much
 
     linearAvg = []
-
     for key in perfFeet:
         for i in range(len(locDict[key]) - 1):
             v = locDeriv(key, i)
@@ -381,12 +380,14 @@ def restoreObjMat(performer_obj, enduser_obj, perf_obj_mat, enduser_obj_mat, str
 
 #create (or return if exists) the related IK empty to the bone
 def originalLocationTarget(end_bone, enduser_obj):
-    if not end_bone.name + "IK" in enduser_obj.data.bones:
+    ik_bone = hasIKConstraint(end_bone).subtarget
+    if not ik_bone:
+        print("Adding IK bones for: " + end_bone.name)
         newBone = enduser_obj.data.edit_bones.new(end_bone.name + "IK")
         newBone.head = end_bone.tail
         newBone.tail = end_bone.tail + Vector((0, 0.1, 0))
     else:
-        newBone = enduser_obj.pose.bones[end_bone.name + "IK"]
+        newBone = enduser_obj.pose.bones[ik_bone]
     return newBone
 
 
@@ -500,6 +501,7 @@ def totalRetarget(performer_obj, enduser_obj, scene, s_frame, e_frame):
     end_arm = enduser_obj.data
     advanced = end_arm.advancedRetarget
     step = end_arm.frameStep
+    enduser_obj.animation_data_create()
 
     try:
         enduser_obj.animation_data.action = bpy.data.actions.new("temp")
-- 
GitLab