diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-19 20:19:08 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-19 20:19:08 +0400 |
commit | 9ac0a714bee5df2153e0a73bb55962139ba18eb2 (patch) | |
tree | 029104d14b7e942dd616bf8443e09d0461ac6350 /mocap | |
parent | 5e44117da5a35882e7f3919f4c48c234acebe045 (diff) |
indentation edits and copy pyrimid from contrib (where I had made some edits), removed so this wont happen again.
Diffstat (limited to 'mocap')
-rw-r--r-- | mocap/mocap_constraints.py | 10 | ||||
-rw-r--r-- | mocap/mocap_tools.py | 138 | ||||
-rw-r--r-- | mocap/retarget.py | 10 |
3 files changed, 79 insertions, 79 deletions
diff --git a/mocap/mocap_constraints.py b/mocap/mocap_constraints.py index a8d88c3a..d9f41ea1 100644 --- a/mocap/mocap_constraints.py +++ b/mocap/mocap_constraints.py @@ -363,11 +363,11 @@ def bakeAllConstraints(obj, s_frame, e_frame, bones): ik = retarget.hasIKConstraint(end_bone) cons_obj = getConsObj(end_bone) if ik: - #If it's an auto generated IK: - if ik.chain_count == 0: - selectedBones += bones # Chain len 0, bake everything - else: - selectedBones += [end_bone] + end_bone.parent_recursive[:ik.chain_count - 1] # Bake the chain + #If it's an auto generated IK: + if ik.chain_count == 0: + selectedBones += bones # Chain len 0, bake everything + else: + selectedBones += [end_bone] + end_bone.parent_recursive[:ik.chain_count - 1] # Bake the chain else: #It's either an FK bone which we should just bake #OR a user created IK target bone diff --git a/mocap/mocap_tools.py b/mocap/mocap_tools.py index 35376e0a..5d852052 100644 --- a/mocap/mocap_tools.py +++ b/mocap/mocap_tools.py @@ -631,80 +631,80 @@ def rotate_fix_armature(arm_data): #Roughly scales the performer armature to match the enduser armature #IN: perfromer_obj, enduser_obj, Blender objects whose .data is an armature. def scale_fix_armature(performer_obj, enduser_obj): - perf_bones = performer_obj.data.bones - end_bones = enduser_obj.data.bones - - 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 - factor = end_rad / perf_rad * 1.2 - performer_obj.scale *= factor + perf_bones = performer_obj.data.bones + end_bones = enduser_obj.data.bones + + 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 + factor = end_rad / perf_rad * 1.2 + performer_obj.scale *= factor #Guess Mapping #Given a performer and enduser armature, attempts to guess the hiearchy mapping 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 - #~ elif match == 1 and not perf_bone.map: - #~ oppo = perf_bones[oppositeBone(perf_bone)].map - # if oppo: - # perf_bone = oppo - 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) + 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 + #~ elif match == 1 and not perf_bone.map: + #~ oppo = perf_bones[oppositeBone(perf_bone)].map + # if oppo: + # perf_bone = oppo + 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) # Creates limit rotation constraints on the enduser armature based on range of motion (max min of fcurves) of the performer. diff --git a/mocap/retarget.py b/mocap/retarget.py index 410ea0be..d8dae356 100644 --- a/mocap/retarget.py +++ b/mocap/retarget.py @@ -76,11 +76,11 @@ def createIntermediate(performer_obj, enduser_obj, root, s_frame, e_frame, scene #Simple 1to1 retarget of a bone def singleBoneRetarget(inter_bone, perf_bone): - perf_world_rotation = perf_bone.matrix - inter_world_base_rotation = inter_bone.bone.matrix_local - inter_world_base_inv = inter_world_base_rotation.inverted() - bake_matrix = (inter_world_base_inv.to_3x3() * perf_world_rotation.to_3x3()) - return bake_matrix.to_4x4() + perf_world_rotation = perf_bone.matrix + inter_world_base_rotation = inter_bone.bone.matrix_local + inter_world_base_inv = inter_world_base_rotation.inverted() + bake_matrix = (inter_world_base_inv.to_3x3() * perf_world_rotation.to_3x3()) + return bake_matrix.to_4x4() #uses 1to1 and interpolation/averaging to match many to 1 retarget def manyPerfToSingleInterRetarget(inter_bone, performer_bones_s): |