Exemplo n.º 1
0
    def doRig(self):
        cnstrGrp = pm.group(em=True, n=self.name + 'EyeLid_constrained_grp')
        sysGrp = pm.group(em=True, n=self.name + 'EyeLidSys_grp')
        crvsGrp = pm.group(em=True, n=self.name + 'Curves_grp')
        clsGrp = pm.group(em=True, n=self.name + 'Clusters_grp')
        jntGrp = pm.group(em=True, n=self.name + 'Joints_grp')
        locGrp = pm.group(em=True, n=self.name + 'Locators_grp')

        if pm.objExists('head_contrained'):
            constrained_grp = 'head_contrained'
        else:
            constrained_grp = pm.group(n='head_contrained', em=True)

        pm.parent(crvsGrp, clsGrp, jntGrp, locGrp, sysGrp)
        sysGrp.visibility.set(False)

        pm.delete(self.upCtrlCrv, self.lowCtrlCrv, ch=True)

        self.upEdgeLoop = selectLoopByLocators(mesh=self.mesh,
                                               loc1=self.inCorner,
                                               loc2=self.outCorner,
                                               loc3=self.upCorner)
        pm.select(self.upEdgeLoop)
        upCrv = pm.polyToCurve(form=2,
                               degree=1,
                               n=self.name + 'UpperCrv',
                               ch=False)[0]
        self.upCrv = pm.rebuildCurve(upCrv,
                                     rt=3,
                                     rpo=True,
                                     d=3,
                                     end=1,
                                     kr=0,
                                     kcp=1,
                                     kep=0,
                                     kt=0,
                                     s=25,
                                     tol=0.01,
                                     ch=False)[0]

        if not atStart(loc=self.inCorner, crvName=self.upCrv):
            pm.reverseCurve(self.upCrv, ch=False, replaceOriginal=True)

        self.lowEdgeLoop = selectLoopByLocators(mesh=self.mesh,
                                                loc1=self.inCorner,
                                                loc2=self.outCorner,
                                                loc3=self.lowCorner)
        pm.select(self.lowEdgeLoop)
        lowCrv = pm.polyToCurve(form=2,
                                degree=1,
                                n=self.name + 'LowerCrv',
                                ch=False)[0]
        self.lowCrv = pm.rebuildCurve(lowCrv,
                                      rt=3,
                                      rpo=True,
                                      d=3,
                                      end=1,
                                      kr=0,
                                      kcp=1,
                                      kep=0,
                                      kt=0,
                                      s=25,
                                      tol=0.01,
                                      ch=False)[0]

        if not atStart(loc=self.inCorner, crvName=self.lowCrv):
            pm.reverseCurve(self.lowCrv, ch=False, replaceOriginal=True)

        upBlink = pm.rebuildCurve(self.upCrv,
                                  s=20,
                                  rt=0,
                                  rpo=False,
                                  ch=False,
                                  n=self.name + 'upBlink')[0]
        lowBlink = pm.rebuildCurve(self.lowCrv,
                                   s=20,
                                   rt=0,
                                   rpo=False,
                                   ch=False,
                                   n=self.name + 'lowBlink')[0]
        upTarget = pm.rebuildCurve(self.upCrv,
                                   s=20,
                                   rt=0,
                                   rpo=False,
                                   ch=False,
                                   n=self.name + 'upTarget')[0]
        lowTarget = pm.rebuildCurve(self.lowCrv,
                                    s=20,
                                    rt=0,
                                    rpo=False,
                                    ch=False,
                                    n=self.name + 'lowTarget')[0]
        midTarget = pm.rebuildCurve(self.lowCrv,
                                    s=20,
                                    rt=0,
                                    rpo=False,
                                    ch=False,
                                    n=self.name + 'midTarget')[0]

        pm.parent(upTarget, lowTarget, midTarget, lowBlink, upBlink,
                  self.upCtrlCrv, self.lowCtrlCrv, self.upCrv, self.lowCrv,
                  crvsGrp)

        w1 = pm.wire(self.upCrv, w=upBlink)[0]
        w2 = pm.wire(self.lowCrv, w=lowBlink)[0]
        w3 = pm.wire(upTarget, w=self.upCtrlCrv)[0]
        w4 = pm.wire(lowTarget, w=self.lowCtrlCrv)[0]

        bs_upBlink = pm.blendShape(upTarget,
                                   midTarget,
                                   upBlink,
                                   n=self.name + "blendShapeUpBlink")
        bs_lowBlink = pm.blendShape(lowTarget,
                                    midTarget,
                                    lowBlink,
                                    n=self.name + "blendShapeLowBlink")
        bs_mid = pm.blendShape(lowTarget,
                               upTarget,
                               midTarget,
                               n=self.name + "blendShapeLowBlink")

        # setting blendshape reverse connections
        rev_node = pm.createNode("reverse")
        pm.connectAttr(bs_upBlink[0].attr(midTarget.name()),
                       rev_node + ".inputX")
        pm.connectAttr(rev_node + ".outputX",
                       bs_upBlink[0].attr(upTarget.name()))
        rev_node = pm.createNode("reverse")
        pm.connectAttr(bs_lowBlink[0].attr(midTarget.name()),
                       rev_node + ".inputX")
        pm.connectAttr(rev_node + ".outputX",
                       bs_lowBlink[0].attr(lowTarget.name()))
        rev_node = pm.createNode("reverse")
        pm.connectAttr(bs_mid[0].attr(upTarget.name()), rev_node + ".inputX")
        pm.connectAttr(rev_node + ".outputX", bs_mid[0].attr(lowTarget.name()))

        # setting default values
        bs_mid[0].attr(upTarget.name()).set(.3)

        cvsUp = self.upCtrlCrv.getCVs(space="world")
        cvsLow = self.lowCtrlCrv.getCVs(space="world")

        upCtrls = []
        lowCtrls = []
        cornerCtrls = []

        for i in range(1, 4):
            pos = cvsUp[i]
            clsUp = pm.cluster(self.upCtrlCrv.cv[i],
                               n=self.name + 'ClsUp' + str(i))[1]
            pm.group()
            rp = pm.xform(clsUp, q=True, rp=True, ws=True)
            grp = pm.group(em=True, n=clsUp.name() + 'off1_grp')
            pm.xform(grp, t=rp, ws=True)
            grp1 = pm.duplicate(grp, n=clsUp.name() + 'off2_grp')[0]
            pm.parent(grp, grp1)
            pm.parent(clsUp.getParent(), grp)
            pm.parent(grp1, clsGrp)

            ctrlUp = controlTools.cntrlCrv(name=self.name + 'EyeLidUp' +
                                           str(i),
                                           obj=clsUp,
                                           connType='connection',
                                           hasZeroGrp=True,
                                           cntrlSulfix='_ctrl',
                                           icone='circuloZ',
                                           size=.1,
                                           offsets=1)

            ctrlUp.getParent().translate >> grp.translate
            ctrlUp.getParent().rotate >> grp.rotate
            ctrlUp.getParent().scale >> grp.scale

            pm.xform(ctrlUp.getParent(2), ws=True, t=pos)
            pm.parent(ctrlUp.getParent(2), cnstrGrp)
            upCtrls.append(ctrlUp)

            pos = cvsLow[i]
            clsLow = pm.cluster(self.lowCtrlCrv.cv[i],
                                n=self.name + 'ClsLow' + str(i))[1]
            pm.group()
            rp = pm.xform(clsLow, q=True, rp=True, ws=True)
            grp = pm.group(em=True, n=clsLow.name() + 'off1_grp')
            pm.xform(grp, t=rp, ws=True)
            grp1 = pm.duplicate(grp, n=clsLow.name() + 'off2_grp')[0]
            pm.parent(grp, grp1)
            pm.parent(clsLow.getParent(), grp)
            pm.parent(grp1, clsGrp)

            ctrlLow = controlTools.cntrlCrv(name=self.name + 'EyeLidLow' +
                                            str(i),
                                            obj=clsLow,
                                            connType='connection',
                                            hasZeroGrp=True,
                                            cntrlSulfix='_ctrl',
                                            icone='circuloZ',
                                            size=.1,
                                            offsets=1)

            ctrlLow.getParent().translate >> grp.translate
            ctrlLow.getParent().rotate >> grp.rotate
            ctrlLow.getParent().scale >> grp.scale

            pm.xform(ctrlLow.getParent(2), ws=True, t=pos)
            pm.parent(ctrlLow.getParent(2), cnstrGrp)
            lowCtrls.append(ctrlLow)

        for i in [0, 4]:
            pos = cvsUp[i]
            clsCorner = pm.cluster(self.upCtrlCrv.cv[i],
                                   self.lowCtrlCrv.cv[i],
                                   n=self.name + 'ClsCorner' + str(i))[1]
            pm.group()
            rp = pm.xform(clsCorner, q=True, rp=True, ws=True)
            grp = pm.group(em=True, n=clsCorner.name() + 'off1_grp')
            pm.xform(grp, t=rp, ws=True)
            grp1 = pm.duplicate(grp, n=clsCorner.name() + 'off2_grp')[0]
            pm.parent(grp, grp1)
            pm.parent(clsCorner.getParent(), grp)
            pm.parent(grp1, clsGrp)

            ctrlCorner = controlTools.cntrlCrv(name=self.name +
                                               'EyeLidCorner' + str(i),
                                               obj=clsCorner,
                                               connType='connection',
                                               hasZeroGrp=True,
                                               cntrlSulfix='_ctrl',
                                               icone='circuloZ',
                                               size=.1,
                                               offsets=1)

            pm.xform(ctrlCorner.getParent(2), ws=True, t=pos)
            pm.parent(ctrlCorner.getParent(2), cnstrGrp)
            cornerCtrls.append(ctrlCorner)

        upCrvNode = pm.PyNode(self.upCrv)
        lowCrvNode = pm.PyNode(self.lowCrv)
        centerPos = pm.xform(self.eyeCenter, q=True, ws=True, t=True)

        cvs = upCrvNode.getCVs(space="world")
        aimLocs = []
        for i, pos in enumerate(cvs):
            pm.select(cl=True)
            jntBase = pm.joint(p=centerPos,
                               n=self.name + 'EyelidUp_' + str(i) + '_zero')
            jnt = pm.joint(p=pos, n=self.name + 'EyelidUp_' + str(i) + '_jnt')
            self.skinJoints.append(jnt.name())
            pm.joint(jntBase, e=True, zso=True, oj='xyz', sao='yup')
            pm.parent(jntBase, jntGrp)
            loc = pm.spaceLocator(p=[0, 0, 0], n=jnt.name() + 'UpAim_loc')
            loc.translate.set(pos)
            loc.localScale.set(.01, .01, .01)
            pm.aimConstraint(loc,
                             jntBase,
                             aim=(1, 0, 0),
                             u=(0, 1, 0),
                             wut='vector',
                             wu=(0, 1, 0))
            pm.parent(loc, locGrp)
            aimLocs.append(loc)

        pm.select(aimLocs, self.upCrv)
        attachTools.hookOnCurve(tangent=False)

        cvs = lowCrvNode.getCVs(space="world")
        aimLocs = []
        for i, pos in enumerate(cvs):
            pm.select(cl=True)
            jntBase = pm.joint(p=centerPos,
                               n=self.name + 'EyelidLw_' + str(i) + '_zero')
            jnt = pm.joint(p=pos, n=self.name + 'EyelidLw_' + str(i) + '_jnt')
            self.skinJoints.append(jnt.name())
            pm.joint(jntBase, e=True, zso=True, oj='xyz', sao='yup')
            pm.parent(jntBase, jntGrp)
            loc = pm.spaceLocator(p=[0, 0, 0], n=jnt.name() + 'LwAim_loc')
            loc.translate.set(pos)
            loc.localScale.set(.01, .01, .01)
            pm.aimConstraint(loc,
                             jntBase,
                             aim=(1, 0, 0),
                             u=(0, 1, 0),
                             wut='vector',
                             wu=(0, 1, 0))
            pm.parent(loc, locGrp)
            aimLocs.append(loc)

        pm.select(aimLocs, self.lowCrv)
        attachTools.hookOnCurve(tangent=False)

        pm.parentConstraint(upCtrls[1],
                            cornerCtrls[0],
                            upCtrls[0].getParent(),
                            mo=1)
        pm.parentConstraint(upCtrls[1],
                            cornerCtrls[1],
                            upCtrls[2].getParent(),
                            mo=1)
        pm.parentConstraint(lowCtrls[1],
                            cornerCtrls[0],
                            lowCtrls[0].getParent(),
                            mo=1)
        pm.parentConstraint(lowCtrls[1],
                            cornerCtrls[1],
                            lowCtrls[2].getParent(),
                            mo=1)

        up_ctl = upCtrls[1]
        pm.addAttr(up_ctl,
                   ln="blink",
                   at="float",
                   dv=0,
                   minValue=0,
                   maxValue=1,
                   k=True)
        pm.addAttr(up_ctl,
                   ln="blinkMult",
                   at="float",
                   dv=1,
                   minValue=1,
                   maxValue=2,
                   k=True)
        pm.addAttr(up_ctl,
                   ln="blinkHeight",
                   at="float",
                   dv=0.3,
                   minValue=0,
                   maxValue=1,
                   k=True)
        pm.addAttr(up_ctl,
                   ln="fleshyEye",
                   at="float",
                   dv=0.5,
                   minValue=0,
                   maxValue=1,
                   k=True)

        fleshyEye_loc = pm.spaceLocator(n=self.name + 'FleshyEye_loc')
        fleshyEye_loc.visibility.set(0)
        pm.parent(fleshyEye_loc, cnstrGrp)
        pm.xform(fleshyEye_loc, t=centerPos, ws=True)
        pm.parentConstraint(fleshyEye_loc, upCtrls[1].getParent(), mo=1)
        pm.parentConstraint(fleshyEye_loc, lowCtrls[1].getParent(), mo=1)
        fleshyEyeMulti = pm.createNode('multiplyDivide',
                                       name=self.name + 'multiFleshy')
        fleshyEyeMulti.output.outputX >> fleshyEye_loc.rotate.rotateX
        fleshyEyeMulti.output.outputY >> fleshyEye_loc.rotate.rotateY
        fleshyEyeMulti.output.outputZ >> fleshyEye_loc.rotate.rotateZ
        up_ctl.fleshyEye >> fleshyEyeMulti.input2.input2X
        up_ctl.fleshyEye >> fleshyEyeMulti.input2.input2Y
        up_ctl.fleshyEye >> fleshyEyeMulti.input2.input2Z

        mult_node = pm.createNode('multDoubleLinear',
                                  name=self.name + 'multBlink')
        up_ctl.blink >> mult_node.input1
        up_ctl.blinkMult >> mult_node.input2
        mult_node.output >> bs_upBlink[0].attr(midTarget.name())
        mult_node.output >> bs_lowBlink[0].attr(midTarget.name())

        up_ctl.blinkHeight >> bs_mid[0].attr(upTarget.name())

        reverse_node = pm.createNode('reverse',
                                     name=self.name + 'blinkReverse')
        up_ctl.blink >> reverse_node.inputX
        reverse_node.outputX >> w1.scale[0]
        reverse_node.outputX >> w2.scale[0]
        reverse_node.outputX >> w3.scale[0]
        reverse_node.outputX >> w4.scale[0]

        self.guideMoveall.visibility.set(0)
        pm.parent(cnstrGrp, constrained_grp)
Exemplo n.º 2
0
    def doGuide(self,
                eyeball=None,
                edgeLoop=None,
                autoExtremes=True,
                **kwargs):
        self.__dict__.update(kwargs)

        if pm.objExists(self.name + 'Crv_grp'):
            pm.delete(self.name + 'Crv_grp')

        self.guideMoveall = self.createCntrl('moveallGuide')
        self.eyeCenter = self.createCntrl(setupName='eyeCenterGuide',
                                          nameTempl=self.name + 'EyeCenter' +
                                          self.guideSulfix)
        self.inCorner = self.createCntrl(setupName='cornersGuide',
                                         nameTempl=self.name + 'InCorner' +
                                         self.guideSulfix)
        self.outCorner = self.createCntrl(setupName='cornersGuide',
                                          nameTempl=self.name + 'OutCorner' +
                                          self.guideSulfix)
        self.upCorner = self.createCntrl(setupName='cornersGuide',
                                         nameTempl=self.name + 'UpCorner' +
                                         self.guideSulfix)
        self.lowCorner = self.createCntrl(setupName='cornersGuide',
                                          nameTempl=self.name + 'LowCorner' +
                                          self.guideSulfix)
        pm.parent(self.eyeCenter, self.inCorner, self.outCorner, self.upCorner,
                  self.lowCorner, self.guideMoveall)

        crvGrp = pm.group(n=self.name + 'Crv_grp', em=True)
        clsGuideGrp = pm.group(em=True,
                               n=self.name + 'crvCtrlGuideClusters',
                               p=crvGrp)
        clsGuideGrp.visibility.set(False)
        ctrlGuideGrp = pm.group(em=True,
                                n=self.name + 'crvCtrlsGuide',
                                p=self.guideMoveall)

        if eyeball:
            bbox = eyeball.getBoundingBox(space='world')
            pos = bbox.center()
            self.guideDict['moveall'][0] = (pos[0], pos[1], pos[2])
        else:
            logger.debug('no eyeball passed')

        if edgeLoop:
            self.edgeLoop = edgeLoop
            self.meshName = self.edgeLoop[0].name().split('.')[0]
            self.mesh = pm.PyNode(self.meshName)
        else:
            logger.debug('no edgeloop passed')
            #self.mesh = None
            self.edgeLoop = None

        if autoExtremes:
            try:
                pts = getEdgeLoopExtremesPoints(self.edgeLoop)
                inPos = pm.xform(pts[0], q=True, ws=True, t=True)
                outPos = pm.xform(pts[1], q=True, ws=True, t=True)
                upPos = pm.xform(pts[2], q=True, ws=True, t=True)
                lowPos = pm.xform(pts[3], q=True, ws=True, t=True)

                self.guideDict['inCorner'] = [inPos, (0, 0, 0)]
                self.guideDict['outCorner'] = [outPos, (0, 0, 0)]
                self.guideDict['upCorner'] = [upPos, (0, 0, 0)]
                self.guideDict['lowCorner'] = [lowPos, (0, 0, 0)]
            except:
                logger.debug('not possible autoextremes')

        self.setCntrl(self.guideMoveall, 'moveall', space='world')
        self.setCntrl(self.eyeCenter, 'eyeCenter', space='object')
        self.setCntrl(self.inCorner, 'inCorner', space='world')
        self.setCntrl(self.outCorner, 'outCorner', space='world')
        self.setCntrl(self.upCorner, 'upCorner', space='world')
        self.setCntrl(self.lowCorner, 'lowCorner', space='world')

        try:
            upEdgeLoop = selectLoopByLocators(mesh=self.mesh,
                                              loc1=self.inCorner,
                                              loc2=self.outCorner,
                                              loc3=self.upCorner)
            pm.select(cl=True)
            pm.select(upEdgeLoop)
            upCrv = pm.polyToCurve(form=2,
                                   degree=3,
                                   n=self.name + 'UpperCrv',
                                   ch=False)[0]

            if not atStart(loc=self.inCorner, crvName=upCrv):
                pm.reverseCurve(upCrv, ch=False, replaceOriginal=True)

            lowEdgeLoop = selectLoopByLocators(mesh=self.mesh,
                                               loc1=self.inCorner,
                                               loc2=self.outCorner,
                                               loc3=self.lowCorner)
            pm.select(cl=True)
            pm.select(lowEdgeLoop)
            lowCrv = pm.polyToCurve(form=2,
                                    degree=3,
                                    n=self.name + 'LowerCrv',
                                    ch=False)[0]

            if not atStart(loc=self.inCorner, crvName=lowCrv):
                pm.reverseCurve(lowCrv, ch=False, replaceOriginal=True)

            self.upCtrlCrv = pm.rebuildCurve(upCrv,
                                             s=2,
                                             rt=0,
                                             rpo=False,
                                             ch=False,
                                             n=self.name + 'upCtrl')[0]
            self.lowCtrlCrv = pm.rebuildCurve(lowCrv,
                                              s=2,
                                              rt=0,
                                              rpo=False,
                                              ch=False,
                                              n=self.name + 'lowCtrl')[0]

            pm.delete(upCrv, lowCrv)
        except:
            logger.debug(
                'Found no edgeloop by locators. Using coordinates to draw')
            self.upCtrlCrv = pm.curve(n=self.name + 'upCrv_guide',
                                      d=3,
                                      p=self.guideDict['upCtrlGrp'])
            self.setCntrl(self.upCtrlCrv, 'moveall', space='world')
            self.lowCtrlCrv = pm.curve(n=self.name + 'lowCrv_guide',
                                       d=3,
                                       p=self.guideDict['lowCtrlGrp'])
            self.setCntrl(self.lowCtrlCrv, 'moveall', space='world')

        self.crvGuideCtrls = {'upCtrlCrv': [], 'lowCtrlCrv': []}

        for crvName in ['upCtrlCrv', 'lowCtrlCrv']:
            crv = self.__dict__[crvName]
            for i in range(5):
                cls = pm.cluster(crv.cv[i])[1]
                pm.parent(cls, clsGuideGrp)
                ctrl = controlTools.cntrlCrv(name=self.name + crvName + str(i),
                                             align='pivot',
                                             obj=cls,
                                             connType='pointConstraint',
                                             hasZeroGrp=True,
                                             cntrlSulfix='_ctrl',
                                             icone='bola',
                                             size=.05)
                pm.parent(ctrl.getParent(), ctrlGuideGrp)
                self.crvGuideCtrls[crvName].append(ctrl)

        for crvName in ['upCtrlCrv', 'lowCtrlCrv']:
            for i in range(5):
                self.crvGuideCtrls[crvName][i].setTranslation(
                    self.guideDict[crvName][i], space='object')

        pm.parent(self.upCtrlCrv, self.lowCtrlCrv, crvGrp, r=True)

        try:
            facialGrp = pm.PyNode('facial_guides_grp')
            pm.parent(self.guideMoveall, crvGrp, facialGrp)
        except:
            pass

        pm.addAttr(self.guideMoveall, ln='eyeLidDict', dt='string')
        self.guideMoveall.eyeLidDict.set(json.dumps(self.exportDict()))
Exemplo n.º 3
0
def edgeToJnt( edges=None, reverse=False, dispCV=False, dispAxis=False, createCurve=False):
    '''
    update : 2015-04-27
    '''
    if not edges:
        edges = pm.filterExpand( sm=32 )

    if not edges:
        raise

    # recast
    # edges = [ pm.PyNode(edge) for edge in edges ] # 이렇게 하면 파이멜이 엣지를 제대로 처리 못함 선택한걸로 해야 할듯
    pm.select(edges)
    edges = pm.selected()

    # 엣지 이름에서 폴리곤 이름 알아옴
    mesh = pm.PyNode( edges[0].name().split('.')[0] )

    # 폴리곤에서 커브 추출
    crvFromPoly = pm.polyToCurve( form=0, degree=1, ch=False )[0]
    curve = pm.PyNode( crvFromPoly )
    curve.dispCV.set(dispCV)

    # cv좌표 얻어옴.
    points = curve.getCVs()

    # 좌표에 조인트 생성
    pm.select(cl=True)
    jnts = []
    for point in points:
        jnt = pm.joint( p=point )
        jnt.displayLocalAxis.set( dispAxis )
        jnts.append( jnt )

    # 뒤집기
    if reverse:
        # 조인트 뒤집음
        pm.select( jnts[-1] )
        pm.mel.RerootSkeleton()

        pm.reverseCurve( curve, replaceOriginal=True, ch=False )

        jnts.reverse()

    # 조인트 오리엔트 조정
    for jnt in jnts:
        parentJnt = jnt.getParent()
        if parentJnt:
            # point에서 가장 가까운 Vertex의 Normal을 up으로 설정
            pos   = parentJnt.getTranslation( ws=True)
            vtx   = getClosestVertexOnMesh( mesh, pos )
            pos   = vtx.getPosition( space='world' )
            norm  = vtx.getNormal()
            upPos = pos + norm

            upLoc = pm.spaceLocator(n='parentJnt_upLoc#')
            upLoc.t.set( upPos )

            jntOrient( [parentJnt, jnt, upLoc], aimAxis='x', worldAimVector='x', upAxis='y', worldUpVector='y' )

            #pm.joint( parentJnt, edit=True, zso=True, oj='xyz', sao='yup' )
            pm.delete( upLoc ) # 버텍스의 위치를 확인하고 싶으면 이 구문을 주석 처리할것
            pm.select( jnt )

    # 끝 조인트 오리엔트 조정
    pm.joint( jnts[-1], edit=True, oj='none' )

    if not createCurve:
        pm.delete( curve )

    return jnts
Exemplo n.º 4
0
    tempHolder = pm.PyNode(curve.name() + '.cv[' + str(cvPick) + ']')
    cvList.append(tempHolder)
pm.select(cvList)

#set pivot on curve root TESTED
import pymel.core as pm
selection = pm.selected()
for curve in selection:
    root = pm.PyNode(curve.name() + '.cv[0]')
    rootPosition = pm.xform(root, q=True, t=True, ws=True)
    pm.xform(curve, rp=rootPosition, sp=rootPosition)
print 'done'

#reverse curve TESTED
import pymel.core as pm
pm.reverseCurve()

#rebuild curve option toolbox
nb_cv = 5  #import user var
pm.rebuildCurve(keepEndPoints=True, keepRange=1, degree=3, span=nb_cv)

#remove cv by index
import pymel.core as pm

userVariable = [
    3, 4, 5
]  #user input.split(',') to get multiple index to delete at the same time
curve_selection = pm.selected()
curve_selection.span(
    userVariable
)  # span is a mistake that indicates I want a comparable manner then polyMesh.cv(0,1,3) to get cv's
Exemplo n.º 5
0
def makeHairMesh(name="HairMesh#",
                 mat="",
                 cSet="hairCrease",
                 reverse=False,
                 lengthDivs=7,
                 widthDivs=4,
                 Segments=4,
                 width=1,
                 curveDel=False,
                 cShape='triangle'):
    '''Create a Hair Tube From Select Curve line or Edge or IsoPram'''
    sel = pm.selected()
    if not sel:
        print "Select some Curves or Edges or isopram"
        return
    if type(sel[0]) == pm.general.MeshEdge:
        pm.runtime.CreateCurveFromPoly()
        pathTransform = pm.selected()[0]
    elif type(sel[0]) == pm.general.NurbsSurfaceIsoparm:
        pm.runtime.DuplicateCurve()
        pathTransform = pm.selected()[0]
    pathTransform = [
        t for t in pm.selected() if type(t) == pm.nodetypes.Transform
    ]
    pm.select(pathTransform, r=1)
    pathShape = pm.listRelatives(shapes=True)
    if type(pathShape[0]) == pm.nodetypes.NurbsCurve:
        minscale = [0.001, 0.001, 0.001]
        pathCurve = [(i, pathShape[pathTransform.index(i)])
                     for i in pathTransform]
        if pm.objExists("HairBaseProfileCurve"):
            profileCurve = pm.ls("HairBaseProfileCurve")[0]
            #print profileCurve.listRelatives()[0].listConnections()[0]
            profileCurve.listRelatives()[0].listConnections()[0].setRadius(
                width)
            pm.showHidden(profileCurve, a=1)
        else:
            shapeType = {
                'circle': (3, 8),
                'triangle': (1, 3),
                'square': (1, 4)
            }
            profileCurve = pm.circle(c=(0, 0, 0),
                                     nr=(0, 1, 0),
                                     sw=360,
                                     r=width,
                                     d=shapeType[cShape][0],
                                     ut=0,
                                     tol=5.77201e-008,
                                     s=shapeType[cShape][1],
                                     ch=1,
                                     name="HairBaseProfileCurve")
            for a in [('overrideEnabled', 1), ('overrideRGBColors', 1),
                      ('overrideColorRGB', (0.2, 0.5, 0.2))]:
                profileCurve[0].getShape().attr(a[0]).set(a[1])
        pm.select(d=1)
        for crv in pathCurve:
            print crv
            pm.rebuildCurve(crv[0], kep=1)
            if reverse:
                pm.reverseCurve(crv[0])
            #profileInstance = instance(profileCurve,n="pCrv_instance"+string(pathCurve.index(crv)))
            if pm.objExists("HairCtrlGroup"):
                hairOncsGroup = pm.ls("HairCtrlGroup")[0]
            else:
                hairOncsGroup = pm.group(name="HairCtrlGroup")
            #pm.parent(hairOncGroup,crv[0])
            mPath = pm.pathAnimation(profileCurve,
                                     crv[0],
                                     fa='y',
                                     ua='x',
                                     stu=1,
                                     etu=Segments * 10,
                                     b=1)
            HairProfile = []
            hairOncGroup = pm.group(name="HairCtrls#")
            pm.parent(hairOncGroup, hairOncsGroup, r=1)
            for u in range(Segments + 1):
                pm.currentTime(u * 10)
                profileInstance = pm.duplicate(profileCurve,
                                               n=(crv[0] + "HairProFileCrv_" +
                                                  str(u)),
                                               rr=1)[0]
                pm.parent(profileInstance, hairOncGroup, r=1)
                HairProfile.append(profileInstance)
                if u == 0 or u == Segments:
                    pm.scale(profileInstance, minscale, a=1, os=1)
            HairMesh = createHairMesh(HairProfile,
                                      name=name,
                                      cSet=cSet,
                                      mat=mat,
                                      lengthDivs=lengthDivs,
                                      widthDivs=widthDivs)
            pm.rename(hairOncGroup, hairOncGroup.name() + HairMesh[0].name())
            pm.delete(profileCurve, mp=1)
            pm.delete(profileCurve)
            pm.xform(hairOncsGroup,
                     ws=1,
                     piv=pm.xform(hairOncsGroup.getChildren()[-1],
                                  q=1,
                                  ws=1,
                                  piv=1)[:3])
        if curveDel:
            pm.delete(pathTransform, hi=1)