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

618 lines
16 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 update_blendshape_selection():
"""更新BlendShape选择"""
try:
print("更新BlendShape选择")
except Exception as e:
print(f"更新BlendShape选择时出错: {str(e)}")
def update_blendshape_value(value):
"""更新BlendShape值"""
try:
print(f"更新BlendShape值: {value}")
except Exception as e:
print(f"更新BlendShape值时出错: {str(e)}")
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)}")
# BlendShape操作相关功能
def reset_blendshape():
"""
重置混合形状
"""
print("重置混合形状")
# 这里实现重置混合形状的功能
return True
def mirror_blendshape():
"""
镜像混合形状
"""
print("镜像混合形状")
# 这里实现镜像混合形状的功能
return True
def remove_blendshape():
"""
移除混合形状
"""
print("移除混合形状")
# 这里实现移除混合形状的功能
return True
def update_blendshape():
"""
更新混合形状
"""
print("更新混合形状")
# 这里实现更新混合形状的功能
return True
def isolate_blendshape():
"""
隔离混合形状
"""
print("隔离混合形状")
# 这里实现隔离混合形状的功能
return True
def new_blendshape():
"""
新建混合形状
"""
print("新建混合形状")
# 这里实现新建混合形状的功能
return True
def combine_blendshape():
"""
组合混合形状
"""
print("组合混合形状")
# 这里实现组合混合形状的功能
return True
# 标签页相关功能
def switch_tab(tab):
"""切换标签页"""
try:
print(f"切换到标签页: {tab}")
except Exception as e:
print(f"切换标签页时出错: {str(e)}")
# 底部相关功能
def update_main_value(value):
"""更新主滑块值"""
try:
print(f"更新主滑块值: {value}")
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)}")
def exchange_from_expression():
"""
交换从表情
"""
print("交换从表情")
# 这里实现交换从表情的功能
return True
def reset_selected_expression():
"""
重置选定表情
"""
print("重置选定表情")
# 这里实现重置选定表情的功能
return True
def import_expression():
"""
导入表情
"""
print("导入表情")
try:
file_path = cmds.fileDialog2(
fileFilter="Expression Files (*.exp);;JSON Files (*.json);;All Files (*.*)",
dialogStyle=2,
fileMode=1
)
if file_path:
# 这里实现导入表情的功能
print(f"将从{file_path[0]}导入表情")
except Exception as e:
print(f"导入表情时出错: {e}")
return True
def control_panel_search():
"""
控制面板搜索
"""
print("控制面板搜索")
# 这里实现控制面板搜索的功能
return True
def select_related_keys():
"""
选择相关键值
"""
print("选择相关键值")
# 这里实现选择相关键值的功能
return True
def import_map_expression():
"""
导入表情映射
"""
print("导入表情映射")
try:
file_path = cmds.fileDialog2(
fileFilter="Map Files (*.map);;JSON Files (*.json);;All Files (*.*)",
dialogStyle=2,
fileMode=1
)
if file_path:
# 这里实现导入表情映射的功能
print(f"将从{file_path[0]}导入表情映射")
except Exception as e:
print(f"导入表情映射时出错: {e}")
return True
# 勾选框处理函数
def toggle_raw_slider_all(state):
"""
切换左侧滑块的All选项
Args:
state (int): 勾选框状态
"""
try:
print(f"切换左侧滑块All选项: {state}")
# 根据勾选状态执行相应操作
if state == 2: # 选中状态
print("应用到所有控制器")
# TODO: 实现应用到所有控制器的逻辑
else: # 未选中状态
print("仅应用到选中的控制器")
# TODO: 实现仅应用到选中控制器的逻辑
except Exception as e:
print(f"切换左侧滑块All选项时出错: {str(e)}")
def toggle_bs_slider_all(state):
"""
切换右侧BS滑块的All选项
Args:
state (int): 勾选框状态
"""
try:
print(f"切换右侧BS滑块All选项: {state}")
# 根据勾选状态执行相应操作
if state == 2: # 选中状态
print("应用到所有BlendShape")
# TODO: 实现应用到所有BlendShape的逻辑
else: # 未选中状态
print("仅应用到选中的BlendShape")
# TODO: 实现仅应用到选中BlendShape的逻辑
except Exception as e:
print(f"切换右侧BS滑块All选项时出错: {str(e)}")
def toggle_bottom_slider_all(state):
"""
切换底部主滑块的All选项
Args:
state (int): 勾选框状态
"""
try:
print(f"切换底部主滑块All选项: {state}")
# 根据勾选状态执行相应操作
if state == 2: # 选中状态
print("应用到所有表情")
# TODO: 实现应用到所有表情的逻辑
else: # 未选中状态
print("仅应用到当前表情")
# TODO: 实现仅应用到当前表情的逻辑
except Exception as e:
print(f"切换底部主滑块All选项时出错: {str(e)}")
# 滑块更新函数
def update_raw_slider_value(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}")
# 更新控制值
update_control_value(value)
return normalized_value
def update_bs_slider_value(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值
update_blendshape_value(value)
return normalized_value
def update_bottom_slider_value(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)
return normalized_value
# 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:
increase_range()
else:
decrease_range()
def on_raw_slider_changed(value):
"""
处理Raw滑块值变化
Args:
value (int): 滑块值
"""
# 更新显示值
print(f"Raw滑块值变化: {value}")
# 调用实际的更新函数
update_raw_slider_value(value)
def on_bs_slider_changed(value):
"""
处理BlendShape滑块值变化
Args:
value (int): 滑块值
"""
# 更新显示值
print(f"BlendShape滑块值变化: {value}")
# 调用实际的更新函数
update_bs_slider_value(value)
def on_bottom_slider_changed(value):
"""
处理底部主滑块值变化
Args:
value (int): 滑块值
"""
# 更新显示值
print(f"底部主滑块值变化: {value}")
# 调用实际的更新函数
update_bottom_slider_value(value)
def on_control_selection_changed():
"""处理控制列表选择变化"""
print("控制列表选择变化")
update_control_selection()
def on_blendshape_selection_changed():
"""处理BlendShape列表选择变化"""
print("BlendShape列表选择变化")
update_blendshape_selection()
def adjust_bs_range(delta):
"""
调整BlendShape滑块范围
Args:
delta (float): 范围调整值
"""
print(f"调整BlendShape滑块范围: {delta}")
adjust_range(delta)
# 保留原来的函数作为兼容性考虑
def behaviour_temp_utils_function():
"""
Placeholder function for behaviour module
This function will be replaced with actual functionality in future updates
"""
print("Behaviour module temporary function called")
return True
def reposition_joints():
"""
重新定位关节
根据当前选择的模型重新定位关节位置
"""
print("重新定位关节...")
# 这里将来会实现关节重新定位的功能
# 目前仅作为占位函数
cmds.warning("关节重新定位功能尚未实现")