Created
May 7, 2020 11:05
-
-
Save xDShot/63faa5ddc63474d89bab2c1a364b0f98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
side_identifier = "_X_" | |
finger_identifier = "_FingerN" | |
chainlinks = {} | |
chainlinks["body"] = ( "ValveBiped.Bip01", "ValveBiped.Bip01_Pelvis", "ValveBiped.Bip01_Spine", "ValveBiped.Bip01_Spine1", "ValveBiped.Bip01_Spine2", "ValveBiped.Bip01_Spine4" ) | |
chainlinks["arms"] = ( "ValveBiped.Bip01_X_Clavicle", "ValveBiped.Bip01_X_UpperArm", "ValveBiped.Bip01_X_Forearm", "ValveBiped.Bip01_X_Hand" ) | |
chainlinks["fingers"] = ( "ValveBiped.Bip01_X_FingerN", "ValveBiped.Bip01_X_FingerN1", "ValveBiped.Bip01_X_FingerN2" ) | |
# TODO: legs, pelvis+neck+head | |
obj = bpy.context.selected_objects[0] | |
bones = obj.data.edit_bones | |
def this_thing_doesnt_exist(str): | |
print( str, "not in hiearchy" ) | |
def make_connected_chaintuple(tuple_obj, side="", fingernum=0): | |
tuple_len = len(tuple_obj) | |
chainboneslist = [] | |
for chainbonenum in range(0, tuple_len): | |
bonename = tuple_obj[ chainbonenum ] | |
bonename = bonename.replace( side_identifier, side ).replace( finger_identifier, "_Finger" + str(fingernum) ) | |
if bonename in bones: | |
chainboneslist.append( bonename ) | |
print(chainbonenum, tuple_obj[ chainbonenum ], bonename) | |
else: | |
this_thing_doesnt_exist(bonename) | |
print(tuple_obj,chainboneslist) | |
list_len = len( chainboneslist ) | |
for chainbonenum in range(0, list_len-1): | |
curbone = bones[ chainboneslist[ chainbonenum ] ] | |
nextbone = bones[ chainboneslist[ chainbonenum+1 ] ] | |
endpos = nextbone.head | |
curbone.tail = endpos | |
nextbone.use_connect = True | |
curbone = bones[ chainboneslist[ list_len-1 ] ] | |
curbone.length = bones[ chainboneslist[ list_len-2 ] ].length | |
def make_connected_chain(): | |
make_connected_chaintuple( chainlinks["body"] ) | |
for side in ("_L_", "_R_"): | |
make_connected_chaintuple( chainlinks["arms"], side ) | |
for fingernum in range(0,5): | |
make_connected_chaintuple( chainlinks["fingers"], side, fingernum ) | |
make_connected_chain() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment