Conversation Complete
- This now removes bones which are not needed for Unity. - Renamed the armature to armature.
This commit is contained in:
@@ -404,3 +404,22 @@ rigify_basic_unity_names = {
|
||||
"foot.R": "RightFoot",
|
||||
"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.'
|
||||
]
|
||||
@@ -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.logging_setup import logger
|
||||
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):
|
||||
"""Convert Rigify armature to Unity-compatible format"""
|
||||
@@ -18,9 +18,8 @@ class AvatarToolkit_OT_ConvertRigifyToUnity(Operator):
|
||||
armature = get_active_armature(context)
|
||||
if not armature:
|
||||
return False
|
||||
valid, _ = validate_armature(armature)
|
||||
return valid and ("DEF-spine" in armature.data.bones or
|
||||
"spine" in armature.data.bones and "metarig" in armature.name.lower())
|
||||
return ("DEF-spine" in armature.data.bones or
|
||||
"spine" in armature.data.bones and "metarig" in armature.name.lower())
|
||||
|
||||
def execute(self, context: Context) -> Set[str]:
|
||||
try:
|
||||
@@ -31,6 +30,10 @@ class AvatarToolkit_OT_ConvertRigifyToUnity(Operator):
|
||||
|
||||
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:
|
||||
self.move_def_bones(armature)
|
||||
self.rename_bones_for_unity(armature)
|
||||
@@ -56,11 +59,10 @@ class AvatarToolkit_OT_ConvertRigifyToUnity(Operator):
|
||||
"""Remove unnecessary bones and merge neck bones"""
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
# Remove heel and pelvis bones
|
||||
# Remove bones matching patterns from dictionary
|
||||
bones_to_remove = []
|
||||
for bone in armature.data.edit_bones:
|
||||
if ('heel' in bone.name.lower() or
|
||||
'pelvis.' in bone.name.lower()):
|
||||
if any(pattern in bone.name.lower() for pattern in rigify_unnecessary_bones):
|
||||
bones_to_remove.append(bone.name)
|
||||
|
||||
for bone_name in bones_to_remove:
|
||||
@@ -144,10 +146,11 @@ class AvatarToolkit_OT_ConvertRigifyToUnity(Operator):
|
||||
bone.name = new_name
|
||||
|
||||
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:
|
||||
# Get the first collection as main
|
||||
main_collection = armature.data.collections[0]
|
||||
while len(armature.data.collections) > 0:
|
||||
collection = armature.data.collections[0]
|
||||
armature.data.collections.remove(collection)
|
||||
|
||||
# Remove other collections
|
||||
while len(armature.data.collections) > 1:
|
||||
|
||||
Reference in New Issue
Block a user