Skip to content

Commit

Permalink
Merge pull request #112 from OctavoPE/main
Browse files Browse the repository at this point in the history
NPC fixes to upper body, prop bones, and root recategorizing
  • Loading branch information
michael-gh1 authored May 7, 2024
2 parents 84a82c7 + c37ebca commit 0f2753b
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 18 deletions.
Binary file modified setup_wizard/character_rig_setup/RootShape.blend
Binary file not shown.
79 changes: 66 additions & 13 deletions setup_wizard/character_rig_setup/npc_rig_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@ def move_bone(bone_name,to_layers):
bpy.ops.wm.append(filename='append_Foot', directory=path_to_file)

bpy.ops.wm.append(filename='append_Hand', directory=path_to_file)

bpy.ops.wm.append(filename='append_Props', directory=path_to_file)

this_obj = our_char

Expand Down Expand Up @@ -1056,6 +1058,11 @@ def move_bone(bone_name,to_layers):
hand_l_rig_obj = bpy.data.objects.get("handrig-L")
if hand_l_rig_obj:
hand_l_rig_obj.select_set(True)

# Select prop rig
prop_rig_obj = bpy.data.objects.get("prop-rig")
if prop_rig_obj:
prop_rig_obj.select_set(True)

# Select char armature
if our_char:
Expand Down Expand Up @@ -1164,13 +1171,18 @@ def project_line_in_space(points1, points2, axis):
armature.edit_bones['MCH-upper_arm_ik_target.L'].parent = armature.edit_bones['mch-hand-ik-wrist-L']
armature.edit_bones['MCH-upper_arm_ik_target.R'].parent = armature.edit_bones['mch-hand-ik-wrist-R']


armature.edit_bones['shoulder_driver.L'].parent = armature.edit_bones['ORG-spine.002']
armature.edit_bones['shoulder_driver.R'].parent = armature.edit_bones['ORG-spine.002']
armature.edit_bones['MCH-shoulder_follow.L'].parent = armature.edit_bones['ORG-spine.002']
armature.edit_bones['MCH-shoulder_follow.R'].parent = armature.edit_bones['ORG-spine.002']
# on NPC's only, org spine 003 is missing, so shoulders act weird. instead try parenting to def spine 002
armature.edit_bones['shoulder_driver.L'].parent = armature.edit_bones['DEF-spine.002']
armature.edit_bones['shoulder_driver.R'].parent = armature.edit_bones['DEF-spine.002']
armature.edit_bones['MCH-shoulder_follow.L'].parent = armature.edit_bones['DEF-spine.002']
armature.edit_bones['MCH-shoulder_follow.R'].parent = armature.edit_bones['DEF-spine.002']
armature.edit_bones['shoulder.L'].parent = armature.edit_bones['MCH-shoulder_follow.L']
armature.edit_bones['shoulder.R'].parent = armature.edit_bones['MCH-shoulder_follow.R']
armature.edit_bones['shoulder.R'].parent = armature.edit_bones['MCH-shoulder_follow.R']
armature.edit_bones['ORG-shoulder.L'].parent = armature.edit_bones['DEF-spine.002']
armature.edit_bones['ORG-shoulder.R'].parent = armature.edit_bones['DEF-spine.002']



# RENAME imported bones
rename_bones_list = [("root", "root.002")]
rename_bones_list.append(("root-inner", "root.001"))
Expand Down Expand Up @@ -1349,7 +1361,9 @@ def project_line_in_space(points1, points2, axis):
armature.edit_bones['MCH-shoulder_follow.L'].tail = armature.edit_bones['shoulder.L'].tail.copy()

armature.edit_bones['MCH-shoulder_follow.R'].head = armature.edit_bones['shoulder.R'].head.copy()
armature.edit_bones['MCH-shoulder_follow.R'].tail = armature.edit_bones['shoulder.R'].tail.copy()
armature.edit_bones['MCH-shoulder_follow.R'].tail = armature.edit_bones['shoulder.R'].tail.copy()



