#!/usr/bin/env python # -*- coding: utf-8 -*- """ Behaviour function module 行为系统功能模块 - 提供行为系统相关的功能函数 """ #===================================== 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 ======================================== # 左侧面板功能 # 搜索相关功能 # def filter_controls(text): # """ # 过滤控制列表 # """ # print(f"过滤控制列表: {text}") # # 这里实现过滤控制列表的功能 # return True # 控制列表相关功能 # def control_selected(item): # """ # 控制项目被选中 # """ # print(f"控制项目被选中: {item.text()}") # # 这里实现控制项目选中的功能 # return True # def update_control_selection(): # """更新控制器选择""" # try: # print("更新控制器选择") # except Exception as e: # print(f"更新控制器选择时出错: {str(e)}") # def update_control_value(value): # """更新控制器值""" # try: # print(f"更新控制器值: {value}") # except Exception as e: # print(f"更新控制器值时出错: {str(e)}") # def switch_page(page): # """切换页面""" # try: # print(f"切换到页面: {page}") # except Exception as e: # print(f"切换页面时出错: {str(e)}") # 页码相关功能 # def decrease_range(): # """ # 减小范围 # """ # print("减小范围") # # 这里实现减小范围的功能 # return True # def increase_range(): # """ # 增加范围 # """ # print("增加范围") # # 这里实现增加范围的功能 # return True # 右侧面板功能 # BlendShapes相关功能 # def blendshape_selected(item): # """ # 混合形状项目被选中 # """ # print(f"混合形状项目被选中: {item.text()}") # # 这里实现混合形状项目选中的功能 # return True def flip_target(): """翻转目标""" try: print("翻转目标") except Exception as e: print(f"翻转目标时出错: {str(e)}") def mirror_target(): """镜像目标""" try: print("镜像目标") except Exception as e: print(f"镜像目标时出错: {str(e)}") def find_flip_target(): """查找翻转目标""" try: print("查找翻转目标") except Exception as e: print(f"查找翻转目标时出错: {str(e)}") def add_blendshape(): """添加BlendShape""" try: print("添加BlendShape") except Exception as e: print(f"添加BlendShape时出错: {str(e)}") def delete_blendshape(): """删除BlendShape""" try: print("删除BlendShape") except Exception as e: print(f"删除BlendShape时出错: {str(e)}") def batch_blendshape(): """批量处理BlendShape""" try: print("批量处理BlendShape") except Exception as e: print(f"批量处理BlendShape时出错: {str(e)}") def rebuild_select(): """重建选择""" try: print("重建选择") except Exception as e: print(f"重建选择时出错: {str(e)}") def reposition(): """重新定位""" try: print("重新定位") except Exception as e: print(f"重新定位时出错: {str(e)}") def blend_select(): """混合选择""" try: print("混合选择") except Exception as e: print(f"混合选择时出错: {str(e)}") def reset_default_expression(): """重置默认表情""" try: print("重置默认表情") except Exception as e: print(f"重置默认表情时出错: {str(e)}") def find_select_expression(): """查找选择表情""" try: print("查找选择表情") except Exception as e: print(f"查找选择表情时出错: {str(e)}") def write_current_expressions(): """写入当前表情""" try: print("写入当前表情") except Exception as e: print(f"写入当前表情时出错: {str(e)}") def controller_find(): """控制器查找""" try: print("控制器查找") except Exception as e: print(f"控制器查找时出错: {str(e)}") def select_associated_joint(): """选择关联关节""" try: print("选择关联关节") except Exception as e: print(f"选择关联关节时出错: {str(e)}") def write_find_mirror(): """写入查找镜像""" try: print("写入查找镜像") except Exception as e: print(f"写入查找镜像时出错: {str(e)}") # UI事件处理相关的功能函数 def on_selection_changed(ui_instance): """ 处理Maya选择变化事件 Args: ui_instance: UI实例对象 """ print("选择变化事件触发") # 这里将来会实现选择变化的处理逻辑 # 目前仅作为占位函数 def switch_tab(ui_instance, index): """ 切换标签页 Args: ui_instance: UI实例对象 index (int): 标签页索引 """ if hasattr(ui_instance, 'controls') and 'bottom_tab_widget' in ui_instance.controls: ui_instance.controls["bottom_tab_widget"].setCurrentIndex(index) print(f"切换到标签页: {index}") def adjust_range(delta): """ 调整滑块范围 Args: delta (float): 范围调整值 """ if delta > 0: """ 增加范围 """ print("增加范围") # 这里实现增加范围的功能 return True else: """ 减小范围 """ print("减小范围") # 这里实现减小范围的功能 return True def on_raw_slider_changed(value): """ 更新左侧滑块数值显示 Args: value (int): 滑块值 Returns: float: 标准化后的值(0-1范围) """ # 将滑块值转换为0-1范围的浮点数,并显示3位小数 normalized_value = value / 100.0 # 获取UI实例并更新显示 from scripts.ui import behaviour behaviour_ui = behaviour.BehaviourUI.get_instance() if behaviour_ui and hasattr(behaviour_ui, 'controls'): behaviour_ui.controls["raw_slider_value"].setText(f"{normalized_value:.3f}") # 更新控制值 try: print(f"更新控制器值: {value}") except Exception as e: print(f"更新控制器值时出错: {str(e)}") return normalized_value def on_bs_slider_changed(value): """ 更新右侧BS滑块数值显示 Args: value (int): 滑块值 Returns: float: 标准化后的值(0-1范围) """ # 将滑块值转换为0-1范围的浮点数,并显示3位小数 normalized_value = value / 100.0 # 获取UI实例并更新显示 from scripts.ui import behaviour behaviour_ui = behaviour.BehaviourUI.get_instance() if behaviour_ui and hasattr(behaviour_ui, 'controls'): behaviour_ui.controls["bs_slider_value"].setText(f"{normalized_value:.3f}") # 更新BlendShape值 try: print(f"更新BlendShape值: {value}") except Exception as e: print(f"更新BlendShape值时出错: {str(e)}") return normalized_value def on_bottom_slider_changed(value): """ 更新底部主滑块数值显示 Args: value (int): 滑块值 Returns: float: 标准化后的值(0-1范围) """ # 将滑块值转换为0-1范围的浮点数,并显示3位小数 normalized_value = value / 100.0 # 获取UI实例并更新显示 from scripts.ui import behaviour behaviour_ui = behaviour.BehaviourUI.get_instance() if behaviour_ui and hasattr(behaviour_ui, 'controls'): behaviour_ui.controls["bottom_slider_value"].setText(f"{normalized_value:.3f}") # 更新主值 update_main_value(value) try: print(f"更新BlendShape值: {value}") except Exception as e: print(f"更新BlendShape值时出错: {str(e)}") return normalized_value def on_control_selection_changed(): """更新控制器选择""" try: print("更新控制器选择") except Exception as e: print(f"更新控制器选择时出错: {str(e)}") def on_blendshape_selection_changed(): """处理BlendShape列表选择变化""" print("BlendShape列表选择变化") try: print("更新BlendShape选择") except Exception as e: print(f"更新BlendShape选择时出错: {str(e)}") def adjust_bs_range(delta): """ 调整BlendShape滑块范围 Args: delta (float): 范围调整值 """ print(f"调整BlendShape滑块范围: {delta}") if delta > 0: """ 增加范围 """ print("增加范围") # 这里实现增加范围的功能 return True else: """ 减小范围 """ print("减小范围") # 这里实现减小范围的功能 return True def reposition_joints(): """ 重新定位关节 根据当前选择的模型重新定位关节位置 """ print("重新定位关节...") # 这里将来会实现关节重新定位的功能 # 目前仅作为占位函数 cmds.warning("关节重新定位功能尚未实现")