接上篇将骨骼均匀放置在曲线后,设置动力学驱动骨骼。需要说明的是,由于动力学化曲线以后,会自动创建出一条曲线作为动力学曲线。原有的曲线仅仅作为动力学曲线开始位置。由于我没有找到返回创建的曲线名称的方法。所以手动的复制了一条曲线链接到follicle上,方便后面绑定使用。
依然先选择曲线在选择根骨骼运行脚本。
import pymel.core as pm
sl = pm.ls(selection=1)
cv = sl[0]
bone = pm.listRelatives(sl[1],allDescendents=True)
bone.append(sl[1])
bone.reverse()
pm.rebuildCurve(cv,constructionHistory=False,replaceOriginal=True,
rebuildType=0,endKnots=1,keepRange=0,keepControlPoints=True,
keepEndPoints=True,keepTangents=False,spans=0,
degree=3,tolerance=0)
for i in range(0,len(bone)):
pos = py.pointOnCurve(cv,parameter=(i*(1.0/len(bone)*(len(bone)/(len(bone)-1.0)))),position=1)
py.move(pos[0],pos[1],pos[2],bone[i])
pm.joint(bone[0],edit=True,orientJoint='xyz',secondaryAxisOrient='yup',
children=True,zeroScaleOrient=True)
pm.setAttr(bone[len(bone)-1]+'.jointOrient',0,0,0,type='double3')
pm.select(cv)
pm.mel.makeCurvesDynamic(2, ["1", "0", "1", "1", "0"])
follicles = pm.listRelatives(cv,allParents=True,fullPath=True,shapes=True)
follicles = pm.listRelatives(follicles, children=True,shapes=True)
dyCV = pm.duplicate(cv,name=(cv+'_Dynamic'))
pm.connectAttr(follicles[0]+'.outCurve' ,dyCV[0]+'Shape.create')
ikhan = pm.ikHandle(name = bone[0]+'_ikSplineSolver',endEffector = bone[len(bone)-1],startJoint = bone[0],solver = 'ikSplineSolver',
curve = dyCV[0], createCurve = False)