Create centralized method for identifying bones

- also fixes an issue where VRM bones would never be identified due to the names having "_" in them.
This commit is contained in:
989onan
2025-03-31 18:28:04 -04:00
parent 08f37d3202
commit feb2f5ac85
3 changed files with 52 additions and 36 deletions
+14
View File
@@ -18,6 +18,7 @@ from bpy.utils import register_class
from ..core.logging_setup import logger
from ..core.translations import t
from ..core.dictionaries import bone_names
from .dictionaries import reverse_bone_lookup, bone_names
class ProgressTracker:
"""Universal progress tracking for Avatar Toolkit operations"""
@@ -412,6 +413,19 @@ def simplify_bonename(name: str) -> str:
"""Simplify bone name by removing spaces, underscores, dots and converting to lowercase"""
return name.lower().translate(dict.fromkeys(map(ord, u" _.")))
def identify_bones(arm_data: bpy.types.Armature, context: bpy.types.Context) -> Dict[str,str]:
"""Identify bone names in an armature based on our reverse dictionary, so there is no confusion to what a bone is.
Essentially makes a dictionary of keys from dictionaries.bone_names like "hips", and the corosponding value is the bone that can be mapped to that key."""
returned: Dict[str,str] = {}
for bone in arm_data.bones:
simplified_name = simplify_bonename(bone.name)
if simplified_name in reverse_bone_lookup:
returned[reverse_bone_lookup[simplified_name]] = bone.name
return returned
def duplicate_bone_chain(bones: List[EditBone]) -> List[EditBone]:
"""Duplicate a chain of bones while preserving hierarchy"""
new_bones: List[EditBone] = []