Example #1
0
def copyBitSettings():
    '''
    Copies the bit shape settings (OpenGL stuff) from the second object to the
    first (in selection order).
    '''
    selList = cmds.ls( selection=True, long=True )
    depFn = OpenMaya.MFnDependencyNode()
    
    if len(selList) == 2:
        # First object is target.
        targetShape = cmds.listRelatives( selList[0], shapes=True, fullPath=True )[0]
        targetShapeMObj = NodeUtility.getDependNode( targetShape )
        depFn.setObject( targetShapeMObj )
        targetShapeType = depFn.typeName()
        
        # Second object is source.
        sourceShape = cmds.listRelatives( selList[1], shapes=True, fullPath=True )[0]
        sourceShapeMObj = NodeUtility.getDependNode( sourceShape )
        depFn.setObject( sourceShapeMObj )
        sourceShapeType = depFn.typeName()
        
        if targetShapeType == sourceShapeType:        
            # The types match. Do the copy of attribute settings.
            for attr in cmds.listAttr( sourceShape, multi=True, keyable=True ):
                # Get the plugs.
                sourcePlug = NodeUtility.getPlug( sourceShape, attr )
                targetPlug = NodeUtility.getPlug( targetShape, attr )
                
                # Get the source plug value.
                sourcePlugValue = NodeUtility.getPlugValue( sourcePlug )
                
                # Set the target's plug value.
                NodeUtility.setPlugValue( targetPlug, sourcePlugValue )
        else:
            raise ValueError( '{0} and {1} do not match.'.format( selList[0], selList[1] ) )
 def setPriorities( self ):
     '''
     Applies the user adjusted priorities to all the modules of a character.
     '''
     for index in xrange( self.dropList.count() ):
         moduleName = self.dropList.item( index ).text()
         moduleComponent = self.modDict[moduleName][0]
         priorityPlug = NodeUtility.getPlug( moduleComponent, 'buildPriority' )
         NodeUtility.setPlugValue( priorityPlug, index )
         
     self.close()
Example #3
0
 def setAttribute( self, inPlugName, inPlugValue, inNodeName, inLock=False ):
     #print inPlugName, inPlugValue, inNodeName
     #print type( inPlugValue )
     '''
     if isinstance( inPlugValue, unicode ):
         # This is a unicode string. Likely a node name.
         print 'UNICODE'
         plugValue = inPlugValue
     elif isinstance( inPlugValue, str ):
         print 'STRING'
         plugValue = inPlugValue
     else:
         # This is likely coming from a QT object.
         print 'PASS'
         plugValue = inPlugValue.text()
     '''
     plug = NodeUtility.getPlug( inNodeName, inPlugName )
     NodeUtility.setPlugValue( plug, inPlugValue )
     cmds.setAttr( '{0}.{1}'.format( inNodeName, inPlugName ), lock=inLock )
Example #4
0
def storeControlTransforms( sourceObj, targetObj ):
    '''
    Store control transform data.
    
    @param sourceObj: String. Name of object to pull data from.
    @param targetObj: String. Name of object to store data on.
    '''    
    sourceMatrix = TransformUtility.getMatrix( sourceObj, 'matrix' )
    
    # Store the position
    targetPosPlug = NodeUtility.getPlug( targetObj, 'controlPosition' )
    sourceTranslation = TransformUtility.getMatrixTranslation( sourceMatrix, OpenMaya.MSpace.kTransform )
    pos = [ sourceTranslation.x, sourceTranslation.y, sourceTranslation.z ]
    NodeUtility.setPlugValue( targetPosPlug, pos )
    
    # Store the rotation
    targetRotPlug = NodeUtility.getPlug( targetObj, 'controlRotation' )
    sourceRotation = TransformUtility.getMatrixRotation( sourceMatrix, 'euler' )
    #rot = [ degrees(angle) for angle in (sourceRotation.x, sourceRotation.y, sourceRotation.z) ]
    rot = [ sourceRotation.x, sourceRotation.y, sourceRotation.z ]
    NodeUtility.setPlugValue( targetRotPlug, rot )
    
    # Store the scale.
    targetSclPlug = NodeUtility.getPlug( targetObj, 'controlScale' )
    sourceScale = TransformUtility.getMatrixScale( sourceMatrix, OpenMaya.MSpace.kTransform )
    scl = [ sourceScale.x, sourceScale.y, sourceScale.z ]
    NodeUtility.setPlugValue( targetSclPlug, scl )
