예제 #1
0
def insertMulitiplyDivideBridge(drivenAttribute, newDriver):
    """ 
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Inserts a multiplyDivide bridge node for help taking care of compound scales
    
    1) get the driver
    2) create node
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    #>>> Get variables
    driverAttribute = attributes.returnDriverAttribute(drivenAttribute)
    print driverAttribute

    driverBuffer = driverAttribute.split('.')
    drivenBuffer = drivenAttribute.split('.')

    #>>> Create
    bridgeMDNode = createNamedNode((driverBuffer[0] + '_to_' + newDriver),
                                   'multiplyDivide')

    #>>> Connect
    attributes.doConnectAttr(driverAttribute, (bridgeMDNode + '.input1'))
    attributes.doConnectAttr(newDriver, (bridgeMDNode + '.input2'))

    attributes.doConnectAttr((bridgeMDNode + '.output'), drivenAttribute)
    """
예제 #2
0
파일: nodes.py 프로젝트: Italic-/maya-prefs
def insertMulitiplyDivideBridge(drivenAttribute, newDriver):
    """ 
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Inserts a multiplyDivide bridge node for help taking care of compound scales
    
    1) get the driver
    2) create node
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    # >>> Get variables
    driverAttribute = attributes.returnDriverAttribute(drivenAttribute)
    print driverAttribute

    driverBuffer = driverAttribute.split(".")
    drivenBuffer = drivenAttribute.split(".")

    # >>> Create
    bridgeMDNode = createNamedNode((driverBuffer[0] + "_to_" + newDriver), "multiplyDivide")

    # >>> Connect
    attributes.doConnectAttr(driverAttribute, (bridgeMDNode + ".input1"))
    attributes.doConnectAttr(newDriver, (bridgeMDNode + ".input2"))

    attributes.doConnectAttr((bridgeMDNode + ".output"), drivenAttribute)
    """
예제 #3
0
    def getMessage(self, *a, **kw):
        """ 
        Get and store attribute value as if they were messages. Used for bufferFactory to use a connected
        attribute as a poor man's attribute message function
        
        Keyword arguments:
        *a, **kw
        """
        try:
            if self.form == 'message':
                self.value = attributes.returnMessageObject(
                    self.obj.nameShort, self.attr)
                if search.returnObjectType(self.value) == 'reference':
                    if attributes.repairMessageToReferencedTarget(
                            self.obj.nameLong, self.attr, *a, **kw):
                        self.value = attributes.returnMessageObject(
                            self.obj.nameShort, self.attr)
            else:
                self.value = attributes.returnDriverAttribute(
                    "%s.%s" % (self.obj.nameShort, self.attr))

            guiFactory.report("'%s.%s' >Message> '%s'" %
                              (self.obj.nameShort, self.attr, self.value))
            return self.value

        except:
            guiFactory.warning("'%s.%s' failed to get" %
                               (self.obj.nameShort, self.attr))
예제 #4
0
    def getMessage(self,*a, **kw):
        """ 
        Get and store attribute value as if they were messages. Used for bufferFactory to use a connected
        attribute as a poor man's attribute message function
        
        Keyword arguments:
        *a, **kw
        """   
        try:
            if self.form == 'message':
                self.value = attributes.returnMessageObject(self.obj.nameShort,self.attr)
            else:
                self.value = attributes.returnDriverAttribute("%s.%s"%(self.obj.nameShort,self.attr))

            guiFactory.report("'%s.%s' >Message> '%s'"%(self.obj.nameShort,self.attr,self.value))
            return self.value
            
        except:
            guiFactory.warning("'%s.%s' failed to get"%(self.obj.nameShort,self.attr))
