def returnPolyUniteNodeFromResultGeo(geo): shapes = mc.listRelatives(geo,shapes=True) if shapes: if mc.objExists('%s%s' % (shapes[0],'.inMesh')): bufferObject = attributes.returnDriverObject('%s%s' % (shapes[0],'.inMesh')) if mc.objExists('%s%s' % (bufferObject,'.inputGeometry')): return attributes.returnDriverObject('%s%s' % (bufferObject,'.inputGeometry')) else: return False else: return False else: return False
def returnPolyUniteSourceShapes(polyUniteNode): i = 0 rawDrivers = [] if mc.objExists(polyUniteNode): while mc.connectionInfo (('%s%s%i%s' % (polyUniteNode,'.inputPoly[',i,']')),isDestination=True) == True: rawDrivers.append(attributes.returnDriverObject('%s%s%i%s' % (polyUniteNode,'.inputPoly[',i,']'))) i+=1 return rawDrivers else: return False
def groupToConditionNodeSet(group, chooseAttr='switcher', controlObject=None, connectTo='visibility'): """ Hack job for the gig to make a visibility switcher for all the first level of children of a group """ children = search.returnChildrenObjects(group) #Check for children if not children: #If none, break out guiFactory("'%s' has no children! Aborted." % group) return False if controlObject is None: controlObject = group #Make our attr a = AttrFactory.AttrFactory(controlObject, chooseAttr, 'enum') children.insert(0, 'none') print children if len(children) == 2: a.setEnum('off:on') else: a.setEnum(':'.join(children)) for i, c in enumerate(children[1:]): print i print c #see if the node exists condNodeTest = attributes.returnDriverObject('%s.%s' % (c, connectTo)) if condNodeTest: buffer = condNodeTest else: if mc.objExists('%s_condNode' % c): mc.delete('%s_condNode' % c) buffer = nodes.createNamedNode('%s_picker' % c, 'condition') #Make our node print buffer attributes.doSetAttr(buffer, 'secondTerm', i + 1) attributes.doSetAttr(buffer, 'colorIfTrueR', 1) attributes.doSetAttr(buffer, 'colorIfFalseR', 0) a.doConnectOut('%s.firstTerm' % buffer) attributes.doConnectAttr('%s.outColorR' % buffer, '%s.%s' % (c, connectTo))
def singleObjectVisToggle(obj,chooseAttr = 'switcher', controlObject = None, connectTo = 'visibility'): #Make our attr a = AttrFactory.AttrFactory(controlObject,chooseAttr,'enum') a.setEnum('off:on') condNodeTest = attributes.returnDriverObject('%s.%s'%(obj,connectTo)) if condNodeTest: buffer = condNodeTest else: if mc.objExists('%s_condNode'%obj): mc.delete('%s_condNode'%obj) buffer = nodes.createNamedNode('%s_picker'%obj,'condition') #Make our node print buffer attributes.doSetAttr(buffer,'secondTerm',1) attributes.doSetAttr(buffer,'colorIfTrueR',1) attributes.doSetAttr(buffer,'colorIfFalseR',0) a.doConnectOut('%s.firstTerm'%buffer) attributes.doConnectAttr('%s.outColorR'%buffer,'%s.%s'%(obj,connectTo))
def groupToConditionNodeSet(group,chooseAttr = 'switcher', controlObject = None, connectTo = 'visibility'): """ Hack job for the gig to make a visibility switcher for all the first level of children of a group """ children = search.returnChildrenObjects(group) #Check for children if not children: #If none, break out guiFactory("'%s' has no children! Aborted."%group) return False if controlObject is None: controlObject = group #Make our attr a = AttrFactory.AttrFactory(controlObject,chooseAttr,'enum') children.insert(0,'none') print children if len(children) == 2: a.setEnum('off:on') else: a.setEnum(':'.join(children)) for i,c in enumerate(children[1:]): print i print c #see if the node exists condNodeTest = attributes.returnDriverObject('%s.%s'%(c,connectTo)) if condNodeTest: buffer = condNodeTest else: if mc.objExists('%s_condNode'%c): mc.delete('%s_condNode'%c) buffer = nodes.createNamedNode('%s_picker'%c,'condition') #Make our node print buffer attributes.doSetAttr(buffer,'secondTerm',i+1) attributes.doSetAttr(buffer,'colorIfTrueR',1) attributes.doSetAttr(buffer,'colorIfFalseR',0) a.doConnectOut('%s.firstTerm'%buffer) attributes.doConnectAttr('%s.outColorR'%buffer,'%s.%s'%(c,connectTo))
def singleObjectVisToggle(obj, chooseAttr='switcher', controlObject=None, connectTo='visibility'): #Make our attr a = AttrFactory.AttrFactory(controlObject, chooseAttr, 'enum') a.setEnum('off:on') condNodeTest = attributes.returnDriverObject('%s.%s' % (obj, connectTo)) if condNodeTest: buffer = condNodeTest else: if mc.objExists('%s_condNode' % obj): mc.delete('%s_condNode' % obj) buffer = nodes.createNamedNode('%s_picker' % obj, 'condition') #Make our node print buffer attributes.doSetAttr(buffer, 'secondTerm', 1) attributes.doSetAttr(buffer, 'colorIfTrueR', 1) attributes.doSetAttr(buffer, 'colorIfFalseR', 0) a.doConnectOut('%s.firstTerm' % buffer) attributes.doConnectAttr('%s.outColorR' % buffer, '%s.%s' % (obj, connectTo))
def surfRigger(objectNull,anchor,worldScale,mirror,mode,jointsPerChain,deformChains,ctrlChains): """ Get variables""" nullBase = names.stripSuffixObj (objectNull) templateNull = (nullBase + '_templateNull') moverNull = (nullBase + '_mover') templateNullMessageData = [] templateNullMessageData = attributes.returnMessageAttrs (templateNull) templateObjects = [] coreNamesList = [] spineJointNumber = int(mc.getAttr (objectNull+'.rollJoints')) #spineChainList = search.returnChildrenJoints (spineChain) spineChainList = [] spineChainList.append (anchor) jointChains = [] for set in templateNullMessageData: templateObjects.append (set[1]) coreNamesList.append (set[0]) #>>>>>>>>>>>>>>>>>>>>>Store skin joint data """ check for master skin info group """ if mc.objExists ('master_skinJntList_grp'): masterSkinJointList = ('master_skinJntList_grp') else: masterSkinJointList = mc.group (n= ('master_skinJntList_grp'), w=True, empty=True) mc.parent(masterSkinJointList,'rigStuff_grp') """ check for segment skin info group """ if mc.objExists (nullBase+'_skinJntList_grp'): skinJointListGrp = (nullBase+'_skinJntList_grp') else: skinJointListGrp = mc.group (n= (nullBase+'_skinJntList_grp'), w=True, empty=True) attributes.storeObjNameToMessage (skinJointListGrp,masterSkinJointList) mc.parent (skinJointListGrp,masterSkinJointList) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ Rebuild curve - with actual curve in it!""" mc.rebuildCurve ((templateObjects[3]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=jointsPerChain, d=1, tol=5) mc.rebuildCurve ((templateObjects[7]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=jointsPerChain, d=1, tol=5) mc.rebuildCurve ((templateObjects[11]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=jointsPerChain, d=1, tol=5) """ Reverse the curve """ mc.reverseCurve ((templateObjects[3]),ch=False,rpo=True) mc.reverseCurve ((templateObjects[7]),ch=False,rpo=True) mc.reverseCurve ((templateObjects[11]),ch=False,rpo=True) """ loft our surface to figure out joint positions, then delete it""" controlSurface = mc.loft ([templateObjects[3],templateObjects[7],templateObjects[11]],name=(nullBase+'_surf'),ss=(ctrlChains-mode),ch=1,u=1,c=0,ar=1,d=3,rn=0,po=0,rsn=True) mc.select (cl=True) jointChains = joints.createJointChainsFromLoftSurface (nullBase,controlSurface[0],2,False) frontChain = jointChains[0] backChain = jointChains[-1] """ Chain - orienting, sizing """ for chain in jointChains: joints.orientJointChain (chain, 'xyz', 'zup') joints.setGoodJointRadius(chain,.5) #IF we have mode 0, gotta make a main ctrl if mode == 0: midChain = [] if (len(jointChains)) > 3: midChain = jointChains[int(len(jointChains)/2)] else: midChain = jointChains[1] jointChains.remove(midChain) if ctrlChains > 2: masterCtrlBuffer = mc.duplicate (midChain[0],parentOnly=True) else: masterCtrlBuffer = midChain[0] mc.delete (midChain[1]) masterCtrl = mc.rename (masterCtrlBuffer,(nullBase+'_master_anim')) position.movePointSnap(masterCtrl,moverNull) """ temp parenting the master control for mirroring purposes """ spineHookJoint = distance.returnClosestObject (masterCtrl, spineChainList) mc.parent (masterCtrl,spineHookJoint) mc.delete (controlSurface[0]) #>>>>>>>>>>>>Parent time """ Get closest joint """ if mode == 0: for chain in jointChains: mc.parent (chain[0],masterCtrl) else: for chain in jointChains: tailHookJoint = distance.returnClosestObject (chain[0], spineChainList) mc.parent (chain[0],tailHookJoint) #>>>>>>>>>>>>>>>>>>>>>>>>>>>> Ctrl Joints to Ctrls cnt = 0 for chain in jointChains: ctrlSize = (distance.returnAverageDistanceBetweenObjects (chain)/2) for jnt in chain[0:-1]: rigging.makeObjCtrl (jnt,ctrlSize) """ adds our Anim tag """ chainBuffer = [] chainBuffer = names.addSuffixList ('anim', chain) jointChains[cnt]= chainBuffer cnt +=1 #>>>>>>>>>>>>>>>>>>>Mirroring while getting chain info """ If mirroring ....""" if mirror == True: # if we have a main control leftSkinChains = [] rightSkinChains = [] masterCtrls = [] if mode == 0: leftChain = [] rightChain = [] finHeirarchy = [] finHeirarchy.append (masterCtrl) children = search.returnChildrenJoints (masterCtrl) finHeirarchy += children leftChain = names.addPrefixList ('left',finHeirarchy) masterCtrl = leftChain [0] rightChainBuffer = mc.mirrorJoint (masterCtrl,mirrorYZ=True,mirrorBehavior=True, searchReplace =['left','right']) rightChainJointBuffer = mc.ls (rightChainBuffer,type='joint') rightChain = rightChainJointBuffer leftSkinChains.append(leftChain) rightSkinChains.append(rightChain) masterCtrls.append(leftChain[0]) masterCtrls.append(rightChain[0]) else: for chain in jointChains: leftChain =[] leftChain = names.addPrefixList ('left',chain) rightChainBuffer = (mc.mirrorJoint (leftChain[0],mirrorYZ=True,mirrorBehavior=True, searchReplace =['left','right'])) rightChainJointBuffer = mc.ls (rightChainBuffer,type='joint') rightChain = rightChainJointBuffer rightSkinChains.append (rightChainJointBuffer) leftSkinChains.append (leftChain) """ complile our chains to lists of skin joints """ leftSkinJointList=[] rightSkinJointList=[] for chain in leftSkinChains: for jnt in chain: leftSkinJointList.append (jnt) for chain in rightSkinChains: for jnt in chain: rightSkinJointList.append (jnt) """if we're not mirroring, let's return our skin joints for the deformation surface""" else: skinJointList = [] skinChains = [] for chain in jointChains: skinChains.append (chain) for jnt in chain: skinJointList.append (jnt) #>>>>>>>>>>>>>>>>>>>>>>>>>>Time to make the deformation surface stuff """ Rebuild curve - with actual curve in it!""" #mc.rebuildCurve ((templateObjects[3]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=(3), d=1, tol=5) #mc.rebuildCurve ((templateObjects[7]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=(3), d=1, tol=5) """ loft our surface to figure out joint positions, then delete it""" deformSurface = mc.loft ([templateObjects[3],templateObjects[7],templateObjects[11]],name=(nullBase+'_surf'),ss=(deformChains-1),ch=0,u=1,c=0,ar=1,d=3,rn=0,po=0,rsn=True) if mirror == True: deformSurfaceNameBuffer = deformSurface[0] """we have a surface to mirror...""" surfaceMirrorBuffer = mc.duplicate (deformSurface[0]) mc.setAttr ((surfaceMirrorBuffer[0]+'.sx'),-1) leftBuffer = mc.rename (deformSurface[0],('left_'+deformSurfaceNameBuffer)) rightBuffer = mc.rename (surfaceMirrorBuffer[0],('right_'+deformSurfaceNameBuffer)) deformSurface[0]=leftBuffer deformSurface.append(rightBuffer) leftDeformJointChains = joints.createJointChainsFromLoftSurface (('left_'+nullBase),deformSurface[0],2,False) rightDeformJointChains = joints.createJointChainsFromLoftSurface (('right_'+nullBase),deformSurface[1],2,False) """ Connecting to surface """ for chain in leftDeformJointChains: attachSurfaceReturn = joints.attachJointChainToSurface (chain,deformSurface[0],'xyz','zup') tailHookJoint = distance.returnClosestObject (chain[0], spineChainList) """ break the connection so we can parent it""" """first return the original thing to follow""" parentBuffer = attributes.returnDriverObject ((chain[0]+'.translate')) attributes.doBreakConnection (chain[0]+'.translate') #mc.parent (chain[0],tailHookJoint) """ reconstrain it to the driver""" constraintBuffer = mc.pointConstraint (parentBuffer,chain[0], maintainOffset = True) mc.rename (constraintBuffer[0],(chain[0]+'_pointConst')) """ store the skin joint data """ for jnt in chain: attributes.storeObjNameToMessage (jnt,skinJointListGrp) for chain in rightDeformJointChains: attachSurfaceMirrorReturn = joints.attachJointChainToSurface (chain,deformSurface[1],'xyz','zup') tailHookJoint = distance.returnClosestObject (chain[0], spineChainList) """ break the connection s we can parent it""" """first return the original thing to follow""" parentBuffer = attributes.returnDriverObject ((chain[0]+'.translate')) attributes.doBreakConnection (chain[0]+'.translate') #mc.parent (chain[0],tailHookJoint) """ reconstrain it to the driver""" constraintBuffer = mc.pointConstraint (parentBuffer,chain[0], maintainOffset = True) mc.rename (constraintBuffer[0],(chain[0]+'_pointConst')) """ store the skin joint data """ for jnt in chain: attributes.storeObjNameToMessage (jnt,skinJointListGrp) """ parent the scale stuff to rig stuff grp""" mc.select (cl=True) for item in attachSurfaceReturn[0]: mc.parent(item,'rigStuff_grp') for item in attachSurfaceMirrorReturn[0]: mc.parent(item,'rigStuff_grp') """ hook up world scale """ mc.connectAttr (worldScale,attachSurfaceReturn[1]) mc.connectAttr (worldScale,attachSurfaceMirrorReturn[1]) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Skin in the control joints """ Time to set skin our surface to our control joints """ mc.skinCluster (leftSkinJointList,deformSurface[0],tsb=True, n=(deformSurface[0]+'_skinCluster'),maximumInfluences = 8, normalizeWeights = 1, dropoffRate=1,smoothWeights=.5,obeyMaxInfluences=True, weight = 1) mc.skinCluster (rightSkinJointList,deformSurface[1],tsb=True, n=(deformSurface[1]+'_skinCluster'),maximumInfluences = 8, normalizeWeights = 1, dropoffRate=1,smoothWeights=.5,obeyMaxInfluences=True, weight = 1) #>>>>>If we,re not mirrored, let's make our deform setup else: deformJointChains = [] deformJointChains = joints.createJointChainsFromLoftSurface (nullBase,deformSurface[0],2,False) """ Connecting to surface """ for chain in deformJointChains: attachSurfaceReturn = joints.attachJointChainToSurface (chain,deformSurface[0],'xyz','zup') tailHookJoint = distance.returnClosestObject (chain[0], spineChainList) """ break the connection so we can parent it""" """first return the original thing to follow""" parentBuffer = attributes.returnDriverObject ((chain[0]+'.translate')) attributes.doBreakConnection (chain[0]+'.translate') #mc.parent (chain[0],tailHookJoint) """ reconstrain it to the driver""" constraintBuffer = mc.pointConstraint (parentBuffer,chain[0], maintainOffset = True) mc.rename (constraintBuffer[0],(chain[0]+'_pointConst')) """ store the skin joint data """ for jnt in chain: attributes.storeObjNameToMessage (jnt,skinJointListGrp) """ hook up world scale """ partScaleBuffer = attachSurfaceReturn[1] mc.connectAttr (worldScale, partScaleBuffer) """ parent the scale stuff to rig stuff grp""" mc.select (cl=True) for item in attachSurfaceReturn[0]: mc.parent(item,'rigStuff_grp') """ Time to set skin our surface to our control joints """ mc.skinCluster (skinJointList,deformSurface[0],tsb=True, n=(deformSurface[0]+'_skinCluster'),maximumInfluences = 8, normalizeWeights = 1, dropoffRate=1,smoothWeights=.5,obeyMaxInfluences=True, weight = 1) """ Setting up the joint starts""" if mode == 0: if mirror == True: for ctrl in masterCtrls: rigging.makeObjCtrl (ctrl,(ctrlSize*4)) masterCtrlGrp = rigging.groupMeObject (ctrl,True) """ Get closest joint and connect the Cntrl """ spineHookJoint = distance.returnClosestObject (masterCtrlGrp, spineChainList) mc.parent(masterCtrlGrp,spineHookJoint) else: rigging.makeObjCtrl (masterCtrl,(ctrlSize*4)) masterCtrlGrp = rigging.groupMeObject (masterCtrl,True) """ Get closest joint and connect the Cntrl """ spineHookJoint = distance.returnClosestObject (masterCtrlGrp, spineChainList) mc.parent(masterCtrlGrp,spineHookJoint) #else we need to connect the individual chains to the spine else: if mirror == True: for chain in leftSkinChains: chainCtrlGrp = rigging.groupMeObject (chain[0],True) spineHookJoint = distance.returnClosestObject (chainCtrlGrp, spineChainList) mc.parent(chainCtrlGrp,spineHookJoint) for chain in rightSkinChains: chainCtrlGrp = rigging.groupMeObject (chain[0],True) spineHookJoint = distance.returnClosestObject (chainCtrlGrp, spineChainList) mc.parent(chainCtrlGrp,spineHookJoint) else: for chain in skinChains: chainCtrlGrp = rigging.groupMeObject (chain[0],True) spineHookJoint = distance.returnClosestObject (chainCtrlGrp, spineChainList) mc.parent(chainCtrlGrp,spineHookJoint)
def makeChainsDynamic(startJoints,name): """ Makes input joint chains dynamic and names things properly """ curves = [] startNames=[] for start in startJoints: curveBuffer= (joints.createCurveFromJoints(start)) jointCount = search.returnJointHeirarchyCount(start) mc.rebuildCurve ((curveBuffer), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=(jointCount*1.5), d=1, tol=5) curves.append(curveBuffer) startNames.append(start) """ see if we have enough points """ #create test for crv in curves: """ rebuild curve """ mc.rebuildCurve ((crv), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=(20), d=1, tol=5) """ create hairsystem """ mc.select (curves) mel.eval('makeCurvesDynamicHairs 0 0 1') #>>>>>>>>>>>>>>>>>>>>>>Get data and name stuff right """ return useful info on the curves since the maya command returns jack squat""" crvsInfo =[] follicles = [] cnt=0 for crv in curves: crvInfo = [] follicleOldNameBuffer = mc.listRelatives (crv,parent=True) follicleBuffer=mc.rename(follicleOldNameBuffer[0],(startNames[cnt]+'_follicle')) shapeBuffer = mc.listRelatives (follicleBuffer,shapes=True) inputCurveOldNameBuffer = attributes.returnDriverObject(shapeBuffer[0]+'.startPosition') inputCurveBuffer = mc.rename(inputCurveOldNameBuffer,(startNames[cnt]+'_input_crv')) outputCurveShapeBuffer = attributes.returnDrivenObject(shapeBuffer[0]+'.outCurve') outputCurveOldNameBuffer = mc.listRelatives (outputCurveShapeBuffer,parent=True) outputCurveBuffer = mc.rename(outputCurveOldNameBuffer,(startNames[cnt]+'_output_crv')) hairSystemOldShapeNameBuffer = attributes.returnDriverObject(shapeBuffer[0]+'.currentPosition') hairSystemOldNameBuffer = mc.listRelatives (hairSystemOldShapeNameBuffer,parent=True) hairSystemBuffer = mc.rename(hairSystemOldNameBuffer,(name+'_hairSystem')) crvInfo.append(follicleBuffer) follicles.append(follicleBuffer) crvInfo.append(shapeBuffer[0]) crvInfo.append(inputCurveBuffer) crvInfo.append(outputCurveBuffer) crvInfo.append(hairSystemBuffer) cnt+=1 crvsInfo.append(crvInfo) """ Fix a few group names """ oldFolicleGroupBuffer = (mc.listRelatives (crvInfo[0],parent=True)) folicleGroup = mc.rename(oldFolicleGroupBuffer[0],(name+'follicles_grp')) oldOutputGroupBuffer = (mc.listRelatives (crvInfo[3],parent=True)) outputCrvsGroup = mc.rename(oldOutputGroupBuffer[0],(name+'OutputCrvs_grp')) print crvsInfo #>>>>>>>>>>>>>>>>>>>>>>>>>>>>> set follicle settings for follicle in follicles: """lock to base""" mc.setAttr ((follicle+'Shape.pointLock'),1) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>> set hair system settings hairSystem = crvInfo[4] mc.setAttr ((hairSystem+'Shape.drag'),.675) mc.setAttr ((hairSystem+'Shape.motionDrag'),.126) mc.setAttr ((hairSystem+'Shape.startCurveAttract'),.046) mc.setAttr ((hairSystem+'Shape.iterations'),50) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>> set up IK cnt=0 handlesList = [] for start in startJoints: currentCurveInfo = crvsInfo[cnt] heirarchy = search.returnJointHeirarchy (start) handle = mc.ikHandle(startJoint = heirarchy[0], curve = currentCurveInfo[3], endEffector = heirarchy[-1] ,sol='ikSplineSolver',ccv=False,pcv=False) handleName = mc.rename (handle[0],(start+'_ikHandle')) effectorName = mc.rename (handle[1],(start+'_effector')) handlesList.append(handleName) cnt+=1 #>>>>>>>>>>>>>>>>>>>>>>>>>>>> prep data for return returnList = [] returnList.append(follicles) returnList.append(handlesList) returnList.append(crvInfo[-1]) return returnList