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",
|
"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.'
|
||||||
|
]
|
||||||
@@ -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,8 +18,7 @@ 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]:
|
||||||
@@ -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,11 +59,10 @@ 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:
|
||||||
@@ -144,10 +146,11 @@ 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:
|
||||||
|
|||||||
Reference in New Issue
Block a user