Skip to content

Commit 98ebc96

Browse files
committed
Fix Finger issues with newer models
1 parent fa7ac82 commit 98ebc96

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

Tools/armature_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,3 +1180,29 @@ def ReparentBone(armature, bone_name, parent_name):
11801180
bone.parent = parent_bone
11811181
else:
11821182
print(f"Could not find bone {bone_name} or parent bone {parent_name}")
1183+
1184+
1185+
def MergeBones(armature, bone_to_merge, parent_bone):
1186+
"""
1187+
Merges a bone into its parent by connecting the parent to the child's children
1188+
1189+
Args:
1190+
armature: The armature object
1191+
bone_to_merge: Name of the bone to be merged
1192+
parent_bone: Name of the parent bone to merge into
1193+
"""
1194+
if bone_to_merge not in armature.data.edit_bones or parent_bone not in armature.data.edit_bones:
1195+
return
1196+
1197+
bone = armature.data.edit_bones[bone_to_merge]
1198+
parent = armature.data.edit_bones[parent_bone]
1199+
1200+
# Store children of the bone to be merged
1201+
children = [child for child in bone.children]
1202+
1203+
# Reparent all children to the parent bone
1204+
for child in children:
1205+
child.parent = parent
1206+
1207+
# Remove the merged bone
1208+
armature.data.edit_bones.remove(bone)

Tools/convertWWPC.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,52 @@ def MergeEyes():
376376

377377
# Deselect all objects
378378
bpy.ops.object.select_all(action='DESELECT')
379+
380+
def FixFingers():
381+
# Make sure armature is selected and active
382+
bpy.context.view_layer.objects.active = armature
383+
armature.select_set(True)
379384

385+
# Enter edit mode first
386+
blender_utils.ChangeMode("EDIT")
387+
print("\nStarting finger renaming process...")
380388

381-
389+
# Rename thumb bones
390+
for side in ["L", "R"]:
391+
thumb1 = armature.data.edit_bones.get(f"Thumb1_{side}")
392+
thumb4 = armature.data.edit_bones.get(f"Thumb4_{side}")
393+
if thumb1 and thumb4:
394+
print(f"Renaming {thumb1.name} to Thumb_{side}")
395+
thumb1.name = f"Thumb_{side}"
396+
# Rename remaining bones up the chain
397+
for i in range(2, 5):
398+
old_name = f"Thumb{i}_{side}"
399+
new_name = f"Thumb{i-1}_{side}"
400+
if bone := armature.data.edit_bones.get(old_name):
401+
print(f"Renaming {old_name} to {new_name}")
402+
bone.name = new_name
403+
404+
# Rename finger bones
405+
finger_types = ["Index", "Middle", "Ring", "Little"]
406+
for finger in finger_types:
407+
for side in ["L", "R"]:
408+
finger1 = armature.data.edit_bones.get(f"{finger}Finger1_{side}")
409+
finger4 = armature.data.edit_bones.get(f"{finger}Finger4_{side}")
410+
if finger1 and finger4:
411+
print(f"Renaming {finger1.name} to Bone_{side}")
412+
finger1.name = f"Bone_{side}"
413+
# Rename remaining bones up the chain
414+
for i in range(2, 5):
415+
old_name = f"{finger}Finger{i}_{side}"
416+
new_name = f"{finger}Finger{i-1}_{side}"
417+
if bone := armature.data.edit_bones.get(old_name):
418+
print(f"Renaming {old_name} to {new_name}")
419+
bone.name = new_name
420+
421+
print("\nFinger renaming completed")
422+
# Return to object mode
423+
blender_utils.ChangeMode("OBJECT")
424+
382425
def Run():
383426
armature_utils.RenameBones(game, armature)
384427
armature_utils.CleanBones()
@@ -392,6 +435,7 @@ def Run():
392435
CreateEyesBones("Left Eye", "Eye_L")
393436
CreateEyesBones("Right Eye", "Eye_R")
394437
MergeEyes()
438+
FixFingers()
395439
blender_utils.ResetCursor()
396440

397441

0 commit comments

Comments
 (0)