예제 #5
0
def plasticConstraintsAndScaleFromObjectToTransform():
    selection = mc.ls(sl=True, flatten=True)
    for obj in selection:
        #Make a transform
        group = rigging.groupMeObject(obj,maintainParent = True)

        #Get scale connections
        objScaleConnections = []
        for s in 'sx','sy','sz':
            buffer =  attributes.returnDriverAttribute(obj+'.'+s)
            attributes.doBreakConnection(obj+'.'+s)
            attributes.doConnectAttr(buffer,(group+'.'+s))

        # Get constraint info from obj
        objConstraints = constraints.returnObjectConstraints(obj)

        for const in objConstraints:
            constraintTargets = constraints.returnConstraintTargets(const)
            mc.delete(const)

            mc.parentConstraint(constraintTargets,group, maintainOffset = True)
예제 #6
0
def plasticConstraintsAndScaleFromObjectToTransform():
    selection = mc.ls(sl=True, flatten=True)
    for obj in selection:
        #Make a transform
        group = rigging.groupMeObject(obj,maintainParent = True)

        #Get scale connections
        objScaleConnections = []
        for s in 'sx','sy','sz':
            buffer =  attributes.returnDriverAttribute(obj+'.'+s)
            attributes.doBreakConnection(obj+'.'+s)
            attributes.doConnectAttr(buffer,(group+'.'+s))

        # Get constraint info from obj
        objConstraints = constraints.returnObjectConstraints(obj)

        for const in objConstraints:
            constraintTargets = constraints.returnConstraintTargets(const)
            mc.delete(const)

            mc.parentConstraint(constraintTargets,group, maintainOffset = True)
예제 #7
0
    def updateData(self, *a, **kw):
        """ 
        Get's attr updated data       
        """
        assert mc.objExists(
            '%s.%s' % (self.obj.nameShort, self.attr)
        ) is True, "'%s.%s' doesn't exist" % (self.obj.nameShort, self.attr)
        # Default attrs
        self.nameCombined = '%s.%s' % (self.obj.nameShort, self.attr)
        self.minValue = False
        self.maxValue = False
        self.defaultValue = False
        self.nameNice = mc.attributeQuery(self.attr,
                                          node=self.obj.nameShort,
                                          niceName=True)
        self.nameLong = mc.attributeQuery(self.attr,
                                          node=self.obj.nameShort,
                                          longName=True)
        self.nameAlias = False
        if mc.aliasAttr(self.nameCombined, q=True):
            self.nameAlias = mc.aliasAttr(self.nameCombined, q=True)

        self.get(*a, **kw)

        #>>> Parent Stuff
        pBuffer = mc.attributeQuery(self.attr,
                                    node=self.obj.nameShort,
                                    listParent=True)
        if pBuffer is None:
            self.parent = False
        else:
            self.parent = pBuffer[0]
        self.children = mc.attributeQuery(self.attr,
                                          node=self.obj.nameShort,
                                          listChildren=True)
        if self.children is None:
            self.children = False
        self.siblings = mc.attributeQuery(self.attr,
                                          node=self.obj.nameShort,
                                          listSiblings=True)
        if self.siblings is None:
            self.siblings = False
        self.enum = False

        self.userAttrs = mc.listAttr(self.obj.nameShort,
                                     userDefined=True) or []

        standardFlagsBuffer = attributes.returnStandardAttrFlags(
            self.obj.nameShort, self.nameLong)
        standardDataBuffer = attributes.returnAttributeDataDict(
            self.obj.nameShort, self.nameLong)

        #Check connections
        self.driver = attributes.returnDriverAttribute(self.nameCombined,
                                                       False)
        self.driven = attributes.returnDrivenAttribute(self.nameCombined,
                                                       False)

        self.numeric = standardFlagsBuffer.get('numeric')
        self.dynamic = standardFlagsBuffer.get('dynamic')

        self.locked = standardFlagsBuffer.get('locked')
        self.keyable = standardFlagsBuffer.get('keyable')
        self.hidden = standardFlagsBuffer.get('hidden')

        if self.dynamic:
            self.readable = standardFlagsBuffer.get('readable')
            self.writable = standardFlagsBuffer.get('writable')
            self.storable = standardFlagsBuffer.get('storable')
            self.usedAsColor = standardFlagsBuffer.get('usedAsColor')

        #>>> Numeric
        if self.numeric:
            bufferDict = attributes.returnNumericAttrSettingsDict(
                self.obj.nameShort, self.nameLong)
            if bufferDict:
                self.maxValue = bufferDict.get('max')
                self.minValue = bufferDict.get('min')
                self.defaultValue = bufferDict.get('default')
                self.softMaxValue = bufferDict.get('softMax')
                self.softMinValue = bufferDict.get('softMin')
                self.rangeValue = bufferDict.get('range')
                self.softRangeValue = bufferDict.get('softRange')
            else:
                self.maxValue = False
                self.minValue = False
                self.defaultValue = False
                self.softMaxValue = False
                self.softMinValue = False
                self.rangeValue = False
                self.softRangeValue = False

        if self.form == 'enum':
            self.enum = standardFlagsBuffer.get('enum')
