def doPointConstraintObjectGroup(targets,object,mode=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Groups an object and constrains that group to the other objects ARGUMENTS: targets(list) object(string mode(int) - 0 - equal influence 1 - distance spread RETURNS: group(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ objGroup = rigging.groupMeObject(object,True,True) constraint = mc.pointConstraint (targets,objGroup, maintainOffset=True) if mode == 1: distances = [] for target in targets: distances.append(distance.returnDistanceBetweenObjects(target,objGroup)) normalizedDistances = cgmMath.normList(distances) targetWeights = mc.pointConstraint(constraint,q=True, weightAliasList=True) cnt=1 for value in normalizedDistances: mc.setAttr(('%s%s%s' % (constraint[0],'.',targetWeights[cnt])),value ) cnt-=1 return objGroup
def returnNormalizedWeightsByDistance(obj,targets): """ Returns a normalized weight set based on distance from object to targets ARGUMENTS: obj(string)-- targets(string)-- RETURNS: weights(list)-- """ weights = [] distances = [] distanceObjDict = {} objDistanceDict = {} for t in targets: buffer = distance.returnDistanceBetweenObjects(obj,t) # get the distance distances.append(buffer) distanceObjDict[buffer] = t objDistanceDict[t] = buffer normalizedDistances = cgmMath.normList(distances) # get normalized distances to 1 distances.sort() #sort our distances normalizedDistances.sort() # sort the normalized list (should match the distance sort) normalizedDistances.reverse() # reverse the sort for weight values for i,t in enumerate(targets): d = objDistanceDict[t] index = distances.index(d) weights.append( normalizedDistances[index] ) return weights
def doPointConstraintObjectGroup(targets, object, mode=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Groups an object and constrains that group to the other objects ARGUMENTS: targets(list) object(string mode(int) - 0 - equal influence 1 - distance spread RETURNS: group(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ objGroup = rigging.groupMeObject(object, True, True) constraint = mc.pointConstraint(targets, objGroup, maintainOffset=True) if mode == 1: distances = [] for target in targets: distances.append( distance.returnDistanceBetweenObjects(target, objGroup)) normalizedDistances = cgmMath.normList(distances) targetWeights = mc.pointConstraint(constraint, q=True, weightAliasList=True) cnt = 1 for value in normalizedDistances: mc.setAttr(('%s%s%s' % (constraint[0], '.', targetWeights[cnt])), value) cnt -= 1 return objGroup
def doConstraintObjectGroup(targets,obj = False,constraintTypes = [],group = False, mode=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Groups an object and constrains that group to the other objects ARGUMENTS: targets(list) object(string) constraintTypes(list) group(string) -- whether to pass a group through mode(int) - 0 - equal influence 1 - distance spread RETURNS: group(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ log.debug(">>> doConstraintObjectGroup") log.info("targets: %s"%str(targets)) log.debug("obj: %s"%str(obj)) log.info("constraintTypes: %s"%str(constraintTypes)) log.debug("group: %s"%str(group)) log.debug("mode: %s"%str(mode)) if targets and not type(targets)==list:targets=[targets]#thanks Mark, for this syntax if constraintTypes and not type(constraintTypes)==list:constraintTypes=[constraintTypes] normalizedDistances = False if not obj and not group: log.warning("Must have a obj or a group") return False if group and mc.objExists(group): objGroup = group elif obj: objGroup = rigging.groupMeObject(obj,True,True) else: log.warning("Not enough info") return False for c in constraintTypes: constraint = False if mode == 1: distances = [] for target in targets: distances.append(distance.returnDistanceBetweenObjects(target,objGroup)) normalizedDistances = cgmMath.normList(distances) if c == 'point': constraint = mc.pointConstraint(targets,objGroup, maintainOffset=True) targetWeights = mc.pointConstraint(constraint,q=True, weightAliasList=True) if c == 'parent': constraint = mc.parentConstraint(targets,objGroup, maintainOffset=True) targetWeights = mc.parentConstraint(constraint,q=True, weightAliasList=True) if c == 'orient': constraint = mc.orientConstraint(targets,objGroup, maintainOffset=True) targetWeights = mc.orientConstraint(constraint,q=True, weightAliasList=True) if c == 'scale': constraint = mc.scaleConstraint(targets,objGroup, maintainOffset=True) targetWeights = mc.scaleConstraint(constraint,q=True, weightAliasList=True) if constraint: try:mc.setAttr("%s.interpType"%constraint[0],0)#Set to no flip except:pass if normalizedDistances: for cnt,value in enumerate(normalizedDistances): mc.setAttr(('%s%s%s' % (constraint[0],'.',targetWeights[cnt])),value ) return objGroup
def doPointAimConstraintObjectGroup(targets,object,mode=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ACKNOWLEDGEMENT: Idea for this stype of constraint setup is from http://td-matt.blogspot.com/2011/01/spine-control-rig.html DESCRIPTION: Groups an object and constrains that group to the other objects ARGUMENTS: targets(list) - should be in format of from to back with the last one being the aim object object(string) mode(int) - 0 - equal influence 1 - distance spread RETURNS: group(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ returnList = [] """ figure out which is the aim direction """ aimVector = logic.returnLocalAimDirection(object,targets[-1]) upVector = logic.returnLocalUp(aimVector) """ create locators """ locs = [] toMake = ['point','aim','up'] for type in toMake: locBuffer = locators.locMeObject(object) attributes.storeInfo(locBuffer,'cgmName',object) attributes.storeInfo(locBuffer,'cgmTypeModifier',type) locs.append(NameFactory.doNameObject(locBuffer)) pointLoc = locs[0] aimLoc = locs[1] upLoc = locs[2] """ move the locators """ mc.xform(aimLoc,t=aimVector,r=True,os=True) mc.xform(upLoc,t=upVector,r=True,os=True) """group constraint""" objGroup = rigging.groupMeObject(object,True,True) attributes.storeInfo(objGroup,'cgmName',object) attributes.storeInfo(objGroup,'cgmTypeModifier','follow') objGroup = NameFactory.doNameObject(objGroup) pointConstraintBuffer = mc.pointConstraint (pointLoc,objGroup, maintainOffset=False) aimConstraintBuffer = mc.aimConstraint(aimLoc,objGroup,maintainOffset = False, weight = 1, aimVector = aimVector, upVector = upVector, worldUpObject = upLoc, worldUpType = 'object' ) """loc constraints""" locConstraints = [] for loc in locs: parentConstraintBuffer = mc.parentConstraint (targets,loc, maintainOffset=True) locConstraints.append(parentConstraintBuffer[0]) if mode == 1: distances = [] for target in targets: distances.append(distance.returnDistanceBetweenObjects(target,objGroup)) normalizedDistances = cgmMath.normList(distances) for constraint in locConstraints: targetWeights = mc.parentConstraint(constraint,q=True, weightAliasList=True) cnt=1 for value in normalizedDistances: mc.setAttr(('%s%s%s' % (constraint,'.',targetWeights[cnt])),value ) cnt-=1 returnList.append(objGroup) returnList.append(locs) return returnList
def doConstraintObjectGroup(targets, obj=False, constraintTypes=[], group=False, mode=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Groups an object and constrains that group to the other objects ARGUMENTS: targets(list) object(string) constraintTypes(list) group(string) -- whether to pass a group through mode(int) - 0 - equal influence 1 - distance spread RETURNS: group(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ log.debug(">>> doConstraintObjectGroup") log.info("targets: %s" % str(targets)) log.debug("obj: %s" % str(obj)) log.info("constraintTypes: %s" % str(constraintTypes)) log.debug("group: %s" % str(group)) log.debug("mode: %s" % str(mode)) if targets and not type(targets) == list: targets = [targets] #thanks Mark, for this syntax if constraintTypes and not type(constraintTypes) == list: constraintTypes = [constraintTypes] normalizedDistances = False if not obj and not group: log.warning("Must have a obj or a group") return False if group and mc.objExists(group): objGroup = group elif obj: objGroup = rigging.groupMeObject(obj, True, True) else: log.warning("Not enough info") return False for c in constraintTypes: constraint = False if mode == 1: distances = [] for target in targets: distances.append( distance.returnDistanceBetweenObjects(target, objGroup)) normalizedDistances = cgmMath.normList(distances) if c == 'point': constraint = mc.pointConstraint(targets, objGroup, maintainOffset=True) targetWeights = mc.pointConstraint(constraint, q=True, weightAliasList=True) if c == 'parent': constraint = mc.parentConstraint(targets, objGroup, maintainOffset=True) targetWeights = mc.parentConstraint(constraint, q=True, weightAliasList=True) if c == 'orient': constraint = mc.orientConstraint(targets, objGroup, maintainOffset=True) targetWeights = mc.orientConstraint(constraint, q=True, weightAliasList=True) if c == 'scale': constraint = mc.scaleConstraint(targets, objGroup, maintainOffset=True) targetWeights = mc.scaleConstraint(constraint, q=True, weightAliasList=True) if constraint: try: mc.setAttr("%s.interpType" % constraint[0], 0) #Set to no flip except: pass if normalizedDistances: for cnt, value in enumerate(normalizedDistances): mc.setAttr( ('%s%s%s' % (constraint[0], '.', targetWeights[cnt])), value) return objGroup
def doPointAimConstraintObjectGroup(targets, object, mode=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ACKNOWLEDGEMENT: Idea for this stype of constraint setup is from http://td-matt.blogspot.com/2011/01/spine-control-rig.html DESCRIPTION: Groups an object and constrains that group to the other objects ARGUMENTS: targets(list) - should be in format of from to back with the last one being the aim object object(string) mode(int) - 0 - equal influence 1 - distance spread RETURNS: group(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ returnList = [] """ figure out which is the aim direction """ aimVector = logic.returnLocalAimDirection(object, targets[-1]) upVector = logic.returnLocalUp(aimVector) """ create locators """ locs = [] toMake = ['point', 'aim', 'up'] for type in toMake: locBuffer = locators.locMeObject(object) attributes.storeInfo(locBuffer, 'cgmName', object) attributes.storeInfo(locBuffer, 'cgmTypeModifier', type) locs.append(NameFactory.doNameObject(locBuffer)) pointLoc = locs[0] aimLoc = locs[1] upLoc = locs[2] """ move the locators """ mc.xform(aimLoc, t=aimVector, r=True, os=True) mc.xform(upLoc, t=upVector, r=True, os=True) """group constraint""" objGroup = rigging.groupMeObject(object, True, True) attributes.storeInfo(objGroup, 'cgmName', object) attributes.storeInfo(objGroup, 'cgmTypeModifier', 'follow') objGroup = NameFactory.doNameObject(objGroup) pointConstraintBuffer = mc.pointConstraint(pointLoc, objGroup, maintainOffset=False) aimConstraintBuffer = mc.aimConstraint(aimLoc, objGroup, maintainOffset=False, weight=1, aimVector=aimVector, upVector=upVector, worldUpObject=upLoc, worldUpType='object') """loc constraints""" locConstraints = [] for loc in locs: parentConstraintBuffer = mc.parentConstraint(targets, loc, maintainOffset=True) locConstraints.append(parentConstraintBuffer[0]) if mode == 1: distances = [] for target in targets: distances.append( distance.returnDistanceBetweenObjects(target, objGroup)) normalizedDistances = cgmMath.normList(distances) for constraint in locConstraints: targetWeights = mc.parentConstraint(constraint, q=True, weightAliasList=True) cnt = 1 for value in normalizedDistances: mc.setAttr(('%s%s%s' % (constraint, '.', targetWeights[cnt])), value) cnt -= 1 returnList.append(objGroup) returnList.append(locs) return returnList
def simpleControlSurfaceSmoothWeights(surface,maxBlend = 3): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Early version of a weight smoother for a ARGUMENTS: surface(string) RETURNS: Nada >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ cvList = (mc.ls ([surface+'.cv[*][*]'],flatten=True)) skinCluster = querySkinCluster (surface) influenceObjects = queryInfluences (skinCluster) #find the closest influence object to the start startObject = (distance.returnClosestObjToCV (cvList[0], influenceObjects)) #find the closest influence object to the end endObject = (distance.returnClosestObjToCV (cvList[-1], influenceObjects)) #getting the last cv list number cvChainLength = ((len(cvList)-1)/2) #Smooth interior weights """ get our interior CVs """ interiorCvList = [] cnt = 1 for i in range(cvChainLength): interiorCvList.append('%s%s%i%s' % (surface,'.cv[0][',cnt,']')) interiorCvList.append('%s%s%i%s' % (surface,'.cv[1][',cnt,']')) cnt += 1 """ overall blend """ for cv in interiorCvList: closestObject = (distance.returnClosestObjToCV (cv, influenceObjects)) closestObjectsDict = distance.returnClosestObjectsFromAim(closestObject,influenceObjects) upObjects = closestObjectsDict.get('up') downObjects = closestObjectsDict.get('dn') objectsToCheck = [] if upObjects != None: objectsToCheck += upObjects if downObjects != None: objectsToCheck += downObjects blendInfluences =[] blendInfluences.append(closestObject) distances = [] cnt = 1 print objectsToCheck while cnt < maxBlend and cnt < len(objectsToCheck): closestSubObj = distance.returnClosestObject(closestObject, objectsToCheck) blendInfluences.append(closestSubObj) objectsToCheck.remove(closestSubObj) cnt+=1 """ get our distances to normalize """ locBuffer = locators.locMeSurfaceCV(cv) for obj in blendInfluences: distances.append(distance.returnDistanceBetweenObjects(locBuffer,obj)) normalizedDistances = cgmMath.normList(distances, normalizeTo=1) cnt = 0 for obj in blendInfluences: mc.skinPercent (skinCluster,cv, tv = [obj,normalizedDistances[cnt]]) cnt +=1 mc.delete(locBuffer) """ Set closest cv's to respective infuences to max """ cvList1 = [] cvList2 = [] for i in range(cvChainLength): cvList1.append('%s%s%i%s' % (surface,'.cv[0][',cnt,']')) cvList2.append('%s%s%i%s' % (surface,'.cv[1][',cnt,']')) cnt += 1 for obj in influenceObjects: closestCV1 = distance.returnClosestCVFromList(obj, cvList1) mc.skinPercent (skinCluster,closestCV1, tv = [obj,1]) closestCV2 = distance.returnClosestCVFromList(obj, cvList2) mc.skinPercent (skinCluster,closestCV2, tv = [obj,1]) #set the skin weights for the top and bottom mc.skinPercent (skinCluster,(surface+'.cv[0:1][0:1]'), tv = [startObject,1]) mc.skinPercent (skinCluster,('%s%s%i%s%i%s' % (surface,'.cv[0:1][',(cvChainLength-1),':',cvChainLength,']')), tv = [endObject,1]) #Blend in the nearest row to the start and end mc.skinPercent (skinCluster,(surface+'.cv[0:1][2]'), tv = [startObject,1]) mc.skinPercent (skinCluster,('%s%s%i%s' % (surface,'.cv[0:1][',(cvChainLength-2),']')), tv = [endObject,1]) mc.skinPercent (skinCluster,(surface+'.cv[0:1][3]'), tv = [startObject,.7]) mc.skinPercent (skinCluster,('%s%s%i%s' % (surface,'.cv[0:1][',(cvChainLength-3),']')), tv = [endObject,.7])