Example #5
0
 def redoIt( self ):
     ''' Do the actual work of the command. '''
     # Perform the operations enqueued within our reference to MDagModifier. This effectively
     # creates the DAG nodes specified using self.dagModifier.createNode(). Node creation is 
     # done in doIt().
     self.MDagMod.doIt()
     
     # Apply the user defined arguments to the controller node.
     self.MFnDagNode.setObject( self.controllerNode )
     
     # Set the name.
     self.MFnDagNode.setName( self.name )
     # Get the aim node's shape.
     self.MFnDepNode.setObject( self.MFnDagNode.child( 0 ) )
     print self.MFnDepNode.name()
     
     # Update plugs with values, if any, from the command.
     print self.MFnDepNode.findPlug( 'color' )
     
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'color' ), self.color )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'localPosition' ), self.position )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'rotate' ), self.rotation )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'transparency' ), self.transparency )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'backAlpha' ), self.backAlpha )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'lineWidth' ), self.lineWidth )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'width' ), self.width )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'height' ), self.height )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'depth' ), self.depth )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'drawType' ), self.drawType )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'topFrontRight' ), self.opTFR )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'topFrontLeft' ), self.opTFL )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'topBackRight' ), self.opTBR )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'topBackLeft' ), self.opTBL )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'botFrontRight' ), self.opBFR )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'botFrontLeft' ), self.opBFL )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'botBackRight' ), self.opBBR )
     NodeUtility.setPlugValue( self.MFnDepNode.findPlug( 'botBackLeft' ), self.opBBL )
         
     self.MDGMod.doIt()
Example #6
0
def applyXMLtoControl():
    # Get the selected object. Only takes one object.
    sel = cmds.ls( selection=True, dagObjects=True, allPaths=True, transforms=True )
    
    # Get the XML file.
    attrList = readControlXML()
    
    # Grab the shape node.
    transNode = NodeUtility.getDagPath( sel[0] )
    MFnDepNode = OpenMaya.MFnDependencyNode()
    MFnDepNode.setObject( transNode.child( 0 ) )
    
    if MFnDepNode.typeName() == 'ControlBox':        
        # Update plugs with values, if any, from the command.
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'color' ),
                                  [ float( attrList[ 'color' ][ 'value' ][0] ), float( attrList[ 'color' ][ 'value' ][1] ), float( attrList[ 'color' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'localPosition' ),
                                  [ float( attrList[ 'localPosition' ][ 'value' ][0] ), float( attrList[ 'localPosition' ][ 'value' ][1] ), float( attrList[ 'localPosition' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'rotate' ),
                                  [ float( attrList[ 'rotate' ][ 'value' ][0] ), float( attrList[ 'rotate' ][ 'value' ][1] ), float( attrList[ 'rotate' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'transparency' ), float( attrList[ 'transparency' ][ 'value' ] ) )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'backAlpha' ), float( attrList[ 'backAlpha' ][ 'value' ] ) )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'lineWidth' ), int( attrList[ 'lineWidth' ][ 'value' ] ) )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'width' ), float( attrList[ 'width' ][ 'value' ] ) )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'height' ), float( attrList[ 'height' ][ 'value' ] ) )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'depth' ), float( attrList[ 'depth' ][ 'value' ] ) )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'drawType' ), int( attrList[ 'drawType' ][ 'value' ] ) )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'topFrontRight' ),
                                  [ float( attrList[ 'topFrontRight' ][ 'value' ][0] ), float( attrList[ 'topFrontRight' ][ 'value' ][1] ), float( attrList[ 'topFrontRight' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'topFrontLeft' ),
                                  [ float( attrList[ 'topFrontLeft' ][ 'value' ][0] ), float( attrList[ 'topFrontLeft' ][ 'value' ][1] ), float( attrList[ 'topFrontLeft' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'topBackRight' ),
                                  [ float( attrList[ 'topBackRight' ][ 'value' ][0] ), float( attrList[ 'topBackRight' ][ 'value' ][1] ), float( attrList[ 'topBackRight' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'topBackLeft' ),
                                  [ float( attrList[ 'topBackLeft' ][ 'value' ][0] ), float( attrList[ 'topBackLeft' ][ 'value' ][1] ), float( attrList[ 'topBackLeft' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'botFrontRight' ),
                                  [ float( attrList[ 'botFrontRight' ][ 'value' ][0] ), float( attrList[ 'botFrontRight' ][ 'value' ][1] ), float( attrList[ 'botFrontRight' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'botFrontLeft' ),
                                  [ float( attrList[ 'botFrontLeft' ][ 'value' ][0] ), float( attrList[ 'botFrontLeft' ][ 'value' ][1] ), float( attrList[ 'botFrontLeft' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'botBackRight' ),
                                  [ float( attrList[ 'botBackRight' ][ 'value' ][0] ), float( attrList[ 'botBackRight' ][ 'value' ][1] ), float( attrList[ 'botBackRight' ][ 'value' ][2] ) ] )
        NodeUtility.setPlugValue( MFnDepNode.findPlug( 'botBackLeft' ),
                                  [ float( attrList[ 'botBackLeft' ][ 'value' ][0] ), float( attrList[ 'botBackLeft' ][ 'value' ][1] ), float( attrList[ 'botBackLeft' ][ 'value' ][2] ) ] )
Example #7
0
def applyDeformerMesh():
    '''
    Applies the deformer mesh to the OpenGL values of the active controller.
    '''
    selList = OpenMaya.MSelectionList()
    OpenMaya.MGlobal.getActiveSelectionList( selList )
    if selList.length() is 1:
        control = OpenMaya.MObject()
        selList.getDependNode( 0, control )    
        controlDagNode = OpenMaya.MFnDagNode( control )
        controlShape = controlDagNode.child( 0 )
        controlShapeDep = OpenMaya.MFnDependencyNode( controlShape )
        locCheck = False
        meshCheck = False
        for c in xrange( controlDagNode.childCount() ):
            child = controlDagNode.child( c )
            if child.apiType() == OpenMaya.MFn.kPluginLocatorNode:
                locCheck = True
            elif child.apiType() == OpenMaya.MFn.kMesh:
                # Set the check to True.
                meshCheck = True
                # Grab the mesh.
                deformMesh = OpenMaya.MFnMesh( child )
                
                # Grab the vertices of the mesh.
                vertexCount = OpenMaya.MIntArray()    
                vertexList = OpenMaya.MIntArray()
                vertexArray = OpenMaya.MFloatPointArray()
                deformMesh.getVertices( vertexCount, vertexList )
                deformMesh.getPoints( vertexArray, OpenMaya.MSpace.kObject )
                
                # Set the OpenGL points.
                glPosition = NodeUtility.getPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'localPosition' ) )
                glWidth = NodeUtility.getPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'width' ) )
                glHeight = NodeUtility.getPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'height' ) )
                glDepth = NodeUtility.getPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'depth' ) )
                NodeUtility.setPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'botBackRight' ), [ (vertexArray[0].x-(-glWidth/2))-glPosition[0],(vertexArray[0].y-(-glHeight/2))-glPosition[1],(vertexArray[0].z-(-glDepth/2))-glPosition[2] ]  )
                NodeUtility.setPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'botBackLeft' ), [ (vertexArray[1].x-(glWidth/2))-glPosition[0],(vertexArray[1].y-(-glHeight/2))-glPosition[1],(vertexArray[1].z-(-glDepth/2))-glPosition[2] ] )
                NodeUtility.setPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'botFrontLeft' ), [ (vertexArray[2].x-(glWidth/2))-glPosition[0],(vertexArray[2].y-(-glHeight/2))-glPosition[1],(vertexArray[2].z-(glDepth/2))-glPosition[2] ] )
                NodeUtility.setPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'botFrontRight' ), [ (vertexArray[3].x-(-glWidth/2))-glPosition[0],(vertexArray[3].y-(-glHeight/2))-glPosition[1],(vertexArray[3].z-(glDepth/2))-glPosition[2] ] )
                NodeUtility.setPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'topBackRight' ), [ (vertexArray[4].x-(-glWidth/2))-glPosition[0],(vertexArray[4].y-(glHeight/2))-glPosition[1],(vertexArray[4].z-(-glDepth/2))-glPosition[2] ] )
                NodeUtility.setPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'topFrontRight' ), [ (vertexArray[5].x-(-glWidth/2))-glPosition[0],(vertexArray[5].y-(glHeight/2))-glPosition[1],(vertexArray[5].z-(glDepth/2))-glPosition[2] ] )
                NodeUtility.setPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'topFrontLeft' ), [ (vertexArray[6].x-(glWidth/2))-glPosition[0],(vertexArray[6].y-(glHeight/2))-glPosition[1],(vertexArray[6].z-(glDepth/2))-glPosition[2] ] )
                NodeUtility.setPlugValue( NodeUtility.getPlug( controlShapeDep.name(), 'topBackLeft' ), [ (vertexArray[7].x-(glWidth/2))-glPosition[0],(vertexArray[7].y-(glHeight/2))-glPosition[1],(vertexArray[7].z-(-glDepth/2))-glPosition[2] ] )
                
                # Clean up by deleting the mesh.
                MDGMod = OpenMaya.MDGModifier()
                MDGMod.deleteNode( child )
                MDGMod.doIt()
        if locCheck is False:
            sys.stderr.write( 'applyDeformerMesh: This is the wrong type of object. Needs to be an OpenGl Controller.' )
        if meshCheck is False:
            sys.stderr.write( 'applyDeformerMesh: This control object doesn\'t have a deformer mesh.' )
    elif selList.length() > 1:
        sys.stderr.write( 'applyDeformerMesh: To many things selected. Only select one controller.' )
    else:
        sys.stderr.write( 'applyDeformerMesh: Nothing selected.' )