Exemplo n.º 1
0
def centerPivotLocMeObject(obj):
    """
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	DESCRIPTION:
	Pass  an object into it and return locator placed at the center of
	the bounding box of the object while matching other factors

	ARGUMENTS:
	obj(string)

	RETURNS:
	name(string)
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	"""
    """pass  an object into it and get locator placed at the pivots - matching translation, rotation and rotation order"""
    rotationOrderDictionary = {
        'xyz': 0,
        'yzx': 1,
        'zxy': 2,
        'xzy': 3,
        'yxz': 4,
        'zyx': 5,
        'none': 6
    }
    """get stuff to transfer"""
    objTrans = distance.returnCenterPivotPosition(obj)
    objRot = mc.xform(obj, q=True, ws=True, ro=True)
    objRoo = mc.xform(obj, q=True, roo=True)
    """get rotation order"""
    correctRo = rotationOrderDictionary[objRoo]
    wantedName = (obj + '_loc')
    cnt = 1
    while mc.objExists(wantedName) == True:
        wantedName = ('%s%s%s%i' % (obj, '_', 'loc_', cnt))
        cnt += 1
    actualName = mc.spaceLocator(n=wantedName)
    """ account for multipleNamed things """
    if '|' in list(obj):
        locatorName = ('|' + actualName[0])
    else:
        locatorName = actualName[0]

    mc.move(objTrans[0], objTrans[1], objTrans[2], locatorName)
    mc.setAttr((locatorName + '.rotateOrder'), correctRo)
    mc.rotate(objRot[0], objRot[1], objRot[2], locatorName, ws=True)

    return locatorName
Exemplo n.º 2
0
def centerPivotLocMeObject(obj):
	"""
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	DESCRIPTION:
	Pass  an object into it and return locator placed at the center of
	the bounding box of the object while matching other factors

	ARGUMENTS:
	obj(string)

	RETURNS:
	name(string)
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	"""
	"""pass  an object into it and get locator placed at the pivots - matching translation, rotation and rotation order"""
	rotationOrderDictionary = {'xyz':0,'yzx':1 ,'zxy':2 ,'xzy':3 ,'yxz':4,'zyx':5,'none':6}

	"""get stuff to transfer"""
	objTrans = distance.returnCenterPivotPosition(obj)
	objRot = mc.xform (obj, q=True, ws=True, ro=True)
	objRoo = mc.xform (obj, q=True, roo=True )

	"""get rotation order"""
	correctRo = rotationOrderDictionary[objRoo]
	wantedName = (obj + '_loc')
	cnt = 1
	while mc.objExists(wantedName) == True:
		wantedName = ('%s%s%s%i' % (obj,'_','loc_',cnt))
		cnt +=1
	actualName = mc.spaceLocator (n= wantedName)

	""" account for multipleNamed things """
	if '|' in list(obj):
		locatorName = ('|'+actualName[0])
	else:
		locatorName = actualName[0]


	mc.move (objTrans[0],objTrans[1],objTrans[2], locatorName)
	mc.setAttr ((locatorName+'.rotateOrder'), correctRo)
	mc.rotate (objRot[0], objRot[1], objRot[2], locatorName, ws=True)

	return locatorName
