Exemple #1
0
    def transferReverseWeightList(geo, fromDeformer, toDeformer):
        '''
        method for quickly transfering reversed weightList
        input python string (mesh)
        input pythin string (fromDeformer)
        input python string (toDeformer)
        '''

        geoPath = GenAPI.getDagPath(geo)
        deformerObjectFrom = GenAPI.getMObject(fromDeformer)
        deformerObjectTo = GenAPI.getMObject(toDeformer)
        vertItr = om.MItMeshVertex(geoPath)
        deformerWeightFn = oma.MFnWeightGeometryFilter()

        while not vertItr.isDone():

            componentObject = vertItr.currentItem()
            weights = om.MFloatArray()
            deformerWeightFn.setObject(deformerObjectFrom)
            deformerWeightFn.getWeights(geoPath, componentObject, weights)

            if weights[0] > 0.000:
                weights[0] = abs(weights[0] - 1.0)

            deformerWeightFn.setObject(deformerObjectTo)
            deformerWeightFn.setWeight(geoPath, componentObject, weights)
            vertItr.next()
Exemple #2
0
 def transferReverseWeightList(geo,fromDeformer,toDeformer):
     
     '''
     method for quickly transfering reversed weightList
     input python string (mesh)
     input pythin string (fromDeformer)
     input python string (toDeformer)
     '''
     
     geoPath = GenAPI.getDagPath(geo)
     deformerObjectFrom = GenAPI.getMObject(fromDeformer)
     deformerObjectTo = GenAPI.getMObject(toDeformer)
     vertItr = om.MItMeshVertex(geoPath)
     deformerWeightFn = oma.MFnWeightGeometryFilter()
     
     while not vertItr.isDone():
         
         componentObject = vertItr.currentItem()
         weights = om.MFloatArray()
         deformerWeightFn.setObject(deformerObjectFrom)
         deformerWeightFn.getWeights(geoPath,componentObject,weights)
         
         if weights[0] > 0.000:
             weights[0] = abs(weights[0] - 1.0)
             
         deformerWeightFn.setObject(deformerObjectTo)
         deformerWeightFn.setWeight(geoPath,componentObject,weights)
         vertItr.next()   
Exemple #3
0
 def __init__(self,startJoint = '',endJoint = ''):
     
     self.startJoint = startJoint
     self.endJoint = endJoint
     
     self.startJointObject = GenAPI.getMObject(startJoint)
     self.startJointPath = GenAPI.getDagPath(startJoint)
     
     self.endJointObject = GenAPI.getMObject(endJoint)
     self.endJointPath = GenAPI.getDagPath(endJoint)
Exemple #4
0
    def __init__(self, startJoint='', endJoint=''):

        self.startJoint = startJoint
        self.endJoint = endJoint

        self.startJointObject = GenAPI.getMObject(startJoint)
        self.startJointPath = GenAPI.getDagPath(startJoint)

        self.endJointObject = GenAPI.getMObject(endJoint)
        self.endJointPath = GenAPI.getDagPath(endJoint)
Exemple #5
0
    def __init__(self, mesh='', deformer=''):

        self.mesh = mesh
        self.deformer = deformer
        self.meshPath = GenAPI.getDagPath(mesh)
        self.meshObject = GenAPI.getMObject(mesh)
        self.deformerObject = GenAPI.getMObject(deformer)

        if self.meshObject.apiTypeStr() == 'kTransform':

            shape = cmds.listRelatives(mesh, type='shape')[0]
            self.meshPath = GenAPI.getDagPath(shape)
            self.meshObject = GenAPI.getMObject(shape)
Exemple #6
0
 def __init__(self,mesh = '',deformer = ''):
     
     self.mesh = mesh
     self.deformer = deformer
     self.meshPath = GenAPI.getDagPath(mesh)
     self.meshObject = GenAPI.getMObject(mesh)
     self.deformerObject = GenAPI.getMObject(deformer) 
     
     if self.meshObject.apiTypeStr() == 'kTransform':
         
         shape = cmds.listRelatives(mesh,type = 'shape')[0]
         self.meshPath  = GenAPI.getDagPath(shape)
         self.meshObject = GenAPI.getMObject(shape)
Exemple #7
0
 def __init__(self,skincluster = '',shape = ''):
     
     self.skincluster = skincluster
     self.shape = shape
     
     if not self.skincluster == '':
         
         self.skinclusterObject = GenAPI.getMObject(skincluster)
         self.skinclusterFn = oma.MFnSkinCluster(self.skinclusterObject)
         
     if not self.shape == '':
         
         self.shapePath = GenAPI.getDagPath(self.shape)
         self.shapeObject = GenAPI.getMObject(self.shape)
Exemple #8
0
    def __init__(self, skincluster='', shape=''):

        self.skincluster = skincluster
        self.shape = shape

        if not self.skincluster == '':

            self.skinclusterObject = GenAPI.getMObject(skincluster)
            self.skinclusterFn = oma.MFnSkinCluster(self.skinclusterObject)

        if not self.shape == '':

            self.shapePath = GenAPI.getDagPath(self.shape)
            self.shapeObject = GenAPI.getMObject(self.shape)
Exemple #9
0
 def getDagMembers(deformer):
     
     '''
     method for gathering dag members from a deformer
     output members (pythonList[python string])
     '''
     
     dagList = []
     deformerObject = GenAPI.getMObject(deformer)
     
     geoFilter = oma.MFnGeometryFilter(deformerObject)
     deformerSet = geoFilter.deformerSet()
     deformerSetFn = om.MFnSet(deformerSet)
     
     selectionList = om.MSelectionList()
     deformerSetFn.getMembers(selectionList, False)
     
     selectionItr = om.MItSelectionList(selectionList)
     
     while not selectionItr.isDone():
         
         dagPath = om.MDagPath()
         selectionItr.getDagPath(dagPath)
         
         dagList.append(dagPath.partialPathName())
         
         selectionItr.next()
     
     return dagList
Exemple #10
0
    def getDagMembers(deformer):
        '''
        method for gathering dag members from a deformer
        output members (pythonList[python string])
        '''

        dagList = []
        deformerObject = GenAPI.getMObject(deformer)

        geoFilter = oma.MFnGeometryFilter(deformerObject)
        deformerSet = geoFilter.deformerSet()
        deformerSetFn = om.MFnSet(deformerSet)

        selectionList = om.MSelectionList()
        deformerSetFn.getMembers(selectionList, False)

        selectionItr = om.MItSelectionList(selectionList)

        while not selectionItr.isDone():

            dagPath = om.MDagPath()
            selectionItr.getDagPath(dagPath)

            dagList.append(dagPath.partialPathName())

            selectionItr.next()

        return dagList
Exemple #11
0
    def pointOnCurveLocCV(name,curve):
        
        if not cmds.nodeType(curve) == 'shape':
            
            curve = cmds.listRelatives(curve, type = 'shape')[0]
            
        mobject = GenAPI.getMObject(curve)
        iterCVs = om.MItCurveCV(mobject)
        
        while not iterCVs.isDone():

            index = iterCVs.index()
            nameIndex = index + 1            
            moPath = cmds.createNode('motionPath')
            
            moPath = cmds.createNode('motionPath',n = '%s_0%i_MotionPath'%(name,nameIndex))
            cmds.connectAttr('%s.worldSpace[0]'%curve,'%s.geometryPath'%moPath)
            
            locator = cmds.spaceLocator(n = '%s_0%i_MP_Loc'%(name,nameIndex))
            cmds.addAttr(locator[0],ln = "Offset" ,at = 'double')
            cmds.setAttr('%s.Offset'%locator[0], e = True, keyable = True)
            upLocator = cmds.spaceLocator(n = '%s_0%i_MP_Up_Loc'%(name,nameIndex))
                        
            cmds.connectAttr('%s.allCoordinates'%moPath,'%s.translate'%locator[0])
            cmds.connectAttr('%s.rotate'%moPath,'%s.rotate'%locator[0])
            cmds.connectAttr('%s.rotateOrder'%moPath, '%s.rotateOrder'%locator[0])
            
            uValue = MeasuringTool.curveCVtoU(curve,index)
            cmds.setAttr('%s.uValue'%moPath, uValue)
            cmds.setAttr('%s.worldUpType'%moPath, 2)
            cmds.setAttr ('%s.frontAxis'%moPath,0)
            cmds.setAttr ('%s.upAxis'%moPath,2)
            
            offsetMD = cmds.createNode('multiplyDivide', n = '%s_0%i_Offset_MD'%(locator[0],nameIndex))
            cmds.connectAttr('%s.Offset'%locator[0],'%s.input1X'%offsetMD)
            cmds.setAttr('%s.input2X'%offsetMD, 0.1)
            offsetPMA = cmds.createNode('plusMinusAverage', n = '%s_0%i_Offset_PMA'%(locator[0],nameIndex))
            cmds.connectAttr('%s.outputX'%offsetMD,'%s.input1D[0]'%offsetPMA )
            cmds.setAttr('%s.input1D[1]'%offsetPMA,uValue)
            cmds.connectAttr('%s.output1D'%offsetPMA, '%s.uValue'%moPath)
            
            
            locPos = cmds.xform(locator[0], q = True, ws = True, translation = True)
            locOrient = cmds.xform(locator[0], q = True, ws = True, rotation = True)
            
            cmds.setAttr ('%s.worldUpVectorX'%moPath,0)
            cmds.setAttr ('%s.worldUpVectorY'%moPath,0)
            cmds.setAttr ('%s.worldUpVectorZ'%moPath,1)
            cmds.connectAttr('%s.worldMatrix[0]'%upLocator[0], '%s.worldUpMatrix'%moPath)
            
            nullGroup = cmds.group(empty = True, n = '%s_Group'%upLocator[0])
            cmds.move(locPos[0], locPos[1],locPos[2],nullGroup)
            cmds.rotate(locOrient[0],locOrient[1],locOrient[2], nullGroup)
            
            cmds.parent(upLocator[0], nullGroup,r = True)
            cmds.move(0,0,10,upLocator[0], a = True, os = True)
            
            cmds.group(locator[0],nullGroup,n = '%s_0%i_MP_Loc_Group'%(name,nameIndex))
            
            iterCVs.next()
Exemple #12
0
    def __init__(self,transformNodes = []):

        self.transformNodes = transformNodes
        
        for node in self.transformNodes:
            
            self.transformObjects.append(GenAPI.getMObject(node))
            self.transformDagPaths.append(GenAPI.getDagPath(node))
Exemple #13
0
    def __init__(self, transformNodes=[]):

        self.transformNodes = transformNodes

        for node in self.transformNodes:

            self.transformObjects.append(GenAPI.getMObject(node))
            self.transformDagPaths.append(GenAPI.getDagPath(node))
Exemple #14
0
 def curveCVtoU (curveShape,curveCVIndex):
 
     curveFn = om.MFnNurbsCurve(GenAPI.getMObject(curveShape))
     mpoint = om.MPoint()
     curveFn.getCV(curveCVIndex,mpoint)
     uValue =  om.MScriptUtil()
     uValueNull = uValue.asDoublePtr()
     curveFn.closestPoint(mpoint,uValueNull)
     return uValue.getDouble(uValueNull)
Exemple #15
0
    def getMemberSet(self, filePath):

        output = open(filePath, 'wb')

        setsToDump = []

        for objectSet in self.sets:

            print 'saving %s set...' % objectSet

            setObject = GenAPI.getMObject(objectSet)
            self.__setFn.setObject(setObject)

            selectionList = om.MSelectionList()
            self.__setFn.getMembers(selectionList, True)
            selectionListItr = om.MItSelectionList(selectionList)

            members = dict()
            members['setName'] = objectSet
            members['dagMembers'] = []
            members['components'] = []

            while not selectionListItr.isDone():

                dagPath = om.MDagPath()
                component = om.MObject()

                selectionListItr.getDagPath(dagPath, component)

                pathName = dagPath.partialPathName()

                if not component.isNull():

                    if component.apiTypeStr() == 'kMeshPolygonComponent':

                        componentFn = om.MFnSingleIndexedComponent(component)
                        elementArray = om.MIntArray()
                        componentFn.getElements(elementArray)

                        for element in elementArray:

                            members['components'].append('%s.f[%i]' %
                                                         (pathName, element))

                else:
                    members['dagMembers'].append(pathName)

                selectionListItr.next()

            setsToDump.append(members)

        pickle.dump(setsToDump, output)
        output.close()
        print 'I\'m Done!'
Exemple #16
0
    def getAllAnimation():

        animCurveTU = cmds.ls(type='animCurveTU')
        animCurveTA = cmds.ls(type='animCurveTA')
        animCurveTL = cmds.ls(type='animCurveTU')

        animCurves = animCurveTU + animCurveTA + animCurveTL

        objectArray = om.MObjectArray()

        for curve in animCurves:

            mobject = GenAPI.getMObject(curve)
            objectArray.add(mobject)

        return objectArray
Exemple #17
0
    def getSkinCluster(shape):
        '''
        get skinCluster from shape
        input python string (shape)
        out mObject (skincluster)
        '''

        shapeObject = GenAPI.getMObject(shape)

        depItr = om.MItDependencyGraph(shapeObject, om.MFn.kSkinClusterFilter,
                                       om.MItDependencyGraph.kUpstream,
                                       om.MItDependencyGraph.kDepthFirst,
                                       om.MItDependencyGraph.kNodeLevel)

        return depItr.currentItem(), GenAPI.getStringFromMObject(
            depItr.currentItem())
Exemple #18
0
    def getSkinCluster(shape):
        
        '''
        get skinCluster from shape
        input python string (shape)
        out mObject (skincluster)
        '''
        
        shapeObject = GenAPI.getMObject(shape)
        
        depItr = om.MItDependencyGraph(shapeObject,om.MFn.kSkinClusterFilter,
                                       om.MItDependencyGraph.kUpstream,om.MItDependencyGraph.kDepthFirst,
                                       om.MItDependencyGraph.kNodeLevel)
    

        return depItr.currentItem(),GenAPI.getStringFromMObject(depItr.currentItem())
Exemple #19
0
 def getAllAnimation():
     
     animCurveTU = cmds.ls(type = 'animCurveTU')
     animCurveTA = cmds.ls(type = 'animCurveTA')
     animCurveTL = cmds.ls(type = 'animCurveTU')
     
     animCurves = animCurveTU + animCurveTA + animCurveTL
     
     objectArray = om.MObjectArray()
     
     for curve in animCurves:
         
         mobject = GenAPI.getMObject(curve)
         objectArray.add(mobject)
         
     return objectArray
Exemple #20
0
    def optimizeMembership(deformer, prune=0.001):

        deformerObject = GenAPI.getMObject(deformer)
        geoFilter = oma.MFnGeometryFilter(deformerObject)
        deformerSet = geoFilter.deformerSet()
        deformerSetFn = om.MFnSet(deformerSet)

        addSelectionList = om.MSelectionList()
        removeSelectionList = om.MSelectionList()

        dagMembers = WeightListTool.getDagMembers(deformer)

        progressWindow = UILib.ProgressWin()
        progressWindow.setTitle('Optimizing Deformer')
        progressWindow.itr = len(dagMembers)

        for i in range(len(dagMembers)):

            dagPath = GenAPI.getDagPath(dagMembers[i])
            vertItr = om.MItGeometry(dagPath)
            weightListTool = WeightListTool(dagPath.fullPathName(), deformer)
            weightList = weightListTool.getWeightList()

            while not vertItr.isDone():
                index = vertItr.index()
                component = vertItr.currentItem()

                if weightList[index] < prune:
                    removeSelectionList.add(dagPath, component)

                else:
                    addSelectionList.add(dagPath, component)

                vertItr.next()

            if not addSelectionList.isEmpty():
                deformerSetFn.addMembers(addSelectionList)

            if not removeSelectionList.isEmpty():
                deformerSetFn.removeMembers(removeSelectionList)

            progressWindow.inc = i
            progressWindow.message = '%s...%s' % (deformer, dagMembers[i])
            progressWindow.progress()

        progressWindow.end()
Exemple #21
0
    def addDagMember(mesh, deformer):
        '''
        method for adding dagObject to deformer
        input meshPath (python string)
        input defrormer(python string)
        '''

        deformerObject = GenAPI.getMObject(deformer)
        meshPath = GenAPI.getDagPath(mesh)
        vertObjects = GenAPI.getMObjectAllVerts(mesh)

        geoFilter = oma.MFnGeometryFilter(deformerObject)
        deformerSet = geoFilter.deformerSet()
        deformerSetFn = om.MFnSet(deformerSet)

        for vert in vertObjects:

            deformerSetFn.addMember(meshPath, vert)
Exemple #22
0
 def addDagMember(mesh,deformer):
     
     '''
     method for adding dagObject to deformer
     input meshPath (python string)
     input defrormer(python string)
     '''
     
     deformerObject = GenAPI.getMObject(deformer)
     meshPath = GenAPI.getDagPath(mesh)
     vertObjects = GenAPI.getMObjectAllVerts(mesh)
     
     geoFilter = oma.MFnGeometryFilter(deformerObject)
     deformerSet = geoFilter.deformerSet()
     deformerSetFn = om.MFnSet(deformerSet)
     
     for vert in vertObjects:
     
         deformerSetFn.addMember(meshPath,vert)
Exemple #23
0
def createClusterFromSoftSelection(name):
    '''function for creating a cluster from a soft selection'''

    clusterData = MeasuringLib.MeasuringTool.createWeightListFromSoftSelection(
    )
    cluster = cmds.cluster(name=name)

    deformerObject = GenAPI.getMObject(cluster[0])
    deformerTool = oma.MFnWeightGeometryFilter(deformerObject)

    inc = 0

    progressWindow = UILib.ProgressWin()
    progressWindow.setTitle('Cluster From Soft Selection')
    progressWindow.itr = len(clusterData[1])

    for components in clusterData[1]:

        geoFilter = oma.MFnGeometryFilter(deformerObject)
        deformerSet = geoFilter.deformerSet()
        setFn = om.MFnSet(deformerSet)
        setFn.addMember(components[0], components[1])

        floatArray = om.MFloatArray()

        for i in range(len(clusterData[2][inc])):

            floatArray.append(clusterData[2][inc][i])

        deformerTool.setWeight(components[0], components[1], floatArray)
        inc += 1

        progressWindow.inc = inc
        progressWindow.message = '%s.vtx[%i]' % (components[0].fullPathName(),
                                                 inc)
        progressWindow.progress()

    progressWindow.end()
    om.MGlobal.displayInfo('Created cluster from soft selection')
Exemple #24
0
def createClusterFromSoftSelection(name):
    
    '''function for creating a cluster from a soft selection'''
    
    clusterData = MeasuringLib.MeasuringTool.createWeightListFromSoftSelection()
    cluster = cmds.cluster(name = name)
      
    deformerObject = GenAPI.getMObject(cluster[0])
    deformerTool = oma.MFnWeightGeometryFilter(deformerObject)
    
    inc = 0
    
    progressWindow = UILib.ProgressWin()
    progressWindow.setTitle('Cluster From Soft Selection')
    progressWindow.itr = len(clusterData[1])
    
    for components in clusterData[1]:
        
        geoFilter = oma.MFnGeometryFilter(deformerObject)
        deformerSet = geoFilter.deformerSet()
        setFn = om.MFnSet(deformerSet)
        setFn.addMember(components[0],components[1])
        
        floatArray = om.MFloatArray()
        
        for i in range(len(clusterData[2][inc])):
        
            floatArray.append(clusterData[2][inc][i])
            
        deformerTool.setWeight(components[0],components[1],floatArray)
        inc += 1
        
        progressWindow.inc = inc
        progressWindow.message = '%s.vtx[%i]'%(components[0].fullPathName(),inc)
        progressWindow.progress()
    
    progressWindow.end()
    om.MGlobal.displayInfo('Created cluster from soft selection')
Exemple #25
0
    def jointsOnCVs(name,curve):
        
        if not cmds.nodeType(curve) == 'shape':
            
            curve = cmds.listRelatives(curve, type = 'shape')[0]
            
        mobject = GenAPI.getMObject(curve)
        iterCVs = om.MItCurveCV(mobject)
        
        while not iterCVs.isDone():

            index = iterCVs.index()
            nameIndex = index + 1         
            pos = iterCVs.position()
            joint = cmds.joint(n = '%s_0%i_Jnt'%(name,nameIndex), p = (pos[0],pos[1],pos[2]))
            
            try:
                cmds.parent(joint,w = True) 
                
            except RuntimeError:
                pass        
            
            iterCVs.next()
Exemple #26
0
    def jointsOnCVs(name, curve):

        if not cmds.nodeType(curve) == 'shape':

            curve = cmds.listRelatives(curve, type='shape')[0]

        mobject = GenAPI.getMObject(curve)
        iterCVs = om.MItCurveCV(mobject)

        while not iterCVs.isDone():

            index = iterCVs.index()
            nameIndex = index + 1
            pos = iterCVs.position()
            joint = cmds.joint(n='%s_0%i_Jnt' % (name, nameIndex),
                               p=(pos[0], pos[1], pos[2]))

            try:
                cmds.parent(joint, w=True)

            except RuntimeError:
                pass

            iterCVs.next()
Exemple #27
0
def extrapToCluster(transform, meshes):
    '''function for extraping weights from a transform to a cluster'''

    vertSelection = om.MSelectionList()

    for mesh in meshes:

        #gathering verticies
        meshPath = GenAPI.getDagPath(mesh)
        meshObject = GenAPI.getMObject(mesh)
        shape = mesh

        if meshObject.apiTypeStr() == 'kTransform':
            shape = cmds.listRelatives(meshPath.fullPathName(),
                                       type='shape')[0]

        meshObject = GenAPI.getMObject(shape)
        verts = GenAPI.getMObjectAllVerts(mesh)
        vertSelection.add(meshPath, verts)

    om.MGlobal.setActiveSelectionList(vertSelection)

    #creating cluster
    cluster = cmds.cluster()
    transformPosition = cmds.xform(transform, q=True, ws=True, rp=True)
    clusterShape = cmds.listRelatives(cluster[1], type='shape')

    cmds.setAttr('%s.originX' % clusterShape[0], transformPosition[0])
    cmds.setAttr('%s.originY' % clusterShape[0], transformPosition[1])
    cmds.setAttr('%s.originZ' % clusterShape[0], transformPosition[2])

    cmds.setAttr('%s.rotatePivotX' % cluster[1], transformPosition[0])
    cmds.setAttr('%s.rotatePivotY' % cluster[1], transformPosition[1])
    cmds.setAttr('%s.rotatePivotZ' % cluster[1], transformPosition[2])

    cmds.setAttr('%s.scalePivotX' % cluster[1], transformPosition[0])
    cmds.setAttr('%s.scalePivotY' % cluster[1], transformPosition[1])
    cmds.setAttr('%s.scalePivotZ' % cluster[1], transformPosition[2])

    #retrieving weight lists

    progressWin = UILib.ProgressWin()
    progressWin.setTitle('Extrap Cluster')
    progressWin.itr = len(meshes)
    inc = 0
    for mesh in meshes:

        meshObject = GenAPI.getMObject(mesh)
        meshPath = GenAPI.getDagPath(mesh)
        shape = mesh
        weightList = []

        if meshObject.apiTypeStr() == 'kTransform':
            shape = cmds.listRelatives(meshPath.fullPathName(),
                                       type='shape')[0]

        weightList = MeasuringLib.MeasuringTool.createWeigthListFromTransform(
            shape, transform)
        weightTool = WeightListTool(shape, cluster[0])
        weightTool.setWeightList(weightList)

        progressWin.inc = inc
        progressWin.progress()
        inc += 1

    progressWin.end()

    om.MGlobal.displayInfo('Extraped cluster from %s' % transform)
