Exemplo n.º 1
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
Exemplo n.º 2
0
 def requiredAttributes( self, *args, **kwargs ):
     '''
     kwargs
     curveType: Type of curve control to make. Square, triangle, arrow, plus, pyramid, circle, ringDirection.
     '''
     super( CurveControlComponent, self ).requiredAttributes()
     NodeUtility.addPlug( self.newNode, 'controlName', 'dataType', 'string' )
     NodeUtility.addPlug( self.newNode, 'curveType', 'dataType', 'string' )
     self.setAttribute( 'curveType', kwargs['curveType'], self.newNode )
     
     # Add attribute for control color.
     NodeUtility.addPlug( self.newNode, 'controlColor', 'attributeType', 'byte' )
     self.setAttribute( 'controlColor', 1, self.newNode )
     
     # Control transform relative to the parent.
     NodeUtility.addPlug( self.newNode, 'controlPosition', 'attributeType', 'float3' )
     NodeUtility.addPlug( self.newNode, 'controlRotation', 'attributeType', 'float3' )
     NodeUtility.addPlug( self.newNode, 'controlScale', 'attributeType', 'float3' )
     
     # Add attributes for the curve CVs.
     tempCurve = self.createCurveControl( '{0}TempCurve'.format( self.newNode ), kwargs['curveType'] )
     tempCurveName = OpenMaya.MDagPath.getAPathTo( tempCurve ).fullPathName()
     tempCurvePoints = NurbsCurveUtility.getCurveCvs( tempCurveName )
     NurbsCurveUtility.addCurveValues( self.newNode, tempCurvePoints )
     
     # Update curve transform values.
     storeControlTransforms( tempCurveName, self.newNode )
     
     # Clean up.
     cmds.delete( tempCurveName )
Exemplo n.º 3
0
 def createCurveControl( self, inName, inShape ):
     '''
     Creates a nurbs curve control.
     
     @param inName: String. Name of the control curve to create.
     @param inShape: String. Type of shape to create.
     @return: MObject. Control curve.
     '''
     # Point locations for shapes. These are created on the XZ plane.
     square = ( [-1,0,-1], [1,0,-1], [1,0,1], [-1,0,1], [-1,0,-1] )
     
     triangle = ( [0,0,1], [1,0,-1], [-1,0,-1], [0,0,1] )
     
     arrow = ( [0,0,-2], [1,0,0], [0.5,0,0], [0.5,0,2], [-0.5,0,2], [-0.5,0,0], [-1,0,0], [0,0,-2] )
     
     plus = ( [-0.5,0,-2], [0.5,0,-2], [0.5,0,-0.5], [2,0,-0.5], [2,0,0.5], [0.5,0,0.5],
             [0.5,0,2], [-0.5,0,2], [-0.5,0,0.5], [-2,0,0.5], [-2,0,-0.5], [-0.5,0,-0.5], [-0.5,0,-2] )
     
     pyramid = ( [-1,0,-1], [1,0,-1], [1,0,1], [-1,0,1], [-1,0,-1], [0,2,0], [1,0,-1], [1,0,1], [0,2,0], [-1,0,1] )
     
     
     # Grab the points for the passed in shape.
     points = {'square':square,
               'triangle':triangle,
               'arrow':arrow,
               'plus':plus,
               'pyramid':pyramid}
     
     # Create the shape.
     if inShape == 'circle':
         control = NurbsCurveUtility.createCurveCircle( inName )
     elif inShape == 'ringDirection':
         rdCircle = NurbsCurveUtility.createCurveCircle( inName )
         rdTriangle = NurbsCurveUtility.createCurve( 'triangle', points['triangle'], 1, inForm=False, inOffset=[0,0,1.5], inScale=0.25 )
         cirName = OpenMaya.MDagPath.getAPathTo( rdCircle ).fullPathName()
         triName = OpenMaya.MDagPath.getAPathTo( rdTriangle ).fullPathName()
         control = NurbsCurveUtility.createCompoundCurve( [cirName, triName] )
     else:
         control = NurbsCurveUtility.createCurve( inName, points[inShape], inForm=False )
         
     return control
Exemplo n.º 4
0
    def editCurveProperties( self ):
        '''
        Activates the control so the user can edit it's properties.
        '''
        if self.editButton.isChecked():
            if self.textBox.text():
                # Lock the components UI.
                if self.parent.selectedLockActive is False:
                    self.parent.lockSelection()
                
                # Create the curve.
                curveType = CurveControlComponent( self.componentLabel.text() ).curveType
                node = CurveControlComponent( self.componentLabel.text() ).createCurveControl( self.textBox.text(), curveType )
                controlName = OpenMaya.MDagPath.getAPathTo( node ).fullPathName()
                
                # Parent the control to the bit.
                parentNode = CurveControlComponent( self.componentLabel.text() ).parentNode[0]
                cmds.parent( controlName, parentNode )
                self.CONTROL = OpenMaya.MDagPath.getAPathTo( node ).fullPathName()
                
                # Set the control to the transform matrix.
                applyStoredTransforms( self.componentLabel.text(), self.CONTROL )
                
                # Get the saved properties and apply them to the curve.
                cvList = NurbsCurveUtility.readCurveValues( self.componentLabel.text() )
                cvPointArray = NurbsCurveUtility.buildCVPointArray( cvList )
                NurbsCurveUtility.setCurveCvs( self.CONTROL, cvPointArray )
                
                # Color.
                GeneralUtility.setUserColor( self.CONTROL, userColor=self.COLOR )
            else:
                raise ValueError( '{0} does not have a Control Name set.'.format( self.componentLabel.text() ) )
        else:
            if self.CONTROL is not None:
                # Read the control properties and save them to the component node.
                cvList = NurbsCurveUtility.getCurveCvs( self.CONTROL )
                NurbsCurveUtility.writeCurveValues( self.componentLabel.text(), cvList )
                
                # Update the transform matrix.
                storeControlTransforms( self.CONTROL, self.componentLabel.text() )

                # Delete the control
                cmds.delete( self.CONTROL )
                self.CONTROL = None
                
            # Unlock the UI.
            if self.parent.selectedLockActive:
                self.parent.lockSelection()