MetaFusion/scripts/utils/RBFDeformerWindow.py
2025-02-07 05:10:30 +08:00

200 lines
6.2 KiB
Python
Raw Permalink 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 -*-
import maya.cmds as cmds
from scripts.utils.Core import Descriptor, RBFDeformer
def rbf_deformer_window():
"""
创建RBF变形器窗口
"""
# 检查主窗口是否存在
if not cmds.window('SuperRiggingEditor', exists=True):
return
# 如果RBF窗口已存在则删除
if cmds.window('RBFDeformerWin', exists=True):
cmds.deleteUI('RBFDeformerWin')
# 设置UI文本支持中英文
texts = {
'Load': 'Load...',
'Original': 'Original:',
'Deformed': 'Deformed:',
'Radius': 'Radius:',
'Points': 'Points:',
'Execute': 'Execute'
}
if Descriptor(l=True) == "ZH":
texts.update({
'Load': '加载...',
'Original': '原始模型:',
'Deformed': '变形模型:',
'Radius': '搜索半径:',
'Points': '采样点数:',
'Execute': '开始执行'
})
# 创建窗口
window = cmds.window('RBFDeformerWin',
title="RBF Deformer",
width=310,
height=100,
sizeable=True,
toolbox=True,
parent='SuperRiggingEditor')
# 主布局
cmds.columnLayout(adjustableColumn=True,
columnAttach=('both', 5),
rowSpacing=2,
columnWidth=150)
cmds.separator(height=10, style="in")
# 原始模型和变形模型选择
cmds.textFieldButtonGrp('RBFDeformer_Original',
label=texts['Original'],
buttonLabel=texts['Load'],
columnWidth3=[70, 1, 30],
adjustableColumn2=2,
buttonCommand=rbf_deformer_load_original)
cmds.textFieldButtonGrp('RBFDeformer_Deformed',
label=texts['Deformed'],
buttonLabel=texts['Load'],
columnWidth3=[70, 1, 30],
adjustableColumn2=2,
buttonCommand=rbf_deformer_load_deformed)
cmds.separator(height=10, style="in")
# 半径设置
cmds.rowLayout(numberOfColumns=3,
columnWidth3=[70, 70, 1],
columnAttach3=['right', 'left', 'left'],
adjustableColumn3=3)
cmds.text(label=texts['Radius'])
cmds.floatField('RBFDeformer_RadiusField',
width=70,
maxValue=2,
minValue=0.001,
value=0.1,
changeCommand=set_radius_field)
cmds.floatSlider('RBFDeformer_RadiusSlider',
maxValue=2,
minValue=0.001,
value=0.1,
dragCommand=set_radius_field)
cmds.setParent('..')
# 采样点设置
cmds.rowLayout(numberOfColumns=3,
columnWidth3=[70, 70, 1],
columnAttach3=['right', 'left', 'left'],
adjustableColumn3=3)
cmds.text(label=texts['Points'])
cmds.intField('RBFDeformer_PointsField',
width=70,
maxValue=10000,
minValue=100,
value=2000,
changeCommand=set_points_field)
cmds.intSlider('RBFDeformer_PointsSlider',
maxValue=10000,
minValue=100,
value=2000,
dragCommand=set_points_field)
cmds.setParent('..')
cmds.separator(height=10, style="in")
# 执行按钮
cmds.button(label=texts['Execute'],
align="center",
command=rbf_deformer_execute)
cmds.separator(height=10, style="in")
cmds.showWindow(window)
def rbf_deformer_execute(*args):
"""
执行RBF变形器操作
"""
# 获取UI值
original = cmds.textFieldButtonGrp('RBFDeformer_Original', query=True, text=True)
deformed = cmds.textFieldButtonGrp('RBFDeformer_Deformed', query=True, text=True)
radius = cmds.floatField('RBFDeformer_RadiusField', query=True, value=True)
points = cmds.intField('RBFDeformer_PointsField', query=True, value=True)
# 检查模型顶点数是否一致
org_vtx = cmds.polyEvaluate(original, vertex=True)
def_vtx = cmds.polyEvaluate(deformed, vertex=True)
if org_vtx != def_vtx:
cmds.error("The topology of the two models is inconsistent...")
return
# 获取选中的目标模型
selection = cmds.ls(selection=True)
# 执行RBF变形
RBFDeformer(
r=radius,
np=points,
rbf=1,
m=[original, deformed],
t=selection
)
def rbf_deformer_load_original(*args):
"""
加载原始模型
"""
selection = cmds.ls(selection=True)
if selection:
cmds.textFieldButtonGrp('RBFDeformer_Original', edit=True, text=selection[0])
def rbf_deformer_load_deformed(*args):
"""
加载变形模型
"""
selection = cmds.ls(selection=True)
if selection:
cmds.textFieldButtonGrp('RBFDeformer_Deformed', edit=True, text=selection[0])
def set_radius_field(*args):
"""
更新半径滑块值
"""
value = cmds.floatSlider('RBFDeformer_RadiusSlider', query=True, value=True)
cmds.floatField('RBFDeformer_RadiusField', edit=True, value=value)
def set_radius_field(*args):
"""
更新半径输入框值
"""
value = cmds.floatField('RBFDeformer_RadiusField', query=True, value=True)
cmds.floatSlider('RBFDeformer_RadiusSlider', edit=True, value=value)
def set_points_field(*args):
"""
更新采样点滑块值
"""
value = cmds.intSlider('RBFDeformer_PointsSlider', query=True, value=True)
cmds.intField('RBFDeformer_PointsField', edit=True, value=value)
def set_points_field(*args):
"""
更新采样点输入框值
"""
value = cmds.intField('RBFDeformer_PointsField', query=True, value=True)
cmds.intSlider('RBFDeformer_PointsSlider', edit=True, value=value)
# 如果直接运行此脚本
if __name__ == '__main__':
rbf_deformer_window()