205 lines
7.1 KiB
Python
205 lines
7.1 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.ui.widgets import (BaseWidget, BlendShapeList, BlendShapeControls, BlendShapeTools, IconButton, SliderWithValue)
|
|
|
|
try:
|
|
from PySide2 import QtCore, QtGui, QtWidgets
|
|
from shiboken2 import wrapInstance
|
|
print("从PySide2加载Qt和shiboken2")
|
|
except ImportError:
|
|
try:
|
|
from PySide6 import QtCore, QtGui, QtWidgets
|
|
from shiboken6 import wrapInstance
|
|
print("从PySide6加载Qt和shiboken6")
|
|
except ImportError:
|
|
try:
|
|
from PySide import QtCore, QtGui, QtWidgets
|
|
from shiboken import wrapInstance
|
|
print("从PySide加载Qt和shiboken")
|
|
except ImportError as e:
|
|
print(f"Qt加载失败: {str(e)}")
|
|
QtCore = QtGui = QtWidgets = None
|
|
wrapInstance = None
|
|
|
|
#===================================== 2. Adjust Tab Class =====================================
|
|
class AdjustTab(BaseWidget):
|
|
"""调整标签页"""
|
|
def __init__(self, parent=None):
|
|
super(AdjustTab, self).__init__(parent)
|
|
|
|
def setup_ui(self):
|
|
layout = QtWidgets.QVBoxLayout(self)
|
|
|
|
# 创建分割器
|
|
splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
|
|
layout.addWidget(splitter)
|
|
|
|
# 上部分 - 主要BlendShape列表
|
|
top_widget = QtWidgets.QWidget()
|
|
top_layout = QtWidgets.QVBoxLayout(top_widget)
|
|
|
|
# RowControl BlendShape列表
|
|
self.main_bs_list = BlendShapeList("RowControl")
|
|
top_layout.addWidget(self.main_bs_list)
|
|
|
|
# BlendShape控制
|
|
self.bs_controls = BlendShapeControls()
|
|
top_layout.addWidget(self.bs_controls)
|
|
|
|
splitter.addWidget(top_widget)
|
|
|
|
# 下部分 - 相关BlendShape和工具
|
|
bottom_widget = QtWidgets.QWidget()
|
|
bottom_layout = QtWidgets.QVBoxLayout(bottom_widget)
|
|
|
|
# Related BlendShape列表
|
|
self.related_bs_list = BlendShapeList("Related Blend Shapes")
|
|
bottom_layout.addWidget(self.related_bs_list)
|
|
|
|
# BlendShape工具
|
|
self.bs_tools = BlendShapeTools()
|
|
bottom_layout.addWidget(self.bs_tools)
|
|
|
|
# 表情控制工具栏
|
|
expression_tools = self.create_expression_tools()
|
|
bottom_layout.addWidget(expression_tools)
|
|
|
|
splitter.addWidget(bottom_widget)
|
|
|
|
# 设置分割器比例
|
|
splitter.setStretchFactor(0, 2)
|
|
splitter.setStretchFactor(1, 1)
|
|
|
|
# 连接信号
|
|
self.connect_signals()
|
|
|
|
def create_expression_tools(self):
|
|
"""创建表情控制工具栏"""
|
|
group = QtWidgets.QGroupBox("表情控制")
|
|
layout = QtWidgets.QVBoxLayout(group)
|
|
|
|
# 功能开关
|
|
toggle_layout = QtWidgets.QHBoxLayout()
|
|
|
|
toggles = [
|
|
("PSD", "psd.png"),
|
|
("BSE", "blendShape.png"),
|
|
("KEY", "centerCurrentTime.png"),
|
|
("MIR", "mirrorR.png"),
|
|
("ARK", "ARKit52.png"),
|
|
("CTR", "ctrl_hide.png")
|
|
]
|
|
|
|
for text, icon in toggles:
|
|
btn = IconButton(icon, text)
|
|
btn.setCheckable(True)
|
|
toggle_layout.addWidget(btn)
|
|
|
|
layout.addLayout(toggle_layout)
|
|
|
|
# 数值控制
|
|
value_layout = QtWidgets.QHBoxLayout()
|
|
|
|
self.expr_slider = SliderWithValue(min_val=0.0, max_val=1.0, default=0.0)
|
|
value_layout.addWidget(self.expr_slider)
|
|
|
|
self.expr_all_check = QtWidgets.QCheckBox("全部")
|
|
value_layout.addWidget(self.expr_all_check)
|
|
|
|
layout.addLayout(value_layout)
|
|
|
|
# 表情控制按钮
|
|
expr_layout = QtWidgets.QHBoxLayout()
|
|
|
|
expr_btns = [
|
|
("还原默认表情", "reset.png", self.reset_expression),
|
|
("选择选择表情", "expressions_current.png", self.select_expression),
|
|
("写入当前表情", "expression.png", self.write_expression),
|
|
("控制面板查找", "controller.png", self.find_controller),
|
|
("选择关联关节", "kinJoint.png", self.select_joints),
|
|
("写入镜像表情", "ctrl_hide.png", self.write_mirror_expression)
|
|
]
|
|
|
|
for text, icon, callback in expr_btns:
|
|
btn = IconButton(icon, text)
|
|
btn.clicked.connect(callback)
|
|
expr_layout.addWidget(btn)
|
|
|
|
layout.addLayout(expr_layout)
|
|
|
|
return group
|
|
|
|
def connect_signals(self):
|
|
"""连接信号"""
|
|
# BlendShape列表选择变化
|
|
self.main_bs_list.list_widget.itemSelectionChanged.connect(
|
|
self.on_main_selection_changed)
|
|
self.related_bs_list.list_widget.itemSelectionChanged.connect(
|
|
self.on_related_selection_changed)
|
|
|
|
# 数值变化
|
|
self.bs_controls.value_slider.valueChanged.connect(
|
|
self.on_bs_value_changed)
|
|
self.expr_slider.valueChanged.connect(
|
|
self.on_expr_value_changed)
|
|
|
|
# 回调函数
|
|
def on_main_selection_changed(self):
|
|
"""主BlendShape列表选择变化"""
|
|
from scripts.utils import adjust_utils
|
|
items = self.main_bs_list.list_widget.selectedItems()
|
|
adjust_utils.on_main_bs_selected([item.text() for item in items])
|
|
|
|
def on_related_selection_changed(self):
|
|
"""相关BlendShape列表选择变化"""
|
|
from scripts.utils import adjust_utils
|
|
items = self.related_bs_list.list_widget.selectedItems()
|
|
adjust_utils.on_related_bs_selected([item.text() for item in items])
|
|
|
|
def on_bs_value_changed(self, value):
|
|
"""BlendShape权重变化"""
|
|
from scripts.utils import adjust_utils
|
|
adjust_utils.set_bs_value(value)
|
|
|
|
def on_expr_value_changed(self, value):
|
|
"""表情权重变化"""
|
|
from scripts.utils import adjust_utils
|
|
adjust_utils.set_expr_value(value)
|
|
|
|
# 表情控制回调
|
|
def reset_expression(self):
|
|
"""还原默认表情"""
|
|
from scripts.utils import adjust_utils
|
|
adjust_utils.reset_expression()
|
|
|
|
def select_expression(self):
|
|
"""选择表情"""
|
|
from scripts.utils import adjust_utils
|
|
adjust_utils.select_expression()
|
|
|
|
def write_expression(self):
|
|
"""写入当前表情"""
|
|
from scripts.utils import adjust_utils
|
|
adjust_utils.write_expression()
|
|
|
|
def find_controller(self):
|
|
"""查找控制器"""
|
|
from scripts.utils import adjust_utils
|
|
adjust_utils.find_controller()
|
|
|
|
def select_joints(self):
|
|
"""选择关联关节"""
|
|
from scripts.utils import adjust_utils
|
|
adjust_utils.select_joints()
|
|
|
|
def write_mirror_expression(self):
|
|
"""写入镜像表情"""
|
|
from scripts.utils import adjust_utils
|
|
adjust_utils.write_mirror_expression() |