예제 #8
0
 def updateData(self,*a, **kw):
     """ 
     Get's attr updated data       
     """     
     assert mc.objExists('%s.%s'%(self.obj.nameShort,self.attr)) is True, "'%s.%s' doesn't exist" %(self.obj.nameShort,self.attr)
     # Default attrs
     self.nameCombined = '%s.%s'%(self.obj.nameShort,self.attr)        
     self.minValue = False
     self.maxValue = False
     self.defaultValue = False
     self.nameNice = mc.attributeQuery(self.attr, node = self.obj.nameShort, niceName = True)
     self.nameLong = mc.attributeQuery(self.attr, node = self.obj.nameShort, longName = True)
     self.nameAlias = False
     if mc.aliasAttr(self.nameCombined,q=True):
         self.nameAlias = mc.aliasAttr(self.nameCombined,q=True)
         
     self.get(*a, **kw)
     
     #>>> Parent Stuff
     pBuffer = mc.attributeQuery(self.attr, node = self.obj.nameShort, listParent=True)
     if pBuffer is None:
         self.parent = False
     else:
         self.parent = pBuffer[0]
     self.children = mc.attributeQuery(self.attr, node = self.obj.nameShort, listChildren=True)
     if self.children is None:
         self.children = False        
     self.siblings = mc.attributeQuery(self.attr, node = self.obj.nameShort, listSiblings=True)
     if self.siblings is None:
         self.siblings = False    
     self.enum = False
     
     self.userAttrs = mc.listAttr(self.obj.nameShort, userDefined = True) or []
     
     standardFlagsBuffer = attributes.returnStandardAttrFlags(self.obj.nameShort,self.nameLong)
     standardDataBuffer = attributes.returnAttributeDataDict(self.obj.nameShort,self.nameLong)
     
     #Check connections
     self.driver = attributes.returnDriverAttribute(self.nameCombined,False)
     self.driven = attributes.returnDrivenAttribute(self.nameCombined,False)
     
     self.numeric = standardFlagsBuffer.get('numeric')
     self.dynamic = standardFlagsBuffer.get('dynamic')
         
     self.locked = standardFlagsBuffer.get('locked')
     self.keyable = standardFlagsBuffer.get('keyable')
     self.hidden = standardFlagsBuffer.get('hidden')
      
     
     if self.dynamic:
         self.readable = standardFlagsBuffer.get('readable')
         self.writable = standardFlagsBuffer.get('writable')
         self.storable = standardFlagsBuffer.get('storable')
         self.usedAsColor = standardFlagsBuffer.get('usedAsColor')   
         
     #>>> Numeric 
     if self.numeric:
         bufferDict = attributes.returnNumericAttrSettingsDict(self.obj.nameShort,self.nameLong)
         if bufferDict:
             self.maxValue = bufferDict.get('max')
             self.minValue = bufferDict.get('min')
             self.defaultValue = bufferDict.get('default')
             self.softMaxValue = bufferDict.get('softMax')
             self.softMinValue = bufferDict.get('softMin')
             self.rangeValue = bufferDict.get('range')
             self.softRangeValue = bufferDict.get('softRange')
         else:
             self.maxValue = False
             self.minValue = False
             self.defaultValue = False
             self.softMaxValue = False
             self.softMinValue = False
             self.rangeValue = False
             self.softRangeValue = False               
                        
     if self.form == 'enum':
         self.enum = standardFlagsBuffer.get('enum')
예제 #9
0
def bakeBlendShapeNode(sourceObject, blendShapeNode, baseNameToUse = False, stripPrefix = False, ignoreInbetweens = False, ignoreTargets = False):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Function for exporting an object's blendshapes

    ARGUMENTS:
    targetObject(string)
    sourceObject(string)
    blendShapeNode(string) the node to bake from
    baseName(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied
    stripPrefix(bool) - whether to strip the first '_' segment
    ignoreInbetweens(bool)
    ignoreTargets(list) - targets to ignore in the processing

    RETURNS:
    Success(bool)
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Prep
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ declare variables """
    returnList = []
    blendShapeNamesBaked = []
    blendShapeConnections = []
    currentConnections = []

    """ base name """
    if baseNameToUse == False:
        baseName = ''
    else:
        baseName = baseNameToUse + '_'


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Meat of it
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    targetDict = returnBlendShapeTargetsAndWeights(sourceObject,blendShapeNode)
    targetSets = []
    blendShapeNodeChannels = []

    for key in targetDict.keys():
        targetSetBuffer = targetDict.get(key)
        targetSets.append(targetSetBuffer)

        baseSet = targetSetBuffer[-1]
        blendShapeNodeChannels.append(baseSet[0])

    blendShapeShortNames = []

    """ first loop gets connections, breaks them and sets everything to 0 """
    for shape in blendShapeNodeChannels:
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ get the connection """
        blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer))
        print blendShapeConnections
        """break it """
        attributes.doBreakConnection(blendShapeBuffer)
        attributes.doSetAttr(blendShapeBuffer,0)


    # Bake it
    bakedGeo = bakeBlendShapes(sourceObject, sourceObject, blendShapeNode, baseNameToUse, stripPrefix, ignoreInbetweens, ignoreTargets)


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Finish out
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ restore connections """
    for shape in blendShapeNodeChannels:
        currentIndex = blendShapeNodeChannels.index(shape)
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ Restore the connection """
        if blendShapeConnections[currentIndex] != False:
            attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)

    """ group for geo """
    meshGroup = mc.group( em=True)
    if baseNameToUse != False:
        attributes.storeInfo(meshGroup,'cgmName', baseNameToUse)
    attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo')
    meshGroup = NameFactory.doNameObject(meshGroup)

    for geo in bakedGeo:
        rigging.doParentReturnName(geo,meshGroup)

    returnList.append(meshGroup)
    returnList.append(bakedGeo)

    return returnList
예제 #10
0
def bakeCombinedBlendShapeNode(sourceObject, blendShapeNode, baseNameToUse = False, directions=['left','right']):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Function for baking a series of blendshapes out from one object that have a split type

    ARGUMENTS:
    sourceObject(string)
    sourceObject(string)
    blendShapeNode(string) the node to bake from
    baseName(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied
    directions[list] = (['left','right'])

    RETURNS:
    Success(bool)
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Prep
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ declare variables """
    returnList = []
    blendShapeNamesBaked = []
    blendShapeConnections = []
    currentConnections = []
    bakedGeo = []

    """ size """
    sizeBuffer = distance.returnBoundingBoxSize(sourceObject)
    sizeX = sizeBuffer[0]
    sizeY = sizeBuffer[1]

    """ base name """
    if baseNameToUse == False:
        baseName = ''
    else:
        baseName = baseNameToUse + '_'


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Meat of it
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    blendShapeNodeChannels = search.returnBlendShapeAttributes(blendShapeNode)
    blendShapeShortNames = []

    """ first loop stores and sets everything to 0 """
    for shape in blendShapeNodeChannels:
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer))
        """break it """
        attributes.doBreakConnection(blendShapeBuffer)
        attributes.doSetAttr(blendShapeBuffer,0)

    """ Find pairs """
    blendshapePairs = lists.returnMatchedStrippedEndList(blendShapeNodeChannels,directions)

    """ first loop stores and sets everything to 0 """
    for pair in blendshapePairs:
        blendShapeBuffer = (blendShapeNode+'.'+pair[0])
        splitBuffer = pair[0].split('_')
        nameBuffer = splitBuffer[:-1]
        pairBaseName = '_'.join(nameBuffer)

        if '_' in list(pairBaseName):
            newSplitBuffer = pair[0].split('_')
            newNameBuffer = newSplitBuffer[1:]
            blendShapeShortNames.append('_'.join(newNameBuffer))
        else:
            blendShapeShortNames.append(pairBaseName)

    t=1
    pair = 0
    for i in range (len(blendshapePairs)):
        row = i//5
        if t>5:
            t=1
        """ start extracting """
        blendShapeNodeChannelsBuffer = blendshapePairs[pair]
        shape1 = blendShapeNodeChannelsBuffer[0]
        shape2 = blendShapeNodeChannelsBuffer[1]
        blendShape1Buffer = (blendShapeNode+'.'+shape1)
        blendShape2Buffer = (blendShapeNode+'.'+shape2)
        attributes.doSetAttr(blendShape1Buffer,1)
        attributes.doSetAttr(blendShape2Buffer,1)
        dupBuffer = mc.duplicate(sourceObject)


        splitBuffer = blendShapeShortNames[pair].split('_')
        if len(splitBuffer)>1:
            nameBuffer = splitBuffer[:-1]
        else:
            nameBuffer = splitBuffer
        shortName = '_'.join(nameBuffer)

        dupBuffer = mc.rename (dupBuffer,(baseName+shortName))
        """ Unlock it """
        attributes.doSetLockHideKeyableAttr(dupBuffer,False,True,True)

        mc.xform(dupBuffer,r=True,t=[((sizeX*(t+1.2))*1.5),(sizeY*row*-1.5),0])
        bakedGeo.append(dupBuffer)

        attributes.doSetAttr(blendShape1Buffer,0)
        attributes.doSetAttr(blendShape2Buffer,0)
        pair +=1
        t+=1

    """ restore connections """
    for shape in blendShapeNodeChannels:
        currentIndex = blendShapeNodeChannels.index(shape)
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ Restore the connection """
        if blendShapeConnections[currentIndex] != False:
            attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Finish out
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ group for geo """
    meshGroup = mc.group( em=True)
    attributes.storeInfo(meshGroup,'cgmName', baseNameToUse)
    attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo')
    meshGroup = NameFactory.doNameObject(meshGroup)

    for geo in bakedGeo:
        rigging.doParentReturnName(geo,meshGroup)

    returnList.append(meshGroup)
    returnList.append(bakedGeo)

    return returnList
예제 #11
0
def bakeCombinedBlendShapeNodeToTargetObject(targetObject,sourceObject, blendShapeNode, baseName = False, directions=['left','right']):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Function for baking a series of blendshapes from one object to another when you have a left/right variant

    ARGUMENTS:
    targetObject(string)
    sourceObject(string)
    blendShapeNode(string) the node to bake from
    baseName(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied
    directions[list] = (['left','right'])

    RETURNS:
    Success(bool)
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Prep
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ declare variables """
    returnList = []
    blendShapeNamesBaked = []
    blendShapeConnections = []
    currentConnections = []
    bakedGeo = []

    """ size """
    sizeBuffer = distance.returnBoundingBoxSize(targetObject)
    sizeX = sizeBuffer[0]
    sizeY = sizeBuffer[1]

    """ base name """
    if baseName == False:
        baseName = ''
    else:
        baseName = baseName + '_'

    """reference check """
    refPrefix = search.returnReferencePrefix(sourceObject)
    if refPrefix != False:
        referencePrefix = (search.returnReferencePrefix(sourceObject) + ':')
    else:
        referencePrefix = ''

    """ wrap deform object """
    wrapBuffer = wrapDeformObject(targetObject,sourceObject,True)
    targetObjectBaked = wrapBuffer[1]

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Meat of it
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    #setAttr ($wrapDeformer[0] + ".autoWeightThreshold") 1;
    """ cause maya is stupid and doesn't have a python equivalent"""
    mc.select(targetObjectBaked,r=True)
    mc.select(sourceObject,tgl=True)
    mel.eval('AddWrapInfluence')
    mc.select(cl=True)

    """
    may need to add this in later
    //reorders deformation order for proper baking of skinned mesh
    //reorderDeformers "tweak1" "face_skinCluster" $deformerGeo;
    """

    blendShapeNodeChannels = search.returnBlendShapeAttributes(blendShapeNode)
    blendShapeShortNames = []

    """ first loop stores and sets everything to 0 """
    for shape in blendShapeNodeChannels:
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer))
        """break it """
        attributes.doBreakConnection(blendShapeBuffer)
        attributes.doSetAttr(blendShapeNode,shape,0)

    """ Find pairs """
    blendshapePairs = lists.returnMatchedStrippedEndList(blendShapeNodeChannels,directions)

    """ first loop stores and sets everything to 0 """
    for pair in blendshapePairs:
        blendShapeBuffer = (blendShapeNode+'.'+pair[0])
        splitBuffer = pair[0].split('_')
        nameBuffer = splitBuffer[:-1]
        pairBaseName = '_'.join(nameBuffer)

        if '_' in list(pairBaseName):
            newSplitBuffer = pair[0].split('_')
            newNameBuffer = newSplitBuffer[1:]
            blendShapeShortNames.append('_'.join(newNameBuffer))
        else:
            blendShapeShortNames.append(pairBaseName)

    t=1
    pair = 0
    for i in range (len(blendshapePairs)):
        row = i//5
        if t>5:
            t=1
        """ start extracting """
        blendShapeNodeChannelsBuffer = blendshapePairs[pair]
        shape1 = blendShapeNodeChannelsBuffer[0]
        shape2 = blendShapeNodeChannelsBuffer[1]
        attributes.doSetAttr(blendShapeNode,shape1,1)
        attributes.doSetAttr(blendShapeNode,shape2,1)
        dupBuffer = mc.duplicate(targetObjectBaked)
        splitBuffer = blendShapeShortNames[pair].split('_')
        nameBuffer = splitBuffer[:-1]
        shortName = '_'.join(nameBuffer)

        dupBuffer = mc.rename (dupBuffer,(baseName+shortName))
        mc.xform(dupBuffer,r=True,t=[((sizeX*(t+1.2))*1.5),(sizeY*row*-1.5),0])
        bakedGeo.append(dupBuffer)

        attributes.doSetAttr(blendShapeNode,shape1,0)
        attributes.doSetAttr(blendShapeNode,shape2,0)
        pair +=1
        t+=1

    """ restore connections """
    for shape in blendShapeNodeChannels:
        currentIndex = blendShapeNodeChannels.index(shape)
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ Restore the connection """
        if blendShapeConnections[currentIndex] != False:
            attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)

    """delete the wrap"""
    mc.delete(wrapBuffer[0])

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Finish out
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ group for geo """
    meshGroup = mc.group( em=True)
    attributes.storeInfo(meshGroup,'cgmName', baseName)
    attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo')
    meshGroup = NameFactory.doNameObject(meshGroup)

    for geo in bakedGeo:
        rigging.doParentReturnName(geo,meshGroup)

    returnList.append(meshGroup)
    returnList.append(bakedGeo)

    mc.delete(targetObjectBaked)
    return returnList
