Qualoth一键创建布料和约束
功能演示:
加载方式: Python
打开maya脚本编辑器把代码放在python栏加载,或全选鼠标中键保存到工具架上
源码如下:↓
1 # encoding:utf-8 2 """ 3 @Author: Meng 4 @software: PyCharm 5 @file: QualothDecide.py 6 @time: 2021/12/18 20:39 7 """ 8 from pymel.core import * 9 10 def mui(*args): 11 if window("win",exists=1): 12 deleteUI("win") 13 window("win",title='Qualoth一键创建布料和约束', width=200) 14 columnLayout( adjustableColumn=True ) 15 button( label='选择后一键创建布料和约束',h=80,bgc=(0.25,0.25,0.25),command="QualothDecide()" ) 16 button( label='选择转到布料属性调试窗口',h=40,bgc=(0.25,0.25,0.25),command="shuxing()") 17 showWindow("win") 18 mui() 19 def shuxing(): 20 mel.eval('qlConvertSelectionToClothes()') 21 def QualothDecide(*args): 22 sel= ls(sl=1) 23 idNum = len(sel) 24 for i in sel: 25 select(i) 26 newname=i.split(":") 27 qcloth_mesh= duplicate(rr=0,n=newname[-1]) 28 copymash=parent(qcloth_mesh, w=1) 29 setAttr(str(i+".v"), 0) 30 refoldd=str(newname[0]+ ":" + newname[-1]) 31 print refoldd 32 select(copymash) 33 #创建布料节点 34 qcloth_comm = mel.eval('qlCreateCloth') 35 qcloth_node_Cloth=rename("qlCloth1", i+"___Cloth") 36 print qcloth_node_Cloth 37 #布料属性 38 setAttr((str(qcloth_node_Cloth) + "Shape.lengthScale"),1) 39 setAttr((str(qcloth_node_Cloth) + "Shape.density"),0.05) 40 setAttr((str(qcloth_node_Cloth) + "Shape.stretch"),40) 41 setAttr((str(qcloth_node_Cloth) + "Shape.shear"),0.1) 42 setAttr((str(qcloth_node_Cloth) + "Shape.stretchDamp"),0.01) 43 setAttr((str(qcloth_node_Cloth) + "Shape.bend"),0.5) 44 setAttr((str(qcloth_node_Cloth) + "Shape.bendDamp"),0.1) 45 setAttr((str(qcloth_node_Cloth) + "Shape.bendYield"),0) 46 setAttr((str(qcloth_node_Cloth) + "Shape.bendPlasticity"),0) 47 setAttr((str(qcloth_node_Cloth) + "Shape.airDrag"),0.01) 48 setAttr((str(qcloth_node_Cloth) + "Shape.rubber"), 1) 49 setAttr((str(qcloth_node_Cloth) + "Shape.viscousDamp"),0) 50 setAttr((str(qcloth_node_Cloth) + "Shape.friction"),0) 51 setAttr((str(qcloth_node_Cloth) + "Shape.pressure"),0) 52 setAttr((str(qcloth_node_Cloth) + "Shape.friction"),0) 53 setAttr((str(qcloth_node_Cloth) + "Shape.gravity0"), 0) 54 setAttr((str(qcloth_node_Cloth) + "Shape.gravity1"),-980) 55 setAttr((str(qcloth_node_Cloth) + "Shape.gravity2"), 0) 56 #修改名称mash 57 newmash_out=rename("qlCloth1Out" ,i+"___out") 58 select(str(newmash_out) + ".vtx[0:*]") 59 select(str(i), add=1) 60 #创建约束 61 qcloth_constraints = mel.eval('qlCreateAttachConstraint()') 62 qcloth_constraints_new=rename("qlAttachConstraint1" ,i+"___QlAtt") 63 setAttr((str(qcloth_constraints_new) + ".soft"), 1) 64 select(cl=1) 65 #解算器属性 66 setAttr("qlSolverShape1.startTime", 50) 67 setAttr("qlSolverShape1.frameSamples", 5) 68 setAttr("qlSolverShape1.selfCollision", 1)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# encoding:utf-8 """ @Author: Meng @software: PyCharm @file: QualothDecide.py @time: 2022/07/12 16:52 """ import os, re import random from pymel.core import * from maya.cmds import * if not cmds.pluginInfo('qualoth_2018_x64', loaded=1, q=1): cmds.loadPlugin('qualoth_2018_x64') def mui(*args): if window("win",exists=1): deleteUI("win") window("win",title=u'Qualoth一键创建布料和约束', width=200) columnLayout( adjustableColumn=True ) button( label=u'选择后一键创建布料和约束',h=80,bgc=(0.20,0.20,0.20),command="QualothDecide()" ) button( label=u'选择转到布料属性调试窗口',h=40,bgc=(0.20,0.20,0.20),command="shuxing()") button( label=u'材质随机颜色',h=40,bgc=(0.20,0.20,0.20),command="color_sj()") showWindow("win") mui() def shuxing(*args): mel.eval('qlConvertSelectionToClothes()') def color_sj(*args): sel=ls(sl=True) print sel if sel!=[]: for obj in sel: myShade = shadingNode('lambert',asShader=True,name='Color') myShadeSG=sets(renderable=True,noSurfaceShader=True, name=(myShade+"SG")) connectAttr ((myShade+".outColor"),(myShadeSG+".surfaceShader")) select(obj) sets(forceElement=myShadeSG) colorR1=random.random() colorG1=random.random() colorB1=random.random() setAttr((myShade+".color"),colorR1,colorG1,colorB1,type="double3") else: inViewMessage( amg='请选择待解算模型',pos='midCenter',fade=True) def QualothDecide(*args): sel = ls(sl=1) idNum = len(sel) all = [] modelEditor("modelPanel4", e=True, locators=True) for i in sel: select(i) newname=i.split(":") #复制 #qcloth_mesh= duplicate(rr=0,n=newname[-1]) #移出组 #copymash=parent(qcloth_mesh, w=1) refoldd=str(newname[0]+ ":" + newname[-1]) print refoldd select(i) #创建布料节点 qcloth_comm = mel.eval('qlCreateCloth') qcloth_node_Cloth=rename("qlCloth1", i+"___Cloth") all.append(qcloth_node_Cloth) print qcloth_node_Cloth #布料属性 setAttr((str(qcloth_node_Cloth) + "Shape.lengthScale"),1) setAttr((str(qcloth_node_Cloth) + "Shape.density"),0.05) setAttr((str(qcloth_node_Cloth) + "Shape.stretch"),40) setAttr((str(qcloth_node_Cloth) + "Shape.shear"),0.1) setAttr((str(qcloth_node_Cloth) + "Shape.stretchDamp"),0.01) setAttr((str(qcloth_node_Cloth) + "Shape.bend"),0.5) setAttr((str(qcloth_node_Cloth) + "Shape.bendDamp"),0.1) setAttr((str(qcloth_node_Cloth) + "Shape.bendYield"),0) setAttr((str(qcloth_node_Cloth) + "Shape.bendPlasticity"),0) setAttr((str(qcloth_node_Cloth) + "Shape.airDrag"),0.01) setAttr((str(qcloth_node_Cloth) + "Shape.rubber"), 1) setAttr((str(qcloth_node_Cloth) + "Shape.viscousDamp"),0) setAttr((str(qcloth_node_Cloth) + "Shape.friction"),0) setAttr((str(qcloth_node_Cloth) + "Shape.pressure"),0) setAttr((str(qcloth_node_Cloth) + "Shape.friction"),0) setAttr((str(qcloth_node_Cloth) + "Shape.gravity0"), 0) setAttr((str(qcloth_node_Cloth) + "Shape.gravity1"),-980) setAttr((str(qcloth_node_Cloth) + "Shape.gravity2"), 0) #修改名mash newmash_out=rename("qlCloth1Out" ,i+"___out") all.append(newmash_out) select(str(newmash_out) + ".vtx[0:*]") select(str(i), add=1) #创建约束 qcloth_constraints = mel.eval('qlCreateAttachConstraint()') qcloth_constraints_new=rename("qlAttachConstraint1" ,i+"___QlAtt") all.append(qcloth_constraints_new) setAttr((str(qcloth_constraints_new) + ".soft"), 1) #原始 setAttr(str(i+".visibility"), 1) #主 select(cl=1) QlSolver = rename ("qlSolver1" ,"QlSolver") select(QlSolver,r=1) QlSolverShape = ls(shapes=True) #解算器属性 setAttr(QlSolverShape[0]+".startTime", 50) setAttr(QlSolverShape[0]+".frameSamples", 5) setAttr(QlSolverShape[0]+".selfCollision", 1) #分支 print (all) for i in all : select(i,add=True) group(n = QlSolver+'__z1') #创建显示层 select(cl=1) dlayer = 'Q_Old_Show' dar = ls(type='displayLayer') if dlayer not in dar : createDisplayLayer(nr=1, name=dlayer, number=1) else : print u"已存在Q_Old_Show层" select(sel,r=1) editDisplayLayerMembers(dlayer , sel) #mel.layerEditorLayerButtonVisibilityChange(dlayer) setAttr(dlayer+".v", 0)