Esempio n. 1
0
	def __func__(self):
	    """
	    """
	    self.mi_baseCurve = cgmMeta.validateObjArg(self.d_kws['baseCurve'],mayaType='nurbsCurve',noneValid=False)
	    self._str_funcCombined = self._str_funcCombined + "(%s)"%self.mi_baseCurve.p_nameShort
	    
	    self.str_arg = cgmValid.stringArg(self.d_kws['arg'],noneValid=True)
	    self.b_keepOriginal = cgmValid.boolArg(self.d_kws['keepOriginal'], calledFrom=self._str_funcCombined)
	    
	    if isEP(self.mi_baseCurve):
		log.warning("%s %s already an ep curve"%(self._str_reportStart,self.mi_baseCurve.p_nameShort))
		return False
	    
	    mi_crv = self.mi_baseCurve
	    if self.str_arg.lower() == 'ep':
		l_pos = []
		for cv in mi_crv.getComponents('cv'):
		    locatorName = locators.locMeObject(cv)
		    pos = distance.returnClosestUPosition(locatorName,mi_crv.mNode)
		    mc.delete(locatorName)
		    l_pos.append( pos )	
		if not self.b_keepOriginal:mi_crv.delete()
		return mc.curve(d = 2,ep = l_pos, os = True)
		#return curves.curveFromPosList(l_pos)
	    raise NotImplementedError,"arg: %s"%self.str_arg
Esempio n. 2
0
def ObjectFacesToFolicles():
    try:
	import parentConstraintToSurface
    except:
	"Can't find parentConstraintToSurface"
	
    selection = mc.ls(sl=True) or []
    if not selection:
	return "Nothing selected"
    
    #If we're going, create a return set
    returnSet = SetFactory.SetFactory('folicledLocs','td',True)
    
    # Make some groups
    mLocGroup = mc.group(em=True,name = 'locators_grp')   
    
    number = len(selection)
    returnList = []
    for i,o in enumerate(selection):
	guiFactory.report("On %s. %s of %s"%(o,i,number))
	faceBuffer = "%s.f[4]"%o
	if not mc.objExists(faceBuffer):
	    print "'%s' has no face!"%o
	    
	loc = locators.locMeObject(faceBuffer)
	returnSet.store(loc)	
	mc.select(cl=True)
	mc.select(loc,o)
	parentConstraintToSurface.parentConstraintToSurface()
	
	rigging.doParentReturnName(loc,mLocGroup)
	
    
    follicles = mc.ls(type='follicle')
    mc.select(follicles)
    mc.group(name = 'folicles_grp')
Esempio n. 3
0
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
Esempio n. 4
0
	def getCurveMirrorData(self,mi_crv):
	    d_return = {}
	    d_return['f_bbMin'] = mi_crv.boundingBoxMin[self.int_across]
	    d_return['f_bbMax'] = mi_crv.boundingBoxMax[self.int_across]
	    d_return['b_oneSided'] = False
	    d_return['b_balanced'] = False
	    d_return['b_weighted'] = None	    
	    	    
	    #> First see our push direction ----------------------------------------------------------
	    try:
		if cgmMath.isFloatEquivalent( d_return['f_bbMax'], d_return['f_bbMin']):
		    d_return['b_balanced'] = 1
		    
		if d_return['f_bbMax'] > d_return['f_bbMin']:
		    d_return['b_weighted'] = 1
		elif d_return['f_bbMax'] < d_return['f_bbMin']:
		    d_return['b_weighted'] = -1
	    except Exception,error:raise StandardError,"Push direction check | %s"%error

	    #> Check thresholds ----------------------------------------------------------------------
	    try:
		if -d_return['f_bbMin'] <= self.f_threshold and d_return['f_bbMax'] >= self.f_threshold or d_return['f_bbMin'] <= -self.f_threshold and d_return['f_bbMax'] <= -self.f_threshold:
		    d_return['b_oneSided'] = True		
		"""if abs(d_return['f_bbMin']) <= self.f_threshold or abs(d_return['f_bbMax']) <= self.f_threshold:
		    d_return['b_oneSided'] = True"""
	    except Exception,error:raise StandardError,"Threshholds check | %s"%error
	
	    #> Is ep --------------------------------------------------------------------
	    try:
		d_return['b_epState'] = isEP(mi_crv)
	    except Exception,error:raise StandardError,"ep check | %s"%error
	    
	    #> Get positions -------------------------------------------------------------------------
	    try:
		l_cvs = mi_crv.getComponents('cv')	    	    		
		l_cvPos = []
		l_epPos = []
		if d_return['b_epState']:
		    for ep in  mi_crv.getComponents('ep'):
			pos = mc.pointPosition(ep,w=True)
			l_epPos.append( pos )	
		    for cv in l_cvs:
			l_cvPos.append( mc.pointPosition(cv,w=True) )	
		else:
		    for cv in l_cvs:
			l_cvPos.append( mc.pointPosition(cv,w=True) )	 
			#Get an ep value
			locatorName = locators.locMeObject(cv)
			pos = distance.returnClosestUPosition(locatorName,mi_crv.mNode)
			mc.delete(locatorName)
			l_epPos.append( pos )	 
			
		d_return['l_cvPos'] = l_cvPos
		d_return['l_epPos'] = l_epPos	    
		d_return['l_cvs'] = l_cvs
	    except Exception,error:raise StandardError,"Get positions | %s"%error
	     
	    #> Is even --------------------------------------------------------------------
	    try:
		if len(l_cvs)%2==0:#even
		    d_return['b_even'] = True
		else: d_return['b_even'] = False
	    except Exception,error:"Even check | %s"%error
	    
	    #> Which end is bigger
	    try:
		if abs(l_cvPos[0][self.int_across]) <= self.f_threshold:
		    d_return['b_startInThreshold'] = True
		else:d_return['b_startInThreshold'] = False
		if abs(l_cvPos[-1][self.int_across]) <= self.f_threshold:
		    d_return['b_endInThreshold'] = True
		else:d_return['b_endInThreshold'] = False
	    except Exception,error:raise StandardError,"End check | %s"%error
	    
	    return d_return