def gizmoPrepareRig(): print 'Prepare gizmo' rig_transform(0, name='headJAWorld', target='headJALocal_GRP') rig_transform(0, name='headShapeWorld', target='headJALocal_GRP') rig_bipedPrepare()
def facialTransformHierarchy(joints, parent): parentTrans = parent.replace('_JNT', '_GRP') if not cmds.objExists(parentTrans): parentTrans = rig_transform(0, name=parent.replace('_JNT', ''), target=parent).object for jnt in joints: mirrorJnt = rig_nameMirror(jnt) if jnt == mirrorJnt: print 'joint ' + jnt + ' is middle joint' mirrorJnt = '' for j in (jnt, mirrorJnt): if cmds.objExists(j): offset = rig_transform(0, name=j.replace('JA_JNT', 'Offset'), target=j, parent=parentTrans).object loc1 = rig_transform(0, name=j.replace('JA_JNT', '_sdk1'), target=offset, type='locator', parent=offset).object loc2 = rig_transform(0, name=j.replace('JA_JNT', '_sdk2'), target=loc1, type='locator', parent=loc1).object cmds.parent(j, loc2)
def rig_curveBetweenTwoPoints(start,end, name='curveBetween' , degree=1, colour='white', parent='allModel_GRP'): startPos = pm.xform( start, translation=True, query=True, ws=True) endPos = pm.xform( end, translation=True, query=True, ws=True) pm.select(cl=True) startJnt = pm.joint(name=name+'Start_JNT') pm.pointConstraint( start, startJnt ) pm.select(cl=True) endJnt = pm.joint(name=name+'End_JNT') pm.pointConstraint( end, endJnt ) curve = pm.curve( n=name+'_CRV', d=degree, p=(startPos, endPos), k=(0,1) ) sc = pm.skinCluster( (startJnt, endJnt),curve , tsb=True, dr=1) pm.skinPercent( sc, curve.cv[0],tv=(startJnt, 1) ) pm.skinPercent( sc, curve.cv[1],tv=(endJnt, 1) ) col = name_to_rgb(colour) curve.overrideColorRGB.set(col[0], col[1], col[2]) topGrp = 'puppetLinearCurves_GRP' if not pm.objExists(topGrp): topGrp = rig_transform(0, name='puppetLinearCurves', type='group', parent=parent).object pm.parent(curve,startJnt,endJnt, topGrp) pm.setAttr(curve+".inheritsTransform", 0) pm.setAttr(curve+".template", 1) pm.hide( startJnt, endJnt ) return curve
def facialShapeDriver(): shapeDriver = 'facialShapeDriver_LOC' if not cmds.objExists(shapeDriver): shapeDriver = rig_transform(0, name='facialShapeDriver', type='locator', parent='rig_GRP').object shapeDriver = pm.PyNode(shapeDriver) shapes = defaultShapeDriverList() pm.addAttr(shapeDriver, ln='SHAPE', at='enum', enumName='___________', k=True) shapeDriver.SHAPE.setLocked(True) for shape in shapes: print shape pm.addAttr(shapeDriver, longName=shape, at='float', k=True, min=0, max=1, dv=0)
def facialTransformHierarchyChildren(joints): for j in joints: parentJnt = cmds.listRelatives(j, p=True)[0] offset = rig_transform( 0, name=j.replace('JA_JNT', 'Offset'), target=j, ).object loc1 = rig_transform(0, name=j.replace('JA_JNT', '_sdk1'), target=offset, type='locator', parent=offset).object loc2 = rig_transform(0, name=j.replace('JA_JNT', '_sdk2'), target=loc1, type='locator', parent=loc1).object cmds.parent(j, loc2) cmds.parentConstraint(parentJnt, offset, mo=True)
def __init__(self, character, root, **kwds): self.character = character self.root = root try: pm.select(cl=True) self.globalCtrl = rig_control(name='global', colour='white', shape='arrows', con=0, showAttrs=['sx', 'sy', 'sz']) self.topNode = rig_transform(0, name=self.character + 'RigSkeletonTop', child=self.globalCtrl.offset).object self.skeleton = rig_transform(0, name='skeleton', child=self.root, parent=self.globalCtrl.ctrl).object connectAttrToVisObj(self.globalCtrl.ctrl, 'skeletonVis', self.skeleton, defaultValue=1) pm.select(cl=True) self.sup = super(skeleton, self) self.sup.__init__(self.topNode, **kwds) except Exception as e: raise
def facialMirrorSDKLocator(sdkLoc): mirror = 'facialtmpMirror_GRP' if cmds.objExists(mirror): cmds.delete(mirror) mirror = rig_transform(0, name='facialtmpMirror').object cmds.setAttr(mirror + '.scaleX', 1) copy = 'facialtmp_GRP' if cmds.objExists(copy): cmds.delete(copy) copy = rig_transform(0, name='facialtmp', target=sdkLoc, parent=mirror).object cmds.setAttr(mirror + '.scaleX', -1) mirrorLoc = rig_nameMirror(sdkLoc) print 'mirrorLoc = ' + mirrorLoc if cmds.objExists(mirrorLoc): con = cmds.parentConstraint(copy, mirrorLoc) cmds.dgdirty(allPlugs=True)
def connectIkFkSwitch(self, chains, module, name='rigSwitch'): # switch switchParent = module.parts if pm.objExists('rig_GRP'): switchParent = 'rig_GRP' if not pm.objExists(self.switchLoc): self.switchLoc = pm.PyNode( rig_transform(0, type='locator', name='ikFkSwitch', parent=switchParent).object) pm.addAttr(self.switchLoc, longName=name, at='float', k=True, min=0, max=1) # blend joints together print 'chain[0] ' + str(chains[0]) print 'chain[1] ' + str(chains[1]) print 'chain[2] ' + str(chains[2]) for i in range(0, len(chains[0])): blendColors(chains[1][i], chains[2][i], chains[0][i], name=name + str(i), driverAttr=self.switchLoc + '.' + name, attribute='rotate') switchAttr = getattr(self.switchLoc, name) pm.connectAttr(switchAttr, module.top.ikFkSwitch)
def make(self): listOrigJoints = mc.listRelatives(self.rootJoint, type="joint", ad=True) listOrigJoints.append(self.rootJoint) listOrigJoints.reverse() listJoints = [] if self.makeDynamic: listJoints = rig_jointCopyChain(self.rootJoint, replaceName=(self.name, self.name + 'ChainSpline')) self.origRootJoint = str(self.rootJoint) self.rootJoint = listJoints[0] else: listJoints = listOrigJoints ''' rig_makeSpline(string $baseName, int $nControls, string $controlType, int $detail, int $nRead, string $readType, string $ctrls[], string $reads[], int $bConstrainMid ) ''' # make cMus tail joints mm.eval('string $ctrls[];string $reads[];rig_makeSpline( "' + self.name + '", 4, "cube", 8, ' + str(self.numIKCtrls) + ', "joint", $ctrls, $reads, 0);') # place them every thirds if len(self.splinePosList) == 0: thirds = len(listJoints) / 3 pm.delete( pm.parentConstraint(self.rootJoint, self.name + 'BaseIKOffset_GRP')) pm.delete( pm.parentConstraint(listJoints[thirds], self.name + 'MidAIKOffset_GRP')) pm.delete( pm.parentConstraint(listJoints[thirds + thirds], self.name + 'MidBIKOffset_GRP')) pm.delete( pm.parentConstraint(listJoints[len(listJoints) - 2], self.name + 'TipIKOffset_GRP')) elif len(self.splinePosList) > 0: pm.delete( pm.parentConstraint(self.splinePosList[0], self.name + 'BaseIKOffset_GRP')) pm.delete( pm.parentConstraint(self.splinePosList[1], self.name + 'MidAIKOffset_GRP')) pm.delete( pm.parentConstraint(self.splinePosList[2], self.name + 'MidBIKOffset_GRP')) pm.delete( pm.parentConstraint(self.splinePosList[3], self.name + 'TipIKOffset_GRP')) tailModule = rig_ikChainSpline(self.name, self.rootJoint, ctrlSize=self.ctrlSize, parent=self.parent, numIkControls=self.numIKCtrls, numFkControls=self.numFKCtrls, dWorldUpAxis=self.dWorldUpAxis) fkBaseCtrl = pm.PyNode(self.name + 'FKA_CTRL') fkBaseName = self.name + 'FKA_CTRL' if self.makeLag: pm.addAttr(fkBaseCtrl, longName='startFrame', attributeType="long", defaultValue=1, keyable=True) pm.addAttr(fkBaseCtrl, ln='lagExpr', at='enum', enumName='___________', k=True) fkBaseCtrl.lagExpr.setLocked(True) pm.addAttr(fkBaseCtrl, longName='lagBlend', attributeType="double", min=0, max=10, defaultValue=10, keyable=True) pm.addAttr(fkBaseCtrl, longName='lagStiffness', attributeType="double", min=0, max=10, defaultValue=0, keyable=True) pm.addAttr(fkBaseCtrl, longName='lagStiffnessBlend', attributeType="double", min=0, max=1, defaultValue=0, keyable=False) rig_animDrivenKey(fkBaseCtrl.lagStiffness, (0, 10), fkBaseCtrl.lagStiffnessBlend, (0, 1)) pm.addAttr(fkBaseCtrl, longName='upDownMult', attributeType="long", min=0, max=1, defaultValue=1, keyable=True) pm.addAttr(fkBaseCtrl, longName='leftRightMult', attributeType="long", min=0, max=1, defaultValue=1, keyable=True) # tail upgrade prevCtrl = fkBaseName tailLagGrp = rig_transform(0, name=self.name + 'Lag', parent=tailModule.parts).object tailJnts = pm.listRelatives(self.name + 'SplineJoints_GRP', type='joint') dynJnts = [] if self.makeDynamic: for i in range(0, len(tailJnts)): tailNme = tailJnts[i].stripNamespace() tailDyn = tailNme.replace('IK', 'DynJ') tailDyn = tailDyn.replace('_JNT', '') tailDyn = rig_transform(0, name=tailDyn, type='joint', target=tailJnts[i]).object dynJnts.append(tailDyn) pm.addAttr(fkBaseCtrl, ln='Dynamics', at='enum', enumName='___________', k=True) pm.addAttr(fkBaseCtrl, longName='dynamicBlend', attributeType="double", min=0, max=10, defaultValue=0, keyable=True) pm.addAttr(fkBaseCtrl, longName='stiffness', attributeType="double", min=0, max=10, defaultValue=5, keyable=True) for i in range(1, len(tailJnts)): tailNme = tailJnts[i].stripNamespace() tailIK = tailJnts[i] tailFK = tailNme.replace('IK', 'FK') tailFK = tailFK.replace('_JNT', '') constrainObject(tailFK + 'Modify2_GRP', [tailFK + 'Modify1_GRP', tailIK], tailFK + '_CTRL', ['parent', 'IK'], type='parentConstraint') # make lag reference locators if self.makeLag: lagOffset = rig_transform(0, name=tailFK + 'LagOffset', parent=tailLagGrp, target=tailFK + '_CTRL').object lagExpLoc = rig_transform(0, name=tailFK + 'Lag', type='locator', parent=lagOffset, target=tailFK + '_CTRL').object lagExpRefLoc = rig_transform(0, name=tailFK + 'LagRef', type='locator', parent=lagOffset, target=tailFK + '_CTRL').object lagExpDriveLoc = rig_transform(0, name=tailFK + 'LagDrive', type='locator', parent=lagExpRefLoc, target=tailFK + '_CTRL').object pm.parentConstraint(self.spine, lagOffset, mo=True) pm.parentConstraint(prevCtrl, lagExpRefLoc, mo=True) con = pm.parentConstraint(lagExpRefLoc, lagExpLoc, lagExpDriveLoc, mo=True, sr=('x', 'y', 'z')) targets = con.getWeightAliasList() rig_animDrivenKey(fkBaseCtrl.lagBlend, (0, 10), targets[0], (1, 0)) rig_animDrivenKey(fkBaseCtrl.lagBlend, (0, 10), targets[1], (0, 1)) mm.eval( 'expression -o ("' + lagExpLoc + '") -n ("' + tailFK + 'Lag_EXP") -s ("$attrStart = ' + fkBaseName + '.startFrame;vector $refLoc = <<' + lagExpRefLoc + '.translateX,' + lagExpRefLoc + '.translateY,' + lagExpRefLoc + '.translateZ>>;vector $ball = <<' + lagExpLoc + '.translateX,' + lagExpLoc + '.translateY,' + lagExpLoc + '.translateZ>>;$stiffness = 0.9+(0.1*' + fkBaseName + '.lagStiffnessBlend);$friction = 1.0;vector $velocity;vector $oldVelocity;$distanceVector = ($refLoc - $ball)/2.0;$force = $distanceVector * $stiffness;$oldVelocity = $oldVelocity +(($ball+$force)-$ball);' + lagExpLoc + '.translateX=((' + lagExpLoc + '.translateX+$oldVelocity.x)*$friction)*' + fkBaseName + '.leftRightMult;' + lagExpLoc + '.translateY=((' + lagExpLoc + '.translateY+$oldVelocity.y)*$friction)*' + fkBaseName + '.upDownMult;' + lagExpLoc + '.translateZ=((' + lagExpLoc + '.translateZ+$oldVelocity.z)*$friction)*' + fkBaseName + '.upDownMult;if(frame == $attrStart){$velocity = <<0,0,0>>;}if(frame == $attrStart){' + lagExpLoc + '.translateX = 0;' + lagExpLoc + '.translateY= 0;' + lagExpLoc + '.translateZ = 0;}") -ae 1 -uc all ;') for at in ('tx', 'ty', 'tz'): pm.connectAttr(lagExpDriveLoc + '.' + at, tailFK + 'Modify1_GRP.' + at, f=True) prevCtrl = tailFK + '_CTRL' pm.parentConstraint(self.name + 'FKACon_GRP', self.name + 'BaseIKOffset_GRP', mo=True) constrainObject( self.name + 'MidAIKOffset_GRP', [self.name + 'FKACon_GRP', self.parent, self.worldSpace], self.name + 'MidAIK_CTRL', ['base', self.parentName, 'world'], type='parentConstraint') constrainObject(self.name + 'MidBIKOffset_GRP', [ self.name + 'FKACon_GRP', self.name + 'MidAIKCon_GRP', self.parent, self.worldSpace ], self.name + 'MidBIK_CTRL', ['base', 'FK', self.parentName, 'world'], type='parentConstraint') constrainObject(self.name + 'TipIKOffset_GRP', [ self.name + 'FKACon_GRP', self.name + 'MidBIKCon_GRP', self.parent, self.worldSpace ], self.name + 'TipIK_CTRL', ['base', 'FK', self.parentName, 'world'], type='parentConstraint') ctrlSizeHalf = [ self.ctrlSize / 2.0, self.ctrlSize / 2.0, self.ctrlSize / 2.0 ] ctrlSizeQuarter = [ self.ctrlSize / 4.0, self.ctrlSize / 4.0, self.ctrlSize / 4.0 ] self.ctrlSize = [self.ctrlSize, self.ctrlSize, self.ctrlSize] # scale ctrls for ctrl in (self.name + 'MidAIK_CTRL', self.name + 'MidBIK_CTRL', self.name + 'TipIK_CTRL'): c = pm.PyNode(ctrl) pm.scale(c.cv, self.ctrlSize[0], self.ctrlSize[0], self.ctrlSize[0]) pm.move(c.cv, [0, 2 * self.ctrlSize[0], 0], relative=True, worldSpace=True) tailPointer = rig_control(name=self.name + 'Pointer', shape='pyramid', lockHideAttrs=['rx', 'ry', 'rz'], colour='white', parentOffset=tailModule.controls, rotateOrder=2, scale=self.ctrlSize) pm.delete( pm.parentConstraint(listJoints[len(listJoints) - 2], tailPointer.offset)) constrainObject(tailPointer.offset, [self.parent, self.spine, self.worldSpace], tailPointer.ctrl, [self.parentName, 'fullBody', 'world'], type='parentConstraint') tailPointerBase = rig_transform(0, name=self.name + 'PointerBase', type='locator', parent=tailModule.parts, target=self.name + 'FKA_CTRL').object tailPointerTip = rig_transform(0, name=self.name + 'PointerTip', type='locator', parent=tailModule.parts, target=tailPointer.con).object pm.rotate(tailPointerBase, 0, 0, -90, r=True, os=True) pm.rotate(tailPointerTip, 0, 0, -90, r=True, os=True) pm.parentConstraint(self.parent, tailPointerBase, mo=True) pm.parentConstraint(tailPointer.con, tailPointerTip, mo=True) tailPointerTop = mm.eval('rig_makePiston("' + tailPointerBase + '", "' + tailPointerTip + '", "' + self.name + 'PointerAim");') pm.orientConstraint(tailPointerBase.replace('LOC', 'JNT'), self.name + 'FKAModify2_GRP', mo=True) pm.parent(self.name + 'MidAIKOffset_GRP', self.name + 'MidBIKOffset_GRP', self.name + 'TipIKOffset_GRP', tailModule.controls) pm.parent(tailJnts, tailModule.skeleton) pm.parent(self.name + '_cMUS', self.name + 'BaseIKOffset_GRP', tailPointerTop, tailModule.parts) pm.parent(self.name + 'SplineSetup_GRP', self.name + 'BaseIKOffset_GRP', tailPointerTop, tailModule.parts) pm.setAttr(tailModule.skeleton + '.inheritsTransform', 0) if self.makeDynamic: chainParent(dynJnts, reverse=0) dynJnts.reverse() finalChain = rig_jointCopyChain(dynJnts[0], replaceName=('Dyn', 'Final')) mc.select(self.name + "SplineIK_CRV") mm.eval('makeCurvesDynamic 2 { "1", "0", "1", "1", "0"};') hairSystem = pm.ls("|hairSystem?")[0] nucleus = pm.ls("|nucleus?")[0] dynCurveGrp = pm.ls("|hairSystem?OutputCurves")[0] dynCurve = pm.listRelatives(dynCurveGrp, c=True)[0] dynCurve = pm.rename(dynCurve, self.name + 'Dyn_CRV') nmeUpper = self.name.capitalize() #ikData = pm.ikHandle(n='dyn'+nmeUpper, sj=dynJnts[0], ee=dynJnts[-1], # solver='ikSplineSolver',curve=dynCurve,ccv=False, ns=self.numFKCtrls) ikData = rig_ik('dyn' + nmeUpper, dynJnts[0], dynJnts[-1], 'ikSplineSolver', numSpans=self.numFKCtrls, curve=dynCurve, createCurve=False) # advanced twist pm.setAttr(ikData.handle + '.dTwistControlEnable', 1) pm.setAttr(ikData.handle + '.dWorldUpType', 2) # object up start and end pm.setAttr(ikData.handle + '.dForwardAxis', 2) # positive y pm.setAttr(ikData.handle + '.dWorldUpAxis', self.dWorldUpAxis) # positive x pm.connectAttr(self.name + 'UpperAim_LOCUp.worldMatrix[0]', ikData.handle.dWorldUpMatrixEnd, f=True) pm.connectAttr(self.name + 'LowerAim_LOCUp.worldMatrix[0]', ikData.handle.dWorldUpMatrix, f=True) mc.setAttr(hairSystem + ".collide", 0) mc.setAttr(hairSystem + ".stretchResistance", 25) mc.setAttr(hairSystem + ".bendResistance", .1) mc.setAttr(hairSystem + ".stiffness", 1) mc.setAttr(hairSystem + ".lengthFlex", 1) mc.setAttr(hairSystem + ".damp", .05) mc.setAttr(hairSystem + ".stretchDamp", 1) mc.setAttr(hairSystem + ".mass", .2) mc.setAttr(hairSystem + ".attractionDamp", 1) mc.setAttr(hairSystem + ".startCurveAttract", .5) mc.setAttr("follicleShape1.pointLock", 1) mc.setAttr("follicleShape1.overrideDynamics", 1) mc.setAttr("follicleShape1.collide", 0) mc.setAttr("follicleShape1.damp", .25) mc.setAttr("follicleShape1.stiffness", 0) #mc.setAttr( "follicleShape1.startCurveAttract" ,.3) # 0.3 default dyn stiffness at 0, 1 = 10 rig_animDrivenKey(fkBaseCtrl.stiffness, (0, 10), "follicleShape1.startCurveAttract", (0.3, 1)) pm.connectAttr(fkBaseCtrl.startFrame, 'nucleus1.startFrame', f=True) # create tail dyn controls with joints parentd underneath # creat another ikSPline 'tailDriven_CRV' and 'tailDriven_ikHandle' and drive final geo, with tail dyn jonints skinned to the ikPlane tail driven crv. sc = simpleControls(dynJnts, modify=1, constrainJoints=0, parentCon=1, colour='red') pm.parent(sc[dynJnts[0]].offset, tailModule.controlsSec) collections.OrderedDict(sorted(sc.items(), key=lambda t: t[0])) i = 0 for jnt in finalChain: driverJnt = jnt.replace('Final', 'Driver') dynJnt = jnt.replace('Final', 'Dyn') pm.parent(jnt, sc[dynJnt].con) con = pm.parentConstraint(driverJnt, dynJnt, sc[dynJnt].offset, mo=True) pm.setAttr(con.interpType, 2) targets = con.getWeightAliasList() rig_animDrivenKey(fkBaseCtrl.dynamicBlend, (0, 10), targets[0], (1, 0)) rig_animDrivenKey(fkBaseCtrl.dynamicBlend, (0, 10), targets[1], (0, 1)) i += 1 chainList = rig_chain(self.origRootJoint).chain ik = rig_ik(self.name + 'Driven', self.origRootJoint, chainList[-1], 'ikSplineSolver', numSpans=self.numIKCtrls) pm.parent(ik.handle, ik.curve, tailModule.parts) # advanced twist pm.setAttr(ik.handle + '.dTwistControlEnable', 1) pm.setAttr(ik.handle + '.dWorldUpType', 2) # object up start and end pm.setAttr(ik.handle + '.dForwardAxis', 2) # positive y pm.setAttr(ik.handle + '.dWorldUpAxis', self.dWorldUpAxis) # positive x pm.connectAttr(self.name + 'UpperAim_LOCUp.worldMatrix[0]', ik.handle.dWorldUpMatrixEnd, f=True) pm.connectAttr(self.name + 'LowerAim_LOCUp.worldMatrix[0]', ik.handle.dWorldUpMatrix, f=True) pm.skinCluster(finalChain, ik.curve, tsb=True) pm.setAttr(self.name + 'Dyn_CRV.inheritsTransform', 0) pm.parent(dynJnts[0], 'nucleus1', hairSystem, ikData.handle, ikData.curve, tailModule.parts) pm.delete('hairSystem1OutputCurves') self.module = tailModule
def arm(self, side='', ctrlSize=1.0): name = side + '_arm' if side == '': name = 'arm' module = rig_module(name) self.armModule = module arm = self.armName elbow = self.elbowName hand = self.handName if side != '': arm = side + '_' + arm elbow = side + '_' + elbow hand = side + '_' + hand chain = [arm, elbow, hand] pm.parent(arm, module.skeleton) print 'arm ' + arm print 'elbow ' + elbow print 'hand ' + hand ctrlSizeHalf = [ctrlSize / 4.0, ctrlSize / 4.0, ctrlSize / 4.0] ctrlSize = [ctrlSize, ctrlSize, ctrlSize] self.armTop = rig_transform(0, name=side + '_armTop', target=arm, parent=module.parts).object armSkeletonParts = rig_transform(0, name=side + '_armSkeletonParts', parent=self.armTop).object # chain result armResult = rig_transform(0, name=side + '_armResult', type='joint', target=arm, parent=armSkeletonParts, rotateOrder=2).object elbowResult = rig_transform(0, name=side + '_elbowResult', type='joint', target=elbow, rotateOrder=2).object handResult = rig_transform(0, name=side + '_handResult', type='joint', target=hand, rotateOrder=2).object chainResult = [armResult, elbowResult, handResult] chainParent(chainResult) chainResult.reverse() # chain FK armFK = rig_transform(0, name=side + '_armFK', type='joint', target=arm, parent=armSkeletonParts, rotateOrder=2).object elbowFK = rig_transform(0, name=side + '_elbowFK', type='joint', target=elbow, rotateOrder=2).object handFK = rig_transform(0, name=side + '_handFK', type='joint', target=hand, rotateOrder=2).object chainFK = [armFK, elbowFK, handFK] chainParent(chainFK) chainFK.reverse() # chain IK armIK = rig_transform(0, name=side + '_armIK', type='joint', target=arm, parent=armSkeletonParts, rotateOrder=2).object elbowIK = rig_transform(0, name=side + '_elbowIK', type='joint', target=elbow, rotateOrder=2).object handIK = rig_transform(0, name=side + '_handIK', type='joint', target=hand, rotateOrder=2).object chainIK = [armIK, elbowIK, handIK] chainParent(chainIK) chainIK.reverse() # create ik ik = rig_ik(name, armIK, handIK, 'ikRPsolver') pm.parent(ik.handle, module.parts) poleVector = rig_control(side=side, name='armPV', shape='pointer', modify=1, lockHideAttrs=['rx', 'ry', 'rz'], targetOffset=[arm, hand], parentOffset=module.controls, scale=ctrlSizeHalf) if side == 'r': pm.rotate(poleVector.ctrl.cv, 90, 0, 0, r=True, os=True) else: pm.rotate(poleVector.ctrl.cv, -90, 0, 0, r=True, os=True) pm.connectAttr(module.top.ikFkSwitch, poleVector.offset + '.visibility') self.armControls['poleVector'] = poleVector pm.delete(pm.aimConstraint(elbow, poleVector.offset, mo=False)) handPos = pm.xform(hand, translation=True, query=True, ws=True) elbowPos = pm.xform(elbow, translation=True, query=True, ws=True) poleVectorPos = pm.xform(poleVector.con, translation=True, query=True, ws=True) pvDistance = lengthVector(elbowPos, poleVectorPos) pm.xform(poleVector.offset, translation=[pvDistance, 0, 0], os=True, r=True) pm.poleVectorConstraint(poleVector.con, ik.handle) # create pv pm.move(poleVector.offset, [0, -pvDistance * 40, 0], relative=True, objectSpace=True) ''' pvDistance = lengthVector(handPos, elbowPos) pm.move(poleVector.offset, [pvDistance*2, 0, 0], relative=True, objectSpace=True) ''' print 'ik handle ' + ik.handle handControl = rig_control(side=side, name='hand', shape='box', modify=2, parentOffset=module.controls, scale=ctrlSize, rotateOrder=2) pm.delete(pm.pointConstraint(hand, handControl.offset)) pm.parentConstraint(handControl.con, ik.handle, mo=True) handControl.gimbal = createCtrlGimbal(handControl) handControl.pivot = createCtrlPivot(handControl) constrainObject( handControl.offset, [self.spineConnection, self.centerConnection, 'worldSpace_GRP'], handControl.ctrl, ['spine', 'main', 'world'], type='parentConstraint') pm.addAttr(handControl.ctrl, longName='twist', at='float', k=True) pm.connectAttr(handControl.ctrl.twist, ik.handle.twist) pm.connectAttr(module.top.ikFkSwitch, handControl.offset + '.visibility') self.armControls['hand'] = handControl handIK_loc = rig_transform(0, name=side + '_handIKBuffer', type='locator', target=handIK, parent=handControl.con).object pm.hide(handIK_loc) pm.parentConstraint(handIK_loc, handIK, mo=True, skipTranslate=('x', 'y', 'z')) # auto pole vector autoPVOffset = rig_transform(0, name=side + '_autoPVOffset', parent=module.parts, target=poleVector.con).object autoPVLoc = rig_transform(0, name=side + '_autoPV', type='locator', parent=autoPVOffset, target=autoPVOffset).object pm.parentConstraint(self.spineConnection, autoPVOffset, mo=True) pm.pointConstraint(self.spineConnection, handControl.con, autoPVLoc, mo=True) constrainObject(poleVector.offset, [ autoPVLoc, self.spineConnection, self.centerConnection, 'worldSpace_GRP' ], poleVector.ctrl, ['auto', 'spine', 'main', 'world'], type='parentConstraint') # create fk print 'fk chain ' + str(chainFK) fkCtrls = fkControlChain(chainFK, scale=ctrlSize) for fk in fkCtrls: pm.parent(fk.offset, module.controls) pm.setDrivenKeyframe(fk.offset + '.visibility', cd=module.top.ikFkSwitch, dv=1, v=0) pm.setDrivenKeyframe(fk.offset + '.visibility', cd=module.top.ikFkSwitch, dv=0, v=1) elbowFk = fkCtrls[1] rotateAxis = ['rx', 'ry', 'rz'] if self.elbowAxis in rotateAxis: rotateAxis.remove(self.elbowAxis) for at in rotateAxis: elbowFk.ctrl.attr(at).setKeyable(False) elbowFk.ctrl.attr(at).setLocked(True) self.armControls['fk'] = fkCtrls self.connectIkFkSwitch(chains=[chainResult, chainIK, chainFK], module=module, name=name) # constrain result to skeleton for i in range(0, len(chain)): pm.parentConstraint(chainResult[i], chain[i], mo=True) return module
def connectArmShoulder(self, side=''): if side != '': side = side + '_' fkCtrls = self.armControls['fk'] hand = self.armControls['hand'] print 'self.shoulderControl ' + str(self.shoulderControl.ctrl) pm.parentConstraint(self.shoulderControl.con, fkCtrls[0].offset, mo=True) pm.parentConstraint(self.shoulderControl.con, self.armTop, mo=True) handAim = rig_transform(0, name=side + 'handAim', type='locator', parent=self.armModule.parts).object shoulderAim = rig_transform(0, name=side + 'shoulderAim', type='locator', parent=self.armModule.parts).object pm.pointConstraint(hand.con, handAim) pm.pointConstraint(self.shoulderControl.con, shoulderAim) pistonTop = mm.eval('rig_makePiston("' + handAim + '", "' + shoulderAim + '", "' + side + 'shoulderAim");') pistonChildren = pm.listRelatives(pistonTop, type='transform', c=True) pm.parentConstraint(self.spineConnection, pistonTop, mo=True) for child in pistonChildren: if child.stripNamespace().endswith('shoulderAim_LOCAimOffset'): pm.delete(pm.listRelatives(child, type='constraint')) pm.parentConstraint(self.spineConnection, child, mo=True) if child.stripNamespace().endswith('shoulderAim_LOC'): con = pm.parentConstraint(self.shoulderControl.offset, child, self.shoulderControl.modify, mo=True) pm.setAttr(con.interpType, 0) childConAttr = con.getWeightAliasList()[1] pm.addAttr(self.shoulderControl.ctrl, longName='followArm', at='float', k=True, min=0, max=10, defaultValue=5) pm.setDrivenKeyframe(childConAttr, cd=self.shoulderControl.ctrl.followArm, dv=0, v=0) pm.setDrivenKeyframe(childConAttr, cd=self.shoulderControl.ctrl.followArm, dv=10, v=1) if child.stripNamespace().endswith('handAim_LOCAimOffset'): pm.delete(pm.listRelatives(child, type='constraint')) pm.pointConstraint(hand.con, child, mo=True) pm.parent(pistonTop, self.armModule.parts) return
def __init__(self, **kwds): self.character = defaultReturn('jerry', 'character', param=kwds) self.rigBound = defaultReturn(None, 'rigBound', param=kwds) self.rigVersion = defaultReturn(0, 'version', param=kwds) self.buildInScene = defaultReturn(0, 'buildInScene', param=kwds) if self.buildInScene == 0: pm.newFile(f=True) print "START: rigPuppet build " + self.character pm.timer(s=True) pm.undoInfo(state=False) pm.evaluationManager(mode='serial') try: self.charModule = importlib.import_module('char.' + self.character + 'Puppet') print self.charModule pm.workspace(update=True) projectRoot = pm.workspace( q=True, rd=True) + 'scenes/release/rigBound/' + self.character + '/' print ' project root ' + projectRoot + ' found' if self.rigVersion == 0: puppetPath = pm.workspace( q=True, rd=True ) + 'scenes/release/rigPuppet/' + self.character + '/' # find what is next puppet version puppetList = [] os.chdir(puppetPath) for f in glob.glob("*.ma"): puppetList.append(f) self.rigVersion = len(puppetList) + 1 print 'rigVersion = ' + str(self.rigVersion) if self.rigBound is None: #projectRoot = pm.workspace(q=True, rd=True) + 'scenes/release/rigBound/' fileList = [] os.chdir(projectRoot) for f in glob.glob("*.ma"): fileList.append(f) fileList.sort() latestFile = fileList[-1:][0] self.rigBound = projectRoot + latestFile print 'latestFile = ' + latestFile #else: # self.rigBound = projectRoot + self.rigBound + '.ma' if self.buildInScene == 0: print 'rigBound file path = ' + self.rigBound # import rigBound file try: #filePath = cmds.file(self.rigBound, f=True, ignoreVersion=True, # typ="mayaAscii", o=True) filePath = cmds.file(self.rigBound, i=True, ignoreVersion=True, ra=False, mergeNamespacesOnClash=False, typ="mayaAscii", loadReferenceDepth='none') except RuntimeError: print self.rigBound + ' file not found' cmds.dgdirty(allPlugs=True) cmds.refresh() # unparent skeleton rootJoint = cmds.parent(cmds.listRelatives('skeleton_GRP', typ='joint'), w=True)[0] loadPose(rootJoint, 'tPose') pm.rename('globalOffset_GRP', 'globalOffset_GRPx') pm.rename('global_CTRL', 'global_CTRLx') self.globalCtrl = rig_control(name='global', colour='white', shape='arrows', con=0, showAttrs=['sx', 'sy', 'sz']) self.globalCtrl.gimbal = createCtrlGimbal(self.globalCtrl).ctrl self.topNode = rig_transform(0, name=self.character + 'RigPuppetTop', child=self.globalCtrl.offset).object topNode = pm.PyNode(self.topNode) pm.addAttr(topNode, ln='rpAuthor', at='enum', enumName='JerryLee', k=True) topNode.rpAuthor.setLocked(True) pm.addAttr(topNode, ln='rpVersion', at='enum', enumName=str(self.rigVersion), k=True) topNode.rpVersion.setLocked(True) topNode.translate.setLocked(True) topNode.rotate.setLocked(True) topNode.scale.setLocked(True) for cb in ('t', 'r', 's'): for at in ('x', 'y', 'z'): cbAttr = getattr(topNode, cb + at) cbAttr.setKeyable(False) try: self.rigGrp = pm.parent('rig_GRP', self.globalCtrl.gimbal)[0] except Exception as e: self.rigGrp = rig_transform( 0, name='rig', parent=self.globalCtrl.gimbal).object pm.addAttr(self.rigGrp, longName='worldScale', at='float', k=True, min=0, defaultValue=1) self.rigGrp.worldScale.set(cb=True) try: self.rigModule = pm.parent('rigModules_GRP', self.globalCtrl.gimbal)[0] except Exception as e: self.rigModule = rig_transform( 0, name='rigModules', parent=self.globalCtrl.gimbal).object try: self.model = pm.parent('model_GRP', self.topNode)[0] except Exception as e: self.model = rig_transform(0, name='model', parent=self.topNode).object try: self.rigModel = pm.parent('rigModel_GRP', self.model)[0] except Exception as e: self.rigModel = rig_transform(0, name='rigModel', parent=self.model).object self.worldSpace = rig_transform( 0, name='worldSpace', parent=self.globalCtrl.gimbal).object try: pm.delete("|*RigBoundTop_GRP") except pm.MayaNodeError: print 'RigBound top node does not exist' # create attributes on global ctrl pm.addAttr(self.globalCtrl.ctrl, ln='puppetSettings', at='enum', enumName='___________', k=True) self.globalCtrl.ctrl.puppetSettings.setLocked(True) # model and skeleton vis # model connectAttrToVisObj(self.globalCtrl.ctrl, 'modelVis', self.model, defaultValue=1) # skeleton pm.addAttr(self.globalCtrl.ctrl, longName='skeletonVis', at='long', k=True, min=0, max=1, defaultValue=0) self.globalCtrl.ctrl.skeletonVis.set(cb=True) # controls pm.addAttr(self.globalCtrl.ctrl, longName='controlsVis', at='long', k=True, min=0, max=1, defaultValue=1) self.globalCtrl.ctrl.controlsVis.set(cb=True) # referencing and selecting pm.addAttr(self.globalCtrl.ctrl, ln='model', at='enum', enumName='Selectable:Reference', k=True, defaultValue=1) pm.addAttr(self.globalCtrl.ctrl, ln='skeleton', at='enum', enumName='Selectable:Reference', k=True, defaultValue=1) # LOD vis pm.addAttr(self.globalCtrl.ctrl, ln='lodSetting', at='enum', enumName='___________', k=True) self.globalCtrl.ctrl.lodSetting.setLocked(True) pm.addAttr(self.globalCtrl.ctrl, ln='lodDisplay', at='enum', enumName='Low:Mid:High', k=True, defaultValue=0) lodModel = [ 'lowLOD_GRP', 'lowMidLOD_GRP', 'midLOD_GRP', 'midHighLOD_GRP', 'highLOD_GRP' ] for lod in lodModel: if pm.objExists(lod): lodGRP = pm.PyNode(lod) if 'low' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=0) if 'mid' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=0) if 'high' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=1) if 'lowMid' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=0) if 'midHigh' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=1) if cmds.objExists('allModel_GRP'): cmds.setAttr("allModel_GRP.visibility", 1) # scale global control self.bbox = self.model.boundingBox() width = self.bbox.width() * 0.3 cvsGlobal = pm.PyNode(self.globalCtrl.ctrl + '.cv[:]') cvsGimbal = pm.PyNode(self.globalCtrl.gimbal + '.cv[:]') pm.scale(cvsGlobal, width, width, width) pm.scale(cvsGimbal, width / 1.5, width / 1.5, width / 1.5) # make display toggle self.displayTransform = pm.circle( name='displayModulesToggleControl', sw=360, nr=(0, 1, 0), ch=0)[0] pm.delete(self.displayTransform.getShape()) displayCurves = pm.PyNode( pm.textCurves(f="Quartz|wt:50|sz:28|sl:n|st:100", t="Display", ch=0, fzn=True)[0]) pm.setAttr(displayCurves.translateX, -1.7) pm.move(0, 0, 0, displayCurves.rotatePivot, p=True, ws=True) pm.move(0, 0, 0, displayCurves.scalePivot, p=True, ws=True) pm.move(0, (self.bbox.height() + (self.bbox.height() * 0.1)), 0, displayCurves, r=True) displayScale = self.bbox[1][0] / 4 pm.scale(displayCurves, displayScale, displayScale, displayScale) allCurves = pm.listRelatives(displayCurves, ad=True, c=True, type="nurbsCurve") parentCurves = [] for crv in allCurves: parentTransform = pm.listRelatives(crv, p=True)[0] pm.parent(parentTransform, w=True) pm.makeIdentity(parentTransform, apply=True, t=1, r=1, s=1) pm.parent(crv, self.displayTransform, shape=True, add=True) parentCurves.append(parentTransform) pm.dgdirty(allPlugs=True) pm.refresh() pm.delete(parentCurves, s=False) pm.delete(displayCurves) pm.parent(self.displayTransform, self.globalCtrl.ctrl) for at in [ 'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ', 'visibility' ]: #getattr(self.displayTransform, at).set(k=False) self.displayTransform.attr(at).set(k=False) self.displayTransform.attr(at).setLocked(True) pm.connectAttr(self.globalCtrl.ctrl + '.scaleX', self.rigGrp.worldScale) pm.hide(self.rigGrp, self.rigModel) pm.addAttr(self.globalCtrl.ctrl, ln='rigAuthor', at='enum', enumName='Jerry:Lee', k=False, dv=0) self.prepareRig() self.createRigModules() self.finishRig() pm.select(cl=True) #self.sup = super(puppet, self) #self.sup.__init__(self.topNode, **kwds) except Exception as e: print "*************************************" print "=========== Error happened =========" raise finally: pm.evaluationManager(mode='parallel') mayaTimer = pm.timer(e=True) pm.undoInfo(state=True) print '' print '' print "END: rigPuppet built in %g seconds" % mayaTimer print ''
def __init__(self, **kwds): self.character = defaultReturn('jerry', 'character', param=kwds) self.model = defaultReturn(None, 'model', param=kwds) self.skeleton = defaultReturn(None, 'skeleton', param=kwds) self.mayaScene = self.character + '_rigBound_buildScene' self.makeBiped = defaultReturn(False, 'biped', param=kwds) self.makeQuadruped = defaultReturn(False, 'quadruped', param=kwds) pm.newFile(f=True) print "START: rigBound build " + self.character pm.timer(s=True) pm.undoInfo(state=False) pm.evaluationManager(mode='serial') try: self.charModule = importlib.import_module('char.' + self.character + 'Bound') print self.charModule pm.workspace(update=True) projectRoot = pm.workspace(q=True, rd=True) + 'scenes/release/' print ' project root ' + projectRoot + ' found' modelPath = projectRoot + 'model/' + self.character + '/' if self.model is None: fileList = [] os.chdir(modelPath) for f in glob.glob("*.ma"): fileList.append(f) fileList.sort() latestFile = fileList[-1:][0] print fileList self.model = modelPath + latestFile else: self.model = modelPath + self.model + '.ma' print 'model file path = ' + self.model # import model file try: filePath = cmds.file(self.model, i=True, ignoreVersion=True, ra=False, mergeNamespacesOnClash=False, typ="mayaAscii", loadReferenceDepth='none') except RuntimeError: print self.model + ' file not found' cmds.dgdirty(allPlugs=True) cmds.refresh() skeletonPath = projectRoot + 'rigSkeleton/' + self.character + '/' if self.skeleton is None: fileList = [] os.chdir(skeletonPath) for f in glob.glob("*.ma"): fileList.append(f) fileList.sort() latestFile = fileList[-1:][0] self.skeleton = skeletonPath + latestFile else: self.skeleton = skeletonPath + self.skeleton + '.ma' print 'skeleton file path = ' + self.skeleton # import skeleton file try: filePath = cmds.file(self.skeleton, i=True, ignoreVersion=True, ra=False, mergeNamespacesOnClash=False, typ="mayaAscii", loadReferenceDepth='none') except RuntimeError: print self.skeleton + ' file not found' cmds.dgdirty(allPlugs=True) cmds.refresh() # unparent skeleton #skeleton = pm.listRelatives('skeleton_GRP', typ='joint') self.globalCtrl = rig_control(name='global', colour='white', shape='arrows', con=0, showAttrs=['sx', 'sy', 'sz']) self.topNode = rig_transform(0, name=self.character + 'RigBoundTop', child=self.globalCtrl.offset).object self.rigGrp = rig_transform(0, name='rig', parent=self.globalCtrl.ctrl).object pm.addAttr(self.rigGrp, longName='worldScale', at='float', k=True, min=0, defaultValue=1) #self.rigGrp.worldScale.set(cb=True) pm.connectAttr(self.globalCtrl.ctrl.scaleX, self.rigGrp + '.worldScale') self.modelGrp = rig_transform(0, name='model', parent=self.topNode).object self.modelGrp = pm.PyNode(self.modelGrp) self.rigModel = rig_transform(0, name='rigModel', parent=self.modelGrp).object #self.skeleton = rig_transform(0, name='skeleton', parent=self.globalCtrl.ctrl, child=skeleton).object self.skeleton = 'skeleton_GRP' pm.parent('skeleton_GRP', self.globalCtrl.ctrl) pm.parent('allModel_GRP', self.modelGrp) # create attributes on global ctrl pm.addAttr(self.globalCtrl.ctrl, ln='boundSettings', at='enum', enumName='___________', k=True) self.globalCtrl.ctrl.boundSettings.setLocked(True) # model and skeleton vis # model print(self.modelGrp) connectAttrToVisObj(self.globalCtrl.ctrl, 'modelVis', self.modelGrp, defaultValue=1) # skeleton connectAttrToVisObj(self.globalCtrl.ctrl, 'skeletonVis', self.skeleton, defaultValue=1) # referencing and selecting pm.addAttr(self.globalCtrl.ctrl, ln='model', at='enum', enumName='Selectable:Reference', k=True, defaultValue=1) pm.addAttr(self.globalCtrl.ctrl, ln='skeleton', at='enum', enumName='Selectable:Reference', k=True, defaultValue=1) # LOD vis pm.addAttr(self.globalCtrl.ctrl, ln='lodSetting', at='enum', enumName='___________', k=True) self.globalCtrl.ctrl.lodSetting.setLocked(True) pm.addAttr(self.globalCtrl.ctrl, ln='lodDisplay', at='enum', enumName='Low:Mid:High', k=True, defaultValue=0) lodModel = [ 'lowLOD_GRP', 'lowMidLOD_GRP', 'midLOD_GRP', 'midHighLOD_GRP', 'highLOD_GRP' ] for lod in lodModel: if pm.objExists(lod): lodGRP = pm.PyNode(lod) pm.parent(lodGRP, self.modelGrp) if 'low' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=0) if 'mid' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=0) if 'high' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=1) if 'lowMid' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=0) if 'midHigh' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=1) # scale global control self.bbox = self.modelGrp.boundingBox() width = self.bbox.width() * 0.3 cvsGlobal = pm.PyNode(self.globalCtrl.ctrl + '.cv[:]') pm.scale(cvsGlobal, width, width, width) try: pm.delete("|*RigSkeletonTop_GRP") except pm.MayaNodeError: print 'RigSkeleton top node does not exist' pm.hide(self.rigGrp, self.rigModel) self.prepareRig() self.createRigModules() self.finishRig() pm.select(cl=True) self.sup = super(bound, self) self.sup.__init__(self.topNode, **kwds) except Exception as e: print "*************************************" print "=========== Error happened =========" raise finally: pm.evaluationManager(mode='parallel') mayaTimer = pm.timer(e=True) pm.undoInfo(state=True) print '' print '' print "END: rigBound built in %g seconds" % mayaTimer print ''
def _setDefaultSettings(self): lastParent = self.ctrl if self.con > 0: self.con = rig_transform(0, name=self.name + 'Con', parent=self.ctrl).object mc.setAttr(self.con + ".rotateOrder", self.rotateOrder) lastParent = self.con if self.offset > 0: self.offset = rig_transform(0, name=self.name + 'Offset', parent=self.parentOffset, target=self.targetOffset, child=self.ctrl).object pm.setAttr(self.offset + ".rotateOrder", self.rotateOrder) self.parent = self.offset mods = [] if self.modify > 0: modParent = '' for i in range(1, self.modify + 1): modParent = rig_transform(0, name=self.name + 'Modify' + str(i), target=self.offset, parent=modParent).object pm.setAttr(modParent + ".rotateOrder", self.rotateOrder) mods.append(modParent) if len(mods) == 1: self.modify = mods[0] else: self.modify = mods pm.parent(mods[0], self.offset) lastMod = mods[-1:][0] self.parent = lastMod # parent ctrl to obj above, either offset or modify pm.parent(self.ctrl, self.parent) # set rotate order self.ctrl.rotateOrder.set(k=True) pm.setAttr(self.ctrl.rotateOrder, self.rotateOrder) # set scale pm.scale(self.ctrl.cv, self.scale[0], self.scale[1], self.scale[2]) if self.side == 'r': # flip right ctrls to match left pm.scale(self.ctrl.cv, -1, -1, -1) # set colour self.ctrl.overrideEnabled.set(1) self.ctrl.overrideRGBColors.set(1) try: col = name_to_rgb(self.colour) self.ctrl.overrideColorRGB.set(col[0], col[1], col[2]) except ValueError: pm.warning('Could not find specified ' + self.colour + '... Using yellow' + '\n') col = name_to_rgb('yellow') self.ctrl.overrideColorRGB.set(col[0], col[1], col[2]) # lock attrs for at in self.lockHideAttrs: self.ctrl.attr(at).setKeyable(False) self.ctrl.attr(at).setLocked(True) for at in self.showAttrs: self.ctrl.attr(at).setKeyable(True) self.ctrl.attr(at).setLocked(False) if pm.objExists(self.child): pm.parent(self.child, lastParent)
def facialLocalWorldControllers(module, parent, ctrlSize=1): ctrlSizeHalf = [ctrlSize / 2.0, ctrlSize / 2.0, ctrlSize / 2.0] ctrlSizeQuarter = [ctrlSize / 4.0, ctrlSize / 4.0, ctrlSize / 4.0] ctrlSize = [ctrlSize, ctrlSize, ctrlSize] transLocs = cmds.ls("*_sdk2_LOC", type="transform") for loc in transLocs: locName = loc.replace('_sdk2', '') side = rig_nameGetSide(locName) base = locName #if side: base = rig_nameGetBase(locName) print 'side = ' + side print 'base = ' + base name = loc.replace('_sdk2_LOC', '') print 'name = ' + name localOffset = rig_transform(0, name=name + 'LocalOffset', parent=module.parts, target=loc).object localCon = rig_transform(0, name=name + 'LocalCon', parent=localOffset, target=localOffset).object pm.parentConstraint(loc, localCon, mo=True) ctrlName = base + 'Twk' if 'Tweak' in base: ctrlName = base.replace('Tweak', 'Twker') print 'ctrlName = ' + ctrlName ctrl = rig_control(side=side, name=ctrlName, shape='circle', modify=1, scale=ctrlSize, directCon=1, parentOffset=module.controlsSec, secColour=1, directConAttrs=('tx', 'ty', 'tz', 'rx', 'ry', 'rz')) pm.rotate(ctrl.ctrl.cv, 0, 0, 90, r=True, os=True) if side == 'r': pm.move(ctrl.ctrl.cv, -0.2, 0, 0, r=True, os=True) else: pm.move(ctrl.ctrl.cv, 0.2, 0, 0, r=True, os=True) jnt = pm.listRelatives(loc, type='joint', c=True)[0] pm.delete(pm.parentConstraint(loc, ctrl.offset)) pm.parent(ctrl.offset, parent) for at in ('tx', 'ty', 'tz', 'rx', 'ry', 'rz'): pm.connectAttr(localCon + '.' + at, ctrl.modify + '.' + at) pm.connectAttr(ctrl.ctrl + '.' + at, jnt + '.' + at)
def gizmoRigModules(): print 'Create gizmo rig modules' biped = rig_biped() biped.elbowAxis = 'ry' biped.spine(ctrlSize=6) biped.pelvis(ctrlSize=5) biped.neck(ctrlSize=2.5) biped.head(ctrlSize=5) for side in ['l', 'r']: armModule = biped.arm(side, ctrlSize=3) fingersModule = biped.hand(side, ctrlSize=0.5) shoulderModule = biped.shoulder(side, ctrlSize=2) biped.connectArmShoulder(side) legModule = biped.leg(side, ctrlSize=3) toesModule = biped.foot(side, ctrlSize=0.5) biped.connectLegPelvis() # make tail ''' tailModule = rig_ikChainSpline('tail', 'tailJA_JNT', ctrlSize=1, parent='pelvisJA_JNT', numIkControls=4, numFkControls=4) chainList = rig_chain('tailJOTip_JNT').chain print '====== MAKING TAIL TIP ==============' fkCtrls = fkControlChain(chainList, modify=1, scale=[1, 1, 1], directCon=1) for fk in fkCtrls: pm.parent(fk.offset, tailModule.controls) ''' tailModule = rig_ikChainSpline('tail', 'tailHiJA_JNT', ctrlSize=1, parent='pelvisJA_JNT', numIkControls=12, numFkControls=12) # tail upgrade tailJnts = pm.listRelatives('tailskeleton_GRP', type='joint') for i in range(1, len(tailJnts)): tailNme = tailJnts[i].stripNamespace() tailIK = tailJnts[i] tailFK = tailNme.replace('IK', 'FK') tailFK = tailFK.replace('_JNT', '') constrainObject(tailFK + 'Modify2_GRP', [tailIK, tailFK + 'Modify1_GRP'], tailFK + '_CTRL', ['IK', 'parent'], type='parentConstraint') pm.parentConstraint('tailFKACon_GRP', 'tailBaseIKOffset_GRP', mo=True) constrainObject('tailMidAIKOffset_GRP', ['tailFKACon_GRP', 'pelvisCon_GRP', 'worldSpace_GRP'], 'tailMidAIK_CTRL', ['base', 'pelvis', 'world'], type='parentConstraint') constrainObject('tailMidBIKOffset_GRP', [ 'tailFKACon_GRP', 'tailMidAIKCon_GRP', 'pelvisCon_GRP', 'worldSpace_GRP' ], 'tailMidBIK_CTRL', ['base', 'FK', 'pelvis', 'world'], type='parentConstraint') constrainObject('tailTipIKOffset_GRP', [ 'tailFKACon_GRP', 'tailMidBIKCon_GRP', 'pelvisCon_GRP', 'worldSpace_GRP' ], 'tailTipIK_CTRL', ['base', 'FK', 'pelvis', 'world'], type='parentConstraint') tailPointer = rig_control(name='tailPointer', shape='pyramid', scale=(1, 2, 1), lockHideAttrs=['rx', 'ry', 'rz'], colour='white', parentOffset=tailModule.controls, rotateOrder=2) pm.delete(pm.parentConstraint('tailHiJEnd_JNT', tailPointer.offset)) constrainObject( tailPointer.offset, ['pelvisCon_GRP', 'spineFullBodyCon_GRP', 'worldSpace_GRP'], tailPointer.ctrl, ['pelvis', 'fullBody', 'world'], type='parentConstraint') tailPointerBase = rig_transform(0, name='tailPointerBase', type='locator', parent=tailModule.parts, target='tailFKA_CTRL').object tailPointerTip = rig_transform(0, name='tailPointerTip', type='locator', parent=tailModule.parts, target=tailPointer.con).object pm.rotate(tailPointerBase, 0, 0, -90, r=True, os=True) pm.rotate(tailPointerTip, 0, 0, -90, r=True, os=True) pm.parentConstraint('pelvisCon_GRP', tailPointerBase, mo=True) pm.parentConstraint(tailPointer.con, tailPointerTip, mo=True) tailPointerTop = mm.eval('rig_makePiston("' + tailPointerBase + '", "' + tailPointerTip + '", "tailPointerAim");') pm.orientConstraint(tailPointerBase.replace('LOC', 'JNT'), 'tailFKAModify2_GRP', mo=True) pm.parent('tailMidAIKOffset_GRP', 'tailMidBIKOffset_GRP', 'tailTipIKOffset_GRP', tailModule.controls) pm.parent(tailJnts, tailModule.skeleton) pm.parent('tail_cMUS', 'tailBaseIKOffset_GRP', tailPointerTop, tailModule.parts) pm.setAttr(tailModule.skeleton + '.inheritsTransform', 0) # build facial facialModule = rig_module('facial') pm.parent(facialModule.top, 'rigModules_GRP') # build shape locators for side in ['l', 'r']: muzzleCtrl = fourWayShapeControl( side + '_muzzleShape_LOC', (side + 'MuzzleUp', side + 'MuzzleDown', side + 'MuzzleForward', side + 'MuzzleBack'), 'headShapeWorld_GRP', ctrlSize=1) pm.rotate(muzzleCtrl.ctrl.cv, 0, 0, 90, r=True, os=True) pm.rotate(muzzleCtrl.ctrl.cv, -45, 0, 0, r=True, os=True) browCtrl = twoWayShapeControl(side + '_browShape_LOC', (side + 'BrowUp', side + 'BrowDown'), 'headShapeWorld_GRP', ctrlSize=0.8) pm.rotate(browCtrl.ctrl.cv, 90, 0, 0, r=True, os=True) pm.rotate(browCtrl.ctrl.cv, 0, -75, 0, r=True, os=True) blinkCtrl = oneWayShapeControl(side + '_blinkShape_LOC', side + 'Blink', 'headShapeWorld_GRP', ctrlSize=0.5) if side == 'r': pm.rotate(blinkCtrl.ctrl.cv, 0, 0, 180, r=True, os=True) #pm.move(blinkCtrl.ctrl.cv, 0, -0.4, 0, relative=True) #pm.parent( muzzleCtrl.offset, browCtrl.offset , blinkCtrl.offset ,facialModule.controls) pm.parent('headShapeWorld_GRP', facialModule.controls) pm.parentConstraint('headJA_JNT', 'headShapeWorld_GRP') # build simple controllers facialLocalWorldControllers(facialModule, 'headJAWorld_GRP', ctrlSize=0.1) pm.parentConstraint('headJA_JNT', 'headJAWorld_GRP') pm.parent('headJAWorld_GRP', facialModule.controlsSec) pm.move(pm.PyNode('noseTwk_CTRL').cv, 0.15, 0, 0, r=True, os=True) pm.scale(pm.PyNode('noseTwk_CTRL').cv, 2.5, 2.5, 2.5) # jaw control jawControl = rig_control(name='jaw', shape='circle', scale=(2, 2, 2), lockHideAttrs=['rx'], parentOffset=facialModule.controls, colour='white') pm.rotate(jawControl.ctrl.cv, -90, 0, 0, r=True, os=True) pm.move(jawControl.ctrl.cv, 2, 0, 0, r=True, os=True) pm.delete(pm.parentConstraint('jawJA_JNT', jawControl.offset)) pm.parentConstraint('headJA_JNT', jawControl.offset, mo=True) pm.parent('jawHeadOffset_LOC', jawControl.offset) pm.pointConstraint(jawControl.con, 'jawHeadOffset_LOC', mo=True) facialLoc = 'facialShapeDriver_LOC' rig_animDrivenKey(jawControl.ctrl.rotateY, (0, 35), facialLoc + '.jawOpen', (0, 1)) rig_animDrivenKey(jawControl.ctrl.rotateY, (0, -5), facialLoc + '.jawClosed', (0, 1)) rig_animDrivenKey(jawControl.ctrl.rotateZ, (0, -10), facialLoc + '.rJawSide', (0, 1)) rig_animDrivenKey(jawControl.ctrl.rotateZ, (0, 10), facialLoc + '.lJawSide', (0, 1)) pm.transformLimits(jawControl.ctrl, ry=(-5, 35), ery=(1, 1)) pm.transformLimits(jawControl.ctrl, rz=(-10, 10), erz=(1, 1)) pm.transformLimits(jawControl.ctrl, tx=(-0.1, 0.1), etx=(1, 1)) pm.transformLimits(jawControl.ctrl, ty=(-0.1, 0.1), ety=(1, 1)) pm.transformLimits(jawControl.ctrl, tz=(0, 0.1), etz=(1, 1)) upperLipCtrls = pm.ls("*upperLip*Twk*CTRL") for c in upperLipCtrls: pm.scale(c.cv, 0.6, 0.6, 0.6, r=True) pm.move(c.cv, 0, 0, 0.3, r=True) pm.move(c.cv, 0, 0.1, 0, r=True) lowerLipCtrls = pm.ls("*lowerLip*Twk*CTRL") for c in lowerLipCtrls: pm.scale(c.cv, 0.6, 0.6, 0.6, r=True) pm.move(c.cv, 0, 0, 0.3, r=True) pm.move(c.cv, 0, -0.1, 0, r=True) pm.setAttr(facialModule.parts + '.inheritsTransform', 0) pm.parent('tongueControls_GRP', facialModule.controls) # eye controls eyeModule = rig_module('eye') pm.parent(eyeModule.top, 'rigModules_GRP') eyeControl = rig_control(name='eye', shape='circle', modify=1, parentOffset=eyeModule.controls, scale=(1, 1, 1), rotateOrder=2, lockHideAttrs=['rx', 'ry', 'rz']) pm.delete(pm.parentConstraint('eyeAim_LOC', eyeControl.offset)) #pm.parentConstraint( 'headCon_GRP', eyeControl.offset, mo=True ) pm.rotate(eyeControl.ctrl.cv, 90, 0, 0, r=True, os=True) pm.select(eyeControl.ctrl.cv[1], r=True) pm.select(eyeControl.ctrl.cv[5], add=True) pm.scale(0, 0, 0, r=True) constrainObject(eyeControl.offset, ['headCon_GRP', 'worldSpace_GRP'], eyeControl.ctrl, ['head', 'world'], type='parentConstraint') pm.parent('eyeAim_LOC', eyeControl.con) pm.hide('eyeAim_LOC') for side in ('l', 'r'): eyeBase = rig_transform(0, name=side + '_eyeBase', type='locator', target=side + '_eyeJA_JNT', parent=eyeModule.parts).object eyeTarget = rig_transform(0, name=side + '_eyeTarget', type='locator', target='eyeAim_LOC', parent=eyeModule.parts).object pm.parentConstraint('headJA_JNT', eyeBase, mo=True) pm.parentConstraint('eyeAim_LOC', eyeTarget, mo=True) eyeAimTop = mm.eval('rig_makePiston("' + eyeBase + '", "' + eyeTarget + '", ' '"' + side + '_eyeAim");') pm.orientConstraint(side + '_eyeBase_JNT', side + '_eyeJA_JNT', mo=True) pm.parent(eyeAimTop, eyeModule.parts) upperEyeControl = rig_control( side=side, name='eyeUpper', shape='circle', modify=1, parentOffset=eyeModule.controlsSec, scale=(0.1, 0.1, 0.1), constrain=side + '_upperEyeLidRotateOffset_GRP', rotateOrder=2, directCon=1, lockHideAttrs=['tx', 'ty', 'tz', 'rx', 'ry']) pm.delete( pm.parentConstraint(side + '_eyeLocalOffset_GRP', upperEyeControl.offset)) pm.delete( pm.pointConstraint(side + '_eyeJA_JNT', upperEyeControl.offset)) lowerEyeControl = rig_control( side=side, name='eyeLower', shape='circle', modify=1, parentOffset=eyeModule.controlsSec, scale=(0.1, 0.1, 0.1), constrain=side + '_lowerEyeLidRotateOffset_GRP', rotateOrder=2, directCon=1, lockHideAttrs=['tx', 'ty', 'tz', 'rx', 'ry']) pm.delete( pm.parentConstraint(side + '_eyeLocalOffset_GRP', lowerEyeControl.offset)) pm.delete( pm.pointConstraint(side + '_eyeJA_JNT', lowerEyeControl.offset)) ''' eyeControl = rig_control(side=side, name='eye', shape='circle', modify=1, parentOffset=eyeModule.controls, scale=(1,1,1), rotateOrder=2, lockHideAttrs=['rx', 'ry', 'rz']) ''' # ear controls chainEars = rig_chain(side + '_earJA_JNT').chain earCtrls = fkControlChain( [side + '_earJA_JNT', side + '_earJB_JNT', side + '_earJC_JNT'], modify=0, scale=[0.8, 0.8, 0.8], directCon=0) # parent ears to headJA_JNT for ctrl in earCtrls: pm.parent(ctrl.parent, 'headControlsSecondary_GRP')
def constrainObject(obj, multipleConstrainer, ctrl='', enumName=[], **kwds): maintainOffset = defaultReturn(True, 'mo', param=kwds) constrainType = defaultReturn('parentConstraint', 'type', param=kwds) skip = defaultReturn(None, 'skip', param=kwds) skipTrans = defaultReturn(None, 'skipTrans', param=kwds) skipRot = defaultReturn(None, 'skipRot', param=kwds) #skipTranslate = defaultReturn(None, 'skipTranslate', param=kwds) #skipRotate = defaultReturn(None, 'skipRotate', param=kwds) interp = defaultReturn(0, 'interp', param=kwds) spaceAttr = defaultReturn('space', 'spaceAttr', param=kwds) setSpace = defaultReturn(0, 'setSpace', param=kwds) setVal = defaultReturn([], 'setVal', param=kwds) blendVal = defaultReturn(0, 'blendVal', param=kwds) doSpace = 1 if type(multipleConstrainer) is str: doSpace = 0 doSpace = defaultReturn(1, 'doSpace', param=kwds) doBlend = defaultReturn(0, 'doBlend', param=kwds) if doBlend == 1 and len(enumName) == 0: for con in multipleConstrainer: enumName.append('0') interp = 2 # make shortest interp constrainerList = [] #if doSpace: for space in multipleConstrainer: suffix = space.split('_')[-1:][0] spaceName = space.replace('_' + suffix, '_' + obj + 'Proxy' + spaceAttr) loc = spaceName + '_LOC' if pm.objExists(loc): pm.delete(loc) loc = rig_transform(0, name=spaceName, type='locator', parent=space, target=space).object pm.delete(pm.orientConstraint(obj, loc)) pm.hide(loc) constrainerList.append(loc) #else: # constrainerList = multipleConstrainer[:] obj = pm.PyNode(obj) targets = '' if pm.objExists(obj): try: con = '' if constrainType is 'parentConstraint': if skipTrans is None and skipRot is None: con = pm.parentConstraint(constrainerList, obj, mo=maintainOffset) elif skipTrans is not None and skipRot is not None: con = pm.parentConstraint(constrainerList, obj, mo=maintainOffset, st=skipTrans, sr=skipRot) else: if skipTrans is None and skipRot is not None: con = pm.parentConstraint(constrainerList, obj, mo=maintainOffset, sr=skipRot) else: con = pm.parentConstraint(constrainerList, obj, mo=maintainOffset, st=skipTrans) if constrainType is 'orientConstraint': if skip is None: con = pm.orientConstraint(constrainerList, obj, mo=maintainOffset) else: con = pm.orientConstraint(constrainerList, obj, mo=maintainOffset, skip=skip) if constrainType is 'pointConstraint': if skip is None: con = pm.pointConstraint(constrainerList, obj, mo=maintainOffset) else: con = pm.pointConstraint(constrainerList, obj, mo=maintainOffset, skip=skip) try: pm.setAttr(con.interpType, interp) except AttributeError: print 'No interpType attribute' if doSpace or doBlend: ctrl = pm.PyNode(ctrl) if len(constrainerList) is len(enumName): targets = con.getWeightAliasList() enumList = enumName[0] for i in range(1, len(enumName)): enumList += ':' + enumName[i] if not ctrl.hasAttr(spaceAttr): if doBlend: pm.addAttr(ctrl, longName=spaceAttr, attributeType="double", min=0, max=1, defaultValue=blendVal, keyable=True) else: pm.addAttr(ctrl, ln=spaceAttr, at='enum', enumName=enumList, k=True) valueDict = {} for t in targets: list = [] for ta in targets: if ta is t: list.append(1) else: list.append(0) valueDict[t] = list for v in valueDict: for i in range(0, len(valueDict)): #print 'spaceAttr = '+ spaceAttr ctrlSpace = getattr(ctrl, spaceAttr) #print 'ctrlSpace = ' + ctrlSpace pm.setDrivenKeyframe(v, cd=ctrlSpace, dv=i, v=(valueDict[v])[i]) if setSpace > 0: pm.setAttr(ctrl.stripNamespace() + '.' + spaceAttr, setSpace) else: pm.error(' Unequal amount of constrainer to enum names ') elif len(setVal) > 0: targets = con.getWeightAliasList() i = 0 for t in targets: pm.setAttr(t, setVal[i]) i += 1 except pm.MayaNodeError: for m in constrainerList: print m + ' does not exist' + '\n' else: print obj + ' does not exist' + '\n' return targets