Exemple #28
0
def extrapFromLattice(latticeTransform):
    '''function for extraping skincluster from ffd'''

    progressWin = UILib.ProgressWin()
    progressWin.setTitle('Extrap Skincluster from Lattice')
    progressWin.itr = 7

    progressWin.inc = 1
    progressWin.progress()
    #gather lattice nodes
    latticeShape = cmds.listRelatives(latticeTransform, type='shape')[0]

    latticeFFD = cmds.listConnections(latticeShape, type='ffd')[0]
    #get skincluster and gather influences in lattice skincluster

    latticeSkinCluster = SkinningTool.getSkinCluster(latticeShape)
    latticeSkinningTool = SkinningTool(skincluster=latticeSkinCluster[1],
                                       shape=latticeShape)
    influenceArray = latticeSkinningTool.getInfluencesFromSkincluster()
    floatingJointList = []

    progressWin.inc = 2
    progressWin.progress()
    #create string list from influence array
    latticeInfluenceStringList = []
    for latInf in range(influenceArray.length()):

        latticeInfluenceStringList.append(
            influenceArray[latInf].fullPathName())
        print influenceArray[latInf].fullPathName()

    progressWin.inc = 3
    progressWin.progress()
    #swapping influence for floating joints
    for influenceInc in range(influenceArray.length()):

        currentInfluenceString = influenceArray[influenceInc].fullPathName()

        #clear selection and gather verts
        om.MGlobal.clearSelectionList()

        #creating floating joint
        transformFn = om.MFnTransform(influenceArray[influenceInc])
        position = transformFn.getTranslation(om.MSpace.kWorld)

        floatingJoint = [cmds.joint()][0]
        floatingJointPath = GenAPI.getDagPath(floatingJoint)
        transformFn.setObject(floatingJointPath)
        transformFn.setTranslation(position, om.MSpace.kWorld)
        floatingJointList.append(floatingJoint)

        #add floating joint to skin cluster and swap weights
        cmds.skinCluster(latticeSkinCluster[1],
                         e=True,
                         weight=0,
                         addInfluence=floatingJoint)

        latticeWeightList = latticeSkinningTool.getWeightsFromLattice(
            influenceArray[influenceInc])

        #re-gather influences after adding floating joint
        latticeInfluenceStringList02 = []

        influenceArray02 = latticeSkinningTool.getInfluencesFromSkincluster()

        for latInf in range(influenceArray02.length()):

            latticeInfluenceStringList02.append(
                influenceArray02[latInf].fullPathName())

        #lock influences
        for influence in latticeInfluenceStringList02:

            cmds.setAttr('%s.lockInfluenceWeights' % influence, 1)

        cmds.setAttr('%s.lockInfluenceWeights' % floatingJoint, 0)
        cmds.setAttr('%s.lockInfluenceWeights' % currentInfluenceString, 0)

        #swapWeights

        latticeSkinningTool.setWeightsForLattice(floatingJointPath,
                                                 latticeWeightList)

    progressWin.inc = 4
    progressWin.progress()
    #gather meshes affected by lattice
    latticeFn = oma.MFnLatticeDeformer(GenAPI.getMObject(latticeFFD))
    meshObjArray = om.MObjectArray()
    latticeFn.getAffectedGeometry(meshObjArray)

    progressWin.inc = 5
    progressWin.progress()
    #iterate meshes and gather weightLists
    for meshInc in range(meshObjArray.length()):

        weightLists = []

        #creating weightList from floating joint
        for floatingJoint in floatingJointList:

            #creating weightList
            weightList = MeasuringLib.MeasuringTool.createWeigthListFromInfluence2(
                GenAPI.getStringFromMObject(meshObjArray[meshInc]),
                floatingJoint)
            weightLists.append(weightList)

        #remove mesh from lattice
        latticeFn.removeGeometry(meshObjArray[meshInc])

        #create skincluster for current mesh in iteration
        meshSkinCluster = cmds.skinCluster(
            GenAPI.getStringFromMObject(meshObjArray[meshInc]),
            latticeInfluenceStringList)[0]
        meshSkinningTool = SkinningTool(
            meshSkinCluster,
            GenAPI.getStringFromMObject(meshObjArray[meshInc]))

        #unlock all influences
        for influence in latticeInfluenceStringList:

            cmds.setAttr('%s.lockInfluenceWeights' % influence, 0)

        #setWeightLists
        for influenceInc in range(influenceArray.length()):

            meshSkinningTool.setWeights(influenceArray[influenceInc],
                                        weightLists[influenceInc])

            cmds.setAttr(
                '%s.lockInfluenceWeights' %
                influenceArray[influenceInc].fullPathName(), 1)

    progressWin.inc = 6
    progressWin.progress()
    #reset weighting

    for inc in range(influenceArray.length()):

        floatingJointPath = GenAPI.getDagPath(floatingJointList[inc])
        weightList = latticeSkinningTool.getWeightsFromLattice(
            floatingJointPath)

        allLatticeInfluences = latticeSkinningTool.getInfluencesFromSkincluster(
        )

        #lock all inluences

        for influence in range(allLatticeInfluences.length()):
            cmds.setAttr(
                '%s.lockInfluenceWeights' %
                allLatticeInfluences[influence].fullPathName(), 1)

        #unlock current influences
        cmds.setAttr('%s.lockInfluenceWeights' % floatingJointList[inc], 0)
        cmds.setAttr(
            '%s.lockInfluenceWeights' % influenceArray[inc].fullPathName(), 0)

        latticeSkinningTool.setWeightsForLattice(influenceArray[inc],
                                                 weightList)

    progressWin.inc = 7
    progressWin.progress()
    #delete floating joints
    for joint in floatingJointList:
        cmds.delete(joint)

    progressWin.end()
Exemple #29
0
def extrapFromLattice(latticeTransform):
    
    '''function for extraping skincluster from ffd'''
    
    progressWin = UILib.ProgressWin()
    progressWin.setTitle('Extrap Skincluster from Lattice')
    progressWin.itr = 7
    
    progressWin.inc = 1
    progressWin.progress()  
    #gather lattice nodes
    latticeShape = cmds.listRelatives(latticeTransform, type = 'shape')[0]
    
    latticeFFD = cmds.listConnections(latticeShape, type = 'ffd')[0]
    #get skincluster and gather influences in lattice skincluster

    latticeSkinCluster = SkinningTool.getSkinCluster(latticeShape)
    latticeSkinningTool = SkinningTool(skincluster = latticeSkinCluster[1],shape = latticeShape)
    influenceArray = latticeSkinningTool.getInfluencesFromSkincluster()
    floatingJointList = []
    
    progressWin.inc = 2
    progressWin.progress() 
    #create string list from influence array
    latticeInfluenceStringList = []
    for latInf in range(influenceArray.length()):
    
        latticeInfluenceStringList.append(influenceArray[latInf].fullPathName())
        print influenceArray[latInf].fullPathName()
    
    progressWin.inc = 3
    progressWin.progress() 
    #swapping influence for floating joints
    for influenceInc in range(influenceArray.length()):
            
            currentInfluenceString = influenceArray[influenceInc].fullPathName()
            
            #clear selection and gather verts
            om.MGlobal.clearSelectionList()
            
            #creating floating joint
            transformFn = om.MFnTransform(influenceArray[influenceInc])
            position = transformFn.getTranslation(om.MSpace.kWorld)
            
            floatingJoint = [cmds.joint()][0]
            floatingJointPath = GenAPI.getDagPath(floatingJoint)
            transformFn.setObject(floatingJointPath)
            transformFn.setTranslation(position,om.MSpace.kWorld)
            floatingJointList.append(floatingJoint)
            
            #add floating joint to skin cluster and swap weights
            cmds.skinCluster(latticeSkinCluster[1],e = True , weight = 0,addInfluence = floatingJoint)
            
            latticeWeightList = latticeSkinningTool.getWeightsFromLattice(influenceArray[influenceInc])
    
            #re-gather influences after adding floating joint
            latticeInfluenceStringList02 = []
            
            influenceArray02 = latticeSkinningTool.getInfluencesFromSkincluster()
    
            for latInf in range(influenceArray02.length()):
            
                latticeInfluenceStringList02.append(influenceArray02[latInf].fullPathName())
            
            #lock influences        
            for influence in latticeInfluenceStringList02:
                
                cmds.setAttr('%s.lockInfluenceWeights'%influence,1)

            cmds.setAttr('%s.lockInfluenceWeights'%floatingJoint,0)
            cmds.setAttr('%s.lockInfluenceWeights'%currentInfluenceString,0)                
            
            #swapWeights

            latticeSkinningTool.setWeightsForLattice(floatingJointPath,latticeWeightList)   
    
    progressWin.inc = 4
    progressWin.progress() 
    #gather meshes affected by lattice
    latticeFn = oma.MFnLatticeDeformer(GenAPI.getMObject(latticeFFD))
    meshObjArray = om.MObjectArray()
    latticeFn.getAffectedGeometry(meshObjArray)
    
    progressWin.inc = 5
    progressWin.progress() 
    #iterate meshes and gather weightLists   
    for meshInc in range(meshObjArray.length()):
        
        weightLists = []
   
        #creating weightList from floating joint      
        for floatingJoint in floatingJointList:

            #creating weightList
            weightList = MeasuringLib.MeasuringTool.createWeigthListFromInfluence2(GenAPI.getStringFromMObject(meshObjArray[meshInc]),floatingJoint) 
            weightLists.append(weightList)
        

        #remove mesh from lattice
        latticeFn.removeGeometry(meshObjArray[meshInc])
                  
        #create skincluster for current mesh in iteration  
        meshSkinCluster = cmds.skinCluster(GenAPI.getStringFromMObject(meshObjArray[meshInc]),latticeInfluenceStringList)[0]
        meshSkinningTool = SkinningTool(meshSkinCluster,GenAPI.getStringFromMObject(meshObjArray[meshInc]))

        #unlock all influences
        for influence in latticeInfluenceStringList:
            
            cmds.setAttr('%s.lockInfluenceWeights'%influence,0)
    
        #setWeightLists 
        for influenceInc in range(influenceArray.length()):
            
            meshSkinningTool.setWeights(influenceArray[influenceInc], weightLists[influenceInc])
                     
            cmds.setAttr('%s.lockInfluenceWeights'%influenceArray[influenceInc].fullPathName(),1)
    
    progressWin.inc = 6
    progressWin.progress()                      
    #reset weighting
    
    for inc in range(influenceArray.length()):
        
        floatingJointPath = GenAPI.getDagPath(floatingJointList[inc])
        weightList = latticeSkinningTool.getWeightsFromLattice(floatingJointPath)
        
        allLatticeInfluences = latticeSkinningTool.getInfluencesFromSkincluster()
        
        #lock all inluences
        
        for influence in range(allLatticeInfluences.length()):
            cmds.setAttr('%s.lockInfluenceWeights'%allLatticeInfluences[influence].fullPathName(),1)
            
            
        #unlock current influences
        cmds.setAttr('%s.lockInfluenceWeights'%floatingJointList[inc],0)
        cmds.setAttr('%s.lockInfluenceWeights'%influenceArray[inc].fullPathName(),0)
        
        
        latticeSkinningTool.setWeightsForLattice(influenceArray[inc],weightList)
        
    progressWin.inc = 7
    progressWin.progress() 
    #delete floating joints   
    for joint in floatingJointList: 
        cmds.delete(joint)
        
    progressWin.end()
