From b39e20e6476492383fee5f0db99b6e96d4029c9a Mon Sep 17 00:00:00 2001 From: Yusarina Date: Sun, 3 Aug 2025 16:33:51 +0100 Subject: [PATCH] Removed hardcoded bones names --- core/dictionaries.py | 16 +++---- core/vrm_unity_converter.py | 91 +++---------------------------------- 2 files changed, 14 insertions(+), 93 deletions(-) diff --git a/core/dictionaries.py b/core/dictionaries.py index 95a7fc9..7100b34 100644 --- a/core/dictionaries.py +++ b/core/dictionaries.py @@ -285,12 +285,12 @@ bone_names.update({ 'head': bone_names['head'] + ['jbipchead', 'jhead', 'vrmhead', 'lefteye', 'righteye'], # VRM arms - both simplified patterns - 'left_shoulder': bone_names['left_shoulder'] + ['jbipllshoulder', 'jlshoulder', 'jbiplshoulder', 'leftshoulder'], + 'left_shoulder': bone_names['left_shoulder'] + ['jbipllshoulder', 'jlshoulder', 'jbiplshoulder', 'leftshoulder', 'jbipllclavicle'], 'left_arm': bone_names['left_arm'] + ['jbiplupperarm', 'jlupperarm', 'leftupperarm'], 'left_elbow': bone_names['left_elbow'] + ['jbipllforearm', 'jlforearm', 'jbipllowerarm', 'leftlowerarm'], 'left_wrist': bone_names['left_wrist'] + ['jbipllhand', 'jlhand', 'jbiplhand', 'lefthand'], - 'right_shoulder': bone_names['right_shoulder'] + ['jbiprlshoulder', 'jrshoulder', 'jbiprshoulder', 'rightshoulder'], + 'right_shoulder': bone_names['right_shoulder'] + ['jbiprlshoulder', 'jrshoulder', 'jbiprshoulder', 'rightshoulder', 'jbiprrclavicle'], 'right_arm': bone_names['right_arm'] + ['jbiprrupperarm', 'jrupperarm', 'jbiprupperarm', 'rightupperarm'], 'right_elbow': bone_names['right_elbow'] + ['jbiprrforearm', 'jrforearm', 'jbiprforearm', 'jbiprlowerarm', 'rightlowerarm'], 'right_wrist': bone_names['right_wrist'] + ['jbiprrhand', 'jrhand', 'jbiprhand', 'righthand'], @@ -314,12 +314,12 @@ bone_names.update({ 'jaw': ['jaw', 'mandible', 'lowerjaw', 'chin', 'あご', 'ik_あご'], # Breast bones - 'breast_1_l': bone_names['breast_1_l'] + ['jbipcbreast1l', 'jlbreast1'], - 'breast_2_l': bone_names['breast_2_l'] + ['jbipcbreast2l', 'jlbreast2'], - 'breast_3_l': bone_names['breast_3_l'] + ['jbipcbreast3l', 'jlbreast3'], - 'breast_1_r': bone_names['breast_1_r'] + ['jbipcbreast1r', 'jrbreast1'], - 'breast_2_r': bone_names['breast_2_r'] + ['jbipcbreast2r', 'jrbreast2'], - 'breast_3_r': bone_names['breast_3_r'] + ['jbipcbreast3r', 'jrbreast3'], + 'breast_1_l': bone_names['breast_1_l'] + ['jbipcbreast1l', 'jlbreast1', 'jseclbust1'], + 'breast_2_l': bone_names['breast_2_l'] + ['jbipcbreast2l', 'jlbreast2', 'jseclbust2'], + 'breast_3_l': bone_names['breast_3_l'] + ['jbipcbreast3l', 'jlbreast3', 'jseclbust3'], + 'breast_1_r': bone_names['breast_1_r'] + ['jbipcbreast1r', 'jrbreast1', 'jsecrbust1'], + 'breast_2_r': bone_names['breast_2_r'] + ['jbipcbreast2r', 'jrbreast2', 'jsecrbust2'], + 'breast_3_r': bone_names['breast_3_r'] + ['jbipcbreast3r', 'jrbreast3', 'jsecrbust3'], # VRM fingers - Left (including Little finger variations) 'thumb_0_l': bone_names['thumb_0_l'] + ['jbipllthumb0', 'jlthumb0', 'jbipllthumbmetacarpal', 'jlthumbmetacarpal', 'leftthumbmetacarpal'], diff --git a/core/vrm_unity_converter.py b/core/vrm_unity_converter.py index 73e6458..8d6f92e 100644 --- a/core/vrm_unity_converter.py +++ b/core/vrm_unity_converter.py @@ -85,94 +85,15 @@ def find_vrm_bones_in_armature(armature: Object) -> Dict[str, str]: def guess_unity_name_from_vrm(vrm_simplified: str) -> Optional[str]: """ - Attempt to guess Unity bone name from VRM simplified name + Attempt to guess Unity bone name from VRM simplified name using dictionary lookup """ - # Map common VRM patterns to Unity equivalents - pattern_mappings = { - 'jbipcupperchest': 'UpperChest', - 'jbipcchest': 'Chest', - 'jbipcspine': 'Spine', - 'jbipchips': 'Hips', - 'jbipcneck': 'Neck', - 'jbipchead': 'Head', + if vrm_simplified in reverse_bone_lookup: + standard_bone_key = reverse_bone_lookup[vrm_simplified] - # Left arm - 'jbipllclavicle': 'LeftShoulder', - 'jbipllshoulder': 'LeftShoulder', - 'jbiplshoulder': 'LeftShoulder', - 'jbiplupperarm': 'LeftUpperArm', - 'jbipllforearm': 'LeftLowerArm', - 'jbipllowerarm': 'LeftLowerArm', - 'jbipllhand': 'LeftHand', - 'jbiplhand': 'LeftHand', - - # Right arm (both single and double R patterns) - 'jbiprrclavicle': 'RightShoulder', - 'jbiprlshoulder': 'RightShoulder', - 'jbiprshoulder': 'RightShoulder', - 'jbiprupperarm': 'RightUpperArm', - 'jbiprrupperarm': 'RightUpperArm', - 'jbiprforearm': 'RightLowerArm', - 'jbiprrforearm': 'RightLowerArm', - 'jbiprlowerarm': 'RightLowerArm', - 'jbiprhand': 'RightHand', - 'jbiprrhand': 'RightHand', - - # Left leg - 'jbiplupperleg': 'LeftUpperLeg', - 'jbipllowerleg': 'LeftLowerLeg', - 'jbipllfoot': 'LeftFoot', - 'jbiplfoot': 'LeftFoot', - 'jbiplltoe': 'LeftToes', - 'jbipltoebase': 'LeftToes', - - # Right leg (both single and double R patterns) - 'jbiprupperleg': 'RightUpperLeg', - 'jbiprrupperleg': 'RightUpperLeg', - 'jbiprlowerleg': 'RightLowerLeg', - 'jbiprrlowerleg': 'RightLowerLeg', - 'jbiprfoot': 'RightFoot', - 'jbiprrfoot': 'RightFoot', - 'jbiprtoe': 'RightToes', - 'jbiprrtoe': 'RightToes', - 'jbiprtoebase': 'RightToes', - - # Eyes - 'jbipcleye': 'LeftEye', - 'jbipcreye': 'RightEye', - 'jadjlfaceeye': 'LeftEye', - 'jadjrfaceeye': 'RightEye', - - # Fingers - Left - 'jbiplthumb1': 'LeftThumb1', - 'jbiplthumb2': 'LeftThumb2', - 'jbiplthumb3': 'LeftThumb3', - 'jbiplindex1': 'LeftIndex1', - 'jbiplindex2': 'LeftIndex2', - 'jbiplindex3': 'LeftIndex3', - 'jbiplmiddle1': 'LeftMiddle1', - 'jbiplmiddle2': 'LeftMiddle2', - 'jbiplmiddle3': 'LeftMiddle3', - 'jbiplring1': 'LeftRing1', - 'jbiplring2': 'LeftRing2', - 'jbiplring3': 'LeftRing3', - 'jbipllittle1': 'LeftPinky1', - 'jbipllittle2': 'LeftPinky2', - 'jbipllittle3': 'LeftPinky3', - 'jbiprlittle1': 'RightPinky1', - 'jbiprlittle2': 'RightPinky2', - 'jbiprlittle3': 'RightPinky3', - - # Breast bones - 'jseclbust1': 'Breast1_L', - 'jseclbust2': 'Breast2_L', - 'jseclbust3': 'Breast3_L', - 'jsecrbust1': 'Breast1_R', - 'jsecrbust2': 'Breast2_R', - 'jsecrbust3': 'Breast3_R' - } + if standard_bone_key in standard_bones: + return standard_bones[standard_bone_key] - return pattern_mappings.get(vrm_simplified) + return None def is_vrm_collider_object(obj_name: str) -> bool: