Conversation Complete

- This now removes bones which are not needed for Unity.
- Renamed the armature to armature.
This commit is contained in:
Yusarina
2025-02-07 15:27:48 +00:00
parent 1333b4d2d4
commit 251c006498
2 changed files with 35 additions and 13 deletions
+20 -1
View File
@@ -403,4 +403,23 @@ rigify_basic_unity_names = {
"shin.R": "RightLowerLeg", "shin.R": "RightLowerLeg",
"foot.R": "RightFoot", "foot.R": "RightFoot",
"toe.R": "RightToes" "toe.R": "RightToes"
} }
rigify_unnecessary_bones = [
'face',
'ear.l', 'ear.r',
'forehead',
'cheek.t.l', 'cheek.t.r',
'cheek.b.l', 'cheek.b.r',
'brow.t.l', 'brow.t.r',
'brow.b.l', 'brow.b.r',
'jaw',
'chin',
'nose',
'temple.l', 'temple.r',
'teeth',
'lip',
'lid',
'heel',
'pelvis.'
]
+15 -12
View File
@@ -4,7 +4,7 @@ from bpy.types import Operator, Context, Object, PoseBone, EditBone, Bone, Const
from ...core.common import get_active_armature, validate_armature from ...core.common import get_active_armature, validate_armature
from ...core.logging_setup import logger from ...core.logging_setup import logger
from ...core.translations import t from ...core.translations import t
from ...core.dictionaries import rigify_unity_names, rigify_basic_unity_names from ...core.dictionaries import rigify_unity_names, rigify_basic_unity_names, rigify_unnecessary_bones
class AvatarToolkit_OT_ConvertRigifyToUnity(Operator): class AvatarToolkit_OT_ConvertRigifyToUnity(Operator):
"""Convert Rigify armature to Unity-compatible format""" """Convert Rigify armature to Unity-compatible format"""
@@ -18,9 +18,8 @@ class AvatarToolkit_OT_ConvertRigifyToUnity(Operator):
armature = get_active_armature(context) armature = get_active_armature(context)
if not armature: if not armature:
return False return False
valid, _ = validate_armature(armature) return ("DEF-spine" in armature.data.bones or
return valid and ("DEF-spine" in armature.data.bones or "spine" in armature.data.bones and "metarig" in armature.name.lower())
"spine" in armature.data.bones and "metarig" in armature.name.lower())
def execute(self, context: Context) -> Set[str]: def execute(self, context: Context) -> Set[str]:
try: try:
@@ -31,6 +30,10 @@ class AvatarToolkit_OT_ConvertRigifyToUnity(Operator):
logger.info("Starting Rigify to Unity conversion") logger.info("Starting Rigify to Unity conversion")
# Rename armature object to "Armature"
armature.name = "Armature"
armature.data.name = "Armature"
if "DEF-spine" in armature.data.bones: if "DEF-spine" in armature.data.bones:
self.move_def_bones(armature) self.move_def_bones(armature)
self.rename_bones_for_unity(armature) self.rename_bones_for_unity(armature)
@@ -56,17 +59,16 @@ class AvatarToolkit_OT_ConvertRigifyToUnity(Operator):
"""Remove unnecessary bones and merge neck bones""" """Remove unnecessary bones and merge neck bones"""
bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='EDIT')
# Remove heel and pelvis bones # Remove bones matching patterns from dictionary
bones_to_remove = [] bones_to_remove = []
for bone in armature.data.edit_bones: for bone in armature.data.edit_bones:
if ('heel' in bone.name.lower() or if any(pattern in bone.name.lower() for pattern in rigify_unnecessary_bones):
'pelvis.' in bone.name.lower()):
bones_to_remove.append(bone.name) bones_to_remove.append(bone.name)
for bone_name in bones_to_remove: for bone_name in bones_to_remove:
if bone_name in armature.data.edit_bones: if bone_name in armature.data.edit_bones:
armature.data.edit_bones.remove(armature.data.edit_bones[bone_name]) armature.data.edit_bones.remove(armature.data.edit_bones[bone_name])
# Handle neck bones # Handle neck bones
if 'spine.004' in armature.data.edit_bones and 'spine.005' in armature.data.edit_bones: if 'spine.004' in armature.data.edit_bones and 'spine.005' in armature.data.edit_bones:
neck_start = armature.data.edit_bones['spine.004'] neck_start = armature.data.edit_bones['spine.004']
@@ -144,11 +146,12 @@ class AvatarToolkit_OT_ConvertRigifyToUnity(Operator):
bone.name = new_name bone.name = new_name
def cleanup_bone_collections(self, armature: Object) -> None: def cleanup_bone_collections(self, armature: Object) -> None:
"""Remove or consolidate bone collections""" """Remove all bone collections since they're not needed for Unity"""
if hasattr(armature.data, 'collections') and armature.data.collections: if hasattr(armature.data, 'collections') and armature.data.collections:
# Get the first collection as main while len(armature.data.collections) > 0:
main_collection = armature.data.collections[0] collection = armature.data.collections[0]
armature.data.collections.remove(collection)
# Remove other collections # Remove other collections
while len(armature.data.collections) > 1: while len(armature.data.collections) > 1:
collection = armature.data.collections[1] collection = armature.data.collections[1]