Example #1
0
    def getFollowNode(self, target):

        retargetNodes = []

        retargetBlender = cmds.listConnections(target,
                                               type='retargetBlender')[0]

        cuIndex = fnc.getLastIndex(retargetBlender + '.input')

        retargetTransNodeCons = cmds.listConnections(retargetBlender +
                                                     '.input[%d].transMatrix' %
                                                     cuIndex)
        retargetOrientNodeCons = cmds.listConnections(
            retargetBlender + '.input[%d].orientMatrix' % cuIndex)

        if retargetTransNodeCons:
            retargetNodes.append(retargetTransNodeCons[0])
        if retargetOrientNodeCons:
            retargetNodes.append(retargetOrientNodeCons[0])

        sourceFollow = cmds.listConnections(retargetNodes[-1] +
                                            '.sourceParentMatrix',
                                            type='followMatrix')[0]
        targetFollow = cmds.listConnections(retargetNodes[-1] +
                                            '.targetParentMatrix',
                                            type='followMatrix')[0]

        return sourceFollow, targetFollow
Example #2
0
 def connectMovedDriverToFixedNode(self):
     
     targetMesh = self._targetMesh
     node = getBlendAndFixedShapeNode( targetMesh )
     
     attrs = []
     
     for driver, attr in self._driverAndAttr:
         value0 = cmds.getAttr( driver+'.'+attr )
         attrs.append( driver+'.'+attr )
     
     self._connectIndices = []
     self._connectWeights = []
     
     for attr in attrs:
         blendAndFixedShapeCons = cmds.listConnections( attr, type='blendAndFixedShape' )
         
         if not blendAndFixedShapeCons:
             targetIndex = fnc.getLastIndex( node+'.driverWeights' )+1
             cmds.connectAttr( attr, node+'.driverWeights[%d]' % targetIndex )
             self._connectIndices.append( targetIndex )
             self._connectWeights.append( value0 )
             continue
         
         if not node in blendAndFixedShapeCons:
             continue
         
         cons = cmds.listConnections( attr, p=1, c=1 )
         targetAttr = cons[1]
         
         connectedIndex = int( targetAttr.split('[')[1].replace(']','' ) )
         connectedValue = cmds.getAttr( cons[1] )
         self._connectIndices.append( connectedIndex )
         self._connectWeights.append( connectedValue )
Example #3
0
 def getRetargetNode_for( self, target ):
     
     retargetBlenderCons = cmds.listConnections( target, s=1, d=0, type='retargetBlender' )
     
     if not retargetBlenderCons:
         retargetBlender = cmds.createNode( 'retargetBlender', n= target+'_retargetBlender' )
         
         sourceName = target.replace( self._targetNS, self._sourceNS )
         retargetNode = cmds.createNode( 'retargetTransNode', n= sourceName+'_RTTrans' )
         
         self.blenderToControl( retargetBlender, target )
         
         if cmds.nodeType( target ) == 'joint':
             fnc.tryConnect( target+'.jo', retargetBlender+'.orient' )
         
         cmds.connectAttr( retargetNode+'.transMatrix', retargetBlender+'.input[0].transMatrix' )
     
     else:
         retargetBlender = retargetBlenderCons[0]
         fnc.clearArrayElement( retargetBlender+'.input' )
         cuIndex = fnc.getLastIndex( retargetBlender+'.input' )
         
         if cuIndex == -1: cuIndex = 0
         retargetTransCons = cmds.listConnections( retargetBlender+'.input[%d].transMatrix ' % cuIndex )
         
         if retargetTransCons: cuIndex += 1
         
         sourceName = target.replace( self._targetNS, self._sourceNS )
         retargetNode = cmds.createNode( 'retargetTransNode', n= sourceName+'_RTTrans' )
         
         cmds.connectAttr( retargetNode+'.transMatrix', retargetBlender+'.input[%d].transMatrix' % cuIndex )
     
     return retargetNode
Example #4
0
    def doIt( self ):
        
        targetCtls = cmds.ls( topInfo.targetNS+'*_CTL', tr=1 )
        
        for ctl in targetCtls:
            originName = ctl.replace( topInfo.targetNS, '' )
            
            retargetBlenderCons = cmds.listConnections( ctl, type='retargetBlender', s=1, d=0 )

            if retargetBlenderCons:
                retargetBlender = retargetBlenderCons[0]
                
                fnc.clearArrayElement( retargetBlender+'.input' )
                inputLen = fnc.getLastIndex( retargetBlender+'.input' )+1
                
                for i in range( inputLen ):
                    RTTrans = cmds.listConnections( retargetBlender+'.input[%d].transMatrix' % i )
                    if not RTTrans: continue
                    
                    RTTrans = RTTrans[0].split( '_RTTrans' )[0]
                    
                    RTNamespace = RTTrans.replace( originName, '' )
                    
                    if RTNamespace != topInfo.sourceNS: continue
                    
                    if not cmds.isConnected( self._timeControl+'.outWeight', retargetBlender+'.input[%d].weight' % i ):
                        cmds.connectAttr( self._timeControl+'.outWeight', retargetBlender+'.input[%d].weight' % i, f=1 )
            
            udAttrBlenderCons = cmds.listConnections( ctl, type='udAttrBlender', s=1, d=0 )

            if udAttrBlenderCons:
                udAttrBlender = udAttrBlenderCons[0]
                
                fnc.clearArrayElement( udAttrBlender+'.input' )
                inputLen = fnc.getLastIndex( udAttrBlender+'.input' )+1
                
                for i in range( inputLen ):
                    outputNodes = cmds.listConnections( udAttrBlender+'.input[%d].udAttr' % i, s=1, d=0 )
                    
                    if not outputNodes: continue
                    
                    if outputNodes[0].find( topInfo.sourceNS.replace( 'DGTR_','') ) == 0:     
                        if not cmds.isConnected( self._timeControl+'.outWeight', udAttrBlender+'.input[%d].weight' % i ):
                            cmds.connectAttr( self._timeControl+'.outWeight', udAttrBlender+'.input[%d].weight' % i, f=1 )
Example #5
0
    def setGroup(self, targetObjs, surfGrp, setName):

        if not targetObjs:
            cmds.warning("Target surface has no curve")
            return None
        setObj = cmds.sets(targetObjs)
        setObj = cmds.rename(setObj, setName)

        self._setNames.append(setObj)

        fnc.clearArrayElement(surfGrp + '.sets')
        cuIndex = fnc.getLastIndex(surfGrp + '.sets') + 1

        cmds.connectAttr(setObj + '.message', surfGrp + '.sets[%d]' % cuIndex)
Example #6
0
   def setGroup(self, targetObjs, surfGrp, setName ):
 
       if not targetObjs:
           cmds.warning( "Target surface has no curve" ) 
           return None
       setObj = cmds.sets( targetObjs )
       setObj = cmds.rename( setObj, setName )
       
       self._setNames.append( setObj )
       
       fnc.clearArrayElement( surfGrp+'.sets' )
       cuIndex = fnc.getLastIndex( surfGrp+'.sets' )+1
       
       cmds.connectAttr( setObj+'.message', surfGrp+'.sets[%d]' % cuIndex )
Example #7
0
 def __init__(self):
     
     TopInfo.__init__( self )
     
     self._source = self._target.replace( self._targetNS, self._sourceNS )
     
     udAttrBlenderCons = cmds.listConnections( self._target, s=1, d=0, type='udAttrBlender' )
     
     if udAttrBlenderCons:
         self._udAttrNode = udAttrBlenderCons[0]
         fnc.clearArrayElement( self._udAttrNode+'.input' )
         self._cuIndex    = fnc.getLastIndex( self._udAttrNode+'.input' )+1
     else:
         self._udAttrNode = cmds.createNode( 'udAttrBlender', n= self._target+'_udAttrBl' )
         self._cuIndex    = 0
Example #8
0
 def connectMesh( self ):
     
     targetMesh = self._targetMesh
     targetShape = cmds.listRelatives( targetMesh, s=1 )[0]
     print "%s exists : " % self._editMesh, cmds.objExists( self._editMesh )
     editMeshShape = cmds.listRelatives( self._editMesh, s=1 )[0]
     skinNode = self.getSkinCluster( targetShape )
     if not skinNode: return None
     
     origShape = fnc.getOrigShape( targetShape )
     
     inverseMesh = cmds.createNode( 'mesh' )
     cmds.connectAttr( origShape+'.outMesh', inverseMesh+'.inMesh' )
     
     inverseSkinNode = cmds.deformer( inverseMesh, type='inverseSkinCluster' )[0]
     
     cmds.connectAttr( targetMesh+'.wm', inverseSkinNode+'.geomMatrix' )
     cmds.connectAttr( editMeshShape+'.outMesh', inverseSkinNode+'.inMesh' )
     cmds.connectAttr( skinNode+'.message', inverseSkinNode+'.targetSkinCluster' )
     
     cmds.disconnectAttr( self._editMesh+'.message', targetMesh+'.editMesh' )
     
     node = getBlendAndFixedShapeNode( targetMesh )
     
     connectIndex = fnc.getLastIndex( node+'.blendMeshInfos' )+1
     
     inverseMeshObj = cmds.listRelatives( inverseMesh, p=1 )[0]
     keepEditMeshName = self._editMesh
     self._editMesh = cmds.rename( self._editMesh, self._editMesh+'_tempEditMesh' )
     inverseMeshObj = cmds.rename( inverseMeshObj, keepEditMeshName )
     inverseMesh = cmds.listRelatives( inverseMeshObj, s=1 )[0]
     cmds.assignBlendMeshInfo( inverseMesh, node )
     
     for i in range( len( self._connectIndices ) ):
         index = self._connectIndices[i]
         value = self._connectWeights[i]
         cmds.setAttr( node+'.blendMeshInfos[%d].targetWeights[%d]' %( connectIndex, index ), value )
     
     cmds.setAttr( self._editMesh+'.v', 0 )
     cmds.setAttr( targetMesh+'.v', 1 )
     
     self.addMatrixInfo( node, skinNode, connectIndex )
     
     self._inverseMesh = inverseMeshObj
     self._assignIndex = connectIndex
     self._node  = node
Example #9
0
    def getRetargetNode_for(self, target):

        retargetBlenderCons = cmds.listConnections(target,
                                                   s=1,
                                                   d=0,
                                                   type='retargetBlender')

        if not retargetBlenderCons:
            retargetBlender = cmds.createNode('retargetBlender',
                                              n=target + '_retargetBlender')

            self.blenderToControl(retargetBlender, target)

            sourceName = target.replace(self._targetNS, self._sourceNS)
            retargetNode = cmds.createNode('retargetOrientNode',
                                           n=sourceName + '_RTOrient')

            if cmds.nodeType(target) == 'joint':
                cmds.connectAttr(target + '.jo', retargetBlender + '.orient')

            cmds.connectAttr(retargetNode + '.orientMatrix',
                             retargetBlender + '.input[0].orientMatrix')

        else:
            retargetBlender = retargetBlenderCons[0]
            fnc.clearArrayElement(retargetBlender + '.input')
            cuIndex = fnc.getLastIndex(retargetBlender + '.input')

            if cuIndex < 0: cuIndex = 0

            retargetOrientCons = cmds.listConnections(
                retargetBlender + '.input[%d].orientMatrix ' % cuIndex)

            if retargetOrientCons: cuIndex += 1

            sourceName = target.replace(self._targetNS, self._sourceNS)
            retargetNode = cmds.createNode('retargetOrientNode',
                                           n=sourceName + '_RTOrient')

            cmds.connectAttr(
                retargetNode + '.orientMatrix',
                retargetBlender + '.input[%d].orientMatrix' % cuIndex)

        return retargetNode