Exemple #30
0
    def mirrorWeightListMultiMesh(fromMesh,toMesh,deformer,table = [-1,1,1]):
        
        '''
        this method will create a mirrored weightList from one mesh to another
        meshes must be symetrical
        input python string (fromMesh)
        input python string (toMesh)
        input python string (deformer)
        input python list (symetry table)
        '''

        weightList = []
        membershipList = []
        
        util = om.MScriptUtil()
        
        fromMeshPath = GenAPI.getDagPath(fromMesh)
        toMeshPath = GenAPI.getDagPath(toMesh)
        
        meshToVertItr = om.MItMeshVertex(toMeshPath)
        
        deformerObject = GenAPI.getMObject(deformer)
        
        deformerWeightFn = oma.MFnWeightGeometryFilter(deformerObject)
        weights = om.MFloatArray()
        
        progressWindow = UILib.ProgressWin()
        progressWindow.setTitle('Mirror Wieghts')
        progressWindow.itr = meshToVertItr.count()
        
        while not meshToVertItr.isDone():
            
            fromVertPoint = meshToVertItr.position(om.MSpace.kWorld)
            
            vertID =  MeasuringLib.MeasuringTool.getSymVertFromClosestPoint(fromMeshPath,fromVertPoint,table = table)

            meshFromVertItr = om.MItMeshVertex(fromMeshPath)
            intPtr = util.asIntPtr()
            
            meshFromVertItr.setIndex(vertID[0],intPtr)
            fromVert = meshToVertItr.currentItem()
            
            try:
                deformerWeightFn.getWeights(fromMeshPath,fromVert,weights)
                weightTool = WeightListTool(fromMesh,deformer)
                membershipList.append(weightTool.checkMembership(fromVert))
                weightList.append(weights[0])
            except:
                weightTool = WeightListTool(fromMesh,deformer)
                membershipList.append(weightTool.checkMembership(fromVert))
                weightList.append(0)
            
            
            
            progressWindow.inc = meshToVertItr.index()
            progressWindow.message = '%s...%i of %i'%(fromMesh,meshToVertItr.index(),meshToVertItr.count())
            progressWindow.progress()
             
            meshToVertItr.next()
            
        progressWindow.end()
            
        return weightList,membershipList
