----------------------------------------生长绑定脚本----------------------------------------------------
import maya.cmds as cmd
import maya.mel as mel
def cm(fun):
ret=mel.eval_r(fun)
return ret
def tem(name):#####判断intermediateobject属性的情况
temp = cmd.getAttr(name+".intermediateObject")
if type(temp)==type(True):
if temp==True:return True
else:return False
if type(temp)==type([0,0]):
if temp[-1]==True:return True
else:return False
def getshape(objectT):###返回对象实际在显示的shape形态节点
objectshape = cmd.listRelatives(objectT,shapes=True)
if len(objectshape)!=1:
for shape in objectshape:
if tem(shape)!= True:
return shape
else:
return objectshape[0]
def flowcurveControl(curves):###
ci = cmd.createNode("curveInfo")
curveshape = cmd.listRelatives(curves,shapes=True)[0]
cmd.connectAttr(curveshape+".worldSpace[0]",ci+".inputCurve",f=True)
cvspan = cmd.getAttr(getshape(curves)+".controlPoints",size=True)
jointlist = []
controlgrouplist = []
loclist = []
for i in range(cvspan):
jointpos = cmd.xform(curves+".ep["+str(i)+"]",q=True,t=True,ws=True)
loc = cmd.spaceLocator()[0]
loclist.append(loc)
cmd.setAttr(loc+".sx",3)
cmd.setAttr(loc+".sy",3)
cmd.setAttr(loc+".sz",3)
jo = cmd.joint()
jointlist.append(jo)
##cmd.parent(jo,loc)
groupnode = cmd.group(loc)
controlgrouplist.append(groupnode) ##控制器打组
cmd.move(jointpos[0],jointpos[1],jointpos[2],rpr=True)
cmd.connectAttr(ci+".controlPoints["+str(i)+"]",groupnode+".translate",f=True)
if i == 0:
radiusCurve = cmd.circle(c=jointpos,nr=[0,1,0],sw=360,r=4,d=3)[0]
cmd.select(radiusCurve+".cv[1]",radiusCurve+".cv[3]",radiusCurve+".cv[5]",radiusCurve+".cv[7]")
cmd.scale(0.002,0.002,0.002,r=True,p=jointpos)
cmd.select(radiusCurve)
cmd.CenterPivot()
cmd.select(cl=True)
cmd.parent(radiusCurve,groupnode)
cmd.select(cl=True)
return [jointlist,controlgrouplist,radiusCurve,loclist]
def CusAddAttribute(goalobjectAttr,modifyobjectAttr,attrtype):
name = goalobjectAttr.split(".")[1]
goalobject = goalobjectAttr.split(".")[0]
if cmd.attributeQuery(name,node =goalobject,ex=True) != True:
addAttribute((name,attrtype),goalobject)
cmd.connectAttr(goalobjectAttr,modifyobjectAttr,f=True)
def addAttribute(atrname,particleshape):###
if cmd.objectType(particleshape)=="particle":
cmd.addAttr(particleshape,ln=atrname[0]+"0",dt=atrname[1])
cmd.addAttr(particleshape,ln=atrname[0],dt=atrname[1])
else:
cmd.addAttr(particleshape,ln=atrname[0],at=atrname[1])
cmd.setAttr(particleshape+"."+atrname[0],e=True,keyable=True)
sel= cmd.ls(sl=True,l=True,fl=True)
goalobject=sel[-1]
sel.remove(goalobject)
growlist=[]
for s in sel:
dupcurve=cmd.duplicate(s)[0]
cmd.select(dupcurve,goalobject)
warpnode=cm('doWrapArgList "7" { "1","0.01","0.02", "2", "0", "1", "0", "0" }')
cmd.select(s)
joints=flowcurveControl(dupcurve)##复制出来得曲线生成骨骼和控制器(骨骼放在控制器下面)
cmd.select(joints[0],s)
cmd.SmoothBindSkin()
JointGroup=cmd.rename(cmd.group(joints[1]),"GrowJoint")
curveshape=getshape(s)
strokenode=cmd.connectionInfo(curveshape+".worldSpace[0]",dfs=True)[0].split(".")[0]
brush=cmd.connectionInfo(strokenode+".brush",sfd=True).split(".")[0]
stroketrs=cmd.listRelatives(strokenode,parent=True)[0]
width=cmd.getAttr( brush+".brushWidth")
grow=cmd.getAttr( strokenode+".maxClip")
CusAddAttribute(joints[2]+".grow",strokenode+".maxClip","float")
CusAddAttribute(joints[2]+".width",brush+".brushWidth","float")
cmd.setAttr(joints[2]+".width",width)
cmd.setAttr(joints[2]+".grow",grow)
cmd.hide(joints[0],dupcurve,s)
for l in joints[3]:
CusAddAttribute(joints[2]+".conVis",l+".v","bool")
sourcecurve=cmd.rename(s,"SourceCurve")
dupcu=cmd.rename(dupcurve,"DuplicateCurve")
strok=cmd.rename(stroketrs,"GrowStroke")
cmd.rename(joints[2],"GrowControl")
growlist.append(cmd.rename(cmd.group(JointGroup,sourcecurve,dupcu,strok),"Grow"))
cmd.rename(cmd.group(growlist),"GROW_LIST")
#####作者######
#####用法选中曲线选中需要吸附得模型执行脚本################
(来源:tiancgVFX)
原文链接: http://blog.sina.com.cn/tiancgweb