Example #10
0
    def __init__(self):

        TopInfo.__init__(self)

        self._source = self._target.replace(self._targetNS, self._sourceNS)

        udAttrBlenderCons = cmds.listConnections(self._target,
                                                 s=1,
                                                 d=0,
                                                 type='udAttrBlender')

        if udAttrBlenderCons:
            self._udAttrNode = udAttrBlenderCons[0]
            fnc.clearArrayElement(self._udAttrNode + '.input')
            self._cuIndex = fnc.getLastIndex(self._udAttrNode + '.input') + 1
        else:
            self._udAttrNode = cmds.createNode('udAttrBlender',
                                               n=self._target + '_udAttrBl')
            self._cuIndex = 0
Example #11
0
 def getFollowNode(self, target ):
     
     retargetNodes = []
     
     retargetBlender = cmds.listConnections( target, type='retargetBlender' )[0]
     
     cuIndex = fnc.getLastIndex( retargetBlender+'.input' )
     
     retargetTransNodeCons = cmds.listConnections( retargetBlender+'.input[%d].transMatrix' % cuIndex )
     retargetOrientNodeCons = cmds.listConnections( retargetBlender+'.input[%d].orientMatrix' % cuIndex )
     
     if retargetTransNodeCons:
         retargetNodes.append( retargetTransNodeCons[0] )
     if retargetOrientNodeCons:
         retargetNodes.append( retargetOrientNodeCons[0] )
     
     sourceFollow = cmds.listConnections( retargetNodes[-1]+'.sourceParentMatrix', type='followMatrix' )[0]
     targetFollow = cmds.listConnections( retargetNodes[-1]+'.targetParentMatrix', type='followMatrix' )[0]
     
     return sourceFollow, targetFollow
Example #12
0
    def __init__(self):

        TopInfo.__init__(self)

        origName = self._target.replace(self._targetNS, '')

        distObjInfos = distObjInfo.getDistObjByName(origName)

        if distObjInfos:
            upperObj, lowerObj, part = distObjInfos

            worldCtl = self._targetNS + 'World_CTL'
            worldShape = cmds.listRelatives(worldCtl, s=1)[0]

            if not cmds.attributeQuery(part, node=worldShape, ex=1):
                msgAttr = om.MFnMessageAttribute()
                attr = msgAttr.create(part, part)
                msgAttr.setArray(True)
                selList = om.MSelectionList()
                selList.add(worldShape)
                mObj = om.MObject()
                selList.getDependNode(0, mObj)
                fnNode = om.MFnDependencyNode(mObj)
                fnNode.addAttribute(attr)

            fnc.clearArrayElement(worldShape + '.%s' % part)
            cons = cmds.listConnections(worldShape + '.%s' % part)

            distNodeExist = False

            if cons:
                for con in cons:
                    if con.find(self._sourceNS) != -1:
                        self._name = con
                        distNodeExist = True
                        break

            if not distNodeExist:
                sUpperDist = cmds.createNode('distanceBetween',
                                             n=part + '_sUpperDist')
                sLowerDist = cmds.createNode('distanceBetween',
                                             n=part + '_sLowerDist')
                tUpperDist = cmds.createNode('distanceBetween',
                                             n=part + '_tUpperDist')
                tLowerDist = cmds.createNode('distanceBetween',
                                             n=part + '_tLowerDist')

                sDistAll = cmds.createNode('addDoubleLinear',
                                           n=part + '_sDistAll')
                tDistAll = cmds.createNode('addDoubleLinear',
                                           n=part + '_tDistAll')

                distRateNode = cmds.createNode('multiplyDivide',
                                               n=self._sourceNS + part +
                                               '_distRate')
                cmds.setAttr(distRateNode + '.op', 2)

                cmds.connectAttr(self._sourceNS + upperObj + '.t',
                                 sUpperDist + '.point1')
                cmds.connectAttr(self._sourceNS + lowerObj + '.t',
                                 sLowerDist + '.point1')
                cmds.connectAttr(self._targetNS + upperObj + '.t',
                                 tUpperDist + '.point1')
                cmds.connectAttr(self._targetNS + lowerObj + '.t',
                                 tLowerDist + '.point1')

                cmds.connectAttr(sUpperDist + '.distance',
                                 sDistAll + '.input1')
                cmds.connectAttr(sLowerDist + '.distance',
                                 sDistAll + '.input2')

                cmds.connectAttr(tUpperDist + '.distance',
                                 tDistAll + '.input1')
                cmds.connectAttr(tLowerDist + '.distance',
                                 tDistAll + '.input2')

                cmds.connectAttr(sDistAll + '.output',
                                 distRateNode + '.input2X')
                cmds.connectAttr(tDistAll + '.output',
                                 distRateNode + '.input1X')

                connectIndex = fnc.getLastIndex(worldShape + '.%s' % part) + 1
                cmds.connectAttr(distRateNode + '.message',
                                 worldShape + '.%s[%d]' % (part, connectIndex))

                self._name = distRateNode
        else:
            self._name = None
