Example #1
0
def createCompoundCurve(inCurves):
    """
    Merges all the controls into one transform node.
    
    @param inCurves: List of Strings. Names of curves to combine under one transform node.
                        The first curve in the list is considered the parent of all the others.
    @return: MObject. Compound curve transform node.
    """
    # List for creating the compound.
    compoundList = []

    # Get the nurbs curves of all curves in the list.
    for index in range(1, len(inCurves)):
        curve = NodeUtility.getDagPath(inCurves[index])
        for child in xrange(curve.childCount()):
            nurb = curve.child(child)
            nurbDagPath = OpenMaya.MDagPath.getAPathTo(nurb)
            if nurb.apiType() == OpenMaya.MFn.kNurbsCurve:
                compoundList.append(nurbDagPath.fullPathName())

    # Add the transform of the parent curve. This is the first curve passed into
    # the function.
    parent = NodeUtility.getDagPath(inCurves[0])
    compoundList.append(parent.fullPathName())

    # Now parent the shapes to the first curve's transform node.
    cmds.parent(compoundList, shape=True, relative=True)

    # Delete the remaining transform nodes of the other curves.
    for index in range(1, len(inCurves)):
        cmds.delete(inCurves[index])

    # Returns a MObject.
    return NodeUtility.getDependNode(parent.fullPathName())
Example #2
0
def getComponents( inObj ):
    '''
    Creates the components GUI.
    '''    
    if inObj is not None:
        components_list = NodeUtility.getFrameBitSettings( inObj )
    else:
        components_list = None
    
    # If the newly selected bit has components then update the UI to show them.
    # Check to see if any of the components are connected to a meta node.
    # We do this check so that we don't create a bunch of UI elements
    # unnecessarily.
    if components_list is not None and metaNodeCheck( inObj, components_list ):            
        # Loop through each component on the bit.
        components_class_list = {}
        for node_name in components_list:
            # Check to see if the component is connected to a meta node.
            metaNode = NodeUtility.getNodeAttrDestination( inObj, node_name )
            if metaNode:
                # It has a meta node.
                # Get the meta node properties. This returns a dict.
                meta_properties = NodeUtility.getFrameBitSettings( metaNode[0] )
                component_class = meta_properties[ 'classType' ]
                # test hack!!!
                components_class_list[ node_name ] = component_class
        return components_class_list
    else:
        return None
Example #3
0
def addComponentToObject( inClassType, **kwargs ):    
    if kwargs.has_key('inObject'):
        targetObj = kwargs['inObject']
        print 'targetObj: {0}'.format( targetObj )
        del kwargs['inObject']
        prevSel = None
    else:
        selList = cmds.ls( selection=True, long=True )
        if len( selList ) is 1:
            targetObj = selList[0]
            prevSel = selList[0]
    
    if targetObj is not None:
        component_class = str_to_class( inClassType )
        newNode = component_class.createCompNode( inClassType, **kwargs )
        
        # Add the component attribute to the object.
        NodeUtility.addPlug( targetObj, newNode.name(), 'attributeType', 'message' )
        nodePlug = '{0}.parentName'.format( newNode.name() )
        objectPlug = '{0}.{1}'.format( targetObj, newNode.name() )
        NodeUtility.connectPlugs( objectPlug, nodePlug )
        if prevSel is not None:
            cmds.select( prevSel )
            
        return newNode
Example #4
0
 def requiredAttributes( self, *args, **kwargs ):
     NodeUtility.addPlug( self.newNode, 'parentName', 'attributeType', 'message' )
     #cmds.addAttr( newNode, longName='parentName', attributeType='message', storable=True )
     #self.setAttribute( cls(), 'parentName', self.newNode, inNodeName=self.newNode )
     self.setAttribute( 'parentName', self.newNode, self.newNode )
     
     NodeUtility.addPlug( self.newNode, 'classType', 'dataType', 'string' )
     #cls( self.newNode ).classType = [ self.newNode, self.nodeType, True ]
     self.classType = [ self.newNode, self.nodeType, True ]
Example #5
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 )
 def connectModules(self):
     '''
     Connects a module to the character component.
     '''
     # Get modules selected from disList
     selList = self.disList.selectedItems()
     for module in selList:
         NodeUtility.connectNodes( self.charNode, 'modules', self.disMods[module.text()], 'characterRoot' )
         
     # Refresh the lists.
     self.updateLists()
 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 #8
0
 def __init__( self, nodeName, parent=None ):
     super( componentWidget, self ).__init__( parent )
     self.parent = parent
     
     def on_context_menu( point, inNodeName ):
         popMenu = QtGui.QMenu()
         deleteAction = QtGui.QAction( 'Delete Component', popMenu, triggered=lambda a=inNodeName:self.deleteComponentFromObject( a ) )
         popMenu.addAction( deleteAction )
         
         popMenu.exec_( self.componentLabel.mapToGlobal( point ) )
         
     # Setup layout.
     verticalLayout = QtGui.QVBoxLayout()
     verticalLayout.setContentsMargins( 0,0,0,0 )
     verticalLayout.setSpacing( 0 )
     verticalLayout.setAlignment( QtCore.Qt.AlignTop )
     
     # Label for component
     componentLabel = QTWidgets.basicLabel( nodeName, 'bold', 10, 'black', '6E9094', inIndent=20 )
     componentLabel.setMinimumHeight( 18 )    
     componentLabel.setContextMenuPolicy( QtCore.Qt.CustomContextMenu )
     componentLabel.customContextMenuRequested.connect( lambda point, nodeName=nodeName:on_context_menu( point, nodeName ) )
     
     # Properties
     propertyStack = QtGui.QVBoxLayout()
     
     propertyFrame = QTWidgets.basicFrame()
     propertyFrame.setMinimumHeight( 40 )
     propertyFrame.setMaximumHeight( 40 )
     
     # Add string edit property
     modulePlug = NodeUtility.getPlug( nodeName, 'moduleName' )
     moduleValue = NodeUtility.getPlugValue( modulePlug )
     moduleTextLayout = QTWidgets.stringProperty( 'Module Name', moduleValue )
     
     '''
     ADD EDIT FIELDS FOR PRIORITY AND CHARACTER ROOT!!!!!!!!!
     '''
     
     # Add everything to the vertical layout.
     propertyStack.addLayout( moduleTextLayout )        
     propertyFrame.setLayout( propertyStack )
     
     verticalLayout.addWidget( componentLabel )
     verticalLayout.addWidget( propertyFrame )
     
     # Connections
     moduleTextBox = propertyFrame.findChild( QtGui.QLineEdit, 'Module Name' )
     moduleTextBox.editingFinished.connect( lambda inPlugName='moduleName', inQTType='QLineEdit', inPlugValue=moduleTextBox, inNodeName=nodeName
                                            :ModuleRootComponent( inNodeName ).setComponentAttributeFromQT( inPlugName, inQTType, inPlugValue, inNodeName ) )
     
     #return mainWidget
     self.setLayout( verticalLayout )
Example #9
0
 def addComponentToObject( self, inClassType ):
     selList = cmds.ls( selection=True, long=True )
     if len( selList ) is 1:
         prevSel = selList[0]
         component_class = Components.str_to_class( inClassType )
         newNode = component_class.createCompNode( inClassType )
         
         # Add the component attribute to the object.
         FrameUtility.addPlug( selList[0], newNode.name(), 'attributeType', 'message' )
         nodePlug = '{0}.parentName'.format( newNode.name() )
         objectPlug = '{0}.{1}'.format( selList[0], newNode.name() )
         NodeUtility.connectPlugs( objectPlug, nodePlug )
         cmds.select( prevSel )
Example #10
0
    def __init__( self, nodeName, parent=None ):
        super( componentWidget, self ).__init__( parent )
        self.parent = parent
                
        def on_context_menu( point, inNodeName ):
            popMenu = QtGui.QMenu()
            buildAction = QtGui.QAction( 'Build Joint', popMenu, triggered=lambda a=inNodeName:self.buildNode( a ) )
            popMenu.addAction( buildAction )
            
            deleteAction = QtGui.QAction( 'Delete Component', popMenu, triggered=lambda a=inNodeName:self.deleteComponentFromObject( a ) )
            popMenu.addAction( deleteAction )
            
            popMenu.exec_( componentLabel.mapToGlobal( point ) )
        
        # Setup layout.
        verticalLayout = QtGui.QVBoxLayout()
        verticalLayout.setContentsMargins( 0,0,0,0 )
        verticalLayout.setSpacing( 0 )
        verticalLayout.setAlignment( QtCore.Qt.AlignTop )
                
        # Label for component
        componentLabel = QTWidgets.basicLabel( nodeName, 'bold', 10, 'black', '6E9094', inIndent=20 )
        componentLabel.setMinimumHeight( 18 )    
        componentLabel.setContextMenuPolicy( QtCore.Qt.CustomContextMenu )
        componentLabel.customContextMenuRequested.connect( lambda point, node=nodeName:on_context_menu( point, node ) )
        
        # Properties
        propertyStack = QtGui.QVBoxLayout()
        
        propertyFrame = QTWidgets.basicFrame()
        propertyFrame.setMinimumHeight( 40 )
        propertyFrame.setMaximumHeight( 40 )
        
        # Add string edit property
        propertyPlug = NodeUtility.getPlug( nodeName, 'jointName' )
        propertyValue = NodeUtility.getPlugValue( propertyPlug )
        jointTextLayout = QTWidgets.stringProperty( 'Joint Name', propertyValue )
        
        propertyStack.addLayout( jointTextLayout )        
        propertyFrame.setLayout( propertyStack )
        
        verticalLayout.addWidget( componentLabel )
        verticalLayout.addWidget( propertyFrame )

        # Connections
        textBox = propertyFrame.findChild( QtGui.QLineEdit )
        textBox.editingFinished.connect( lambda inPlugName='jointName', inQTType='QLineEdit', inPlugValue=textBox, inNodeName=nodeName
                                         :BasicJointComponent( inNodeName ).setComponentAttributeFromQT( inPlugName, inQTType, inPlugValue, inNodeName ) )
        
        self.setLayout( verticalLayout )
Example #11
0
 def addComponentToObject( self, inClassType ):
     '''
     '''
     selList = cmds.ls( selection=True, long=True )
     if len( selList ) is 1:
         prevSel = selList[0]
         newNode = componentNodes.jointComponentNode().createCompNode( inClassType )
         # Add the component attribute to the object.
         FrameUtility.addPlug( selList[0], newNode.name(), 'attributeType', 'message' )
         #cmds.addAttr( inObject, longName='jointComponent', attributeType='message', storable=False )
         nodePlug = '{0}.parentName'.format( newNode.name() )
         objectPlug = '{0}.{1}'.format( selList[0], newNode.name() )
         NodeUtility.connectPlugs( objectPlug, nodePlug )
         cmds.select( prevSel )
Example #12
0
def getFramesInSceneWIP():
    # Get all the meta nodes in the scene.
    metaNodes = NodeUtility.getMetaNodesInScene()
    print metaNodes
    
    if not metaNodes:
        return None
    else:
        for node in metaNodes:
            # Get the root bit of the frame module.
            rootBit = NodeUtility.getNodeAttrSource( node, 'rootBit' )
            # Get the parent's full path. We need to remove the group name from the beginning as well.
            parent = cleanParentFullName( rootBit[0] )
            print parent
Example #13
0
def mirrorModule():
    # Mirrors a module.
    selList = cmds.ls( selection=True, long=True )
    if len( selList ) == 1:
        # Prompt for axis.
        mirrorAxis = int( cmds.layoutDialog( ui=mirrorObjectPrompt ) )
        
        inBitObj = selList[0]
    
        # Check if selected bit is the root.
        if NodeUtility.attributeCheck( inBitObj, 'frameRoot' ):
            # This is the root bit of the module. From here we know we can get the
            # meta node by accessing the frameRoot attribute.
            metaNode = NodeUtility.getNodeAttrDestination( inBitObj, 'frameRoot' )[0]
        else:
            # The selected bit is not the root. Run through each custom attribute
            # to find one connected to the meta node.
            attrList = cmds.listAttr( inBitObj, userDefined=True )
            for attr in attrList:
                connection = NodeUtility.getNodeAttrDestination( inBitObj, attr )
                if NodeUtility.attributeCheck( connection[0], 'metaType' ):
                    metaNode = connection[0]
                    break
                
        # Now that we have the meta node, we need the XML file name and it's location.
        metaClassPlug = NodeUtility.getPlug( metaNode, 'metaClass' )
        metaClassValue = NodeUtility.getPlugValue( metaClassPlug )
        
        metaBuildFolderPlug = NodeUtility.getPlug( metaNode, 'buildFolder' )
        metaBuildFolderValue = NodeUtility.getPlugValue( metaBuildFolderPlug )
        
        # Create the target module.
        targetRootBit = buildFrameModule( metaBuildFolderValue, metaClassValue )
    
        # Loop through each object in the source module.
        metaRootBit = NodeUtility.getNodeAttrSource( metaNode, 'rootBit' )[0]
        
        sourceChildBits = getFrameRootAllChildren( metaRootBit )
        targetChildBits = getFrameRootAllChildren( targetRootBit )
        
        sourceBits = []
        targetBits = []
        
        for i,bit in enumerate( sourceChildBits ):
            sourceBits.append( bit )
        sourceBits.insert( 0, metaRootBit )
        
        for i, bit in enumerate( targetChildBits ):
            targetBits.append( bit )
        targetBits.insert( 0, targetRootBit )
        
        for bit in xrange( len(sourceBits) ):
            # Mirror the source onto the target.
            mirrorObject( inSourceObj=sourceBits[bit], inTargetObj=targetBits[bit], inMirrorAxis=mirrorAxis )