Exemplo n.º 3
0
def returnInfoForLoc(obj,forceBBCenter = False):
	"""
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	DESCRIPTION:
	Return info to create or update a locator.

	ARGUMENTS:
	obj(string)

	RETURNS:
	locInfo(dict)
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	"""
	"""pass  an object into it and get locator placed at the pivots - matching translation, rotation and rotation order"""
	rotationOrderDictionary = {'xyz':0,'yzx':1 ,'zxy':2 ,'xzy':3 ,'yxz':4,'zyx':5,'none':6}

	"""get stuff to transfer"""
	objType = search.returnObjectType(obj)

	# vertex
	if objType == 'polyVertex':
		objTrans = mc.pointPosition(obj,w=True)
	elif objType == 'polyEdge':
		mc.select(cl=True)
		mc.select(obj)
		mel.eval("PolySelectConvert 3")
		edgeVerts = mc.ls(sl=True,fl=True)
		posList = []
		for vert in edgeVerts:
			posList.append(mc.pointPosition(vert,w=True))
		objTrans = distance.returnAveragePointPosition(posList)
		mc.select(cl=True)
	elif objType == 'polyFace':
		mc.select(cl=True)
		mc.select(obj)
		mel.eval("PolySelectConvert 3")
		edgeVerts = mc.ls(sl=True,fl=True)
		posList = []
		for vert in edgeVerts:
			posList.append(mc.pointPosition(vert,w=True))
		objTrans = distance.returnAveragePointPosition(posList)
		mc.select(cl=True)
	elif objType in ['surfaceCV','curveCV','editPoint','nurbsUV','curvePoint']:
		mc.select(cl=True)
		objTrans = mc.pointPosition (obj,w=True)
	else:
		if forceBBCenter == True:
			objTrans = distance.returnCenterPivotPosition(obj)
		else:
			objTrans = mc.xform (obj, q=True, ws=True, sp=True)

	objRot = mc.xform (obj, q=True, ws=True, ro=True)
	objRoo = mc.xform (obj, q=True, roo=True )

	"""get rotation order"""
	correctRo = rotationOrderDictionary[objRoo]


	locInfo = {}
	locInfo['createdFrom']=obj
	locInfo['objectType']=objType
	locInfo['position']=objTrans
	locInfo['rotation']=objRot
	locInfo['rotationOrder']=correctRo


	return locInfo
