学习Python制作的CG行业中基本算是主流软件maya关于刷权重的插件源代码
#=======================================================#mel写的拖动式安装代码
global proc getPath(){
}
string $getFilePath = `whatIs getPath`;
python("import os");
python("getFilePath = \"" + $getFilePath + "\"");
python("tempPath = getFilePath");
python("path = os.path.dirname(tempPath)");
python("def dataPyToMel(file_path):return file_path");
string $finalPath = python("dataPyToMel(path)");
if(`shelfLayout -exists "VioletNight"`){
deleteShelfTab "VioletNight";
}
addNewShelfTab "VioletNight" ;
string $butPath = `shelfLayout -q -fpn "VioletNight"`;
scriptToShelf "" ("import sys\n\ninstall_Path = \'" + $finalPath + "\'\n\nwork_Path = ['%s/scripts/Qt' % install_Path, '%s/scripts/Rig' % install_Path]\n\nfor each in work_Path:\n\n\tif each not in sys.path:\n\n\t\tsys.path.append(each)\n\nimport VN_weightTool\n\nfrom VN_weightTool import *\n\nVN_weightTool.VN_installPath = install_Path\n\nVN_weightTool()") false;
string $butName[] = `shelfLayout -q -ca "VioletNight"`;
shelfButton -e -i ($finalPath + "/icons/VN_01.png") ($butPath + "|" + $butName);
scriptToShelf "" ("import sys\n\ninstall_Path = \'" + $finalPath + "\'\n\nwork_Path = ['%s/scripts/Qt' % install_Path, '%s/scripts/Model' % install_Path]\n\nfor each in work_Path:\n\n\tif each not in sys.path:\n\n\t\tsys.path.append(each)\n\nimport VN_freeToolShelf\n\nfrom VN_freeToolShelf import *\n\nVN_freeToolShelf.VN_installPath = install_Path\n\nVN_freeToolShelf.VN_filePath = '%s/prefs/shelves' % install_Path\n\nVN_freeToolShelf()") false;
string $butName[] = `shelfLayout -q -ca "VioletNight"`;
shelfButton -e -i ($finalPath + "/icons/VN_02.png") ($butPath + "|" + $butName);
#==============================================================================
#刷权重插件真正内容
# -*- coding utf-8 -*-
import maya.cmds as cmds
import maya.mel as mel
from Qt import QtWidgets
class VN_weightTool:
VN_screenWidth = QtWidgets.QApplication.desktop().screenGeometry().width()
VN_screenHeight = QtWidgets.QApplication.desktop().screenGeometry().height()
VN_installPath = ''
def __init__(self):
VN_showWeightToolWin()
def VN_showWeightToolWin(VN_weightWin='VN_weightWinDialog'):
u'''
使用try语句来监控代码段,因为如果变量没有被定义就被使用的话会报错
检查是否存在上次打开的权重窗口,如果有就进行删除
'''
try:
if cmds.window(VN_weightWin, exists=True):
cmds.deleteUI(VN_weightWin)
except NameError:
pass
u'''
加载QT设计的UI文件,把标题名保存到变量中,并对这个窗口进行一次大小编辑然后显示
'''
VN_uiPath = VN_weightTool.VN_installPath + '/UI/VN_weightTool.ui'
VN_weightWin = cmds.loadUI(uiFile=VN_uiPath)
if not cmds.windowPref(VN_weightWin, exists = True):
cmds.deleteUI(VN_weightWin)
VN_weightWin = cmds.loadUI(uiFile=VN_uiPath)
cmds.windowPref(VN_weightWin, e=True, wh=(360, 550),tlc=(VN_weightTool.VN_screenHeight - 850, VN_weightTool.VN_screenWidth - 790))
cmds.showWindow(VN_weightWin)
def VN_showWeightToolContactWin(VN_contactWin='VN_contactDialog'):
u'''
用传递参数的方式来对标题名进行判断,否则一直点击联系紫夜会无限生成信息窗口
'''
try:
if cmds.window(VN_contactWin, exists=True):
cmds.deleteUI(VN_contactWin)
except NameError:
pass
VN_uiPath = VN_weightTool.VN_installPath + '/UI/VN_weightToolContact.ui'
VN_contactWin = cmds.loadUI(uiFile=VN_uiPath)
if not cmds.windowPref(VN_contactWin, exists = True):
cmds.deleteUI(VN_contactWin)
VN_contactWin = cmds.loadUI(uiFile=VN_uiPath)
cmds.windowPref(VN_contactWin, e=True, wh=(400, 330), tlc=(VN_weightTool.VN_screenHeight-850, VN_weightTool.VN_screenWidth-415))
cmds.showWindow(VN_contactWin)
def VN_webSite():
u'''
跳转到B站紫夜的直播间
'''
cmds.showHelp('http://live.bilibili.com/9188936', absolute=True)
def VN_autoSkin():
u'''
判断是否在绘制蒙皮状态,如果不是执行进入
'''
VN_selName = cmds.ls(sl=True)
VN_tempSet = set()
VN_judgmentChange = 0
for i in range(3):
try:
VN_tempName = VN_selName.split('.')
VN_tempSet.add(VN_tempName)
if len(VN_selName.split('.')) != 1:
VN_judgmentChange += 1
except IndexError:
pass
if VN_judgmentChange:
cmds.ConvertSelectionToVertices()
if VN_tempSet:
VN_selSkinObjectHistoryName = []
for each_obj in VN_tempSet:
VN_selSkinObjectHistoryName += cmds.listConnections(cmds.listRelatives(each_obj, shapes=True))
for each in VN_selSkinObjectHistoryName:
if cmds.objectType(each) == 'skinCluster':
break
else:
cmds.confirmDialog(title=u'友情提示', message=u'请选择一个蒙皮的对象再进行此操作', button=['Yes'])
return None
else:
cmds.confirmDialog(title=u'友情提示', message=u'请选择一个蒙皮的对象再进行此操作', button=['Yes'])
return None
if cmds.currentCtx() == 'artAttrSkinContext':
print(u'现在是绘制蒙皮状态... 本操作失效')
else:
cmds.ArtPaintSkinWeightsToolOptions()
def VN_autoPosit():
u'''
在权重列表自动定位当前绘制蒙皮选择的骨骼
'''
if cmds.currentCtx() != 'artAttrSkinContext':
print(u'现在不是绘制蒙皮状态... 本操作失效')
else:
mel.eval('artSkinRevealSelected artAttrSkinPaintCtx;')
def VN_selColor():
u'''
判断是否启用彩色蒙皮
'''
if cmds.currentCtx() == 'artAttrSkinContext':
tempName = cmds.currentCtx()
if cmds.checkBox('colorSkinSwitchcheckBox', q=True, v=True):
cmds.artAttrCtx(tempName, e=True, useColorRamp=True)
else:
cmds.artAttrCtx(tempName, e=True, useColorRamp=False)
def VN_judgmentCustom():
u'''
判断是否开启了使用自定义数值,并以元组的形式返回判断结果和自定义数值的大小
'''
cusValueSwitch = cmds.checkBox('customValueSwitchcheckBox', q=True, v=True)
cusValue = float(cmds.textField('cusValuelineEdit1', q=True, tx=True))
return (cusValueSwitch, cusValue)
def VN_judgmentAutoBrushSwitch():
u'''
判断是否开启了即时生效,如果开启了那么在点击下面减、加、数值、平滑等button时直接生效
'''
if cmds.checkBox('autoBrushSwitchcheckBox', q=True, v=True):
VN_brushSkin()
def VN_brushSkin():
u'''
执行按钮,如果开启即时生效,点击数值等按钮直接执行,不开启只能使用执行按钮进行刷权重(当然场景里面是可以用笔刷刷的,这里说的是数值等按钮的应用)
'''
if cmds.currentCtx() != 'artAttrSkinContext':
print(u'现在不是绘制蒙皮状态... 本操作失效')
else:
tempName = cmds.currentCtx()
cmds.artAttrSkinPaintCtx(tempName, e=True, clear=True)
def VN_cusAddSkin():
u'''
自定义数值加法专用按钮,如果没开启使用自定义会无效
'''
if VN_judgmentCustom():
VN_addSkin(VN_judgmentCustom())
else:
print(u'自定义数值未启用... 本操作失效')
def VN_cusSubSkin():
u'''
自定义数值减法专用按钮,如果没开启使用自定义会无效
'''
if VN_judgmentCustom():
VN_subSkin(VN_judgmentCustom())
else:
print(u'自定义数值未启用... 本操作失效')
def VN_addSkin(num=0):
u'''
设置蒙皮增量的状态,增量的大小取决与按钮反馈的大小(每个按钮里面都有点击传递进函数的参数数值)
'''
if cmds.currentCtx() != 'artAttrSkinContext':
print(u'现在不是绘制蒙皮状态... 本操作失效')
else:
tempName = cmds.currentCtx()
cmds.artAttrSkinPaintCtx(tempName, edit=True, sao='additive')
cmds.artAttrSkinPaintCtx(tempName, edit=True, opacity=num)
mel.eval('artSkinSetSelectionValue 1 false artAttrSkinPaintCtx artAttrSkin;')
VN_judgmentAutoBrushSwitch()
def VN_subSkin(num=0):
u'''
设置蒙皮减量的状态,增量的大小取决与按钮反馈的大小(每个按钮里面都有点击传递进函数的参数数值)
'''
if cmds.currentCtx() != 'artAttrSkinContext':
print(u'现在不是绘制蒙皮状态... 本操作失效')
else:
tempName = cmds.currentCtx()
cmds.artAttrSkinPaintCtx(tempName, edit=True, sao='absolute')
cmds.artAttrSkinPaintCtx(tempName, edit=True, opacity=num)
mel.eval('artSkinSetSelectionValue 0 false artAttrSkinPaintCtx artAttrSkin;')
VN_judgmentAutoBrushSwitch()
def VN_smoothSkin():
u'''
设置蒙皮平滑状态
'''
if cmds.currentCtx() != 'artAttrSkinContext':
print(u'现在不是绘制蒙皮状态... 本操作失效')
else:
cusNum = int(cmds.textField('cusValuelineEdit2', q=True, tx=True))
for i in range(int(cusNum)):
if VN_judgmentCustom():
num = VN_judgmentCustom()
else:
num = 1
tempName = cmds.currentCtx()
cmds.artAttrSkinPaintCtx(tempName, edit=True, sao='smooth')
cmds.artAttrSkinPaintCtx(tempName, edit=True, opacity=num)
VN_judgmentAutoBrushSwitch()
def VN_mirrorSkin():
u'''
打开maya默认的镜像权重面板
'''
cmds.MirrorSkinWeightsOptions()
def VN_copySkin():
u'''
打开maya默认的拷贝权重面板
'''
cmds.CopySkinWeightsOptions()
不知道为何不能上传图片 ,插件图片如下
页:
[1]