164 lines
7.6 KiB
Python
164 lines
7.6 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#===================================== 1. Module Imports =====================================
|
|
import maya.cmds as cmds
|
|
import maya.mel as mel
|
|
import sys
|
|
import os
|
|
from scripts.config import data
|
|
from scripts.ui import menu_utils as menu_utils
|
|
from scripts.ui import mesh_utils as mesh_utils
|
|
from scripts.ui import rigging_utils as rigging_utils
|
|
from scripts.ui import define_utils as define_utils
|
|
from scripts.ui import adjust_utils as adjust_utils
|
|
from scripts.ui import widgets as widgets
|
|
|
|
try:
|
|
from PySide2 import QtCore, QtGui, QtWidgets
|
|
from shiboken2 import wrapInstance
|
|
except ImportError:
|
|
try:
|
|
from PySide6 import QtCore, QtGui, QtWidgets
|
|
from shiboken6 import wrapInstance
|
|
except ImportError:
|
|
try:
|
|
from PySide import QtCore, QtGui, QtWidgets
|
|
from shiboken import wrapInstance
|
|
except ImportError as e:
|
|
QtCore = QtGui = QtWidgets = None
|
|
wrapInstance = None
|
|
|
|
#===================================== 2. Menu Manager Class =====================================
|
|
|
|
class MenuManager:
|
|
"""菜单管理器"""
|
|
def __init__(self, parent):
|
|
self.parent = parent
|
|
self.menu_bar = parent.menuBar()
|
|
self._create_menus()
|
|
self._create_toolbar()
|
|
|
|
def _create_menus(self):
|
|
"""创建菜单"""
|
|
# 定义所有菜单项
|
|
self.menu_definitions = {
|
|
"文件": [
|
|
("打开DNA", "open.png", menu_utils.load_dna),
|
|
("保存DNA", "save.png", menu_utils.save_dna),
|
|
("加载当前项目的DNA", "open.png", menu_utils.load_project_dna),
|
|
None,
|
|
("修改混合目标名称", "rename.png", menu_utils.rename_blendshape_target),
|
|
("重置混合目标名称", "resetname.png", menu_utils.reset_blendshape_target),
|
|
None,
|
|
("导出FBX", "export.png", menu_utils.export_fbx),
|
|
None,
|
|
("退出", "exit.png", menu_utils.shutdown)
|
|
],
|
|
"编辑": [
|
|
("创建RL4节点", "connect.png", adjust_utils.create_rl4_node),
|
|
("删除RL4节点", "disconnect.png", adjust_utils.delete_rl4_node),
|
|
None,
|
|
("镜像左至右", "mirrorL.png", adjust_utils.mirror_left_to_right),
|
|
("镜像右至左", "mirrorR.png", adjust_utils.mirror_right_to_left),
|
|
None,
|
|
("姿势由A型转T型", "pose_A_To_T.png", adjust_utils.pose_a_to_t),
|
|
("姿势由T型转A型", "pose_T_To_A.png", adjust_utils.pose_t_to_a),
|
|
None,
|
|
("传输LOD贴图", "locator.png", adjust_utils.transfer_lod_texture),
|
|
("设置关节颜色", "color.png", adjust_utils.set_joint_color),
|
|
None,
|
|
("取消全部标记", "unmark_all.png", adjust_utils.unmark_all),
|
|
("重建所有目标", "rebuildTargets.png", adjust_utils.rebuild_all_targets),
|
|
None,
|
|
("为所有表情设置关键帧", "bakeAnimation.png", adjust_utils.bake_all_animations),
|
|
("烘焙所有表情的关键帧", "centerCurrentTime.png", adjust_utils.bake_all_keyframes)
|
|
],
|
|
"工具": [
|
|
("导出蒙皮", "export_skin.png", rigging_utils.export_skin),
|
|
("导入蒙皮", "import_skin.png", rigging_utils.import_skin),
|
|
("拷贝蒙皮", "copy_skin.png", rigging_utils.copy_skin),
|
|
None,
|
|
("RBF变形器", "blendShape.png", rigging_utils.create_rbf_deformer),
|
|
("快速绑定服装", "clothing_weight.png", rigging_utils.quick_bind_clothing),
|
|
("克隆混合变形", "blendShape.png", rigging_utils.clone_blendshape),
|
|
None,
|
|
("UV传递点序", "repair_vertex_order.png", rigging_utils.transfer_uv_order),
|
|
("面部生成控制器", "controller.png", rigging_utils.create_face_controller),
|
|
("提取52BS", "ARKit52.png", rigging_utils.extract_52bs),
|
|
None,
|
|
("关节轴向修复", "joint.png", rigging_utils.fix_joint_orientation),
|
|
("生成身体控制器", "create_body_ctrl.png", rigging_utils.create_body_controller),
|
|
None,
|
|
("导入面部动画", "import_face_anim.png", rigging_utils.import_face_animation),
|
|
("导入身体动画", "import_body_anim.png", rigging_utils.import_body_animation)
|
|
],
|
|
"语言": [
|
|
("中文", "chinese.png", menu_utils.set_chinese),
|
|
("English", "english.png", menu_utils.set_english)
|
|
],
|
|
"帮助": [
|
|
("帮助文档", "help.png", menu_utils.show_help),
|
|
("关于", "warning.png", menu_utils.show_about)
|
|
]
|
|
}
|
|
|
|
# 创建所有菜单
|
|
for menu_name, items in self.menu_definitions.items():
|
|
menu = self.menu_bar.addMenu(menu_name)
|
|
self._add_menu_items(menu, items)
|
|
|
|
def _create_toolbar(self):
|
|
"""创建工具栏"""
|
|
toolbar = self.parent.addToolBar("主工具栏")
|
|
toolbar.setMovable(True)
|
|
toolbar.setFloatable(True)
|
|
toolbar.setIconSize(QtCore.QSize(24, 24))
|
|
|
|
# 定义工具栏按钮 (text, icon, callback, tooltip)
|
|
toolbar_items = [
|
|
("保存DNA", "save.png", menu_utils.save_dna, "保存DNA"),
|
|
("加载当前项目DNA", "open.png", menu_utils.load_dna, "加载DNA"),
|
|
None,
|
|
("创建RL4节点", "connect.png", adjust_utils.create_rl4_node, "连接表情控制"),
|
|
("删除RL4节点", "disconnect.png", adjust_utils.delete_rl4_node, "断开表情控制"),
|
|
None,
|
|
("导入FBX蒙皮", "import_skin.png", rigging_utils.import_skin, "导入蒙皮"),
|
|
("导出FBX蒙皮", "export_skin.png", rigging_utils.export_skin, "导出蒙皮"),
|
|
None,
|
|
("帮助文档", "help.png", menu_utils.show_help, "帮助文档"),
|
|
("关于", "warning.png", menu_utils.show_about, "关于MetaFusion")
|
|
]
|
|
|
|
self._add_toolbar_items(toolbar, toolbar_items)
|
|
|
|
def _add_menu_items(self, menu, items):
|
|
"""添加菜单项"""
|
|
for item in items:
|
|
if item is None:
|
|
menu.addSeparator()
|
|
else:
|
|
text, icon, callback = item
|
|
action = QtWidgets.QAction(text, self.parent)
|
|
if icon:
|
|
icon_path = os.path.join(data.ICONS_PATH, icon)
|
|
if os.path.exists(icon_path):
|
|
action.setIcon(QtGui.QIcon(icon_path))
|
|
action.triggered.connect(lambda checked=False, fn=callback: fn())
|
|
menu.addAction(action)
|
|
|
|
def _add_toolbar_items(self, toolbar, items):
|
|
"""添加工具栏项"""
|
|
for item in items:
|
|
if item is None:
|
|
toolbar.addSeparator()
|
|
else:
|
|
text, icon, callback, tooltip = item # 现在解包4个值
|
|
action = QtWidgets.QAction(text, self.parent)
|
|
if icon:
|
|
icon_path = os.path.join(data.ICONS_PATH, icon)
|
|
if os.path.exists(icon_path):
|
|
action.setIcon(QtGui.QIcon(icon_path))
|
|
action.setToolTip(tooltip) # 设置工具提示
|
|
action.triggered.connect(lambda checked=False, fn=callback: fn())
|
|
toolbar.addAction(action) |