Exemple #31
0
    def IKFKRig(name, rootJoint, blendAttr, poleVector=[0, 0, 1]):

        ##get joint chain...
        bindJoints = cmds.listRelatives(rootJoint, ad=True)
        bindJoints.append(rootJoint)
        bindJoints.reverse()

        ##clear selection
        cmds.select(cl=True)

        ikJoints = []

        ##create ik joint chain
        inc = 1
        for joint in bindJoints:

            prefferedAngle = [
                cmds.getAttr('%s.preferredAngleX' % joint),
                cmds.getAttr('%s.preferredAngleY' % joint),
                cmds.getAttr('%s.preferredAngleZ' % joint)
            ]

            ikJoint = cmds.joint(n='%s_IK_0%i_Jnt' % (name, inc))
            parentConstraint = cmds.parentConstraint(joint, ikJoint)
            cmds.delete(parentConstraint)
            cmds.makeIdentity(a=True)
            cmds.setAttr('%s.preferredAngleX' % ikJoint, prefferedAngle[0])
            cmds.setAttr('%s.preferredAngleY' % ikJoint, prefferedAngle[1])
            cmds.setAttr('%s.preferredAngleZ' % ikJoint, prefferedAngle[2])

            ikJoints.append(ikJoint)

            inc += 1

        ##create ik handle
        ikHandle = cmds.ikHandle(sj=ikJoints[0],
                                 ee=ikJoints[-1],
                                 sol='ikRPsolver',
                                 n='%s_IKHandle' % name)
        poleVectorLoc = cmds.spaceLocator(n='%s_PoleVector_Loc' % name)

        ##create pole vector
        poleVectorLocGroup = cmds.group(empty=True,
                                        n='%s_Group' % poleVectorLoc[0])
        pointConstraint = cmds.pointConstraint(ikJoints[1], ikJoints[-2],
                                               poleVectorLocGroup)
        orientConstraint = cmds.orientConstraint(rootJoint, poleVectorLocGroup)
        cmds.delete(pointConstraint)
        cmds.delete(orientConstraint)

        cmds.parent(poleVectorLoc[0], poleVectorLocGroup)
        cmds.move(0, 0, 0, poleVectorLoc[0], os=True)
        cmds.move(poleVector[0],
                  poleVector[1],
                  poleVector[2],
                  poleVectorLoc[0],
                  os=True)
        cmds.rotate(0, 0, 0, poleVectorLoc[0], os=True)
        cmds.poleVectorConstraint(poleVectorLoc[0], ikHandle[0])

        #measure joint hierarchy length
        rootObject = GenAPI.getMObject(rootJoint)
        measurement = MeasuringLib.MeasuringTool.getLengthOfHierarchy(
            rootObject)

        #build measuring rig
        measuringTool = MeasuringLib.MeasuringTool(ikJoints[0], ikJoints[-1])
        measuringLoc = measuringTool.nullMeasurementRig('%s_Measurement' %
                                                        name)

        #create controls
        ikControl = cmds.group(empty=True, name='%s_IK_Ctrl' % name)
        ikControlGroup = cmds.group(empty=True,
                                    name='%s_IK_Ctrl_Offset' % name)
        cmds.parent(ikControl, ikControlGroup)
        parentConstraint = cmds.parentConstraint(ikJoints[-1], ikControlGroup)
        cmds.delete(parentConstraint)

        cmds.setAttr('%s.sx' % ikControl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.setAttr('%s.sy' % ikControl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.setAttr('%s.sz' % ikControl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.setAttr('%s.v' % ikControl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.addAttr(ikControl, ln='stretchy', at='double', min=0, max=1, dv=0)
        cmds.setAttr('%s.stretchy' % ikControl, e=True, keyable=True)
        cmds.addAttr(ikControl, ln='length', at='double', dv=0)
        cmds.setAttr('%s.length' % ikControl, e=True, keyable=True)
        cmds.addAttr(ikControl, ln='noBend', at='bool', dv=False)
        cmds.setAttr('%s.noBend' % ikControl, e=True, keyable=True)
        cmds.addAttr(ikControl, ln='twist', at='double', dv=0)
        cmds.setAttr('%s.twist' % ikControl, e=True, keyable=True)

        poleVectorCtrl = cmds.group(empty=True,
                                    name='%s_PoleVector_Ctrl' % name)
        poleVectorCtrlGroup = cmds.group(empty=True,
                                         name='%s_PoleVector_Ctrl_Offset' %
                                         name)
        cmds.parent(poleVectorCtrl, poleVectorCtrlGroup)
        poleVectorCtrlPos = cmds.xform(poleVectorLoc,
                                       q=True,
                                       ws=True,
                                       translation=True)
        cmds.move(poleVectorCtrlPos[0], poleVectorCtrlPos[1],
                  poleVectorCtrlPos[2], poleVectorCtrlGroup)
        cmds.setAttr('%s.sx' % poleVectorCtrl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.setAttr('%s.sy' % poleVectorCtrl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.setAttr('%s.sz' % poleVectorCtrl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.setAttr('%s.rx' % poleVectorCtrl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.setAttr('%s.ry' % poleVectorCtrl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.setAttr('%s.rz' % poleVectorCtrl,
                     lock=True,
                     keyable=False,
                     channelBox=False)
        cmds.setAttr('%s.v' % poleVectorCtrl,
                     lock=True,
                     keyable=False,
                     channelBox=False)

        #create constraints
        cmds.pointConstraint(ikControl, ikHandle[0])
        cmds.pointConstraint(ikControl, measuringLoc[2])
        cmds.pointConstraint(poleVectorCtrl, poleVectorLoc[0])

        #make stretchy
        stretchOutput = Utilities.stretchNodeNetwork(name, measurement,
                                                     '%s.tx' % measuringLoc[1])
        inc = 0
        for joint in ikJoints:

            if inc < ikJoints[-1]:

                cmds.connectAttr('%s.outputR' % stretchOutput[0],
                                 '%s.sx' % joint)

            inc += 1

        #create elbow stretch
        for joint in ikJoints:

            if not joint == ikJoints[0]:

                pmaNode = cmds.createNode('plusMinusAverage',
                                          n='%s_IKLength_PMA' % joint)
                translateVal = cmds.getAttr('%s.tx' % joint)
                cmds.setAttr('%s.input1D[0]' % pmaNode, translateVal)
                cmds.connectAttr('%s.length' % ikControl,
                                 '%s.input1D[1]' % pmaNode)
                cmds.connectAttr('%s.output1D' % pmaNode, '%s.tx' % joint)

        #connect control attrs
        cmds.connectAttr('%s.stretchy' % ikControl,
                         '%s.blender' % stretchOutput[0])
        cmds.connectAttr('%s.noBend' % ikControl,
                         '%s.firstTerm' % stretchOutput[1])
        cmds.connectAttr('%s.twist' % ikControl, '%s.twist' % ikHandle[0])

        ##create fk joint chain
        fkJoints = []
        inc = 1
        cmds.select(cl=True)
        for joint in ikJoints:

            prefferedAngle = [
                cmds.getAttr('%s.preferredAngleX' % joint),
                cmds.getAttr('%s.preferredAngleY' % joint),
                cmds.getAttr('%s.preferredAngleZ' % joint)
            ]

            fkJoint = cmds.joint(n='%s_FK_0%i_Jnt' % (name, inc))
            parentConstraint = cmds.parentConstraint(joint, fkJoint)
            cmds.delete(parentConstraint)
            cmds.makeIdentity(a=True)
            cmds.setAttr('%s.preferredAngleX' % fkJoint, prefferedAngle[0])
            cmds.setAttr('%s.preferredAngleY' % fkJoint, prefferedAngle[1])
            cmds.setAttr('%s.preferredAngleZ' % fkJoint, prefferedAngle[2])

            fkJoints.append(fkJoint)

            inc += 1

        #create FK Rig
        fkRig = SkeletalRigs.FKRig(name, fkJoints[0])

        #createConstraints
        ikfkReverseBlend = cmds.createNode('reverse',
                                           n='%s_IKFK_Reverse' % name)
        cmds.connectAttr(blendAttr, '%s.inputX' % ikfkReverseBlend)
        inc = 0

        for joint in bindJoints:

            constraint = cmds.parentConstraint(ikJoints[inc], fkJoints[inc],
                                               joint)[0]

            cmds.connectAttr(blendAttr,
                             '%s.%sW0' % (constraint, ikJoints[inc]))
            cmds.connectAttr('%s.outputX' % ikfkReverseBlend,
                             '%s.%sW1' % (constraint, fkJoints[inc]))

            inc += 1

        #clean-up
        ikJointGroup = cmds.group(empty=True, name='%s_IK_Jnt_Group' % name)
        ikCtrlGroup = cmds.group(empty=True, name='%s_IK_Ctrl_Group' % name)

        cmds.parent(ikHandle[0], ikJointGroup)
        cmds.parent(poleVectorLocGroup, ikJointGroup)
        cmds.parent(measuringLoc[3], ikJointGroup)
        cmds.parent(ikJoints[0], ikJointGroup)

        jointGroup = cmds.group(empty=True, n='%s_Jnt_Group' % name)
        cmds.parent(fkRig[2], jointGroup)
        cmds.parent(ikJointGroup, jointGroup)

        cmds.parent(ikControlGroup, ikCtrlGroup)
        cmds.parent(poleVectorCtrlGroup, ikCtrlGroup)

        ctrlGroup = cmds.group(empty=True, n='%s_Ctrl_Group' % name)
        cmds.parent(fkRig[1], ctrlGroup)
        cmds.parent(ikCtrlGroup, ctrlGroup)

        cmds.select(cl=True)

        return ikControl, poleVectorCtrl, fkRig[1]
Exemple #32
0
    def mirrorWeightListMultiMesh(fromMesh,
                                  toMesh,
                                  deformer,
                                  table=[-1, 1, 1]):
        '''
        this method will create a mirrored weightList from one mesh to another
        meshes must be symetrical
        input python string (fromMesh)
        input python string (toMesh)
        input python string (deformer)
        input python list (symetry table)
        '''

        weightList = []
        membershipList = []

        util = om.MScriptUtil()

        fromMeshPath = GenAPI.getDagPath(fromMesh)
        toMeshPath = GenAPI.getDagPath(toMesh)

        meshToVertItr = om.MItMeshVertex(toMeshPath)

        deformerObject = GenAPI.getMObject(deformer)

        deformerWeightFn = oma.MFnWeightGeometryFilter(deformerObject)
        weights = om.MFloatArray()

        progressWindow = UILib.ProgressWin()
        progressWindow.setTitle('Mirror Wieghts')
        progressWindow.itr = meshToVertItr.count()

        while not meshToVertItr.isDone():

            fromVertPoint = meshToVertItr.position(om.MSpace.kWorld)

            vertID = MeasuringLib.MeasuringTool.getSymVertFromClosestPoint(
                fromMeshPath, fromVertPoint, table=table)

            meshFromVertItr = om.MItMeshVertex(fromMeshPath)
            intPtr = util.asIntPtr()

            meshFromVertItr.setIndex(vertID[0], intPtr)
            fromVert = meshToVertItr.currentItem()

            try:
                deformerWeightFn.getWeights(fromMeshPath, fromVert, weights)
                weightTool = WeightListTool(fromMesh, deformer)
                membershipList.append(weightTool.checkMembership(fromVert))
                weightList.append(weights[0])
            except:
                weightTool = WeightListTool(fromMesh, deformer)
                membershipList.append(weightTool.checkMembership(fromVert))
                weightList.append(0)

            progressWindow.inc = meshToVertItr.index()
            progressWindow.message = '%s...%i of %i' % (
                fromMesh, meshToVertItr.index(), meshToVertItr.count())
            progressWindow.progress()

            meshToVertItr.next()

        progressWindow.end()

        return weightList, membershipList
Exemple #33
0
    def pointOnCurveNearLoc(name,curve,controlAttr):

        zero = ''
        i = 0
        
        selection = om.MSelectionList()
        om.MGlobal.getActiveSelectionList(selection)
        selectionItr = om.MItSelectionList(selection )
        
        #iterate through selection
        while not selectionItr.isDone():

            if i<=9:
                zero = '0'
                
            else:
                zero = ''
            
            nameIndex = i + 1
            objPath = om.MDagPath()
            selectionItr.getDagPath(objPath)
            
            transformFn = om.MFnTransform(objPath)
            pos = transformFn.getTranslation(om.MSpace.kWorld)
            mpoint = om.MPoint(pos)
            
            curveFn = om.MFnNurbsCurve(GenAPI.getMObject(curve))
            util =  om.MScriptUtil()
            uValueNull = util.asDoublePtr()
            curveFn.closestPoint(mpoint,uValueNull,om.MSpace.kWorld)
            
            uValue = util.getDouble(uValueNull)
            
            locator = cmds.spaceLocator(n = '%s_%s%i_Loc'%(name,zero,nameIndex))
            cmds.addAttr(locator[0],ln = "Offset" ,at = 'double')
            cmds.setAttr('%s.Offset'%locator[0], e = True, keyable = True)
            motionPath = cmds.createNode('motionPath',n = '%s_%s%i_MotionPath'%(name,zero,nameIndex))
            cmds.connectAttr('%s.worldSpace[0]'%curve,'%s.geometryPath'%motionPath)
                    
            cmds.connectAttr('%s.allCoordinates'%motionPath,'%s.translate'%locator[0])
            cmds.connectAttr('%s.rotate'%motionPath,'%s.rotate'%locator[0])
            cmds.connectAttr('%s.rotateOrder'%motionPath, '%s.rotateOrder'%locator[0])
            
            cmds.setAttr('%s.fractionMode'%motionPath,1)
            cmds.setAttr('%s.frontAxis'%motionPath,1)
            cmds.setAttr('%s.upAxis'%motionPath,1)
            cmds.setAttr('%s.worldUpType'%motionPath,1)
            cmds.setAttr('%s.fractionMode'%motionPath,0)
            
            cmds.setAttr('%s.uValue'%motionPath, uValue)
            cmds.setAttr('%s.worldUpType'%motionPath, 2)
            cmds.setAttr ('%s.frontAxis'%motionPath,0)
            cmds.setAttr ('%s.upAxis'%motionPath,2)
            
            sliderMD = cmds.createNode('multiplyDivide', n = '%s_%s%i_Slider_MD'%(name,zero,nameIndex))
            cmds.connectAttr(controlAttr,'%s.input1X'%sliderMD)
            cmds.setAttr('%s.input2X'%sliderMD, 0.01)
            sliderPMA = cmds.createNode('plusMinusAverage', n = '%s_%s%i_Slider_PMA'%(name,zero,nameIndex))
            cmds.connectAttr('%s.outputX'%sliderMD,'%s.input1D[0]'%sliderPMA )
            cmds.setAttr('%s.input1D[1]'%sliderPMA,uValue)
            
            offsetMD = cmds.createNode('multiplyDivide', n = '%s_%s%i_Slider_MD'%(name,zero,nameIndex))
            cmds.connectAttr('%s.Offset'%locator[0],'%s.input1X'%offsetMD )
            cmds.setAttr('%s.input2X'%offsetMD, 0.001)
            offsetPMA = cmds.createNode('plusMinusAverage', n = '%s_%s%i_Offset_PMA'%(name,zero,nameIndex))
            cmds.connectAttr('%s.outputX'%offsetMD,'%s.input1D[0]'%offsetPMA )
            cmds.connectAttr('%s.output1D'%sliderPMA,'%s.input1D[1]'%offsetPMA )
            
            cmds.connectAttr('%s.output1D'%offsetPMA, '%s.uValue'%motionPath)
        
        
            selectionItr.next()
Exemple #34
0
def extrapToCluster(transform,meshes):
    
    '''function for extraping weights from a transform to a cluster'''
       
    vertSelection = om.MSelectionList()
    
    for mesh in meshes:
        
        #gathering verticies
        meshPath = GenAPI.getDagPath(mesh)
        meshObject = GenAPI.getMObject(mesh)
        shape = mesh
        
        if meshObject.apiTypeStr() == 'kTransform':
            shape = cmds.listRelatives(meshPath.fullPathName(),type = 'shape')[0]
            
        meshObject = GenAPI.getMObject(shape)
        verts = GenAPI.getMObjectAllVerts(mesh)
        vertSelection.add(meshPath,verts)
        
    om.MGlobal.setActiveSelectionList(vertSelection)

    #creating cluster    
    cluster = cmds.cluster()
    transformPosition = cmds.xform(transform,q = True,ws = True, rp = True)
    clusterShape = cmds.listRelatives(cluster[1],type = 'shape')
    
    cmds.setAttr('%s.originX'%clusterShape[0],transformPosition[0])
    cmds.setAttr('%s.originY'%clusterShape[0],transformPosition[1])
    cmds.setAttr('%s.originZ'%clusterShape[0],transformPosition[2])
    
    cmds.setAttr('%s.rotatePivotX'%cluster[1],transformPosition[0])
    cmds.setAttr('%s.rotatePivotY'%cluster[1],transformPosition[1])
    cmds.setAttr('%s.rotatePivotZ'%cluster[1],transformPosition[2])
    
    cmds.setAttr('%s.scalePivotX'%cluster[1],transformPosition[0])
    cmds.setAttr('%s.scalePivotY'%cluster[1],transformPosition[1])
    cmds.setAttr('%s.scalePivotZ'%cluster[1],transformPosition[2])
    
    #retrieving weight lists

    progressWin = UILib.ProgressWin()
    progressWin.setTitle('Extrap Cluster')
    progressWin.itr = len(meshes)
    inc = 0
    for mesh in meshes:
        
        meshObject = GenAPI.getMObject(mesh)
        meshPath = GenAPI.getDagPath(mesh)
        shape = mesh
        weightList = []
        
        if meshObject.apiTypeStr() == 'kTransform':
            shape = cmds.listRelatives(meshPath.fullPathName(),type = 'shape')[0]
        
        weightList = MeasuringLib.MeasuringTool.createWeigthListFromTransform(shape,transform)
        weightTool = WeightListTool(shape,cluster[0])
        weightTool.setWeightList(weightList)
                 
        progressWin.inc = inc
        progressWin.progress()
        inc += 1
        
    progressWin.end()
 
    om.MGlobal.displayInfo('Extraped cluster from %s'%transform)
Exemple #35
0
    def IKFKRig(name,rootJoint,blendAttr,poleVector = [0,0,1]):
            
        ##get joint chain...
        bindJoints = cmds.listRelatives(rootJoint,ad = True)
        bindJoints.append(rootJoint)
        bindJoints.reverse()
        
        ##clear selection
        cmds.select(cl = True)
        
        ikJoints = []
        
        ##create ik joint chain
        inc = 1
        for joint in bindJoints:
        
            prefferedAngle = [cmds.getAttr('%s.preferredAngleX'%joint),
                              cmds.getAttr('%s.preferredAngleY'%joint),
                              cmds.getAttr('%s.preferredAngleZ'%joint)]
        
            ikJoint = cmds.joint(n = '%s_IK_0%i_Jnt'%(name,inc))
            parentConstraint = cmds.parentConstraint(joint,ikJoint)
            cmds.delete(parentConstraint)
            cmds.makeIdentity(a = True)
            cmds.setAttr('%s.preferredAngleX'%ikJoint,prefferedAngle[0])
            cmds.setAttr('%s.preferredAngleY'%ikJoint,prefferedAngle[1])
            cmds.setAttr('%s.preferredAngleZ'%ikJoint,prefferedAngle[2])
            
            ikJoints.append(ikJoint)
            
            inc += 1
        
        ##create ik handle
        ikHandle = cmds.ikHandle(sj = ikJoints[0], ee = ikJoints[-1], sol = 'ikRPsolver', n = '%s_IKHandle'%name)
        poleVectorLoc = cmds.spaceLocator(n = '%s_PoleVector_Loc'%name)
        
        ##create pole vector
        poleVectorLocGroup = cmds.group(empty = True, n = '%s_Group'%poleVectorLoc[0])
        pointConstraint = cmds.pointConstraint(ikJoints[1],ikJoints[-2],poleVectorLocGroup)
        orientConstraint = cmds.orientConstraint(rootJoint,poleVectorLocGroup)
        cmds.delete(pointConstraint);cmds.delete(orientConstraint)
        
        cmds.parent(poleVectorLoc[0],poleVectorLocGroup)
        cmds.move(0,0,0,poleVectorLoc[0],os = True)
        cmds.move(poleVector[0],poleVector[1],poleVector[2],poleVectorLoc[0],os = True)
        cmds.rotate(0,0,0,poleVectorLoc[0],os = True)
        cmds.poleVectorConstraint(poleVectorLoc[0],ikHandle[0])
        
        #measure joint hierarchy length
        rootObject = GenAPI.getMObject(rootJoint)
        measurement = MeasuringLib.MeasuringTool.getLengthOfHierarchy(rootObject)

        
        #build measuring rig
        measuringTool = MeasuringLib.MeasuringTool(ikJoints[0],ikJoints[-1])
        measuringLoc = measuringTool.nullMeasurementRig('%s_Measurement'%name)
        
        #create controls
        ikControl = cmds.group(empty = True, name = '%s_IK_Ctrl'%name)
        ikControlGroup = cmds.group(empty = True, name = '%s_IK_Ctrl_Offset'%name)
        cmds.parent(ikControl, ikControlGroup)
        parentConstraint = cmds.parentConstraint(ikJoints[-1],ikControlGroup)
        cmds.delete(parentConstraint)

        cmds.setAttr('%s.sx'%ikControl,lock = True, keyable = False,channelBox = False)
        cmds.setAttr('%s.sy'%ikControl,lock = True, keyable = False,channelBox = False)
        cmds.setAttr('%s.sz'%ikControl,lock = True, keyable = False,channelBox = False)
        cmds.setAttr('%s.v'%ikControl,lock = True, keyable = False,channelBox = False)
        cmds.addAttr(ikControl, ln = 'stretchy' , at = 'double', min = 0, max = 1, dv = 0)
        cmds.setAttr('%s.stretchy'%ikControl, e = True, keyable = True)       
        cmds.addAttr(ikControl, ln = 'length' , at = 'double', dv = 0)
        cmds.setAttr('%s.length'%ikControl, e = True, keyable = True)        
        cmds.addAttr(ikControl, ln = 'noBend' , at = 'bool', dv = False)
        cmds.setAttr('%s.noBend'%ikControl, e = True, keyable = True)        
        cmds.addAttr(ikControl, ln = 'twist' , at = 'double', dv = 0)
        cmds.setAttr('%s.twist'%ikControl, e = True, keyable = True)
                
        poleVectorCtrl = cmds.group(empty = True, name = '%s_PoleVector_Ctrl'%name)
        poleVectorCtrlGroup = cmds.group(empty = True, name = '%s_PoleVector_Ctrl_Offset'%name)
        cmds.parent(poleVectorCtrl,poleVectorCtrlGroup)
        poleVectorCtrlPos = cmds.xform(poleVectorLoc, q = True, ws = True, translation = True)
        cmds.move(poleVectorCtrlPos[0],poleVectorCtrlPos[1],poleVectorCtrlPos[2],poleVectorCtrlGroup)
        cmds.setAttr('%s.sx'%poleVectorCtrl,lock = True, keyable = False,channelBox = False)
        cmds.setAttr('%s.sy'%poleVectorCtrl,lock = True, keyable = False,channelBox = False)
        cmds.setAttr('%s.sz'%poleVectorCtrl,lock = True, keyable = False,channelBox = False)
        cmds.setAttr('%s.rx'%poleVectorCtrl,lock = True, keyable = False,channelBox = False)
        cmds.setAttr('%s.ry'%poleVectorCtrl,lock = True, keyable = False,channelBox = False)
        cmds.setAttr('%s.rz'%poleVectorCtrl,lock = True, keyable = False,channelBox = False)
        cmds.setAttr('%s.v'%poleVectorCtrl,lock = True, keyable = False,channelBox = False)
        
        #create constraints
        cmds.pointConstraint(ikControl,ikHandle[0])
        cmds.pointConstraint(ikControl,measuringLoc[2])
        cmds.pointConstraint(poleVectorCtrl,poleVectorLoc[0])
        
        #make stretchy
        stretchOutput = Utilities.stretchNodeNetwork(name, measurement, '%s.tx'%measuringLoc[1])
        inc = 0
        for joint in ikJoints:
            
            if inc < ikJoints[-1]:
                
                cmds.connectAttr('%s.outputR'%stretchOutput[0],'%s.sx'%joint)
                
            inc += 1
            
          
        #create elbow stretch
        for joint in ikJoints:
            
            if not joint == ikJoints[0]:
                
                pmaNode = cmds.createNode('plusMinusAverage', n = '%s_IKLength_PMA'%joint)
                translateVal = cmds.getAttr('%s.tx'%joint)
                cmds.setAttr('%s.input1D[0]'%pmaNode,translateVal)
                cmds.connectAttr('%s.length'%ikControl,'%s.input1D[1]'%pmaNode)
                cmds.connectAttr('%s.output1D'%pmaNode, '%s.tx'%joint)
                
        
        
        #connect control attrs
        cmds.connectAttr('%s.stretchy'%ikControl, '%s.blender'%stretchOutput[0])
        cmds.connectAttr('%s.noBend'%ikControl, '%s.firstTerm'%stretchOutput[1])
        cmds.connectAttr('%s.twist'%ikControl, '%s.twist'%ikHandle[0])
        
        ##create fk joint chain
        fkJoints = []
        inc = 1
        cmds.select(cl = True)
        for joint in ikJoints:
        
            prefferedAngle = [cmds.getAttr('%s.preferredAngleX'%joint),
                              cmds.getAttr('%s.preferredAngleY'%joint),
                              cmds.getAttr('%s.preferredAngleZ'%joint)]
        
            fkJoint = cmds.joint(n = '%s_FK_0%i_Jnt'%(name,inc))
            parentConstraint = cmds.parentConstraint(joint,fkJoint)
            cmds.delete(parentConstraint)
            cmds.makeIdentity(a = True)
            cmds.setAttr('%s.preferredAngleX'%fkJoint,prefferedAngle[0])
            cmds.setAttr('%s.preferredAngleY'%fkJoint,prefferedAngle[1])
            cmds.setAttr('%s.preferredAngleZ'%fkJoint,prefferedAngle[2])
            
            fkJoints.append(fkJoint)
            
            inc += 1
            
        #create FK Rig
        fkRig = SkeletalRigs.FKRig(name, fkJoints[0])
            
        #createConstraints
        ikfkReverseBlend = cmds.createNode('reverse',n = '%s_IKFK_Reverse'%name)
        cmds.connectAttr(blendAttr,'%s.inputX'%ikfkReverseBlend)
        inc = 0
        
        for joint in bindJoints:
            
            constraint = cmds.parentConstraint(ikJoints[inc],fkJoints[inc],joint)[0]
            
            cmds.connectAttr(blendAttr, '%s.%sW0'%(constraint,ikJoints[inc]))
            cmds.connectAttr('%s.outputX'%ikfkReverseBlend, '%s.%sW1'%(constraint,fkJoints[inc]))
            
            inc += 1
            

        #clean-up
        ikJointGroup = cmds.group(empty = True, name = '%s_IK_Jnt_Group'%name)
        ikCtrlGroup = cmds.group(empty = True, name = '%s_IK_Ctrl_Group'%name)
        
        cmds.parent(ikHandle[0],ikJointGroup)
        cmds.parent(poleVectorLocGroup,ikJointGroup)
        cmds.parent(measuringLoc[3],ikJointGroup)
        cmds.parent(ikJoints[0],ikJointGroup)
        
        jointGroup = cmds.group(empty = True, n = '%s_Jnt_Group'%name)
        cmds.parent(fkRig[2],jointGroup)
        cmds.parent(ikJointGroup,jointGroup)
        
        cmds.parent(ikControlGroup,ikCtrlGroup)
        cmds.parent(poleVectorCtrlGroup,ikCtrlGroup)
        
        ctrlGroup = cmds.group(empty = True, n = '%s_Ctrl_Group'%name)
        cmds.parent(fkRig[1],ctrlGroup)
        cmds.parent(ikCtrlGroup,ctrlGroup)
        
        cmds.select(cl = True)
        
        return ikControl,poleVectorCtrl,fkRig[1]