Example #14
0
 def nodeRotation( self ):
     '''
     dagFn= OpenMaya.MFnDagNode( self.fNodePath )
     path = OpenMaya.MDagPath()
     dagFn.getPath( path )
     path.pop()
     transformFn = OpenMaya.MFnTransform( path )
     q = OpenMaya.MQuaternion()
     transformFn.getRotation( q, OpenMaya.MSpace.kWorld )
     return q
     '''
     plug = NodeUtility.getPlug( 'ControlBox1', 'rotate' )
     rot = NodeUtility.getPlugValue( plug )
     e = OpenMaya.MEulerRotation( rot[0], rot[1], rot[2] )
     return e
Example #15
0
def matchTransforms( inType ):
    '''
    @param inType: String. Type of matching to perform. 'tran', 'rot', or 'all'
    '''
    selObjs = cmds.ls( selection=True, dag=False, ap=True )
    
    if len( selObjs ) == 0:
        cmds.warning( 'No objects are selected. Select two objects and try again' )
    elif len( selObjs ) > 2:
        cmds.warning( 'To many objects are selected. Select only two objects and try again' )
    else:
        # first object is child, second object is target
        cObj = selObjs[0]
        tObj = selObjs[1]
        
        # do the matching of child to target
        MFnTrans = OpenMaya.MFnTransform()
        childDagPath = NodeUtility.getDagPath( cObj )
        MFnTrans.setObject( childDagPath )
        targetMatrix = getMatrix( tObj, 'worldMatrix' )
        if inType == 'tran' or inType == 'all':
            childTranslation = getMatrixTranslation( targetMatrix, OpenMaya.MSpace.kWorld )
            MFnTrans.setTranslation( childTranslation, OpenMaya.MSpace.kWorld )
        if inType == 'rot' or inType == 'all':            
            childRotation = getMatrixRotation( targetMatrix, 'quat' )
            MFnTrans.setRotation( childRotation, OpenMaya.MSpace.kWorld )
Example #16
0
 def buildNode( cls, nodeName ):
     '''
     Builds a curve control.
     
     @param nodeName: String. Name of the node.
     '''        
     # Create the curve.
     curveNode = CurveControlComponent( nodeName ).createCurveControl( cls( nodeName ).controlName, cls( nodeName ).curveType )
     controlName = OpenMaya.MDagPath.getAPathTo( curveNode ).fullPathName()
     
     # Set the control to the transform matrix.
     applyStoredTransforms( nodeName, controlName )
     
     # Get the saved properties and apply them to the curve.
     cvList = NurbsCurveUtility.readCurveValues( nodeName )
     cvPointArray = NurbsCurveUtility.buildCVPointArray( cvList )
     NurbsCurveUtility.setCurveCvs( controlName, cvPointArray )
     
     # Color.
     GeneralUtility.setUserColor( controlName, userColor=cls( nodeName ).controlColor )
     
     # Create the control spacer.
     transReference = NodeUtility.getNodeAttrSource( nodeName, 'parentName' )
     controlSpacer = GeneralUtility.createSpacer( None, inGroupName=cls( nodeName ).controlName, inTargetObject=transReference[0], inDoParent=False, inPrefix='sp' )
     cmds.parent( controlName, controlSpacer, relative=True )
     return curveNode
Example #17
0
def getCurveCvs(inCurve):
    """
    Retrieves the positions for all CVs on the curve.
    
    @param inCurve: String. Name of the curve from which to retrieve CV positions.
    @return: List of Dicts. Each dict holds the information for one nurbs curve. since
                there could be multiple curves for one object we build a list of each curve.
    """
    curDag = NodeUtility.getDagPath(inCurve)
    curFn = OpenMaya.MFnNurbsCurve()
    curCvs = OpenMaya.MPointArray()

    storedCvs = []
    childShapes = curDag.childCount()
    for child in xrange(childShapes):
        childObj = curDag.child(child)
        # if childObj.apiType() == OpenMaya.MFn.kNurbsCurve:
        tempCvs = {}
        curFn.setObject(childObj)
        curFn.getCVs(curCvs)
        for cv in xrange(curCvs.length()):
            tempCvs[cv] = [curCvs[cv].x, curCvs[cv].y, curCvs[cv].z]
        storedCvs.append(tempCvs)

    return storedCvs
Example #18
0
def addPlug( inBit, inPlugName, inAttrType, inAttrDataType ):
    '''
    Adds a plug to the frame bit.
    
    @param inBit: String. Name of the bit to add the attribute to.
    @param inPlugName: String. Name of the plug to add.
    @param inAttrType: String. Type of attribute to add.
    @param inAttrDataType: String. The attribute data type.
    '''
    if inAttrType == 'attributeType':
        if inAttrDataType == 'float3':
            cmds.addAttr( inBit, longName=inPlugName, attributeType=inAttrDataType )
            cmds.addAttr( longName='{0}X'.format( inPlugName ), attributeType='float', parent=inPlugName )
            cmds.addAttr( longName='{0}Y'.format( inPlugName ), attributeType='float', parent=inPlugName )
            cmds.addAttr( longName='{0}Z'.format( inPlugName ), attributeType='float', parent=inPlugName )
        else:
            cmds.addAttr( inBit, longName=inPlugName, attributeType=inAttrDataType )
    elif inAttrType == 'dataType':
        if inAttrDataType == 'typed':
            # Make it a string.
            inAttrDataType = 'string'
        cmds.addAttr( inBit, longName=inPlugName, dataType=inAttrDataType )
    elif inAttrType == 'matrixType':
        mObj = NodeUtility.getDependNode( inBit )
        dgModifier = OpenMaya.MDGModifier()
        mAttr = OpenMaya.MFnMatrixAttribute()
        controlMatrix = mAttr.create( inPlugName, inPlugName, OpenMaya.MFnMatrixAttribute.kDouble )
        dgModifier.addAttribute( mObj, controlMatrix )
        dgModifier.doIt()
Example #19
0
def getFrameBitSettings( inFrameBit ):
    '''
    Retrieves the settings for the frame bit.
    
    @param inFrameBit: String. Name of frame bit.
    @return: Dictionary. All the custom attributes on the frame bit.
    '''    
    attrList = cmds.listAttr( inFrameBit, userDefined=True )
    if attrList is not None:
        tempDict = {}
        for attr in attrList:
            plug = NodeUtility.getPlug( inFrameBit, attr )
            plugValue = NodeUtility.getPlugValue( plug )
            tempDict[ attr ] = plugValue
    else:
        tempDict = None
    return tempDict
Example #20
0
 def saveModule( self ):
     '''
     Save the module into an XML file for re-use.
     We assume that the root node of the module is the one with the module root meta node.
     This means it and all of it's children will be saved in the XML.
     '''
     # Get the selected module
     item = cmds.ls( long=True, selection=True )[0]
     
     # Try to get the module meta component.
     moduleComp = Components.searchModule( item, 'ModuleRootComponent' )
     
     if moduleComp:
         # Get the module info and save it as an XML.
         modulePlug = NodeUtility.getPlug( moduleComp[1], 'moduleName' )
         moduleName = NodeUtility.getPlugValue( modulePlug )
         XMLUtility.writeModuleXML( moduleComp[0], self.SELECTED_ITEM, moduleName )
Example #21
0
 def buildNode( cls, nodeName ):
     '''
     Builds a GL Box control.
     
     @param nodeName: String. Name of the node.
     '''
     jointName = cmds.getAttr( '{0}.jointName'.format( nodeName ) )
     transReference = NodeUtility.getNodeAttrSource( nodeName, 'parentName' )