예제 #12
0
def bakeBlendShapeNodeToTargetObject(targetObject,sourceObject, blendShapeNode, baseNameToUse = False, stripPrefix = False,ignoreInbetweens = False, ignoreTargets = False, transferConnections = True):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Function for baking a series of blendshapes from one object to another

    ARGUMENTS:
    targetObject(string)
    sourceObject(string)
    blendShapeNode(string) the node to bake from
    baseNameToUse(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied
    stripPrefix(bool)
    ignoreInbetweens(bool)
    ignoreTargets(list) - list of targets to ignore
    transferConnections(bool) - if True, builds a new blendshape node and transfers the connections from our base objects

    RETURNS:
    Success(bool)
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Prep
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ declare variables """
    returnList = []
    blendShapeNamesBaked = []
    blendShapeConnections = []
    currentConnections = []
    bakedGeo = []

    """ size """
    sizeBuffer = distance.returnBoundingBoxSize(targetObject)
    sizeX = sizeBuffer[0]
    sizeY = sizeBuffer[1]

    """ base name """
    if baseNameToUse == False:
        baseName = ''
    else:
        baseName = baseNameToUse + '_'

    """ wrap deform object """
    wrapBuffer = wrapDeformObject(targetObject,sourceObject,True)
    targetObjectBaked = wrapBuffer[1]

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Meat of it
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    blendShapeNodeChannels = returnBlendShapeAttributes(blendShapeNode)

    blendShapeShortNames = []
    """ first loop stores and sets everything to 0 """

    for shape in blendShapeNodeChannels:
        keepGoing = True
        if ignoreTargets != False:
            if shape in ignoreTargets:
                keepGoing = False
            else:
                keepGoing = True

        blendShapeBuffer = (blendShapeNode + '.' + shape)
        """ get the connection """
        blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer))

        if keepGoing == True:
            print ('breaking....' + blendShapeBuffer)
            """break it """
            attributes.doBreakConnection(blendShapeBuffer)
            attributes.doSetAttr(blendShapeNode,shape,0)

    # Bake it
    bakedGeo = bakeBlendShapes(sourceObject, targetObjectBaked, blendShapeNode, baseNameToUse, stripPrefix, ignoreInbetweens, ignoreTargets)


    """ restore connections """
    for shape in blendShapeNodeChannels:
        keepGoing = True
        if ignoreTargets != False:
            if shape in ignoreTargets:
                keepGoing = False
            else:
                keepGoing = True

        currentIndex = blendShapeNodeChannels.index(shape)
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ Restore the connection """
        if keepGoing == True:
            print ('connecting....' + blendShapeBuffer)
            print blendShapeConnections[currentIndex]
            if blendShapeConnections[currentIndex] != False:
                attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)


    # Need to build a new blendshape node?
    if transferConnections == True:
        # Build it
        newBlendShapeNode = buildBlendShapeNode(targetObject, bakedGeo, baseNameToUse)

        newBlendShapeChannels = returnBlendShapeAttributes(newBlendShapeNode)

        for shape in newBlendShapeChannels:
            blendShapeBuffer = (newBlendShapeNode+'.'+shape)
            currentIndex = newBlendShapeChannels.index(shape)
            if blendShapeConnections[currentIndex] != False:
                attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)

    """delete the wrap"""
    mc.delete(wrapBuffer[0])

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Finish out
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ group for geo """
    meshGroup = mc.group( em=True)
    if baseNameToUse != False:
        attributes.storeInfo(meshGroup,'cgmName', baseNameToUse)
    attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo')
    meshGroup = NameFactory.doNameObject(meshGroup)

    for geo in bakedGeo:
        rigging.doParentReturnName(geo,meshGroup)

    returnList.append(meshGroup)
    returnList.append(bakedGeo)

    mc.delete(targetObjectBaked)
    return returnList