Fixed issue where some bones was not being renamed

This commit is contained in:
Yusarina
2025-08-01 12:01:22 +01:00
parent 6f5e7a394d
commit 8c2c52f882
2 changed files with 33 additions and 40 deletions
+17 -24
View File
@@ -13,7 +13,9 @@ from ...core.dictionaries import (
bone_hierarchy,
acceptable_bone_names,
acceptable_bone_hierarchy,
non_standard_mappings
non_standard_mappings,
reverse_bone_lookup,
simplify_bonename
)
class AvatarToolkit_OT_StandardizeArmature(Operator):
@@ -134,17 +136,14 @@ class AvatarToolkit_OT_StandardizeArmature(Operator):
existing_standard_bones.add(bone.name)
logger.debug(f"Found existing standard bone: {bone.name}")
# Build a mapping of non-standard bone names to standard names
# Use the reverse bone lookup that's already built and simplified
name_mapping: Dict[str, str] = {}
for category, standard_name in standard_bones.items():
# Skip if this standard bone already exists
if standard_name in existing_standard_bones:
continue
# Get all variants for this category
if category in non_standard_mappings:
for variant in non_standard_mappings[category]:
name_mapping[variant.lower()] = standard_name
for simplified_name, category in reverse_bone_lookup.items():
if category in standard_bones:
standard_name = standard_bones[category]
# Skip if this standard bone already exists
if standard_name not in existing_standard_bones:
name_mapping[simplified_name] = standard_name
# First pass: identify bones to rename
bones_to_rename: Dict[str, str] = {}
@@ -155,20 +154,14 @@ class AvatarToolkit_OT_StandardizeArmature(Operator):
if original_name in standard_bones.values():
continue
simplified_name: str = original_name.lower().replace(' ', '').replace('_', '').replace('.', '')
simplified_name: str = simplify_bonename(original_name)
# Check if this bone matches any known pattern
for variant, standard_name in name_mapping.items():
# More precise matching - exact match or with common separators
if (variant == simplified_name or
variant == original_name.lower() or
f"{variant}_" in simplified_name or
f"{variant}." in simplified_name):
if original_name != standard_name:
bones_to_rename[original_name] = standard_name
logger.debug(f"Identified bone to rename: {original_name} -> {standard_name}")
break
# Check if this simplified bone name has a standard mapping
if simplified_name in name_mapping:
standard_name = name_mapping[simplified_name]
if original_name != standard_name:
bones_to_rename[original_name] = standard_name
logger.debug(f"Identified bone to rename: {original_name} -> {standard_name}")
# Special case for spine/chest hierarchy
# If we don't have an upper chest, don't rename chest to upper chest because it will break hierarchy