This commit is contained in:
Yusarina
2025-11-26 19:35:20 +00:00
parent d85231b62b
commit 4b538cb8b2
3 changed files with 0 additions and 1358 deletions
File diff suppressed because it is too large Load Diff
-154
View File
@@ -1,154 +0,0 @@
"""
MMD Conversion Operator
Converts MMD armatures to standard Blender format
"""
import bpy
from bpy.types import Operator
from ...core.common import get_active_armature
from ...core.translations import t
from ...core.mmd_converter import (convert_mmd_armature, detect_mmd_armature,
translate_mmd_everything, restructure_mmd_to_unity_bones,
remove_mmd_ik_bones, remove_mmd_twist_bones, remove_mmd_zero_weight_bones)
from ...core.logging_setup import logger
class AvatarToolkit_OT_ConvertMMDArmature(Operator):
"""Convert MMD armature to standard Blender format"""
bl_idname = "avatar_toolkit.convert_mmd_armature"
bl_label = t("MMD.convert_armature.label")
bl_description = t("MMD.convert_armature.desc")
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
armature = get_active_armature(context)
return armature is not None
def execute(self, context):
armature = get_active_armature(context)
if not armature:
logger.warning("No active armature found for MMD conversion")
self.report({'ERROR'}, t("MMD.no_armature_selected"))
return {'CANCELLED'}
logger.info(f"Starting MMD conversion for armature: {armature.name}")
# Check if it's an MMD armature
if not detect_mmd_armature(armature):
logger.warning(f"Armature '{armature.name}' does not appear to be an MMD armature")
self.report({'WARNING'}, t("MMD.not_mmd_armature"))
return {'CANCELLED'}
# Get conversion settings
toolkit = context.scene.avatar_toolkit
make_parent = toolkit.mmd_make_parent
rename_armature = toolkit.mmd_rename_armature
translate_names = toolkit.mmd_translate_names
translate_bones = toolkit.mmd_translate_bones
translate_materials = toolkit.mmd_translate_materials
translate_shapekeys = toolkit.mmd_translate_shapekeys
translate_objects = toolkit.mmd_translate_objects
restructure_bones = toolkit.mmd_restructure_bones
remove_twist_bones = toolkit.mmd_remove_twist_bones
remove_zero_weight_bones = toolkit.mmd_remove_zero_weight_bones
logger.info(f"Conversion settings - Make parent: {make_parent}, Rename: {rename_armature}, " +
f"Restructure: {restructure_bones}")
logger.info(f"Bone cleanup - IK: True (automatic), Twist: {remove_twist_bones}, Zero weight: {remove_zero_weight_bones}")
logger.info(f"Translation settings - Enabled: {translate_names}, Bones: {translate_bones}, " +
f"Materials: {translate_materials}, Shapekeys: {translate_shapekeys}, Objects: {translate_objects}")
# Step 1: Basic conversion (parent and rename)
success, messages = convert_mmd_armature(armature, make_parent, rename_armature)
if not success:
logger.warning(f"MMD conversion failed: {messages}")
for msg in messages:
self.report({'WARNING'}, msg)
return {'CANCELLED'}
logger.info(f"MMD basic conversion completed successfully")
for msg in messages:
self.report({'INFO'}, msg)
# Step 2: Remove IK bones BEFORE translation (always automatic)
logger.info("Starting IK bone removal (before translation)")
self.report({'INFO'}, "Removing IK bones...")
ik_success, ik_messages = remove_mmd_ik_bones(armature)
if ik_success:
logger.info("IK bone removal completed successfully")
else:
logger.warning("IK bone removal completed with errors")
for msg in ik_messages:
self.report({'INFO'}, msg)
# Step 3: Remove twist bones BEFORE translation (if enabled)
if remove_twist_bones:
logger.info("Starting twist bone removal (before translation)")
self.report({'INFO'}, "Removing twist bones...")
twist_success, twist_messages = remove_mmd_twist_bones(armature)
if twist_success:
logger.info("Twist bone removal completed successfully")
else:
logger.warning("Twist bone removal completed with errors")
for msg in twist_messages:
self.report({'INFO'}, msg)
# Step 4: Translation (if enabled)
if translate_names:
logger.info("Starting MMD name translation")
self.report({'INFO'}, t("MMD.translation_starting"))
trans_success, trans_messages = translate_mmd_everything(
armature,
translate_bones=translate_bones,
translate_materials=translate_materials,
translate_shapekeys=translate_shapekeys,
translate_objects=translate_objects
)
if trans_success:
logger.info("MMD name translation completed successfully")
else:
logger.warning("MMD name translation completed with some failures")
for msg in trans_messages:
self.report({'INFO'}, msg)
# Step 5: Restructure bones to Unity format (if enabled)
if restructure_bones:
logger.info("Starting bone restructuring to Unity format")
self.report({'INFO'}, t("MMD.restructure_starting"))
struct_success, struct_messages = restructure_mmd_to_unity_bones(armature)
if struct_success:
logger.info("Bone restructuring completed successfully")
else:
logger.warning("Bone restructuring completed with errors")
for msg in struct_messages:
self.report({'INFO'}, msg)
# Step 6: Remove zero weight bones (if enabled)
if remove_zero_weight_bones:
logger.info("Starting zero weight bone removal")
self.report({'INFO'}, "Removing zero weight bones...")
zero_success, zero_messages = remove_mmd_zero_weight_bones(armature)
if zero_success:
logger.info("Zero weight bone removal completed successfully")
else:
logger.warning("Zero weight bone removal completed with errors")
for msg in zero_messages:
self.report({'INFO'}, msg)
return {'FINISHED'}
-125
View File
@@ -1,125 +0,0 @@
"""
MMD Converter Panel - UI for MMD conversion tools
"""
import bpy
from bpy.types import Panel, Context, UILayout
from .main_panel import AvatarToolKit_PT_AvatarToolkitPanel, CATEGORY_NAME
from .panel_layout import get_panel_order, should_open_by_default
from ..core.translations import t
from ..core.common import get_active_armature
from ..core.mmd_converter import detect_mmd_armature
from ..functions.tools.mmd_conversion import AvatarToolkit_OT_ConvertMMDArmature
class AvatarToolKit_PT_MMDPanel(Panel):
"""Panel for MMD conversion tools"""
bl_label = t("MMD.panel.label")
bl_idname = "OBJECT_PT_avatar_toolkit_mmd"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = CATEGORY_NAME
bl_parent_id = AvatarToolKit_PT_AvatarToolkitPanel.bl_idname
bl_order = get_panel_order('mmd')
bl_options = set() if not should_open_by_default('MMD') else {'DEFAULT_CLOSED'}
def draw(self, context: Context) -> None:
"""Draw the MMD conversion panel interface"""
layout: UILayout = self.layout
# MMD Conversion Tools
mmd_box: UILayout = layout.box()
col: UILayout = mmd_box.column(align=True)
col.label(text=t("MMD.converter.title"), icon='ARMATURE_DATA')
col.separator(factor=0.5)
# Check if we have an active armature
armature = get_active_armature(context)
if not armature:
col.label(text=t("MMD.no_armature_selected"), icon='ERROR')
col.label(text=t("MMD.select_armature_to_convert"))
return
# Check if the armature appears to be MMD
is_mmd = detect_mmd_armature(armature)
if is_mmd:
col.label(text=t("MMD.armature_name", name=armature.name), icon='CHECKMARK')
col.label(text=t("MMD.armature_detected"), icon='INFO')
col.separator(factor=0.3)
toolkit = context.scene.avatar_toolkit
# Basic conversion settings
col.prop(toolkit, 'mmd_make_parent', text=t("MMD.make_armature_parent"))
col.prop(toolkit, 'mmd_rename_armature', text=t("MMD.rename_to_armature"))
col.separator(factor=0.2)
# Bone restructuring
col.prop(toolkit, 'mmd_restructure_bones', text=t("MMD.restructure_bones"))
col.separator(factor=0.2)
# Bone cleanup options
col.label(text=t("MMD.bone_cleanup"), icon='BONE_DATA')
cleanup_box = col.box()
cleanup_col = cleanup_box.column(align=True)
cleanup_col.prop(toolkit, 'mmd_remove_twist_bones', text=t("MMD.remove_twist_bones"))
cleanup_col.prop(toolkit, 'mmd_remove_zero_weight_bones', text=t("MMD.remove_zero_weight_bones"))
col.separator(factor=0.2)
# Translation settings
col.prop(toolkit, 'mmd_translate_names', text=t("MMD.translate_names"))
# Translation sub-options (only show if translation is enabled)
if toolkit.mmd_translate_names:
trans_box = col.box()
trans_col = trans_box.column(align=True)
trans_col.label(text=t("MMD.translation_options"), icon='WORLD')
trans_col.prop(toolkit, 'mmd_translate_bones', text=t("MMD.translate_bones"))
trans_col.prop(toolkit, 'mmd_translate_materials', text=t("MMD.translate_materials"))
trans_col.prop(toolkit, 'mmd_translate_shapekeys', text=t("MMD.translate_shapekeys"))
trans_col.prop(toolkit, 'mmd_translate_objects', text=t("MMD.translate_objects"))
col.separator(factor=0.2)
col.operator(
AvatarToolkit_OT_ConvertMMDArmature.bl_idname,
text=t("MMD.convert_armature_button"),
icon='EXPORT'
)
info_box = mmd_box.box()
info_col = info_box.column(align=True)
info_col.label(text=t("MMD.conversion_info.title"), icon='INFO')
info_col.label(text=t("MMD.conversion_info.removes_parent"))
info_col.label(text=t("MMD.conversion_info.renames_armature"))
if toolkit.mmd_restructure_bones:
info_col.label(text=t("MMD.conversion_info.restructures_bones"))
info_col.label(text=t("MMD.conversion_info.removes_ik_bones"))
if toolkit.mmd_remove_twist_bones:
info_col.label(text=t("MMD.conversion_info.removes_twist_bones"))
if toolkit.mmd_remove_zero_weight_bones:
info_col.label(text=t("MMD.conversion_info.removes_zero_weight_bones"))
info_col.label(text=t("MMD.conversion_info.maintains_hierarchy"))
if toolkit.mmd_translate_names:
info_col.label(text=t("MMD.conversion_info.translates_names"))
else:
col.label(text=t("MMD.armature_name", name=armature.name), icon='ERROR')
col.label(text=t("MMD.no_mmd_bones_detected"), icon='CANCEL')
col.separator(factor=0.3)
row = col.row()
row.enabled = False
row.operator(
AvatarToolkit_OT_ConvertMMDArmature.bl_idname,
text=t("MMD.convert_armature_button"),
icon='CANCEL'
)
help_box = mmd_box.box()
help_col = help_box.column(align=True)
help_col.label(text=t("MMD.detection_failed.title"), icon='QUESTION')
help_col.label(text=t("MMD.detection_failed.not_mmd_format"))
help_col.label(text=t("MMD.detection_failed.need_mmd_bones"))
help_col.label(text=t("MMD.detection_failed.check_bone_names"))