try:
armature.edit_bones["DEF-eye.L"].name = "+EyeBone L A01"
Expand Down Expand Up @@ -1471,6 +1485,11 @@ def del_bone(bone_name):
to_del_coll = bpy.data.collections.get("wgt.005")
for obj in to_del_coll.objects:
move_into_collection(obj.name,"wgt")

# props
to_del_coll = bpy.data.collections.get("wgt.006")
for obj in to_del_coll.objects:
move_into_collection(obj.name,"wgt")

# After moving into collection, delete the old empty ones.
bpy.data.collections.remove(bpy.data.collections.get("append_Root"),do_unlink=True)
Expand All @@ -1479,6 +1498,7 @@ def del_bone(bone_name):
bpy.data.collections.remove(bpy.data.collections.get("append_Pelvis"),do_unlink=True)
bpy.data.collections.remove(bpy.data.collections.get("append_Foot"),do_unlink=True)
bpy.data.collections.remove(bpy.data.collections.get("append_Hand"),do_unlink=True)
bpy.data.collections.remove(bpy.data.collections.get("append_Props"),do_unlink=True)

# Adding Shape Key Drivers
ourRig = char_name
Expand Down Expand Up @@ -1790,6 +1810,7 @@ def assign_bone_to_group(bone_name, group_name):
assign_bone_to_group("hand-ik-L", "Limbs L")
assign_bone_to_group("upper_arm_parent.L", "Limbs L")
assign_bone_to_group("forearm_tweak-pin.L", "Limbs L")
assign_bone_to_group("prop.L", "Limbs L")
if not use_arm_ik_poles:
assign_bone_to_group("upper_arm_ik.L", "Limbs L")

Expand All @@ -1801,6 +1822,7 @@ def assign_bone_to_group(bone_name, group_name):
assign_bone_to_group("hand-ik-R", "Limbs R")
assign_bone_to_group("upper_arm_parent.R", "Limbs R")
assign_bone_to_group("forearm_tweak-pin.R", "Limbs R")
assign_bone_to_group("prop.R", "Limbs R")
if not use_arm_ik_poles:
assign_bone_to_group("upper_arm_ik.R", "Limbs R")

Expand Down Expand Up @@ -2013,9 +2035,33 @@ def nuke_old_torso_const():
depsgraph.update()

# Toggle the constraint off, we HAVE to reenable it later to work!!
new.enabled = False
new.enabled = False
# We have to nuke the existing driver in the torso.

def remake_spine_constraint(bone, target):
const = this_obj.pose.bones[bone].constraints
to_del = [c for c in const]
for c in to_del:
const.remove(c)

new = const.new('COPY_TRANSFORMS')
new.name = 'Copy Transforms'
# add target
#new.targets.new()
new.target = bpy.data.objects[char_name]
new.subtarget = target

new.target_space = "LOCAL"
new.owner_space = "LOCAL"

new.influence = 0.5

# Toggle the constraint off, we HAVE to reenable it later to work!!
new.enabled = False

nuke_old_torso_const()
remake_spine_constraint("MCH-spine.002","chest")
remake_spine_constraint("MCH-pivot","spine_fk.001")

# Use this to swap a variable in a constraint
def swap_const_follow_in_const(bone, constraint_type, new_var):
Expand Down Expand Up @@ -2050,6 +2096,7 @@ def swap_const_follow_in_const(bone, constraint_type, new_var):
collections.new("Tweaks")
collections.new("Pivots & Pins")
collections.new("Offsets")
collections.new("Props")
collections.new("Face")
collections.new("Torso (IK)")
collections.new("Torso (FK)")
Expand Down Expand Up @@ -2114,6 +2161,8 @@ def swap_const_follow_in_const(bone, constraint_type, new_var):
this_obj.pose.bones["MCH-shin_tweak-pin.parent.L"].constraints[0].enabled = True
this_obj.pose.bones["MCH-shin_tweak-pin.parent.R"].constraints[0].enabled = True
this_obj.pose.bones["MCH-torso.parent"].constraints[0].enabled = True
this_obj.pose.bones["MCH-spine.002"].constraints[0].enabled = True
this_obj.pose.bones["MCH-pivot"].constraints[0].enabled = True
# Deselect everything, we're done.
for bone in bpy.context.active_object.pose.bones:
bone.bone.select = False
Expand All @@ -2125,7 +2174,7 @@ def swap_const_follow_in_const(bone, constraint_type, new_var):
rig_text = rig_file.as_string()
complete_rig_text = rig_text
# My disclaimer, out of respect for modifying Rigify core's script
rig_text_disclaimer = "\n# This RigUI script has been modified by Llama for use with Genshin Impact characters using a custom made rig. Any issues arising as a result of these modifications are my own fault and are not indicitive of Rigify's original functionalities. \n# Rigify's writers bare no responsibility for issues/errors made here. Additionally, these modifications have been made for the sole reason of improving the custom made rigs for Genshin Impact characters, meaning that\n# attempting to use this script elsewhere for characters/models/skeletons it was NOT intended to be used with, could yield improper or erroneous results - of which neither Rigify's development team nor I, am responsible for. \n\n# Otherwise, if you are seeing this disclaimer with a Genshin Impact character made with the proper addons, run this as needed. (Such as after appending to build the rig layers)\n# Do NOT however, attempt to use this rig in another version of blender than what it was made in. (3.6.X rigs will NOT work adequately in 4.X or beyond; and 4.X rigs will not work in previous versions before 4.0)\n"
rig_text_disclaimer = "\n# This RigUI script has been modified by Llama for use with Genshin Impact characters using a custom made rig. Any issues arising as a result of these modifications are not indicitive of Rigify's original functionalities. \n# Rigify's writers bare no responsibility for issues/errors made here. Additionally, these modifications have been made to improve the custom made rigs for Genshin Impact characters, meaning that\n# attempting to use this script elsewhere for characters/models/skeletons it was NOT intended to be used with, could yield improper or erroneous results - of which neither Rigify's development team nor I, am responsible for. \n\n# Otherwise, if you are seeing this disclaimer with a Hoyoverse character made with the proper addons, run this as needed. (Such as after appending to build the rig layers)\n# Do NOT however, attempt to use this rig in another version of blender than what it was made in. (3.6.X rigs will NOT work adequately in 4.X or beyond; and 4.X rigs will not work in previous versions before 4.0)\n"

# MODIFICATIONS to the text file are made here:
# Get the ID of this char's rig ui script.
Expand All @@ -2141,7 +2190,7 @@ def make_layer_str(text, layer, version):
return string3

