def postJawGenHuman(): eyeMaskOrig = 'eyeMask_ctrl_orig' JawClenchLOrig = 'Jaw_Clench_l_ctrl_orig' JawClenchROrig = 'Jaw_Clench_r_ctrl_orig' UpHeadOrig = 'UpHead_ctrl_01_orig' UpHeadCtrl = 'UpHead_ctrl_01' LowerHeadOrig = 'LowerHead_ctrl_01_orig' LowerHeadCtrl = 'LowerHead_ctrl_01' mouthSquashOrig = 'mouthSquash_jnt_orig' foreheadGrp = 'forehead_grp' headSKN = 'head_SKN' jawctrl = 'jaw_ctrl' noseGrp = 'nose_grp' #reparent halfSkulls and nose mc.parent(noseGrp, eyeMaskOrig, UpHeadOrig, LowerHeadOrig, headSKN) #reparent jawClenches mc.parent(JawClenchLOrig, JawClenchROrig, jawctrl) #change midSkulls ctrlShapes shapes.create(UpHeadCtrl, shape='circleHalf', size=2, scale=[1.25, 1, 1.75], axis='y', twist=-90, offset=[0, 0, 0.5], color=[255, 255, 0], colorDegradeTo=None, replace=True, middle=False) shapes.create(LowerHeadCtrl, shape='circleHalf', size=2, scale=[1.25, 1, 1.75], axis='y', twist=90, offset=[0, 0, -0.5], color=[255, 255, 0], colorDegradeTo=False, replace=True, middle=False)
def createFKSection(baseName, ctrlName, offsetName, num, suff, doOffset, makeShape, color): #baseName:string #ctrlName:string #offsetName:string #num:int #suffix:string #doOffset:bool #makeShape:bool #color: None or List [#,#,#] ctrlNodeName = '%s_%s_%02d%s' % (baseName, ctrlName, num, suff) offsetNodeName = '%s_%s_%s_%02d%s' % (baseName, offsetName, ctrlName, num, suff) mc.select(cl=True) newCtrl = mc.joint(n=ctrlNodeName) mc.setAttr('%s.radius' % newCtrl, 0.1) if makeShape == True: mc.setAttr('%s.drawStyle' % newCtrl, 2) shapes.create(newCtrl, shape='circle', size=.5, scale=[1, 1, 1], axis='y', twist=0, offset=[0, 0, 0], color=color, colorDegradeTo=None, replace=True, middle=False) newCtrlOrig = orig.orig(objlist=[newCtrl], suffix=['_orig'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] newCtrlOrig = mc.rename(newCtrlOrig, newCtrlOrig.replace('smart_orig', 'orig_smart')) if doOffset == True: mc.select(cl=True) newOffset = mc.joint(n=offsetNodeName) mc.setAttr('%s.radius' % newOffset, 0.1) if makeShape == True: mc.setAttr('%s.drawStyle' % newOffset, 2) shapes.create(newOffset, shape='circle', size=.25, scale=[1, 1, 1], axis='y', twist=0, offset=[0, 0, 0], color=color, colorDegradeTo=None, replace=True, middle=False) newOffsetOrig = orig.orig(objlist=[newOffset], suffix=['_orig'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] newOffsetOrig = mc.rename( newOffsetOrig, newOffsetOrig.replace('smart_orig', 'orig_smart')) mc.parent(newOffsetOrig, newCtrl) return ([newCtrl, newCtrlOrig], [newOffset, newOffsetOrig]) return ([newCtrl, newCtrlOrig])
def makeVolumeEars(smartParentTarget, smartDupTargets, side, sides): ############################################################################################################################################### # --- ears smart Rig #smartParentTarget = 'head_gimbal_ctrl' #smartDupTargets = ['L_ear_fk_ctrl_01_orig','R_ear_fk_ctrl_01_orig'] earsNoXformGrp = 'ears_ctrl_noXformGrp' WORLDGrp = 'WORLD' ## --- create noXform Grp for ears mc.group(n=earsNoXformGrp, em=True) mc.parent(earsNoXformGrp, WORLDGrp) mc.hide(earsNoXformGrp) # --- duplicate the base of the fkHierarchy, will be use as base of smart hierarchy smartParent = mc.duplicate(smartParentTarget, po=True, n='%s_smart' % smartParentTarget)[0] mc.parent(smartParent, earsNoXformGrp) # --- duplicate all of the fks in one go to create fk_smarts smartsList = mc.duplicate(smartDupTargets) for i, each in enumerate(smartDupTargets): mc.parent(smartsList[i], w=True) # --- goes into the hierarchy of duplicated Fks and counts the depth of the hierarchy. stops when arrived at end of hierarchy hierarchyDepthList = [] for i, each in enumerate(smartDupTargets): hierarchyDepth = 0 nexChild = '' stopLoop = False for j in range(0, 20): if j == 0: nexChild = each getChild = mc.listRelatives(nexChild, c=True, f=True) if getChild: for child in getChild: if not mc.objectType(child) == 'nurbsCurve': if mc.objectType(child) == 'joint': splittedName1 = child.rsplit('|')[-1] splittedName2 = splittedName1.split('offset') checkEnd = splittedName1.rsplit('_', 1)[-1] if not len(splittedName2) > 1: if not checkEnd == 'end': nexChild = child else: stopLoop = True hierarchyDepthList.append(j) break if stopLoop == True: break mc.delete(smartsList[i]) # --- derives controls loop from hierarchy depth smartLoopLenthList = [] for each in hierarchyDepthList: loopLength = (each / 2) + 2 smartLoopLenthList.append(loopLength) # --- recreates hierarchy as smart nodes for i, each in enumerate(smartDupTargets): loop = smartLoopLenthList[i] baseName = each.split('_ctrl_', 1)[0] ctrlName = 'ctrl' offsetName = 'offset' suff = '_smart' makeShape = False color = None parentNext = smartParent for j in range(0, loop): num = j + 1 if j < loop - 1: if j == 0: doOffset = False newCtrls = createFKSection(baseName, ctrlName, offsetName, num, suff, doOffset, makeShape, color) mc.parent(newCtrls[1], parentNext) trgt = newCtrls[0].rsplit('_', 1)[0] origTrgt = newCtrls[1].rsplit('_', 1)[0] smartConnect(trgt, newCtrls[0]) smartConnect(origTrgt, newCtrls[1]) parentNext = newCtrls[0] else: doOffset = True newCtrls = createFKSection(baseName, ctrlName, offsetName, num, suff, doOffset, makeShape, color) mc.parent(newCtrls[0][1], parentNext) trgt = newCtrls[0][0].rsplit('_', 1)[0] origTrgt = newCtrls[0][1].rsplit('_', 1)[0] offsetTrgt = newCtrls[1][0].rsplit('_', 1)[0] origOffsetTrgt = newCtrls[1][1].rsplit('_', 1)[0] smartConnect(trgt, newCtrls[0][0]) smartConnect(origTrgt, newCtrls[0][1]) smartConnect(offsetTrgt, newCtrls[1][0]) smartConnect(origOffsetTrgt, newCtrls[1][1]) parentNext = newCtrls[0][0] if j == loop - 1: mc.select(cl=True) endJoint = mc.joint(n='%s_%s_end_smart' % (baseName, ctrlName)) endOffsetOrig = mc.joint( n='%s_%s_%s_%02d_orig_smart' % (baseName, offsetName, ctrlName, loop)) endOffset = mc.joint(n='%s_%s_%s_%02d_smart' % (baseName, offsetName, ctrlName, loop)) mc.setAttr('%s.radius' % endJoint, 0.1) mc.setAttr('%s.radius' % endOffsetOrig, 0.1) mc.setAttr('%s.drawStyle' % endOffsetOrig, 2) mc.setAttr('%s.radius' % endOffset, 0.1) mc.parent(endJoint, parentNext) smartConnect('%s_%s_end' % (baseName, ctrlName), endJoint) smartConnect( '%s_%s_%s_%02d_orig' % (baseName, offsetName, ctrlName, loop), endOffsetOrig) smartConnect( '%s_%s_%s_%02d' % (baseName, offsetName, ctrlName, loop), endOffset) # --- creates volumeSurf and deforms for ears //temporary use of firstSurf rigPart = 'ear' deformGrp = 'ctrl_DeformGrp' endSurfDeformGrp = 'ears_endSurf_%s' % deformGrp # --- assign values for columeSurf characteristics volspansV = 16 volspansU = 8 volDeg = 3 ## ---creates ears volSurfaces earCurveGUIDEList = [ 'L_topEar_curve_GUIDE', 'L_topMidtEar_curve_GUIDE', 'L_midtEar_curve_GUIDE', 'L_botMidEar_curve_GUIDE', 'L_BotEar_curve_GUIDE' ] earVolSurfList = [] # --- create left volume surface duplicatedCurves = mc.duplicate(earCurveGUIDEList) loftCurves = [] mc.parent(duplicatedCurves, w=True) for u, curve in enumerate(duplicatedCurves): curveName = str(curve) strippedName = curveName.rsplit('_', 1)[0] loftCurves.append(mc.rename(curve, '%s_loftCurve' % strippedName)) loftCurves = loftCurves[::-1] volSurf = mc.loft(loftCurves, ch=False, ar=False, d=3, u=True, n='L_%s_volume_surfNurbs' % rigPart)[0] mc.rebuildSurface(volSurf, rt=0, su=volspansU, sv=volspansV, kc=True, ch=False) mc.delete(loftCurves) mc.parent(volSurf, earsNoXformGrp) earVolSurfList.append(volSurf) # --- creates right ear surf from scale rVolsurf = mc.duplicate(volSurf, n='R_%s_volume_surfNurbs' % rigPart)[0] rVolsurfUSpans = mc.getAttr('%s.spansU' % rVolsurf) rVolsurfVSpans = mc.getAttr('%s.spansV' % rVolsurf) rVolsurfUDeg = mc.getAttr('%s.degreeU' % rVolsurf) rVolsurfVDeg = mc.getAttr('%s.degreeV' % rVolsurf) rVolsurfUCount = rVolsurfUSpans + rVolsurfUDeg rVolsurfVCount = rVolsurfVSpans for u in range(0, rVolsurfUCount): for v in range(0, rVolsurfVCount): pointPos = mc.pointPosition('%s.cv[%d][%d]' % (rVolsurf, u, v)) mc.move(-pointPos[0], pointPos[1], pointPos[2], '%s.cv[%d][%d]' % (rVolsurf, u, v), a=True, ws=True) mc.reverseSurface(rVolsurf, d=1, ch=False) earVolSurfList.append(rVolsurf) mc.group(n=endSurfDeformGrp, em=True) mc.parent(endSurfDeformGrp, smartParentTarget) volumeEarsDeformSKNList = [] for s, surf in enumerate(earVolSurfList): ## --- creates and attaches jointsCloud side = sides[s] sideEndSurfDeformGrp = '%s_%s' % (side, endSurfDeformGrp) mc.group(n=sideEndSurfDeformGrp, em=True) mc.parent(sideEndSurfDeformGrp, endSurfDeformGrp) UDeformsCount = 9 VDeformCount = 10 endSurf = surf tempPOSI = tempPOSI = mc.createNode('pointOnSurfaceInfo', n='volumeSpine_temp_posi') mc.setAttr('%s.turnOnPercentage' % tempPOSI, True) mc.connectAttr('%s.worldSpace[0]' % endSurf, '%s.inputSurface' % tempPOSI) for i in range(0, UDeformsCount - 1): for j in range(0, VDeformCount - 1): ## --- creates deform ctrl/skin hierarchy mc.select(cl=True) deformSkn = mc.joint(n='%s_%s_deform_U%02d_V%02d_SKN' % (side, rigPart, i, j)) mc.setAttr('%s.radius' % deformSkn, 0.01) mc.select(cl=True) deformCtrl = mc.joint(n='%s_%s_deform_U%02d_V%02d_ctrl' % (side, rigPart, i, j)) mc.setAttr('%s.radius' % deformCtrl, 0.01) mc.setAttr('%s.drawStyle' % deformCtrl, 2) smartConnect(deformCtrl, deformSkn) shapes.create(deformCtrl, shape='pyramidDouble', size=0.05, scale=[1, 1, 1], axis='y', twist=0, offset=[0, 0, 0], color=[0.5, 0, 0.5], colorDegradeTo=None, replace=True, middle=False) deformOrig = orig.orig(objlist=[deformCtrl], suffix=['_orig'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] deformAuto = orig.orig(objlist=[deformCtrl], suffix=['_auto'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] mc.parent(deformSkn, deformAuto) volumeEarsDeformSKNList.append(deformSkn) ## --- getWorld Position placement for deform orig from UV UValue = ((1.000 / (UDeformsCount - 1)) * i) VValue = ((1.000 / (VDeformCount - 1)) * j) mc.setAttr('%s.parameterU' % tempPOSI, UValue) mc.setAttr('%s.parameterV' % tempPOSI, VValue) ctrlPos = mc.getAttr('%s.position' % tempPOSI)[0] mc.setAttr('%s.translate' % deformOrig, ctrlPos[0], ctrlPos[1], ctrlPos[2]) ## --- attach deformer ctrl/joints to endSurface xrivetTrOnNurbs(deformOrig, endSurf, mainDirection=1, out='worldSpace[0]', u=None, v=None, offsetOrient=[0, 0, 0], min=False) ## --- reparent deform origs into rig mc.parent(deformOrig, sideEndSurfDeformGrp) mc.select(cl=True) mc.delete(tempPOSI) ## --- TempCleanup of ears sets volumeEarsSkinSet = 'volume_ears_skin_set' mc.sets(volumeEarsDeformSKNList, n=volumeEarsSkinSet) mc.sets(volumeEarsSkinSet, add='skin_set') ### --- disconnect inverseScale on ears to allow headScale fkEarsOrigs = ['L_ear_fk_ctrl_01_orig', 'R_ear_fk_ctrl_01_orig'] for earOrig in fkEarsOrigs: mc.disconnectAttr('head_gimbal_ctrl.scale', '%s.inverseScale' % earOrig)
def buildLegsTopIks(sides, intFixes, chestAdjust): #sides = ['L','R'] #intFixes = ['front','back'] #chestAdjust = 'chest_adjust_ctrl' baseRgb = [[0, 0, 1], [1, 0, 0]] darkRgb = [[0, 0, .8], [.8, 0, 0]] lightRgb = [[.5, .5, 1], [1, .5, .5]] for s, side in enumerate(sides): fix = intFixes[0] #### front leg # add of Auto node + orig on top of leg root offset orig nodeRoot = '{}_{}_leg_root_offset_ctrl'.format(side, fix) makeAutoNode(nodeRoot) # --- recreate reverse scapula joint with Ik and scaleBlend nodeEnd = '{}_scapula_ctrl'.format(side) baseName = nodeEnd.replace('scapula_ctrl', 'reverse_scapula') attrNode = '{}_{}_leg_SW_ctrl'.format(side, fix) attrName = '{}ScapulaStretch'.format(side) revIK = makeRevIk(nodeRoot, nodeEnd, baseName, attrNode, attrName) # --- add auto group on reverse ikh orig revIkAuto = makeAutoNode(revIK[2]) print 'ikAuto Target = %s' % revIK[3] print revIkAuto # --- recrate base scapula chain and pointConstraint scapula_orig to it baseScapRoot = chestAdjust baseScapName = nodeEnd.replace('scapula_ctrl', 'scapula_base_jnt') scapulaBaseChain = makeChainFromObj(baseScapRoot, nodeEnd, baseScapName) mc.parent(scapulaBaseChain[2], chestAdjust) mc.pointConstraint(scapulaBaseChain[1], mc.listRelatives(nodeEnd, p=True), mo=False) # --- recreate base scapula secondary chain + ik fullScale baseScapSecName = nodeEnd.replace('scapula_ctrl', 'scapula_base_sec_jnt') baseScapAttrName = 'baseScapeScale' baseScapSecEnd = mc.listRelatives(nodeEnd, p=True) basScapSecChain = makeRevIk(scapulaBaseChain[0], baseScapSecEnd, baseScapSecName, scapulaBaseChain[0], baseScapAttrName) mc.setAttr('{}.{}'.format(scapulaBaseChain[0], baseScapAttrName), 1) mc.setAttr('{}.{}'.format(scapulaBaseChain[0], baseScapAttrName), l=True) # --- make scapula base ctrl mc.select(cl=True) scapulaBaseCtrl = mc.joint( n=nodeEnd.replace('scapula', 'scapula_base')) mc.setAttr('{}.drawStyle'.format(scapulaBaseCtrl), 2) mc.setAttr('{}.radius'.format(scapulaBaseCtrl), k=False) mc.parent(scapulaBaseCtrl, nodeEnd, r=True) shapes.create(scapulaBaseCtrl, shape='root', size=.6, scale=[1, 1, 1], axis='y', twist=0, offset=[0, 0, 0], color=lightRgb[s], colorDegradeTo=None, replace=True, middle=False) scapulaBaseCtrlOrig = orig.orig(objlist=[scapulaBaseCtrl], suffix=['_orig'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] scapulaBaseCtrlAuto = orig.orig(objlist=[scapulaBaseCtrlOrig], suffix=['_auto'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] patchLib.locksSwitch(scapulaBaseCtrl, T=False, R=True, S=True, V=True, lockdo='lock', keydo=False) mc.pointConstraint(revIK[1], scapulaBaseCtrlAuto, mo=True) # --- make reverse scapula secondary chain and full ik stretch baseSecName = nodeEnd.replace('scapula_ctrl', 'reverse_scapula_sec') revSecIK = makeRevIk(revIK[0], scapulaBaseCtrl, baseSecName, revIK[0], baseScapAttrName) mc.setAttr('{}.{}'.format(revIK[0], baseScapAttrName), 1) mc.setAttr('{}.{}'.format(revIK[0], baseScapAttrName), l=True) mc.pointConstraint(revSecIK[1], basScapSecChain[3], mo=True) # constraint reverse chain Orig to base leg ctrl revChainOrig = mc.listRelatives(revIK[0], p=True) legBaseCtrl = '{}_{}_leg_01_base_ctrl'.format(side, fix) mc.pointConstraint(legBaseCtrl, revChainOrig, mo=True) # connect base scapula ctrl to advance attr mc.connectAttr('{}.advanced'.format(attrNode), '{}.visibility'.format(scapulaBaseCtrlOrig)) #### back leg #### fix = intFixes[1] sideHipRoot = '{}_hip_ctrl'.format(side) sideHipEnd = '{}_{}_leg_root_offset_ctrl'.format(side, fix) # --- make side hip auto sideHipAuto = makeAutoNode(sideHipEnd) # --- add end joint on side hips control sideHipBaseName = sideHipRoot.replace('ctrl', 'chain') siddeHipChain = makeChainFromObj(sideHipRoot, sideHipEnd, sideHipBaseName) mc.parent(siddeHipChain[2], sideHipRoot) # --- re PointConstraint mc.pointConstraint(siddeHipChain[1], sideHipAuto[1]) # --- double side hip chain in IK fullStretch controlled by back leg offset sideHipSecRoot = mc.listRelatives(sideHipEnd, p=True) sideHipSecBaseName = sideHipBaseName.replace('chain', 'sec') sideHipSecattrName = 'sideHipScale' sideHipSecChain = makeRevIk(siddeHipChain[0], sideHipSecRoot, sideHipSecBaseName, siddeHipChain[0], sideHipSecattrName) mc.setAttr('{}.{}'.format(siddeHipChain[0], sideHipSecattrName), 1) mc.setAttr('{}.{}'.format(siddeHipChain[0], sideHipSecattrName), l=True) # --- constraint side hip ik to back leg base Ctrl backLegBaseCtrl = '{}_{}_leg_01_base_ctrl'.format(side, fix) mc.pointConstraint(backLegBaseCtrl, sideHipSecChain[3], mo=True)
def buildToes(sides, intFixes, baseName, branches): #sides = ['L','R'] #intFixes = ['front','back'] #baseName = 'toes' #branches = ['pinkyToe','ringToe','middleToe','bigToe'] baseRgb = [[0, 0, 1], [1, 0, 0]] darkRgb = [[0, 0, .8], [.8, 0, 0]] lightRgb = [[.5, .5, 1], [1, .5, .5]] for fix in intFixes: for s, side in enumerate(sides): # toes All control ## get average toes world pos worldPosList = [] for branch in branches: tipPos = mc.xform('{}_{}_{}_IK_ctrl'.format(side, fix, branch), q=True, ws=True, t=True) worldPosList.append(tipPos) worldPosListLen = len(worldPosList) worldPosSum = [0, 0, 0] for i in range(0, worldPosListLen): worldPosSum[0] += worldPosList[i][0] worldPosSum[1] += worldPosList[i][1] worldPosSum[2] += worldPosList[i][2] worldPosAverage = [ worldPosSum[0] / worldPosListLen, worldPosSum[1] / worldPosListLen, worldPosSum[2] / worldPosListLen ] ## create toes All Ctrl toesAllCtrl = mc.group(n='{}_{}_toes_all_IK_ctrl'.format( side, fix), em=True) mc.setAttr('{}.translate'.format(toesAllCtrl), worldPosAverage[0], worldPosAverage[1], worldPosAverage[2]) mc.parent(toesAllCtrl, '{}_{}_foot_03_SKN'.format(side, fix)) mc.setAttr('{}.translateX'.format(toesAllCtrl), 0) shapes.create(toesAllCtrl, shape='square', size=1, scale=[.55, .2, .4], axis='y', twist=0, offset=[0, 0, 0], color=lightRgb[s], colorDegradeTo=None, replace=True, middle=False) orig.orig(objlist=[toesAllCtrl], suffix=['_orig'], origtype='transform', fromsel=False, viz=False, get_ssc=False, rtyp='auto') # reparent and constraint main toes grp mc.parent('{}_{}_toes'.format(side, fix), '{}_{}_leg_scl'.format(side, fix)) mc.parentConstraint('{}_{}_foot_02_SKN'.format(side, fix), '{}_{}_toes'.format(side, fix), mo=True) # reparent cushion joint mc.parent('{}_{}_cushion_ctrl_orig'.format(side, fix), '{}_{}_leg_scl'.format(side, fix)) mc.disconnectAttr( '{}_{}_leg_scl.scale'.format(side, fix), '{}_{}_cushion_ctrl_orig.inverseScale'.format(side, fix)) for branch in branches: # reparent toes hierarchy mc.parent('{}_{}_{}_IK_ctrl_orig'.format(side, fix, branch), toesAllCtrl) # reparent toes tips in toes end joints mc.parent('{}_{}_{}_tip_ctrl_orig'.format(side, fix, branch), '{}_{}_{}_end'.format(side, fix, branch)) # reparent ik poleVectors in ik ctrl origs mc.parent('{}_{}_{}_PV_ctrl_orig'.format(side, fix, branch), '{}_{}_{}_IK_ctrl_orig'.format(side, fix, branch)) # add upVectors visSwitch attrNode = '{}_{}_{}_IK_ctrl'.format(side, fix, branch) AttrName = 'showUpV' mc.addAttr(attrNode, ln=AttrName, at='bool', dv=0) mc.setAttr('{}.{}'.format(attrNode, AttrName), edit=True, k=True) mc.connectAttr('{}.{}'.format(attrNode, AttrName), '{}_{}_{}_PV_ctrl_orig.visibility'.format( side, fix, branch), f=True) # make blens orient rig for toes tips tipOrigParent = mc.listRelatives( '{}_{}_{}_tip_ctrl_orig'.format(side, fix, branch), p=True)[0] ## create hold grp holdGrp = mc.group(n='{}_{}_{}_tip_hold'.format( side, fix, branch), em=True) mc.parent(holdGrp, '{}_{}_{}_tip_ctrl_orig'.format(side, fix, branch), r=True) mc.parent(holdGrp, tipOrigParent) ## create orient constraint and blend ### create orient Attr attrNode = '{}_{}_{}_IK_ctrl'.format(side, fix, branch) AttrName = 'toeTipOrient' mc.addAttr(attrNode, ln=AttrName, at='double', min=0, max=1, dv=0) mc.setAttr('{}.{}'.format(attrNode, AttrName), edit=True, k=True) ### multipliy Attr and ikFK blend toeTipOrientMDL = mc.createNode( 'multDoubleLinear', n='{}_{}_{}_tipOrient_mdl'.format(side, fix, branch)) mc.connectAttr('{}.{}'.format(attrNode, AttrName), '{}.input1'.format(toeTipOrientMDL)) mc.connectAttr( '{}_{}_{}_SW_ctrl.fkIk'.format(side, fix, branch), '{}.input2'.format(toeTipOrientMDL)) ### orientConstraint toes tip orig tipOrientCns = mc.orientConstraint( '{}_{}_{}_IK_ctrl'.format(side, fix, branch), holdGrp, '{}_{}_{}_tip_ctrl_orig'.format(side, fix, branch), mo=True)[0] ### add reverse node and connect blend on orient constraint toeTipOrientRv = mc.createNode( 'reverse', n='{}_{}_{}_tipOrient_rv'.format(side, fix, branch)) mc.connectAttr('{}.output'.format(toeTipOrientMDL), '{}.inputX'.format(toeTipOrientRv)) mc.connectAttr( '{}.output'.format(toeTipOrientMDL), '{}.target[0].targetWeight'.format(tipOrientCns), f=True) mc.connectAttr( '{}.outputX'.format(toeTipOrientRv), '{}.target[1].targetWeight'.format(tipOrientCns), f=True) # change shapes shapes.create('{}_{}_{}_nail_ctrl'.format(side, fix, branch), shape='cube', size=.1, scale=[.5, 1, .5], axis='z', twist=0, offset=[0, 0, 0], color=lightRgb[s], colorDegradeTo=None, replace=True, middle=False) shapes.create('{}_{}_{}_tip_ctrl'.format(side, fix, branch), shape='square', size=.25, scale=[.4, .5, .75], axis='y', twist=0, offset=[0, 0, 0], color=darkRgb[s], colorDegradeTo=None, replace=True, middle=False) shapes.create('{}_{}_{}_squash_ctrl'.format(side, fix, branch), shape='cube', size=.15, scale=[.6, .1, 1], axis='y', twist=0, offset=[0, 0, 0], color=lightRgb[s], colorDegradeTo=None, replace=True, middle=False) shapes.create('{}_{}_{}_IK_ctrl'.format(side, fix, branch), shape='square', size=.25, scale=[.5, .5, 1], axis='y', twist=0, offset=[0, 0, 0], color=baseRgb[s], colorDegradeTo=None, replace=True, middle=False) shapes.create('{}_{}_cushion_ctrl'.format(side, fix), shape='square', size=.3, scale=[1, 1, 1], axis='y', twist=0, offset=[0, 0, 0], color=baseRgb[s], colorDegradeTo=None, replace=True, middle=False) shapes.create('{}_{}_leg_scl_ctrl'.format(side, fix), shape='cube', size=.22, scale=[1, .3, 1], axis='y', twist=0, offset=[0, 0, 0], color=lightRgb[s], colorDegradeTo=None, replace=True, middle=False)
def patch(): facialDrv = 'facialDrivers' eyeMaskOrig = 'eyeMask_ctrl_orig' JawClenchLOrig = 'Jaw_Clench_l_ctrl_orig' JawClenchROrig = 'Jaw_Clench_r_ctrl_orig' UpHeadGuide = 'UpHead_ctrl_GUIDE_01' UpHeadOrig = 'UpHead_ctrl_01_orig' UpHeadCtrl = 'UpHead_ctrl_01' LowerHeadGuide = 'LowerHead_ctrl_GUIDE_01' LowerHeadOrig = 'LowerHead_ctrl_01_orig' LowerHeadCtrl = 'LowerHead_ctrl_01' mouthSquashOrig = 'mouthSquash_jnt_orig' foreheadGrp = 'forehead_grp' headSKN = 'head_SKN' jawctrl = 'jaw_ctrl' noseGrp = 'nose_grp' noseUpCtrl = 'nose_up_ctrl' try: #reparent halfSkulls mc.parent(eyeMaskOrig, UpHeadOrig, LowerHeadOrig, headSKN) #reparent jawClenches mc.parent(JawClenchLOrig, JawClenchROrig, jawctrl) #reparent foreHead into topSKull mc.parent(foreheadGrp, UpHeadCtrl) #reparent mouthSquash et nose into lowerSkull mc.parent(mouthSquashOrig, LowerHeadCtrl) mc.parent(noseGrp, headSKN) #deparent halfSkulls guides mc.parent(UpHeadGuide, LowerHeadGuide, facialDrv) #hide guides mc.hide(UpHeadGuide, LowerHeadGuide) #change midSkulls ctrlShapes shapes.create(UpHeadCtrl, shape='circleHalf', size=2, scale=[1.25, 1, 1.75], axis='y', twist=-90, offset=[0, 0, 0.5], color=[255, 255, 0], colorDegradeTo=None, replace=True, middle=False) shapes.create(LowerHeadCtrl, shape='circleHalf', size=2, scale=[1.25, 1, 1.75], axis='y', twist=90, offset=[0, 0, -0.5], color=[255, 255, 0], colorDegradeTo=False, replace=True, middle=False) #add noseFollow noseCtrlOrig = mc.listRelatives(noseUpCtrl, p=True)[0] noseHold = mc.group(n='%s_hold' % noseCtrlOrig, em=True) mc.parent(noseHold, noseCtrlOrig, r=True) mc.parent(noseHold, noseGrp) noseCns = mc.parentConstraint(LowerHeadCtrl, noseHold, noseCtrlOrig, mo=True)[0] noseRv = mc.createNode('reverse', n='%s_rv' % noseCtrlOrig) mc.connectAttr('%s.Nose_Follow' % noseUpCtrl, '%s.target[0].targetWeight' % noseCns, f=True) mc.connectAttr('%s.Nose_Follow' % noseUpCtrl, '%s.inputX' % noseRv) mc.connectAttr('%s.outputX' % noseRv, '%s.target[1].targetWeight' % noseCns, f=True) # attaches the tongue FK to the mouth inside mesh layeredFKTongue.doLayeredFkTongue() # upgrades teeth rig teethGen.generateTeeth() except: print 'template not conform to patchScript'
def generateTeeth(): stacks = ['up', 'dn'] sides = ['L', 'R'] baseName = 'teeth' MainGuideSuff = 'jnt_GUIDE' noXformGrp = 'teeth_noXformGrp' mouthCtrl = 'mouth_ctrl' gumsMesh = 'gum_hi' gumsMeshAlt = 'gums_hi' teethGuidesGrp = '%s_guides_grp' % baseName # --- creating noXformGrp for later use mc.group(n=noXformGrp, em=True) mc.parent(noXformGrp, 'facial_fGrp') mc.hide(noXformGrp) # --- creating hold_jnt for further use mc.select(cl=True) holdJnt = mc.joint(n='%s_hold_jnt' % baseName) mc.parent(holdJnt, noXformGrp) for stack in stacks: mainTeethParent = '%s_%s_SKN' % (baseName, stack) mainBaseGuide = '%s_%s_%s' % (baseName, stack, MainGuideSuff) crvGuidesGrp = '%s_%s_guides_grp' % (baseName, stack) # --- get all teeth guides from template groups mainGuides = mc.listRelatives(mainBaseGuide, c=True, type='joint') # --- tweak and realign jawGen generated controls allGuides = mainGuides mainGuides.append(mainBaseGuide) allOrient = [] for guide in allGuides: parent = mc.listRelatives(guide, p=True)[0] mc.parent(guide, w=True) RO = mc.getAttr('%s.rotate' % guide)[0] JO = mc.getAttr('%s.jointOrient' % guide)[0] orient = (RO[0] + JO[0], RO[1] + JO[1], RO[2] + JO[2]) allOrient.append(orient) mc.parent(guide, parent) parentList = [] for g, guide in enumerate(allGuides): ctrl = guide.replace('GUIDE', 'orig') parent = mc.listRelatives(ctrl, p=True)[0] parentList.append(parent) mc.parent(ctrl, w=True) mc.setAttr('%s.jointOrient' % ctrl, 0, 0, 0) mc.setAttr('%s.rotate' % ctrl, allOrient[g][0], allOrient[g][1], allOrient[g][2]) for g, guide in enumerate(reversed(allGuides)): ctrl = guide.replace('GUIDE', 'orig') parent = parentList[-1 - g] mc.parent(ctrl, parent) if g > 0: mc.setAttr('%s.jointOrientX' % ctrl, 0) mc.setAttr('%s.jointOrientZ' % ctrl, 0) mc.setAttr('%s.rotateX' % ctrl, 0) mc.setAttr('%s.rotateZ' % ctrl, 0) ## --- create midCtrls symmetry midCtrls = [] for g, guide in enumerate(allGuides): ctrl = guide.replace('GUIDE', 'orig') splitName = ctrl.rsplit('_', 3)[1] if splitName == 'mid': midCtrls.append(ctrl) RCtrls = mc.duplicate(ctrl, n=ctrl.replace('L_', 'R_')) midCtrls.append(RCtrls[0]) ### --- rename childs of dupilcated control RCtrlChilds = mc.listRelatives(RCtrls[0], ad=True, f=True) for c, child in enumerate(RCtrlChilds): if c > 0: strippedName = child.rsplit('|', 1)[1] newName = mc.rename(child, strippedName.replace('L_', 'R_')) ### --- reconnect control to SKN of duplicated mid Ctrl renamedChilds = mc.listRelatives(RCtrls[0], ad=True) for child in renamedChilds: splitName = child.rsplit('_', 1)[1] if splitName == 'ctrl': if not mc.objectType(child) == 'nurbsCurve': patchLib.smartcopyAttr( child, child.replace('_ctrl', '_SKN')) patchLib.smartConnect( child, child.replace('_ctrl', '_SKN')) ### --- position RCtrl on symmetry #print ctrl mc.setAttr('%s.translateX' % RCtrls[0], -(mc.getAttr('%s.translateX' % ctrl))) mc.setAttr('%s.scaleX' % RCtrls[0], -1) ## --- create new parent placed at origin for midCtrls midParent = mc.group(n='%s_%s_mids_orig' % (stack, baseName), em=True) mc.parent(midParent, mainTeethParent) mc.parent(midCtrls, midParent) # --- create world rigs from jawGen generated controls ## --- get all the objects that need a world duplicate mainTeethChilds = mc.listRelatives(mainTeethParent, c=True, ad=True, s=False) worldTargets = [] for child in mainTeethChilds: if not mc.objectType(child) == 'nurbsCurve': worldTargets.append(child) ## --- create duplicated world objects and connects them to the actual controls ### --- create duplicate for main node worldParent = mc.duplicate(mainTeethParent, po=True, n='%s_world' % mainTeethParent)[0] mc.parent(worldParent, noXformGrp) ### --- create duplicates for every childNode of main node. Connect local Rig to world Rig worldParentdict = dict() worldNodes = [] for target in worldTargets: splitName = target.split('_') parent = mc.listRelatives(target, p=True)[0] if not 'ctrl' in splitName: if not splitName[0] == 'C': #### --- create world node worldNode = mc.duplicate(target, po=True, n='%s_world' % target)[0] mc.parent(worldNode, noXformGrp) worldNodes.append(worldNode) worldParentdict[worldNode] = (parent) #### --- do the conection if not 'mid' in splitName: if not 'mids' in splitName: patchLib.smartcopyAttr(target, worldNode) patchLib.smartConnect(target, worldNode) elif 'mids' in splitName: pass elif 'mid' in splitName: if not 'orig' in splitName: patchLib.smartcopyAttr(target, worldNode) patchLib.smartConnect(target, worldNode) else: ROCon = mc.listConnections('%s.rotateOrder' % target, s=True, p=True) if ROCon: mc.disconnectAttr(ROCon[0], '%s.rotateOrder' % target) patchLib.smartcopyAttr(worldNode, target) patchLib.smartConnect(worldNode, target) elif splitName[0] == 'C': #### --- create world node LWorldNode = mc.duplicate(target, po=True, n='L%s_world' % target)[0] RWorldNode = mc.duplicate(target, po=True, n='R%s_world' % target)[0] mc.parent(LWorldNode, RWorldNode, noXformGrp) worldNodes.append(LWorldNode) worldNodes.append(RWorldNode) parentSplit = parent.split('_', 1)[0] if not parentSplit == 'C': worldParentdict[LWorldNode] = (parent) worldParentdict[RWorldNode] = (parent) elif parentSplit == 'C': worldParentdict[LWorldNode] = ('L%s' % parent) worldParentdict[RWorldNode] = ('R%s' % parent) #### --- do the conection patchLib.smartcopyAttr(target, LWorldNode) patchLib.smartcopyAttr(target, RWorldNode) patchLib.smartConnect(target, LWorldNode) patchLib.smartConnect(target, RWorldNode) ### --- reparent world nodes to recreate local hierarchy for node in worldNodes: localParent = worldParentdict.get(node) mc.parent(node, '%s_world' % localParent) # --- get all curve teeth guides from template groups allCrvGuides = mc.listRelatives(crvGuidesGrp, c=True) ## --- separate the loft guides from the rest popIndex = 0 crvLoftGuide = '' for g, guide in enumerate(allCrvGuides): splitName = guide.rsplit('_crv_')[-1] if splitName == 'GUIDE': popIndex = g crvLoftGuide = allCrvGuides.pop(g) # --- lofts from curves and symmetrise them to create n0 surfaces ## --- create left loft curves LdnCrv = mc.duplicate(crvLoftGuide, n=crvLoftGuide.replace('GUIDE', 'Loft_00'))[0] LupCrv = mc.duplicate(crvLoftGuide, n=crvLoftGuide.replace('GUIDE', 'Loft_01'))[0] patchLib.locksSwitch(LdnCrv, T=True, R=True, S=True, V=True, lockdo='unlock', keydo=True) patchLib.locksSwitch(LupCrv, T=True, R=True, S=True, V=True, lockdo='unlock', keydo=True) mc.parent(LdnCrv, LupCrv, mainTeethParent) mc.makeIdentity(LdnCrv, a=True) mc.makeIdentity(LupCrv, a=True) mc.makeIdentity(LdnCrv, a=False) mc.makeIdentity(LupCrv, a=False) offsetVal = 0.01 mc.setAttr('%s.translateY' % LdnCrv, (-offsetVal)) mc.setAttr('%s.translateY' % LupCrv, offsetVal) mc.parent(LdnCrv, LupCrv, w=True) mc.makeIdentity(LdnCrv, a=True) mc.makeIdentity(LupCrv, a=True) mc.makeIdentity(LdnCrv, a=False) mc.makeIdentity(LupCrv, a=False) ## --- create right loft curves RdnCrv = mc.duplicate(LdnCrv, n=LdnCrv.replace('L_', 'R_'))[0] RupCrv = mc.duplicate(LupCrv, n=LupCrv.replace('L_', 'R_'))[0] mc.setAttr('%s.scaleX' % RdnCrv, -1) mc.setAttr('%s.scaleX' % RupCrv, -1) mc.makeIdentity(RdnCrv, a=True) mc.makeIdentity(RupCrv, a=True) mc.makeIdentity(RdnCrv, a=False) mc.makeIdentity(RupCrv, a=False) ## --- create loft surfaces LLoftSurf = mc.loft(LdnCrv, LupCrv, n='L_%s_%s_surf_n0' % (stack, baseName), ch=False)[0] RLoftSurf = mc.loft(RdnCrv, RupCrv, n='R_%s_%s_surf_n0' % (stack, baseName), ch=False)[0] loftSurfsN0 = [LLoftSurf, RLoftSurf] loftSurfsN1 = mc.duplicate(loftSurfsN0) loftSurfsN2 = mc.duplicate(loftSurfsN0) loftSurfsAll = [loftSurfsN0, loftSurfsN1, loftSurfsN2] mc.delete(LdnCrv, LupCrv, RdnCrv, RupCrv) mc.parent(loftSurfsAll[0], loftSurfsAll[1], loftSurfsAll[2], noXformGrp) ## --- disconnect unwanted ctrl to joints connections for target in worldNodes: splitName = target.split('_') if not 'gumsBase' in splitName: if 'SKN' in splitName: scaleCons = mc.listConnections('%s.scale' % target, s=True, p=True) if scaleCons: for con in scaleCons: mc.disconnectAttr(con, '%s.scale' % target) if 'mid' in splitName: mc.connectAttr('%sX' % con, '%s.scaleX' % target) if not 'mid' in splitName: if 'LC' in splitName or 'RC' in splitName: mc.connectAttr('%sX' % con, '%s.scaleX' % target) if 'L' in splitName or 'R' in splitName: mc.connectAttr('%sZ' % con, '%s.scaleZ' % target) ## --- symmetrise teeth guides and creates final teeth hierarchy LCtrlList = [] RCtrlList = [] ctrlLists = [LCtrlList, RCtrlList] for guide in allCrvGuides: guideChild = mc.listRelatives(guide, c=True, type='transform')[0] mainCtrl = createTeethCtrl(guide, mouthCtrl, stack) tipCtrl = createTeethCtrl(guideChild, mouthCtrl, stack) mc.parent(tipCtrl[1], mainCtrl[0]) mc.parent(mainCtrl[1], '%s_%s_SKN_world' % (baseName, stack)) skelLib.jointOrientToRotate(mainCtrl[1]) LCtrlList.append(mainCtrl[1]) splitName = guide.split('ibt_01') if not len(splitName) > 1: getTx = mc.getAttr('%s.translateX' % mainCtrl[1]) getRy = mc.getAttr('%s.rotateY' % mainCtrl[1]) symOrig = mc.duplicate(mainCtrl[1], ic=True, n=mainCtrl[1].replace('L_', 'R_'))[0] skelLib.jointOrientToRotate(symOrig) mc.setAttr('%s.translateX' % symOrig, -getTx) mc.setAttr('%s.rotateY' % symOrig, -getRy) symChilds = mc.listRelatives(symOrig, c=True, ad=True, f=True) for child in symChilds: splitName = child.rsplit('|', 1)[1] mc.rename(child, splitName.replace('L_', 'R_')) RCtrlList.append(symOrig) teethGroup = '%s_%s_allCtrls_orig' % (baseName, stack) mc.group(n=teethGroup, em=True) mc.parent(teethGroup, mainTeethParent) mc.parent(LCtrlList, RCtrlList, teethGroup) ## --- generating surfaces deformers and connections for s, side in enumerate(sides): ## --- weighting n0 surface n0SKC = mc.skinCluster( '%sC_%s_%s_SKN_world' % (side, baseName, stack), '%s_%s_%s_SKN_world' % (side, baseName, stack), loftSurfsN0[s], n='%s_SKC' % loftSurfsN0[s], mi=2, tsb=True)[0] ### --- create skinWeights anime Curve and reskin Surf from that curve skinCurveDef = { 'tangentsVal': [ 0.0, 47.702933224999114, 53.989547386085576, 55.545989790698755 ], 'keyCount': 4, 'keysValues': [0.0, 0.1322238293848932, 0.6123709362161491, 1.0], 'keysAtFrame': [0.0, 0.404, 0.696, 1.0] } skinCurve = patchLib.createAnimCurveFromDef( skinCurveDef, 'temp_teeth_skinCurve') ## --- weighting n1 surfaces and connect n0 outShape to n1 orig n1SKC = mc.skinCluster('%s_%s_%s_mid_SKN_world' % (side, baseName, stack), holdJnt, loftSurfsN1[s], n='%s_SKC' % loftSurfsN1[s], mi=2, dr=2, tsb=True)[0] patchLib.sineWeightsOnSurf(loftSurfsN1[s], 'u', False) patchLib.basicBPMOnNurbs(SKC=n1SKC, holdJnt=holdJnt) n0OutShape = mc.listConnections('%s.outputGeometry' % n0SKC, sh=True)[0] n1ShapeOrig = dagLib.findShapeOrig(loftSurfsN1[s]) mc.connectAttr('%s.worldSpace[0]' % n0OutShape, '%s.create' % n1ShapeOrig) ## --- attache midCtrls to surf n0 with XRivet for node in worldNodes: splitName = node.split('_') if side in splitName: if stack in splitName: if 'mid' in splitName: if 'orig' in splitName: if side == 'L': offset = getOffsetFromXrivet('x', 'y') elif side == 'R': offset = getOffsetFromXrivet('-x', '-y') mc.setAttr('%s.rotateOrder' % node, 0) mc.setAttr('%s.jointOrient' % node, 0, 0, 0) midXrivet = xrivetTrOnNurbs( node, loftSurfsN0[s], mainDirection=1, out='worldSpace[0]', u=None, v=None, offsetOrient=offset, min=False) #print '%s is beeing xrivetted !!! ' %node ## --- create node based final n2 surfaces ### --- extract new curves from isoParms dnCfsi = mc.createNode('curveFromSurfaceIso', n='%s_dn_cfsi' % loftSurfsN1[s]) upCfsi = mc.createNode('curveFromSurfaceIso', n='%s_up_cfsi' % loftSurfsN1[s]) mc.setAttr('%s.isoparmDirection' % dnCfsi, 1) mc.setAttr('%s.isoparmDirection' % upCfsi, 1) mc.setAttr('%s.isoparmValue' % dnCfsi, 0) mc.setAttr('%s.isoparmValue' % upCfsi, 1) mc.connectAttr('%s.worldSpace[0]' % loftSurfsN1[s], '%s.inputSurface' % dnCfsi) mc.connectAttr('%s.worldSpace[0]' % loftSurfsN1[s], '%s.inputSurface' % upCfsi) ### --- create sliding from rebuild on curves dnRc = mc.createNode('rebuildCurve', n='%s_dn_rc' % loftSurfsN1[s]) upRc = mc.createNode('rebuildCurve', n='%s_up_rc' % loftSurfsN1[s]) surfSpans = mc.getAttr('%s.spansV' % loftSurfsN1[s]) mc.setAttr('%s.spans' % dnRc, surfSpans) mc.setAttr('%s.spans' % upRc, surfSpans) mc.connectAttr('%s.outputCurve' % dnCfsi, '%s.inputCurve' % dnRc) mc.connectAttr('%s.outputCurve' % upCfsi, '%s.inputCurve' % upRc) ### --- create finalLoft and connect to surf n2 loft = mc.createNode('loft', n='%s_loft' % loftSurfsN2[s]) mc.setAttr('%s.uniform' % loft, 1) mc.connectAttr('%s.outputCurve' % dnRc, '%s.inputCurve[0]' % loft) mc.connectAttr('%s.outputCurve' % upRc, '%s.inputCurve[1]' % loft) mc.connectAttr('%s.outputSurface' % loft, '%s.create' % loftSurfsN2[s]) ## --- attach teeth on n2 surface for control in ctrlLists[s]: endXrivet = xrivetTrOnNurbs(control, loftSurfsN2[s], mainDirection=1, out='worldSpace[0]', u=None, v=None, offsetOrient=offset, min=False) mc.setAttr('%s.jointOrient' % control, 0, 0, 0) ## --- connect teeth ctrl joits to teeth scales endsCtrls = [ 'C_%s_%s_ctrl' % (baseName, stack), '%s_%s_%s_ctrl' % (side, baseName, stack) ] midCtrl = '%s_%s_%s_mid_ctrl' % (side, baseName, stack) for i, each in enumerate(ctrlLists[s]): # getting position percentage from position on surface ## getVpos from joints, it will be used in the 'curveFromSurfaceUV' node surfShape = dagLib.getFirstShape(loftSurfsN2[s]) cpos = mc.createNode('closestPointOnSurface', n='temp_cpos') mc.connectAttr('%s.worldSpace[0]' % surfShape, '%s.inputSurface' % cpos) pointPos = mc.xform(each, q=True, ws=True, t=True) mc.setAttr('%s.inPosition' % cpos, pointPos[0], pointPos[1], pointPos[2]) paramV = mc.getAttr('%s.parameterV' % cpos) mc.delete(cpos) ## creates curve from node and get position percentage of joint from it tempCrv = mc.curve(d=3, p=[(0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3)]) tempCfsi = mc.createNode('curveFromSurfaceIso', n='temp_cfsi') mc.setAttr('%s.isoparmValue' % tempCfsi, paramV) mc.setAttr('%s.isoparmDirection' % tempCfsi, 1) mc.connectAttr('%s.worldSpace[0]' % surfShape, '%s.inputSurface' % tempCfsi) mc.connectAttr('%s.outputCurve' % tempCfsi, '%s.create' % tempCrv) paramOnCrv = curveLib.getClosestPointOnCurve(tempCrv, pointPos, space='world')[1] percent = curveLib.findPercentFromParam(tempCrv, paramOnCrv) mc.delete(tempCfsi, tempCrv) #print '%s is %s percent' %(each,percent) # get soft fallof from percent and sine function sideSine = ((math.sin((percent * math.pi) - (math.pi / 2))) + 1) / 2 midSine = math.sin(percent * math.pi) #print '%s is %s sideSine' %(each,sideSine) PMA = mc.createNode('plusMinusAverage', n='%s_scale_pma' % each) centerPMA = mc.createNode('plusMinusAverage', n='%s_scale_center_pma' % each) sidePMA = mc.createNode('plusMinusAverage', n='%s_scale_center_side_pma' % each) midPMA = mc.createNode('plusMinusAverage', n='%s_scale_center_mid_pma' % each) mc.setAttr('%s.operation' % centerPMA, 2) mc.setAttr('%s.input3D[1]' % centerPMA, 1, 1, 1) mc.setAttr('%s.operation' % sidePMA, 2) mc.setAttr('%s.input3D[1]' % sidePMA, 1, 1, 1) mc.setAttr('%s.operation' % midPMA, 2) mc.setAttr('%s.input3D[1]' % midPMA, 1, 1, 1) mc.connectAttr('%s.scale' % endsCtrls[0], '%s.input3D[0]' % centerPMA) mc.connectAttr('%s.scale' % endsCtrls[1], '%s.input3D[0]' % sidePMA) mc.connectAttr('%s.scale' % midCtrl, '%s.input3D[0]' % midPMA) centerMD = mc.createNode('multiplyDivide', n='%s_center_scale_MD' % each) sideMD = mc.createNode('multiplyDivide', n='%s_side_scale_MD' % each) midMD = mc.createNode('multiplyDivide', n='%s_mid_scale_MD' % each) mc.connectAttr('%s.output3D' % centerPMA, '%s.input1' % centerMD) mc.connectAttr('%s.output3D' % sidePMA, '%s.input1' % sideMD) mc.connectAttr('%s.output3D' % midPMA, '%s.input1' % midMD) mc.setAttr('%s.input2' % centerMD, 1 - sideSine, 1 - sideSine, 1 - sideSine) mc.setAttr('%s.input2' % sideMD, sideSine, sideSine, sideSine) mc.setAttr('%s.input2' % midMD, midSine, midSine, midSine) mc.setAttr('%s.input2D[0]' % PMA, 1, 1) mc.connectAttr('%s.outputZ' % centerMD, '%s.input2D[1].input2Dx' % PMA) mc.connectAttr('%s.outputY' % centerMD, '%s.input2D[1].input2Dy' % PMA) mc.connectAttr('%s.outputX' % sideMD, '%s.input2D[2].input2Dx' % PMA) mc.connectAttr('%s.outputY' % sideMD, '%s.input2D[2].input2Dy' % PMA) mc.connectAttr('%s.outputZ' % midMD, '%s.input2D[3].input2Dx' % PMA) mc.connectAttr('%s.outputY' % midMD, '%s.input2D[3].input2Dy' % PMA) mc.connectAttr('%s.output2Dx' % PMA, '%s.scaleZ' % each) mc.connectAttr('%s.output2Dy' % PMA, '%s.scaleY' % each) # --- add bpm cluster to top and bottom teeth for ctrl in worldTargets: splitName = ctrl.split('_') if 'gumsBase' in splitName: if 'SKN' in splitName: parent = mc.listRelatives(ctrl, p=True)[0] mc.select(cl=True) newClstr = mc.cluster(n='%s_%s_cluster' % (splitName[0], splitName[1]), bs=True, wn=(ctrl, ctrl))[0] mc.connectAttr('%s.parentInverseMatrix[0]' % ctrl, '%s.bindPreMatrix' % newClstr) if mc.objExists(gumsMesh): clstrSet = mc.listConnections(newClstr, type="objectSet")[0] mc.sets(gumsMesh, add=clstrSet) elif mc.objExists(gumsMeshAlt): clstrSet = mc.listConnections(newClstr, type="objectSet")[0] mc.sets(gumsMeshAlt, add=clstrSet) # --- tweak shapes and colors of base ctrls for ctrl in worldTargets: splitName = ctrl.split('_') if 'gumsBase' in splitName: if 'ctrl' in splitName: shapes.create(ctrl, shape='circleLowHalf', size=0.2, scale=[1, 1, 1], axis='y', twist=90, offset=[0, 0, -0.06], color=[1, 0, 0], colorDegradeTo=None, replace=True, middle=False) if 'L' in splitName: if 'ctrl' in splitName: if not 'mid' in splitName: shapes.create(ctrl, shape='pyramid', size=0.15, scale=[1, 1, 1], axis='x', twist=0, offset=[0.05, 0, 0], color=[0, 0, 1], colorDegradeTo=None, replace=True, middle=False) if 'mid' in splitName: shapes.create(ctrl, shape='pyramid', size=0.1, scale=[1, 1, 1], axis='z', twist=0, offset=[0, 0, 0.05], color=[0.5, 0.5, 1], colorDegradeTo=None, replace=True, middle=False) if 'R' in splitName: if 'ctrl' in splitName: if not 'mid' in splitName: shapes.create(ctrl, shape='pyramid', size=0.15, scale=[1, 1, 1], axis='-x', twist=0, offset=[-0.05, 0, 0], color=[1, 0, 0], colorDegradeTo=None, replace=True, middle=False) if 'mid' in splitName: shapes.create(ctrl, shape='pyramid', size=0.1, scale=[1, 1, 1], axis='z', twist=0, offset=[0, 0, 0.05], color=[1, 0.5, 0.5], colorDegradeTo=None, replace=True, middle=False) if 'C' in splitName: if 'ctrl' in splitName: shapes.create(ctrl, shape='pyramid', size=0.15, scale=[1, 1, 1], axis='z', twist=0, offset=[0, 0, 0.05], color=[1, 1, 0], colorDegradeTo=None, replace=True, middle=False) # --- cleanup , sets and stuff trashNodes = mc.ls('transform?', type='transform') mc.delete(trashNodes) mc.parent(teethGuidesGrp, 'head_%s' % MainGuideSuff) addToSetList = [ 'L_teeth_up_ctrl', 'R_teeth_up_ctrl', 'C_teeth_up_ctrl', 'L_teeth_dn_ctrl', 'R_teeth_dn_ctrl', 'C_teeth_dn_ctrl', 'gumsBase_up_ctrl', 'gumsBase_dn_ctrl', 'L_teeth_up_mid_ctrl', 'L_teeth_dn_mid_ctrl', 'R_teeth_up_mid_ctrl', 'R_teeth_dn_mid_ctrl' ] if mc.objExists('anim_set'): mc.sets(addToSetList, add='anim_set')
def patch(): facialDrv = 'facialDrivers' eyeMaskOrig = 'eyeMask_ctrl_orig' JawClenchLOrig = 'Jaw_Clench_l_ctrl_orig' JawClenchROrig = 'Jaw_Clench_r_ctrl_orig' jawChinOrig = 'jawChin_ctrl_orig' UpHeadGuide = 'UpHead_ctrl_GUIDE_01' UpHeadOrig = 'UpHead_ctrl_01_orig' UpHeadCtrl = 'UpHead_ctrl_01' LowerHeadGuide = 'LowerHead_ctrl_GUIDE_01' LowerHeadOrig = 'LowerHead_ctrl_01_orig' LowerHeadCtrl = 'LowerHead_ctrl_01' mouthSquashOrig = 'mouthSquash_jnt_orig' mouthSquashSKN = 'mouthSquash_SKN' mouthGlobal = 'mouthGlobal_ctrl_orig' foreheadGrp = 'forehead_grp' headSKN = 'head_SKN' jawctrl = 'jaw_ctrl' jawJntOrig = 'jaw_jnt_orig' jawShapeGrp = 'jaw_SHAPE_grp' jawMidSkin = 'jaw_02_SKN' noseGrp = 'nose_grp' noseUp = 'nose_up_ctrl' noseUpOrig = 'nose_up_ctr_orig' neckTrash = 'neck_grpTRASH' earGrp = 'ear_grp' eyeGrp = 'eye_grp' eyeMaskGrp = 'eyeMask_ctrl_orig' sides = ['L', 'R', 'C'] lipFlapOrig = 'lipFlap_ctrl_01_orig' lipflapAll = 'lipFlap_all_ctrl' lipflapTip = 'lipFlap_tip_ctrl' lipflapCup = 'lipFlap_cup_ctrl' lipFlapList = [lipflapAll, lipflapTip, lipflapCup] #try : #reparent halfSkulls mc.parent(eyeMaskOrig, UpHeadOrig, LowerHeadOrig, headSKN) #reparent jawClenches mc.parent(JawClenchLOrig, JawClenchROrig, jawctrl) #reparent foreHead into topSKull mc.parent(foreheadGrp, UpHeadCtrl) #reparent mouthSquash et nose into lowerSkull mc.parent(noseGrp, mouthSquashOrig, LowerHeadCtrl) #deparent halfSkulls guides mc.parent(UpHeadGuide, LowerHeadGuide, facialDrv) # reparent jawChin in MidHJaw mc.parent(jawChinOrig, jawMidSkin) #change midSkulls ctrlShapes shapes.create(UpHeadCtrl, shape='circleHalf', size=2, scale=[1.25, 1, 1.75], axis='y', twist=-90, offset=[0, 0, 0.5], color=[255, 255, 0], colorDegradeTo=None, replace=True, middle=False) shapes.create(LowerHeadCtrl, shape='circleHalf', size=2, scale=[1.25, 1, 1.75], axis='y', twist=90, offset=[0, 0, -0.5], color=[255, 255, 0], colorDegradeTo=False, replace=True, middle=False) # --- add upjaw ctrl ## create jawUp and jawUp proxies mc.select(cl=True) upJaw = mc.joint(n='upJaw_ctrl') mc.setAttr('{}.radius'.format(upJaw), 0.01) mc.select(cl=True) upJawLoHeadProxy = mc.joint(n='upJaw_loHead_proxy') mc.setAttr('{}.radius'.format(upJawLoHeadProxy), 0.01) mc.select(cl=True) upJawMSquashProxy = mc.joint(n='upJaw_mSquash_proxy') mc.setAttr('{}.radius'.format(upJawMSquashProxy), 0.01) jawpPos = mc.xform(jawctrl, q=True, ws=True, t=True) mc.xform(upJaw, ws=True, t=jawpPos) mc.xform(upJawLoHeadProxy, ws=True, t=jawpPos) mc.xform(upJawMSquashProxy, ws=True, t=jawpPos) jawPosOrigs = orig.orig( objlist=[upJaw, upJawLoHeadProxy, upJawMSquashProxy], suffix=['_orig'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto') ## reparent nodes in jawUp nodes mc.parent(eyeGrp, eyeMaskGrp, UpHeadOrig, upJaw) mc.parent(noseGrp, upJawLoHeadProxy) mSquashSKNChilds = mc.listRelatives(mouthSquashSKN, c=True) for child in mSquashSKNChilds: if not (child == jawJntOrig or child == jawShapeGrp): print child mc.parent(child, upJawMSquashProxy) ## reparent jawUp nodes mc.parent(jawPosOrigs[0], headSKN) mc.parent(jawPosOrigs[1], LowerHeadCtrl) mc.parent(jawPosOrigs[2], mouthSquashSKN) ## connectJawUps smartConnect(upJaw, upJawLoHeadProxy) smartConnect(upJaw, upJawMSquashProxy) # --- add shape to UpJaw shapes.create(upJaw, shape='pinSphere', size=0.75, scale=[1, 1, 1], axis='y', twist=0, offset=[0, .75, 0], color=[1, 1, 0], colorDegradeTo=None, replace=True, middle=False) # --- change mouthGlobal parentConstraint targets mouthGlobalCns = mc.listConnections('{}.translateX'.format(mouthGlobal), s=True)[0] mc.delete(mouthGlobalCns) mc.parentConstraint(upJaw, jawctrl, mouthGlobal, mo=True) # --- add upJaw to skinSet mc.sets(upJaw, add='head_jnt_skin_set') # --- reparent and adjust Shapes for flaps ctrls mainColList = [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0]] secColList = [[0.5, 0.5, 1.0], [1.0, 0.5, 0.5], [1.0, 1.0, 0.65]] sizeList = [0.07, 0.07, 0.04] for s, side in enumerate(sides): ## --- reparent dKey ctrls to world allCtrl = '%s_%s' % (side, lipflapAll) tipCtrl = '%s_%s' % (side, lipflapTip) allCtrlOrig = mc.listRelatives('%s_%s' % (side, lipflapAll), p=True)[0] mc.parent(allCtrlOrig, w=True) if side == 'L': shapes.create(allCtrl, shape='pyramid', size=sizeList[s], scale=[1.5, -1.5, 1.5], axis='y', twist=0, offset=[0, -0.5, 0], color=mainColList[s], colorDegradeTo=None, replace=True, middle=False) shapes.create(tipCtrl, shape='arrowFourCurve', size=sizeList[s], scale=[0.8, -0.8, 0.8], axis='y', twist=0, offset=[0, -0.28, 0], color=secColList[s], colorDegradeTo=None, replace=True, middle=False) elif side == 'R': shapes.create(allCtrl, shape='pyramid', size=sizeList[s], scale=[1.5, 1.5, 1.5], axis='y', twist=0, offset=[0, 0.5, 0], color=mainColList[s], colorDegradeTo=None, replace=True, middle=False) shapes.create(tipCtrl, shape='arrowFourCurve', size=sizeList[s], scale=[0.8, 0.8, 0.8], axis='y', twist=0, offset=[0, 0.28, 0], color=secColList[s], colorDegradeTo=None, replace=True, middle=False) elif side == 'C': shapes.create(allCtrl, shape='pyramid', size=sizeList[s], scale=[1.5, -1.5, 1.5], axis='y', twist=0, offset=[0, -0.2, 0], color=mainColList[s], colorDegradeTo=None, replace=True, middle=False) shapes.create(tipCtrl, shape='arrowFourCurve', size=sizeList[s], scale=[0.8, -0.8, 0.8], axis='y', twist=0, offset=[0, -0.12, 0], color=secColList[s], colorDegradeTo=None, replace=True, middle=False) # add hierarchy for drivenKeys on lipFlaps fk joints dKeyAllNodesList = [] dKeyTipNodesList = [] for side in sides: sideDKeyNodesList = [] firstOrig = '%s_%s' % (side, lipFlapOrig) flapRoot = orig.orig(objlist=[firstOrig], suffix=['_root'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] allChilds = mc.listRelatives(flapRoot, c=True, typ='transform', ad=True) allChilds.reverse() for child in allChilds: stripName = child.rsplit('_', 1)[-1] if not stripName == 'orig' and not stripName == 'end': dkeyNode = orig.orig(objlist=[child], suffix=['_dKeyAll'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] sideDKeyNodesList.append(dkeyNode) dKeyAllNodesList.append(sideDKeyNodesList) for list in dKeyAllNodesList: sideDKeyNodesList = [] listLen = len(list) for i in range((listLen / 2), listLen): ctrl = mc.listRelatives(list[i], c=True, typ='transform')[0] dkeyNode = orig.orig(objlist=[ctrl], suffix=['_dKeyTip'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] sideDKeyNodesList.append(dkeyNode) dKeyTipNodesList.append(sideDKeyNodesList) # change controls shapes on lipFlaps FKs attrName = 'showLipFlapsFK' for s, side in enumerate(sides): mainFlapCtrl = '%s_%s' % (side, lipflapAll) mc.addAttr(mainFlapCtrl, ln=attrName, at='bool') mc.setAttr('%s.%s' % (mainFlapCtrl, attrName), edit=True, k=True) flapRoot = '%s_%s_root' % (side, lipFlapOrig) allChilds = mc.listRelatives(flapRoot, c=True, typ='transform', ad=True) allChilds.reverse() for child in allChilds: stripName = child.rsplit('_', 1)[-1] if not stripName == 'orig' and not stripName == 'end' and not stripName == 'dKeyAll' and not stripName == 'dKeyTip': if not side == 'R': shapes.create(child, shape='pinPyramid', size=sizeList[s], scale=[4, 5, 5], axis='-X', twist=0, offset=[0, 0, 0], color=mainColList[s], colorDegradeTo=None, replace=True, middle=False) else: shapes.create(child, shape='pinPyramid', size=sizeList[s], scale=[-4, 5, 5], axis='-X', twist=0, offset=[0, 0, 0], color=mainColList[s], colorDegradeTo=None, replace=True, middle=False) childShapes = mc.listRelatives(child, s=True) if childShapes: for childShape in childShapes: mc.connectAttr('%s.%s' % (mainFlapCtrl, attrName), '%s.visibility' % childShape) # scale R side -1 to get propper symmetrical behavior for each in (lipFlapList[0], lipFlapList[1]): if each == 'lipFlap_cup_ctrl': mc.setAttr('%s_%s.jointOrientY' % (sides[1], each), 180) else: mc.setAttr('%s_%s_orig.scale' % (sides[1], each), -1, -1, -1) for side in sides[1]: root = '%s_%s_root' % (side, lipFlapOrig) allChilds = mc.listRelatives(root, c=True, typ='transform', ad=True) allChilds.reverse() for child in allChilds: stripName = child.rsplit('_', 1)[-1] if stripName == 'orig' or stripName == 'dKeyAll' or stripName == 'dKeyTip': mc.setAttr('%s.scale' % child, -1, -1, -1) #reparent all flaps inside mouthSquash for side in sides: mc.parent('%s_%s_root' % (side, lipFlapOrig), '%s_%s_orig' % (side, lipflapAll), mouthSquashSKN) mc.parent('%s_%s_orig' % (side, lipflapCup), mouthSquashSKN) # --- create smart_flaps joints smartFlapsGrp = mc.group(n='flaps_smart_grp', em=True) mc.parent(smartFlapsGrp, 'facial_fGrp') mc.setAttr('%s.inheritsTransform' % smartFlapsGrp, False) mc.select(cl=True) smartFlapsHoldJnt = mc.joint(n='flaps_smart_hold_jnt') mc.parent(smartFlapsHoldJnt, smartFlapsGrp) smartTrgt = [ '%s_%s_root' % (sides[0], lipFlapOrig), '%s_%s_root' % (sides[1], lipFlapOrig), '%s_%s_root' % (sides[2], lipFlapOrig) ] smartDupTargets = [] for each in smartTrgt: newTrgt = mc.duplicate(each, n='%s_smart' % each)[0] smartDupTargets.append(newTrgt) mc.parent(smartDupTargets, smartFlapsGrp) # --- add dkNode on top of nose_upCtrl noseUpDkey = mc.group(n='{}_dKey'.format(noseUp), em=True) mc.parent(noseUpDkey, mouthSquashSKN) mc.setAttr('{}.translate'.format(noseUpDkey), 0, 0, 0) mc.parent(noseUpDkey, noseGrp) mc.parent(noseUpOrig, noseUpDkey) # --- goes into the hierarchy of duplicated Fks and counts the depth of the hierarchy. stops when arrived at end of hierarchy for i, each in enumerate(smartDupTargets): nexChild = '' stopLoop = False for j in range(0, 30): if j == 0: nexChild = each getChild = mc.listRelatives(nexChild, c=True, f=True) if getChild: for child in getChild: if mc.objectType(child) == 'nurbsCurve': mc.delete(child) else: if mc.objectType(child) == 'joint': splittedName1 = child.rsplit('|')[-1] checkEnd = splittedName1.rsplit('_', 1)[-1] newName = mc.rename(child, '%s_smart' % splittedName1) smartConnect(splittedName1, newName) if not checkEnd == 'end': nexChild = newName else: stopLoop = True if stopLoop == True: break # --- add dkNode on top of C_lipFlap_dKey CNoseSideDKeyAll = orig.orig(objlist=['C_lipFlap_ctrl_01_dKeyAll'], suffix=['_side'], origtype='transform', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] CNoseSideDKeyAllSmart = orig.orig( objlist=['C_lipFlap_ctrl_01_dKeyAll_smart'], suffix=['_side'], origtype='transform', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] smartConnect(CNoseSideDKeyAll, CNoseSideDKeyAllSmart) #save lists in tempNode tempSaveGrp = mc.group(n='tempSaveGrp', em=True) mc.hide(tempSaveGrp) mc.addAttr(tempSaveGrp, ln='dKeyAllNodesList', dt='string') mc.addAttr(tempSaveGrp, ln='dKeyTipNodesList', dt='string') mc.setAttr('%s.dKeyAllNodesList' % tempSaveGrp, dKeyAllNodesList, type='string') mc.setAttr('%s.dKeyTipNodesList' % tempSaveGrp, dKeyTipNodesList, type='string') # --- do teeth generate teethGen.generateTeeth()
def patch(): pelvName = 'pelvis' clavName = 'clavicle' armRootOff = 'arm_root_offset' legRootOffName = 'leg_root_offset' armIK = 'arm_IK' legIK = 'leg_IK' armFK = 'arm' legFK = 'leg' footFK = 'foot' wristFK = 'wrist' root = 'root' rootGimbal = 'root_gimbal' head = 'head' headGimbal = 'head_gimbal' ikFKSwitchTgt = 'arm_ik_tgt' neckIKTipAdjust = 'neck_ik_tip_adjust' headRotProxyOrig = 'headRotProxy_orig' headProxyRot = 'headRotProxy' ribCage2 = 'ribCage_bend_ctrl_02' palmCtrlName = 'hand_palm_ctrl' middleCtrlName = 'middle_01' sides = ['L', 'R'] ###Fix Axises and rotate Orders############################################################ #reorient translate R clavicle rClavRelatives = patchLib.getRelatives(sides[1], clavName, 1) mc.parent(rClavRelatives[3], w=True) mc.setAttr('%s.scale' % rClavRelatives[1], -1, -1, -1) mc.parent(rClavRelatives[3], rClavRelatives[2]) #reorient R arm root offset rArmRootOfftRelatives = patchLib.getRelatives(sides[1], armRootOff, '') mc.parent(rArmRootOfftRelatives[3], w=True) mc.setAttr('%s.scale' % rArmRootOfftRelatives[1], -1, -1, -1) mc.setAttr('%s.jointOrientX' % rArmRootOfftRelatives[1], 0) mc.parent(rArmRootOfftRelatives[3], rArmRootOfftRelatives[2]) #reorient R ik Hand rArmIKRelatives = patchLib.getRelatives(sides[1], armIK, '') for rel in rArmIKRelatives[3]: patchLib.locksSwitch(rel, T=True, R=True, S=True, V=False, lockdo='unlock', keydo=False) mc.parent(rArmIKRelatives[3], w=True) mc.setAttr('%s.jointOrientX' % rArmIKRelatives[0], 90) mc.setAttr('%s.jointOrientY' % rArmIKRelatives[0], -90) mc.parent(rArmIKRelatives[3], rArmIKRelatives[2]) for rel in rArmIKRelatives[3]: patchLib.locksSwitch(rel, T=True, R=True, S=True, V=False, lockdo='lock', keydo=False) ##reorient IKFK switch target mc.setAttr('%s_%s.rotate' % (sides[1], ikFKSwitchTgt), l=False) mc.setAttr('%s_%s.rotateY' % (sides[1], ikFKSwitchTgt), -180) mc.setAttr('%s_%s.rotate' % (sides[1], ikFKSwitchTgt), l=True) #reorient et hide Attr legs root offset llegRootOffRelatives = patchLib.getRelatives(sides[0], legRootOffName, '') mc.parent(llegRootOffRelatives[3], w=True) mc.setAttr('%s.rotateX' % llegRootOffRelatives[1], 0) mc.parent(llegRootOffRelatives[3], llegRootOffRelatives[2]) rlegRootOffRelatives = patchLib.getRelatives(sides[1], legRootOffName, '') RLegProxyScaleGrp = '%s_%s_scaleProxy' % (sides[1], legRootOffName) mc.group(n=RLegProxyScaleGrp, em=True) mc.parent(RLegProxyScaleGrp, rlegRootOffRelatives[0], r=True) mc.parent(rlegRootOffRelatives[3], RLegProxyScaleGrp) mc.parent(RLegProxyScaleGrp, w=True) mc.setAttr('%s.scale' % rlegRootOffRelatives[1], -1, -1, -1) mc.parent(RLegProxyScaleGrp, rlegRootOffRelatives[2]) mc.setAttr('L_leg_root_offset_ctrl.scaleX', k=False, l=True) mc.setAttr('L_leg_root_offset_ctrl.scaleY', k=False, l=True) mc.setAttr('L_leg_root_offset_ctrl.scaleZ', k=False, l=True) mc.setAttr('R_leg_root_offset_ctrl.scaleX', k=False, l=True) mc.setAttr('R_leg_root_offset_ctrl.scaleY', k=False, l=True) mc.setAttr('R_leg_root_offset_ctrl.scaleZ', k=False, l=True) #connects feets rotateOrder to feets_SKN rotateORders for side in sides: for i in range(1, 3): mc.connectAttr('%s_%s_%02d.rotateOrder' % (side, footFK, i), '%s_%s_%02d_SKN.rotateOrder' % (side, footFK, i), f=True) ################################################################################################# # --- add leg ground IK ctrls on top of actual leg Iks for side in sides: if side == 'L': ctrlcolor = 6 elif side == 'R': ctrlcolor = 13 mc.select(cl=True) newCtrl = mc.joint(n='%s_%s_ground_ctrl' % (side, legIK)) mc.setAttr('%s.drawStyle' % newCtrl, 2) shapes.create(newCtrl, shape='square', size=2, scale=[1, 1, 2], axis='y', twist=0, offset=[0, 0, 1], color=ctrlcolor, colorDegradeTo=None, replace=True, middle=False) newCtrlOrig = orig.orig(objlist=[newCtrl], suffix=['_orig'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] mc.parent(newCtrlOrig, '%s_%s_rvfoot_heel_ctrl' % (side, legFK)) mc.setAttr('%s.translate' % newCtrlOrig, 0, 0, 0) mc.parent(newCtrlOrig, 'traj') mc.parent('%s_%s_ctrl_orig' % (side, legIK), newCtrl) mc.sets(newCtrl, add='%s_%s_anim_set' % (side, legFK)) mc.sets(newCtrl, add='%s_%s_ZS_set' % (side, legFK)) mc.connectAttr('%s_leg_SW_ctrl.fkIk' % side, '%s.visibility' % newCtrl) # --- fix right fuckedUp bank Rbank01Source = mc.listConnections( '%s_%s_rvfoot_bank_01_ctrl.rotateAxisZ' % (sides[1], legFK), p=True, s=True)[0] Rbank02Source = mc.listConnections( '%s_%s_rvfoot_bank_02_ctrl.rotateAxisZ' % (sides[1], legFK), p=True, s=True)[0] mc.connectAttr(Rbank02Source, '%s_%s_rvfoot_bank_01_ctrl.rotateAxisZ' % (sides[1], legFK), f=True) mc.connectAttr(Rbank01Source, '%s_%s_rvfoot_bank_02_ctrl.rotateAxisZ' % (sides[1], legFK), f=True) mc.keyframe((Rbank01Source.split('.', 1)[0]), index=(1, 1), absolute=True, valueChange=-1) mc.keyframe((Rbank02Source.split('.', 1)[0]), index=(0, 0), absolute=True, valueChange=1) ################################################################################################# #reparent armTwist reader rig to avoid flips when FKarm currentSpace not in restPose twistTrgtList = ['twist', 'twist_aimdir'] for side in sides: parentTrgt = mc.listRelatives('%s_%s_01_orig' % (side, armFK), p=True) for twist in twistTrgtList: twistname = '%s_%s_01_%s' % (side, armFK, twist) patchLib.locksSwitch(twistname, T=True, R=True, S=True, V=True, lockdo='unlock', keydo=False) mc.parent(twistname, parentTrgt) patchLib.locksSwitch(twistname, T=True, R=False, S=True, V=True, lockdo='lock', keydo=False) ################################################################################################## # --- readjust Palm Controls JOSettings = [(-180, 0, 90), (0, 0, -90)] for side in sides: palmCtrl = '%s_%s' % (side, palmCtrlName) palmOrig = mc.listRelatives(palmCtrl, p=True)[0] # get constraints from palmCtrl, its targets and the blend settings, then remove constraints outCns = mc.listConnections('%s.parentMatrix[0]' % palmCtrl) cnsTargets = [] for cns in outCns: target = mc.listConnections('%s.constraintTranslateX' % cns)[0] blend0 = mc.getAttr('%s.target[0].targetWeight' % cns) blend1 = mc.getAttr('%s.target[1].targetWeight' % cns) cnsTargets.append((target, (blend0, blend1))) mc.delete(cns) # realigns the palm ctrl orig palmOrigParent = mc.listRelatives(palmOrig, p=True)[0] mc.parent(palmOrig, w=True) mc.setAttr('%s.jointOrient' % palmOrig, JOSettings[0][0], JOSettings[0][1], JOSettings[0][2]) alignPos = mc.xform('%s_%s' % (side, middleCtrlName), q=True, t=True, ws=True) mc.setAttr('%s.translateY' % palmOrig, alignPos[1]) mc.setAttr('%s.translateZ' % palmOrig, alignPos[2]) mc.parent(palmOrig, palmOrigParent) #reconstraint Targets to palmCtrl for each in cnsTargets: target = each[0] blends = each[1] newCns = mc.parentConstraint(palmOrig, palmCtrl, target, mo=True)[0] blend0 = mc.listConnections('%s.target[0].targetWeight' % newCns, p=True)[0] blend1 = mc.listConnections('%s.target[1].targetWeight' % newCns, p=True)[0] mc.setAttr(blend0, blends[0]) mc.setAttr(blend1, blends[1]) #neckTwist####################################### attrName = 'neckTwistFollow' neckFollowMdl = '%s_mdl' % attrName mc.group(n=headRotProxyOrig, em=True) mc.group(n=headProxyRot, em=True) mc.parent(headProxyRot, headRotProxyOrig) mc.parent(headRotProxyOrig, '%s_orig' % neckIKTipAdjust, r=True) getRO = mc.getAttr('%s.jointOrient' % neckIKTipAdjust)[0] mc.setAttr('%s.rotateAxis' % headRotProxyOrig, getRO[0], getRO[1], getRO[2]) mc.setAttr('%s.rotateOrder' % neckIKTipAdjust, 2) mc.setAttr('%s.rotateOrder' % headProxyRot, 2) mc.orientConstraint('head_gimbal_ctrl', headProxyRot, mo=True) # --- adds blendattribute for neckTwist on head mc.addAttr('%s_ctrl' % head, ln=attrName, at='double', min=0, max=1, dv=1) mc.setAttr('%s_ctrl.%s' % (head, attrName), edit=True, k=True) mc.createNode('multDoubleLinear', n=neckFollowMdl) mc.connectAttr('%s.rotateY' % headProxyRot, '%s.input1' % neckFollowMdl, f=True) mc.connectAttr('%s_ctrl.%s' % (head, attrName), '%s.input2' % neckFollowMdl, f=True) mc.connectAttr('%s.output' % neckFollowMdl, '%s.rotateY' % neckIKTipAdjust) #neckTwist####################################### #reparent last neck deform####################### lastNeckDeform = mc.ls('neck_ctrl_deform_*_orig')[-1] mc.parent(lastNeckDeform, neckIKTipAdjust) # --- add head_hook for later facial parenting headHook = 'head_hook' mc.group(n=headHook, em=True) mc.parent(headHook, '%s_ctrl' % headGimbal, r=True) # --- add breathCtrl breathingCtrl = 'breathing_ctrl' mc.select(cl=True) mc.joint(n=breathingCtrl) shapes.create(breathingCtrl, shape='arrowTwo', size=0.5, scale=[1, 1, 1], axis='z', twist=0, offset=[0, 0, 0], color=[1, 0.5, 0.3], colorDegradeTo=None, replace=True, middle=False) mc.setAttr('%s.drawStyle' % breathingCtrl, 2) breathingOrig = orig.orig(objlist=[breathingCtrl], suffix=['_orig'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] mc.parent(breathingOrig, ribCage2, r=True) mc.setAttr('%s.jointOrient' % breathingOrig, 0, 0, 0) mc.setAttr('%s.translate' % breathingOrig, 0, 0, 1) mc.sets(breathingCtrl, add='spine_ctrl_anim_set') mc.sets(breathingCtrl, add='spine_ctrl_ZS_set') ## set locks and limits mc.setAttr('%s.translateX' % breathingCtrl, l=True, k=False) mc.setAttr('%s.translateY' % breathingCtrl, l=True, k=False) mc.setAttr('%s.rotateX' % breathingCtrl, l=True, k=False) mc.setAttr('%s.rotateY' % breathingCtrl, l=True, k=False) mc.setAttr('%s.rotateZ' % breathingCtrl, l=True, k=False) mc.setAttr('%s.scaleX' % breathingCtrl, l=True, k=False) mc.setAttr('%s.scaleY' % breathingCtrl, l=True, k=False) mc.setAttr('%s.scaleZ' % breathingCtrl, l=True, k=False) mc.transformLimits(breathingCtrl, etz=(True, True), tz=(-1.5, 1.5)) # --- expose and tweak missing rotate Orders --- ctrlList = mc.listConnections('?_hand_fk_set.dagSetMembers') ctrlList.append(mc.listConnections('L_hand_anim_set.dagSetMembers')[0]) ctrlList.append(mc.listConnections('R_hand_anim_set.dagSetMembers')[0]) ctrlList.append('L_leg_01') ctrlList.append('R_leg_01') xyzRoList = [] yzxRoList = [] zxyRoList = ctrlList xzyRoList = [ 'head_ctrl', 'head_gimbal_ctrl', 'root_ctrl', 'root_gimbal_ctrl', 'pelvis_ctrl', 'spine_mid_ctrl', 'spine_tip_ctrl', 'spine_tip_adjust_ctrl', 'L_arm_IK_ctrl', 'R_arm_IK_ctrl', 'L_wrist', 'R_wrist', 'L_wrist_offset', 'R_wrist_offset', 'L_leg_IK_ctrl', 'R_leg_IK_ctrl', 'L_leg_IK_ground_ctrl', 'R_leg_IK_ground_ctrl', 'L_leg_root_offset_ctrl', 'R_leg_root_offset_ctrl' ] yxzRoList = ['L_leg_02', 'R_leg_02', 'L_arm_02', 'R_arm_02'] zyxRoList = [ 'L_foot_01', 'R_foot_01', 'L_foot_02', 'R_foot_02', 'L_arm_01', 'R_arm_01' ] roLib.updateRotateOrder(xyz=xyzRoList, yzx=yzxRoList, zxy=zxyRoList, xzy=xzyRoList, yxz=yxzRoList, zyx=zyxRoList)
def patch(): #vars######################################################################################### sides = ['L', 'R'] intFixes = ['front', 'back'] fullLegDuplicate = ['leg_01', 'leg_02', 'foot_01', 'foot_02'] ############################################################################################## for side in sides: if side == 'L': ctrlcolor = 6 elif side == 'R': ctrlcolor = 13 #duplicates legs joints to create new fullLeg chain###################################################### newChain = [] for i, joint in enumerate(fullLegDuplicate): target = '%s_%s_%s' % (side, intFixes[1], joint) if mc.objExists(target): newjoint = mc.duplicate(target, po=True)[0] patchLib.locksSwitch(newjoint, T=True, R=True, S=True, V=True, lockdo='unlock', keydo=True) mc.parent(newjoint, w=True) newName = '%s_%s_fullLeg_%02d' % (side, intFixes[1], (i + 1)) mc.rename(newjoint, newName) newChain.append(newName) if newChain: mc.parent(newChain[3], newChain[2]) mc.parent(newChain[2], newChain[1]) mc.parent(newChain[1], newChain[0]) ##parents new fullLeg at the same place as base legs######################################################## newParent = mc.listRelatives('%s_%s_leg_01_orig' % (side, intFixes[1]), p=True)[0] mc.parent(newChain[0], newParent) ############################################################################################################ #creates new upvector and ik for fullLeg#################################################################### duplicatedUpVector = mc.duplicate('%s_%s_leg_PV_ctrl' % (side, intFixes[1]))[0] fullLegUpV = mc.rename(duplicatedUpVector, '%s_%s_fullLeg_PV_ctrl' % (side, intFixes[1])) shapes.create(fullLegUpV, shape='pyramid', size=1, scale=[1, 1, 1], axis='y', twist=0, offset=[0, 0, 0], color=ctrlcolor, colorDegradeTo=None, replace=True, middle=False) fullLegUpVOrig = orig.orig(objlist=[fullLegUpV], suffix=['_orig'], origtype='transform', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] mc.parent(fullLegUpVOrig, 'traj') ###scales newUpvector shape up ########################################################## scalePoints = mc.ls('%s.cv[*]' % fullLegUpV, fl=True) mc.scale(1.25, 1.25, 1.25, scalePoints, r=True, ocp=True) ##creates ik for fullLeg################################################################################### fullLegIkName = '%s_%s_fullLeg_ikh' % (side, intFixes[1]) fullLegIk = mc.ikHandle(sj=newChain[0], ee=newChain[3], n=fullLegIkName, sol='ikRPsolver') mc.poleVectorConstraint(fullLegUpV, fullLegIk[0]) ##reparent log upV in FullLeg upV and replace constraint upVCnsName = '%s_%s_leg_PV_ctrl_orig_parentConstraint1' % (side, intFixes[1]) upVCnsTarget = mc.parentConstraint(upVCnsName, q=True, tl=True)[0] mc.delete(upVCnsName) legUpVOrig = '%s_%s_leg_PV_ctrl_orig' % (side, intFixes[1]) mc.parent(legUpVOrig, fullLegUpV) mc.parentConstraint(upVCnsTarget, fullLegUpVOrig, mo=True) ############################################################################################################ #updating original ball 01 and 02 rigs###################################################################### ball01 = '%s_%s_leg_rvfoot_ball_01_ctrl' % (side, intFixes[1]) ball02Orig = '%s_%s_leg_rvfoot_ball_02_ctrl_orig' % (side, intFixes[1]) ball02 = '%s_%s_leg_rvfoot_ball_02_ctrl' % (side, intFixes[1]) #updating original ball_01 rig############################################################################## ##ads ik offset on ball01################################################################################### patchLib.locksSwitch(ball01, T=True, R=True, S=True, V=True, lockdo='unlock', keydo=True) ball01ik = mc.duplicate(ball01, po=True) ball01ikend = mc.duplicate(ball02Orig, po=True) ball01ikName = '%s_%s_leg_ik_rvfoot_ball_01_joint' % (side, intFixes[1]) ball01ikEndName = '%s_%s_leg_ik_rvfoot_ball_01_end' % (side, intFixes[1]) ball01ik = mc.rename(ball01ik, ball01ikName) ball01ikend = mc.rename(ball01ikend, ball01ikEndName) mc.parent(ball01ikend, ball01ik) mc.parent(ball01, ball01ik) ###creates ctrl for ball01 ik offset########################################################################### ballIKCtrlname = '%s_%s_leg_rvfoot_ik_ball_01_ctrl' % (side, intFixes[1]) mc.select(cl=True) ballIKCtrl = mc.joint(n=ballIKCtrlname) mc.setAttr('%s.drawStyle' % ballIKCtrl, 2) ballIKCtrlOrig = orig.orig(objlist=[ballIKCtrl], suffix=['_orig'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] shapes.create(ballIKCtrl, shape='cube', size=.25, scale=[1, .5, 1], axis='y', twist=0, offset=[0, 0, 0], color=ctrlcolor, colorDegradeTo=None, replace=True, middle=False) mc.parent(ballIKCtrlOrig, ball01ikend) mc.setAttr('%s.translate' % ballIKCtrlOrig, 0, 0, 0) mc.parent(ballIKCtrlOrig, (mc.listRelatives(ball01ik, p=True))) ###creates ikSCsolver for ball 01 ik ##################################################################### ball01ikhName = '%s_%s_leg_rvfoot_ik_ball_01_ikh' % (side, intFixes[1]) ball01ikh = mc.ikHandle(sj=ball01ik, ee=ball01ikend, n=ball01ikhName, sol='ikSCsolver') mc.parent(ball01ikh[0], ballIKCtrl) patchLib.locksSwitch(ball01, T=True, R=False, S=True, V=True, lockdo='lock', keydo=False) #updating original ball_02 rig############################################################################## ##remove original aim constraint############################################################################ ball02AimCns = mc.listConnections('%s.rotateX' % ball02Orig)[0] mc.delete(ball02AimCns) ##ads ik offset on ball02################################################################################### ballDublicate = [ ball02Orig, '%s_%s_leg_rvfoot_ball_02_ctrl' % (side, intFixes[1]), '%s_%s_leg_rvfoot_ankle_ctrl' % (side, intFixes[1]) ] newBall = [] for j, ballJnt in enumerate(ballDublicate): newJnt = mc.duplicate(ballJnt, po=True) newJntName = ballDublicate[j].replace('rvfoot', 'rvfoot_ik') newJntName = newJntName.replace('ctrl', 'jnt') mc.rename(newJnt, newJntName) newBall.append(newJntName) mc.parent(newBall[2], newBall[1]) mc.parent(newBall[1], newBall[0]) mc.parent(newBall[0], ball02Orig) mc.parent(ball02, newBall[1]) ###creates ikSCsolver for ball ik offset##################################################################### ball02ikhName = '%s_%s_leg_rvfoot_ik_ball_02_ikh' % (side, intFixes[1]) ball02ikh = mc.ikHandle(sj=newBall[1], ee=newBall[2], n=ball02ikhName, sol='ikSCsolver') ###creates ctrl for ball ik offset########################################################################### ballIKCtrlname = '%s_%s_leg_rvfoot_ik_ball_02_ctrl' % (side, intFixes[1]) mc.select(cl=True) ballIKCtrl = mc.joint(n=ballIKCtrlname) mc.setAttr('%s.drawStyle' % ballIKCtrl, 2) ballIKCtrlOrig = orig.orig(objlist=[ballIKCtrl], suffix=['_orig'], origtype='joint', fromsel=False, viz=False, get_ssc=False, rtyp='auto')[0] if side == 'L': ctrlcolor = 6 elif side == 'R': ctrlcolor = 13 shapes.create(ballIKCtrl, shape='locator', size=1, scale=[1, 1, 1], axis='y', twist=0, offset=[0, 0, 0], color=ctrlcolor, colorDegradeTo=None, replace=True, middle=False) mc.parent(ballIKCtrlOrig, newBall[2], r=True) mc.parent(ballIKCtrlOrig, newBall[0]) ####adjusts ctrl position#################################################################################### mc.setAttr('%s.translateY' % ballIKCtrlOrig, (mc.getAttr('%s.translateY' % ballIKCtrlOrig)) * 2) mc.xform(ballIKCtrlOrig, ws=True, r=True, a=True, ro=(0, 0, 0)) if side == 'L': mc.setAttr('%s.jointOrientX' % ballIKCtrl, 180 - (mc.getAttr('%s.rotateX' % ballIKCtrlOrig))) if side == 'R': mc.setAttr('%s.jointOrientX' % ballIKCtrl, -(mc.getAttr('%s.rotateX' % ballIKCtrlOrig))) ##parents ball 02 ikh into ctrl############################################################################## mc.parent(ball02ikh[0], ballIKCtrl) mc.setAttr('%s.translate' % ball02ikh[0], 0, 0, 0) ##constraints updated ball02 to fullLeg###################################################################### mc.parentConstraint(newChain[3], newBall[0], st=["x", "y", "z"], mo=True) ##connects translate of fullLegs first joint to base legs first joint####################################### mc.connectAttr('%s.translate' % newChain[0], '%s_%s_leg_01_orig.translate' % (side, intFixes[1]), f=True) ##parent new ikh############################################################################################ fullLegParent = '%s_%s_leg_rvfoot_ball_01_ctrl' % (side, intFixes[1]) mc.parent(fullLegIk[0], fullLegParent) ############################################################################################################## #temp remove front aim cns on ball_02 mc.delete('%s_%s_leg_rvfoot_ball_02_ctrl_orig_aimConstraint1' % (side, intFixes[0])) ############################################################################################################## # rough cleanup hideList = [ 'leg_rvfoot_ik_ball_02_ikh', 'fullLeg_ikh', 'leg_rvfoot_ik_ball_01_ikh', 'fullLeg_01' ] for toHide in hideList: mc.hide('%s_%s_%s' % (side, intFixes[1], toHide))