Created
September 7, 2017 21:14
-
-
Save cyaoeu/806ed5555960a5e84f23c4fa634a8927 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 | |
bpy.ops.object.mode_set(mode='POSE', toggle=False) | |
bpy.ops.pose.select_all(action="SELECT") | |
selbones = bpy.context.selected_pose_bones | |
targetrig = bpy.data.objects["root"] | |
ignore = ("CS_thigh","CS_calf", "CS_upperarm","CS_lowerarm","CS_LegPoletarget","CS_ElboRoll","CS_foot_l","CS_foot_r","CS_FootRoolMain","CS_hand_l","CS_hand_r","CS_thumb_all","CS_middle_All","CS_index_all","CS_pinky_All","CS_ring_All") | |
retarget = True | |
#retarget = False | |
if retarget == True: | |
for bone in selbones: | |
abort = 0 | |
for thing in ignore: | |
if bone.name.startswith(thing) == True: | |
abort = 1 | |
splitname = bone.name.split("_") | |
if len(splitname) == 4: | |
if splitname[1] == "ik": | |
fixedname = splitname[2] + "_" + splitname[3] | |
abort = 2 | |
else: | |
fixedname = splitname[1] + "_" + splitname[2] + "_" + splitname[3] | |
if len(splitname) == 3: | |
if splitname[1] == "FootMainIK": | |
fixedname = "foot" + "_" + splitname[2].lower() | |
abort = 2 | |
else: | |
fixedname = splitname[1] + "_" + splitname[2] | |
if len(splitname) == 2: | |
if splitname[1] == "neck": | |
fixedname = "neck_01" | |
else: | |
fixedname = splitname[1] | |
if len(splitname) == 1: | |
fixedname = splitname[0] | |
if fixedname == "root": | |
print("root") | |
else: | |
if abort == 1: | |
continue | |
if abort == 2: | |
nc = bone.constraints.new(type='CHILD_OF') | |
nc.influence = 1 | |
nc.target = targetrig | |
nc.subtarget = fixedname | |
nc.owner_space = "WORLD" | |
nc.target_space = "WORLD" | |
context_copy = bpy.context.copy() | |
context_copy["constraint"] = bone.constraints["Child Of"] | |
bpy.context.active_object.data.bones.active = bone.bone | |
bpy.ops.constraint.childof_set_inverse(context_copy, constraint="Child Of", owner='BONE') # set inverse - resets the root bone to original location | |
else: | |
nc = bone.constraints.new(type='COPY_TRANSFORMS') | |
nc.influence = 1 | |
nc.target = targetrig | |
nc.subtarget = fixedname | |
nc.owner_space = "WORLD" | |
nc.target_space = "WORLD" | |
else: | |
for bone in selbones: | |
for constraint in bone.constraints: | |
if constraint.type == "CHILD_OF" or constraint.type == "COPY_TRANSFORMS": | |
bone.constraints.remove(constraint) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment