コード例 #1
0
	def create_plane_rig( self ):
		nurb_name = 'plane'

		cmds.group( n = '{0}Rig_grp'.format( nurb_name ), em = True )
		plane_grp_dag = oopmaya.DAG_Node()

		cmds.group( n = '{0}Controller_grp'.format( nurb_name ), em = True )
		controller_grp_dag = oopmaya.DAG_Node()

		cmds.nurbsPlane( n = '{0}_nurb'.format( nurb_name ), p = [0, 0, 0], ax = [0, 1, 0], w = 10, lr = 1, d = 3, u = 4, v = 1, ch = True )
		plane_nurb_dag = oopmaya.DAG_Node()

		soft_mod = cmds.softMod( '{0}.cv[3][0:3]'.format( plane_nurb_dag.name() ) )[0]
		soft_mod_handle_dag = oopmaya.DAG_Node()

		oopmaya.Maya_Controller( name = '{0}Deformer_controller'.format( nurb_name ), shape = 'diamond_curve' )
		controller_dag = oopmaya.DAG_Node()

		plane_nurb_dag.set_parent( plane_grp_dag )
		controller_grp_dag.set_parent( plane_grp_dag )
		controller_dag.set_parent( controller_grp_dag )
		soft_mod_handle_dag.set_parent( plane_nurb_dag )
		soft_mod_handle_dag.parent_constraint( controller_dag )

		controller_grp_dag.parent_constraint( plane_nurb_dag )
		controller_grp_dag.scale_constraint( plane_nurb_dag )

		soft_mod_handle_dag.hide()

		cmds.setAttr( '{0}.relative'.format( soft_mod ), 1 )
		cmds.setAttr( '{0}.falloffAroundSelection'.format( soft_mod ), 0 )

		cmds.select( plane_nurb_dag.name() )
コード例 #2
0
ファイル: crack_tool.py プロジェクト: jonntd/art_pipeline
    def create_plane_rig(self):
        nurb_name = "plane"

        cmds.group(n="{0}Rig_grp".format(nurb_name), em=True)
        plane_grp_dag = oopmaya.DAG_Node()

        cmds.group(n="{0}Controller_grp".format(nurb_name), em=True)
        controller_grp_dag = oopmaya.DAG_Node()

        cmds.nurbsPlane(n="{0}_nurb".format(nurb_name), p=[0, 0, 0], ax=[0, 1, 0], w=10, lr=1, d=3, u=4, v=1, ch=True)
        plane_nurb_dag = oopmaya.DAG_Node()

        soft_mod = cmds.softMod("{0}.cv[3][0:3]".format(plane_nurb_dag.name()))[0]
        soft_mod_handle_dag = oopmaya.DAG_Node()

        oopmaya.Maya_Controller(name="{0}Deformer_controller".format(nurb_name), shape="diamond_curve")
        controller_dag = oopmaya.DAG_Node()

        plane_nurb_dag.set_parent(plane_grp_dag)
        controller_grp_dag.set_parent(plane_grp_dag)
        controller_dag.set_parent(controller_grp_dag)
        soft_mod_handle_dag.set_parent(plane_nurb_dag)
        soft_mod_handle_dag.parent_constraint(controller_dag)

        controller_grp_dag.parent_constraint(plane_nurb_dag)
        controller_grp_dag.scale_constraint(plane_nurb_dag)

        soft_mod_handle_dag.hide()

        cmds.setAttr("{0}.relative".format(soft_mod), 1)
        cmds.setAttr("{0}.falloffAroundSelection".format(soft_mod), 0)

        cmds.select(plane_nurb_dag.name())
コード例 #3
0
def pub_spawnPoints():
	_sel = mc.ls(sl=True)
	if len(_sel) > 0:
		# template the object
		mc.setAttr ( _sel[0] + ".template", 1)
		# get object BB and position in worldspace
		_objBB = mc.xform( _sel[0], q=True, bb=True)
		_objPos = mc.xform( _sel[0], ws=True, q=True, rp=True)
		# set the position of the plane under the object
		_poz = [0, 0, 0]
		_poz[0] = _objPos[0]
		_poz[1] = _objPos[1] - (( _objBB[4] - _objBB[1]) / 1.75)
		_poz[2] = _objPos[2]
		# scale the plane larger than the bounding box
		_scale = [0, 0, 0]
		_scale[0] = ( _objBB[0] - _objBB[3]) * 1.2
		_scale[2] = ( _objBB[2] - _objBB[5]) * 1.2
		# create, place, scale and rename the plane
		mc.nurbsPlane( p=(0, 0, 0), ax=(0, 1, 0), w=1, lr=1, d=3, u=1, v=1, ch=0)
		mc.move( _poz[0], _poz[1], _poz[2])
		mc.scale( _scale[0], 0, _scale[2])
		_nPlane = mc.rename( "emissionPlane_" + _sel[0] )
		# create the emitter
		mc.emitter( _nPlane, type='surface', r=20, sro=0, nuv=1, cye='none', cyi=1, spd=2, srn=1, nsp=1, tsp=0, mxd=0, mnd=0, sp=0)
		_emitter = mc.rename( "emitter_" + _sel[0] )
		# create the particle object
		mc.particle( n="xxx")
		_pParticle = mc.rename( "particle_" + _sel[0] )
		# connect the emitter to the particle object
		mc.connectDynamic( _pParticle, em=_emitter )
		# template the plane and the particle object
		mc.setAttr ( _nPlane + ".template", 1)
		mc.setAttr ( _pParticle + ".template", 1)
	else:
		assert "No object selected!"
コード例 #4
0
ファイル: maya_renderer.py プロジェクト: brianhou/GPIS
def create_scene_with_mesh(mesh_file):
	global center_of_interest
	global working_min_dist
	global working_max_dist

	cmd.file(f=True, new=True)

	if table:
		cmd.nurbsPlane(name=plane_name, p=(0,0,0), ax=(0,1,0), w=10000, lr=1, d=3, u=1, v=1, ch=1)

	try:
		cmd.file(mesh_file, i=True, ns=obj_name)
	except RuntimeError as e:
		print 'Failed to import mesh file: '+mesh_file
		print e.message
		return False

	cmd.select(obj_name+":Mesh", r=True)
	bounding_box = cmd.polyEvaluate(b=True)
	cmd.move(-bounding_box[1][0], y=True)
	object_height = bounding_box[1][1] - bounding_box[1][0]
	center_of_interest = [0, object_height/2, 0]

	if min_dist == 0:
		major_dist = math.sqrt(math.pow(bounding_box[0][0]-bounding_box[0][1], 2) + math.pow(bounding_box[1][0]-bounding_box[1][1], 2) + math.pow(bounding_box[2][0]-bounding_box[2][1], 2))
		working_min_dist = major_dist*2
		working_max_dist = major_dist*4
		print major_dist

	cmd.setAttr("defaultRenderGlobals.imageFormat", 8) # 32)
	cmd.setAttr("defaultResolution.width", 256)
	cmd.setAttr("defaultResolution.height", 256)
	cmd.setAttr("defaultResolution.deviceAspectRatio", 1.0)

	return True
コード例 #5
0
    def createRibbon(self):
        # checking for master group
        if cmds.objExists('MASTER'):
            print 'warning --- there is another MASTER group you slave!'
        else:
            rs.createMasterAsset()
        # End of master group

        cmds.nurbsPlane(n=self.name + "_" + self.side,
                        axis=(0, 1, 0),
                        width=self.width,
                        lengthRatio=(1.0 / self.width),
                        u=self.numJoints,
                        v=1,
                        degree=3,
                        ch=0)

        ctrlTop = self.__createCurveCtrl(name=(self.name + '_top_CNT'),
                                         freezeTransforms=1,
                                         color=9,
                                         pos=(self.topPoint, 0, 0))
        ctrlMid = self.__createCurveCtrl(name=(self.name + '_mid_CNT'),
                                         freezeTransforms=1,
                                         color=9,
                                         pos=(0, 0, 0))
        ctrlEnd = self.__createCurveCtrl(name=(self.name + '_end_CNT'),
                                         freezeTransforms=1,
                                         color=9,
                                         pos=(self.endPoint, 0, 0))

        # PointConstraint the midCtrl between the top/end
        midConst = cmds.pointConstraint(ctrlTop, ctrlEnd, grpMid)
コード例 #6
0
    def make(self, _make, **kwargs):
        """Can make a node in maya using this command.
        Valid things to make are, group, circle, scriptNode, customCurve.
        
        If customcurve, format type is sObjName..make(what = 'customCurve', curveType = 'validCurveType', orientation = 'Y')
        The list of valid types:
            triangle                      worldMove
            angledCompass                 worldRotate
            straightCompass               twoDirRotate
            square                        fourDirRotate
            sphere                        moveRotate
            plus                          worldMove02
            halfDiamond                   toe
            cube                          spineType01
            cross                         jawEgg
            bulb                          hand
            star                          foot
            eyes
        """
        if cmds.objExists(self.name):
            raise Exception, 'Object with name already exists in scene, you can not have duplicate names in scenes.'
        else:
            if _make == 'group':
                #print 'Making group %s now.' % self.name
                objects = kwargs.get('objects')
                if objects:
                    cmds.group(objects, name = self.name, em = False)
                else:
                    cmds.group(name = self.name, em = True)
            
            elif _make == 'locator':
                #print 'Building spacelocator %s now' % self.name
                cmds.spaceLocator(n = self.name, **kwargs)
            
            elif _make == 'circle':
                cmds.circle(n = self.name, **kwargs)
                self.name = '%s_ctrl' % self.name
            
            elif _make == 'scriptNode':
                cmds.scriptNode(n = self.name, **kwargs)
            
            elif _make == 'customCurve':
                ## Curve options are
                ### curveType = 'circle', snapTo = False, cstTo = False, orientation = 'Y', grouped = False, scaleFactor = 1, color = 15, boundingBox = True, dest = '', suffix = True, addGeoShowHide = True
                myNewCurve = BD_CurveBuilder.buildControlCurve(curveName = self.name, **kwargs)
                if kwargs.get('suffix'):
                    self.name = '%s_ctrl' % myNewCurve
                else:
                    self.name = '%s' % myNewCurve

            elif _make == 'nurbsPlane':
                cmds.nurbsPlane(n = '%s' % self.name, **kwargs)

            elif _make == 'camera':
                cmds.camera()
                cmds.rename('camera1', '%s' % self.name)
コード例 #7
0
    def testAnimNSurfaceAndPolyDeleteReload(self):

        # create a poly cube and animate
        shapeName = 'pCube'
        MayaCmds.polyCube(name=shapeName)
        MayaCmds.move(5, 0, 0, r=True)
        MayaCmds.setKeyframe(shapeName + '.vtx[2:5]', time=[1, 24])
        MayaCmds.currentTime(12)
        MayaCmds.select(shapeName + '.vtx[2:5]', replace=True)
        MayaCmds.move(0, 4, 0, r=True)
        MayaCmds.setKeyframe(shapeName + '.vtx[2:5]', time=[12])

        # create an animated Nurbs plane
        MayaCmds.nurbsPlane(ch=False, name='nPlane')
        MayaCmds.move(-5, 5, 0, relative=True)
        MayaCmds.select('nPlane.cv[0:3][0:3]', replace=True)
        MayaCmds.setKeyframe(time=1)
        MayaCmds.currentTime(12, update=True)
        MayaCmds.rotate(0, 0, 90, relative=True)
        MayaCmds.setKeyframe(time=12)
        MayaCmds.currentTime(24, update=True)
        MayaCmds.rotate(0, 0, 90, relative=True)
        MayaCmds.setKeyframe(time=24)

        # write it out to Abc file and load back in
        self.__files.append(
            util.expandFileName('testNSurfaceAndPolyReload.abc'))
        MayaCmds.AbcExport(j='-fr 1 24 -root pCube -root nPlane -file ' +
                           self.__files[-1])
        # load back the Abc file, delete the cube and save to a maya file
        MayaCmds.AbcImport(self.__files[-1], mode='open')
        MayaCmds.delete('pCube')
        self.__files.append(util.expandFileName('test.mb'))
        MayaCmds.file(rename=self.__files[-1])
        MayaCmds.file(save=True)

        # import the saved maya file to compare with the original scene
        MayaCmds.file(self.__files[-1], open=True)
        MayaCmds.select('nPlane', replace=True)
        MayaCmds.group(name='ReloadGrp')
        MayaCmds.AbcImport(self.__files[-2], mode='import')

        shapeList = MayaCmds.ls(type='mesh')
        self.failUnlessEqual(len(shapeList), 1)
        surfaceList = MayaCmds.ls(type='nurbsSurface')
        self.failUnlessEqual(len(surfaceList), 2)

        # test the equality of plane
        surface1 = '|nPlane|nPlaneShape'
        surface2 = '|ReloadGrp|nPlane|nPlaneShape'
        for t in range(1, 25):
            MayaCmds.currentTime(t, update=True)
            if not util.compareNurbsSurface(surface1, surface2):
                self.fail('%s and %s are not the same at frame %d' %
                          (surface1, surface2, t))
コード例 #8
0
    def create_scene_with_mesh(self, mesh_filename, rot=np.eye(3)):
        """ Creates the maya scene with the specified mesh """
        cmd.file(f=True, new=True)

        if self.use_table_:
            cmd.nurbsPlane(name=self.plane_name_,
                           p=(0, 0, 0),
                           ax=(0, 0, 1),
                           w=10000,
                           lr=1,
                           d=3,
                           u=1,
                           v=1,
                           ch=1)

        try:
            cmd.file(mesh_filename, i=True, ns=self.obj_name_)
        except RuntimeError as e:
            print 'Failed to import mesh file: ' + mesh_filename
            print e.message
            return False

        # convert the rotation to euler angles and rotate the mesh
        axes = 'sxyz'
        r = tfx.canonical.CanonicalRotation(rot)
        euler = r.euler(axes)
        euler = [(180. / np.pi) * a for a in euler]  # convert to degrees
        cmd.select(self.obj_name_ + ":Mesh", r=True)
        cmd.rotate(euler[0], euler[1], euler[2])

        # move the object on top of the table if specified
        bounding_box = cmd.polyEvaluate(b=True)
        object_height = bounding_box[2][1]
        if self.use_table_:
            cmd.move(object_height, z=True)
            self.center_of_interest_ = [0, 0, object_height]

        # set the min and max distances
        if self.min_dist_ == 0:
            major_dist = math.sqrt(
                math.pow(bounding_box[0][0] - bounding_box[0][1], 2) +
                math.pow(bounding_box[1][0] - bounding_box[1][1], 2) +
                math.pow(bounding_box[2][0] - bounding_box[2][1], 2))
            self.min_dist_ = 1.0 * major_dist
            self.max_dist_ = 2.0 * major_dist

        # set image attributes
        cmd.setAttr("defaultRenderGlobals.imageFormat", self.image_format_)
        cmd.setAttr("defaultResolution.width", self.image_width_)
        cmd.setAttr("defaultResolution.height", self.image_height_)
        cmd.setAttr("defaultResolution.deviceAspectRatio",
                    float(self.image_width_) / float(self.image_height_))

        return True
コード例 #9
0
    def testAnimNSurfaceAndPolyDeleteReload(self):

        # create a poly cube and animate
        shapeName = 'pCube'
        MayaCmds.polyCube(name=shapeName)
        MayaCmds.move(5, 0, 0, r=True)
        MayaCmds.setKeyframe(shapeName+'.vtx[2:5]', time=[1, 24])
        MayaCmds.currentTime(12)
        MayaCmds.select(shapeName+'.vtx[2:5]',replace=True)
        MayaCmds.move(0, 4, 0, r=True)
        MayaCmds.setKeyframe(shapeName+'.vtx[2:5]', time=[12])

        # create an animated Nurbs plane
        MayaCmds.nurbsPlane(ch=False, name='nPlane')
        MayaCmds.move(-5, 5, 0, relative=True)
        MayaCmds.select('nPlane.cv[0:3][0:3]', replace=True)
        MayaCmds.setKeyframe(time=1)
        MayaCmds.currentTime(12, update=True)
        MayaCmds.rotate(0, 0, 90, relative=True)
        MayaCmds.setKeyframe(time=12)
        MayaCmds.currentTime(24, update=True)
        MayaCmds.rotate(0, 0, 90, relative=True)
        MayaCmds.setKeyframe(time=24)

        # write it out to Abc file and load back in
        self.__files.append(util.expandFileName('testNSurfaceAndPolyReload.abc'))
        MayaCmds.AbcExport(j='-fr 1 24 -root pCube -root nPlane -file ' + self.__files[-1])
        # load back the Abc file, delete the cube and save to a maya file
        MayaCmds.AbcImport(self.__files[-1], mode='open')
        MayaCmds.delete('pCube')
        self.__files.append(util.expandFileName('test.mb'))
        MayaCmds.file(rename=self.__files[-1])
        MayaCmds.file(save=True)

        # import the saved maya file to compare with the original scene
        MayaCmds.file(self.__files[-1], open=True)
        MayaCmds.select('nPlane', replace=True)
        MayaCmds.group(name='ReloadGrp')
        MayaCmds.AbcImport(self.__files[-2], mode='import')

        shapeList = MayaCmds.ls(type='mesh')
        self.failUnlessEqual(len(shapeList), 1)
        surfaceList = MayaCmds.ls(type='nurbsSurface')
        self.failUnlessEqual(len(surfaceList), 2)

        # test the equality of plane
        surface1 = '|nPlane|nPlaneShape'
        surface2 = '|ReloadGrp|nPlane|nPlaneShape'
        for t in range(1, 25):
            MayaCmds.currentTime(t, update=True)
            if not util.compareNurbsSurface( surface1, surface2 ):
                self.fail('%s and %s are not the same at frame %d' %
                    (surface1, surface2, t))
コード例 #10
0
def CreateRibbon (*args):
    planeName = cmds.textFieldGrp (planeNameField, q = True, text = True)
    jointAmount = cmds.intSliderGrp (JointAmountSlider, q = True, value = 10)
    
    if cmds.objExists ('hairSystem1Follicles'):
        cmds.warning ('HairSystem1Follicles allready Exists, please rename that hair system and nucleus')
    
    else:
        cmds.nurbsPlane (ax = (0, 1, 0), w = 1, lr = jointAmount, d = 3, u = 1, v = jointAmount,  n = planeName)
        pm.mel.createHair(1, jointAmount, 10, 0, 0, 0, 0, 5, 0, 1, 2, 1)
        cmds.delete ('hairSystem1','pfxHair1','nucleus1')
        cmds.setAttr(str (planeName)+'.inheritsTransform', 0)
        
        for C in range (1, jointAmount + 1):
            cmds.delete ('curve' + str (C) )
        cmds.rename ('hairSystem1Follicles', planeName + 'Follicle_GRP')
        
        Follicles = cmds.ls (planeName + 'Follicle_GRP', dag = True, type = 'follicle')
        
    NewName = 01
    BindJoints= []
        
    for item in Follicles:
        
        cmds.select (item)
        JointPos= pm.mel.joint (n =  str (planeName)+'RibbonJoint' + str (NewName) )
        cmds.select (cl=True)
        JointController= pm.mel.joint (n =  str (planeName)+'RibbonJointController' + str (NewName) )
        BindJoints.append(JointController)
        Poisiton= cmds.pointConstraint(JointPos,JointController, mo = False)
        cmds.setAttr (str(JointController)+'.radius', 2)
        Controlador = cmds.circle(n =  str (planeName)+'Controller' + str (NewName) )
        grupoControlador = cmds.group(n =  str (planeName)+'ControllerGRP' + str (NewName))
        grupoControladorPoint = cmds.group(n =  str (planeName)+'ControllerGRP_Point' + str (NewName))
        grupoControladorOrient = cmds.group(n =  str (planeName)+'ControllerGRP_Orient' + str (NewName))
        PosicionControlador = cmds.pointConstraint(JointPos, grupoControlador, mo = False)
        cmds.delete(Poisiton,PosicionControlador)
        cmds.parent (JointController,Controlador[0])
        cmds.setAttr(str(Controlador[0])+'.overrideEnabled', 1)
        cmds.setAttr(str(Controlador[0])+'.overrideColor', 16)
        

        NewName = NewName + 1
        
    
    cmds.setAttr (str (planeName) + '.inheritsTransform', 0) 
    cmds.select (cl = True)
   
    print BindJoints
    BindSkin= cmds.skinCluster(BindJoints, str(planeName), tsb= True,  nw=1, wd = 0, mi = 5, omi = True, dr = 4, rui = True )
コード例 #11
0
def build_ribbon_plane(span_count, length_ratio=None, ribbon_name='C_ribbon'):

    # input number of joints desired to use
    width = float(span_count)
    if not length_ratio:
        length_ratio = 1 / width

    cmds.nurbsPlane(ax=[0, 1, 0],
                    w=width,
                    lr=length_ratio,
                    d=3,
                    u=span_count,
                    v=1,
                    ch=0,
                    n=ribbon_name + '_SRF')
コード例 #12
0
    def test_createFollicles(self):
        #--- Setup the scene
        plane = cmds.nurbsPlane(w=1,
                                lengthRatio=5,
                                d=3,
                                u=1,
                                v=6,
                                ax=[0, 0, 1])[0]

        #--- Call method, get results
        result = self.rig._createFollicles(name='test', plane=plane, num=6)

        #--- Check Results
        expected = [
            'test_' + (plane + 'ShapeFollicle_') + str(x + 1).zfill(2)
            for x in range(6)
        ]
        self.test.assertListEqual(l1=result, l2=expected)

        for each in result:
            self.assertTrue(cmds.objExists(each))
            transform = cmds.listRelatives(each, parent=True)[0]
            self.assertEqual(
                cmds.listRelatives(transform, parent=True)[0],
                'test_rbbnFollicles_grp')
            self.assertFalse(cmds.listRelatives(each, c=True))
コード例 #13
0
ファイル: Func.py プロジェクト: darkuress/arFace
    def createBrowCtl(self, jntNum, orderJnts):
        """
        create extra controllor for the panel
        """
        ctlP = "browDetailCtrl0"
        kids = cmds.listRelatives (ctlP, ad=True, type ='transform')   
        if kids:
            cmds.delete (kids)
            
        attTemp = ['scaleX','scaleY','scaleZ', 'rotateX','rotateY', 'tz', 'visibility' ]  
        index = 0

        for jnt in orderJnts:                            
            detailCtl = cmds.circle ( n = 'browDetail' + str(index+1).zfill(2), ch=False, o =True, nr = ( 0, 0, 1), r = 0.2 )
            detailPlane = cmds.nurbsPlane ( ax = ( 0, 0, 1 ), w = 0.1,  lengthRatio = 10, degree = 3, ch=False, n = 'browDetail'+ str(index+1).zfill(2) + 'P' )
            increment = 2.0/(jntNum-1)
            cmds.parent (detailCtl[0], detailPlane[0], relative=True )
            cmds.parent (detailPlane[0], ctlP, relative=True )
            cmds.setAttr (detailPlane[0] + '.tx', -2 + increment*index*2 )
            cmds.xform ( detailCtl[0], r =True, s = (0.2, 0.2, 0.2))  
            cmds.setAttr (detailCtl[0] +".overrideEnabled", 1)
            cmds.setAttr (detailCtl[0] +"Shape.overrideEnabled", 1)
            cmds.setAttr( detailCtl[0]+"Shape.overrideColor", 20)        
            
            cmds.transformLimits ( detailCtl[0] , tx = ( -.4, .4), etx=( True, True) )
            cmds.transformLimits ( detailCtl[0], ty = ( -.8, .8), ety=( True, True) )
            
            for att in attTemp:
                cmds.setAttr (detailCtl[0] +"."+ att, lock = True, keyable = False, channelBox =False)
                    
            index = index + 1
コード例 #14
0
def buildOceanNurbsPreviewPlane(xRes = 20, zRes = 20, size = 8, oceanShader = '', boatName = ''):
    """
    Creates NURBS plane that moves along with ocean so we can intersect this with our boatName to create the emitter curves
    """
    debug(None, method = 'buildOceanNurbsPreviewPlane', message = 'Building NURBS Intersection plane now', verbose = False)
    if cmds.objExists('%s_NurbsIntersect_geo' % boatName):
        cmds.warning('Skipping %s_NurbsIntersect. Already exists in the scene!' % boatName)
        debug(None, method = 'buildOceanNurbsPreviewPlane', message = 'Skipping %s_NurbsIntersect. Already exists in the scene!' % boatName, verbose = False)
    else:
        NURBSPlane = cmds.nurbsPlane( width=1,lengthRatio = 1,degree = 1, patchesU=xRes, patchesV=zRes, axis = (0,1,0) , constructionHistory = 0, name = '%s_NurbsIntersect_geo' % boatName)
        debug(None, method = 'buildOceanNurbsPreviewPlane', message = 'Built NURBSPlane: %s' % NURBSPlane, verbose = False)

        ## Now set the attrs of the NURBSPlane
        cmds.setAttr ( "%s.rotate" % NURBSPlane[0], lock= True)
        cmds.setAttr ("%s.scaleY" % NURBSPlane[0], lock= True)
        cmds.setAttr ("%s.scaleX" % NURBSPlane[0], size)
        cmds.setAttr ("%s.scaleZ" % NURBSPlane[0], size)
        cmds.setAttr ( "%s.translateY" % NURBSPlane[0] , lock= True)
        #cmds.setAttr (NURBSPlane[0] + ".visibility",0)
        cmds.setAttr ("%s.primaryVisibility" % NURBSPlane[0],0)
        cmds.setAttr ("%s.visibleInReflections" % NURBSPlane[0],0)
        cmds.setAttr ("%s.visibleInRefractions" % NURBSPlane[0],0)
        debug(None, method = 'buildOceanNurbsPreviewPlane', message = 'All Attrs set correctly', verbose = False)
        ## Cleanup the build
        _cleanupNURBSPlane(NURBSPlane, boatName)
        debug(None, method = 'buildOceanNurbsPreviewPlane', message = 'Cleanup Performed Successfully', verbose = False)
        ## Build the expression
        _buildNURBSPlaneExpression(NURBSPlane, xRes, zRes, oceanShader)
        debug(None, method = 'buildOceanNurbsPreviewPlane', message = 'Expression Built Successfully', verbose = False)
コード例 #15
0
ファイル: ribbon.py プロジェクト: duncanrudd/rooftops
def build(numBindJoints=6, numSpans=None, name='', numSkinJoints=3, width=None):
    '''
    builds a nurbs ribbon
    If width is not specified, width will be set to numBindJoints
    If numSpans is not specified, it will be set to numBindJoints
    
    '''
    if not width:
        width = numBindJoints
    if not numSpans:
        numSpans = numBindJoints
    
    main_grp = cmds.group(empty=1, name=(name + '_grp'))
    plane = cmds.nurbsPlane(axis=(0, 1, 0), ch=0, lengthRatio=(1.0 / width), w=width, u=numSpans, name=(name + '_nurbsPlane'))[0]
    cmds.parent(plane, main_grp)
    
    # Creat Skin joints
    skinJoints = []
    skinJointPositions = common.pointsAlongVector( start=[width*.5, 0, 0], end=[width*-.5, 0, 0], divisions=(numSkinJoints-1) )
    for index in range(len(skinJointPositions)):
        cmds.select(main_grp)
        j = cmds.joint(position = skinJointPositions[index], name=(name + '_' + str(index) + '_jnt'))
        skinJoints.append(j)
        
    # Add skinning to ribbon
    cmds.skinCluster(skinJoints, plane, tsb=1, name=(plane + '_skinCluster'))
    cmds.setAttr(plane+'.inheritsTransform', 0)
    
    # Add follicles
    for index in range(numBindJoints):
        f = rivet.build( mesh=plane, paramU=(1.0 / (numBindJoints-1) * index), paramV=0.5, name=(name + '_' + str(index)))
        cmds.parent(f, main_grp)
        j = cmds.joint(name=(name + '_' + str(index) + '_bnd'))
コード例 #16
0
ファイル: core.py プロジェクト: bmbtnkr/mayaTools
    def buildRibbonPlane(self):
        # Create Nurbs surface
        flexiPlane = cmds.nurbsPlane(w=self.width, lr=self.lengthRatio,
                                     u=self.numJnts, v=1, ax=[0, 1, 0])
        flexiPlane = cmds.rename(flexiPlane[0], '%s_surface01' % self.name)
        cmds.delete(flexiPlane, constructionHistory=1)

        # Create plane follicles
        mel.eval('createHair %s 1 2 0 0 0 0 1 0 1 1 1;' % str(self.numJnts))
        for obj in ['hairSystem1', 'pfxHair1', 'nucleus1']:
            cmds.delete(obj)
        folChildren = cmds.listRelatives('hairSystem1Follicles', ad=1)
        cmds.delete([i for i in folChildren if 'curve' in i])
        folGrp = cmds.rename('hairSystem1Follicles', '%s_flcs01' % self.name)

        alphabetList = map(chr, range(97, 123))
        folChildren = cmds.listRelatives(str(folGrp), c=1)
        folJnts = []

        for obj, letter in zip(folChildren, alphabetList):
            folJnt = cmds.joint(p=cmds.xform(obj, t=1, q=1), n='%s_bind_%s01' % (self.name, letter))
            folJnts.append(folJnt)
            cmds.parent(folJnt, obj)
            cmds.rename(obj, '%s_flc_%s01' % (self.name, letter))

        utils.lockAttrs(flexiPlane, 1, 1, 1, 0)

        cmds.parent(folGrp, self.extrasGrp)
        cmds.parent(flexiPlane, self.moveGrp)

        return flexiPlane, folGrp
コード例 #17
0
 def test_setupHeirarchy(self):
     #--- Setup the scene
     startJnt = cmds.joint(n='startJnt',p=(3, 0, 0))
     endJnt = cmds.joint(n='endJnt',p=(3, 5, -2))        
     locs = []
     locs.append(cmds.spaceLocator(n='test_topLoc_pos', p=(0, 0, 1))[0])
     locs.append(cmds.spaceLocator(n='test_midLoc_pos',p=(1, 2, 2))[0])
     locs.append(cmds.spaceLocator(n='test_btmLoc_pos',p=(2, 4, 3))[0])
     
     locGrp = cmds.group(em=True)
     fGrp = cmds.group(em=True)
     plane = cmds.nurbsPlane( w=1, lengthRatio=5, d=3, u=1, v=6, ax=[0, 0, 1])[0]
     
     for each in locs:
         cmds.parent(each,locGrp)
     
     #--- Call method, get results
     result = self.rig._setupHeirarchy(name='test', startObj=startJnt, endObj=endJnt, 
                                       locGrp=locGrp, plane=plane, follicleGrp=fGrp)
     
     #--- Check Results
     expectedTopNode = 'test_rbbnTopNode'
     self.assertEqual(result, expectedTopNode)
     self.assertTrue(cmds.objExists(expectedTopNode))
     self.assertEqual(cmds.listRelatives(fGrp,parent=True)[0], expectedTopNode) 
     self.assertEqual(cmds.listRelatives(plane,parent=True)[0], expectedTopNode) 
     self.test.assertConstrained(startJnt,locs[2],type='parent')
     self.test.assertConstrained(endJnt,locs[0],type='parent')
コード例 #18
0
    def setup_object_segmentation(self):
        """ Sets up maya object segmentation masks """
        self.create_mask_for_object_with_color(self.obj_name_ + ":Mesh",
                                               [1, 1, 1])

        if self.use_table_:
            cmd.nurbsPlane(name=self.plane_name_,
                           p=(0, 0, 0),
                           ax=(0, 0, 1),
                           w=10000,
                           lr=1,
                           d=3,
                           u=1,
                           v=1,
                           ch=1)
            self.create_mask_for_object_with_color(self.plane_name_, [1, 0, 0])
コード例 #19
0
ファイル: core.py プロジェクト: bmbtnkr/mayaTools
    def buildRibbonPlane(self):
        # Create Nurbs surface
        flexiPlane = cmds.nurbsPlane(w=self.width,
                                     lr=self.lengthRatio,
                                     u=self.numJnts,
                                     v=1,
                                     ax=[0, 1, 0])
        flexiPlane = cmds.rename(flexiPlane[0], '%s_surface01' % self.name)
        cmds.delete(flexiPlane, constructionHistory=1)

        # Create plane follicles
        mel.eval('createHair %s 1 2 0 0 0 0 1 0 1 1 1;' % str(self.numJnts))
        for obj in ['hairSystem1', 'pfxHair1', 'nucleus1']:
            cmds.delete(obj)
        folChildren = cmds.listRelatives('hairSystem1Follicles', ad=1)
        cmds.delete([i for i in folChildren if 'curve' in i])
        folGrp = cmds.rename('hairSystem1Follicles', '%s_flcs01' % self.name)

        alphabetList = map(chr, range(97, 123))
        folChildren = cmds.listRelatives(str(folGrp), c=1)
        folJnts = []

        for obj, letter in zip(folChildren, alphabetList):
            folJnt = cmds.joint(p=cmds.xform(obj, t=1, q=1),
                                n='%s_bind_%s01' % (self.name, letter))
            folJnts.append(folJnt)
            cmds.parent(folJnt, obj)
            cmds.rename(obj, '%s_flc_%s01' % (self.name, letter))

        utils.lockAttrs(flexiPlane, 1, 1, 1, 0)

        cmds.parent(folGrp, self.extrasGrp)
        cmds.parent(flexiPlane, self.moveGrp)

        return flexiPlane, folGrp
コード例 #20
0
ファイル: maya_renderer.py プロジェクト: puneetp/GPIS
def create_scene_with_mesh(mesh_file):
    global center_of_interest
    global working_min_dist
    global working_max_dist

    cmd.file(f=True, new=True)

    if table:
        cmd.nurbsPlane(name=plane_name,
                       p=(0, 0, 0),
                       ax=(0, 1, 0),
                       w=10000,
                       lr=1,
                       d=3,
                       u=1,
                       v=1,
                       ch=1)

    try:
        cmd.file(mesh_file, i=True, ns=obj_name)
    except RuntimeError as e:
        print 'Failed to import mesh file: ' + mesh_file
        print e.message
        return False

    cmd.select(obj_name + ":Mesh", r=True)
    bounding_box = cmd.polyEvaluate(b=True)
    cmd.move(-bounding_box[1][0], y=True)
    object_height = bounding_box[1][1] - bounding_box[1][0]
    center_of_interest = [0, object_height / 2, 0]

    if min_dist == 0:
        major_dist = math.sqrt(
            math.pow(bounding_box[0][0] - bounding_box[0][1], 2) +
            math.pow(bounding_box[1][0] - bounding_box[1][1], 2) +
            math.pow(bounding_box[2][0] - bounding_box[2][1], 2))
        working_min_dist = major_dist * 2
        working_max_dist = major_dist * 4
        print major_dist

    cmd.setAttr("defaultRenderGlobals.imageFormat", 8)  # 32)
    cmd.setAttr("defaultResolution.width", 256)
    cmd.setAttr("defaultResolution.height", 256)
    cmd.setAttr("defaultResolution.deviceAspectRatio", 1.0)

    return True
コード例 #21
0
ファイル: panopticon.py プロジェクト: chirs/studio5
    def draw(self):
        """
        Ground drawing directions.
        """

        p = cmds.nurbsPlane(w=100, lr=1)
        cmds.move(-20, 0, 0, p)
        assignMaterial(self.name, p[0])
コード例 #22
0
def setUpBrows():
    controls_grp = cmds.group(em=True, n='facialBrowsControls_c_grp')
    system_grp = cmds.group(em=True, n='facialBrowsSystem_c_grp')
    nurbs_grp = cmds.group(em=True, n='browsMainNurbsSkin_c_grp')
    Snurbs_grp = cmds.group(em=True, n='browsSpecificNurbsSkin_c_grp')
    Scontrols_grp = cmds.group(em=True, n='facialBrowsSpecificControls_c_grp')
    geo_grp = cmds.group(em=True, n='browsGeoSkin_c_grp')

    cmds.duplicate('headReference_c_geo', n='headFacialBrows_c_geo')

    mNurb = cmds.nurbsPlane(n='browsMain_c_nurbs',
                            ax=(0, 1, 0),
                            w=True,
                            lr=True,
                            d=3,
                            u=24,
                            v=1,
                            ch=1)
    cmds.parent(mNurb, nurbs_grp)

    mainBrows_l_loc = cmds.spaceLocator(n='mainBrows_l_loc')
    brow_c_loc = cmds.spaceLocator(n='brow_c_loc')
    brow01_l_loc = cmds.spaceLocator(n='brow01_l_loc')
    brow02_l_loc = cmds.spaceLocator(n='brow02_l_loc')
    brow03_l_loc = cmds.spaceLocator(n='brow03_l_loc')

    brow01_r_loc = cmds.spaceLocator(n='brow01_r_loc')
    brow02_r_loc = cmds.spaceLocator(n='brow02_r_loc')
    brow03_r_loc = cmds.spaceLocator(n='brow03_r_loc')

    fun.conElement(source=brow01_l_loc[0], subject=brow01_r_loc[0])
    fun.conElement(source=brow02_l_loc[0], subject=brow02_r_loc[0])
    fun.conElement(source=brow03_l_loc[0], subject=brow03_r_loc[0])

    if cmds.objExists('facialControls_c_grp') == False:
        cmds.group(em=True, n='facialControls_c_grp')
    cmds.parent(controls_grp, 'facialControls_c_grp')
    cmds.parent(Scontrols_grp, 'facialControls_c_grp')
    if cmds.objExists('facialRig_c_grp') == False:
        cmds.group(em=True, n='facialRig_c_grp')
    if cmds.objExists('facialSystems_c_grp') == False:
        cmds.group(em=True, n='facialSystems_c_grp')
        cmds.parent('facialSystems_c_grp', 'facialRig_c_grp')
    cmds.parent(system_grp, 'facialRig_c_grp')
    cmds.parent(nurbs_grp, system_grp)
    cmds.parent(Snurbs_grp, system_grp)
    for i, e in ['brow_c_loc',
                 'brow01_l_loc'], ['brow01_l_loc', 'brow02_l_loc'
                                   ], ['brow02_l_loc', 'brow03_l_loc']:
        for influenceI, influenceE in [0.75, 0.25], [0.5, 0.5], [0.25, 0.75]:
            ubic = cmds.spaceLocator(n='refLoc_dontTouch')
            pc = cmds.parentConstraint(i,
                                       e,
                                       ubic,
                                       n='parentConstraint_reference')
            cmds.setAttr('{}.{}W0'.format(pc[0], i), influenceI)
            cmds.setAttr('{}.{}W1'.format(pc[0], e), influenceE)
コード例 #23
0
def createNurb(trans, angle, scale, transName, *args):
    nurb = cmds.nurbsPlane(patchesU=9,
                           patchesV=1,
                           degree=1,
                           name=transName,
                           axis=[0, 1, 0],
                           width=1)
    cmds.xform(nurb, rotation=angle, translation=trans, scale=scale)
    return nurb
コード例 #24
0
 def __create_plane(self):
     """ Create a nurbsPlane based on flag specifications """
     self.surface = cmds.nurbsPlane(degree=3,
                                    width=10,
                                    lengthRatio=0.2,
                                    patchesU=self._length,
                                    patchesV=1,
                                    axis=(0, 1, 0),
                                    name=self.name + '_surface')[0]
     #--- parent the surface under the global movement group
     cmds.parent(self.surface, self.global_move)
コード例 #25
0
    def _createPlane(self,
                     name=None,
                     baseTransform=None,
                     targetTransform=None,
                     aim=None,
                     up=None,
                     wup=None):
        if self.logger: self.logger.info('_createPlane(): Starting...')

        # Define vectors
        if aim == 'x': aimV = [1, 0, 0]
        if aim == 'y': aimV = [0, 1, 0]
        if aim == 'z': aimV = [0, 0, 1]

        if up == 'x': upV = [1, 0, 0]
        if up == 'y': upV = [0, 1, 0]
        if up == 'z': upV = [0, 0, 1]

        if wup == 'x': wupV = [1, 0, 0]
        if wup == 'y': wupV = [0, 1, 0]
        if wup == 'z': wupV = [0, 0, 1]

        # Get distance between base and target
        p1 = cmds.xform(baseTransform, q=1, ws=1, rp=1)
        p2 = cmds.xform(targetTransform, q=1, ws=1, rp=1)
        dist = math.sqrt( (p2[0]-p1[0])*(p2[0]-p1[0]) + \
                          (p2[1]-p1[1])*(p2[1]-p1[1]) + \
                          (p2[2]-p1[2])*(p2[2]-p1[2]) )

        # Create the plane
        plane = cmds.nurbsPlane(n=name + '_multiAxisRigPlane', axis=[0, 90,
                                                                     0])[0]
        cmds.delete(plane, ch=True)

        # Snap/Constraint to baseTransform
        cmds.pointConstraint(baseTransform,
                             plane,
                             mo=False,
                             n=name + '_multiAxisRigPlanePointConst')

        # Scale it so plane is twice the length of the base/target distance
        cmds.setAttr('%s.scaleX' % plane, dist * 2)
        cmds.setAttr('%s.scaleY' % plane, dist * 2)
        cmds.setAttr('%s.scaleZ' % plane, dist * 2)

        # Aim at targetTransform
        cmds.delete(cmds.aimConstraint(targetTransform, plane, aim=aimV,
                                       u=upV))

        if self.logger:
            self.logger.info('_createPlane(): End...\nReturned: %s' % plane)
        return plane
コード例 #26
0
 def createSimpleRibbon(self, name='ribbon', totalJoints=6, jointLabelNumber=0, jointLabelName="SimpleRibbon", *args):
     """ Creates a Ribbon system.
         Receives the total number of joints to create.
         Returns the ribbon nurbs plane, the joints groups and joints created.
     """
     # create a ribbonNurbsPlane:
     ribbonNurbsPlane = cmds.nurbsPlane(name=name+"RibbonNurbsPlane", constructionHistory=False, object=True, polygon=0, axis=(0, 1, 0), width=1, lengthRatio=8, patchesV=totalJoints)[0]
     # get the ribbonNurbsPlane shape:
     ribbonNurbsPlaneShape = cmds.listRelatives(ribbonNurbsPlane, shapes=True, children=True)[0]
     # make this ribbonNurbsPlane as template, invisible and not renderable:
     cmds.setAttr(ribbonNurbsPlane+".template", 1)
     cmds.setAttr(ribbonNurbsPlane+".visibility", 0)
     self.setNotRenderable([ribbonNurbsPlaneShape])
     # make this ribbonNurbsPlane as not skinable from dpAR_UI:
     cmds.addAttr(ribbonNurbsPlane, longName="doNotSkinIt", attributeType="bool", keyable=True)
     cmds.setAttr(ribbonNurbsPlane+".doNotSkinIt", 1)
     # create groups to be used as a root of the ribbon system:
     ribbonGrp = cmds.group(ribbonNurbsPlane, n=name+"_Rbn_RibbonJoint_Grp")
     # create joints:
     jointList, jointGrpList = [], []
     for j in range(totalJoints+1):
         # create pointOnSurfaceInfo:
         infoNode = cmds.createNode('pointOnSurfaceInfo', name=name+"_POSI"+str(j))
         # setting parameters worldSpace, U and V:
         cmds.connectAttr(ribbonNurbsPlaneShape + ".worldSpace[0]", infoNode + ".inputSurface")
         cmds.setAttr(infoNode + ".parameterV", ((1/float(totalJoints))*j) )
         cmds.setAttr(infoNode + ".parameterU", 0.5)
         # create and parent groups to calculate:
         posGrp = cmds.group(n=name+"Pos"+str(j)+"_Grp", empty=True)
         upGrp  = cmds.group(n=name+"Up"+str(j)+"_Grp", empty=True)
         aimGrp = cmds.group(n=name+"Aim"+str(j)+"_Grp", empty=True)
         cmds.parent(upGrp, aimGrp, posGrp, relative=True)
         # connect groups translations:
         cmds.connectAttr(infoNode + ".position", posGrp + ".translate", force=True)
         cmds.connectAttr(infoNode + ".tangentU", upGrp + ".translate", force=True)
         cmds.connectAttr(infoNode + ".tangentV", aimGrp + ".translate", force=True)
         # create joint:
         cmds.select(clear=True)
         joint = cmds.joint(name=name+"_%02d_Jnt"%j)
         jointList.append(joint)
         cmds.addAttr(joint, longName='dpAR_joint', attributeType='float', keyable=False)
         # parent the joint to the groups:
         cmds.parent(joint, posGrp, relative=True)
         jointGrp = cmds.group(joint, name=name+"Joint"+str(j)+"_Grp")
         jointGrpList.append(jointGrp)
         # create aimConstraint from aimGrp to jointGrp:
         cmds.aimConstraint(aimGrp, jointGrp, offset=(0, 0, 0), weight=1, aimVector=(0, 1, 0), upVector=(0, 0, 1), worldUpType="object", worldUpObject=upGrp, n=name+"Ribbon"+str(j)+"_AimConstraint" )
         # parent this ribbonPos to the ribbonGrp:
         cmds.parent(posGrp, ribbonGrp, absolute=True)
         # joint labelling:
         utils.setJointLabel(joint, jointLabelNumber, 18, jointLabelName+"_%02d"%j)
     return [ribbonNurbsPlane, ribbonNurbsPlaneShape, jointGrpList, jointList]
コード例 #27
0
 def test_createBindJoints(self):
     #--- Setup the scene
     plane = cmds.nurbsPlane( w=1, lengthRatio=5, d=3, u=1, v=6, ax=[0, 0, 1])[0]
     follicles = self.rig._createFollicles(name='test', plane=plane, num=6)
     
     #--- Call method, get results
     result = self.rig._createBindJoints(name='test', parents=follicles)
     
     #--- Check Results
     joints = ['test_'+str(x+1).zfill(2)+'_jnt_deform' for x in range(6)]
     self.test.assertListEqual(result, joints)
     for j in result:
         self.assertTrue(cmds.objExists(j))
コード例 #28
0
    def test_skinPlane(self):    
        #--- Setup the scene
        plane = cmds.nurbsPlane( w=1, lengthRatio=5, d=3, u=1, v=6, ax=[0, 0, 1])[0]
        joints = []
        joints.append(cmds.joint(p=(0, 0, 0)))
        joints.append(cmds.joint(p=(0, 2.5, 0)))
        joints.append(cmds.joint(p=(0, 5, 0)))        

        #--- Call method, get results
        result = self.rig._skinPlane(plane=plane, joints=joints)
        
        #--- Check Results        
        sc = mel.eval('findRelatedSkinCluster("%s");'%plane)
        self.assertEqual(sc,'skinCluster1')
コード例 #29
0
ファイル: ribbon.py プロジェクト: jdynamite/autorigger
    def build(self):
        #create the ribbon rig
        self.setup()

        #create the plane
        self.plane = cmds.nurbsPlane(n=("{0}_surf".format(self.nameSpace)),
                                     u=1,
                                     v=3,
                                     w=1,
                                     lr=float(self.jointAmmount) - 1)
        cmds.move(0, self.middleList, 0)
        cmds.rotate(0, 90, 0)
        cmds.makeIdentity(apply=True)
        self.planeShape = cmds.listRelatives(self.plane, s=True)
        #cmds.delete(constructionHistory=True)

        #create 3 follicles
        self.follicles.append(
            self.createFollicle(self.planeShape[0], "lo", parameterV=0.175))
        self.follicles.append(
            self.createFollicle(self.planeShape[0], "mid", parameterV=0.5))
        self.follicles.append(
            self.createFollicle(self.planeShape[0], "up", parameterV=0.825))
        self.follicles.append(
            self.createFollicle(self.planeShape[0], "end", parameterV=1))

        #skin the plane
        cmds.skinCluster(self.ribbonJnts[0],
                         self.ribbonJnts[1],
                         self.ribbonJnts[-1],
                         self.plane[0],
                         dr=3,
                         mi=2,
                         sw=1)

        #parentConstraint follicle over midCtrl
        #cmds.parentConstraint( self.follicleTransform, self.getMidZeroGroup, mo=True )
        cmds.parent(self.plane[0], self.masterGrp)

        #parent follicle
        #group follicles
        folGrp = cmds.createNode('transform',
                                 n=('grpFol_{0}').format(self.nameSpace))
        cmds.parent(self.follicles[0], self.follicles[1], self.follicles[2],
                    self.follicles[3], folGrp)
        cmds.parent(folGrp, self.masterGrp)

        #parent all Groups under master
        cmds.parent(self.ctrlGrp, self.masterGrp)
        cmds.parent(self.midLoc.getZeroGroup1(), self.masterGrp)
コード例 #30
0
ファイル: dpControls.py プロジェクト: nilouco/dpAutoRigSystem
def createSimpleRibbon(name='noodle', totalJoints=6):
    """ Creates a Ribbon system.
        Receives the total number of joints to create.
        Returns the ribbon nurbs plane, the joints groups and joints created.
    """
    # create a ribbonNurbsPlane:
    ribbonNurbsPlane = cmds.nurbsPlane(name=name+"RibbonNurbsPlane", constructionHistory=False, object=True, polygon=0, axis=(0, 1, 0), width=1, lengthRatio=8, patchesV=totalJoints)[0]
    # get the ribbonNurbsPlane shape:
    ribbonNurbsPlaneShape = cmds.listRelatives(ribbonNurbsPlane, shapes=True, children=True)[0]
    # make this ribbonNurbsPlane as template, invisible and not renderable:
    cmds.setAttr(ribbonNurbsPlane+".template", 1)
    cmds.setAttr(ribbonNurbsPlane+".visibility", 0)
    setNotRenderable([ribbonNurbsPlaneShape])
    # make this ribbonNurbsPlane as not skinable from dpAR_UI:
    cmds.addAttr(ribbonNurbsPlane, longName="doNotSkinIt", attributeType="bool", keyable=True)
    cmds.setAttr(ribbonNurbsPlane+".doNotSkinIt", 1)
    # create groups to be used as a root of the ribbon system:
    ribbonGrp = cmds.group(ribbonNurbsPlane, n=name+"_RibbonJoint_Grp")
    # create joints:
    jointList, jointGrpList = [], []
    for j in range(totalJoints+1):
        # create pointOnSurfaceInfo:
        infoNode = cmds.createNode('pointOnSurfaceInfo', name=name+"_POSI"+str(j))
        # setting parameters worldSpace, U and V:
        cmds.connectAttr(ribbonNurbsPlaneShape + ".worldSpace[0]", infoNode + ".inputSurface")
        cmds.setAttr(infoNode + ".parameterV", ((1/float(totalJoints))*j) )
        cmds.setAttr(infoNode + ".parameterU", 0.5)
        # create and parent groups to calculate:
        posGrp = cmds.group(n=name+"Pos"+str(j)+"_Grp", empty=True)
        upGrp  = cmds.group(n=name+"Up"+str(j)+"_Grp", empty=True)
        aimGrp = cmds.group(n=name+"Aim"+str(j)+"_Grp", empty=True)
        cmds.parent(upGrp, aimGrp, posGrp, relative=True)
        # connect groups translations:
        cmds.connectAttr(infoNode + ".position", posGrp + ".translate", force=True)
        cmds.connectAttr(infoNode + ".tangentU", upGrp + ".translate", force=True)
        cmds.connectAttr(infoNode + ".tangentV", aimGrp + ".translate", force=True)
        # create joint:
        cmds.select(clear=True)
        joint = cmds.joint(name=name+str(j)+"_Jnt")
        jointList.append(joint)
        cmds.addAttr(joint, longName='dpAR_joint', attributeType='float', keyable=False)
        # parent the joint to the groups:
        cmds.parent(joint, posGrp, relative=True)
        jointGrp = cmds.group(joint, name=name+"Joint"+str(j)+"_Grp")
        jointGrpList.append(jointGrp)
        # create aimConstraint from aimGrp to jointGrp:
        cmds.aimConstraint(aimGrp, jointGrp, offset=(0, 0, 0), weight=1, aimVector=(0, 1, 0), upVector=(0, 0, 1), worldUpType="object", worldUpObject=upGrp, n=name+"Ribbon"+str(j)+"_AimConstraint" )
        # parent this ribbonPos to the ribbonGrp:
        cmds.parent(posGrp, ribbonGrp, absolute=True)
    return [ribbonNurbsPlane, ribbonNurbsPlaneShape, jointGrpList, jointList]
コード例 #31
0
ファイル: surface.py プロジェクト: jonntd/japeto
def readSurfaceInfo(filePath):
    dataDict = jsonData.readDicts(filePath)
    surfaces = []
    for surface in dataDict:
        surfaces.append(surface)
        cmds.select(cl=True)
        cmds.nurbsPlane(name=surface, ch=1)
        for key in dataDict[surface].keys():
            # '''
            # if isinstance(dataDict[key], list):
            #     dataDict[key] = common.ddcommon.listToStringArray(dataDict[key])
            # '''
            if isinstance(dataDict[surface][key], list):
                if key == "position":
                    cmds.setAttr(
                        "%s.translate" % (surface),
                        dataDict[surface][key][0],
                        dataDict[surface][key][1],
                        dataDict[surface][key][2],
                    )
                    continue
                else:
                    mel.eval(
                        "nurbsPlane -e -%s %s %s %s %s"
                        % (
                            key,
                            str(dataDict[surface][key][0]),
                            str(dataDict[surface][key][1]),
                            str(dataDict[surface][key][2]),
                            surface,
                        )
                    )
                    continue

            mel.eval("nurbsPlane -e -%s %f %s" % (key, dataDict[surface][key], surface))

    return dataDict
コード例 #32
0
 def test_createFollicles(self):
     #--- Setup the scene
     plane = cmds.nurbsPlane( w=1, lengthRatio=5, d=3, u=1, v=6, ax=[0, 0, 1])[0]
     
     #--- Call method, get results
     result = self.rig._createFollicles(name='test', plane=plane, num=6)
     
     #--- Check Results
     expected = ['test_'+(plane+'ShapeFollicle_')+str(x+1).zfill(2) for x in range(6)]
     self.test.assertListEqual(l1=result, l2=expected)
     
     for each in result:
         self.assertTrue(cmds.objExists(each))
         transform = cmds.listRelatives(each,parent=True)[0]
         self.assertEqual(cmds.listRelatives(transform,parent=True)[0], 'test_rbbnFollicles_grp')
         self.assertFalse(cmds.listRelatives(each,c=True))
コード例 #33
0
 def createNurbsAttachSurface(self, *args):
     """ creates a plain nurbs surface. Optionally you can use your own nurbs surface """
     prefix = str(self.faceControlCreate.prefix_le.text())
     uPatches = self.faceControlCreate.uPatch_hs.value()
     vPatches = self.faceControlCreate.vPatch_hs.value()
     nurbsObject = cmds.nurbsPlane(p=[0, 0, 0],
                                   ax=[0, 1, 0],
                                   w=1,
                                   lr=1,
                                   d=3,
                                   u=uPatches,
                                   v=vPatches,
                                   ch=1,
                                   n=prefix + '_attachSurface#')
     self.faceControlCreate.nurbsSurface_le.setText(nurbsObject[0])
     print('complete', 'Slide Nurbs Surface loaded.')
コード例 #34
0
def CreateCustomNurbsCurve(jointName, nurbShape, nurbSize):
    newName = jointName.replace('_JNT', '_CTRL')
    newNurb = cmds.group(em=True, n=newName)
    if (nurbShape == 'Square'):
        tempNurb = cmds.nurbsPlane(p=(0, 0, 0), ax=(0, 1, 0), w=nurbSize, ch=0)
    if (nurbShape == 'Cube'):
        tempNurb = cmds.nurbsCube(p=(0, 0, 0), ax=(0, 1, 0), w=nurbSize, ch=0)
    cmds.DuplicateCurve()
    shapes = cmds.listRelatives('duplicatedCurve*', c=True, s=True)
    cmds.select(shapes, r=True)
    cmds.select(newNurb, add=True)
    cmds.parent(r=True, s=True)
    cmds.select('duplicatedCurve*', r=True)
    cmds.select('duplicatedCurveShape*', d=True)
    cmds.select(tempNurb, add=True)
    cmds.delete()
    return newNurb
コード例 #35
0
 def _createPlane(self,name=None,
                     baseTransform=None,
                     targetTransform=None,
                     aim=None,up=None,wup=None):
     if self.logger: self.logger.info('_createPlane(): Starting...')
     
     # Define vectors
     if aim == 'x': aimV = [1,0,0]
     if aim == 'y': aimV = [0,1,0]
     if aim == 'z': aimV = [0,0,1]
     
     if up == 'x': upV = [1,0,0]
     if up == 'y': upV = [0,1,0]
     if up == 'z': upV = [0,0,1]  
     
     if wup == 'x': wupV = [1,0,0]
     if wup == 'y': wupV = [0,1,0]
     if wup == 'z': wupV = [0,0,1]  
     
     # Get distance between base and target
     p1 = cmds.xform(baseTransform,q=1,ws=1,rp=1)
     p2 = cmds.xform(targetTransform,q=1,ws=1,rp=1)
     dist = math.sqrt( (p2[0]-p1[0])*(p2[0]-p1[0]) + \
                       (p2[1]-p1[1])*(p2[1]-p1[1]) + \
                       (p2[2]-p1[2])*(p2[2]-p1[2]) )
     
     # Create the plane
     plane = cmds.nurbsPlane(n=name+'_multiAxisRigPlane',axis=[0,90,0])[0]
     cmds.delete(plane,ch=True)
     
     # Snap/Constraint to baseTransform
     cmds.pointConstraint(baseTransform,plane,mo=False,n=name+'_multiAxisRigPlanePointConst')
     
     # Scale it so plane is twice the length of the base/target distance
     cmds.setAttr('%s.scaleX'%plane, dist*2)
     cmds.setAttr('%s.scaleY'%plane, dist*2)
     cmds.setAttr('%s.scaleZ'%plane, dist*2)
     
     # Aim at targetTransform
     cmds.delete( cmds.aimConstraint(targetTransform,plane,aim=aimV,u=upV) )
     
     if self.logger: self.logger.info('_createPlane(): End...\nReturned: %s'%plane)
     return plane
コード例 #36
0
    def test_skinPlane(self):
        #--- Setup the scene
        plane = cmds.nurbsPlane(w=1,
                                lengthRatio=5,
                                d=3,
                                u=1,
                                v=6,
                                ax=[0, 0, 1])[0]
        joints = []
        joints.append(cmds.joint(p=(0, 0, 0)))
        joints.append(cmds.joint(p=(0, 2.5, 0)))
        joints.append(cmds.joint(p=(0, 5, 0)))

        #--- Call method, get results
        result = self.rig._skinPlane(plane=plane, joints=joints)

        #--- Check Results
        sc = mel.eval('findRelatedSkinCluster("%s");' % plane)
        self.assertEqual(sc, 'skinCluster1')
コード例 #37
0
ファイル: ribbon.py プロジェクト: jdynamite/autorigger
    def build(self):
        #create the ribbon rig
        self.setup()

        #create the plane
        self.plane = cmds.nurbsPlane(n=("{0}_surf".format(self.nameSpace)),u=1,v=3,w=1,lr=float(self.jointAmmount)-1)
        cmds.move(0,self.middleList,0)
        cmds.rotate(0,90,0)
        cmds.makeIdentity( apply=True )
        self.planeShape = cmds.listRelatives(self.plane,s=True)
        #cmds.delete(constructionHistory=True)

        #create 3 follicles
        self.follicles.append( self.createFollicle( self.planeShape[0], "lo", parameterV=0.175 ) )
        self.follicles.append( self.createFollicle( self.planeShape[0], "mid", parameterV=0.5 ) )
        self.follicles.append( self.createFollicle( self.planeShape[0], "up", parameterV=0.825 ) )
        self.follicles.append( self.createFollicle( self.planeShape[0], "end", parameterV=1 ) )



        #skin the plane
        cmds.skinCluster( self.ribbonJnts[0],
                          self.ribbonJnts[1],
                          self.ribbonJnts[-1],
                          self.plane[0],
                          dr=3,
                          mi=2,

                          sw=1)

        #parentConstraint follicle over midCtrl
        #cmds.parentConstraint( self.follicleTransform, self.getMidZeroGroup, mo=True )
        cmds.parent ( self.plane[0], self.masterGrp)

        #parent follicle
        #group follicles
        folGrp = cmds.createNode('transform', n=('grpFol_{0}').format(self.nameSpace))
        cmds.parent( self.follicles[0], self.follicles[1], self.follicles[2], self.follicles[3], folGrp)
        cmds.parent ( folGrp, self.masterGrp)

        #parent all Groups under master
        cmds.parent ( self.ctrlGrp, self.masterGrp )
        cmds.parent ( self.midLoc.getZeroGroup1(), self.masterGrp)
コード例 #38
0
    def test_createBindJoints(self):
        #--- Setup the scene
        plane = cmds.nurbsPlane(w=1,
                                lengthRatio=5,
                                d=3,
                                u=1,
                                v=6,
                                ax=[0, 0, 1])[0]
        follicles = self.rig._createFollicles(name='test', plane=plane, num=6)

        #--- Call method, get results
        result = self.rig._createBindJoints(name='test', parents=follicles)

        #--- Check Results
        joints = [
            'test_' + str(x + 1).zfill(2) + '_jnt_deform' for x in range(6)
        ]
        self.test.assertListEqual(result, joints)
        for j in result:
            self.assertTrue(cmds.objExists(j))
コード例 #39
0
    def mk_ribbon(self):
        """
        Create the ribbon that will be the base for your rig
        """
        width = mc.arclen(self.proxieCrv)
        ratio = 1.0 / width
        ribbon = "{}{}".format(self.name, RIB)
        grp = "{}{}".format(ribbon, GRP)

        if not mc.objExists(ribbon):
            ribbon = mc.nurbsPlane(p=(0, 0, 0), ax=(0, 1, 0), w=width, lr=ratio,
                                   d=3, u=self.spans, v=1, name=ribbon, ch=True)[0]

        if not mc.listRelatives(ribbon, p=True) == grp:
            self.mk_parent_grp(ribbon)

        mc.setAttr("{}.rotateOrder".format(grp), 1)
        mc.xform(ribbon, piv=[-(width * .5), 0, 0])

        self.ribbon = ribbon

        return ribbon
コード例 #40
0
    def test_setupHeirarchy(self):
        #--- Setup the scene
        startJnt = cmds.joint(n='startJnt', p=(3, 0, 0))
        endJnt = cmds.joint(n='endJnt', p=(3, 5, -2))
        locs = []
        locs.append(cmds.spaceLocator(n='test_topLoc_pos', p=(0, 0, 1))[0])
        locs.append(cmds.spaceLocator(n='test_midLoc_pos', p=(1, 2, 2))[0])
        locs.append(cmds.spaceLocator(n='test_btmLoc_pos', p=(2, 4, 3))[0])

        locGrp = cmds.group(em=True)
        fGrp = cmds.group(em=True)
        plane = cmds.nurbsPlane(w=1,
                                lengthRatio=5,
                                d=3,
                                u=1,
                                v=6,
                                ax=[0, 0, 1])[0]

        for each in locs:
            cmds.parent(each, locGrp)

        #--- Call method, get results
        result = self.rig._setupHeirarchy(name='test',
                                          startObj=startJnt,
                                          endObj=endJnt,
                                          locGrp=locGrp,
                                          plane=plane,
                                          follicleGrp=fGrp)

        #--- Check Results
        expectedTopNode = 'test_rbbnTopNode'
        self.assertEqual(result, expectedTopNode)
        self.assertTrue(cmds.objExists(expectedTopNode))
        self.assertEqual(
            cmds.listRelatives(fGrp, parent=True)[0], expectedTopNode)
        self.assertEqual(
            cmds.listRelatives(plane, parent=True)[0], expectedTopNode)
        self.test.assertConstrained(startJnt, locs[2], type='parent')
        self.test.assertConstrained(endJnt, locs[0], type='parent')
コード例 #41
0
ファイル: snapShot2.py プロジェクト: adamfok/afok_toolset
def createGuiPlane(objs, axis=[0,0,1], width=400, height=600, offset=1.15):
	
	# build the bounding box and find it's centre
    bBox = createBoundingBox(objs)
    bBoxDimension = cmds.getAttr(bBox + ".boxDimension")[0]
    
    if axis[0]: #x axis
        boxHeight = bBoxDimension[1]
        boxWidth = bBoxDimension[2]
        
    if axis[1]: #y axis
        boxHeight = bBoxDimension[2]
        boxWidth = bBoxDimension[0]
        
    if axis[2]: #z axis
        boxHeight = bBoxDimension[1]
        boxWidth = bBoxDimension[0]        
    
    fitHeight = boxHeight / height
    fitWidth = boxWidth / width

    if fitHeight * width < boxWidth:
        fitHeight = 0
        
    if fitWidth * height < boxHeight:
        fitWidth = 0
        
    fitScale = (fitHeight or fitWidth ) * offset
    
    w = width * fitScale
    lr = height*1.0 / width*1.0
    
    guiPlane = cmds.nurbsPlane(ax = axis, w=w, lr=lr, d=1, u=1, v=1, ch=0)[0]
    
    cmds.delete(cmds.pointConstraint(bBox, guiPlane, maintainOffset=False))
    
    cmds.delete(bBox)
    
    return guiPlane
コード例 #42
0
 def createPlane(self):
     # First we find the distance between the two locators.
     t1 = cmds.getAttr("%s.translate" % self.locators[0][0])
     t2 = cmds.getAttr("%s.translate" % self.locators[1][0])
     distMeasure = cmds.distanceDimension(sp=(t1[0][0], t1[0][1], t1[0][2]),
                                          ep=(t2[0][0], t2[0][1], t2[0][2]))
     self.distance = cmds.getAttr("%s.distance" % distMeasure)
     cmds.delete(cmds.pickWalk(distMeasure, direction="up"))
     # Then we create a plane, freeze its transforms, and delete its construction history.
     plane = cmds.nurbsPlane(name=self.name + "_GEO",
                             width=self.distance,
                             lengthRatio=(1.0 / self.joints),
                             patchesU=self.joints,
                             axis=(0, 0, 1))
     cmds.rotate(0, 0, 90, plane[0])
     cmds.makeIdentity(plane[0],
                       apply=True,
                       translate=True,
                       rotate=True,
                       scale=True)
     cmds.delete(plane, constructionHistory=True)
     del plane[1]
     return plane[0]
コード例 #43
0
def createRibbon(jntLs):
    totalDist = 0
    cmds.select(clear=True)
    jntNum = len(jntLs)
    faceNum = jntNum * 5
    offSetFace = 5
    for i in xrange(len(jntLs)):
        if i != 0:
            totalDist += cmds.getAttr(jntLs[i] + ".translateX")
    length = totalDist / (faceNum - 5) * faceNum
    plane = cmds.nurbsPlane(axis=[0, 1, 0],
                            constructionHistory=True,
                            degree=3,
                            lengthRatio=length,
                            pivot=[0, 0, 0],
                            patchesU=1,
                            patchesV=faceNum)[0]
    cmds.setAttr(plane + ".translateX", length / 2)
    cmds.setAttr(plane + ".rotateX", 90)
    cmds.setAttr(plane + ".rotateZ", -90)
    cmds.makeIdentity(plane, apply=True, translate=True, rotate=True)
    cmds.xform(plane, pivots=[offSetFace / 2.0 * length / faceNum, 0, 0])
    cons = cmds.parentConstraint(jntLs[0], plane, maintainOffset=False)
    cmds.delete(cons)
コード例 #44
0
    def testAnimNurbsPlaneWrite(self, wfg=False):

        ret = MayaCmds.nurbsPlane(p=(0, 0, 0), ax=(0, 1, 0), w=1, lr=1, d=3, u=5, v=5, ch=0)
        name = ret[0]

        MayaCmds.lattice(name, dv=(4, 5, 4), oc=True)
        MayaCmds.select("ffd1Lattice.pt[1:2][0:4][1:2]", r=True)

        MayaCmds.currentTime(1, update=True)
        MayaCmds.setKeyframe()
        MayaCmds.currentTime(24, update=True)
        MayaCmds.setKeyframe()
        MayaCmds.currentTime(12, update=True)
        MayaCmds.move(0, 0.18, 0, r=True)
        MayaCmds.scale(2.5, 1.0, 2.5, r=True)
        MayaCmds.setKeyframe()

        MayaCmds.curveOnSurface(
            name,
            uv=((0.597523, 0), (0.600359, 0.271782), (0.538598, 0.564218), (0.496932, 0.779936), (0.672153, 1)),
            k=(0, 0, 0, 0.263463, 0.530094, 0.530094, 0.530094),
        )

        curvename = MayaCmds.curveOnSurface(
            name,
            uv=(
                (0.170718, 0.565967),
                (0.0685088, 0.393034),
                (0.141997, 0.206296),
                (0.95, 0.230359),
                (0.36264, 0.441381),
                (0.251243, 0.569889),
            ),
            k=(0, 0, 0, 0.200545, 0.404853, 0.598957, 0.598957, 0.598957),
        )
        MayaCmds.closeCurve(curvename, ch=1, ps=1, rpo=1, bb=0.5, bki=0, p=0.1, cos=1)

        MayaCmds.trim(name, lu=0.23, lv=0.39)

        degreeU = MayaCmds.getAttr(name + ".degreeU")
        degreeV = MayaCmds.getAttr(name + ".degreeV")
        spansU = MayaCmds.getAttr(name + ".spansU")
        spansV = MayaCmds.getAttr(name + ".spansV")
        formU = MayaCmds.getAttr(name + ".formU")
        formV = MayaCmds.getAttr(name + ".formV")
        minU = MayaCmds.getAttr(name + ".minValueU")
        maxU = MayaCmds.getAttr(name + ".maxValueU")
        minV = MayaCmds.getAttr(name + ".minValueV")
        maxV = MayaCmds.getAttr(name + ".maxValueV")

        MayaCmds.createNode("surfaceInfo")
        MayaCmds.connectAttr(name + ".worldSpace", "surfaceInfo1.inputSurface", force=True)

        MayaCmds.currentTime(1, update=True)
        controlPoints = MayaCmds.getAttr("surfaceInfo1.controlPoints[*]")
        knotsU = MayaCmds.getAttr("surfaceInfo1.knotsU[*]")
        knotsV = MayaCmds.getAttr("surfaceInfo1.knotsV[*]")

        MayaCmds.currentTime(12, update=True)
        controlPoints2 = MayaCmds.getAttr("surfaceInfo1.controlPoints[*]")
        knotsU2 = MayaCmds.getAttr("surfaceInfo1.knotsU[*]")
        knotsV2 = MayaCmds.getAttr("surfaceInfo1.knotsV[*]")

        if wfg:
            self.__files.append(util.expandFileName("testAnimNurbsPlane.abc"))

            MayaCmds.AbcExport(
                j="-fr 1 24 -frs -0.25 -frs 0.0 -frs 0.25 -wfg -root %s -file %s" % (name, self.__files[-1])
            )

            # reading test
            MayaCmds.AbcImport(self.__files[-1], mode="open")
        else:
            self.__files.append(util.expandFileName("testAnimNurbsPlane.abc"))
            self.__files.append(util.expandFileName("testAnimNurbsPlane01_14.abc"))
            self.__files.append(util.expandFileName("testAnimNurbsPlane15_24.abc"))

            MayaCmds.AbcExport(j="-fr 1 14 -root %s -file %s" % (name, self.__files[-2]))
            MayaCmds.AbcExport(j="-fr 15 24 -root %s -file %s" % (name, self.__files[-1]))

            # use AbcStitcher to combine two files into one
            subprocess.call(self.__abcStitcher + self.__files[-3:])

            # reading test
            MayaCmds.AbcImport(self.__files[-3], mode="open")

        self.failUnlessEqual(degreeU, MayaCmds.getAttr(name + ".degreeU"))
        self.failUnlessEqual(degreeV, MayaCmds.getAttr(name + ".degreeV"))
        self.failUnlessEqual(spansU, MayaCmds.getAttr(name + ".spansU"))
        self.failUnlessEqual(spansV, MayaCmds.getAttr(name + ".spansV"))
        self.failUnlessEqual(formU, MayaCmds.getAttr(name + ".formU"))
        self.failUnlessEqual(formV, MayaCmds.getAttr(name + ".formV"))
        self.failUnlessEqual(minU, MayaCmds.getAttr(name + ".minValueU"))
        self.failUnlessEqual(maxU, MayaCmds.getAttr(name + ".maxValueU"))
        self.failUnlessEqual(minV, MayaCmds.getAttr(name + ".minValueV"))
        self.failUnlessEqual(maxV, MayaCmds.getAttr(name + ".maxValueV"))

        MayaCmds.createNode("surfaceInfo")
        MayaCmds.connectAttr(name + ".worldSpace", "surfaceInfo1.inputSurface", force=True)

        MayaCmds.currentTime(1, update=True)
        errmsg = "At frame #1, Nurbs Plane's control point #%d.%s not equal"
        for i in range(0, len(controlPoints)):
            cp1 = controlPoints[i]
            cp2 = MayaCmds.getAttr("surfaceInfo1.controlPoints[%d]" % (i))
            self.failUnlessAlmostEqual(cp1[0], cp2[0][0], 3, errmsg % (i, "x"))
            self.failUnlessAlmostEqual(cp1[1], cp2[0][1], 3, errmsg % (i, "y"))
            self.failUnlessAlmostEqual(cp1[2], cp2[0][2], 3, errmsg % (i, "z"))

        errmsg = "At frame #1, Nurbs Plane's control knotsU #%d not equal"
        for i in range(0, len(knotsU)):
            ku1 = knotsU[i]
            ku2 = MayaCmds.getAttr("surfaceInfo1.knotsU[%d]" % (i))
            self.failUnlessAlmostEqual(ku1, ku2, 3, errmsg % (i))

        errmsg = "At frame #1, Nurbs Plane's control knotsV #%d not equal"
        for i in range(0, len(knotsV)):
            kv1 = knotsV[i]
            kv2 = MayaCmds.getAttr("surfaceInfo1.knotsV[%d]" % (i))
            self.failUnlessAlmostEqual(kv1, kv2, 3, errmsg % (i))

        MayaCmds.currentTime(12, update=True)
        errmsg = "At frame #12, Nurbs Plane's control point #%d.%s not equal"
        for i in range(0, len(controlPoints2)):
            cp1 = controlPoints2[i]
            cp2 = MayaCmds.getAttr("surfaceInfo1.controlPoints[%d]" % (i))
            self.failUnlessAlmostEqual(cp1[0], cp2[0][0], 3, errmsg % (i, "x"))
            self.failUnlessAlmostEqual(cp1[1], cp2[0][1], 3, errmsg % (i, "y"))
            self.failUnlessAlmostEqual(cp1[2], cp2[0][2], 3, errmsg % (i, "z"))

        errmsg = "At frame #12, Nurbs Plane's control knotsU #%d not equal"
        for i in range(0, len(knotsU2)):
            ku1 = knotsU2[i]
            ku2 = MayaCmds.getAttr("surfaceInfo1.knotsU[%d]" % (i))
            self.failUnlessAlmostEqual(ku1, ku2, 3, errmsg % (i))

        errmsg = "At frame #12, Nurbs Plane's control knotsV #%d not equal"
        for i in range(0, len(knotsV2)):
            kv1 = knotsV2[i]
            kv2 = MayaCmds.getAttr("surfaceInfo1.knotsV[%d]" % (i))
            self.failUnlessAlmostEqual(kv1, kv2, 3, errmsg % (i))

        MayaCmds.currentTime(24, update=True)
        errmsg = "At frame #24, Nurbs Plane's control point #%d.%s not equal"
        for i in range(0, len(controlPoints)):
            cp1 = controlPoints[i]
            cp2 = MayaCmds.getAttr("surfaceInfo1.controlPoints[%d]" % (i))
            self.failUnlessAlmostEqual(cp1[0], cp2[0][0], 3, errmsg % (i, "x"))
            self.failUnlessAlmostEqual(cp1[1], cp2[0][1], 3, errmsg % (i, "y"))
            self.failUnlessAlmostEqual(cp1[2], cp2[0][2], 3, errmsg % (i, "z"))

        errmsg = "At frame #24, Nurbs Plane's control knotsU #%d not equal"
        for i in range(0, len(knotsU)):
            ku1 = knotsU[i]
            ku2 = MayaCmds.getAttr("surfaceInfo1.knotsU[%d]" % (i))
            self.failUnlessAlmostEqual(ku1, ku2, 3, errmsg % (i))

        errmsg = "At frame #24, Nurbs Plane's control knotsV #%d not equal"
        for i in range(0, len(knotsV)):
            kv1 = knotsV[i]
            kv2 = MayaCmds.getAttr("surfaceInfo1.knotsV[%d]" % (i))
            self.failUnlessAlmostEqual(kv1, kv2, 3, errmsg % (i))
コード例 #45
0
ファイル: core.py プロジェクト: pecktd/pkrig
def nurbsPlane( *args , **kwargs ) :
	return Dag( mc.nurbsPlane( *args , **kwargs )[0] )
コード例 #46
0
  cmds.group(em=True, n= 'facialSystems_c_grp')
cmds.parent('facialSystems_c_grp', 'facialRig_c_grp')
cmds.parent(system_grp, 'facialSystems_c_grp')
cmds.group(em=True, n='eyelidsGeoSkin_c_grp')
cmds.group(em=True, n='eyelidsSystem_c_grp')
for side in 'rl':
    grp1 = cmds.group(em=True, n='eyelidsMainSkin_{}_grp'.format(side))
    grp2 = cmds.group(em=True, n='eyelidsSpecificSkin_{}_grp'.format(side))
    cmds.parent(grp1, grp2, system_grp)
    pop = cmds.group(em=True, n= 'eyelidsSystemJoints_{}_grp'.format(side))
    cmds.parent(pop, 'eyelidsSystem_c_grp')
cmds.group(em=True, n='eyelidsGeoSkin_c_grp')
cmds.group(em=True, n='eyelidsSystem_c_grp')
cmds.parent('eyelidsSystem_c_grp', 'eyelidsGeoSkin_c_grp', system_grp)

nurb = cmds.nurbsPlane(n='upEyelidMain_l_nurbs', ax=(0,1,0), w=True, lr= True, d = 3, u = 15, v=1, ch=1) 


#Creation

#Main Structure
cmds.duplicate('upEyelidMain_l_nurbs', n='dwEyelidMain_l_nurbs')

cmds.duplicate('upEyelidMain_l_nurbs', n='dwEyelidMain_r_nurbs')
cmds.duplicate('upEyelidMain_l_nurbs', n='upEyelidMain_r_nurbs')

inv = cmds.group(em=True)
cmds.parent('upEyelidMain_r_nurbs', 'dwEyelidMain_r_nurbs', inv)
cmds.setAttr('{}.sx'.format(inv), -1)
cmds.select(inv)
cmds.FreezeTransformations(inv)
コード例 #47
0
ファイル: red.py プロジェクト: chirs/studio5
import maya.cmds as cmds

# Create a NURBS plane.
cmds.nurbsPlane( d=3, p=(0, 0, 0), lr=1, axis=(0, 0, 0), n='plane1' )

# Make it red.
cmds.sets( name='redMaterialGroup', renderable=True, empty=True )
cmds.shadingNode( 'phong', name='redShader', asShader=True )
cmds.setAttr( 'redShader.color', 1, 0, 0, type='double3' )
cmds.surfaceShaderList( 'redShader', add='redMaterialGroup' )
cmds.sets( 'plane1', e=True, forceElement='redMaterialGroup' )

コード例 #48
0
def nurbsPlane(*args, **kwargs):
    return Dag(mc.nurbsPlane(*args, **kwargs)[0])
コード例 #49
0
ファイル: jcRibbon.py プロジェクト: utsdab/usr
def createRibbon(axis=(0, 0, 1), name='xxxx', horizontal=False, numJoints=3, guias=None, v=True, s=0, firstLimb=True, upCtrl=None, ctrlRadius=1, worldRef="worldRef"):
        retDict = {}
        
        #define variables
        top_Loc = []
        mid_Loc = []
        bttm_Loc = []
        rb_Jnt = []
        drv_Jnt =[]
        fols = []
        aux_Jnt = []
        ribbon = ''
        extraCtrlList = []

        #define attributes
        limbManualVVAttr = "limbManualVolume"
        limbVVAttr       = "limbVolumeVariation"
        limbMinVVAttr    = "limbMinVolume"

        #create a nurbsPlane based in the choose orientation option
        if horizontal:
            ribbon =cmds.nurbsPlane(ax=axis, w=numJoints, lr=(1/float(numJoints)), d=3, u=numJoints, v=1, ch=0, name=name+'_Plane')[0]
            cmds.rebuildSurface(ribbon, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, sv=1, du=3, dv=1, tol=0.01, fr=0, dir=1) 
        else:
            ribbon =cmds.nurbsPlane(ax=axis, w=1, lr=numJoints, d=3, u=1, v=numJoints, ch=0, name=name+'_Plane')[0]
            cmds.rebuildSurface(ribbon, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, su=1, du=1, dv=3, tol=0.01, fr=0, dir=0) 
        # make this ribbonNurbsPlane as not skinable from dpAR_UI:
        cmds.addAttr(ribbon, longName="doNotSkinIt", attributeType="bool", keyable=True)
        cmds.setAttr(ribbon+".doNotSkinIt", 1)
        #call the function to create follicles and joint in the nurbsPlane
        results = createFollicles(rib=ribbon, num=numJoints, name=name, horizontal=horizontal)
        rb_Jnt = results[0]
        fols = results[1]
        #create locator controls for the middle of the ribbon
        mid_Loc.append(cmds.spaceLocator(name=name+'_Mid_Pos_Loc')[0])
        mid_Loc.append(cmds.spaceLocator(name=name+'_Mid_Aim_Loc')[0])
        mid_Loc.append(cmds.spaceLocator(name=name+'_Mid_Off_Loc')[0])
        mid_Loc.append(cmds.spaceLocator(name=name+'_Mid_Up_Loc')[0])
        #parent correctly the middle locators
        cmds.parent(mid_Loc[2], mid_Loc[1], relative=True)
        cmds.parent(mid_Loc[1], mid_Loc[0], relative=True)
        cmds.parent(mid_Loc[3], mid_Loc[0], relative=True)
        #create the locators controls for the top of the ribbon
        top_Loc.append(cmds.spaceLocator(name=name+'_Top_Pos_Loc')[0])
        top_Loc.append(cmds.spaceLocator(name=name+'_Top_Aim_Loc')[0])
        top_Loc.append(cmds.spaceLocator(name=name+'_Top_Up_Loc')[0])
        #parent correctly the top locators
        cmds.parent(top_Loc[1], top_Loc[0], relative=True)
        cmds.parent(top_Loc[2], top_Loc[0], relative=True)
        #create the locators for the end of the ribbon
        bttm_Loc.append(cmds.spaceLocator(name=name+'_Bttm_Pos_Loc')[0])
        bttm_Loc.append(cmds.spaceLocator(name=name+'_Bttm_Aim_Loc')[0])
        bttm_Loc.append(cmds.spaceLocator(name=name+'_Bttm_Up_Loc')[0])
        #parent correctly the bottom locators
        cmds.parent(bttm_Loc[1], bttm_Loc[0], relative=True)
        cmds.parent(bttm_Loc[2], bttm_Loc[0], relative=True)
        
        #put the top locators in the same place of the top joint
        cmds.parent(top_Loc[0], fols[len(fols)-1], relative=True)
        cmds.parent(top_Loc[0], w=True)
        
        #put the bottom locators in the same place of the bottom joint
        cmds.parent(bttm_Loc[0], fols[0], relative=True)
        cmds.parent(bttm_Loc[0], w=True)
        cmds.select(clear=True)
        
        #create the joints that will be used to control the ribbon
        drv_Jnt = cmds.duplicate([rb_Jnt[0], rb_Jnt[(len(rb_Jnt)-1)/2], rb_Jnt[len(rb_Jnt)-1]])
        dup = cmds.duplicate([drv_Jnt[0], drv_Jnt[2]])
        drv_Jnt.append(dup[0])
        drv_Jnt.append(dup[1])
        #cmds.parent(drv_Jnt, w=True)
        for jnt in drv_Jnt:
            cmds.joint(jnt, e=True, oj='none', ch=True, zso=True);
            cmds.setAttr(jnt+'.radius', cmds.getAttr(jnt+'.radius')+0.5)
        #rename created joints
        drv_Jnt[0] = cmds.rename(drv_Jnt[0], name+'_Drv_Bttm_Jxt')
        drv_Jnt[1] = cmds.rename(drv_Jnt[1], name+'_Drv_Mid_Jxt')
        drv_Jnt[2] = cmds.rename(drv_Jnt[2], name+'_Drv_Top_Jxt')
        drv_Jnt[3] = cmds.rename(drv_Jnt[3], name+'_Drv_Bttm_End')
        drv_Jnt[4] = cmds.rename(drv_Jnt[4], name+'_Drv_Top_End')
        
        #place joints correctly accordaly with the user options choose
        if (horizontal and axis==(1, 0, 0)) or (horizontal and axis==(0, 0, 1)):
            cmds.setAttr(bttm_Loc[2]+'.translateY', 2)
            cmds.setAttr(top_Loc[2]+'.translateY', 2)
            cmds.setAttr(mid_Loc[3]+'.translateY', 2)
        elif (horizontal and axis==(0, 1, 0)) or (not horizontal and axis==(1, 0, 0)):
            cmds.setAttr(bttm_Loc[2]+'.translateZ', 2)
            cmds.setAttr(top_Loc[2]+'.translateZ', 2)
            cmds.setAttr(mid_Loc[3]+'.translateZ', 2)
        elif not horizontal and axis==(0, 1, 0) or (not horizontal and axis==(0, 0, 1)):
            cmds.setAttr(bttm_Loc[2]+'.translateX', 2)
            cmds.setAttr(top_Loc[2]+'.translateX', 2)
            cmds.setAttr(mid_Loc[3]+'.translateX', 2)
        elif horizontal and axis==(0, 0, -1):
            if firstLimb:
                cmds.setAttr(bttm_Loc[2]+'.translateY', 2)
                cmds.setAttr(top_Loc[2]+'.translateX', -2)
                cmds.setAttr(mid_Loc[3]+'.translateX', -2)
                cmds.setAttr(mid_Loc[3]+'.translateY', 2)
            else:
                if s == 0:
                    cmds.setAttr(bttm_Loc[2]+'.translateX', -2)
                    cmds.setAttr(top_Loc[2]+'.translateY', -2)
                    cmds.setAttr(mid_Loc[3]+'.translateX', -2)
                    cmds.setAttr(mid_Loc[3]+'.translateY', 2)
                else:
                    cmds.setAttr(bttm_Loc[2]+'.translateX', -2)
                    cmds.setAttr(top_Loc[2]+'.translateY', -2)
                    cmds.setAttr(mid_Loc[3]+'.translateX', -2)
                    cmds.setAttr(mid_Loc[3]+'.translateY', 2)
                
        
        #create auxiliary joints that will be used to control the ribbon
        aux_Jnt.append(cmds.duplicate(drv_Jnt[1], name=name+'_Jxt_Rot')[0])
        cmds.setAttr(aux_Jnt[0]+'.jointOrient', 0, 0, 0)
        aux_Jnt.append(cmds.duplicate(aux_Jnt[0], name=name+'_Jxt_Rot_End')[0])
        
        cmds.parent(aux_Jnt[1], mid_Loc[3])
        cmds.setAttr(aux_Jnt[1]+'.translate', 0, 0, 0)
        cmds.parent(aux_Jnt[1], aux_Jnt[0])
        cmds.parent(mid_Loc[3], aux_Jnt[1])
        #calculate the adjust for the new chain position
        dist = float(numJoints)/2.0
        end_dist = (1/float(numJoints))
        cmds.parent(drv_Jnt[3], drv_Jnt[0])
        cmds.parent(drv_Jnt[4], drv_Jnt[2])
        
        #adjust the joints orientation and position based in the options choose from user
        if horizontal and axis==(1, 0, 0):
            cmds.setAttr(drv_Jnt[0]+'.jointOrient', 0, 90, 0)
            cmds.setAttr(drv_Jnt[2]+'.jointOrient', 0, 90, 0)
            
            cmds.setAttr(drv_Jnt[0]+'.tz', -dist)
            cmds.setAttr(drv_Jnt[3]+'.tz', end_dist*dist)
            cmds.setAttr(drv_Jnt[2]+'.tz', dist)
            cmds.setAttr(drv_Jnt[4]+'.tz', -end_dist*dist)
        
        elif horizontal and axis==(0, 1, 0):
            cmds.setAttr(drv_Jnt[0]+'.jointOrient', 0, 0, 0)
            cmds.setAttr(drv_Jnt[2]+'.jointOrient', 0, 0, 0)
            
            cmds.setAttr(drv_Jnt[0]+'.tx', -dist)
            cmds.setAttr(drv_Jnt[3]+'.tx', end_dist*dist)
            cmds.setAttr(drv_Jnt[2]+'.tx', dist)
            cmds.setAttr(drv_Jnt[4]+'.tx', -end_dist*dist)
        
        elif horizontal and axis==(0, 0, 1):
            cmds.setAttr(drv_Jnt[0]+'.jointOrient', 0, 0, 0)
            cmds.setAttr(drv_Jnt[2]+'.jointOrient', 0, 0, 0)
            
            cmds.setAttr(drv_Jnt[0]+'.tx', -dist)
            cmds.setAttr(drv_Jnt[3]+'.tx', end_dist*dist)
            cmds.setAttr(drv_Jnt[2]+'.tx', dist)
            cmds.setAttr(drv_Jnt[4]+'.tx', -end_dist*dist)
        
        elif horizontal and axis==(0, 0, -1):
            cmds.setAttr(drv_Jnt[0]+'.jointOrient', 0, 0, 0)
            cmds.setAttr(drv_Jnt[2]+'.jointOrient', 0, 0, 0)
            
            cmds.setAttr(drv_Jnt[0]+'.tx', -dist)
            cmds.setAttr(drv_Jnt[3]+'.tx', end_dist*dist)
            cmds.setAttr(drv_Jnt[2]+'.tx', dist)
            cmds.setAttr(drv_Jnt[4]+'.tx', -end_dist*dist)
            
        elif not horizontal and axis==(1, 0, 0):
            cmds.setAttr(drv_Jnt[0]+'.jointOrient', 0, 0, -90)
            cmds.setAttr(drv_Jnt[2]+'.jointOrient', 0, 0, -90)
        
            cmds.setAttr(drv_Jnt[0]+'.ty', -dist)
            cmds.setAttr(drv_Jnt[3]+'.ty', end_dist*dist)
            cmds.setAttr(drv_Jnt[2]+'.ty', dist)
            cmds.setAttr(drv_Jnt[4]+'.ty', -end_dist*dist)
            
        elif not horizontal and axis==(0, 1, 0):
            cmds.setAttr(drv_Jnt[0]+'.jointOrient', 0, 90, 0)
            cmds.setAttr(drv_Jnt[2]+'.jointOrient', 0, 90, 0)
        
            cmds.setAttr(drv_Jnt[0]+'.tz', -dist)
            cmds.setAttr(drv_Jnt[3]+'.tz', end_dist*dist)
            cmds.setAttr(drv_Jnt[2]+'.tz', dist)
            cmds.setAttr(drv_Jnt[4]+'.tz', -end_dist*dist)
            
        elif not horizontal and axis==(0, 0, 1):
            cmds.setAttr(drv_Jnt[0]+'.jointOrient', 0, 0, -90)
            cmds.setAttr(drv_Jnt[2]+'.jointOrient', 0, 0, -90)
        
            cmds.setAttr(drv_Jnt[0]+'.ty', -dist)
            cmds.setAttr(drv_Jnt[3]+'.ty', end_dist*dist)
            cmds.setAttr(drv_Jnt[2]+'.ty', dist)
            cmds.setAttr(drv_Jnt[4]+'.ty', -end_dist*dist)
        
        #fix the control locators position and orientation
        cmds.parent(top_Loc[0], drv_Jnt[2])
        cmds.setAttr(top_Loc[0]+'.translate', 0, 0, 0)
        cmds.parent(top_Loc[0], w=True)
        cmds.setAttr(top_Loc[0]+'.rotate', 0, 0, 0)
        
        cmds.parent(bttm_Loc[0], drv_Jnt[0])
        cmds.setAttr(bttm_Loc[0]+'.translate', 0, 0, 0)
        cmds.parent(bttm_Loc[0], w=True)
        cmds.setAttr(bttm_Loc[0]+'.rotate', 0, 0, 0)    
        
        cmds.parent(drv_Jnt[2], top_Loc[1])
        cmds.parent(drv_Jnt[1], mid_Loc[2])
        cmds.parent(drv_Jnt[0], bttm_Loc[1])
        
        cmds.parent(aux_Jnt[0], mid_Loc[0])
        #create a nurbs control in order to be used in the ribbon offset
        mid_Ctrl = cmds.circle (c=(0, 0, 0), nr=(1, 0, 0), ch=0, name=name+'_MidCtrl')[0]
        ctrls.renameShape([mid_Ctrl])
        midCtrl = mid_Ctrl
        mid_Ctrl = cmds.group(n=mid_Ctrl+'_Grp', em=True)
        cmds.delete(cmds.parentConstraint(midCtrl, mid_Ctrl, mo=0))
        cmds.parent(midCtrl, mid_Ctrl)
        
        #adjust the realtionship between the locators
        cmds.parent(mid_Ctrl, mid_Loc[2], r=True)
        cmds.parent(drv_Jnt[1], midCtrl)
        cmds.parent([top_Loc[2], mid_Loc[3], bttm_Loc[2]], w=True)
        cmds.makeIdentity(top_Loc[0], apply=True)
        cmds.makeIdentity(mid_Loc[0], apply=True)
        cmds.makeIdentity(bttm_Loc[0], apply=True)
        cmds.parent(top_Loc[2], top_Loc[0])
        cmds.parent(bttm_Loc[2], bttm_Loc[0])
        cmds.parent(mid_Loc[3], aux_Jnt[1]) 
        #create needed constraints in the locators in order to set the top always follow, to the base always aim the middle, to the middle always aim the top
        if firstLimb:
            cmds.aimConstraint(drv_Jnt[1], bttm_Loc[1], offset=(0, 0, 0), weight=1, aimVector=(1, 0, 0), upVector=(0, 0, 1), worldUpType='object', worldUpObject=bttm_Loc[2], name=bttm_Loc[1]+"_AimConstraint")
            cmds.aimConstraint(top_Loc[0], mid_Loc[1], offset=(0, 0, 0), weight=1, aimVector=(1, 0, 0), upVector=(0, 0, 1), worldUpType='object', worldUpObject=mid_Loc[3], name=mid_Loc[1]+"_AimConstraint")
            cmds.aimConstraint(drv_Jnt[1], top_Loc[1], offset=(0, 0, 0), weight=1, aimVector=(-1, 0, 0), upVector=(0, 1, 0), worldUpType='object', worldUpObject=top_Loc[2], name=top_Loc[1]+"_AimConstraint")
        else:
            # bug fix to plane twist
            cmds.aimConstraint(drv_Jnt[1], bttm_Loc[1], offset=(0, 0, 0), weight=1, aimVector=(1, 0, 0), upVector=(0, 1, 0), worldUpType='object', worldUpObject=bttm_Loc[2], name=bttm_Loc[1]+"_AimConstraint")
            cmds.aimConstraint(top_Loc[0], mid_Loc[1], offset=(0, 0, 0), weight=1, aimVector=(-1, 0, 0), upVector=(0, 0, 1), worldUpType='object', worldUpObject=mid_Loc[3], name=mid_Loc[1]+"_AimConstraint")
            cmds.aimConstraint(drv_Jnt[1], top_Loc[1], offset=(0, 0, 0), weight=1, aimVector=(-1, 0, 0), upVector=(0, 0, 1), worldUpType='object', worldUpObject=top_Loc[2], name=top_Loc[1]+"_AimConstraint")
        
        #create a point and orient constraint for the middel control
        cmds.pointConstraint(top_Loc[0], bttm_Loc[0], mid_Loc[0], offset=(0, 0, 0), weight=1, name=mid_Loc[0]+"_PointConstraint")
        ori = cmds.orientConstraint(top_Loc[0], bttm_Loc[0], aux_Jnt[0], offset=(0, 0, 0), weight=1, name=aux_Jnt[0]+"_OrientConstraint")
        
        #ribbon scale (volume variation)
        if numJoints == 3:
            proportionList = [0.5, 1, 0.5]
        elif numJoints == 5:
            proportionList = [0.4, 0.8, 1, 0.8, 0.4]
        elif numJoints == 7:
            proportionList = [0.25, 0.5, 0.75, 1, 0.75, 0.5, 0.25]

        curveInfoNode = cmds.arclen(ribbon+".v[0.5]", constructionHistory=True)
        curveInfoNode = cmds.rename(curveInfoNode, ribbon+"_CurveInfo")
        rbScaleMD = cmds.createNode("multiplyDivide", name=ribbon+"_ScaleCompensate_MD")
        rbNormalizeMD = cmds.createNode("multiplyDivide", name=ribbon+"_Normalize_MD")
        cmds.setAttr(rbNormalizeMD+".operation", 2)
        cmds.connectAttr(curveInfoNode+".arcLength", rbNormalizeMD+".input2X", force=True)
        cmds.connectAttr(rbScaleMD+".outputX", rbNormalizeMD+".input1X", force=True)

        if cmds.objExists(worldRef):
            if not cmds.objExists(worldRef+"."+limbManualVVAttr):
                cmds.addAttr(worldRef, longName=limbVVAttr, attributeType="float", minValue=0, maxValue=1, defaultValue=1, keyable=True)
                cmds.addAttr(worldRef, longName=limbManualVVAttr, attributeType="float", defaultValue=1, keyable=True)
                cmds.addAttr(worldRef, longName=limbMinVVAttr, attributeType="float", defaultValue=0.01, keyable=True)
            cmds.connectAttr(worldRef+".scaleX", rbScaleMD+".input1X", force=True)
        
        #fix group hierarchy
        extraCtrlGrp = cmds.group(empty=True, name=name+"_ExtraBendyCtrl_Grp")
        i = 0
        for jnt in rb_Jnt:
            cmds.makeIdentity(jnt, a=True)
            # create extra control
            extraCtrlName = jnt.replace("_Jnt", "_Ctrl")
            extraCtrl = ctrls.cvSquare(ctrlName=extraCtrlName, r=ctrlRadius)
            extraCtrlList.append(extraCtrl)
            cmds.rotate(0, 0, 90, extraCtrl)
            cmds.makeIdentity(extraCtrl, a=True)
            extraCtrlZero = utils.zeroOut([extraCtrl])[0]
            cmds.parent(extraCtrlZero, extraCtrlGrp)
            cmds.parentConstraint(fols[i], extraCtrlZero, w=1, name=extraCtrlZero+"_ParentConstraint")
            cmds.parentConstraint(extraCtrl, jnt, w=1, name=jnt+"_ParentConstraint")
            cmds.scaleConstraint(extraCtrl, jnt, w=1, name=jnt+"_ScaleConstraint")
            
            # work with volume variation
            rbProportionMD = cmds.createNode("multiplyDivide", name=extraCtrlName.replace("_Ctrl", "_Proportion_MD"))
            rbIntensityMD = cmds.createNode("multiplyDivide", name=extraCtrlName.replace("_Ctrl", "_Intensity_MD"))
            rbAddScalePMA = cmds.createNode("plusMinusAverage", name=extraCtrlName.replace("_Ctrl", "_AddScale_PMA"))
            rbScaleClp = cmds.createNode("clamp", name=extraCtrlName.replace("_Ctrl", "_Scale_Clp"))
            rbBlendCB = cmds.createNode("blendColors", name=extraCtrlName.replace("_Ctrl", "_Blend_BC"))
            cmds.connectAttr(worldRef+"."+limbVVAttr, rbBlendCB+".blender", force=True)
            cmds.setAttr(rbBlendCB+".color2", 1, 1, 1, type="double3")
            cmds.connectAttr(rbNormalizeMD+".outputX", rbProportionMD+".input1X", force=True)
            cmds.setAttr(rbProportionMD+".input2X", proportionList[i])
            cmds.connectAttr(rbProportionMD+".outputX", rbIntensityMD+".input1X", force=True)
            cmds.connectAttr(worldRef+"."+limbManualVVAttr, rbIntensityMD+".input2X", force=True)
            cmds.connectAttr(rbIntensityMD+".outputX", rbAddScalePMA+".input1D[1]", force=True)
            cmds.connectAttr(rbAddScalePMA+".output1D", rbScaleClp+".inputR", force=True)
            cmds.connectAttr(worldRef+"."+limbMinVVAttr, rbScaleClp+".minR")
            cmds.setAttr(rbScaleClp+".maxR", 1000000)
            cmds.connectAttr(rbScaleClp+".outputR", rbBlendCB+".color1.color1R", force=True)
            cmds.connectAttr(rbBlendCB+".output.outputR", extraCtrlZero+".scaleY", force=True)
            cmds.connectAttr(rbBlendCB+".output.outputR", extraCtrlZero+".scaleZ", force=True)
            
            # update i
            i = i + 1
        
        locatorsGrp = cmds.group(bttm_Loc[0], top_Loc[0], mid_Loc[0], n=name+'_Loc_Grp')
        skinJntGrp = cmds.group(rb_Jnt, n=name+'_Jnt_Grp')
        finalSystemGrp = cmds.group(ribbon, locatorsGrp, skinJntGrp, n=name+'_RibbonSystem_Grp')
        
        #do the controller joints skin and the ribbon
        ribbonShape = cmds.listRelatives(ribbon, shapes=True)
        skin = cmds.skinCluster(drv_Jnt[0:3], ribbonShape, tsb=True, mi=2, dr=1)
        
        #skin presets for the ribbon (that's amazing!)
        if not horizontal:
            if numJoints == 3:
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][5]', tv=(drv_Jnt[2], 1))
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][4]', tv=[(drv_Jnt[2], 0.6), (drv_Jnt[1], 0.4)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][3]', tv=[(drv_Jnt[2], 0.2), (drv_Jnt[1], 0.8)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][2]', tv=[(drv_Jnt[0], 0.2), (drv_Jnt[1], 0.8)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][1]', tv=[(drv_Jnt[0], 0.6), (drv_Jnt[1], 0.4)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][0]', tv=(drv_Jnt[0], 1))

            elif numJoints == 5:
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][7]', tv=(drv_Jnt[2], 1))
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][6]', tv=[(drv_Jnt[2], 0.80), (drv_Jnt[1], 0.2)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][5]', tv=[(drv_Jnt[2], 0.5), (drv_Jnt[1], 0.5)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][4]', tv=[(drv_Jnt[2], 0.25), (drv_Jnt[1], 0.75)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][3]', tv=[(drv_Jnt[0], 0.25), (drv_Jnt[1], 0.75)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][2]', tv=[(drv_Jnt[0], 0.5), (drv_Jnt[1], 0.5)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][1]', tv=[(drv_Jnt[0], 0.8), (drv_Jnt[1], 0.2)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][0]', tv=(drv_Jnt[0], 1))
            elif numJoints == 7:
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][9]', tv=(drv_Jnt[2], 1))
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][8]', tv=[(drv_Jnt[2], 0.85), (drv_Jnt[1], 0.15)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][7]', tv=[(drv_Jnt[2], 0.6), (drv_Jnt[1], 0.4)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][6]', tv=[(drv_Jnt[2], 0.35), (drv_Jnt[1], 0.65)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][5]', tv=[(drv_Jnt[2], 0.25), (drv_Jnt[1], 0.75)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][4]', tv=[(drv_Jnt[0], 0.25), (drv_Jnt[1], 0.75)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][3]', tv=[(drv_Jnt[0], 0.35), (drv_Jnt[1], 0.65)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][2]', tv=[(drv_Jnt[0], 0.6), (drv_Jnt[1], 0.4)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][1]', tv=[(drv_Jnt[0], 0.85), (drv_Jnt[1], 0.15)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0:1][0]', tv=(drv_Jnt[0], 1))
        else:
            if numJoints == 3:
                cmds.skinPercent(skin[0], ribbon + '.cv[5][0:1]', tv=(drv_Jnt[2], 1))
                cmds.skinPercent(skin[0], ribbon + '.cv[4][0:1]', tv=[(drv_Jnt[2], 0.6), (drv_Jnt[1], 0.4)])
                cmds.skinPercent(skin[0], ribbon + '.cv[3][0:1]', tv=[(drv_Jnt[2], 0.2), (drv_Jnt[1], 0.8)])
                cmds.skinPercent(skin[0], ribbon + '.cv[2][0:1]', tv=[(drv_Jnt[0], 0.2), (drv_Jnt[1], 0.8)])
                cmds.skinPercent(skin[0], ribbon + '.cv[1][0:1]', tv=[(drv_Jnt[0], 0.6), (drv_Jnt[1], 0.4)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0][0:1]', tv=(drv_Jnt[0], 1))
            elif numJoints == 5:
                cmds.skinPercent(skin[0], ribbon + '.cv[7][0:1]', tv=(drv_Jnt[2], 1))
                cmds.skinPercent(skin[0], ribbon + '.cv[6][0:1]', tv=[(drv_Jnt[2], 0.80), (drv_Jnt[1], 0.2)])
                cmds.skinPercent(skin[0], ribbon + '.cv[5][0:1]', tv=[(drv_Jnt[2], 0.5), (drv_Jnt[1], 0.5)])
                cmds.skinPercent(skin[0], ribbon + '.cv[4][0:1]', tv=[(drv_Jnt[2], 0.25), (drv_Jnt[1], 0.75)])
                cmds.skinPercent(skin[0], ribbon + '.cv[3][0:1]', tv=[(drv_Jnt[0], 0.25), (drv_Jnt[1], 0.75)])
                cmds.skinPercent(skin[0], ribbon + '.cv[2][0:1]', tv=[(drv_Jnt[0], 0.5), (drv_Jnt[1], 0.5)])
                cmds.skinPercent(skin[0], ribbon + '.cv[1][0:1]', tv=[(drv_Jnt[0], 0.8), (drv_Jnt[1], 0.2)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0][0:1]', tv=(drv_Jnt[0], 1))
            elif numJoints == 7:
                cmds.skinPercent(skin[0], ribbon + '.cv[9][0:1]', tv=(drv_Jnt[2], 1))
                cmds.skinPercent(skin[0], ribbon + '.cv[8][0:1]', tv=[(drv_Jnt[2], 0.85), (drv_Jnt[1], 0.15)])
                cmds.skinPercent(skin[0], ribbon + '.cv[7][0:1]', tv=[(drv_Jnt[2], 0.6), (drv_Jnt[1], 0.4)])
                cmds.skinPercent(skin[0], ribbon + '.cv[6][0:1]', tv=[(drv_Jnt[2], 0.35), (drv_Jnt[1], 0.65)])
                cmds.skinPercent(skin[0], ribbon + '.cv[5][0:1]', tv=[(drv_Jnt[2], 0.25), (drv_Jnt[1], 0.75)])
                cmds.skinPercent(skin[0], ribbon + '.cv[4][0:1]', tv=[(drv_Jnt[0], 0.25), (drv_Jnt[1], 0.75)])
                cmds.skinPercent(skin[0], ribbon + '.cv[3][0:1]', tv=[(drv_Jnt[0], 0.35), (drv_Jnt[1], 0.65)])
                cmds.skinPercent(skin[0], ribbon + '.cv[2][0:1]', tv=[(drv_Jnt[0], 0.6), (drv_Jnt[1], 0.4)])
                cmds.skinPercent(skin[0], ribbon + '.cv[1][0:1]', tv=[(drv_Jnt[0], 0.85), (drv_Jnt[1], 0.15)])
                cmds.skinPercent(skin[0], ribbon + '.cv[0][0:1]', tv=(drv_Jnt[0], 1))
        constr = []
        if guias:
            top = guias[0]
            bottom = guias[1]
            constr.append(cmds.parentConstraint(top, bttm_Loc[0], mo=False, name=bttm_Loc[0]+"_ParentConstraint"))
            constr.append(cmds.parentConstraint(bottom, top_Loc[0], mo=False, name=top_Loc[0]+"_ParentConstraint"))
        
        #fix orientation issues
        cmds.delete(ori)
        cmds.orientConstraint(bttm_Loc[0], aux_Jnt[0], weight=0.5, mo=True, name=aux_Jnt[0]+"_OrientConstraint")
        
        #fix loc_Grp scale
        if guias:
            from math import sqrt, pow
            auxLoc1 = cmds.spaceLocator(name='auxLoc1')[0]
            auxLoc2 = cmds.spaceLocator(name='auxLoc2')[0]
            cmds.delete(cmds.parentConstraint(top, auxLoc1, mo=False, w=1))
            cmds.delete(cmds.parentConstraint(bottom, auxLoc2, mo=False, w=1))
            a = cmds.xform(auxLoc1, ws=True, translation=True, q=True)
            b = cmds.xform(auxLoc2, ws=True, translation=True, q=True)
            
            dist = sqrt(pow(a[0]-b[0], 2.0)+pow(a[1]-b[1], 2.0)+pow(a[2]-b[2], 2.0))
            scale = dist/float(numJoints)
            
            cmds.setAttr(locatorsGrp+'.s', scale, scale, scale)
        
            cmds.delete(auxLoc1, auxLoc2)
        
        # baseTwist:
        if not upCtrl == None:
            bttm_LocGrp = cmds.group(bttm_Loc[2], name=bttm_Loc[2]+"_Grp")
            bttm_LocPos = cmds.xform(bttm_Loc[0], query=True, worldSpace=True, translation=True)
            cmds.move(bttm_LocPos[0], bttm_LocPos[1], bttm_LocPos[2], bttm_LocGrp+".scalePivot", bttm_LocGrp+".rotatePivot", absolute=True)
            cmds.connectAttr(upCtrl+".baseTwist", bttm_LocGrp+".rotateZ", force=True)
        
        #updating values
        cmds.setAttr(rbScaleMD+".input2X", cmds.getAttr(curveInfoNode+".arcLength"))
        for jnt in rb_Jnt:
            rbAddScalePMA = jnt.replace("_Jnt", "_AddScale_PMA")
            cmds.setAttr(rbAddScalePMA+".input1D[0]", 1-cmds.getAttr(rbAddScalePMA+".input1D[1]"))

        #change renderStats
        ribbonShape = cmds.listRelatives(ribbon, s=True, f=True)[0]
        
        cmds.setAttr(ribbonShape+'.castsShadows', 0)
        cmds.setAttr(ribbonShape+'.receiveShadows', 0)
        cmds.setAttr(ribbonShape+'.motionBlur', 0)
        cmds.setAttr(ribbonShape+'.primaryVisibility', 0)
        cmds.setAttr(ribbonShape+'.smoothShading', 0)
        cmds.setAttr(ribbonShape+'.visibleInReflections', 0)
        cmds.setAttr(ribbonShape+'.visibleInRefractions', 0)
        cmds.setAttr(ribbonShape+'.doubleSided', 1)
        
        retDict['name'] = name
        retDict['locsList'] = [top_Loc[0], mid_Loc[0], bttm_Loc[0]]
        retDict['skinJointsList'] =  rb_Jnt
        retDict['scaleGrp'] = locatorsGrp
        retDict['finalGrp'] = finalSystemGrp
        retDict['middleCtrl'] = mid_Ctrl
        retDict['constraints'] = constr
        retDict['bendGrpList'] = [top_Loc[0], bttm_Loc[0]]
        retDict['extraCtrlGrp'] = extraCtrlGrp
        retDict['extraCtrlList'] = extraCtrlList
        retDict['rbScaleMD'] = rbScaleMD
        retDict['rbNormalizeMD'] = rbNormalizeMD
        cmds.setAttr(finalSystemGrp+'.v', v)
        return retDict
コード例 #50
0
#all the groups for cleanup
ribbonJntsGrp = cmds.group(em=True, n=theName + '_ribbon_jnts_grp')
cmds.hide(ribbonJntsGrp)
ribbonMeshGrp = cmds.group(em=True, n=theName + '_ribbon_geo_grp')
ribbonCtrlsGrp = cmds.group(em=True, n=theName + '_ribbon_ctrls_grp')
ribbonMasterGrp = cmds.group(em=True, n=theName + '_ribbon_grp')

for grp in [ribbonJntsGrp, ribbonMeshGrp, ribbonCtrlsGrp]:
    cmds.select(grp)
    cmds.parent(grp, ribbonMasterGrp)

newNurbsSurface = cmds.nurbsPlane(n=theName,
                                  ax=(0, 1, 0),
                                  w=theNumU,
                                  lr=theNumV,
                                  d=3,
                                  u=theNumU,
                                  v=theNumV,
                                  ch=0)[0]
cmds.parent(newNurbsSurface, ribbonMeshGrp)
cmds.select(newNurbsSurface)
mel.eval("createHair %s %s 2 0 0 0 0 5 0 1 1 1;" % (theNumU, theNumV))

#we need to remove the extra crap now
removalList = ["nucleus1", "pfxHair1", "hairSystem1"]

for i in range(theNumV):
    removalList.append("curve%i" % (i + 1))

for item in removalList:
    CleanRemove(item)
コード例 #51
0
def create_ribbon ( member, side, part, start_jnt, end_jnt, arm_group, scale, color ):

    name = member + side + 'ribbon' + part

    global_group = mc.group ( name = name + 'holder_GRP', empty = True )
    mc.parent ( global_group, arm_group )

    # Create plane
    base_plane = mc.nurbsPlane ( name = name + '_PLN', axis = [0, 1, 0], width = 5, lengthRatio = 0.2, degree = 3, u = 1, v = 5, constructionHistory = 1 )[0]
    mc.delete ( constructionHistory = True )

    mc.parent ( base_plane, global_group )

    # Create three bones system

    rig_jnt = []
    base_loc = []
    up_loc = []
    aim_loc = []
    ctrl_rib = []

    move_z = 0.5

    for num in map ( str, range ( 1, 4 ) ):
        jnt = ( mc.joint ( name = name + num + '_RIJ' ) )
        mc.setAttr ( jnt + '.radius', 0.1 )

        loc_a = mc.spaceLocator ( name = name + num + '_LOC' )[0]
        loc_a_up = mc.spaceLocator ( name = name + num + '_up_LOC' )[0]
        mc.move ( 0, 5, 0, relative = True, objectSpace = True, worldSpaceDistance = True )
        loc_a_aim = mc.spaceLocator ( name = name + num + '_aim_LOC' )[0]

        mc.parent ( loc_a_up, loc_a )
        mc.parent ( loc_a_aim, loc_a )
        mc.parent ( jnt, loc_a_aim )

        mc.move ( 0, 0, move_z, loc_a, relative = True, objectSpace = True, worldSpaceDistance = True )

        mc.setAttr ( jnt + '.translateZ', 0 )

        mc.parent ( loc_a, global_group )
        mid_ctrl = create_ctrl('sphere', name + num + '_CTL', scale, color, jnt, maintain_offset = True, position = True, orient = False )

        mc.parent ( mid_ctrl, loc_a_aim )
        mc.parent ( jnt, mid_ctrl )

        ctrl_rib.append ( mid_ctrl )
        rig_jnt.append ( jnt )
        base_loc.append ( loc_a )
        up_loc.append ( loc_a_up )
        aim_loc.append ( loc_a_aim )

        move_z -= 0.5

    # #Create the follicles and ribbon joints

    fol_grp = mc.group ( name = name + 'follicles_GRP', empty = True )
    mc.parent ( fol_grp, arm_group )

    fol_list = []

    for f in range( 1, 4 ):
        follicle = mc.createNode ( 'follicle', name = ( name + '_' + str ( f ) + '_FollicleShape' ) )
        follicle_transform = mc.listRelatives ( follicle, parent = True )

        ribbon_jnt = mc.joint ( name = name + '_' + str ( f ) + '_JNT' )
        mc.group ( name = ( ribbon_jnt + '_GRP' ) )

        # # connect folliclesShapes to the plane
        mc.connectAttr ( base_plane + '.local' , follicle + '.inputSurface' )
        mc.connectAttr ( base_plane + '.worldMatrix[0]', follicle + '.inputWorldMatrix' )
        # # connect follicleShapes to follicle_transform
        mc.connectAttr ( follicle + '.outTranslate' , follicle_transform[0] + '.translate' )
        mc.connectAttr ( follicle + '.outRotate', follicle_transform[0] + '.rotate' )

        # #position the follicles along the plane
        mc.setAttr ( follicle + '.parameterU', 0.5 )
        v_span_height = ( f / 3. ) - .1
        mc.setAttr ( follicle + '.parameterV', v_span_height )

        # Turn off inherit transforms on the follicles
        mc.setAttr ( follicle_transform[0] + '.inheritsTransform', 0 , lock = True )

        # #parent the follicle to the group and add to lists
        mc.parent ( follicle, fol_grp )

        fol_list.append ( follicle )

    skin = mc.skinCluster ( rig_jnt[0], rig_jnt[1], rig_jnt[2], base_plane, toSelectedBones = True )[0]

    for num in range( 4 ):
        for index, j_ind, weight in zip ( range(8), [0] * 3 + [1] * 2 + [2] * 3, [1, .85, .5, .85, .85, .5, .85, 1] ):
            mc.skinPercent ( skin, '{0}.cv[{1}][{2}]'.format( base_plane, num, index ),
                             transformValue = [ rig_jnt[j_ind], weight ] )

    # Add constraints
    mc.pointConstraint ( up_loc[0], up_loc[2], up_loc[1] )

    mc.pointConstraint ( base_loc[0], base_loc[2], base_loc[1] )
    mc.aimConstraint ( base_loc[0], aim_loc[1], aimVector = [0, 0, 1], upVector = [0, 1, 0], worldUpType = 'object', worldUpObject = up_loc[1] )

    mc.parentConstraint ( start_jnt, base_loc[0] )
    mc.aimConstraint ( ctrl_rib[1], aim_loc[0], aimVector = [0, 0, -1], upVector = [0, 1, 0], worldUpType = 'object', worldUpObject = up_loc[0] )


    mc.parentConstraint ( end_jnt, base_loc[2] )
    mc.aimConstraint ( ctrl_rib[1], aim_loc[2], aimVector = [0, 0, 1], upVector = [0, 1, 0], worldUpType = 'object', worldUpObject = up_loc[2] )
コード例 #52
0
def createRibbon(*args):
    #Gather information
    width = cmds.floatField('widthField', query=True, value=True)
    numJoints = cmds.intField('jointsField', query=True, value=True)
    prefix = cmds.textField('prefixField', query=True, text=True)
    scaleGrp = cmds.textField('scaleGrpField', query=True, text=True)
    topPoint = (width / 2)
    endPoint = (width / 2 * -1)

    #Create the main groups
    grpNoTransform = cmds.group(empty=True, name=(prefix + 'noTransform_grp'))
    grpTransform = cmds.group(empty=True, name=(prefix + 'transform_grp'))
    grpCtrl = cmds.group(empty=True,
                         name=(prefix + 'ctrl_grp'),
                         parent=grpTransform)
    grpSurface = cmds.group(empty=True,
                            name=(prefix + 'surface_grp'),
                            parent=grpTransform)
    grpSurfaces = cmds.group(empty=True,
                             name=(prefix + 'surfaces_grp'),
                             parent=grpNoTransform)
    grpDeformers = cmds.group(empty=True,
                              name=(prefix + 'deformer_grp'),
                              parent=grpNoTransform)
    grpFollMain = cmds.group(empty=True,
                             name=(prefix + 'follicles_skin_grp'),
                             parent=grpNoTransform)
    grpFollVolume = cmds.group(empty=True,
                               name=(prefix + 'follicles_volume_grp'),
                               parent=grpNoTransform)
    grpCluster = cmds.group(empty=True,
                            name=(prefix + 'cluster_grp'),
                            parent=grpNoTransform)
    grpMisc = cmds.group(empty=True,
                         name=(prefix + 'misc_grp'),
                         parent=grpNoTransform)

    #Create a NURBS-plane to use as a base
    tmpPlane = cmds.nurbsPlane(axis=(0, 1, 0),
                               width=width,
                               lengthRatio=(1.0 / width),
                               u=numJoints,
                               v=1,
                               degree=3,
                               ch=0)[0]
    #Create the NURBS-planes to use in the setup
    geoPlane = cmds.duplicate(tmpPlane, name=(prefix + 'geo'))
    geoPlaneTwist = cmds.duplicate(tmpPlane, name=(prefix + 'twist_blnd_geo'))
    geoPlaneSine = cmds.duplicate(tmpPlane, name=(prefix + 'sine_blnd_geo'))
    geoPlaneWire = cmds.duplicate(tmpPlane, name=(prefix + 'wire_blnd_geo'))
    geoPlaneVolume = cmds.duplicate(tmpPlane, name=(prefix + 'volume_geo'))
    #Offset the volume-plane
    cmds.setAttr((geoPlaneVolume[0] + '.translateZ'), -0.5)
    #Delete the base surface
    cmds.delete(tmpPlane)

    #Create the controllers
    ctrlTop = createCurveCtrl(name=(prefix + 'top_ctrl'),
                              freezeTransforms=1,
                              color=9,
                              pos=(topPoint, 0, 0))
    ctrlMid = createCurveCtrl(name=(prefix + 'mid_ctrl'),
                              freezeTransforms=1,
                              color=9,
                              pos=(0, 0, 0))
    ctrlEnd = createCurveCtrl(name=(prefix + 'end_ctrl'),
                              freezeTransforms=1,
                              color=9,
                              pos=(endPoint, 0, 0))
    #Group the controllers
    grpTop = grpObject(objects=[ctrlTop],
                       snapTrans=1,
                       keepTransforms=0,
                       keepHi=1,
                       empty=0,
                       suffix='_grp')[0]
    grpMid = grpObject(objects=[ctrlMid],
                       snapTrans=1,
                       keepTransforms=0,
                       keepHi=1,
                       empty=0,
                       suffix='_grp')[0]
    grpEnd = grpObject(objects=[ctrlEnd],
                       snapTrans=1,
                       keepTransforms=0,
                       keepHi=1,
                       empty=0,
                       suffix='_grp')[0]
    #PointConstraint the midCtrl between the top/end
    midConst = cmds.pointConstraint(ctrlTop, ctrlEnd, grpMid)

    #Add attributes: Twist/Roll attributes
    addAttribute(objects=[ctrlTop, ctrlMid, ctrlEnd],
                 longName=['twistSep'],
                 niceName=['---------------'],
                 at="enum",
                 en='Twist',
                 lock=1,
                 k=True)
    addAttribute(objects=[ctrlTop, ctrlEnd],
                 longName=['twist'],
                 at="float",
                 k=True)
    addAttribute(objects=[ctrlTop, ctrlEnd],
                 longName=['twistOffset'],
                 at="float",
                 k=True)
    addAttribute(objects=[ctrlTop, ctrlEnd],
                 longName=['affectToMid'],
                 at="float",
                 min=0,
                 max=10,
                 dv=10,
                 k=True)
    addAttribute(objects=[ctrlMid], longName=['roll'], at="float", k=True)
    addAttribute(objects=[ctrlMid],
                 longName=['rollOffset'],
                 at="float",
                 k=True)
    #Add attributes: Volume attributes
    addAttribute(objects=[ctrlMid],
                 longName=['volumeSep'],
                 niceName=['---------------'],
                 at="enum",
                 en='Volume',
                 lock=1,
                 k=True)
    addAttribute(objects=[ctrlMid],
                 longName=['volume'],
                 at="float",
                 min=-1,
                 max=1,
                 k=True)
    addAttribute(objects=[ctrlMid],
                 longName=['volumeMultiplier'],
                 at="float",
                 min=1,
                 dv=3,
                 k=True)
    addAttribute(objects=[ctrlMid],
                 longName=['startDropoff'],
                 at="float",
                 min=0,
                 max=1,
                 dv=1,
                 k=True)
    addAttribute(objects=[ctrlMid],
                 longName=['endDropoff'],
                 at="float",
                 min=0,
                 max=1,
                 dv=1,
                 k=True)
    addAttribute(objects=[ctrlMid],
                 longName=['volumeScale'],
                 at="float",
                 min=endPoint * 0.9,
                 max=topPoint * 2,
                 k=True)
    addAttribute(objects=[ctrlMid],
                 longName=['volumePosition'],
                 min=endPoint,
                 max=topPoint,
                 at="float",
                 k=True)
    #Add attributes: Sine attributes
    addAttribute(objects=[ctrlMid],
                 longName=['sineSep'],
                 niceName=['---------------'],
                 attributeType='enum',
                 en="Sine:",
                 keyable=True,
                 lock=1)
    addAttribute(objects=[ctrlMid],
                 longName=['amplitude'],
                 attributeType="float",
                 keyable=True)
    addAttribute(objects=[ctrlMid],
                 longName=['offset'],
                 attributeType="float",
                 keyable=True)
    addAttribute(objects=[ctrlMid],
                 longName=['twist'],
                 attributeType="float",
                 keyable=True)
    addAttribute(objects=[ctrlMid],
                 longName=['sineLength'],
                 min=0.1,
                 dv=2,
                 attributeType="float",
                 keyable=True)
    #Add attributes: Extra attributes
    addAttribute(objects=[ctrlMid],
                 longName=['extraSep'],
                 niceName=['---------------'],
                 at="enum",
                 en='Extra',
                 lock=1,
                 k=True)
    addAttribute(objects=[ctrlMid],
                 longName=['showExtraCtrl'],
                 at="enum",
                 en='Hide:Show:',
                 k=True)
    cmds.setAttr((ctrlMid + '.showExtraCtrl'), 1)

    #Create deformers: Twist deformer, Sine deformer, Squash deformer
    twistDef = nonlinearDeformer(objects=[geoPlaneTwist[0]],
                                 defType='twist',
                                 name=geoPlaneTwist[0],
                                 lowBound=-1,
                                 highBound=1,
                                 rotate=(0, 0, 90))
    sineDef = nonlinearDeformer(objects=[geoPlaneSine[0]],
                                defType='sine',
                                name=geoPlaneSine[0],
                                lowBound=-1,
                                highBound=1,
                                rotate=(0, 0, 90))
    squashDef = nonlinearDeformer(objects=[geoPlaneVolume[0]],
                                  defType='squash',
                                  name=geoPlaneVolume[0],
                                  lowBound=-1,
                                  highBound=1,
                                  rotate=(0, 0, 90))
    cmds.setAttr((sineDef[0] + '.dropoff'), 1)
    #Create deformers: Wire deformer
    deformCrv = cmds.curve(p=[(topPoint, 0, 0), (0, 0, 0), (endPoint, 0, 0)],
                           degree=2)
    deformCrv = cmds.rename(deformCrv, (prefix + 'ribbon_wire_crv'))
    wireDef = cmds.wire(geoPlaneWire, dds=(0, 15), wire=deformCrv)
    wireDef[0] = cmds.rename(wireDef[0], (geoPlaneWire[0] + '_wire'))
    #Create deformers: Clusters
    clsTop = cmds.cluster((deformCrv + '.cv[0:1]'), relative=1)
    clsMid = cmds.cluster((deformCrv + '.cv[1]'), relative=1)
    clsEnd = cmds.cluster((deformCrv + '.cv[1:2]'), relative=1)
    clsTop[0] = cmds.rename(clsTop[0], (ctrlTop + '_top_cluster'))
    clsTop[1] = cmds.rename(clsTop[1], (ctrlTop + '_top_clusterHandle'))
    clsMid[0] = cmds.rename(clsMid[0], (ctrlMid + '_mid_cluster'))
    clsMid[1] = cmds.rename(clsMid[1], (ctrlMid + '_mid_clusterHandle'))
    clsEnd[0] = cmds.rename(clsEnd[0], (ctrlEnd + '_end_cluster'))
    clsEnd[1] = cmds.rename(clsEnd[1], (ctrlEnd + '_end_clusterHandle'))
    cmds.setAttr((cmds.listRelatives(clsTop[1], type="shape")[0] + '.originX'),
                 topPoint)
    cmds.setAttr((cmds.listRelatives(clsEnd[1], type="shape")[0] + '.originX'),
                 endPoint)
    setPivot(objects=[clsTop[1]],
             rotatePivot=1,
             scalePivot=1,
             pivot=(topPoint, 0, 0))
    setPivot(objects=[clsEnd[1]],
             rotatePivot=1,
             scalePivot=1,
             pivot=(endPoint, 0, 0))
    cmds.percent(clsTop[0], (deformCrv + '.cv[1]'), v=0.5)
    cmds.percent(clsEnd[0], (deformCrv + '.cv[1]'), v=0.5)
    posTopPma = cmds.shadingNode('plusMinusAverage',
                                 asUtility=1,
                                 name=(prefix + 'top_ctrl_pos_pma'))
    cmds.connectAttr((ctrlTop + '.translate'), (posTopPma + '.input3D[0]'))
    cmds.connectAttr((grpTop + '.translate'), (posTopPma + '.input3D[1]'))
    posEndPma = cmds.shadingNode('plusMinusAverage',
                                 asUtility=1,
                                 name=(prefix + 'end_ctrl_pos_pma'))
    cmds.connectAttr((ctrlEnd + '.translate'), (posEndPma + '.input3D[0]'))
    cmds.connectAttr((grpEnd + '.translate'), (posEndPma + '.input3D[1]'))
    cmds.connectAttr((posTopPma + '.output3D'), (clsTop[1] + '.translate'))
    cmds.connectAttr((ctrlMid + '.translate'), (clsMid[1] + '.translate'))
    cmds.connectAttr((posEndPma + '.output3D'), (clsEnd[1] + '.translate'))
    #Create deformers: Blendshape
    blndDef = cmds.blendShape(geoPlaneWire[0],
                              geoPlaneTwist[0],
                              geoPlaneSine[0],
                              geoPlane[0],
                              name=(prefix + 'blendShape'),
                              weight=[(0, 1), (1, 1), (2, 1)])

    #Twist deformer: Sum the twist and the roll
    sumTopPma = cmds.shadingNode('plusMinusAverage',
                                 asUtility=1,
                                 name=(prefix + 'twist_top_sum_pma'))
    cmds.connectAttr((ctrlTop + '.twist'), (sumTopPma + '.input1D[0]'))
    cmds.connectAttr((ctrlTop + '.twistOffset'), (sumTopPma + '.input1D[1]'))
    cmds.connectAttr((ctrlMid + '.roll'), (sumTopPma + '.input1D[2]'))
    cmds.connectAttr((ctrlMid + '.rollOffset'), (sumTopPma + '.input1D[3]'))
    cmds.connectAttr((sumTopPma + '.output1D'), (twistDef[0] + '.startAngle'))
    sumEndPma = cmds.shadingNode('plusMinusAverage',
                                 asUtility=1,
                                 name=(prefix + 'twist_low_sum_pma'))
    cmds.connectAttr((ctrlEnd + '.twist'), (sumEndPma + '.input1D[0]'))
    cmds.connectAttr((ctrlEnd + '.twistOffset'), (sumEndPma + '.input1D[1]'))
    cmds.connectAttr((ctrlMid + '.roll'), (sumEndPma + '.input1D[2]'))
    cmds.connectAttr((ctrlMid + '.rollOffset'), (sumEndPma + '.input1D[3]'))
    cmds.connectAttr((sumEndPma + '.output1D'), (twistDef[0] + '.endAngle'))
    #Twist deformer: Set up the affect of the deformer
    topAffMdl = cmds.shadingNode('multDoubleLinear',
                                 asUtility=1,
                                 name=(prefix + 'twist_top_affect_mdl'))
    cmds.setAttr((topAffMdl + '.input1'), -0.1)
    cmds.connectAttr((ctrlTop + '.affectToMid'), (topAffMdl + '.input2'))
    cmds.connectAttr((topAffMdl + '.output'), (twistDef[0] + '.lowBound'))
    endAffMdl = cmds.shadingNode('multDoubleLinear',
                                 asUtility=1,
                                 name=(prefix + 'twist_end_affect_mdl'))
    cmds.setAttr((endAffMdl + '.input1'), 0.1)
    cmds.connectAttr((ctrlEnd + '.affectToMid'), (endAffMdl + '.input2'))
    cmds.connectAttr((endAffMdl + '.output'), (twistDef[0] + '.highBound'))

    #Squash deformer: Set up the connections for the volume control
    volumeRevfMdl = cmds.shadingNode('multDoubleLinear',
                                     asUtility=1,
                                     name=(prefix + 'volume_reverse_mdl'))
    cmds.setAttr((volumeRevfMdl + '.input1'), -1)
    cmds.connectAttr((ctrlMid + '.volume'), (volumeRevfMdl + '.input2'))
    cmds.connectAttr((volumeRevfMdl + '.output'), (squashDef[0] + '.factor'))
    cmds.connectAttr((ctrlMid + '.startDropoff'),
                     (squashDef[0] + '.startSmoothness'))
    cmds.connectAttr((ctrlMid + '.endDropoff'),
                     (squashDef[0] + '.endSmoothness'))
    cmds.connectAttr((ctrlMid + '.volumePosition'),
                     (squashDef[1] + '.translateX'))
    #Squash deformer: Set up the volume scaling
    sumScalePma = cmds.shadingNode('plusMinusAverage',
                                   asUtility=1,
                                   name=(prefix + 'volume_scale_sum_pma'))
    cmds.setAttr((sumScalePma + '.input1D[0]'), topPoint)
    cmds.connectAttr((ctrlMid + '.volumeScale'), (sumScalePma + '.input1D[1]'))
    cmds.connectAttr((sumScalePma + '.output1D'), (squashDef[1] + '.scaleY'))

    #Sine deformer: Set up the connections for the sine
    cmds.connectAttr((ctrlMid + '.amplitude'), (sineDef[0] + '.amplitude'))
    cmds.connectAttr((ctrlMid + '.offset'), (sineDef[0] + '.offset'))
    cmds.connectAttr((ctrlMid + '.twist'), (sineDef[1] + '.rotateY'))
    cmds.connectAttr((ctrlMid + '.sineLength'), (sineDef[0] + '.wavelength'))

    #Cleanup: Hierarchy
    cmds.parent(geoPlaneWire[0], geoPlaneTwist[0], geoPlaneSine[0],
                geoPlaneVolume[0], grpSurfaces)
    cmds.parent(twistDef[1], sineDef[1], squashDef[1], grpDeformers)
    cmds.parent(clsTop[1], clsMid[1], clsEnd[1], grpCluster)
    cmds.parent(grpTop, grpMid, grpEnd, grpCtrl)
    cmds.parent(geoPlane[0], grpSurface)
    cmds.parent(deformCrv,
                (cmds.listConnections(wireDef[0] + '.baseWire[0]')[0]),
                grpMisc)
    #Cleanup: Visibility
    cmds.hide(grpSurfaces, grpDeformers, grpCluster, grpMisc)
    for x in cmds.listConnections(ctrlMid):
        cmds.setAttr((x + '.isHistoricallyInteresting'), 0)
        for y in cmds.listConnections(x):
            cmds.setAttr((y + '.isHistoricallyInteresting'), 0)

    #Update the scale-group
    scaleGrp = scaleGrp if scaleGrp else grpTransform
    #Create follicles: The main-surface and the volume-surface
    for x in range(0, numJoints):
        #Declare a variable for the current index
        num = str(x + 1)
        #Get the normalized position of where to place the current follicle
        uVal = ((0.5 / numJoints) * (x + 1) * 2) - ((0.5 /
                                                     (numJoints * 2)) * 2)
        #Create a follicle for the bind-plane and the volume-plane
        follicleS = createFollicle(scaleGrp=scaleGrp,
                                   inputSurface=cmds.listRelatives(
                                       geoPlane[0], type="shape"),
                                   uVal=uVal,
                                   name=(prefix + num + '_follicle'))
        follicleV = createFollicle(scaleGrp=None,
                                   inputSurface=cmds.listRelatives(
                                       geoPlaneVolume[0], type="shape"),
                                   uVal=uVal,
                                   vVal=0,
                                   name=(prefix + num + '_volume_follicle'))
        cmds.parent(follicleS[0], grpFollMain)
        cmds.parent(follicleV[0], grpFollVolume)
        #Create a joint, controller and a group for the current skin-follicle
        cmds.select(clear=True)
        follicleJoint = cmds.joint(name=(prefix + num + '_jnt'), radius=0.1)
        follicleCtrl = cmds.circle(name=(prefix + num + '_ctrl'),
                                   c=(0, 0, 0),
                                   nr=(1, 0, 0),
                                   sw=360,
                                   r=0.5,
                                   d=3,
                                   s=8,
                                   ch=0)[0]
        follicleXform = cmds.group(name=(prefix + num + '_xform_grp'),
                                   empty=True)
        cmds.parent(follicleXform, follicleS[0])
        cmds.parent(follicleCtrl, follicleXform)
        cmds.parent(follicleJoint, follicleCtrl)
        cmds.delete(cmds.parentConstraint(follicleS[0], follicleXform))
        #Set the color and connect the visibility-switch for the controller
        cmds.setAttr((cmds.listRelatives(follicleCtrl, shapes=True)[0] +
                      '.overrideEnabled'), 1)
        cmds.setAttr((cmds.listRelatives(follicleCtrl, shapes=True)[0] +
                      '.overrideColor'), 12)
        cmds.connectAttr(
            (ctrlMid + '.showExtraCtrl'),
            (cmds.listRelatives(follicleCtrl, shapes=True)[0] + '.visibility'))
        #Make the connections for the volume
        multMpd = cmds.shadingNode('multiplyDivide',
                                   asUtility=1,
                                   name=(prefix + num + '_multiplier_mpd'))
        cmds.connectAttr((ctrlMid + '.volumeMultiplier'),
                         (multMpd + '.input1Z'))
        cmds.connectAttr((follicleV[0] + '.translate'), (multMpd + '.input2'))
        sumPma = cmds.shadingNode('plusMinusAverage',
                                  asUtility=1,
                                  name=(prefix + num + '_volume_sum_pma'))
        cmds.connectAttr((multMpd + '.outputZ'), (sumPma + '.input1D[0]'))
        cmds.setAttr((sumPma + '.input1D[1]'), 1)
        cmds.connectAttr((sumPma + '.output1D'), (follicleXform + '.scaleY'))
        cmds.connectAttr((sumPma + '.output1D'), (follicleXform + '.scaleZ'))
コード例 #53
0
ファイル: lidSurface.py プロジェクト: bennymuller/glTools
def lidSurface_create(curveList, spans=4, attributeObject='', collisionObject='', side='', prefix=''):
    """
    Generate a lidSurface setup from the specified curve list and input parameters
    @param curveList: List of curves to generate the lidSurface from
    @type curveList: list
    @param spans: Number of verticle spans form each lid surface
    @type spans: int
    @param attributeObject: Object that will hold attributes form manipulating the lidSurface node
    @type attributeObject: str
    @param collisionObject: Nurbs surface object that will be used as a collision object for the lid surfaces
    @type collisionObject: str
    @param side: The side of the face the eyelid is on. ("lf" or "rt")
    @type side: str
    @param prefix: Name prefix for all created nodes
    @type prefix: str
    """
    # Define attribute list
    topAttr = 'topLid'
    lowAttr = 'lowLid'
    splitAttr = 'lidCentre'

    # NameUtil
    nameUtil = glTools.tools.namingConvention.NamingConvention()
    # Check prefix
    if not prefix: prefix = nameUtil.stripSuffix(crvList[0], '_')
    # Check side
    if not side: side = prefix.split('_')[0]

    # Check curveList
    for crv in curveList:
        if not cmds.objExists(crv):
            raise UserInputError('Curve "' + crv + '" does not exist!')
        if not glTools.utils.curve.isCurve(crv):
            raise UserInputError('Object "' + crv + '" is not a valid nurbs curve!')

    # Create lidSurface node
    lidSurface = prefix + '_lidSurface'
    lidSurface = cmds.createNode('lidSurface', n=lidSurface)

    # Set spans
    cmds.setAttr(lidSurface + '.spans', spans)

    # Connect curevList
    for i in range(len(curveList)):
        cmds.connectAttr(curveList[i] + '.worldSpace', lidSurface + '.inputCurve[' + str(i) + ']', f=True)

    # Check Attribute Object
    if cmds.objExists(attributeObject):
        # Check attributes
        if not cmds.objExists(attributeObject + '.' + topAttr):
            cmds.addAttr(attributeObject, ln=topAttr, min=-1, max=1, dv=0, k=True)
        if not cmds.objExists(attributeObject + '.' + lowAttr):
            cmds.addAttr(attributeObject, ln=lowAttr, min=-1, max=1, dv=0, k=True)
        if not cmds.objExists(attributeObject + '.' + splitAttr):
            cmds.addAttr(attributeObject, ln=splitAttr, min=0, max=1, dv=0.5, k=True)
        # Connect Attributes
        cmds.connectAttr(attributeObject + '.' + topAttr, lidSurface + '.top', f=True)
        cmds.connectAttr(attributeObject + '.' + lowAttr, lidSurface + '.bottom', f=True)
        cmds.connectAttr(attributeObject + '.' + splitAttr, lidSurface + '.split', f=True)

    # Check Collision Object
    if cmds.objExists(collisionObject):
        if not glTools.utils.surface.isSurface(collisionObject):
            raise UserInputError('Collision object "' + crv + '" is not a valid nurbs surface!')
        cmds.connectAttr(collisionObject + '.worldSpace', lidSurface + '.collisionGeometry', f=True)

    # Create lid surfaces
    topLid_srf = prefix + '_tp01_surface'
    topLid_srf = cmds.nurbsPlane(ch=0, n=topLid_srf)[0]
    lowLid_srf = prefix + '_lw01_surface'
    lowLid_srf = cmds.nurbsPlane(ch=0, n=lowLid_srf)[0]

    # Attach lid surfaces
    cmds.connectAttr(lidSurface + '.topLidSurface', topLid_srf + '.create', f=True)
    cmds.connectAttr(lidSurface + '.lowLidSurface', lowLid_srf + '.create', f=True)

    # Return result
    return (topLid_srf, lowLid_srf)
コード例 #54
0
	def createRibbon(self, *args):
		self.name = cmds.textFieldGrp(self.widgets["ribbonNameTFG"], q=True, tx=True)
		self.numDiv = (cmds.intFieldGrp(self.widgets["jointsIFG"], q=True, v=True)[0]) -1
		self.fk = cmds.checkBox(self.widgets["fkSetupCB"], q=True, v=True)
		self.height = cmds.floatFieldGrp(self.widgets["heightFFG"], q=True, v1=True)
		self.ratio = cmds.floatFieldGrp(self.widgets["ratioFFG"], q=True, v1=True)
		self.axis = cmds.radioButtonGrp(self.widgets["axis"] , q=True, sl=True)

		print("axis = :%s"%self.axis)
		self.ribbonName = "%s_ribbonGeo"%self.name
		self.numJoints = self.numDiv
		self.follicleList = []
		self.follicleJntList = []
		self.own = cmds.checkBox(self.widgets["existingGeoCB"], q=True, v=True)
		self.myGeo = cmds.textFieldButtonGrp(self.widgets["geoTFBG"], q=True, tx=True)
		self.dir = cmds.radioButtonGrp(self.widgets["directionRBG"], q=True, sl=True )
		print("dir: %s"%self.dir)
		self.centerPos = cmds.floatSliderGrp(self.widgets["centerPosFSG"], q=True, v=True )
		self.follicleGrpList = []

#-----------make sure the num of divisions is at least 1
#-----------create the nurbs plane in the correct axis (just make the plane in the axis and figure out how to rotate joint local rotational axes to match it) DON'T WORRY ABOUT THIS SO MUCH (IT'S HIDDEN), WORRY ABOUT THE CONTROLS BEING ORIENTED CORRECTLY!!!

		if self.own == 0:
			self.dir = 2
		if self.dir == 1:
			dir = "u"
			uDiv = self.numDiv
			vDiv = 1
		else:
			dir = "v'"
			uDiv = 1
			vDiv = self.numDiv

		# if self.axis  == 1:
		axis = [0, 0, 1]
		# elif self.axis  == 2:
		# 	axis = [0, 1, 0]
		# elif self.axis  == 3:
		# 	axis = [0, 0, 1]

		if self.own == 0:
			width = self.height/self.ratio
			#create the nurbsPlane
			cmds.nurbsPlane(ax=axis, w=width, lr=self.ratio, d=3, u=uDiv, v=vDiv, ch=0, n=self.ribbonName)
			cmds.rebuildSurface (self.ribbonName, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, su=1, du=1, sv=self.numDiv, dv=3, tol=0.1, fr=0, dir=0)
			cmds.move(0, self.height/2, 0, self.ribbonName)

			cmds.xform(self.ribbonName, ws=True, rp=[0, 0, 0])
		else:
			self.ribbonName = self.myGeo

		#find the ratio for the uv's (one dir will be .5, the other a result of the num joints)
		factor = 1.0/self.numJoints

#-------keep follicle joints separate, not parente under each follicle, separate group for those
#-------follicle jnts each go under a ctrl (star) that is under a group. That group gets parent constrained to the follicles
#-------these joints should be aligned with the follicles??? does that make a difference?

		#create the follicles on the surface, joints on the follicles
		for x in range (self.numJoints+1):
			val = x * factor
			folName = "%s_follicle%s"%(self.name, x)
			#create a follicle in the right direction
			if self.dir ==1:
				follicle = rig.follicle(self.ribbonName, folName, val, 0.5)[0]
			else:
				follicle = rig.follicle(self.ribbonName, folName, 0.5, val)[0]

			self.follicleList.append(follicle)

			#create joint and parent to follicle
			jointName = "%s_fol%s_JNT"%(self.name, x)
#---------have to figure out how to orient this correctly (just translate and rotate the joints (or the controls they're under))
			#create joint control? then move the control and the joint under it to the correct rot and pos
			folPos = cmds.xform(follicle, q=True, ws=True, t=True)
			folRot = cmds.xform(follicle, q=True, ws=True, ro=True)
			cmds.select(cl=True)
			folJoint = cmds.joint(n=jointName, p=(0,0,0))
			folGroup = cmds.group(folJoint, n="%s_GRP"%folJoint) #this could become control for the joint
			cmds.xform(folGroup, a=True, ws=True, t=folPos)
			cmds.xform(folGroup, a=True ,ws=True, ro=folRot)
			self.follicleJntList.append(folJoint)
			self.follicleGrpList.append(folGroup)
			cmds.parent(folGroup, follicle)

		#now create the control structure for the ribbon
		# basePosRaw = cmds.xform(self.follicleJntList[0], ws=True, q=True, t=True)
		# topPosRaw = cmds.xform(self.follicleJntList[self.numJoints], ws=True, q=True, t=True)
		# baseVec = om.MVector(basePosRaw[0], basePosRaw[1], basePosRaw[2])
		# topVec = om.MVector(topPosRaw[0], topPosRaw[1], topPosRaw[2])

		#find the center position
		ratio = self.centerPos #number 0-1, .5 is the middle

#---------------- now just need to feed adjusted uv pos of mid into "alignToUV"
#---------------- here i should align each top, mid, end to the UV pos I want. . .
		midUV = 0.5 * 2 * ratio

		#create ctrl structure
		prefixList = ["base", "mid", "top"]
		uvList = [0.0, midUV, 1.0]
		groupList = []
		# vecList = [baseVec, midVec, topVec]
		locList = []
		upLocList = []
		ctrlList = []
		ctrlJntList = []

#-----------create some options with switches for how things aim, etc at each other
#--------deal with axis stuff below
#-------then down below we need to use object space to move the locators
#--------below must figure out how to parent the up locs to controls? ???
		#for each of "base", "mid", "top" create the control structure
		for i in range(3):
			groupName = "%s_%s_GRP"%(self.name, prefixList[i])
			groupList.append(groupName)

			# vecName = "%sVec"%prefixList[i]
			# vecList.append(vecName)
#----------------create the whole setup at 000, then align the top group
			#create group
			cmds.group(empty=True, n=groupName)

			thisPos = cmds.xform(groupName, ws=True, q=True, t=True)

			#create and parent constraint locator
			locName = "%s_%s_constr_LOC"%(self.name, prefixList[i])
			locList.append(locName)

			cmds.spaceLocator(n=locName)
			cmds.xform(locName, ws=True, t=(thisPos[0], thisPos[1], thisPos[2]))

			cmds.parent(locName, groupName)

			#create a parent constraint locator under the aim locator

			#create up locator
			upLocName = "%s_%s_up_LOC"%(self.name, prefixList[i])
			upLocList.append(upLocName)

			cmds.spaceLocator(n=upLocName)
			#create option for what direction the up vec is?
#----------------axis here
			cmds.xform(upLocName, ws=True, t=[0,0,-1])
			cmds.parent(upLocName, groupName)

			#create controls
			ctrlName = "%s_%s_CTRL"%(self.name, prefixList[i])
			ctrlList.append(ctrlName)
#----------------axis here
			cmds.circle(nr=(0, 1, 0), r=(self.height/10*3), n=ctrlName)
			cmds.parent(ctrlName, locName)

			#create control joints (will already be parented to ctrl)
			jntName = "%s_%s_ctrl_JNT"%(self.name, prefixList[i])
			ctrlJntList.append(jntName)

			ctrlJoint = cmds.joint(n=jntName, p=(0,0,0))
#----------------axis here
			#align group to surface
			rig.alignToUV(targetObj=groupName, sourceObj=self.ribbonName, sourceU=0.5, sourceV=uvList[i], mainAxis="+z", secAxis="+y", UorV="v")

		#now bind the nurbs geo
		cmds.select(cl=True)

		for jnt in ctrlJntList:
			cmds.select(jnt, add=True)
			cmds.select(self.ribbonName, add=True)

		cmds.skinCluster(mi=3, sw=0.5, omi=True, tsb=True, nw=1)

#-------here add in the constraints to make this work properly. . . on each control have it tell what to aim at? lock these or not (depends on whether it's FK or not?)
#-------also add in the FK option here, too. . .

		#base aim constrain to look at center
		#top aim constrain to look at center
		#mid parent constrain to either?, aim to either, point to either?


		#start packaging stuff up
#-------hide the locators

		folGroup = cmds.group(empty=True, n="%s_follicles_GRP"%self.name)
		for fol in self.follicleList:
			cmds.parent(fol, folGroup)
		cmds.setAttr("%s.inheritsTransform"%folGroup, 0)

		ctrlsGroup = cmds.group(empty=True, n="%s_ctrls_GRP"%self.name)
		for grp in groupList:
			cmds.parent(grp, ctrlsGroup)

		geoGroup = cmds.group(empty=True, n="%s_geo_GRP"%self.name)
		cmds.parent(self.ribbonName, geoGroup)
		cmds.setAttr("%s.inheritsTransform"%geoGroup, 0)

		ribbonGroup = cmds.group(empty=True, n="%s_ribbon_GRP"%self.name)
		cmds.parent(folGroup, ribbonGroup)
		cmds.parent(ctrlsGroup, ribbonGroup)
		cmds.parent(geoGroup, ribbonGroup)

		cmds.select(ribbonGroup)
コード例 #55
0
    def testAnimNSurfaceDeleteReload(self):

        # create an animated Nurbs sphere
        MayaCmds.sphere(ch=False, name='nSphere')
        MayaCmds.move(5, 0, 0, relative=True)
        MayaCmds.select('nSphere.cv[0:1][0:7]', 'nSphere.cv[5:6][0:7]',
            replace=True)
        MayaCmds.setKeyframe(time=[1, 24])
        MayaCmds.currentTime(12, update=True)
        MayaCmds.scale(1.5, 1, 1, relative=True)
        MayaCmds.setKeyframe(time=12)

        # create an animated Nurbs torus
        MayaCmds.torus(ch=False, name='nTorus')
        MayaCmds.move(-5, 0, 0, relative=True)
        MayaCmds.select('nTorus.cv[0][0:7]', 'nTorus.cv[2][0:7]',
            replace=True)
        MayaCmds.setKeyframe(time=[1, 24])
        MayaCmds.currentTime(12, update=True)
        MayaCmds.scale(1, 2, 2, relative=True)
        MayaCmds.setKeyframe(time=12)

        # create an animated Nurbs plane
        # should add the trim curve test on this surface, will be easier
        # than the rest
        MayaCmds.nurbsPlane(ch=False, name='nPlane')
        MayaCmds.move(-5, 5, 0, relative=True)
        MayaCmds.select('nPlane.cv[0:3][0:3]', replace=True)
        MayaCmds.setKeyframe(time=1)
        MayaCmds.currentTime(12, update=True)
        MayaCmds.rotate(0, 0, 90, relative=True)
        MayaCmds.setKeyframe(time=12)
        MayaCmds.currentTime(24, update=True)
        MayaCmds.rotate(0, 0, 90, relative=True)
        MayaCmds.setKeyframe(time=24)

        # create an animated Nurbs cylinder
        MayaCmds.cylinder(ch=False, name='nCylinder')
        MayaCmds.select('nCylinder.cv[0][0:7]', replace=True)
        MayaCmds.setKeyframe(time=[1, 24])
        MayaCmds.currentTime(12, update=True)
        MayaCmds.move(-3, 0, 0, relative=True)
        MayaCmds.setKeyframe(time=12)

        # write it out to Abc file and load back in
        self.__files.append(util.expandFileName('testNSurfaceReload.abc'))
        MayaCmds.AbcExport(j='-fr 1 24 -root nSphere -root nTorus -root nPlane -root nCylinder -file ' +
            self.__files[-1])

        # load back the Abc file, delete the torus and save to a maya file
        MayaCmds.AbcImport(self.__files[-1], mode='open')
        MayaCmds.delete('nTorus')
        self.__files.append(util.expandFileName('test.mb'))
        MayaCmds.file(rename=self.__files[-1])
        MayaCmds.file(save=True)

        # import the saved maya file to compare with the original scene
        MayaCmds.file(self.__files[-1], open=True)
        MayaCmds.select('nSphere', 'nPlane', 'nCylinder', replace=True)
        MayaCmds.group(name='ReloadGrp')
        MayaCmds.AbcImport(self.__files[-2], mode='import')

        surfaceList = MayaCmds.ls(type='nurbsSurface')
        self.failUnlessEqual(len(surfaceList), 7)

        surfaces = [('|nSphere|nSphereShape',
            '|ReloadGrp|nSphere|nSphereShape'),
            ('|nPlane|nPlaneShape', '|ReloadGrp|nPlane|nPlaneShape'),
            ('|nCylinder|nCylinderShape',
            '|ReloadGrp|nCylinder|nCylinderShape')]

        for s in surfaces:
            for t in range(1, 25):
                MayaCmds.currentTime(t, update=True)
                if not util.compareNurbsSurface(s[0], s[1]):
                    self.fail('%s and %s are not the same at frame %d' %
                        (s[0], s[1], t))
コード例 #56
0
ファイル: stretchyspine.py プロジェクト: winsi3d/Art-Tools
def nk_createRibbonSpine(prefix='CHAR_SIDE_LIMB', type='offset'):
 
    ##+++++++++++++++++++++++++++++++++##
    ##+++++++nk_createRibbonSpine++++++##
    ##+++++++++++++++++++++++++++++++++##
 
     
    #Check the type of ribbon
    if type == 'basic':
        suffix = 'rbnBasic'
 
    if type =='offset':
        suffix = 'rbnOffset'
     
     
    #create group for ribbon rig
    ribbonRigGrp = mc.group(em=True, n=(prefix + '_' + suffix + '_rig_grp'))
    # ribbonRigGrp = mc.group(em=True, n=(prefix))
 
    # Create nurbs plane
    ribbonPlane = mc.nurbsPlane (n=(prefix + '_' + suffix + 'Plane'), p=[0, 0, 0], ax= [0, 0 ,1], w=1 ,lr=5 ,d=3, u=1, v=5, ch=0)
    ribbonPlaneShape = mc.listRelatives(ribbonPlane, c=True, s=True) #get shape node
     
    # CLEANUP: Parent plane to rigGrp and turn off inheritsTransforms
    mc.parent(ribbonPlane[0], ribbonRigGrp)
    mc.setAttr('{ribbonPlane}.inheritsTransform'.format(ribbonPlane=ribbonPlane[0]),0, lock=True)
    #mc.setAttr('{ribbonPlane}.inheritsTransform'.format(ribbonPlane=ribbonPlane[0]), lock=True)
     
 
    ## rebuildSurface
    mc.rebuildSurface(ribbonPlane[0], rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, su=1, du=1, sv=0, dv=3, tol=0.01, dir=0)
     
    # Create follicles * 5
     
    ##Create an empty group for the follicles
    folGroup = mc.group(em=True, n=(prefix + '_' + suffix + '_follicleGrp'))
         
    # CLEANUP: Parent follicleGrp to rigGrp
    mc.parent(folGroup, ribbonRigGrp)
     
    ##Create a list for the follicles
    folList = []
 
    ##Create the follicles and ribbon joints
    for f in range(5):
        follicle = mc.createNode('follicle', n=('{prefix}_{suffix}_FollicleShape_{number}'.format(prefix=prefix, suffix=suffix ,number=(f+1))))
        print follicle
        follicleTransform = mc.listRelatives(follicle,  p=True) #get transform node
 
        ribbonJnt = mc.joint(n='{prefix}_{suffix}_jnt_{f}'.format(prefix=prefix,suffix=suffix,f=f+1))#create joint
        grp=mc.group(n=(ribbonJnt+'_offsetGrp'))#grp joint
 
        ## connect folliclesShapes to the plane
        mc.connectAttr(('{ribbonPlaneShape}.local'.format(ribbonPlaneShape=ribbonPlaneShape[0])) ,('{follicle}.inputSurface'.format(follicle=follicle)))
        mc.connectAttr(('{ribbonPlaneShape}.worldMatrix[0]'.format(ribbonPlaneShape=ribbonPlaneShape[0])) ,('{follicle}.inputWorldMatrix'.format(follicle=follicle)))
        ## connect follicleShapes to follicleTransform
        mc.connectAttr((follicle+'.outTranslate'), (follicleTransform[0]+'.translate') )
        mc.connectAttr((follicle+'.outRotate'), (follicleTransform[0]+'.rotate') )
 
        ##position the follicles along the plane
        mc.setAttr((follicle+'.parameterU'), 0.5)
        vSpanHeight = ((f+1.0)/5.0) - .1
        mc.setAttr((follicle+'.parameterV'), vSpanHeight)
         
        #Turn off inherit transforms on the follicles
        mc.setAttr('{follicleTransform}.inheritsTransform'.format(follicleTransform=follicleTransform[0]),0, lock=True)
         
        ##parent the follicle to the group and add to lists
        mc.parent(follicleTransform[0], folGroup)
        folList.append(follicle)
         
    # Create ribbon bind joints and setup aim constraints
    mc.select(cl=True)
 
    bindBaseJnt = mc.joint(p=(0,-2.5,0), o=(0,0,90), rad=2, n=(prefix+'_'+suffix+'_base_bind_01'))
    mc.joint(p=(0,-2,0), n=(prefix+'_ribbon_base_bind_02'))
 
    mc.select(cl=True)
 
    bindTipJnt = mc.joint(p=(0,2.5,0), o=(0,0,-90), rad=2, n=(prefix+'_'+suffix+'_tip_bind_01'))
    mc.joint(p=(0,2,0), n=(prefix+'_ribbon_tip_bind_02'))
 
    mc.select(cl=True)
 
 
    bindMidJnt = mc.joint(p=(0,0,0), o=(0,0,0), rad=2, n=(prefix+'_'+suffix+'_mid_bind_01'))
    mc.select(cl=True)
 
    # create control Locators and parent bindJoint to aimLocator
    ##baseLocators
    basePosLoc = mc.spaceLocator(n=(prefix+'_'+suffix+'_base_pos_loc'))
    baseUpLoc = mc.spaceLocator(n=(prefix+'_'+suffix+'_base_up_loc'))
    baseAimLoc = mc.spaceLocator(n=(prefix+'_'+suffix+'_base_aim_loc'))
 
    mc.parent(baseUpLoc,baseAimLoc,basePosLoc )#parent locators
    mc.xform(basePosLoc, t=(0,-2.5,0))#move locator to base position
    mc.xform(baseUpLoc, ws=True, t=(0,-2.5,2))# offset Up locator in Z
    mc.parent(bindBaseJnt,baseAimLoc)#parent jnt to aim locator
     
     
    #CLEANUP: startPosLoc to rigGrp
    mc.parent(basePosLoc, ribbonRigGrp)
     
    ##midLocators
    midPosLoc = mc.spaceLocator(n=(prefix+'_'+suffix+'_mid_pos_loc'))
    midUpLoc = mc.spaceLocator(n=(prefix+'_'+suffix+'_mid_up_loc'))
    midAimLoc = mc.spaceLocator(n=(prefix+'_'+suffix+'_mid_aim_loc'))
 
    mc.parent(midUpLoc,midAimLoc,midPosLoc )#parent locators
    mc.xform(midUpLoc, ws=True, t=(0,0,2))# offset Up locator in Z
    mc.parent(bindMidJnt,midAimLoc)#parent jnt to aim locator
     
    mc.parent(midPosLoc, ribbonRigGrp)
     
    ##tipLocators
    tipPosLoc = mc.spaceLocator(n=(prefix+'_'+suffix+'_tip_pos_loc'))
    tipUpLoc = mc.spaceLocator(n=(prefix+'_'+suffix+'_tip_up_loc'))
    tipAimLoc = mc.spaceLocator(n=(prefix+'_'+suffix+'_tip_aim_loc'))
 
    mc.parent(tipUpLoc,tipAimLoc,tipPosLoc)#parent locators
    mc.xform(tipPosLoc, t=(0,2.5,0))#move locator to tip position
    mc.xform(tipUpLoc, ws=True, t=(0,2.5,2))# offset Up locator in Z
    mc.parent(bindTipJnt,tipAimLoc)#parent jnt to aim locator
     
    #CLEANUP: tipPosLoc to rigGrp 
    mc.parent(tipPosLoc, ribbonRigGrp)
     
    #setup aim relationsips
    ##basic
    if type=='basic':
        ##baseAimLoc > tipPos##
        mc.aimConstraint(tipPosLoc[0],baseAimLoc[0], aim=(0,1,0), u=(0,0,1), wut='object', wuo=baseUpLoc[0])
        ##tipAimLoc > basePos##
        mc.aimConstraint(basePosLoc[0],tipAimLoc[0], aim=(0,-1,0), u=(0,0,1), wut='object', wuo=tipUpLoc[0])
        ##midAimLoc > tipPos##
        mc.aimConstraint(tipPosLoc[0],midAimLoc[0], aim=(0,1,0), u=(0,0,1), wut='object', wuo=midUpLoc[0])
         
        # midPosLoc to follow both base and tip
        mc.pointConstraint(basePosLoc[0],tipPosLoc[0],midPosLoc[0], mo=False)
        # midPosAim to follow both base and tip Aim
        mc.pointConstraint(baseUpLoc[0],tipUpLoc[0],midUpLoc[0], mo=False)
         
    if type=='offset':
         
        ##baseAimLoc > midBindJoint##
        mc.aimConstraint(bindMidJnt,baseAimLoc[0], aim=(0,1,0), u=(0,0,1), wut='object', wuo=baseUpLoc[0])
        #tipAimLoc > midBindJoint##
        mc.aimConstraint(bindMidJnt,tipAimLoc[0], aim=(0,-1,0), u=(0,0,1), wut='object', wuo=tipUpLoc[0])
        ##midAimLoc > tipPos##
        mc.aimConstraint(tipPosLoc[0],midAimLoc[0], aim=(0,1,0), u=(0,0,1), wut='object', wuo=midUpLoc[0])
         
        # midPosLoc to follow both base and tip
        mc.pointConstraint(basePosLoc[0],tipPosLoc[0],midPosLoc[0], mo=False)
        # midPosAim to follow both base and tip Aim
        mc.pointConstraint(baseUpLoc[0],tipUpLoc[0],midUpLoc[0], mo=False)
 
    # Bind skin 
    mc.select(cl=True)
    print bindBaseJnt 
    print bindMidJnt 
    print bindTipJnt
    mc.skinCluster(bindBaseJnt,bindMidJnt,bindTipJnt,ribbonPlane, n=(prefix+'_'+suffix+'_skinCluster'), tsb=True, ih=True, bm=0, sm=0, nw=1, wd=0, mi=3, omi=False, dr=4)
コード例 #57
0
ファイル: zbw_ribbon.py プロジェクト: lefan2016/zTools
    def createRibbon(self, *args):
        self.name = cmds.textFieldGrp(self.widgets["ribbonNameTFG"],
                                      q=True,
                                      tx=True)
        self.numDiv = (cmds.intFieldGrp(
            self.widgets["jointsIFG"], q=True, v=True)[0]) - 1
        self.fk = cmds.checkBox(self.widgets["fkSetupCB"], q=True, v=True)
        self.height = cmds.floatFieldGrp(self.widgets["heightFFG"],
                                         q=True,
                                         v1=True)
        self.ratio = cmds.floatFieldGrp(self.widgets["ratioFFG"],
                                        q=True,
                                        v1=True)
        self.axis = cmds.radioButtonGrp(self.widgets["axis"], q=True, sl=True)

        print("axis = :%s" % self.axis)
        self.ribbonName = "%s_ribbonGeo" % self.name
        self.numJoints = self.numDiv
        self.follicleList = []
        self.follicleJntList = []
        self.own = cmds.checkBox(self.widgets["existingGeoCB"], q=True, v=True)
        self.myGeo = cmds.textFieldButtonGrp(self.widgets["geoTFBG"],
                                             q=True,
                                             tx=True)
        self.dir = cmds.radioButtonGrp(self.widgets["directionRBG"],
                                       q=True,
                                       sl=True)
        print("dir: %s" % self.dir)
        self.centerPos = cmds.floatSliderGrp(self.widgets["centerPosFSG"],
                                             q=True,
                                             v=True)
        self.follicleGrpList = []

        #-----------make sure the num of divisions is at least 1
        #-----------create the nurbs plane in the correct axis (just make the plane in the axis and figure out how to rotate joint local rotational axes to match it) DON'T WORRY ABOUT THIS SO MUCH (IT'S HIDDEN), WORRY ABOUT THE CONTROLS BEING ORIENTED CORRECTLY!!!

        if self.own == 0:
            self.dir = 2
        if self.dir == 1:
            dir = "u"
            uDiv = self.numDiv
            vDiv = 1
        else:
            dir = "v'"
            uDiv = 1
            vDiv = self.numDiv

        # if self.axis  == 1:
        axis = [0, 0, 1]
        # elif self.axis  == 2:
        # 	axis = [0, 1, 0]
        # elif self.axis  == 3:
        # 	axis = [0, 0, 1]

        if self.own == 0:
            width = self.height / self.ratio
            #create the nurbsPlane
            cmds.nurbsPlane(ax=axis,
                            w=width,
                            lr=self.ratio,
                            d=3,
                            u=uDiv,
                            v=vDiv,
                            ch=0,
                            n=self.ribbonName)
            cmds.rebuildSurface(self.ribbonName,
                                ch=0,
                                rpo=1,
                                rt=0,
                                end=1,
                                kr=0,
                                kcp=0,
                                kc=0,
                                su=1,
                                du=1,
                                sv=self.numDiv,
                                dv=3,
                                tol=0.1,
                                fr=0,
                                dir=0)
            cmds.move(0, self.height / 2, 0, self.ribbonName)

            cmds.xform(self.ribbonName, ws=True, rp=[0, 0, 0])
        else:
            self.ribbonName = self.myGeo

        #find the ratio for the uv's (one dir will be .5, the other a result of the num joints)
        factor = 1.0 / self.numJoints

        #-------keep follicle joints separate, not parente under each follicle, separate group for those
        #-------follicle jnts each go under a ctrl (star) that is under a group. That group gets parent constrained to the follicles
        #-------these joints should be aligned with the follicles??? does that make a difference?

        #create the follicles on the surface, joints on the follicles
        for x in range(self.numJoints + 1):
            val = x * factor
            folName = "%s_follicle%s" % (self.name, x)
            #create a follicle in the right direction
            if self.dir == 1:
                follicle = rig.follicle(self.ribbonName, folName, val, 0.5)[0]
            else:
                follicle = rig.follicle(self.ribbonName, folName, 0.5, val)[0]

            self.follicleList.append(follicle)

            #create joint and parent to follicle
            jointName = "%s_fol%s_JNT" % (self.name, x)
            #---------have to figure out how to orient this correctly (just translate and rotate the joints (or the controls they're under))
            #create joint control? then move the control and the joint under it to the correct rot and pos
            folPos = cmds.xform(follicle, q=True, ws=True, t=True)
            folRot = cmds.xform(follicle, q=True, ws=True, ro=True)
            cmds.select(cl=True)
            folJoint = cmds.joint(n=jointName, p=(0, 0, 0))
            folGroup = cmds.group(
                folJoint, n="%s_GRP" %
                folJoint)  #this could become control for the joint
            cmds.xform(folGroup, a=True, ws=True, t=folPos)
            cmds.xform(folGroup, a=True, ws=True, ro=folRot)
            self.follicleJntList.append(folJoint)
            self.follicleGrpList.append(folGroup)
            cmds.parent(folGroup, follicle)

        #now create the control structure for the ribbon
        # basePosRaw = cmds.xform(self.follicleJntList[0], ws=True, q=True, t=True)
        # topPosRaw = cmds.xform(self.follicleJntList[self.numJoints], ws=True, q=True, t=True)
        # baseVec = om.MVector(basePosRaw[0], basePosRaw[1], basePosRaw[2])
        # topVec = om.MVector(topPosRaw[0], topPosRaw[1], topPosRaw[2])

        #find the center position
        ratio = self.centerPos  #number 0-1, .5 is the middle

        #---------------- now just need to feed adjusted uv pos of mid into "alignToUV"
        #---------------- here i should align each top, mid, end to the UV pos I want. . .
        midUV = 0.5 * 2 * ratio

        #create ctrl structure
        prefixList = ["base", "mid", "top"]
        uvList = [0.0, midUV, 1.0]
        groupList = []
        # vecList = [baseVec, midVec, topVec]
        locList = []
        upLocList = []
        ctrlList = []
        ctrlJntList = []

        #-----------create some options with switches for how things aim, etc at each other
        #--------deal with axis stuff below
        #-------then down below we need to use object space to move the locators
        #--------below must figure out how to parent the up locs to controls? ???
        #for each of "base", "mid", "top" create the control structure
        for i in range(3):
            groupName = "%s_%s_GRP" % (self.name, prefixList[i])
            groupList.append(groupName)

            # vecName = "%sVec"%prefixList[i]
            # vecList.append(vecName)
            #----------------create the whole setup at 000, then align the top group
            #create group
            cmds.group(empty=True, n=groupName)

            thisPos = cmds.xform(groupName, ws=True, q=True, t=True)

            #create and parent constraint locator
            locName = "%s_%s_constr_LOC" % (self.name, prefixList[i])
            locList.append(locName)

            cmds.spaceLocator(n=locName)
            cmds.xform(locName,
                       ws=True,
                       t=(thisPos[0], thisPos[1], thisPos[2]))

            cmds.parent(locName, groupName)

            #create a parent constraint locator under the aim locator

            #create up locator
            upLocName = "%s_%s_up_LOC" % (self.name, prefixList[i])
            upLocList.append(upLocName)

            cmds.spaceLocator(n=upLocName)
            #create option for what direction the up vec is?
            #----------------axis here
            cmds.xform(upLocName, ws=True, t=[0, 0, -1])
            cmds.parent(upLocName, groupName)

            #create controls
            ctrlName = "%s_%s_CTRL" % (self.name, prefixList[i])
            ctrlList.append(ctrlName)
            #----------------axis here
            cmds.circle(nr=(0, 1, 0), r=(self.height / 10 * 3), n=ctrlName)
            cmds.parent(ctrlName, locName)

            #create control joints (will already be parented to ctrl)
            jntName = "%s_%s_ctrl_JNT" % (self.name, prefixList[i])
            ctrlJntList.append(jntName)

            ctrlJoint = cmds.joint(n=jntName, p=(0, 0, 0))
            #----------------axis here
            #align group to surface
            rig.alignToUV(targetObj=groupName,
                          sourceObj=self.ribbonName,
                          sourceU=0.5,
                          sourceV=uvList[i],
                          mainAxis="+z",
                          secAxis="+y",
                          UorV="v")

        #now bind the nurbs geo
        cmds.select(cl=True)

        for jnt in ctrlJntList:
            cmds.select(jnt, add=True)
            cmds.select(self.ribbonName, add=True)

        cmds.skinCluster(mi=3, sw=0.5, omi=True, tsb=True, nw=1)

        #-------here add in the constraints to make this work properly. . . on each control have it tell what to aim at? lock these or not (depends on whether it's FK or not?)
        #-------also add in the FK option here, too. . .

        #base aim constrain to look at center
        #top aim constrain to look at center
        #mid parent constrain to either?, aim to either, point to either?

        #start packaging stuff up
        #-------hide the locators

        folGroup = cmds.group(empty=True, n="%s_follicles_GRP" % self.name)
        for fol in self.follicleList:
            cmds.parent(fol, folGroup)
        cmds.setAttr("%s.inheritsTransform" % folGroup, 0)

        ctrlsGroup = cmds.group(empty=True, n="%s_ctrls_GRP" % self.name)
        for grp in groupList:
            cmds.parent(grp, ctrlsGroup)

        geoGroup = cmds.group(empty=True, n="%s_geo_GRP" % self.name)
        cmds.parent(self.ribbonName, geoGroup)
        cmds.setAttr("%s.inheritsTransform" % geoGroup, 0)

        ribbonGroup = cmds.group(empty=True, n="%s_ribbon_GRP" % self.name)
        cmds.parent(folGroup, ribbonGroup)
        cmds.parent(ctrlsGroup, ribbonGroup)
        cmds.parent(geoGroup, ribbonGroup)

        cmds.select(ribbonGroup)
コード例 #58
0
def create(samplePt, pntList, weightCalc=[True, True, True], prefix=None):
    """
    Generate the barycentric point weight setup based on the input arguments
    @param samplePt: The locator used to define the triangle sample point to generate weights for
    @type samplePt: str
    @param pntList: List of points to define triangle
    @type pntList: list
    @param weightCalc: List of booleans to define which point weights are calculated
    @type weightCalc: list
    @param prefix: String name prefix for all created nodes
    @type prefix: str
    """
    # ==========
    # - Checks -
    # ==========

    # Check Sample Point (Locator)
    if not cmds.objExists(samplePt):
        raise Exception('Sample point "' + samplePt + '" does not exist!!')

    # Check prefix
    if not prefix: prefix = 'barycentricPointWeight'

    # ========================
    # - Setup Full Area Calc -
    # ========================

    # Build pntFace surface
    pntFace = cmds.nurbsPlane(p=(0, 0, 0), ax=(0, 1, 0), d=1, ch=False, n=prefix + '_sample_surface')[0]
    pntLoc = glTools.utils.surface.locatorSurface(pntFace, prefix=prefix)
    cmds.delete(cmds.pointConstraint(pntList[0], pntLoc[0]))
    cmds.delete(cmds.pointConstraint(pntList[1], pntLoc[1]))
    cmds.delete(cmds.pointConstraint(pntList[2], pntLoc[2]))
    cmds.delete(cmds.pointConstraint(pntList[2], pntLoc[3]))

    # Attach follow pt
    followLoc = cmds.spaceLocator(n=prefix + '_follow_locator')[0]
    follow_cpos = cmds.createNode('closestPointOnSurface', n=prefix + '_closestPointOnSurface')
    cmds.connectAttr(samplePt + '.worldPosition[0]', follow_cpos + '.inPosition', f=True)
    cmds.connectAttr(pntFace + '.worldSpace[0]', follow_cpos + '.inputSurface', f=True)
    cmds.connectAttr(follow_cpos + '.position', followLoc + '.translate', f=True)

    # Calculate triArea
    triEdge1_pma = cmds.createNode('plusMinusAverage', n=prefix + '_triEdge1Vec_plusMinusAverage')
    triEdge2_pma = cmds.createNode('plusMinusAverage', n=prefix + '_triEdge2Vec_plusMinusAverage')
    cmds.setAttr(triEdge1_pma + '.operation', 2)  # Subtract
    cmds.setAttr(triEdge2_pma + '.operation', 2)  # Subtract
    cmds.connectAttr(pntLoc[1] + '.worldPosition[0]', triEdge1_pma + '.input3D[0]', f=True)
    cmds.connectAttr(pntLoc[0] + '.worldPosition[0]', triEdge1_pma + '.input3D[1]', f=True)
    cmds.connectAttr(pntLoc[2] + '.worldPosition[0]', triEdge2_pma + '.input3D[0]', f=True)
    cmds.connectAttr(pntLoc[0] + '.worldPosition[0]', triEdge2_pma + '.input3D[1]', f=True)

    triArea_vpn = cmds.createNode('vectorProduct', n=prefix + '_triArea_vectorProduct')
    cmds.setAttr(triArea_vpn + '.operation', 2)  # Cross Product
    cmds.connectAttr(triEdge1_pma + '.output3D', triArea_vpn + '.input1', f=True)
    cmds.connectAttr(triEdge2_pma + '.output3D', triArea_vpn + '.input2', f=True)

    triArea_dist = cmds.createNode('distanceBetween', n=prefix + '_triArea_distanceBetween')
    cmds.connectAttr(triArea_vpn + '.output', triArea_dist + '.point1', f=True)

    # =======================
    # - Setup Sub Area Calc -
    # =======================

    # Calculate triPt weights
    for i in range(3):

        # Check weight calculation (bool)
        if weightCalc[i]:
            # Calculate sub-TriArea
            pntEdge1_pma = cmds.createNode('plusMinusAverage', n=prefix + '_pt' + str(i) + 'Edge1Vec_plusMinusAverage')
            pntEdge2_pma = cmds.createNode('plusMinusAverage', n=prefix + '_pt' + str(i) + 'Edge2Vec_plusMinusAverage')
            cmds.setAttr(pntEdge1_pma + '.operation', 2)  # Subtract
            cmds.setAttr(pntEdge2_pma + '.operation', 2)  # Subtract
            cmds.connectAttr(pntLoc[(i + 1) % 3] + '.worldPosition[0]', pntEdge1_pma + '.input3D[0]', f=True)
            cmds.connectAttr(followLoc + '.worldPosition[0]', pntEdge1_pma + '.input3D[1]', f=True)
            cmds.connectAttr(pntLoc[(i + 2) % 3] + '.worldPosition[0]', pntEdge2_pma + '.input3D[0]', f=True)
            cmds.connectAttr(followLoc + '.worldPosition[0]', pntEdge2_pma + '.input3D[1]', f=True)

            pntArea_vpn = cmds.createNode('vectorProduct', n=prefix + '_pt' + str(i) + 'Area_vectorProduct')
            cmds.setAttr(pntArea_vpn + '.operation', 2)  # Cross Product
            cmds.connectAttr(pntEdge1_pma + '.output3D', pntArea_vpn + '.input1', f=True)
            cmds.connectAttr(pntEdge2_pma + '.output3D', pntArea_vpn + '.input2', f=True)

            pntArea_dist = cmds.createNode('distanceBetween', n=prefix + '_pt' + str(i) + 'Area_distanceBetween')
            cmds.connectAttr(pntArea_vpn + '.output', pntArea_dist + '.point1', f=True)

            # Divide ptArea by triArea to get weight
            pntWeight_mdn = cmds.createNode('multiplyDivide', n=prefix + '_pt' + str(i) + 'Weight_multiplyDivide')
            cmds.setAttr(pntWeight_mdn + '.operation', 2)  # Divide
            cmds.connectAttr(pntArea_dist + '.distance', pntWeight_mdn + '.input1X', f=True)
            cmds.connectAttr(triArea_dist + '.distance', pntWeight_mdn + '.input2X', f=True)

            # Add weight attribute to pntLoc
            cmds.addAttr(pntLoc[i], ln='weight', min=0.0, max=1.0, dv=0.0)
            cmds.connectAttr(pntWeight_mdn + '.outputX', pntLoc[i] + '.weight', f=True)

    # ============
    # - CLEAN UP -
    # ============

    # Group mesh locators
    pntLoc_grp = cmds.group(pntLoc, n=prefix + '_3Point_grp')
    cmds.parent(pntFace, pntLoc_grp)

    # Turn off inheritTransforms for tri point face
    cmds.setAttr(pntFace + '.inheritsTransform', 0)

    # Scale follow locator
    cmds.setAttr(followLoc + '.localScale', 0.05, 0.05, 0.05)

    # Parent and hide coincident locator
    cmds.parent(pntLoc[3], pntLoc[2])
    cmds.setAttr(pntLoc[3] + '.v', 0)

    # =================
    # - Return Result -
    # =================

    # Return result
    return [pntLoc, pntFace, pntLoc_grp]
コード例 #59
0
    def createChain(self, *args):
        startJnt = mc.textFieldButtonGrp(self.loadStartJntFld, query=True, text=True   )
        self.startCtrl = mc.textFieldButtonGrp(self.loadStartCtrlFld, query=True, text=True   )
        self.endCtrl = mc.textFieldButtonGrp(self.loadEndCtrlFld, query=True, text=True   )        
        self.prefix = mc.textFieldGrp(self.prefixFld, query=True, text=True   )
        
        jointNames = [] 

        mc.select(startJnt, hierarchy=True) 
        jointNames = mc.ls(sl=True,fl=True,typ="joint") 

        axis = mc.radioButtonGrp(self.axisSelected,query=True,sl=True)
        
        mc.select(clear=True)
        #print jointNames
        
        if axis == 1:
            axVal = [1,0,0]
        if axis == 2:
            axVal = [0,1,0]
        if axis == 3:
            axVal = [0,0,1]
        
        planeName = mc.nurbsPlane(p= (0,0,0), ax= axVal, w=.3, lr= 1, d= 3, u= 1, v= 1, ch= 0);
        planeVisAtt = (planeName[0] + ".visibility")
        #Hiding plane
        mc.setAttr(planeVisAtt, 0)

        #snapping plane to start jnt
        pos = mc.xform( startJnt, q=1, ws=True, t=1)
        mc.xform( planeName, ws=True, t=[pos[0], pos[1], pos[2]]) 
        rot = mc.xform( startJnt, q=1, ws=True, ro=1)
        mc.xform( planeName, ws=True, ro=[rot[0], rot[1], rot[2]]) 	
        
        nodeName = (self.prefix + "_DynChain_TopNode") #Create rig top node
        mc.createNode('transform',n=nodeName)
        
        mc.parent(nodeName, self.startCtrl)
        mc.parent(planeName, nodeName)
        
        posTemp = []
        jointPosArray = []
        
        for x in jointNames: #Storing joint positions to create curve with
        	posTemp = mc.xform(x, q=1, ws=True, t=1)
        	#print posTemp
        	jointPosArray.append(posTemp)
        	
        #Create curve
        curveName = (self.prefix + "_BaseCrv")
        curve1 = mc.curve(d=1, point =jointPosArray[0])
        mc.rename(curve1, curveName)
        
        max = len(jointPosArray)
        self.counter = 0
        for x in jointPosArray: 
        	self.counter= self.counter + 1 
        	if self.counter < max: 
        		mc.curve(curveName, append=1, point= jointPosArray[self.counter])
        		
        #Make curve dynamic
        mc.select(curveName,planeName,r=1)
        mel.eval("makeCurvesDynamicHairs 1 0 1")
        
        hairSystemName = mc.pickWalk(curveName,d="up") #Go up to follice
        hairSystemName = mc.pickWalk(hairSystemName,d="up") #Go up to hairSystemFollicles
        	
        temp = hairSystemName[0] #convert list to string
        self.hairSystemName = temp[:-9]	#Remove"Follicles" from name to derive hair system name
        hairSysOPCurves = (self.hairSystemName + "OutputCurves")
        
        self.dynCurve = mc.pickWalk(hairSysOPCurves, d="down")
        		
        for x in jointNames:
        	endEffector = x #Final joint in list
        self.dynCurve = str(self.dynCurve)
        self.dynCurve = self.dynCurve[3:-2] #Cleaning up name via splicing: [u'name1'] = name1
        
        ikHandleName = (self.prefix + "_ikHandle")

        #print self.dynCurve	
        mc.ikHandle(n=ikHandleName ,sol='ikSplineSolver', ccv=0, scv=0, pcv=0,sj=jointNames[0],ee=endEffector, c=str(self.dynCurve));
        
        hairSysFollicles = (self.hairSystemName + "Follicles")
        groupName = (self.prefix + "_DynChain_Grp")   #Setting group name
        
        #clean up nodes
        mc.select(ikHandleName,hairSysOPCurves,hairSysFollicles,self.hairSystemName,r=1)
        mc.group(n=groupName)
        
        mc.select(clear=True)
        grpAttr = (groupName + ".visibility")
        mc.setAttr(grpAttr, 0)
        
        print ("//Created Chain and hid " + groupName + "\n")
        hairGroups.append(groupName)
        
        self.follicle = mc.pickWalk(hairSysFollicles, d='down')  # The follicle
        
        #Create dynamic attributes on controllers
        self.createAtts()
        
        temp = len(self.endCtrl)
        if temp: #Not zero or null
            self.addConstraint()