Exemplo n.º 4
0
    def createSizeTemplateControl(self):
        """ 
        >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   
        DESCRIPTION:
        Generates a sizeTemplateObject. It's been deleted, it recreates it. Guess the size based off of there
        being a mesh there. If there is no mesh, it sets sets an intial size of a 
        [155,170,29] unit character.
        
        ARGUMENTS:
        self.PuppetNull.nameShort(string)
        
        RETURNS:
        returnList(list) = [startCrv(string),EndCrv(list)]
        >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        """
        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        # Get info
        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        startColors = modules.returnSettingsData('colorStart')
        endColors = modules.returnSettingsData('colorEnd')

        font = mc.getAttr((self.msgSettingsInfo.get() + '.font'))
        """ checks for there being anything in our geo group """
        if not self.geo:
            return guiFactory.warning(
                'Need some geo defined to make this tool worthwhile')
            boundingBoxSize = modules.returnSettingsDataAsFloat(
                'meshlessSizeTemplate')
        else:
            boundingBoxSize = distance.returnBoundingBoxSize(
                self.msgGeoGroup.get())
            boundingBox = mc.exactWorldBoundingBox(self.msgGeoGroup.get())
        """determine orienation """
        maxSize = max(boundingBoxSize)
        matchIndex = boundingBoxSize.index(maxSize)
        """Find the pivot of the bounding box """
        pivotPosition = distance.returnCenterPivotPosition(
            self.msgGeoGroup.get())

        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        # Get our positions
        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        if self.optionPuppetMode.get() == 0:
            #If bio...
            if matchIndex == 1 or matchIndex == 0:
                #Vertical
                posBuffers = [[0, .5, 0], [0, .75, 0]]
                width = (boundingBoxSize[0] / 2)
                height = (boundingBoxSize[1])
                depth = boundingBoxSize[2]

                for cnt, pos in enumerate(posBuffers):
                    posBuffer = posBuffers[cnt]
                    posBuffer[0] = 0
                    posBuffer[1] = (posBuffer[1] * height)
                    posBuffer[2] = 0

            elif matchIndex == 2:
                #Horizontal
                posBuffers = [[0, 0, -.33], [0, 0, .66]]
                width = boundingBoxSize[1]
                height = boundingBoxSize[2] / 2
                depth = (boundingBoxSize[0])

                for cnt, pos in enumerate(posBuffers):
                    posBuffer = posBuffers[cnt]
                    posBuffer[0] = 0
                    posBuffer[1] = boundingBoxSize[1] * .75
                    posBuffer[2] = (posBuffer[2] * height)

        else:
            #Otherwise
            if matchIndex == 1 or matchIndex == 0:
                #Vertical
                width = (boundingBoxSize[0] / 2)
                height = (boundingBoxSize[1])
                depth = boundingBoxSize[2]
                posBuffers = [[0, boundingBox[1], 0], [0, boundingBox[4], 0]]

            elif matchIndex == 2:
                #Horizontal
                width = boundingBoxSize[0]
                height = boundingBoxSize[2] / 2
                depth = (boundingBoxSize[1])
                startHeight = max([boundingBox[4], boundingBox[1]]) - depth / 2
                print startHeight
                posBuffers = [[0, startHeight, boundingBox[2]],
                              [0, startHeight, boundingBox[5]]]
        # Simple reverse of start pos buffers if the object is pointing negative
        if self.optionAimAxis < 2:
            posBuffers.reverse()

        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        # Making the controls
        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        """ make our control object """
        startCurves = []
        startCurve = curves.createControlCurve('circle', depth * .8)
        mc.xform(startCurve, t=posBuffers[0], ws=True)
        attributes.doSetAttr(startCurve, 'rotateOrder', 5)
        curves.setCurveColorByName(startCurve, startColors[1])
        startCurves.append(startCurve)

        startText = curves.createTextCurve('start',
                                           size=depth * .75,
                                           font=font)
        mc.xform(startText, t=posBuffers[0], ws=True)
        curves.setCurveColorByName(startText, startColors[0])
        startCurves.append(startText)

        endCurves = []
        endCurve = curves.createControlCurve('circle', depth * .8)
        mc.xform(endCurve, t=posBuffers[1], ws=True)
        curves.setCurveColorByName(endCurve, endColors[1])
        attributes.doSetAttr(endCurve, 'rotateOrder', 5)
        endCurves.append(endCurve)

        endText = curves.createTextCurve('end', size=depth * .6, font=font)
        mc.xform(endText, t=posBuffers[1], ws=True)
        curves.setCurveColorByName(endText, endColors[0])
        endCurves.append(endText)
        """ aiming """
        position.aimSnap(startCurve, endCurve, [0, 0, 1], [0, 1, 0])
        position.aimSnap(startText, endCurve, [0, 0, 1], [0, 1, 0])

        position.aimSnap(endCurve, startCurve, [0, 0, -1], [0, 1, 0])
        position.aimSnap(endText, startCurve, [0, 0, -1], [0, 1, 0])

        sizeCurveControlStart = curves.combineCurves(startCurves)
        sizeCurveControlEnd = curves.combineCurves(endCurves)
        """ store our info to name our objects"""
        attributes.storeInfo(sizeCurveControlStart, 'cgmName',
                             (self.PuppetNull.nameShort + '.cgmName'))
        attributes.storeInfo(sizeCurveControlStart, 'cgmDirection', 'start')
        attributes.storeInfo(sizeCurveControlStart, 'cgmType',
                             'templateSizeObject')
        sizeCurveControlStart = NameFactory.doNameObject(sizeCurveControlStart)
        mc.makeIdentity(sizeCurveControlStart,
                        apply=True,
                        t=True,
                        s=True,
                        r=True)

        attributes.storeInfo(sizeCurveControlEnd, 'cgmName',
                             (self.PuppetNull.nameShort + '.cgmName'))
        attributes.storeInfo(sizeCurveControlEnd, 'cgmDirection', 'end')
        attributes.storeInfo(sizeCurveControlEnd, 'cgmType',
                             'templateSizeObject')
        sizeCurveControlEnd = NameFactory.doNameObject(sizeCurveControlEnd)

        endGroup = rigging.groupMeObject(sizeCurveControlEnd)
        mc.makeIdentity(sizeCurveControlEnd,
                        apply=True,
                        t=True,
                        s=True,
                        r=True)

        mc.parentConstraint(sizeCurveControlStart,
                            endGroup,
                            maintainOffset=True)
        """ make control group """
        controlGroup = rigging.groupMeObject(sizeCurveControlStart)
        attributes.storeInfo(controlGroup, 'cgmName',
                             (self.PuppetNull.nameShort + '.cgmName'))
        attributes.storeInfo(controlGroup, 'cgmType',
                             'templateSizeObjectGroup')
        controlGroup = NameFactory.doNameObject(controlGroup)

        endGroup = rigging.doParentReturnName(endGroup, controlGroup)
        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        # Getting data ready
        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        attributes.storeInfo(controlGroup, 'controlStart',
                             sizeCurveControlStart)
        attributes.storeInfo(controlGroup, 'controlEnd', sizeCurveControlEnd)
        attributes.storeInfo(self.PuppetNull.nameShort, 'templateSizeObject',
                             controlGroup)

        self.templateSizeObjects['root'] = controlGroup
        self.templateSizeObjects['start'] = sizeCurveControlStart
        self.templateSizeObjects['end'] = sizeCurveControlEnd

        returnList = []
        returnList.append(sizeCurveControlStart)
        returnList.append(sizeCurveControlEnd)
        return returnList
