Beispiel #1
0
 def build_twist_deform(self, *args):
     """ builds a curve with 3 cv's controled by clusters
     Args:
         None
     Returns (None)
     """
     surf_wireShp_name = self.flexiPlaneNameField.getText() + '_flexiPlane_wire_bShp_SURF'
     wireNode_name = self.flexiPlaneNameField.getText() + '_flexiPlane_bShp_wireNode_SURF'
     twistNode_name = self.flexiPlaneNameField.getText() + '_flexiPlane_bShp_twistNode_SURF'
     twistHandle_name = self.flexiPlaneNameField.getText() + '_flexiPlane_twist_Handle'
     surf_bShpGRP_name = self.flexiPlaneNameField.getText() + '_flexiPlane_bShp_GRP'
     
     pm.select( surf_wireShp_name, r = True )
     twist_deformer = mel.eval("nonLinear -type twist -lowBound -1 -highBound 1 -startAngle 0 -endAngle 0;")[0]
     
     twistSurf_inputList = pm.listConnections( surf_wireShp_name + 'Shape' )
     pm.rename( twistSurf_inputList [-3] , twistNode_name )
     
     twistNode_inputList = pm.listConnections( twistNode_name )
     pm.rename( twistNode_inputList [-1] , twistHandle_name )
     pm.setAttr( twistHandle_name + '.rotateZ', 90 )
     pm.reorderDeformers( wireNode_name, twistNode_name, surf_wireShp_name )
     pm.parent( twistHandle_name, surf_bShpGRP_name )
     
     pm.select( cl = True )
Beispiel #2
0
    def add_upper_deformers(self, target, layers_to_add =[], ):
        """
        Add lower layer deformation as blendshapes
        """
        
        new_order = []
        for layer in layers_to_add:
            get_vis = pm.PyNode(layer).v.get()
            pm.PyNode(layer).v.set(1)
            pm.blendShape(layer, target,  o = 'local', w = [(0, 1.0)], foc = False)
            pm.PyNode(layer).v.set(get_vis)
                    
        deformers_order = mel.eval('findRelatedDeformer("' + str(target) + '")')  
        skin_deformer = [x for x in deformers_order if pm.PyNode(x).type()=='skinCluster'][0]
        
        bls_deformer = [x for x in deformers_order if pm.PyNode(x).type()=='blendShape']                                
        new_order.append(skin_deformer)
        new_order.append(target)   

        for bls in bls_deformer:
            new_order.insert(1,bls)
            pm.reorderDeformers(new_order)
            new_order.remove(bls)
            
        return bls_deformer
    def addObjMorphs(self):
        morphPath = os.path.join(
            os.path.split(self.fbxFile)[0], 'blendshapes/')
        morphFiles = [
            f for f in os.listdir(morphPath)
            if f.endswith('.obj') and 'default' not in f
        ]
        meshesVtxCount = {}
        meshes = pm.ls(type='mesh')
        for m in meshes:
            if 'Orig' not in m.name() and 'rg' not in m.name():
                meshesVtxCount[m.name()] = pm.polyEvaluate(m, v=1)
        print meshesVtxCount

        if morphFiles:
            self.hasMorphs = 1
            bsNode = ''
            bsCreated = 0
            bsEntry = 0

            for obj in morphFiles:
                speakName = obj.split('.')[0]
                speakName = 'speak_' + speakName
                pm.importFile(morphPath + obj, namespace='morph')
                morph = pm.ls('morph:*', type='mesh')[0]
                morph.rename(speakName)
                morphVtxCount = pm.polyEvaluate(morph, v=1)

                for mesh, count in meshesVtxCount.iteritems():
                    print mesh, count
                    if count == morphVtxCount:
                        rigMesh = [pm.ls(mesh, type='mesh')[0].getParent()]
                        skinCls = pm.listConnections('%s.inMesh' %
                                                     rigMesh[0].getShape())[0]

                        if not bsCreated:
                            print 'creating blendshape'
                            bsNode = pm.blendShape(rigMesh,
                                                   name='speak_BS')[0].name()
                            pm.reorderDeformers(skinCls.name(), bsNode,
                                                rigMesh[0].name())
                            pm.blendShape(bsNode,
                                          e=1,
                                          t=(rigMesh[0].name(), bsEntry,
                                             morph.name(), 1))
                            bsCreated = 1
                        else:
                            print 'adding blendshape'
                            pm.blendShape(bsNode,
                                          e=1,
                                          t=(rigMesh[0].name(), bsEntry,
                                             morph.name(), 1))
                pm.delete(morph)
                bsEntry += 1

                removeNamespace()
def cbsStart(*args, **kwargs):
    base = kwargs.setdefault('base', pm.ls(sl=True)[0]) # (string) The base model for the character
    shape = kwargs.setdefault('shape') # (string) The shape node of the base model
    tweak = kwargs.setdefault('tweak') # (string) The tweak node of the base model that is being skinned
    skin = kwargs.setdefault('skin') # (string) The skinCluster node that is driving the base model
    
    #gather some info
    base, shape, tweak, skin = gatherInfo(base, shape, tweak, skin)
    verts = pm.polyEvaluate(base, v=True)
    
    #do a quick check to make sure this part hasn't been done before
    if base.hasAttr('baseTransform'):
        pm.error('You have already run the "Start" function on this model, so it is already ready to go.' +
                 'If corrections have already been made, click "Extract Shape to finish the process"')

    for i in pm.listHistory(base, lv=1):
        if i.type() == 'polySmoothFace':
            pm.error('The selected shape is connected to a smooth modifier. This hinders the ability to track edits. %s must be deleted.' % i)
    
    #turn off a couple things that might mess with things
    pm.symmetricModelling(e=True, symmetry= False)
    pm.softSelect(e=True, softSelectEnabled=False)


    for i in range(verts):

        x = pm.getAttr(('%s.vlist[0].vertex[%i].xVertex'%(tweak, i)))
        y = pm.getAttr(('%s.vlist[0].vertex[%i].yVertex'%(tweak, i)))
        z = pm.getAttr(('%s.vlist[0].vertex[%i].zVertex'%(tweak, i)))

        if not (x+y+z) == 0:
            pm.error('You have used the tweak node. No me gusta. If you really wanna clear it, run clearTweaks and try again. It will save what you have')

    #ok, let's get started, first instance the original mesh
    sculptTrans = pm.instance(base, n=('%s_corrective_sculpt'%base))[0]
    pm.reorderDeformers(skin, tweak, base)
    pm.setAttr('%s.v'%base, False)

    #Here, we'll make a duplicate of the base to look back on later if need be (for instance, using sculpt geometry tends to not register on tweak)
    baseRef = pm.duplicate(base, n='%s_editReference'%base)[0]
    pm.connectAttr(('%s.outMesh' %baseRef.getShapes()[1]), ('%s.inMesh' %baseRef.getShape()))

    #We'll also hook up the original so we can get it later
    pm.addAttr(sculptTrans, ln='baseTransform', at='message')
    pm.addAttr(sculptTrans, ln='baseReference', at='message')
    pm.connectAttr('%s.message'%base, '%s.baseTransform'%sculptTrans)
    pm.connectAttr('%s.message'%baseRef, '%s.baseReference'%sculptTrans)

    #now to keep things from changing between functions, we'll lock the three nodes involved in the
    #other script so our pesky little user won't delete or rename anything
    pm.lockNode(base, l=True)
    pm.lockNode(sculptTrans, l=True)
    def addFbxMorphs(self):
        morphPath = os.path.join(os.path.split(self.fbxFile)[0], 'blendshapes')
        morphFiles = [f for f in os.listdir(fbxPath) if f.endswith('.fbx')]

        if morphFiles:
            self.morphFiles = morphFiles
        else:
            pm.warning('No morph file found')
            return 0

        if len(self.morphFiles) > 0:
            rigMesh = [pm.ls(type='mesh')[0].getParent()]
            skinCls = pm.listConnections('%s.inMesh' %
                                         rigMesh[0].getShape())[0]
            bsNode = pm.blendShape(rigMesh, name=self.name + '_BS')[0]

            print bsNode

            pm.reorderDeformers(skinCls.name(), bsNode, rigMesh[0].name())

            for morph in self.morphFiles:
                print morph
                if 'open' in morph:
                    pm.mel.eval('FBXImport -f "' + morphPath + '/' + morph +
                                '"')
                    meshes = set(mesh.getParent()
                                 for mesh in pm.ls(type='mesh'))

                    newMesh = list(meshes - set(rigMesh))
                    newMesh[0].rename('Open')

                    pm.blendShape(bsNode,
                                  e=1,
                                  t=(rigMesh[0].name(), 0, newMesh[0].name(),
                                     1))
                    pm.delete(newMesh)

                elif 'blink' in morph:
                    pm.mel.eval('FBXImport -f "' + morphPath + '/' + morph +
                                '"')
                    meshes = set(mesh.getParent()
                                 for mesh in pm.ls(type='mesh'))

                    newMesh = list(meshes - set(rigMesh))
                    newMesh[0].rename('Blink')

                    pm.blendShape(bsNode,
                                  e=1,
                                  t=(rigMesh[0].name(), 1, newMesh[0].name(),
                                     1))
                    pm.delete(newMesh)
Beispiel #6
0
 def addObjMorphs(self):
     morphPath = os.path.join(os.path.split(self.fbxFile)[0], 'blendshapes/')
     morphFiles = [f for f in os.listdir(morphPath) if f.endswith('.obj') and 'default' not in f ]
     meshesVtxCount = {}
     meshes = pm.ls(type='mesh')
     for m in meshes:
         if 'Orig' not in m.name() and 'rg' not in m.name():
             meshesVtxCount[m.name()] = pm.polyEvaluate(m,v=1)
     print meshesVtxCount
     
     if morphFiles:
         self.hasMorphs = 1
         bsNode = ''
         bsCreated = 0
         bsEntry =0
         
         for obj in morphFiles:
             speakName = obj.split('.')[0]
             speakName = 'speak_' + speakName
             pm.importFile(morphPath + obj,namespace= 'morph')
             morph = pm.ls('morph:*',type='mesh')[0]
             morph.rename(speakName)
             morphVtxCount = pm.polyEvaluate(morph,v=1)
             
             
             for mesh, count in meshesVtxCount.iteritems():
                 print mesh, count
                 if count == morphVtxCount:
                     rigMesh = [pm.ls(mesh,type='mesh')[0].getParent()]
                     skinCls = pm.listConnections('%s.inMesh'%rigMesh[0].getShape())[0]
 
                     
                     if not bsCreated:
                         print 'creating blendshape'
                         bsNode = pm.blendShape(rigMesh,name='speak_BS')[0].name()
                         pm.reorderDeformers(skinCls.name(),bsNode,rigMesh[0].name())
                         pm.blendShape(bsNode,e=1,t=(rigMesh[0].name(), bsEntry , morph.name(), 1))
                         bsCreated = 1
                     else:
                         print 'adding blendshape'
                         pm.blendShape(bsNode,e=1,t=(rigMesh[0].name(), bsEntry , morph.name(), 1))
             pm.delete(morph)
             bsEntry += 1
 
 
 
             removeNamespace()
def build():
    allCtrl = blocks.Ctrl(name='all_ctrl', shape=Ctrl.CIRCLE, radius=20,
                          normal=[0,1,0], color=Ctrl.YELLOW, group=False).ctrl
    rootLoc = pm.PyNode('root_loc')
    rootJoint = utils.placeXform(name="m_root_%s" % defines.BIND, mtype='joint',
                                  matrix=rootLoc.getMatrix(worldSpace=True),
                                  worldSpace=True, parent=allCtrl)
    rootCtrl = InlineOffset(
                     rootJoint, name='m_root_%s' % defines.CTRL,
                     controlShape=Ctrl.CIRCLE, controlRadius=15,
                     controlColor=Ctrl.YELLOW)

    #
    # Inner Tentacles
    #

    innerTentacles(allCtrl, rootCtrl)

    #
    # LOWER BELL
    #
    bell(allCtrl, rootCtrl)
    
    #
    # Outer Tentacles
    #
    outerTentacles(allCtrl)
    
    #
    # SKIN
    #
    skin.bind(skinDict)

    pm.PyNode(u'upperBellLatticeBase').setParent(rootCtrl.controls[0])

    upperBellDefVerts = [MeshVertex(u'headDomeShapeDeformed.vtx[0:421]'), MeshVertex(u'headDomeShapeDeformed.vtx[426:431]'), MeshVertex(u'headDomeShapeDeformed.vtx[433:434]'), MeshVertex(u'headDomeShapeDeformed.vtx[436:437]'), MeshVertex(u'headDomeShapeDeformed.vtx[439:442]'), MeshVertex(u'headDomeShapeDeformed.vtx[444:445]'), MeshVertex(u'headDomeShapeDeformed.vtx[458:461]'), MeshVertex(u'headDomeShapeDeformed.vtx[474:477]'), MeshVertex(u'headDomeShapeDeformed.vtx[480:481]'), MeshVertex(u'headDomeShapeDeformed.vtx[483:486]'), MeshVertex(u'headDomeShapeDeformed.vtx[488:489]'), MeshVertex(u'headDomeShapeDeformed.vtx[491:492]'), MeshVertex(u'headDomeShapeDeformed.vtx[494:496]'), MeshVertex(u'headDomeShapeDeformed.vtx[498]'), MeshVertex(u'headDomeShapeDeformed.vtx[511:514]'), MeshVertex(u'headDomeShapeDeformed.vtx[524:526]'), MeshVertex(u'headDomeShapeDeformed.vtx[528:530]'), MeshVertex(u'headDomeShapeDeformed.vtx[532:535]'), MeshVertex(u'headDomeShapeDeformed.vtx[537:543]'), MeshVertex(u'headDomeShapeDeformed.vtx[545:547]'), MeshVertex(u'headDomeShapeDeformed.vtx[549:553]'), MeshVertex(u'headDomeShapeDeformed.vtx[555:559]'), MeshVertex(u'headDomeShapeDeformed.vtx[561:563]'), MeshVertex(u'headDomeShapeDeformed.vtx[585:595]'), MeshVertex(u'headDomeShapeDeformed.vtx[620:633]'), MeshVertex(u'headDomeShapeDeformed.vtx[636:638]'), MeshVertex(u'headDomeShapeDeformed.vtx[640:644]'), MeshVertex(u'headDomeShapeDeformed.vtx[646:650]'), MeshVertex(u'headDomeShapeDeformed.vtx[652:654]'), MeshVertex(u'headDomeShapeDeformed.vtx[656:660]'), MeshVertex(u'headDomeShapeDeformed.vtx[662:666]'), MeshVertex(u'headDomeShapeDeformed.vtx[668:669]'), MeshVertex(u'headDomeShapeDeformed.vtx[694:705]'), MeshVertex(u'headDomeShapeDeformed.vtx[727:750]'), MeshVertex(u'headDomeShapeDeformed.vtx[760:765]'), MeshVertex(u'headDomeShapeDeformed.vtx[778:801]'), MeshVertex(u'headDomeShapeDeformed.vtx[814:821]'), MeshVertex(u'headDomeShapeDeformed.vtx[834:873]'), MeshVertex(u'headDomeShapeDeformed.vtx[922:953]'), MeshVertex(u'headDomeShapeDeformed.vtx[1002:1105]'), MeshVertex(u'headDomeShapeDeformed.vtx[1154:1177]'), MeshVertex(u'headDomeShapeDeformed.vtx[1214:1296]'), MeshVertex(u'headDomeShapeDeformed.vtx[1339:1362]'), MeshVertex(u'headDomeShapeDeformed.vtx[1411:1414]'), MeshVertex(u'headDomeShapeDeformed.vtx[1417:1427]'), MeshVertex(u'headDomeShapeDeformed.vtx[1430:1441]'), MeshVertex(u'headDomeShapeDeformed.vtx[1444:1449]'), MeshVertex(u'headDomeShapeDeformed.vtx[1452:1463]'), MeshVertex(u'headDomeShapeDeformed.vtx[1466:1477]'), MeshVertex(u'headDomeShapeDeformed.vtx[1480:1485]'), MeshVertex(u'headDomeShapeDeformed.vtx[1490:1517]'), MeshVertex(u'headDomeShapeDeformed.vtx[1566:1587]'), MeshVertex(u'headDomeShapeDeformed.vtx[1630:1635]'), MeshVertex(u'headDomeShapeDeformed.vtx[1638:1649]'), MeshVertex(u'headDomeShapeDeformed.vtx[1652:1663]'), MeshVertex(u'headDomeShapeDeformed.vtx[1666:1671]'), MeshVertex(u'headDomeShapeDeformed.vtx[1674:1691]'), MeshVertex(u'headDomeShapeDeformed.vtx[1694:1701]'), MeshVertex(u'headDomeShapeDeformed.vtx[1704:1709]'), MeshVertex(u'headDomeShapeDeformed.vtx[1712:2583]'), MeshVertex(u'headDomeShapeDeformed.vtx[2632:2663]'), MeshVertex(u'headDomeShapeDeformed.vtx[2712:2823]'), MeshVertex(u'headDomeShapeDeformed.vtx[2872:2895]'), MeshVertex(u'headDomeShapeDeformed.vtx[2932:3361]')]

    pm.skinPercent('skinCluster84', upperBellDefVerts, 
                   transformValue = [(rootJoint,1.0)])
    pm.reorderDeformers(u'upperBellLattice',u'skinCluster84',
                        u'model:headDome')
    pm.reorderDeformers(u'upperBellLattice',u'skinCluster48',
                        u'model:innerDome')

    # save skin dict
    utils.writeFile('rigPirateCaptain_skin.json',skinDict)
Beispiel #8
0
    def addFbxMorphs(self):
        morphPath = os.path.join(os.path.split(self.fbxFile)[0], 'blendshapes')
        morphFiles = [f for f in os.listdir(fbxPath) if f.endswith('.fbx')]

        if morphFiles:
            self.morphFiles = morphFiles
        else:
            pm.warning('No morph file found')
            return 0


        if len(self.morphFiles) > 0:
            rigMesh = [pm.ls(type='mesh')[0].getParent()]
            skinCls = pm.listConnections('%s.inMesh'%rigMesh[0].getShape())[0]      
            bsNode = pm.blendShape(rigMesh,name=self.name + '_BS')[0]

            print bsNode

            pm.reorderDeformers(skinCls.name(),bsNode,rigMesh[0].name())


            for morph in self.morphFiles:
                print morph
                if 'open' in morph:
                    pm.mel.eval( 'FBXImport -f "' + morphPath + '/' + morph + '"')
                    meshes = set(mesh.getParent() for mesh in pm.ls(type='mesh'))

                    newMesh = list(meshes - set(rigMesh))
                    newMesh[0].rename('Open')

                    pm.blendShape(bsNode,e=1,t=(rigMesh[0].name(), 0 , newMesh[0].name(), 1))
                    pm.delete(newMesh)

                elif 'blink' in morph:
                    pm.mel.eval( 'FBXImport -f "' + morphPath + '/' + morph + '"')
                    meshes = set(mesh.getParent() for mesh in pm.ls(type='mesh'))

                    newMesh = list(meshes - set(rigMesh))
                    newMesh[0].rename('Blink')

                    pm.blendShape(bsNode,e=1,t=(rigMesh[0].name(), 1 , newMesh[0].name(), 1))
                    pm.delete(newMesh)
Beispiel #9
0
    def rigRbn(self):
        # -------------- Create the wire curve that will drive the blendshape target srf---#
        self.rbnWireCrv = pm.curve(d=2,
                                   p=[[self.start[0], 0, self.rbnWidth * 5.0],
                                      [0, 0, self.rbnWidth * 5.0],
                                      [self.end[0], 0, self.rbnWidth * 5.0]],
                                   k=[0, 0, 1, 1],
                                   name=self.rbnName + '_wire_crv')
        self.rbnWireCrv.hide()
        pm.parent(self.rbnWireCrv, self.rbnNoTransformGrp)

        # -------------- Create the surface that will be the target blendshape ------------#
        self.rbnBsSrf = pm.duplicate(self.rbnSrf,
                                     name=self.rbnName + '_srf_bs')[0]
        self.rbnBsSrf.hide()
        pm.parent(self.rbnBsSrf, self.rbnNoTransformGrp)
        pm.xform(self.rbnBsSrf, r=1, t=[0, 0, self.rbnWidth * 5.0])

        blendshapeNode = pm.blendShape(self.rbnBsSrf,
                                       self.rbnSrf,
                                       name=self.rbnName + '_blendShape')[0]
        blendshapeNode.attr(self.rbnBsSrf.name()).set(1)

        # -------------- Create the locators that will drive the ribbon -------------------#
        topLocator = pm.spaceLocator(name=self.rbnName + '_loc_01',
                                     p=[self.start[0], 0, 0])
        pm.makeIdentity(topLocator, apply=True, t=True, r=True, s=True)
        topLocator.setPivots(topLocator.c.get())

        midLocator = pm.spaceLocator(name=self.rbnName + '_loc_02',
                                     p=[0, 0, 0])
        midLocatorGrp = pm.group(midLocator, name=midLocator.name() + '_grp')

        botLocator = pm.spaceLocator(name=self.rbnName + '_loc_03',
                                     p=[self.end[0], 0, 0])
        pm.makeIdentity(botLocator, apply=True, t=True, r=True, s=True)
        botLocator.setPivots(botLocator.c.get())

        self.rbnLocs.append(topLocator)
        self.rbnLocs.append(midLocator)
        self.rbnLocs.append(botLocator)

        pm.pointConstraint(topLocator, botLocator, midLocatorGrp)
        locGrp = pm.group([topLocator, midLocatorGrp, botLocator],
                          n=self.rbnName + '_loc_grp')

        pm.parent(locGrp, self.rbnTransformGrp)
        # -------------------------- Create the wire deformer  -----------------------------#
        wireDef = pm.wire(self.rbnBsSrf,
                          w=self.rbnWireCrv,
                          en=1,
                          gw=False,
                          ce=0,
                          li=0,
                          dds=[0, 200],
                          n=self.rbnName + '_wire')

        self.clustersOnCurve()

        for i in range(3):
            self.rbnLocs[i].translate.connect(self.rbnCls[i].translate)

        # -------------------------- Create the twist deformer  -----------------------------#
        self.addTwist()

        botLocator.rotateX.connect(self.rbnTwist.startAngle)
        topLocator.rotateX.connect(self.rbnTwist.endAngle)

        pm.reorderDeformers(wireDef[0], self.rbnTwist, self.rbnBsSrf)
        pm.parent(self.rbnTwist, self.rbnNoTransformGrp)
        # -------------------------------- Add volume  --------------------------------------#
        self.addVolume()
Beispiel #10
0
    def bdBuildRbnDT(self,name,start,end,segments):
        surfaceRbn = pm.nurbsPlane(ax = [0,0,22], d=3, u=1, v=segments , w=1, lr = segments)[0]
        surfaceRbn.rename(name)
        flcGrp = self.bdCreateFol(surfaceRbn,segments)

        surfaceRbn_BS = surfaceRbn.duplicate()[0]
        surfaceRbn_BS.rename(name + '_BS')
        surfaceRbn_BS.translateX.set(segments * 0.5 )
        blendshapeNode = pm.blendShape(surfaceRbn_BS,surfaceRbn,name=surfaceRbn.name() + '_blendShape')[0]
        blendshapeNode.attr(surfaceRbn_BS.name()).set(1)

        locatorsRbn = []

        topLocator = pm.spaceLocator()
        topLocator.rename(name + '_loc_top_CON')
        topLocator.translateY.set(segments * 0.5)
        pm.makeIdentity(topLocator,apply=True,t=True,r=True,s=True)

        midLocator = pm.spaceLocator()
        midLocator.rename(name + '_loc_mid_CON')
        midLocatorGrp = pm.group(midLocator,name=midLocator.name() + '_grp')
        pm.makeIdentity(midLocator,apply=True,t=True,r=True,s=True)

        botLocator = pm.spaceLocator()
        botLocator.rename(name + '_loc_bot_CON')
        botLocator.translateY.set(segments * -0.5)
        pm.makeIdentity(botLocator,apply=True,t=True,r=True,s=True)

        locatorsRbn.append(topLocator)
        locatorsRbn.append(midLocator)
        locatorsRbn.append(botLocator)

        pm.pointConstraint(topLocator,botLocator,midLocatorGrp)
        conGrp = pm.group([topLocator,midLocatorGrp,botLocator],n=name.replace('srf','CON_GRP'))


        curveDrv = pm.curve(d=2, p=[(0, segments * 0.5, 0), (0, 0, 0), (0, segments * -0.5, 0)],k=[0,0,1,1])
        curveDrv.rename(name.replace('srf', 'wire_CRV'))
        curveDrv.translateX.set(segments * 0.5)

        wireDef = pm.wire(surfaceRbn_BS,w=curveDrv,en=1,gw=False,ce=0, li=0, dds = [0,20], n=name.replace('srf','wire'))

        #kind of a hack
        wireDefBase = wireDef[0].baseWire[0].listConnections(d=False,s=True)
        curveCLS,clsGrp = self.bdClustersOnCurve(curveDrv,segments)

        for i in range(3):
            locatorsRbn[i].translate.connect(curveCLS[i].translate)

        #organize a bit
        moveGrp = pm.group([conGrp,surfaceRbn],name=name.replace('srf','move_GRP'))
        extraGrp = pm.group([flcGrp,surfaceRbn_BS,clsGrp,curveDrv,wireDefBase],name = name.replace('srf','extra_GRP'))
        allGrp = pm.group([moveGrp,extraGrp],name = name.replace('srf','RBN'))

        self.bdFlcScaleCnstr(moveGrp,flcGrp)

        globalCon = pm.spaceLocator()
        globalCon.rename(name.replace("srf",'world_CON'))

        pm.parent(globalCon,allGrp)
        pm.parent(moveGrp,globalCon)

        self.bdCreateJoints(flcGrp)

        twistDef, twistDefTransform = self.bdAddTwist(surfaceRbn_BS)
        pm.parent(twistDefTransform, extraGrp)
        topLocator.rotateY.connect(twistDef.startAngle)
        botLocator.rotateY.connect(twistDef.endAngle)

        pm.reorderDeformers(wireDef[0],twistDef,surfaceRbn_BS)
def cbsStart(*args, **kwargs):
    base = kwargs.setdefault(
        'base',
        pm.ls(sl=True)[0])  # (string) The base model for the character
    shape = kwargs.setdefault(
        'shape')  # (string) The shape node of the base model
    tweak = kwargs.setdefault(
        'tweak'
    )  # (string) The tweak node of the base model that is being skinned
    skin = kwargs.setdefault(
        'skin')  # (string) The skinCluster node that is driving the base model

    #gather some info
    base, shape, tweak, skin = gatherInfo(base, shape, tweak, skin)
    verts = pm.polyEvaluate(base, v=True)

    #do a quick check to make sure this part hasn't been done before
    if base.hasAttr('baseTransform'):
        pm.error(
            'You have already run the "Start" function on this model, so it is already ready to go.'
            +
            'If corrections have already been made, click "Extract Shape to finish the process"'
        )

    for i in pm.listHistory(base, lv=1):
        if i.type() == 'polySmoothFace':
            pm.error(
                'The selected shape is connected to a smooth modifier. This hinders the ability to track edits. %s must be deleted.'
                % i)

    #turn off a couple things that might mess with things
    pm.symmetricModelling(e=True, symmetry=False)
    pm.softSelect(e=True, softSelectEnabled=False)

    for i in range(verts):

        x = pm.getAttr(('%s.vlist[0].vertex[%i].xVertex' % (tweak, i)))
        y = pm.getAttr(('%s.vlist[0].vertex[%i].yVertex' % (tweak, i)))
        z = pm.getAttr(('%s.vlist[0].vertex[%i].zVertex' % (tweak, i)))

        if not (x + y + z) == 0:
            pm.error(
                'You have used the tweak node. No me gusta. If you really wanna clear it, run clearTweaks and try again. It will save what you have'
            )

    #ok, let's get started, first instance the original mesh
    sculptTrans = pm.instance(base, n=('%s_corrective_sculpt' % base))[0]
    pm.reorderDeformers(skin, tweak, base)
    pm.setAttr('%s.v' % base, False)

    #Here, we'll make a duplicate of the base to look back on later if need be (for instance, using sculpt geometry tends to not register on tweak)
    baseRef = pm.duplicate(base, n='%s_editReference' % base)[0]
    pm.connectAttr(('%s.outMesh' % baseRef.getShapes()[1]),
                   ('%s.inMesh' % baseRef.getShape()))

    #We'll also hook up the original so we can get it later
    pm.addAttr(sculptTrans, ln='baseTransform', at='message')
    pm.addAttr(sculptTrans, ln='baseReference', at='message')
    pm.connectAttr('%s.message' % base, '%s.baseTransform' % sculptTrans)
    pm.connectAttr('%s.message' % baseRef, '%s.baseReference' % sculptTrans)

    #now to keep things from changing between functions, we'll lock the three nodes involved in the
    #other script so our pesky little user won't delete or rename anything
    pm.lockNode(base, l=True)
    pm.lockNode(sculptTrans, l=True)
Beispiel #12
0
def makeCorrective(items=None, name=None):
    import cvShapeInverter
    xformAttrs = [
        't',
        'r',
        's',
        'tx',
        'ty',
        'tz',
        'rx',
        'ry',
        'rz',
        'sx',
        'sy',
        'sz',
    ]
    xformAttrDefaults = [0, 0, 0, 0, 0, 0, 1, 1, 1]
    duplicates = []
    if name == None:
        result = cmds.promptDialog(title='Create Corrective Shape',
                                   message='Enter Corrective Name:',
                                   text='positionA',
                                   button=['Create', 'Cancel'],
                                   defaultButton='OK',
                                   cancelButton='Cancel',
                                   dismissString='Cancel')

        if result != 'Create':
            return None

        name = cmds.promptDialog(query=True, text=True)

    if not items:
        items = []
        for item in pymel.ls(selection=True):
            inheritedTypes = item.nodeType(inherited=True)
            if 'transform' in inheritedTypes:
                if item.getShapes():
                    items.append(item)

            elif 'shape' in inheritedTypes:
                items.append(item.getParent())

    for item in items:
        itemShape = item.getShape()
        itemPosition = pymel.xform(item,
                                   query=True,
                                   translation=True,
                                   worldSpace=True)
        itemMatrix = pymel.xform(item,
                                 query=True,
                                 matrix=True,
                                 worldSpace=True)

        # get the origShape
        itemOrigShape = getOrigShape(itemShape)

        # create a duplicate
        duplicate = pymel.duplicate(item, smartTransform=False)[0]
        duplicate.rename('%s_%sCorrective' % (
            item.nodeName(),
            name,
        ))
        duplicateShape = duplicate.getShape()
        duplicates.append(duplicate)

        ## set the duplicate's shape to match the item's orig shape
        #itemOrigShape.intermediateObject.set(0)
        #tempBlendShape = pymel.blendShape(itemOrigShape, duplicate)[0]
        #itemOrigShape.intermediateObject.set(1)

        #tempBlendShape.w[0].set(1)
        #tempBlendShape.inputTarget[0].inputTargetGroup[0].inputTargetItem[6000].inputGeomTarget.disconnect()
        #pymel.delete(duplicate, constructionHistory=True)

        # unlock translate attrs so the user can move the target
        for attr in xformAttrs:
            try:
                duplicate.attr(attr).set(lock=False)

            except:
                pass

        # create secondary blendshape node if one does not already exist
        secondaryBlendShape = None
        for deformer in getDeformers(item):
            if hasattr(deformer, 'isSecondaryBlendShape'):
                secondaryBlendShape = deformer
                break

        if not secondaryBlendShape:
            secondaryBlendShape = pymel.blendShape(item)[0]
            secondaryBlendShape.addAttr('isSecondaryBlendShape',
                                        at='bool',
                                        defaultValue=True)
            secondaryBlendShape.isSecondaryBlendShape.set(lock=True)
            secondaryBlendShape.rename(item.nodeName() +
                                       '_secondaryBlendshape')

        #duplicateOrigShape = getOrigShape(duplicateShape)
        #duplicateOrigShape.intermediateObject.set(0)
        #staticBlendShape = pymel.blendShape(item, duplicateOrigShape)[0]
        #duplicateOrigShape.intermediateObject.set(1)
        #staticBlendShape.rename(duplicate.nodeName()+'_staticBlendShape')
        #staticBlendShape.w[0].set(1)
        #pymel.delete(duplicate, constructionHistory=True)

        liveBlendShape = pymel.blendShape(item, duplicate)[0]
        liveBlendShape.rename(duplicate.nodeName() + '_liveBlendShape')
        liveBlendShape.w[0].set(1)

        tweakNode = None
        for deformer in reversed(getDeformers(duplicateShape)):
            if deformer.nodeType() == 'tweak':
                tweakNode = deformer
                break

        tweakNode.rename(duplicate.nodeName() + '_secondaryTweak')
        pymel.reorderDeformers(tweakNode, liveBlendShape)

        #pymel.reorderDeformers(tweakNode, staticBlendShape)

        # connect the input of the blendshape as a target of the live shape
        groupParts = secondaryBlendShape.input[0].inputGeometry.inputs()[0]
        groupParts.outputGeometry >> liveBlendShape.inputTarget[
            0].inputTargetGroup[0].inputTargetItem[6000].inputGeomTarget

        # backgroundTweak
        backgroundTweak = pymel.createNode('tweak')
        backgroundTweak.rename('backgroundTweak')
        groupParts.outputGeometry >> backgroundTweak.input[0].inputGeometry

        #groupParts.outputGeometry >> staticBlendShape.inputTarget[0].inputTargetGroup[0].inputTargetItem[6000].inputGeomTarget

        pymel.blendShape(item, duplicate)[0]
        index = pymel.blendShape(secondaryBlendShape,
                                 query=True,
                                 weightCount=True)
        pymel.blendShape(secondaryBlendShape,
                         edit=True,
                         target=(item, index, duplicate, 1.0))
        secondaryBlendShape.w[index].set(1)
        #backgroundTweak.outputGeometry[0] >> secondaryBlendShape.inputTarget[0].inputTargetGroup[index].inputTargetItem[6000].inputGeomTarget

        #blendShape = None
        #for deformer in getDeformers(item):
        #if deformer.nodeType() == 'blendShape':
        #blendShape = deformer
        #break

        #if blendShape:
        #index = pymel.blendShape(blendShape, query=True, weightCount=True)
        #OOOOOOO = "index"; print '%s: ' % OOOOOOO, eval(OOOOOOO), ' ', type(eval(OOOOOOO))
        #pymel.blendShape(blendShape, edit=True, target=(item, index, invertedItem, 1.0))
        #blendShape.w[index].set(1)
        #OOOOOOO = "blendShape"; print '%s: ' % OOOOOOO, eval(OOOOOOO), ' ', type(eval(OOOOOOO))
        #else:
        #blendShape = pymel.blendShape(invertedItem, item, frontOfChain=True,)[0]
        #blendShape.rename(item.nodeName()+'_blendShape')
        #blendShape.w[0].set(1)
        #print 'NEW'

        #blendShapeA.w[0].set(1)
        #ka_shapes.shapeParent(invertedItem, duplicate)

        #itemBlendShape = None
        #for deformer in getDeformers(item):
        #if defomer.nodeType() == '':
        #pass
        #pymel.blendShape(bs, query=True, weightCount=True)
        #bs[0].w[0].set(2)

        #OOOOOOO = "invertedItem"; print '%s: ' % OOOOOOO, eval(OOOOOOO), ' ', type(eval(OOOOOOO))

        #staticBlendShape.inputTarget[0].inputTargetGroup[0].inputTargetItem[6000].inputGeomTarget.disconnect()
        pymel.xform(
            duplicate,
            translation=[
                itemPosition[0] + 5, itemPosition[1], itemPosition[2]
            ],
            worldSpace=True,
        )
        pymel.select(duplicates)
Beispiel #13
0
    def quick_blendshape(self, driver, driven, name=None, prefix=False, suffix=True):

        if prefix:
            suffix = False

        driver = pm.PyNode(driver)
        driven = pm.PyNode(driven)
        # driven_shape = driven.getShape()

        target_shape_list = []
        type_list = ['mesh', 'nurbsCurve']
        for type in type_list:
            shape_list = driven.listRelatives(ad=True, type=type)
            target_shape_list.extend(shape_list)
        target_shape_list = list(set(target_shape_list))
        for target_shape in target_shape_list:
            if target_shape.isIntermediate():
                target_shape_list.remove(target_shape)

        # tweak node
        old_tweak_list = []
        if target_shape_list:
            for target_shape in target_shape_list:
                tweak_list = target_shape.listConnections(type='tweak')
                tweak_list = list(set(tweak_list))
                old_tweak_list.extend(tweak_list)

        # blend shape history
        blendshape_history_list = []

        for target_shape in target_shape_list:
            blendshape_history = target_shape.listHistory(type='blendShape', lv=1)
            if blendshape_history:
                blendshape_history_list.append([target_shape, blendshape_history[0]])

        blendshape = pm.blendShape(driver, driven, origin='world', automatic=True, weight=[0, 1], envelope=1)[0]

        # tweak node
        new_tweak_list = []
        if target_shape_list:
            for target_shape in target_shape_list:
                tweak_list = target_shape.listConnections(type='tweak')
                tweak_list = list(set(tweak_list))
                new_tweak_list.extend(tweak_list)
            if new_tweak_list:
                for new_tweak in new_tweak_list:
                    if new_tweak not in old_tweak_list:
                        pm.delete(new_tweak)

        # blend shape history
        if blendshape_history_list:
            for blendshape_history in blendshape_history_list:
                pm.reorderDeformers(blendshape, blendshape_history[1], blendshape_history[0])

        if name:
            blendshape.rename(name)
        else:
            name = self.compose_camel_case(driver.nodeName())
            if suffix:
                blendshape.rename(name + '_src_bsn')
            if prefix:
                blendshape.rename('BSH_src_{0}'.format(name))

        return blendshape