Example #22
0
def applyStoredTransforms( sourceObj, targetObj ):
    '''
    Applies stored transform data for a control object.
    
    @param sourceObj: String. Name of object to pull data from.
    @param targetObj: String. Name of object to apply data to.
    '''
    #print 'applyStoredTransforms @@@@@@'
    #print 'sourceObj: {0}'.format( sourceObj )
    #print 'targetObj: {0}'.format( targetObj )
    
    MFnTrans = OpenMaya.MFnTransform()
    targetDagPath = NodeUtility.getDagPath( targetObj )
    MFnTrans.setObject( targetDagPath )
    
    sourcePosPlug = NodeUtility.getPlug( sourceObj, 'controlPosition' )
    sourcePosValue = NodeUtility.getPlugValue( sourcePosPlug )
    sourcePos = OpenMaya.MVector( sourcePosValue[0], sourcePosValue[1], sourcePosValue[2] )
    MFnTrans.setTranslation( sourcePos, OpenMaya.MSpace.kTransform )
    
    sourceRotPlug = NodeUtility.getPlug( sourceObj, 'controlRotation' )
    sourceRotValue = NodeUtility.getPlugValue( sourceRotPlug )
    sourceRot = OpenMaya.MEulerRotation( sourceRotValue[0], sourceRotValue[1], sourceRotValue[2] ) 
    MFnTrans.setRotation( sourceRot )
    
    sourceSclPlug = NodeUtility.getPlug( sourceObj, 'controlScale' )
    sourceSclValue = NodeUtility.getPlugValue( sourceSclPlug )
    scaleDoubleArray = OpenMaya.MScriptUtil()
    scaleDoubleArray.createFromList( [sourceSclValue[0], sourceSclValue[1], sourceSclValue[2]], 3 )
    scaleDoubleArrayPtr = scaleDoubleArray.asDoublePtr()
    MFnTrans.setScale( scaleDoubleArrayPtr )
Example #23
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] ) )
Example #24
0
def createCurveCircle(inName, inNormal=[0, 1, 0], inRadius=1):
    """
    @param inName: String. Name of curve circle.
    @param inNormal: List. Direction the curve faces.
    @param inRadius: Int. Radius of the circle.
    @return. MObject. Curve circle.
    """
    node = cmds.circle(name=inName, normal=inNormal, radius=inRadius)
    return NodeUtility.getDependNode(node[0])
Example #25
0
 def buildNode( cls, nodeName ):
     '''
     Builds a joint.
     
     @param nodeName: String. Name of the node.
     '''
     jointName = cmds.getAttr( '{0}.jointName'.format( nodeName ) )
     transReference = NodeUtility.getNodeAttrSource( nodeName, 'parentName' )
     return marigoldJoints.createJoint( jointName, transReference[0] )
Example #26
0
 def deleteComponentFromObject( cls, inCompNode ):
     '''
     Deletes the selected component from the object. Used in right-click menu
     for components GUI.
     '''
     obj = NodeUtility.getNodeAttrSource( inCompNode, 'parentName' )
     cmds.deleteAttr( '{0}.{1}'.format( obj[0], obj[1] ) )
     cmds.delete( inCompNode )
     cmds.select( obj[0] )
Example #27
0
def mirrorObject( inSourceObj=None, inTargetObj=None, inMirrorAxis=None ):
    # Mirrors the position and rotation of one object(source) and applies it to another (target).
    
    if inSourceObj is None or inTargetObj is None:
        # Target object should be selected first, followed by source object.
        selList = cmds.ls( selection=True, long=True )
        if len( selList ) == 2:
            inTargetObj = selList[0]
            inSourceObj = selList[1]
        
    if inMirrorAxis is None:
        inMirrorAxis = int( cmds.layoutDialog( ui=mirrorObjectPrompt ) )
        
    if inMirrorAxis is not None:
        # Get the source module's root world matrix.
        sourceWorldMatrix = TransformUtility.getMatrix( inSourceObj, 'worldMatrix' )
        
        # Get the source's translation vector.
        sourceWorldTranslation = TransformUtility.getMatrixTranslation( sourceWorldMatrix, OpenMaya.MFn.kWorld )
        
        # Get the source's rotation matrix.
        sourceRotationMatrix = OpenMaya.MTransformationMatrix( sourceWorldMatrix ).asRotateMatrix()
        
        # Mirror the translation across the selected axis.
        if inMirrorAxis is 0:
            sourceWorldTranslation.x = sourceWorldTranslation.x * -1
        elif inMirrorAxis is 1:
            sourceWorldTranslation.y = sourceWorldTranslation.y * -1        
        elif inMirrorAxis is 2:
            sourceWorldTranslation.z = sourceWorldTranslation.z * -1    
    
        # Apply the mirrored position back to the target object.
        MFnTrans = OpenMaya.MFnTransform()
        targetDagPath = NodeUtility.getDagPath( inTargetObj )
        MFnTrans.setObject( targetDagPath )
        MFnTrans.setTranslation( sourceWorldTranslation, OpenMaya.MSpace.kWorld )
        
        # Mirror the rotation.
        baseVectors = {}
            
        for row in xrange( 3 ):
            # We only need the first three rows.
            rowPtr = sourceRotationMatrix[row]
            baseVectors[ row ] = []
            for col in xrange( 3 ):
                # We only need the first three columns.
                if col is not inMirrorAxis:
                    origValue = OpenMaya.MScriptUtil.getDoubleArrayItem( rowPtr, col ) * -1
                    OpenMaya.MScriptUtil.setDoubleArray( rowPtr, col, origValue )
    
        targetInverseMatrix = TransformUtility.getMatrix( inTargetObj, 'parentInverseMatrix' )
        mirroredTarget = sourceRotationMatrix * targetInverseMatrix
        toEuler = OpenMaya.MTransformationMatrix( mirroredTarget ).eulerRotation()
        #x,y,z = map(math.degrees,(toEuler.x,toEuler.y,toEuler.z))
        #print x,y,z 
        
        MFnTrans.setRotation( toEuler )
