199 lines
6.3 KiB
Python
199 lines
6.3 KiB
Python
|
#!/usr/bin/env python
|
|||
|
# -*- coding: utf-8 -*-
|
|||
|
|
|||
|
"""
|
|||
|
版权所有: 深圳时光科技有限公司
|
|||
|
联系方式: q.100@qq.com
|
|||
|
创建日期: 2024/11/18
|
|||
|
"""
|
|||
|
|
|||
|
import maya.cmds as cmds
|
|||
|
|
|||
|
def sg_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 cmds.SGDescriptor(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=sg_rbf_deformer_load_original)
|
|||
|
|
|||
|
cmds.textFieldButtonGrp('RBFDeformer_Deformed',
|
|||
|
label=texts['Deformed'],
|
|||
|
buttonLabel=texts['Load'],
|
|||
|
columnWidth3=[70, 1, 30],
|
|||
|
adjustableColumn2=2,
|
|||
|
buttonCommand=sg_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=sg_set_radius_slider)
|
|||
|
cmds.floatSlider('RBFDeformer_RadiusSlider',
|
|||
|
maxValue=2,
|
|||
|
minValue=0.001,
|
|||
|
value=0.1,
|
|||
|
dragCommand=sg_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=sg_set_points_slider)
|
|||
|
cmds.intSlider('RBFDeformer_PointsSlider',
|
|||
|
maxValue=10000,
|
|||
|
minValue=100,
|
|||
|
value=2000,
|
|||
|
dragCommand=sg_set_points_field)
|
|||
|
cmds.setParent('..')
|
|||
|
|
|||
|
cmds.separator(height=10, style="in")
|
|||
|
|
|||
|
# 执行按钮
|
|||
|
cmds.button(label=texts['Execute'],
|
|||
|
align="center",
|
|||
|
command=sg_rbf_deformer_execute)
|
|||
|
|
|||
|
cmds.separator(height=10, style="in")
|
|||
|
|
|||
|
cmds.showWindow(window)
|
|||
|
|
|||
|
def sg_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变形
|
|||
|
cmds.SGRBFDeformer(r=radius, np=points, rbf=1, m=[original, deformed], t=selection)
|
|||
|
|
|||
|
def sg_rbf_deformer_load_original(*args):
|
|||
|
"""
|
|||
|
加载原始模型
|
|||
|
"""
|
|||
|
selection = cmds.ls(selection=True)
|
|||
|
if selection:
|
|||
|
cmds.textFieldButtonGrp('RBFDeformer_Original', edit=True, text=selection[0])
|
|||
|
|
|||
|
def sg_rbf_deformer_load_deformed(*args):
|
|||
|
"""
|
|||
|
加载变形模型
|
|||
|
"""
|
|||
|
selection = cmds.ls(selection=True)
|
|||
|
if selection:
|
|||
|
cmds.textFieldButtonGrp('RBFDeformer_Deformed', edit=True, text=selection[0])
|
|||
|
|
|||
|
def sg_set_radius_field(*args):
|
|||
|
"""
|
|||
|
更新半径滑块值
|
|||
|
"""
|
|||
|
value = cmds.floatSlider('RBFDeformer_RadiusSlider', query=True, value=True)
|
|||
|
cmds.floatField('RBFDeformer_RadiusField', edit=True, value=value)
|
|||
|
|
|||
|
def sg_set_radius_slider(*args):
|
|||
|
"""
|
|||
|
更新半径输入框值
|
|||
|
"""
|
|||
|
value = cmds.floatField('RBFDeformer_RadiusField', query=True, value=True)
|
|||
|
cmds.floatSlider('RBFDeformer_RadiusSlider', edit=True, value=value)
|
|||
|
|
|||
|
def sg_set_points_field(*args):
|
|||
|
"""
|
|||
|
更新采样点滑块值
|
|||
|
"""
|
|||
|
value = cmds.intSlider('RBFDeformer_PointsSlider', query=True, value=True)
|
|||
|
cmds.intField('RBFDeformer_PointsField', edit=True, value=value)
|
|||
|
|
|||
|
def sg_set_points_slider(*args):
|
|||
|
"""
|
|||
|
更新采样点输入框值
|
|||
|
"""
|
|||
|
value = cmds.intField('RBFDeformer_PointsField', query=True, value=True)
|
|||
|
cmds.intSlider('RBFDeformer_PointsSlider', edit=True, value=value)
|
|||
|
|
|||
|
# 如果直接运行此脚本
|
|||
|
if __name__ == '__main__':
|
|||
|
sg_rbf_deformer_window()
|