Exemplo n.º 5
0
def returnInfoForLoc(obj, forceBBCenter=False):
    """
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	DESCRIPTION:
	Return info to create or update a locator.

	ARGUMENTS:
	obj(string)

	RETURNS:
	locInfo(dict)
	>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	"""
    """pass  an object into it and get locator placed at the pivots - matching translation, rotation and rotation order"""
    rotationOrderDictionary = {
        'xyz': 0,
        'yzx': 1,
        'zxy': 2,
        'xzy': 3,
        'yxz': 4,
        'zyx': 5,
        'none': 6
    }
    """get stuff to transfer"""
    objType = search.returnObjectType(obj)

    # vertex
    if objType == 'polyVertex':
        objTrans = mc.pointPosition(obj, w=True)
    elif objType == 'polyEdge':
        mc.select(cl=True)
        mc.select(obj)
        mel.eval("PolySelectConvert 3")
        edgeVerts = mc.ls(sl=True, fl=True)
        posList = []
        for vert in edgeVerts:
            posList.append(mc.pointPosition(vert, w=True))
        objTrans = distance.returnAveragePointPosition(posList)
        mc.select(cl=True)
    elif objType == 'polyFace':
        mc.select(cl=True)
        mc.select(obj)
        mel.eval("PolySelectConvert 3")
        edgeVerts = mc.ls(sl=True, fl=True)
        posList = []
        for vert in edgeVerts:
            posList.append(mc.pointPosition(vert, w=True))
        objTrans = distance.returnAveragePointPosition(posList)
        mc.select(cl=True)
    elif objType in [
            'surfaceCV', 'curveCV', 'editPoint', 'nurbsUV', 'curvePoint'
    ]:
        mc.select(cl=True)
        objTrans = mc.pointPosition(obj, w=True)
    else:
        if forceBBCenter == True:
            objTrans = distance.returnCenterPivotPosition(obj)
        else:
            objTrans = mc.xform(obj, q=True, ws=True, sp=True)

    objRot = mc.xform(obj, q=True, ws=True, ro=True)
    objRoo = mc.xform(obj, q=True, roo=True)
    """get rotation order"""
    correctRo = rotationOrderDictionary[objRoo]

    locInfo = {}
    locInfo['createdFrom'] = obj
    locInfo['objectType'] = objType
    locInfo['position'] = objTrans
    locInfo['rotation'] = objRot
    locInfo['rotationOrder'] = correctRo

    return locInfo