Example #28
0
def createSpacer(inBitName, inGroupName="newGroup", inTargetObject=None, inDoParent=False, inPrefix=None):
    """
    Creates an empty group. Optionally, the group's transforms can be matched to
    another object.
    
    @param inGroupName: String. Name to give the new group.
    @param inTargetObject: String. Name of object to match the group's transforms
    to.
    @return: The newly created group.
    """
    # Create empty group.
    if inPrefix is not None:
        groupName = inPrefix + "_" + inGroupName
    else:
        groupName = inGroupName

    newGroup = cmds.group(em=True, name=groupName)

    # Set its transforms.
    if inTargetObject is not None:
        # Get target objects matrix.
        targetMatrix = TransformUtility.getMatrix(inTargetObject, "worldMatrix")

        # Get groups transform.
        MFnTrans = OpenMaya.MFnTransform()
        groupDagPath = NodeUtility.getDagPath(newGroup)
        MFnTrans.setObject(groupDagPath)

        # Apply the targets translation to the group.
        targetTranslation = TransformUtility.getMatrixTranslation(targetMatrix, OpenMaya.MSpace.kWorld)
        MFnTrans.setTranslation(targetTranslation, OpenMaya.MSpace.kWorld)

        # Apply the targets rotation to the group.
        targetRotation = TransformUtility.getMatrixRotation(targetMatrix, "quat")
        MFnTrans.setRotation(targetRotation, OpenMaya.MSpace.kWorld)

        # Parent the spacer.
        if inDoParent:
            parent = cmds.listRelatives(inBitName, parent=True)
            if NodeUtility.attributeCheck(parent[0], "controlName"):
                parentControl = NodeUtility.getFrameBitSettings(parent[0])["controlName"]
                cmds.parent(newGroup, parentControl, absolute=True)

    return newGroup
Example #29
0
 def requiredAttributes( self ):
     super( CharacterRootComponent, self ).requiredAttributes()
     NodeUtility.addPlug( self.newNode, 'characterName', 'dataType', 'string' )
     self.setAttribute( 'characterName', 'joe', self.newNode )
             
     NodeUtility.addPlug( self.newNode, 'skeletonGroupName', 'dataType', 'string' )
     self.setAttribute( 'skeletonGroupName', 'skeleton', self.newNode )
     
     NodeUtility.addPlug( self.newNode, 'rigGroupName', 'dataType', 'string' )
     self.setAttribute( 'rigGroupName', 'rig', self.newNode )
     
     NodeUtility.addPlug( self.newNode, 'modules', 'attributeType', 'message' )
Example #30
0
def deleteBitChild():
    # Disconnected the child from it's parent.
    selList = cmds.ls( selection=True, long=True )
    for i in selList:
        connections = NodeUtility.getNodeAttrDestination( i, 'matrix' )
        parent = '{0}.{1}'.format( connections[0], connections[1] )
        for plug in connections:
            if plug.find( 'targetWorldMatrix' ) is not -1:
                cmds.removeMultiInstance( parent, b=True )
        cmds.parent( i, world=True )