419 lines
13 KiB
Python
419 lines
13 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
|
||
#===================================== IMPORT MODULES =====================================
|
||
import maya.cmds as cmds
|
||
import pymel.core as pm
|
||
import maya.mel as mel
|
||
from maya import OpenMayaUI as omui
|
||
from ui.Qt import QtWidgets, QtCore, QtGui
|
||
from ui.Qt.QtCompat import wrapInstance
|
||
import webbrowser
|
||
import subprocess
|
||
import importlib
|
||
import traceback
|
||
import sys
|
||
import os
|
||
# 导入配置
|
||
import config
|
||
TOOL_NAME = config.TOOL_NAME
|
||
TOOL_VERSION = config.TOOL_VERSION
|
||
TOOL_AUTHOR = config.TOOL_AUTHOR
|
||
TOOL_YEAR = config.TOOL_YEAR
|
||
TOOL_MOD_FILENAME = config.TOOL_MOD_FILENAME
|
||
TOOL_LANG = config.TOOL_LANG
|
||
TOOL_WSCL_NAME = config.TOOL_WSCL_NAME
|
||
TOOL_HELP_URL = config.TOOL_HELP_URL
|
||
TOOL_PATH = config.TOOL_PATH
|
||
SCRIPTS_PATH = config.SCRIPTS_PATH
|
||
TOOL_MAIN_SCRIPT = config.TOOL_MAIN_SCRIPT
|
||
UI_PATH = config.UI_PATH
|
||
STYLE_FILE = config.STYLE_FILE
|
||
ICONS_PATH = config.ICONS_PATH
|
||
TOOL_ICON = config.TOOL_ICON
|
||
ASSETS_PATH = config.ASSETS_PATH
|
||
DNA_FILE_PATH = config.DNA_FILE_PATH
|
||
DNA_IMG_PATH = config.DNA_IMG_PATH
|
||
TOOL_COMMAND_ICON = config.TOOL_COMMAND_ICON
|
||
TOOL_WIDTH = config.TOOL_WIDTH
|
||
TOOL_HEIGHT = config.TOOL_HEIGHT
|
||
# Localization
|
||
from scripts.ui import localization
|
||
TEXT = localization.TEXT
|
||
|
||
#========================================== FUNCTIONS ========================================
|
||
|
||
#========================================== DNA 功能 ========================================
|
||
def save_dna():
|
||
"""
|
||
保存DNA文件
|
||
"""
|
||
print("保存DNA文件")
|
||
try:
|
||
file_path = cmds.fileDialog2(
|
||
fileFilter="DNA Files (*.dna);;All Files (*.*)",
|
||
dialogStyle=2,
|
||
fileMode=0,
|
||
caption=TEXT("save_dna", "保存DNA文件")
|
||
)
|
||
|
||
if file_path and len(file_path) > 0:
|
||
# 这里添加保存DNA文件的代码
|
||
print(f"DNA文件已保存到: {file_path[0]}")
|
||
except Exception as e:
|
||
print(f"保存DNA文件时出错: {e}")
|
||
return True
|
||
|
||
def open_dna():
|
||
"""
|
||
打开DNA文件
|
||
"""
|
||
print("打开DNA文件")
|
||
try:
|
||
file_path = cmds.fileDialog2(
|
||
fileFilter="DNA Files (*.dna);;All Files (*.*)",
|
||
dialogStyle=2,
|
||
fileMode=1,
|
||
caption=TEXT("open_dna", "打开DNA文件")
|
||
)
|
||
|
||
if file_path and len(file_path) > 0:
|
||
# 这里添加打开DNA文件的代码
|
||
print(f"打开DNA文件: {file_path[0]}")
|
||
except Exception as e:
|
||
print(f"打开DNA文件时出错: {e}")
|
||
return True
|
||
|
||
#========================================== RL4节点功能 ========================================
|
||
def create_rl4_node():
|
||
"""
|
||
创建RL4节点
|
||
"""
|
||
print("创建RL4节点")
|
||
try:
|
||
# 这里添加创建RL4节点的代码
|
||
print("RL4节点已创建")
|
||
except Exception as e:
|
||
print(f"创建RL4节点时出错: {e}")
|
||
return True
|
||
|
||
def delete_rl4_node():
|
||
"""
|
||
删除RL4节点
|
||
"""
|
||
print("删除RL4节点")
|
||
try:
|
||
# 这里添加删除RL4节点的代码
|
||
print("RL4节点已删除")
|
||
except Exception as e:
|
||
print(f"删除RL4节点时出错: {e}")
|
||
return True
|
||
|
||
#========================================== 蒙皮功能 ========================================
|
||
def import_skin():
|
||
"""
|
||
导入蒙皮
|
||
"""
|
||
print("导入蒙皮")
|
||
try:
|
||
file_path = cmds.fileDialog2(
|
||
fileFilter="Skin Files (*.skin);;XML Files (*.xml);;All Files (*.*)",
|
||
dialogStyle=2,
|
||
fileMode=1,
|
||
caption=TEXT("import_skin", "导入蒙皮")
|
||
)
|
||
|
||
if file_path and len(file_path) > 0:
|
||
# 这里添加导入蒙皮的代码
|
||
print(f"导入蒙皮文件: {file_path[0]}")
|
||
except Exception as e:
|
||
print(f"导入蒙皮时出错: {e}")
|
||
return True
|
||
|
||
def export_skin():
|
||
"""
|
||
导出蒙皮
|
||
"""
|
||
print("导出蒙皮")
|
||
try:
|
||
file_path = cmds.fileDialog2(
|
||
fileFilter="Skin Files (*.skin);;XML Files (*.xml);;All Files (*.*)",
|
||
dialogStyle=2,
|
||
fileMode=0,
|
||
caption=TEXT("export_skin", "导出蒙皮")
|
||
)
|
||
|
||
if file_path and len(file_path) > 0:
|
||
# 这里添加导出蒙皮的代码
|
||
print(f"蒙皮已导出到: {file_path[0]}")
|
||
except Exception as e:
|
||
print(f"导出蒙皮时出错: {e}")
|
||
return True
|
||
|
||
def copy_skin():
|
||
"""
|
||
复制蒙皮
|
||
"""
|
||
print("复制蒙皮")
|
||
try:
|
||
# 这里添加复制蒙皮的代码
|
||
print("蒙皮已复制")
|
||
except Exception as e:
|
||
print(f"复制蒙皮时出错: {e}")
|
||
return True
|
||
|
||
#========================================== 帮助功能 ========================================
|
||
def show_help():
|
||
"""
|
||
显示帮助信息
|
||
"""
|
||
print("显示帮助信息")
|
||
try:
|
||
# 打开帮助文档或显示帮助对话框
|
||
help_dialog = QtWidgets.QMessageBox()
|
||
help_dialog.setWindowTitle(TEXT("help_title", "帮助"))
|
||
help_dialog.setText(TEXT("help_message", "该插件是一个用于自定义MetaHuman的Maya插件。\n\n详细信息请参考文档。"))
|
||
help_dialog.setStandardButtons(QtWidgets.QMessageBox.Ok)
|
||
help_dialog.exec_()
|
||
except Exception as e:
|
||
print(f"显示帮助信息时出错: {e}")
|
||
return True
|
||
|
||
def link_file():
|
||
"""
|
||
链接文件
|
||
"""
|
||
print("链接文件")
|
||
try:
|
||
file_path = cmds.fileDialog2(
|
||
fileFilter="Maya Files (*.ma *.mb);;All Files (*.*)",
|
||
dialogStyle=2,
|
||
fileMode=1
|
||
)
|
||
if file_path:
|
||
# 这里实现链接文件的功能
|
||
print(f"文件已链接: {file_path[0]}")
|
||
except Exception as e:
|
||
print(f"链接文件时出错: {e}")
|
||
return True
|
||
|
||
def unlink_file():
|
||
"""
|
||
取消链接
|
||
"""
|
||
print("取消链接")
|
||
# 这里实现取消链接的功能
|
||
return True
|
||
|
||
def import_file():
|
||
"""
|
||
导入文件
|
||
"""
|
||
print("导入文件")
|
||
try:
|
||
file_path = cmds.fileDialog2(
|
||
fileFilter="Maya Files (*.ma *.mb);;FBX Files (*.fbx);;OBJ Files (*.obj);;All Files (*.*)",
|
||
dialogStyle=2,
|
||
fileMode=1
|
||
)
|
||
if file_path:
|
||
# 根据文件扩展名选择导入方法
|
||
file_ext = os.path.splitext(file_path[0])[1].lower()
|
||
if file_ext == ".fbx":
|
||
cmds.file(file_path[0], i=True, type="FBX")
|
||
elif file_ext == ".obj":
|
||
cmds.file(file_path[0], i=True, type="OBJ")
|
||
else: # .ma or .mb
|
||
cmds.file(file_path[0], i=True)
|
||
print(f"文件已导入: {file_path[0]}")
|
||
except Exception as e:
|
||
print(f"导入文件时出错: {e}")
|
||
return True
|
||
|
||
def export_file():
|
||
"""
|
||
导出文件
|
||
"""
|
||
print("导出文件")
|
||
try:
|
||
file_path = cmds.fileDialog2(
|
||
fileFilter="Maya Files (*.ma *.mb);;FBX Files (*.fbx);;OBJ Files (*.obj);;All Files (*.*)",
|
||
dialogStyle=2,
|
||
fileMode=0
|
||
)
|
||
if file_path:
|
||
# 根据文件扩展名选择导出方法
|
||
file_ext = os.path.splitext(file_path[0])[1].lower()
|
||
if file_ext == ".fbx":
|
||
cmds.file(file_path[0], force=True, options="v=0;", type="FBX export", pr=True, ea=True)
|
||
elif file_ext == ".obj":
|
||
cmds.file(file_path[0], force=True, options="groups=1;ptgroups=1;materials=1;smoothing=1;normals=1", type="OBJexport", pr=True, ea=True)
|
||
else: # .ma or .mb
|
||
cmds.file(file_path[0], force=True, type="mayaAscii" if file_ext == ".ma" else "mayaBinary", pr=True, ea=True)
|
||
print(f"文件已导出: {file_path[0]}")
|
||
except Exception as e:
|
||
print(f"导出文件时出错: {e}")
|
||
return True
|
||
|
||
def save_file():
|
||
"""
|
||
保存文件
|
||
"""
|
||
print("保存文件")
|
||
try:
|
||
current_file = cmds.file(q=True, sceneName=True)
|
||
if current_file:
|
||
cmds.file(save=True)
|
||
print(f"文件已保存: {current_file}")
|
||
else:
|
||
file_path = cmds.fileDialog2(
|
||
fileFilter="Maya ASCII (*.ma);;Maya Binary (*.mb)",
|
||
dialogStyle=2,
|
||
fileMode=0
|
||
)
|
||
if file_path:
|
||
file_ext = os.path.splitext(file_path[0])[1].lower()
|
||
file_type = "mayaAscii" if file_ext == ".ma" else "mayaBinary"
|
||
cmds.file(rename=file_path[0])
|
||
cmds.file(save=True, type=file_type)
|
||
print(f"文件已保存: {file_path[0]}")
|
||
except Exception as e:
|
||
print(f"保存文件时出错: {e}")
|
||
return True
|
||
|
||
def show_user_info():
|
||
"""
|
||
显示用户信息
|
||
"""
|
||
print("显示用户信息")
|
||
# 这里实现显示用户信息的功能
|
||
return True
|
||
|
||
def show_help():
|
||
"""
|
||
显示帮助信息
|
||
"""
|
||
print("显示帮助信息")
|
||
try:
|
||
if hasattr(config, "TOOL_HELP_URL") and config.TOOL_HELP_URL:
|
||
webbrowser.open(config.TOOL_HELP_URL)
|
||
else:
|
||
cmds.confirmDialog(
|
||
title=TEXT("help", "帮助"),
|
||
message=TEXT("help_not_available", "帮助文档暂不可用"),
|
||
button=[TEXT("ok", "确定")],
|
||
defaultButton=TEXT("ok", "确定")
|
||
)
|
||
except Exception as e:
|
||
print(f"显示帮助信息时出错: {e}")
|
||
return True
|
||
|
||
def show_settings():
|
||
"""
|
||
显示设置
|
||
"""
|
||
print("显示设置")
|
||
# 这里实现显示设置的功能
|
||
return True
|
||
|
||
def print_file():
|
||
"""
|
||
打印文件
|
||
"""
|
||
print("打印文件")
|
||
# 这里实现打印文件的功能
|
||
return True
|
||
|
||
# 第二行按钮功能
|
||
def change_view(view_type):
|
||
"""
|
||
切换视图类型
|
||
"""
|
||
print(f"切换到{view_type}视图")
|
||
# 这里实现切换视图的功能
|
||
return True
|
||
|
||
def model_changed(index):
|
||
"""
|
||
模型选择改变
|
||
"""
|
||
print(f"模型选择改变: {index}")
|
||
# 这里实现模型选择改变的功能
|
||
return True
|
||
|
||
# 保留原来的函数作为兼容性考虑
|
||
def toolbar_temp_utils_function():
|
||
"""
|
||
Placeholder function for toolbar module
|
||
This function will be replaced with actual functionality in future updates
|
||
"""
|
||
print("Toolbar module initialized with placeholder function")
|
||
return True
|
||
|
||
def toggle_language():
|
||
"""
|
||
切换界面语言
|
||
在英文和中文之间切换
|
||
"""
|
||
from scripts.ui import localization
|
||
import config
|
||
from scripts.ui.Qt import QtWidgets
|
||
|
||
# 使用localization模块来切换语言
|
||
new_language = localization.switch_language()
|
||
config.TOOL_LANG = new_language
|
||
|
||
try:
|
||
# 查找主窗口
|
||
main_window = None
|
||
for widget in QtWidgets.QApplication.allWidgets():
|
||
if widget.objectName() == f"{config.TOOL_NAME}MainWindow" and isinstance(widget, QtWidgets.QWidget):
|
||
main_window = widget
|
||
break
|
||
|
||
if main_window:
|
||
# 更新主窗口标题
|
||
main_window.setWindowTitle(f"{config.TOOL_NAME} {config.TOOL_VERSION}")
|
||
|
||
# 遍历主窗口的所有子控件,批量动态更新语言
|
||
for child in main_window.findChildren(QtWidgets.QWidget):
|
||
# 只要有update_language方法就调用
|
||
if hasattr(child, 'update_language') and callable(child.update_language):
|
||
try:
|
||
child.update_language()
|
||
except Exception as e:
|
||
print(f"更新语言失败: {child}: {e}")
|
||
|
||
# 更新功能按钮文字
|
||
if hasattr(main_window, 'function_buttons'):
|
||
for key, button in main_window.function_buttons.items():
|
||
button.setText(localization.TEXT(key))
|
||
|
||
print(f"语言已切换到: {new_language}")
|
||
|
||
# 切换语言后强制重载主窗口,保证所有UI和控件100%刷新
|
||
from scripts.Main import main
|
||
for widget in QtWidgets.QApplication.allWidgets():
|
||
if widget.objectName() == f"{config.TOOL_NAME}MainWindow" and isinstance(widget, QtWidgets.QWidget):
|
||
widget.close()
|
||
main()
|
||
return
|
||
except Exception as e:
|
||
print(f"动态更新语言失败,将重启窗口: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
|
||
# 如果动态更新失败,尝试关闭并重启窗口
|
||
try:
|
||
from scripts.Main import main
|
||
# 关闭当前窗口
|
||
for widget in QtWidgets.QApplication.allWidgets():
|
||
if widget.objectName() == f"{config.TOOL_NAME}MainWindow" and isinstance(widget, QtWidgets.QWidget):
|
||
widget.close()
|
||
|
||
# 重新打开窗口
|
||
main()
|
||
except Exception as e:
|
||
print(f"切换语言时出错: {e}")
|
||
import traceback
|
||
traceback.print_exc() |