diff options
author | Benjy Cook <benjycook@hotmail.com> | 2011-07-21 01:03:06 +0400 |
---|---|---|
committer | Benjy Cook <benjycook@hotmail.com> | 2011-07-21 01:03:06 +0400 |
commit | a08a510d6558f203ee21eefb751752a9fa572cee (patch) | |
tree | c58071f60175ec3a38744b0d165bcba7d79d4bc7 /release/scripts/modules | |
parent | 2c61949179c042b785e5b7158b93654e492e5f12 (diff) |
Two new operators for easier retargeting: Auto scale performer, and a first attempt at auto hiearchy mapping
Diffstat (limited to 'release/scripts/modules')
-rw-r--r-- | release/scripts/modules/mocap_tools.py | 66 | ||||
-rw-r--r-- | release/scripts/modules/retarget.py | 4 |
2 files changed, 65 insertions, 5 deletions
diff --git a/release/scripts/modules/mocap_tools.py b/release/scripts/modules/mocap_tools.py index 1ce76dfbe6f..ed945d45251 100644 --- a/release/scripts/modules/mocap_tools.py +++ b/release/scripts/modules/mocap_tools.py @@ -573,7 +573,67 @@ def scale_fix_armature(performer_obj, enduser_obj): perf_bones = performer_obj.data.bones end_bones = enduser_obj.data.bones - #perf_avg = performer_obj.dimensions + def calculateBoundingRadius(bones): + center = Vector() + for bone in bones: + center += bone.head_local + center /= len(bones) + radius = 0 + for bone in bones: + dist = (bone.head_local - center).length + if dist > radius: + radius = dist + return radius + + perf_rad = calculateBoundingRadius(performer_obj.data.bones) + end_rad = calculateBoundingRadius(enduser_obj.data.bones) #end_avg = enduser_obj.dimensions - #print(perf_avg, end_avg) - #performer_obj.scale /= (perf_avg / end_avg) + factor = end_rad / perf_rad * 1.2 + performer_obj.scale *= factor + + +def guessMapping(performer_obj, enduser_obj): + perf_bones = performer_obj.data.bones + end_bones = enduser_obj.data.bones + + root = perf_bones[0] + + def findBoneSide(bone): + if "Left" in bone: + return "Left", bone.replace("Left", "").lower().replace(".", "") + if "Right" in bone: + return "Right", bone.replace("Right", "").lower().replace(".", "") + if "L" in bone: + return "Left", bone.replace("Left", "").lower().replace(".", "") + if "R" in bone: + return "Right", bone.replace("Right", "").lower().replace(".", "") + return "", bone + + def nameMatch(bone_a, bone_b): + # nameMatch - recieves two strings, returns 2 if they are relatively the same, 1 if they are the same but R and L and 0 if no match at all + side_a, noside_a = findBoneSide(bone_a) + side_b, noside_b = findBoneSide(bone_b) + if side_a == side_b: + if noside_a in noside_b or noside_b in noside_a: + return 2 + else: + if noside_a in noside_b or noside_b in noside_a: + return 1 + return 0 + + def guessSingleMapping(perf_bone): + possible_bones = [end_bones[0]] + while possible_bones: + for end_bone in possible_bones: + match = nameMatch(perf_bone.name, end_bone.name) + if match == 2 and not perf_bone.map: + perf_bone.map = end_bone.name + newPossibleBones = [] + for end_bone in possible_bones: + newPossibleBones += list(end_bone.children) + possible_bones = newPossibleBones + + for child in perf_bone.children: + guessSingleMapping(child) + + guessSingleMapping(root) diff --git a/release/scripts/modules/retarget.py b/release/scripts/modules/retarget.py index d05fd71f8ce..f4ab6498e11 100644 --- a/release/scripts/modules/retarget.py +++ b/release/scripts/modules/retarget.py @@ -143,7 +143,7 @@ def createIntermediate(performer_obj, enduser_obj, root, s_frame, e_frame, scene for t in range(s_frame, e_frame): if (t - s_frame) % 10 == 0: - print("First pass: retargeting frame {0}/{1}".format(t, e_frame - s_frame)) + print("First pass: retargeting frame {0}/{1}".format(t, e_frame - s_frame)) scene.frame_set(t) for bone in inter_bones: retargetPerfToInter(bone) @@ -202,7 +202,7 @@ def retargetEnduser(inter_obj, enduser_obj, root, s_frame, e_frame, scene): for t in range(s_frame, e_frame): if (t - s_frame) % 10 == 0: - print("Second pass: retargeting frame {0}/{1}".format(t, e_frame - s_frame)) + print("Second pass: retargeting frame {0}/{1}".format(t, e_frame - s_frame)) scene.frame_set(t) end_bone = end_bones[root] end_bone.location = Vector((0, 0, 0)) |