Files
MetaFusion/scripts/utils/utils_toolbar.py
2025-05-05 22:23:25 +08:00

330 lines
9.5 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 Qt import QtWidgets, QtCore, QtGui
from Qt.QtCompat import wrapInstance
import webbrowser
import subprocess
import importlib
import traceback
import sys
import os
# 导入配置
import config
from scripts.ui import localization
LANG = localization.LANG
#========================================== FUNCTIONS ========================================
#========================================== DNA 功能 ========================================
def save_dna():
"""
保存DNA文件
"""
print("保存DNA文件")
try:
file_path = cmds.fileDialog2(
fileFilter="DNA Files (*.dna);;All Files (*.*)",
dialogStyle=2,
fileMode=0,
caption=LANG.get("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=LANG.get("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=LANG.get("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=LANG.get("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(LANG.get("help_title", "帮助"))
help_dialog.setText(LANG.get("help_message", "MetaFusion是一个用于自定义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=LANG.get("help", "帮助"),
message=LANG.get("help_not_available", "帮助文档暂不可用"),
button=[LANG.get("ok", "确定")],
defaultButton=LANG.get("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