Skip to content

Commit

Permalink
Update bone names in armature_utils.py, convertHI3PC.py, and model_ut…
Browse files Browse the repository at this point in the history
…ils.py + Hotfix OldFace models
  • Loading branch information
Melioli committed Apr 1, 2024
1 parent 49b8abc commit a966c96
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 15 deletions.
46 changes: 46 additions & 0 deletions Tools/armature_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,52 @@ def GetGameData(game):
"RFinger4": "LittleFinger1_R",
"RFinger41": "LittleFinger2_R",
"RFinger42": "LittleFinger3_R",
"RightLeg": "Right leg",
"LeftLeg": "Left leg",
"RightArm": "Right arm",
"LeftArm": "Left arm",
"RightWrist": "Right wrist",
"LeftWrist": "Left wrist",
"RightElbow": "Right elbow",
"LeftElbow": "Left elbow",
"RightShoulder": "Right shoulder",
"LeftShoulder": "Left shoulder",
"LeftKnee": "Left knee",
"RightKnee": "Right knee",
"RightAnkle": "Right ankle",
"LeftAnkle": "Left ankle",
"RightToe": "Right toe",
"LeftToe": "Left toe",
"LFinger0": "Thumb1_L",
"LFinger01": "Thumb2_L",
"LFinger02": "Thumb3_L",
"L": "IndexFinger1_L",
"L_001": "IndexFinger2_L",
"L_002": "IndexFinger3_L",
"L_003": "MiddleFinger1_L",
"L_004": "MiddleFinger2_L",
"L_005": "MiddleFinger3_L",
"L_006": "RingFinger1_L",
"L_007": "RingFinger2_L",
"L_008": "RingFinger3_L",
"L_009": "LittleFinger1_L",
"L_010": "LittleFinger2_L",
"L_011": "LittleFinger3_L",
"RFinger0": "Thumb1_R",
"RFinger01": "Thumb2_R",
"RFinger02": "Thumb3_R",
"R": "IndexFinger1_R",
"R_001": "IndexFinger2_R",
"R_002": "IndexFinger3_R",
"R_003": "MiddleFinger1_R",
"R_004": "MiddleFinger2_R",
"R_005": "MiddleFinger3_R",
"R_006": "RingFinger1_R",
"R_007": "RingFinger2_R",
"R_008": "RingFinger3_R",
"R_009": "LittleFinger1_R",
"R_010": "LittleFinger2_R",
"R_011": "LittleFinger3_R",
},
"starts_with": {
"_": "",
Expand Down
6 changes: 5 additions & 1 deletion Tools/convertHI3PC.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ def Run():
if bpy.context.scene.reconnect_armature:
ConnectArmature()
ReparentBones()
model_utils.MergeFaceByDistance("Face", ["Eyebrow", "EyeShape"], "A")
# Check if 'Face' object has shape keys
if shapekey_utils.GetShapeKey("Face", "A") is None:
model_utils.MergeFaceByDistance("Face", ["Eyebrow", "EyeShape"], "None")
else:
model_utils.MergeFaceByDistance("Face", ["Eyebrow", "EyeShape"], "A")
model_utils.MergeMeshes()

Run()
Expand Down
30 changes: 17 additions & 13 deletions Tools/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def JoinObjects(target_obj):
blender_utils.ChangeMode("OBJECT")


def MergeFaceByDistance(target_obj_name, obj_names_to_merge, shapekey_name):
def MergeFaceByDistance(target_obj_name, obj_names_to_merge, shapekey_name=None):
# Get the target object
target_obj = bpy.data.objects.get(target_obj_name)
if target_obj is None:
Expand All @@ -165,16 +165,18 @@ def MergeFaceByDistance(target_obj_name, obj_names_to_merge, shapekey_name):
# Join the selected objects into the active object
bpy.ops.object.join()

# Store the current active shape key index
current_active_shape_key_index = target_obj.active_shape_key_index
# If shapekey_name is not None and target object has shape keys, apply the shapekey
if shapekey_name is not None and target_obj.data.shape_keys is not None:
# Store the current active shape key index
current_active_shape_key_index = target_obj.active_shape_key_index

# Set the active shape key to the specified one
target_obj.active_shape_key_index = (
target_obj.data.shape_keys.key_blocks.keys().index(shapekey_name)
)
# Set the active shape key to the specified one
target_obj.active_shape_key_index = (
target_obj.data.shape_keys.key_blocks.keys().index(shapekey_name)
)

# Set the shape key value
target_obj.data.shape_keys.key_blocks[shapekey_name].value = 1.0
# Set the shape key value
target_obj.data.shape_keys.key_blocks[shapekey_name].value = 1.0

# Switch to edit mode
blender_utils.ChangeMode("EDIT")
Expand All @@ -191,11 +193,13 @@ def MergeFaceByDistance(target_obj_name, obj_names_to_merge, shapekey_name):
# Switch back to object mode
blender_utils.ChangeMode("OBJECT")

# Reset the shape key value to 0
target_obj.data.shape_keys.key_blocks[shapekey_name].value = 0
# If shapekey_name is not None and target object has shape keys, reset the shape key value and restore the active shape key index
if shapekey_name is not None and target_obj.data.shape_keys is not None:
# Reset the shape key value to 0
target_obj.data.shape_keys.key_blocks[shapekey_name].value = 0

# Restore the active shape key index
target_obj.active_shape_key_index = current_active_shape_key_index
# Restore the active shape key index
target_obj.active_shape_key_index = current_active_shape_key_index


def MergeMeshes():
Expand Down
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bl_info = {
"name": "Hoyo2VRC",
"author": "Meliodas",
"version": (3, 0, 2),
"version": (3, 0, 3),
"blender": (4, 0, 2),
"location": "3D View > Sidebar > Hoyo2VRC",
"description": "Convert Hoyoverse models to VRChat usable models.",
Expand Down

0 comments on commit a966c96

Please sign in to comment.