Example #13
0
    def __init__( self ):

        TopInfo.__init__( self )

        origName = self._target.replace( self._targetNS, '' )

        distObjInfos = distObjInfo.getDistObjByName( origName )

        if distObjInfos:
            upperObj, lowerObj, part = distObjInfos

            worldCtl = self._targetNS+'World_CTL'
            worldShape = cmds.listRelatives( worldCtl, s=1 )[0]

            if not cmds.attributeQuery( part, node=worldShape, ex=1 ):
                msgAttr = om.MFnMessageAttribute()
                attr = msgAttr.create( part, part )
                msgAttr.setArray( True )
                selList = om.MSelectionList()
                selList.add( worldShape )
                mObj = om.MObject()
                selList.getDependNode( 0,mObj )
                fnNode = om.MFnDependencyNode( mObj )
                fnNode.addAttribute( attr )
            
            fnc.clearArrayElement( worldShape+'.%s' % part )
            cons = cmds.listConnections( worldShape+'.%s' % part )
            
            distNodeExist = False
            
            if cons:
                for con in cons:
                    if con.find( self._sourceNS ) != -1:
                        self._name = con
                        distNodeExist = True
                        break
            
            if not distNodeExist:
                sUpperDist = cmds.createNode( 'distanceBetween', n= part+'_sUpperDist' )
                sLowerDist = cmds.createNode( 'distanceBetween', n= part+'_sLowerDist' )
                tUpperDist = cmds.createNode( 'distanceBetween', n= part+'_tUpperDist' )
                tLowerDist = cmds.createNode( 'distanceBetween', n= part+'_tLowerDist' )
                
                sDistAll = cmds.createNode( 'addDoubleLinear', n=part+'_sDistAll' )
                tDistAll = cmds.createNode( 'addDoubleLinear', n=part+'_tDistAll' )
                
                distRateNode = cmds.createNode( 'multiplyDivide', n=self._sourceNS+part+'_distRate' )
                cmds.setAttr( distRateNode+'.op', 2 )
                
                cmds.connectAttr( self._sourceNS+upperObj+'.t', sUpperDist+'.point1' )
                cmds.connectAttr( self._sourceNS+lowerObj+'.t', sLowerDist+'.point1' )
                cmds.connectAttr( self._targetNS+upperObj+'.t', tUpperDist+'.point1' )
                cmds.connectAttr( self._targetNS+lowerObj+'.t', tLowerDist+'.point1' )
                
                cmds.connectAttr( sUpperDist+'.distance', sDistAll+'.input1' )
                cmds.connectAttr( sLowerDist+'.distance', sDistAll+'.input2' )
            
                cmds.connectAttr( tUpperDist+'.distance', tDistAll+'.input1' )
                cmds.connectAttr( tLowerDist+'.distance', tDistAll+'.input2' )
            
                cmds.connectAttr( sDistAll+'.output', distRateNode+'.input2X' )
                cmds.connectAttr( tDistAll+'.output', distRateNode+'.input1X' )
                
                connectIndex = fnc.getLastIndex( worldShape+'.%s' % part )+1
                cmds.connectAttr( distRateNode+'.message', worldShape+'.%s[%d]' % (part,connectIndex) )
                
                self._name = distRateNode
        else:
            self._name = None