def createCurveLengthNode(curve): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Creates a curve lenght measuring node ARGUMENTS: polyFace(string) - face of a poly RETURNS: length(float) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ objType = search.returnObjectType(curve) shapes = [] if objType == 'shape': shapes.append(curve) else: shapes = mc.listRelatives(curve,shapes=True) #first see if there's a length node isConnected = attributes.returnDrivenAttribute(shapes[0]+'.worldSpace[0]') if isConnected !=False: return (attributes.returnDrivenObject(shapes[0]+'.worldSpace')) else: infoNode = nodes.createNamedNode(curve,'curveInfo') attributes.doConnectAttr((shapes[0]+'.worldSpace'),(infoNode+'.inputCurve')) return infoNode
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 makeJointControlSurfaceFish(startJoint,controlJointList,outChannel,name): """ Makes a ricgmon surface for ricgmon rigging """ heirarchyJoints = [] heirarchyJoints.append (startJoint) childrenBuffer = [] controlJointGroups = [] """ Makes some transform groups for our groups""" """ Get joint list """ for jnt in (mc.listRelatives (startJoint, ad = True, type = 'joint')): childrenBuffer.append (jnt) childrenBuffer.reverse () heirarchyJoints += childrenBuffer """ return a good length for out loft curves """ length = (distance.returnDistanceBetweenObjects (heirarchyJoints[0], heirarchyJoints[-1])/2) loftCurveList = [] crvPosBuffer = [] crvPosBuffer.append ([0,0,0]) if outChannel == 'x': crvPosBuffer.append ([length,0,0]) elif outChannel == 'y': crvPosBuffer.append ([0,length,0]) elif outChannel == 'z': crvPosBuffer.append ([0,0,length]) crvPosBuffer.reverse () """ for each joint, make a loft curve and snap it to the joint it goes with """ for jnt in heirarchyJoints: crvBuffer = mc.curve (d=1, p = crvPosBuffer , os=True, n=(jnt+'_tmpCrv')) mc.xform (crvBuffer, cp = True) posBuffer = distance.returnWorldSpacePosition (jnt) cnstBuffer = mc.parentConstraint ([jnt], [crvBuffer], maintainOffset = False) mc.delete (cnstBuffer) loftCurveList.append (crvBuffer) controlSurface = mc.loft (loftCurveList, reverseSurfaceNormals = True, ch = False, uniform = True, degree = 3, n = (name+'_surf') ) """ deletes our loft curve list""" for crv in loftCurveList: mc.delete (crv) cvList = (mc.ls ([controlSurface[0]+'.cv[*]'],flatten=True)) """ Time to set skin our surface to our control joints """ surfaceSkinCluster = mc.skinCluster (controlJointList,controlSurface[0],tsb=True, n=(controlSurface[0]+'_skinCluster'),maximumInfluences = 3, normalizeWeights = 1, dropoffRate=2,smoothWeights=.5,obeyMaxInfluences=True, weight = 1) #surfaceSkinCluster = mc.skinCluster (controlJointList,controlSurface,tsb=True, n=(controlSurface[0]+'_skinCluster'),maximumInfluences = 5, normalizeWeights = 2, dropoffRate=4,smoothWeights=.5,forceNormalizeWeights=True) """ Make our groups to follow the surface and drive out """ posGroups = [] upGroups = [] cnt = 0 for jnt in heirarchyJoints: posGroups.append (mc.group (n= ('%s%s' % (jnt,'_Pos_grp')), w=True, empty=True)) upGroups.append (mc.group (n= ('%s%s' % (jnt,'_Up_grp')), w=True, empty=True)) mc.parent (upGroups[cnt],posGroups[cnt]) cnt +=1 """ Make our v values for our position info groups""" vValues = [] vValues.append (.5) cnt = 0 for item in heirarchyJoints: vValues.append (cnt + 1) cnt += 1 """ Make our position info nodes""" posInfoNodes = [] cnt = 0 for grp in posGroups: node = mc.createNode ('pointOnSurfaceInfo',name= (grp+'_posInfoNode')) print node posInfoNodes.append (node) """ Connect the info node to the surface """ mc.connectAttr ((controlSurface[0]+'Shape.worldSpace'),(posInfoNodes[cnt]+'.inputSurface')) """ Contect the pos group to the info node""" mc.connectAttr ((posInfoNodes[cnt]+'.position'),(grp+'.translate')) """ Connect the U tangent attribute to the child of our first group """ mc.connectAttr ((posInfoNodes[cnt]+'.tangentU'),(upGroups[cnt]+'.translate')) mc.setAttr ((posInfoNodes[cnt]+'.parameterU'),.5) mc.setAttr ((posInfoNodes[cnt]+'.parameterV'),(vValues[cnt])) cnt += 1 """ Make our measure nodes to keep joint position """ posPairsList = lists.parseListToPairs (posInfoNodes) posDistConnections = [] poseDistNameList = [] for pair in posPairsList: distanceInfoBuffer = distance.createDistanceNodeBetweenPosInfoNodes (pair[0],pair[1]) posDistConnections.append(distanceInfoBuffer[2]) poseDistNameList.append(distanceInfoBuffer[0]) """ connect the distances to our stretch translation channels on our joints """ """ connect the distances to our stretch translation channels on our joints """ #find it directionCap = 'X' cnt = 0 jointLengths = [] mdNodes = [] """ need to make our master scale connector""" scaleHolderGrp= (controlSurface[0]+'_scaleHolder_grp') masterScaleAttrBuffer = (scaleHolderGrp+'.worldScale') if mc.objExists (scaleHolderGrp): pass else: mc.group (n= scaleHolderGrp, w=True, empty=True) mc.addAttr (scaleHolderGrp, ln = 'worldScale', at = 'float', hidden=False ) mc.setAttr(masterScaleAttrBuffer,1) """ return our default lengths and store them,then run them through an md node to return our scale values """ for jnt in heirarchyJoints[0:-1]: lengthBuffer = mc.getAttr (posDistConnections[cnt]) jointLengths.append (lengthBuffer) #mc.addAttr (jnt, ln = 'baseLength', at = 'float') mc.addAttr (scaleHolderGrp, ln = (jnt+'_baseLength'), at = 'float') jntAttrBuffer = (scaleHolderGrp+'.'+jnt+'_baseLength') mc.setAttr (jntAttrBuffer,jointLengths[cnt]) mdNodeBuffer = nodes.createNamedNode ((jnt+'_jntScale'), 'multiplyDivide') mdNodes.append(mdNodeBuffer) mc.setAttr ((mdNodeBuffer+'.operation'),2) mc.connectAttr((posDistConnections[cnt]),(mdNodeBuffer+'.input1X')) mc.connectAttr((jntAttrBuffer),(mdNodeBuffer+'.input2X')) mc.connectAttr(masterScaleAttrBuffer,(jnt+'.scaleY')) mc.connectAttr(masterScaleAttrBuffer,(jnt+'.scaleZ')) mc.connectAttr((mdNodeBuffer+'.output.outputX'),(jnt+'.scale'+directionCap)) cnt+=1 """ """ #mc.connectAttr ( """ SET SPECIAL CONDITION FOR FIRST POS GROUP """ #mc.setAttr ((posInfoNodes[0]+'.parameterV'),0) """Clean up stuff """ cleanupGrp = mc.group (n= 'surfacePosFollowStuff_grp', w=True, empty=True) for grp in posGroups: mc.parent (grp, cleanupGrp) """ make some IK effectors and connect everything up""" effectorList = [] cnt = (len(heirarchyJoints) - 1) firstTermCount = 0 secondTermCount = 1 while cnt > 0: effector = mc.ikHandle (name = (heirarchyJoints[firstTermCount]+'_ikHandle') , startJoint=heirarchyJoints[firstTermCount], endEffector = heirarchyJoints[secondTermCount], setupForRPsolver = True, solver = 'ikRPsolver', enableHandles=True ) """ if it's the not the last effector, do this """ if cnt > 1: mc.parent (effector[0],posGroups[secondTermCount]) """ if it is, parent it to the last controlJoint """ if cnt == 1: mc.parent (effector[0],posGroups[secondTermCount]) effectorList.append (effector[0]) cnt-=1 firstTermCount += 1 secondTermCount += 1 if cnt == 0: break """ let's make some pole vector constraints""" #----------->>>>> Need to find a good way of "discovering" correct twist for the effectors cnt = 0 """ Connect first joint to surface """ mc.connectAttr ((posGroups[0]+'.translate'),(heirarchyJoints[0]+'.translate')) for effector in effectorList: #print ('Constrain '+effector+' to '+ upGroups[cnt]) poleVector = mc.poleVectorConstraint (upGroups[cnt],effector,name = (effector+'_pvConst')) """ fix the twist""" if (len(effectorList) - cnt) == 0: mc.setAttr ((effector+'.twist'),-180) elif cnt == 0: mc.setAttr ((effector+'.twist'),0) else: mc.setAttr ((effector+'.twist'),-90) cnt+=1 # """return all our data together to return""" """ clean up measure stuff """ if mc.objExists (name+'_measureStuff_grp'): distCleanupGrp = (name+'_measureStuff_grp') else: distCleanupGrp = mc.group (n= (name+'_measureStuff_grp'), w=True, empty=True) for dist in poseDistNameList: mc.parent (dist, distCleanupGrp) mc.setAttr ((dist+'.v'),0) mc.parent (distCleanupGrp, 'rigStuff_grp') mc.parent (cleanupGrp, 'rigStuff_grp') mc.parent (scaleHolderGrp, 'rigStuff_grp') """ connect master scale to the master """ mc.connectAttr(('placement_anim.sy'),masterScaleAttrBuffer) return controlSurface