def layers_to_generate(vers):
str = "\n row=col.row()\n "+make_layer_str("Tweaks", 2, vers)+"\n row=col.row()\n "+make_layer_str("Pivots & Pins", 19, vers)+"\n row = col.row()\n "+make_layer_str("Offsets", 26, vers)+"\n row = col.row()\n row.separator()\n row = col.row()\n row.separator()\n row = col.row()\n "+make_layer_str("Face", 0, vers)+"\n row = col.row()\n "+make_layer_str("Torso (IK)", 3, vers)+"\n row = col.row()\n "+make_layer_str("Torso (FK)",4,vers)+"\n row = col.row()\n "+make_layer_str("Fingers", 5, vers)+"\n row = col.row()\n "+make_layer_str("Fingers (Detail)", 6, vers)+"\n row = col.row()\n "+make_layer_str("Arm.L (IK)", 7, vers)+"\n "+make_layer_str("Arm.R (IK)", 10, vers)+"\n row = col.row()\n "+make_layer_str("Arm.L (FK)", 8, vers)+"\n "+make_layer_str("Arm.R (FK)", 11, vers)+"\n row = col.row()\n "+make_layer_str("Leg.L (IK)", 13, vers)+"\n "+make_layer_str("Leg.R (IK)", 16, vers)+"\n row = col.row()\n "+make_layer_str("Leg.L (FK)", 14, vers)+"\n "+make_layer_str("Leg.R (FK)", 17, vers)+"\n row = col.row()\n row.separator()\n row = col.row()\n row.separator()\n row = col.row()\n "+make_layer_str("Root", 28, vers)+"\n row = col.row()\n "+make_layer_str("Other", 25, vers)
str = "\n row=col.row()\n "+make_layer_str("Tweaks", 2, vers)+"\n row=col.row()\n "+make_layer_str("Pivots & Pins", 19, vers)+"\n row = col.row()\n "+make_layer_str("Offsets", 26, vers)+"\n row = col.row()\n "+make_layer_str("Props", 21, vers)+"\n row = col.row()\n row.separator()\n row = col.row()\n row.separator()\n row = col.row()\n "+make_layer_str("Face", 0, vers)+"\n row = col.row()\n "+make_layer_str("Torso (IK)", 3, vers)+"\n row = col.row()\n "+make_layer_str("Torso (FK)",4,vers)+"\n row = col.row()\n "+make_layer_str("Fingers", 5, vers)+"\n row = col.row()\n "+make_layer_str("Fingers (Detail)", 6, vers)+"\n row = col.row()\n "+make_layer_str("Arm.L (IK)", 7, vers)+"\n "+make_layer_str("Arm.R (IK)", 10, vers)+"\n row = col.row()\n "+make_layer_str("Arm.L (FK)", 8, vers)+"\n "+make_layer_str("Arm.R (FK)", 11, vers)+"\n row = col.row()\n "+make_layer_str("Leg.L (IK)", 13, vers)+"\n "+make_layer_str("Leg.R (IK)", 16, vers)+"\n row = col.row()\n "+make_layer_str("Leg.L (FK)", 14, vers)+"\n "+make_layer_str("Leg.R (FK)", 17, vers)+"\n row = col.row()\n row.separator()\n row = col.row()\n row.separator()\n row = col.row()\n "+make_layer_str("Root", 28, vers)+"\n row = col.row()\n "+make_layer_str("Other", 25, vers)

return str

Expand Down Expand Up @@ -2244,6 +2293,7 @@ def splice_into_text(divider, text):
bpy.context.object.data.layers[14] = False
bpy.context.object.data.layers[16] = True
bpy.context.object.data.layers[17] = False
bpy.context.object.data.layers[21] = True
bpy.context.object.data.layers[28] = True
bpy.context.object.data.layers[26] = True
else:
Expand Down Expand Up @@ -2309,7 +2359,7 @@ def bone_to_layer(bone, layer, collection, second_coll="None"):
if use_head_tracker:
bone_to_layer("head-controller", 0, "Face")
else:
bone_to_layer("head-controller", 25, "Other")
bone_to_layer("head-controller", 25, "Other")
bone_to_layer("eyetrack_L", 0, "Face")
bone_to_layer("eyetrack_R", 0, "Face")

Expand Down Expand Up @@ -2449,8 +2499,8 @@ def fast_bone_move(bone_list, layer, collection):
fast_bone_move(send_to_pivots, 19, "Pivots & Pins")

bone_to_layer("root.002", 28, "Root")
bone_to_layer("root.001", 28, "Root")
bone_to_layer("root", 28, "Root")
bone_to_layer("root.001", 26, "Offsets")
bone_to_layer("root", 26, "Offsets")

bone_to_layer("hand_ik.L",7,"Arm.L (IK)")
bone_to_layer("hand_ik_wrist.L",26,"Offsets")
Expand Down Expand Up @@ -2499,6 +2549,9 @@ def fast_bone_move(bone_list, layer, collection):
#npc, move invis bones away
bone_to_layer("WinkA-Invis", 25, "Other")
bone_to_layer("WinkB-Invis", 25, "Other")

bone_to_layer("prop.L", 21, "Props")
bone_to_layer("prop.R", 21, "Props")

# MOVING OF BONES END -------------------------------
def setup_neck_and_head_follow(neck_follow_value, head_follow_value):
Expand Down
Loading

0 comments on commit 0f2753b

Please sign in to comment.