Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fix_bone_tail(edit_bones, bone=None):
- # Recursive function to go through a bone hierarchy and move the bone tails to useful positions.
- # Requires the armature to be in edit mode because I don't want to switch between object/edit in a recursive function.
- if(len(edit_bones) == 0):
- raise W3ImporterError("Armature needs to be in edit mode for fix_bone_tail().")
- # Dictionary to help connect the bone tails to specific bone heads
- connect_dict = {
- 'l_shoulder' : 'l_bicep' ,
- 'l_bicep' : 'l_elbowRoll' ,
- 'l_elbowRoll' : 'l_hand' ,
- 'l_hand' : 'l_middle1' ,
- 'l_thigh' : 'l_shin' ,
- 'l_shin' : 'l_foot' ,
- 'l_foot' : 'l_toe' ,
- 'l_index_knuckleRoll' : 'l_index2' ,
- 'l_middle_knuckleRoll' : 'l_middle2' ,
- 'l_ring_knuckleRoll' : 'l_ring2' ,
- 'r_shoulder' : 'r_bicep' ,
- 'r_bicep' : 'r_elbowRoll' ,
- 'r_elbowRoll' : 'r_hand' ,
- 'r_hand' : 'r_middle1' ,
- 'r_thigh' : 'r_shin' ,
- 'r_shin' : 'r_foot' ,
- 'r_foot' : 'r_toe' ,
- 'r_index_knuckleRoll' : 'r_index2' ,
- 'r_middle_knuckleRoll' : 'r_middle2' ,
- 'r_ring_knuckleRoll' : 'r_ring2' ,
- 'pelvis' : 'None' ,
- 'torso' : 'torso2' ,
- 'torso2' : 'torso3' ,
- 'torso3' : 'neck' ,
- 'neck' : 'head' ,
- 'head' : 'None' ,
- 'jaw' : 'chin' ,
- 'tongue2' : 'lowwer_lip' ,
- }
- if(bone == None):
- bone=edit_bones[0]
- # If a bone is in connect_dict, just move its tail to the bone specified in the dictionary.
- if(bone.name in connect_dict):
- target = edit_bones.get(connect_dict[bone.name])
- if(target != None):
- bone.tail = target.head
- else:
- # For bones with children, we'll just connect the bone to the first child.
- if(len(bone.children) > 0):
- bone.tail = bone.children[0].head
- # For bones with no children...
- else:
- if(bone.parent != None):
- # Get the parent's head->tail vector
- parent_vec = bone.parent.tail - bone.parent.head
- # If the bone has siblings, set the scale to an arbitrary amount.
- if( len(bone.parent.children) > 1):
- scale = 0.1
- if('tongue' in bone.name): scale = 0.03
- bone.tail = bone.head + parent_vec.normalized() * scale # Todo change this number to .05 if the apply_transforms() gets fixed.
- # If no siblings, just use the parents transforms.
- else:
- bone.tail = bone.head + parent_vec
- # Special treatment for the children of some bones
- if(bone.parent.name in ['head', 'jaw']):
- bone.tail = bone.head+Vector((0, 0, .02))
- # Recursion over this bone's children.
- for c in bone.children:
- fix_bone_tail(edit_bones, c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement