Ejemplo n.º 1
0
 def createWeigthListFromInfluence(mesh,transform):
     
     meshPath = GenAPI.getDagPath(mesh)
     transformPath = GenAPI.getDagPath(transform)
     
     transformFn = om.MFnTransform(transformPath)
     
     geoItr = om.MItGeometry(meshPath)
     
     weightList = []
     
     translateVector = om.MVector(1,0,0)
     
     while not geoItr.isDone():
         
         transformFn.set(om.MTransformationMatrix.identity)
         vertStartPos = geoItr.position(om.MSpace.kWorld)
         
         transformFn.translateBy(translateVector,om.MSpace.kWorld)
         vertEndPos = geoItr.position(om.MSpace.kWorld)
         
         length = MeasuringTool.getVectorLengthBetween(vertStartPos, vertEndPos)
         
         weightList.append(length)
         transformFn.set(om.MTransformationMatrix.identity)
         
         geoItr.next()
     
     return weightList
Ejemplo n.º 2
0
    def createWeightListFromMesh(fromMesh,toMesh):
        
        fromMeshPath = GenAPI.getDagPath(fromMesh)
        toMeshPath = GenAPI.getDagPath(toMesh)
        
        fromVertItr = om.MItMeshVertex(fromMeshPath)
        toVertItr = om.MItMeshVertex(toMeshPath)
        util = om.MScriptUtil()
        intPtr = util.asIntPtr()
        
        weightList = []

        progressWin = UILib.ProgressWin()
        progressWin.itr = fromVertItr.count()
        
        while not fromVertItr.isDone():
            
            
            toVertItr.setIndex(fromVertItr.index(),intPtr)
            
            currentFromVertPoint = fromVertItr.position()
            currentToVertPoint = toVertItr.position()
            
            length = MeasuringTool.getVectorLengthBetween(currentFromVertPoint, currentToVertPoint)
            weight = max(min(length, 1), 0)
            weightList.append(weight)
            
            progressWin.message = '%s.vtx[%i]'%(fromMesh, fromVertItr.index())
            progressWin.inc = fromVertItr.index()
            progressWin.progress()
            
            fromVertItr.next()
        
        progressWin.end()
        return weightList
Ejemplo n.º 3
0
 def createWeigthListFromTransform(mesh,transform):
     
     meshPath = GenAPI.getDagPath(mesh)
     transformPath = GenAPI.getDagPath(transform)
     
     transformFn = om.MFnTransform(transformPath)
     origTransform = transformFn.transformation()
     transformFn.set(om.MTransformationMatrix.identity)
     
     geoItr = om.MItGeometry(meshPath)
     origPositions = om.MPointArray()
     geoItr.allPositions(origPositions,om.MSpace.kWorld)
        
     translateVector = om.MVector(1,0,0)
     transformFn.translateBy(translateVector,om.MSpace.kWorld)
     
     geoItr = om.MItGeometry(meshPath)
     deltaPositions = om.MPointArray()
     geoItr.allPositions(deltaPositions,om.MSpace.kWorld)
     
     weightList = []
     for i in range(origPositions.length()):
         
         weight = MeasuringTool.getVectorLengthBetween(origPositions[i],deltaPositions[i])
         weightList.append(weight)
    
     transformFn.set(origTransform)
     return weightList
Ejemplo n.º 4
0
def skinclusterFromMesh(meshFrom,meshTo,joints):
    
    floatingJointList = []
    constraintList = []
    weightLists = []
    
    progressWin = UILib.ProgressWin()
    progressWin.setTitle('Mesh To Skincluster')
    
    
    cmds.select(cl = True)
    for joint in joints:
        
        transformFn = om.MFnTransform(GenAPI.getDagPath(joint))
        position = transformFn.getTranslation(om.MSpace.kWorld)
        
        floatingJoint = cmds.joint()
        floatingJointPath = GenAPI.getDagPath(floatingJoint)
        transformFn.setObject(floatingJointPath)
        transformFn.setTranslation(position,om.MSpace.kWorld)
        floatingJointList.append(floatingJoint)
        
        parentConstraint = cmds.parentConstraint(floatingJoint,joint,mo = True)
        constraintList.append(parentConstraint)
        cmds.select(cl = True)
        
    baseJoint = cmds.joint() 
    skincluster = cmds.skinCluster(meshTo,baseJoint)[0]
    skinningTool = SkinningTool(skincluster,meshTo)
    
    cmds.setAttr('%s.liw'%baseJoint, 0)
    
    progressWin.itr = len(joints)
    
    inc = 0
    
    for i in range(len(floatingJointList)):
        
        weightList = MeasuringLib.MeasuringTool.createWeigthListFromInfluence2(meshFrom, floatingJointList[i])
        cmds.skinCluster(skincluster,e = True , weight = 0,addInfluence = joints[i])
        weightLists.append(weightList)
        
        cmds.setAttr('%s.liw'%joints[i], 0)   
        skinningTool.setWeights(GenAPI.getDagPath(joints[i]), weightList)
        cmds.setAttr('%s.liw'%joints[i], 1)
        
        inc += 1
        progressWin.inc = inc
        progressWin.progress()
        
    for i in range(len(floatingJointList)):  
        cmds.delete(constraintList[i])
        cmds.delete(floatingJointList[i])
        
    progressWin.end()
    
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def getQuaternionRotation(dagObject,space = 'world'):
        
        mDagPath = GenAPI.getDagPath(dagObject)

        transformFn = om.MFnTransform(mDagPath)
        mSpace = om.MSpace()
        quatSpace = ''
        
        if(space == 'world'):
            quatSpace = mSpace.kWorld
            
        else:
            quatSpace = mSpace.kObject


        utilX = om.MScriptUtil()
        ptrX = utilX.asDoublePtr()

        utilY = om.MScriptUtil()
        ptrY = utilY.asDoublePtr()

        utilZ = om.MScriptUtil()
        ptrZ = utilZ.asDoublePtr()

        utilW = om.MScriptUtil()
        ptrW = utilW.asDoublePtr()

        transformFn.getRotationQuaternion(ptrX,ptrY,ptrZ,ptrW,quatSpace)

        quatX = utilX.getDouble(ptrX)
        quatY = utilY.getDouble(ptrY)
        quatZ = utilZ.getDouble(ptrZ)
        quatW = utilW.getDouble(ptrW)

        return [quatX,quatY,quatZ,quatW]
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
    def getTranslationVectors(self,fromMesh):
        
        '''
        method build an array of vectors for trnaslation
        input fromMesh (python string)
        '''
        
        fromMeshPath = GenAPI.getDagPath(fromMesh)
        geoItr = om.MItGeometry(fromMeshPath)
        pointArrayA = om.MPointArray()
        geoItr.allPositions(pointArrayA, om.MSpace.kWorld)
        
        pointArrayB = self.getPointArray()

        if pointArrayA.length() == pointArrayB.length():
 
            outVectorArray = om.MVectorArray()
            itr = 0
             
            while itr <= pointArrayA.length():
                 
                vectorA = pointArrayA[itr]
                vectorB = pointArrayB[itr]
                vectorC = vectorA - vectorB
    
                outVectorArray.append(vectorC)
                itr += 1
                
        return  outVectorArray
Ejemplo n.º 12
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()   
Ejemplo n.º 13
0
    def getTranslationVectors(self, fromMesh):
        '''
    method build an array of vectors for translation
    input fromMesh (python string)
    '''
        fromMeshPath = GenAPI.getDagPath(fromMesh)
        geoItr = om.MItGeometry(fromMeshPath)
        pointArrayA = om.MPointArray()
        geoItr.allPositions(pointArrayA, om.MSpace.kObject)

        if cmds.nodeType(self.baseMesh) == 'transform':
            shape = cmds.listRelatives(shape, type='shape')[0]
        else:
            shape = self.baseMesh

        pointArrayB = ShapeTool.getPointArray(self.baseMesh)

        if pointArrayA.length() == pointArrayB.length():
            outVectorArray = om.MVectorArray()
            itr = 0
            while itr <= pointArrayA.length():
                vectorA = pointArrayA[itr]
                vectorB = pointArrayB[itr]
                vectorC = vectorA - vectorB
                outVectorArray.append(vectorC)
                itr += 1
        return outVectorArray
Ejemplo n.º 14
0
def loadClusters(clusterDicts):

    for clusterDict in clusterDicts:

        clusterHandleName = clusterDict.get('clusterHandle')
        clusterName = clusterDict.get('clusterName')
        pos = clusterDict.get('pos')
        dagMembers = clusterDict.get('dagMembers')

        selectionList = om.MSelectionList()

        for member in dagMembers:

            meshPath = GenAPI.getDagPath(member)
            verts = GenAPI.getMObjectAllVerts(member)
            selectionList.add(meshPath, verts)

        om.MGlobal.setActiveSelectionList(selectionList)

        #creating cluster
        cluster = cmds.cluster()
        clusterShape = cmds.listRelatives(cluster[1], type='shape')

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

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

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

        inc = 0

        progressWin = UILib.ProgressWin()
        progressWin.itr = len(dagMembers)
        progressWin.setTitle('Loading Clusters')

        for member in dagMembers:

            deformerTool = WeightListTool(member, cluster[0])
            weightList = clusterDict.get('weightList')[inc]
            membershipList = clusterDict.get('membershipList')[inc]
            deformerTool.setMembershipList(membershipList)
            deformerTool.setWeightList(weightList)
            inc += 1

            progressWin.message = member
            progressWin.inc = inc
            progressWin.progress()

        cmds.rename(cluster[0], clusterName)
        cmds.rename(cluster[1], clusterHandleName)

        progressWin.end()
        om.MGlobal.displayInfo('Successfully loaded clusters.')
Ejemplo n.º 15
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))
Ejemplo n.º 16
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))
Ejemplo n.º 17
0
 def getMPoint(dagObject):
 
     mDagPath = GenAPI.getDagPath(dagObject)
     
     transformFn = om.MFnTransform(mDagPath)
     space = om.MSpace()
     
     mpoint = transformFn.rotatePivot(space.kWorld)
     return mpoint       
Ejemplo n.º 18
0
 def __init__(self,shape):
     
     self.shape = shape
     self.shapePath = GenAPI.getDagPath(shape)
     
     geoItr = om.MItGeometry(self.shapePath)
     pointArray = om.MPointArray()
     geoItr.allPositions(pointArray, om.MSpace.kWorld)
     
     self.origPointArray = pointArray
Ejemplo n.º 19
0
 def setTranslation(mesh,vectorArray):
     
     meshPath = GenAPI.getDagPath(mesh)
     
     vertItr = om.MItMeshVertex(meshPath)
     
     while not vertItr.isDone():
         
         index = vertItr.index()
         vertItr.translateBy(vectorArray[index],om.MSpace.kWorld)
         vertItr.next()
Ejemplo n.º 20
0
    def createWeigthListFromInfluence2(mesh,transform):
        
        meshPath = GenAPI.getDagPath(mesh)
        transformPath = GenAPI.getDagPath(transform)
        
        transformFn = om.MFnTransform(transformPath)
        origTransform = transformFn.transformation()
        transformFn.set(om.MTransformationMatrix.identity)
        
        vertItr = om.MItMeshVertex(meshPath)
        
        startPoints = []
        
        translateVector = om.MVector(1,0,0)
        
        while not vertItr.isDone():
            
            vertStartPos = vertItr.position(om.MSpace.kWorld)
            startPoints.append(vertStartPos)
            vertItr.next()
        
        vertItr.reset()     
        transformFn.translateBy(translateVector,om.MSpace.kObject)
        
        weightList = []
        index = 0
        

        while not vertItr.isDone():
            
            vertEndPos = vertItr.position(om.MSpace.kWorld)
            length = MeasuringTool.getVectorLengthBetween(startPoints[index], vertEndPos)
            
            weightList.append(length)
        
            index += 1
            vertItr.next()
        
        transformFn.set(origTransform)

        return weightList
Ejemplo n.º 21
0
 def getWeights(self,verts,influence):
     
     '''
     get influence value
     input MObject (verts)
     input MDagPath (influence)
     returns MDoubleArray (weights)
     '''
     
     index = self.indexForInfluenceObject(influence)
     weights = om.MDoubleArray()
     self.skinclusterFn.getWeights(GenAPI.getDagPath(self.shape),verts,index,weights)
     return weights
Ejemplo n.º 22
0
    def matchSpace(dagObject,name):
    
        translation = MeasuringTool.getWorldTranslation(dagObject)
        rotation = MeasuringTool.getWorldEulerRotation(dagObject)
        rotationOrder = MeasuringTool.getRotationOrder(dagObject)

        newTransform = cmds.group(empty = True, n = '%s_Group'%(name))
        dagPath = GenAPI.getDagPath(newTransform)
        transformFn = om.MFnTransform(dagPath)

        transformFn.setTranslation(translation,om.MSpace.kWorld)
        transformFn.setRotation(rotation,rotationOrder)
        transformFn.setRotationOrder(rotationOrder,1)
Ejemplo n.º 23
0
def getLatticePointPos(latticeShape):
    
    dagPath = GenAPI.getDagPath(latticeShape)
    geoItr = om.MItGeometry(dagPath)
    
    latPointPos = []
    
    while not geoItr.isDone():
        
        position = geoItr.position(om.MSpace.kWorld)
        latPointPos.append([position.x,position.y,position.z])
        geoItr.next()
        
    return latPointPos
Ejemplo n.º 24
0
 def getComponentPoints(mesh):
     
     meshPath = GenAPI.getDagPath(mesh)
     vertItr = om.MItMeshVertex(meshPath)
     
     pointArray = []
     
     while not vertItr.isDone():
         
         point = vertItr.position(om.MSpace.kWorld)
         pointArray.append([point.x,point.y,point.z])
         vertItr.next()
         
     return pointArray
Ejemplo n.º 25
0
 def mirrorDeformerWeightMultiMesh(self,geoTo,axis = 'x',table = [-1,1,1]):
     
     '''
     method for mirroring deformer...only works on meshes mirrored across given axis
     input python string (geoFrom)
     imput python string (geoTo)
     input python string (deformer)
     input python string (axis)
     input python int list (table)
     '''
     
     nodePathTo = GenAPI.getDagPath(geoTo)
     vertItr = om.MItMeshVertex(self.meshPath)
     
     deformerWeightFn = oma.MFnWeightGeometryFilter(self.deformerObject)
     
     util = om.MScriptUtil()
     
     progressWin = UILib.ProgressWin()
     progressWin.itr = vertItr.count()
     progressWin.setTitle('Mirror Deformer')
     
     while not vertItr.isDone():
         
         inComponent = vertItr.currentItem()
         currentPosition = vertItr.position(om.MSpace.kWorld)
         
         inComponent = vertItr.currentItem()
         mirrorVert = MeasuringLib.MeasuringTool.getSymVertFromClosestPoint(nodePathTo, currentPosition, table)     
         weights = om.MFloatArray()
         
         tempItr = om.MItMeshVertex(nodePathTo)
         intPtr = util.asIntPtr()
         tempItr.setIndex(mirrorVert[0],intPtr)
         outComponent = tempItr.currentItem()
         
         if self.checkMembership(inComponent):
             
             self.addComponentToMembershipList(outComponent)
         
         deformerWeightFn.getWeights(self.meshPath,inComponent,weights)
         deformerWeightFn.setWeight(nodePathTo,outComponent,weights)
         
         progressWin.inc = vertItr.index()
         progressWin.message = '%s.vtx[%i]'%(self.mesh,progressWin.inc)
         progressWin.progress() 
 
         vertItr.next()
         
     progressWin.end()
Ejemplo n.º 26
0
    def mirrorDeformerWeightMultiMesh(self, geoTo, axis='x', table=[-1, 1, 1]):
        '''
        method for mirroring deformer...only works on meshes mirrored across given axis
        input python string (geoFrom)
        imput python string (geoTo)
        input python string (deformer)
        input python string (axis)
        input python int list (table)
        '''

        nodePathTo = GenAPI.getDagPath(geoTo)
        vertItr = om.MItMeshVertex(self.meshPath)

        deformerWeightFn = oma.MFnWeightGeometryFilter(self.deformerObject)

        util = om.MScriptUtil()

        progressWin = UILib.ProgressWin()
        progressWin.itr = vertItr.count()
        progressWin.setTitle('Mirror Deformer')

        while not vertItr.isDone():

            inComponent = vertItr.currentItem()
            currentPosition = vertItr.position(om.MSpace.kWorld)

            inComponent = vertItr.currentItem()
            mirrorVert = MeasuringLib.MeasuringTool.getSymVertFromClosestPoint(
                nodePathTo, currentPosition, table)
            weights = om.MFloatArray()

            tempItr = om.MItMeshVertex(nodePathTo)
            intPtr = util.asIntPtr()
            tempItr.setIndex(mirrorVert[0], intPtr)
            outComponent = tempItr.currentItem()

            if self.checkMembership(inComponent):

                self.addComponentToMembershipList(outComponent)

            deformerWeightFn.getWeights(self.meshPath, inComponent, weights)
            deformerWeightFn.setWeight(nodePathTo, outComponent, weights)

            progressWin.inc = vertItr.index()
            progressWin.message = '%s.vtx[%i]' % (self.mesh, progressWin.inc)
            progressWin.progress()

            vertItr.next()

        progressWin.end()
Ejemplo n.º 27
0
def getLatticePointPos(latticeShape):

    dagPath = GenAPI.getDagPath(latticeShape)
    geoItr = om.MItGeometry(dagPath)

    latPointPos = []

    while not geoItr.isDone():

        position = geoItr.position(om.MSpace.kWorld)
        latPointPos.append([position.x, position.y, position.z])
        geoItr.next()

    return latPointPos
Ejemplo n.º 28
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)
Ejemplo n.º 29
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)
Ejemplo n.º 30
0
    def getPointArray(shape):
        '''
      method gathers point array from verts
      output pointArray(mPointArray)
      '''
        if cmds.nodeType(shape) == 'transform':
            shape = cmds.listRelatives(shape, type='shape')[0]

        geoPath = GenAPI.getDagPath(shape)
        geoItr = om.MItGeometry(geoPath)
        pointArray = om.MPointArray()

        geoItr.allPositions(pointArray, om.MSpace.kObject)

        return pointArray
Ejemplo n.º 31
0
def setLatticePointPos(latticeShape,positions):
    
    dagPath = GenAPI.getDagPath(latticeShape)
    geoItr = om.MItGeometry(dagPath)
    
    latPointPos = []
    
    while not geoItr.isDone():
        
        index = geoItr.index()
        position = positions[index]
        mpoint = om.MPoint(position[0],position[1],position[2])
        geoItr.setPosition(mpoint,om.MSpace.kWorld)
        
        geoItr.next()      
Ejemplo n.º 32
0
def setLatticePointPos(latticeShape, positions):

    dagPath = GenAPI.getDagPath(latticeShape)
    geoItr = om.MItGeometry(dagPath)

    latPointPos = []

    while not geoItr.isDone():

        index = geoItr.index()
        position = positions[index]
        mpoint = om.MPoint(position[0], position[1], position[2])
        geoItr.setPosition(mpoint, om.MSpace.kWorld)

        geoItr.next()
Ejemplo n.º 33
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()
Ejemplo n.º 34
0
    def createBlankList(mesh, floatVal, boolVal):
        '''
        method for creating a blank weight and membershipList
        output blankList (python list)
        '''

        meshPath = GenAPI.getDagPath(mesh)
        vertItr = om.MItMeshVertex(meshPath)
        blankWeightList = []
        blankMemberList = []

        while not vertItr.isDone():

            blankWeightList.append(floatVal)
            blankMemberList.append(boolVal)
            vertItr.next()

        return [blankWeightList, blankMemberList]
Ejemplo n.º 35
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)
Ejemplo n.º 36
0
 def createBlankList(mesh,floatVal,boolVal):
     
     '''
     method for creating a blank weight and membershipList
     output blankList (python list)
     '''
     
     meshPath = GenAPI.getDagPath(mesh)
     vertItr = om.MItMeshVertex(meshPath)
     blankWeightList = []
     blankMemberList = []
     
     while not vertItr.isDone():
     
         blankWeightList.append(floatVal)
         blankMemberList.append(boolVal)
         vertItr.next()
         
     return [blankWeightList,blankMemberList]
Ejemplo n.º 37
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)
Ejemplo n.º 38
0
    def getVertNormal(geo,vert,name):

        #find dag path
        polyPath = GenAPI.getDagPath(geo)
        vertexObject = GenAPI.getComponentsFromList(geo,[vert])

        #create vector instance for vert iterator
        vertNormalVector = om.MVector()

        vertIterator = om.MItMeshVertex(polyPath,vertexObject)
        
        #MIntArray for face indexes
        faceIndexArray = om.MIntArray()
        vertIterator.getNormalIndices(faceIndexArray)

        faceIndexList = []

        for i in faceIndexArray:
            faceIndexList.append(i)

        #store normal vector in MVector instance
        vertIterator.getNormal(vertNormalVector,faceIndexList[0],om.MSpace.kObject)
        vertPos = vertIterator.position(om.MSpace.kWorld)

        #create new vectors form queries
        v1 = om.MVector(vertNormalVector.x,vertNormalVector.y,vertNormalVector.z)
        v2 = om.MVector(vertPos.x,vertPos.y,vertPos.z)
        #add vector1 to vector2 for offset
        v3 = v1 + v2

        #create locators
        vertLoc = cmds.spaceLocator(n = '%s_VertPos_Loc'%(name))
        normalVectorLoc = cmds.spaceLocator(n = '%s_VertNormalVec_Loc'%(name))
        tempLoc = cmds.spaceLocator()

        #move locators into position
        cmds.move(v1.x,v1.y,v1.z,tempLoc[0],ws = True)
        cmds.move(v2.x,v2.y,v2.z,vertLoc[0],ws = True)
        cmds.move(v3.x,v3.y,v3.z,normalVectorLoc[0],ws = True)

        #aim locator2 at locator1
        cmds.aimConstraint(normalVectorLoc,vertLoc, aimVector = (1,0,0), upVector = (0,1,0))
Ejemplo n.º 39
0
def clusterWeightToJoints(geo,cluster,jointFrom,jointTo):
    
    weightTool = DeformerLib.WeightListTool(geo,cluster)
    weightList = weightTool.getWeightList()
    print weightList
    
    skincluster = SkinningTool.getSkinCluster(geo)[1]
    print skincluster
    
    skinningTool = SkinningTool(skincluster,geo)
    influences = skinningTool.getInfluencesFromSkincluster()
    
    
    for i in range(influences.length()):
        cmds.setAttr('%s.liw'%influences[i].fullPathName(), 1)
        
    cmds.setAttr('%s.liw'%jointFrom, 0)
    cmds.setAttr('%s.liw'%jointTo, 0)
    
    skinningTool.setWeights(GenAPI.getDagPath(jointTo), weightList)
    print jointFrom,jointTo
Ejemplo n.º 40
0
def createClusterFromMesh(fromMesh,toMesh):
    
    '''
    Function for creating cluster from another duplicate modified mesh
    input fromMesh (python string)
    input toMesh (python string)
    '''
    
    
    toMeshPath = GenAPI.getDagPath(toMesh)
    
    fromVerts = GenAPI.getMObjectAllVerts(toMesh)
    selectionList = om.MSelectionList()
    
    selectionList.add(toMeshPath,fromVerts)
    om.MGlobal.setActiveSelectionList(selectionList)
    
    #creating cluster   
    cluster = cmds.cluster()
    transformPosition = cmds.xform(fromMesh,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])
    
    weightList = MeasuringLib.MeasuringTool.createWeightListFromMesh(fromMesh, toMesh)
    deformerTool = WeightListTool(toMesh,cluster[0])
    deformerTool.setWeightList(weightList)
    
    om.MGlobal.displayInfo('Created cluster from %s'%fromMesh)
Ejemplo n.º 41
0
def createClusterFromMesh(fromMesh, toMesh):
    '''
    Function for creating cluster from another duplicate modified mesh
    input fromMesh (python string)
    input toMesh (python string)
    '''

    toMeshPath = GenAPI.getDagPath(toMesh)

    fromVerts = GenAPI.getMObjectAllVerts(toMesh)
    selectionList = om.MSelectionList()

    selectionList.add(toMeshPath, fromVerts)
    om.MGlobal.setActiveSelectionList(selectionList)

    #creating cluster
    cluster = cmds.cluster()
    transformPosition = cmds.xform(fromMesh, 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])

    weightList = MeasuringLib.MeasuringTool.createWeightListFromMesh(
        fromMesh, toMesh)
    deformerTool = WeightListTool(toMesh, cluster[0])
    deformerTool.setWeightList(weightList)

    om.MGlobal.displayInfo('Created cluster from %s' % fromMesh)
Ejemplo n.º 42
0
def loadClusters(clusterDicts):
    
    
    for clusterDict in clusterDicts:
        
        clusterHandleName = clusterDict.get('clusterHandle')
        clusterName = clusterDict.get('clusterName')
        pos = clusterDict.get('pos')
        dagMembers = clusterDict.get('dagMembers')
       
        selectionList = om.MSelectionList()
        
        for member in dagMembers:
            try:
                meshPath = GenAPI.getDagPath(member)
                verts = GenAPI.getMObjectAllVerts(member)
                selectionList.add(meshPath,verts)
            except:
                pass
        
        om.MGlobal.setActiveSelectionList(selectionList)
        
        #creating cluster    
        cluster = cmds.cluster()
        clusterShape = cmds.listRelatives(cluster[1],type = 'shape')
        
        cmds.setAttr('%s.originX'%clusterShape[0],pos[0])
        cmds.setAttr('%s.originY'%clusterShape[0],pos[1])
        cmds.setAttr('%s.originZ'%clusterShape[0],pos[2])
        
        cmds.setAttr('%s.rotatePivotX'%cluster[1],pos[0])
        cmds.setAttr('%s.rotatePivotY'%cluster[1],pos[1])
        cmds.setAttr('%s.rotatePivotZ'%cluster[1],pos[2])
        
        cmds.setAttr('%s.scalePivotX'%cluster[1],pos[0])
        cmds.setAttr('%s.scalePivotY'%cluster[1],pos[1])
        cmds.setAttr('%s.scalePivotZ'%cluster[1],pos[2])
        
        inc = 0
        
        progressWin = UILib.ProgressWin()
        progressWin.itr = len(dagMembers)
        progressWin.setTitle('Loading Clusters')
        
        for member in dagMembers:
            
            try:
                deformerTool = WeightListTool(member,cluster[0])
                weightList = clusterDict.get('weightList')[inc]
                membershipList = clusterDict.get('membershipList')[inc]
                deformerTool.setMembershipList(membershipList)
                deformerTool.setWeightList(weightList)
                inc += 1
                
                progressWin.message = member
                progressWin.inc = inc
                progressWin.progress()
                
            except:
                pass
                
        
        cmds.rename(cluster[0],clusterName)
        cmds.rename(cluster[1],clusterHandleName)
            
        progressWin.end()
        om.MGlobal.displayInfo('Successfully loaded clusters.')
            
        
    
        
            
            
        
        
Ejemplo n.º 43
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()
Ejemplo n.º 44
0
def extrapFromWire(wire):
    
    curveShapeConnection = cmds.connectionInfo('%s.deformedWire[0]'%wire, sfd = True)
    curveShape = curveShapeConnection.split('.')[0]
    
    dagMembers = DeformerLib.WeightListTool.getDagMembers(wire)
    
    curvePath = GenAPI.getDagPath(curveShape)
    
    progressWin = UILib.ProgressWin()
    progressWin.setTitle('Extrap Skincluster from Wire')
    progressWin.itr = 5
    
    progressWin.inc = 1
    progressWin.progress()
    #creating clusters
    
    cvSelection = om.MSelectionList()
    
    cvItr = om.MItCurveCV(curvePath)
    
    clusters = []
    
    while not cvItr.isDone():
        
        cvSelection.clear()
        
        currentCV = cvItr.currentItem()
        
        cvSelection.add(curvePath,currentCV)
        om.MGlobal.setActiveSelectionList(cvSelection)
        
        cluster = cmds.cluster()
        clusters.append(cluster)
        
        cvItr.next()
    
    progressWin.inc = 2
    progressWin.message = 'extraping...'
    progressWin.progress()  
    #getting weights from clusters
    
    allWeightLists = []
    
    for mesh in dagMembers:
        
        influenceWeightLists = []
        
        for cluster in clusters:
            
            currentWeightList = MeasuringLib.MeasuringTool.createWeigthListFromTransform(mesh, cluster[1])
            influenceWeightLists.append(currentWeightList)
            
        allWeightLists.append(influenceWeightLists)
    
    #delete clusters
    for cluster in clusters:
        cmds.delete(cluster[0])
    
    progressWin.inc = 3
    progressWin.progress()
    #create joints    
    
    cmds.select(cl = True)
    
    joints = []
    
    cvItr.reset(curvePath)
    
    while not cvItr.isDone():
        
        cmds.select(cl = True)
        
        position = cvItr.position(om.MSpace.kWorld)
        
        currentJoint = cmds.joint()
        cmds.move(position.x,position.y,position.z,currentJoint)
        joints.append(currentJoint)
        
        cvItr.next()
    
    cmds.select(cl = True)
        
    baseJoint = cmds.joint()
    
    progressWin.inc = 4
    progressWin.progress()
    #create group for bind joints
    
    jointGroup = cmds.group(empty = True)
    cmds.parent(baseJoint,jointGroup)
    
    for joint in joints:
        
        cmds.parent(joint,jointGroup)
    
    progressWin.inc = 5
    progressWin.message = 'setting weights'
    progressWin.progress()   
    #smooth bind
    
    
    inc = 0
    for mesh in dagMembers:
        
        progressWin = UILib.ProgressWin()
        progressWin.setTitle('Setting Weights for %s'%mesh)
        progressWin.itr = len(joints)

    
        skincluster = cmds.skinCluster(mesh,baseJoint)[0]
        skinningTool = SkinningTool(skincluster,mesh)
        
        cmds.setAttr('%s.liw'%baseJoint, 0)
        
        for i in range(len(joints)):
            
            cmds.skinCluster(skincluster,e = True , weight = 0,addInfluence = joints[i])
            cmds.setAttr('%s.liw'%joints[i], 0)
            
            skinningTool.setWeights(GenAPI.getDagPath(joints[i]), allWeightLists[inc][i])
            
            cmds.setAttr('%s.liw'%joints[i], 1)
            
            progressWin.inc = i
            progressWin.progress()
            
        inc += 1
        progressWin.end()
Ejemplo n.º 45
0
def build(**kwargs):

    curve = kwargs.get('curve')
    locatorCount = kwargs.get('locatorCount', 2)
    wheelCrv = kwargs.get('wheelCrv')
    name = kwargs.get('name', 'Path')
    frontAxis = kwargs.get('frontAxis', 0)
    reverseFrontAxis = kwargs.get('reverseFrontAxis', False)
    upAxis = kwargs.get('upAxis', 1)
    reverseUpAxis = kwargs.get('reverseUpAxis', False)
    upVector = kwargs.get('upVector', [0, 1, 0])
    controlScale = kwargs.get('controlScale', 15)

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

    curveInfo = cmds.createNode('curveInfo', name='%s_CI' % name)
    cmds.connectAttr('%s.worldSpace[0]' % curveShape,
                     '%s.inputCurve' % curveInfo)

    driveCtrl = cmds.circle(name='Drive_Ctrl')[0]
    driveCtrlGrp = cmds.group(empty=True, name='Drive_Ctrl_Grp')
    cmds.parent(driveCtrl, driveCtrlGrp)

    cmds.addAttr('Drive_Ctrl', ln="FKCtrlVis", at='bool')
    cmds.setAttr('Drive_Ctrl.FKCtrlVis', e=True, cb=True)

    cmds.addAttr('Drive_Ctrl', ln="IKCtrlVis", at='bool')
    cmds.setAttr('Drive_Ctrl.IKCtrlVis', e=True, cb=True)

    locGrp = cmds.group(empty=True, name='%s_Loc_Grp' % name)
    upLocator = cmds.spaceLocator(name='%s_Up_Loc' % name)[0]
    cmds.move(upVector[0], upVector[1], upVector[2], upLocator)
    cmds.parent(upLocator, locGrp)

    for i in range(locatorCount):

        zeroString = '0'
        if i > 9:
            zeroString = ''

        cmds.addAttr(driveCtrl, ln='drive%i' % (i + 1), at='double', min=0)
        cmds.setAttr('%s.drive%i' % (driveCtrl, i + 1), e=True, keyable=True)

        cmds.addAttr(driveCtrl, ln='initOffset%i' % (i + 1), at='double')
        cmds.setAttr('%s.initOffset%i' % (driveCtrl, i + 1),
                     e=True,
                     keyable=True)

        cmds.addAttr(driveCtrl, ln='offset%i' % (i + 1), at='double')
        cmds.setAttr('%s.offset%i' % (driveCtrl, i + 1), e=True, keyable=True)

        addOffsetPMA = cmds.createNode('plusMinusAverage',
                                       name='%s_InitOffset_%s%i_PMA' %
                                       (name, zeroString, i + 1))
        cmds.connectAttr('%s.initOffset%i' % (driveCtrl, i + 1),
                         '%s.input1D[0]' % addOffsetPMA)
        cmds.connectAttr('%s.offset%i' % (driveCtrl, i + 1),
                         '%s.input1D[1]' % addOffsetPMA)

        moPathLoc = cmds.spaceLocator(name='%s_POC_%s%i_Loc' %
                                      (name, zeroString, i + 1))[0]
        motionPathNode = cmds.createNode('motionPath',
                                         name='%s_%s%i_MoPath' %
                                         (name, zeroString, i + 1))
        cmds.connectAttr('%s.worldSpace[0]' % curveShape,
                         '%s.geometryPath' % motionPathNode)
        cmds.setAttr('%s.worldUpType' % motionPathNode, 1)
        cmds.connectAttr('%s.worldMatrix[0]' % upLocator,
                         '%s.worldUpMatrix' % motionPathNode)

        cmds.connectAttr('%s.allCoordinates' % motionPathNode,
                         '%s.translate' % moPathLoc)
        cmds.connectAttr('%s.rotate' % motionPathNode, '%s.rotate' % moPathLoc)

        offsetPMA = cmds.createNode('plusMinusAverage',
                                    name='%s_offset_%s%i_PMA' %
                                    (name, zeroString, i + 1))
        cmds.connectAttr('%s.drive%i' % (driveCtrl, i + 1),
                         '%s.input1D[0]' % offsetPMA)
        cmds.connectAttr('%s.output1D' % addOffsetPMA,
                         '%s.input1D[1]' % offsetPMA)

        dampMD = cmds.createNode('multiplyDivide',
                                 name='%s_Damp_%s%i_MD' %
                                 (name, zeroString, i + 1))
        cmds.connectAttr('%s.output1D' % offsetPMA, '%s.input1X' % dampMD)

        cmds.connectAttr('%s.outputX' % dampMD, '%s.uValue' % motionPathNode)

        cmds.setAttr('%s.frontAxis' % motionPathNode, frontAxis)
        cmds.setAttr('%s.upAxis' % motionPathNode, upAxis)
        cmds.setAttr('%s.inverseFront' % motionPathNode, reverseFrontAxis)
        cmds.setAttr('%s.inverseUp' % motionPathNode, reverseUpAxis)
        cmds.parent(moPathLoc, locGrp)

    for i in range(len(wheelCrv)):

        zeroString = '0'
        if i > 9:
            zeroString = ''

        wheelCrvInfo = cmds.createNode('curveInfo',
                                       name='%s_Wheel_%s%i_CI' %
                                       (name, zeroString, i + 1))
        cmds.connectAttr('%s.worldSpace[0]' % wheelCrv[i],
                         '%s.inputCurve' % wheelCrvInfo)

        divideCircum = cmds.createNode('multiplyDivide',
                                       name='%s_Circum_%s%i_MD' %
                                       (name, zeroString, i + 1))
        cmds.setAttr('%s.operation' % divideCircum, 2)
        cmds.connectAttr('%s.arcLength' % wheelCrvInfo,
                         '%s.input1X' % divideCircum)
        cmds.connectAttr('%s.arcLength' % curveInfo,
                         '%s.input2X' % divideCircum)

        cmds.addAttr(driveCtrl, ln='rotateMultiply%i' % (i + 1), at='double')
        cmds.setAttr('%s.rotateMultiply%i' % (driveCtrl, i + 1),
                     e=True,
                     keyable=True)

        circumMult = cmds.createNode('multiplyDivide',
                                     name='%s_RotateMult_%s%i_MD' %
                                     (name, zeroString, i + 1))
        cmds.connectAttr('%s.outputX' % divideCircum,
                         '%s.input1X' % circumMult)
        cmds.connectAttr('%s.rotateMultiply%i' % (driveCtrl, i + 1),
                         '%s.input2X' % circumMult)

        cmds.addAttr(driveCtrl, ln='outRotate%i' % (i + 1), at='double')
        cmds.setAttr('%s.rotateMultiply%i' % (driveCtrl, i + 1),
                     e=True,
                     keyable=True)

    defJointGrp = cmds.group(empty=True, name='%s_Def_Jnt_Grp' % name)

    cmds.select(cl=True)
    baseJoint = cmds.joint(name='%s_Def_Main_Jnt' % name)
    cmds.parent(baseJoint, defJointGrp)
    skincluster = cmds.skinCluster(curve, baseJoint)[0]
    cmds.setAttr('%s.liw' % baseJoint, 0)

    curveItr = om.MItCurveCV(GenAPI.getDagPath(curve))

    cmds.select(cl=True)

    defJoints = []
    fkCtrls = []
    fkCtrlGrps = []

    allIKCtrlGrp = cmds.group(empty=True, name='%s_IK_Ctrl_Grp' % name)
    allFKCtrlGrp = cmds.group(empty=True, name='%s_FK_Ctrl_Grp' % name)

    i = 1
    while not curveItr.isDone():

        zeroString = '0'
        if i > 9:
            zeroString = ''

        cv = curveItr.index()

        ikCtrlGrp = cmds.group(empty=True,
                               name='%s_IK_%s%i_Ctrl_Grp' %
                               (name, zeroString, i))
        ikCtrl = cmds.circle(name='%s_IK_%s%i_Ctrl' % (name, zeroString, i),
                             r=(5 * controlScale))[0]
        cmds.parent(ikCtrl, ikCtrlGrp)
        cmds.parent(ikCtrlGrp, allIKCtrlGrp)

        fkCtrlGrp = cmds.group(empty=True,
                               name='%s_FK_%s%i_Ctrl_Grp' %
                               (name, zeroString, i))
        fkCtrl = cmds.circle(name='%s_FK_%s%i_Ctrl' % (name, zeroString, i),
                             r=(10 * controlScale))[0]
        cmds.parent(fkCtrl, fkCtrlGrp)
        cmds.parent(fkCtrlGrp, allFKCtrlGrp)
        fkCtrls.append(fkCtrl)
        fkCtrlGrps.append(fkCtrlGrp)

        cmds.connectAttr('Drive_Ctrl.FKCtrlVis', '%s.visibility' % fkCtrlGrp)
        cmds.connectAttr('Drive_Ctrl.IKCtrlVis', '%s.visibility' % ikCtrlGrp)

        cmds.setAttr('%s.overrideEnabled' % ikCtrl, True)
        cmds.setAttr('%s.overrideColor' % ikCtrl, 13)

        cmds.setAttr('%s.overrideEnabled' % fkCtrl, True)
        cmds.setAttr('%s.overrideColor' % fkCtrl, 6)

        cmds.parentConstraint(fkCtrl, ikCtrlGrp, mo=True)

        cmds.select(cl=True)

        joint = cmds.joint(name='%s_Def_%s%i_Jnt' % (name, zeroString, i),
                           radius=200)
        cmds.parent(joint, defJointGrp)
        cmds.parentConstraint(ikCtrl, joint, mo=True)

        cmds.select(cl=True)
        pointPos = curveItr.position(om.MSpace.kWorld)
        cmds.move(pointPos.x, pointPos.y, pointPos.z, joint, ws=True)

        cmds.move(pointPos.x, pointPos.y, pointPos.z, ikCtrlGrp, ws=True)
        cmds.move(pointPos.x, pointPos.y, pointPos.z, fkCtrlGrp, ws=True)

        cmds.skinCluster(skincluster, e=True, weight=0, addInfluence=joint)
        defJoints.append(joint)

        i += 1
        curveItr.next()

    for joint in defJoints:
        cmds.setAttr('%s.liw' % joint, 0)

    for i in range(len(defJoints)):
        cmds.skinPercent(skincluster,
                         '%s.cv[%i]' % (curve, i),
                         transformValue=[(defJoints[i], 1)])

    for i in range(len(fkCtrls)):
        try:
            cmds.parentConstraint(fkCtrls[i], fkCtrlGrps[i + 1], mo=True)
        except:
            pass
Ejemplo n.º 46
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)
Ejemplo n.º 47
0
def mirrorCluster(transform,deformerName,prefix = 'L',oppPrefix = 'R', axis = 'x',direction = '<', table = [-1,1,1]):
    
    vertSelection = om.MSelectionList()
    
    dagList = WeightListTool.sortDagMembers(deformerName,prefix,oppPrefix)
    singles = dagList[0]
    doubles = dagList[1]
    members = WeightListTool.getDagMembers(deformerName)
    
            
    for mesh in singles:
        
        meshPath = GenAPI.getDagPath(mesh)
        verts = GenAPI.getMObjectAllVerts(mesh)
        vertSelection.add(meshPath,verts)
        
    for meshGroup in doubles:
        
        for mesh in meshGroup: 
            
            if not mesh in members:
                blankWeightList = WeightListTool.createBlankList(mesh, 0, True)
                weightTool = WeightListTool(mesh,deformerName)
                weightTool.setMembershipList(blankWeightList[1])
                weightTool.setWeightList(blankWeightList[0])
            
            meshPath = GenAPI.getDagPath(mesh)
            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)
    mirrorPosition = [transformPosition[0] * table[0],transformPosition[1] * table[1],transformPosition[2] * table[2]]
    
    clusterShape = cmds.listRelatives(cluster[1],type = 'shape')
    
    cmds.setAttr('%s.originX'%clusterShape[0],mirrorPosition[0])
    cmds.setAttr('%s.originY'%clusterShape[0],mirrorPosition[1])
    cmds.setAttr('%s.originZ'%clusterShape[0],mirrorPosition[2])
    
    cmds.setAttr('%s.rotatePivotX'%cluster[1],mirrorPosition[0])
    cmds.setAttr('%s.rotatePivotY'%cluster[1],mirrorPosition[1])
    cmds.setAttr('%s.rotatePivotZ'%cluster[1],mirrorPosition[2])
    
    cmds.setAttr('%s.scalePivotX'%cluster[1],mirrorPosition[0])
    cmds.setAttr('%s.scalePivotY'%cluster[1],mirrorPosition[1])
    cmds.setAttr('%s.scalePivotZ'%cluster[1],mirrorPosition[2])
    
    for mesh in singles:
        
        weightTool = WeightListTool(mesh,deformerName)
        weightList = weightTool.mirrorWeightList(table = table,axis = axis, direction = direction)
        weightTool.__init__(mesh,cluster[0])
        
        print weightList
 
        weightTool.setWeightList(weightList[0])
        weightTool.setMembershipList(weightList[1])
        
    
    for meshGroup in doubles:
        
        
        weightListA = WeightListTool.mirrorWeightListMultiMesh(meshGroup[0], meshGroup[1], deformerName, table)
        weightListB = WeightListTool.mirrorWeightListMultiMesh(meshGroup[1], meshGroup[0], deformerName, table)
        
        deformerTool = WeightListTool(meshGroup[1],cluster[0])
        deformerTool.setMembershipList(weightListA[1])
        deformerTool.setWeightList(weightListA[0])
        
        deformerTool.__init__(meshGroup[0],cluster[0])
        deformerTool.setMembershipList(weightListB[1])
        deformerTool.setWeightList(weightListB[0])
        
    om.MGlobal.displayInfo('Created mirrored cluster from %s'%deformerName)
Ejemplo n.º 48
0
def createMoPathLoc(curve, name, upObject):
    curvePath = GenAPI.getDagPath(curve)
    curveItr = om.MItCurveCV(curvePath)
    curveFn = om.MFnNurbsCurve()

    shape = cmds.listRelatives(curve, type='shape')[0]
    curvePath = GenAPI.getDagPath(curve)
    curveItr = om.MItCurveCV(curvePath)
    curveFn = om.MFnNurbsCurve(curvePath)
    util = om.MScriptUtil()

    cmds.addAttr(curve, ln='upperTwist', at='double', keyable=True)
    cmds.addAttr(curve, ln='lowerTwist', at='double', keyable=True)

    locators = []

    while not curveItr.isDone():
        #getting param value
        pos = curveItr.position()
        ptr = util.asDoublePtr()
        curveFn.getParamAtPoint(pos, ptr, om.MSpace.kWorld)
        uValue = util.getDouble(ptr)

        #motion path node setup
        loc = cmds.spaceLocator(name='%s_Twist_%s_Loc' %
                                (name, str(curveItr.index() + 1).zfill(2)))
        offset = cmds.group(name='%s_Twist_%s_Loc_Offset' %
                            (name, str(curveItr.index() + 1).zfill(2)))
        group = cmds.group(name='%s_Twist_%s_Loc_Grp' %
                           (name, str(curveItr.index() + 1).zfill(2)))
        moPathNode = cmds.createNode(
            'motionPath',
            name='%s_Twist_%s_MoPath' %
            (name, str(curveItr.index() + 1).zfill(2)))
        cmds.connectAttr('%s.worldSpace[0]' % shape,
                         '%s.geometryPath' % moPathNode)
        cmds.setAttr('%s.uValue' % moPathNode, uValue)
        cmds.setAttr('%s.follow' % moPathNode, True)
        cmds.setAttr('%s.worldUpType' % moPathNode, 2)
        cmds.setAttr('%s.frontAxis' % moPathNode, 0)
        cmds.connectAttr('%s.worldMatrix[0]' % upObject,
                         '%s.worldUpMatrix' % moPathNode)
        cmds.connectAttr('%s.allCoordinates' % moPathNode,
                         '%s.translate' % group)
        cmds.connectAttr('%s.rotate' % moPathNode, '%s.rotate' % group)

        #setting up twist
        mdNode = cmds.createNode('multiplyDivide',
                                 name='%s_UpperTwist_%s_MD' %
                                 (name, str(curveItr.index() + 1).zfill(2)))
        mdNode2 = cmds.createNode('multiplyDivide',
                                  name='%s_LowerTwist_%s_MD' %
                                  (name, str(curveItr.index() + 1).zfill(2)))
        reverse = cmds.createNode('reverse',
                                  name='%s_Twist_%s_Reverse' %
                                  (name, str(curveItr.index() + 1).zfill(2)))
        pmaNode = cmds.createNode('plusMinusAverage',
                                  name='%s_Twist_%s_PMA' %
                                  (name, str(curveItr.index() + 1).zfill(2)))
        cmds.connectAttr('%s.outputX' % reverse, '%s.input1X' % mdNode2)

        cmds.connectAttr('%s.input1X' % mdNode, '%s.inputX' % reverse)
        cmds.setAttr('%s.input1X' % mdNode, uValue)
        cmds.connectAttr('%s.upperTwist' % curve, '%s.input2X' % mdNode)
        cmds.connectAttr('%s.lowerTwist' % curve, '%s.input2X' % mdNode2)
        cmds.connectAttr('%s.outputX' % mdNode, '%s.input1D[0]' % pmaNode)
        cmds.connectAttr('%s.outputX' % mdNode2, '%s.input1D[1]' % pmaNode)
        cmds.connectAttr('%s.output1D' % pmaNode, '%s.rotateX' % offset)

        locators.append(loc[0])
        curveItr.next()

    return locators
Ejemplo n.º 49
0
def mirrorCluster(transform,
                  deformerName,
                  prefix='L',
                  oppPrefix='R',
                  axis='x',
                  direction='<',
                  table=[-1, 1, 1]):

    vertSelection = om.MSelectionList()
    name = transform.split(prefix)[1]

    dagList = WeightListTool.sortDagMembers(deformerName, prefix, oppPrefix)

    if not len(dagList) == 0:

        singles = dagList[0]
        doubles = dagList[1]
        members = WeightListTool.getDagMembers(deformerName)

        for mesh in singles:

            meshPath = GenAPI.getDagPath(mesh)
            verts = GenAPI.getMObjectAllVerts(mesh)
            vertSelection.add(meshPath, verts)

        for meshGroup in doubles:

            for mesh in meshGroup:

                if not mesh in members:
                    blankWeightList = WeightListTool.createBlankList(
                        mesh, 0, True)
                    weightTool = WeightListTool(mesh, deformerName)
                    weightTool.setMembershipList(blankWeightList[1])
                    weightTool.setWeightList(blankWeightList[0])

                meshPath = GenAPI.getDagPath(mesh)
                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)
        mirrorPosition = [
            transformPosition[0] * table[0], transformPosition[1] * table[1],
            transformPosition[2] * table[2]
        ]

        clusterShape = cmds.listRelatives(cluster[1], type='shape')

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

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

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

        for mesh in singles:

            weightTool = WeightListTool(mesh, deformerName)
            weightList = weightTool.mirrorWeightList(table=table,
                                                     axis=axis,
                                                     direction=direction)
            weightTool.__init__(mesh, cluster[0])

            print weightList

            weightTool.setWeightList(weightList[0])
            weightTool.setMembershipList(weightList[1])

        for meshGroup in doubles:

            weightListA = WeightListTool.mirrorWeightListMultiMesh(
                meshGroup[0], meshGroup[1], deformerName, table)
            weightListB = WeightListTool.mirrorWeightListMultiMesh(
                meshGroup[1], meshGroup[0], deformerName, table)

            deformerTool = WeightListTool(meshGroup[1], cluster[0])
            deformerTool.setMembershipList(weightListA[1])
            deformerTool.setWeightList(weightListA[0])

            deformerTool.__init__(meshGroup[0], cluster[0])
            deformerTool.setMembershipList(weightListB[1])
            deformerTool.setWeightList(weightListB[0])

        try:
            cmds.rename(cluster[1], '%s%s' % (oppPrefix, name))

        except:
            pass

        om.MGlobal.displayInfo('Created mirrored cluster from %s' %
                               deformerName)

    else:
        om.MGlobal.displayError(
            'Cannot mirror %s. Please make sure both sides are members.' %
            deformerName)
Ejemplo n.º 50
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()
Ejemplo n.º 51
0
def build(**kwargs):

    curve = kwargs.get('curve')
    locatorCount = kwargs.get('locatorCount',2)
    wheelCrv = kwargs.get('wheelCrv')
    name =  kwargs.get('name','Path')
    frontAxis = kwargs.get('frontAxis',0)
    reverseFrontAxis = kwargs.get('reverseFrontAxis',False)
    upAxis = kwargs.get('upAxis',1)
    reverseUpAxis = kwargs.get('reverseUpAxis',False)
    upVector = kwargs.get('upVector',[0,1,0])
    controlScale =kwargs.get('controlScale',15)
    
    curveShape = cmds.listRelatives(curve,type = 'shape')[0]
    
    curveInfo = cmds.createNode('curveInfo',name = '%s_CI'%name)
    cmds.connectAttr('%s.worldSpace[0]'%curveShape,'%s.inputCurve'%curveInfo)
    
    driveCtrl = cmds.circle(name = 'Drive_Ctrl')[0]
    driveCtrlGrp = cmds.group(empty = True,name = 'Drive_Ctrl_Grp')
    cmds.parent(driveCtrl,driveCtrlGrp)
    
    cmds.addAttr('Drive_Ctrl',ln =  "FKCtrlVis" ,at = 'bool')
    cmds.setAttr ('Drive_Ctrl.FKCtrlVis',e = True ,cb =  True)
    
    cmds.addAttr('Drive_Ctrl',ln =  "IKCtrlVis" ,at = 'bool')
    cmds.setAttr ('Drive_Ctrl.IKCtrlVis',e = True ,cb =  True)
    
    locGrp = cmds.group(empty = True,name = '%s_Loc_Grp'%name)
    upLocator = cmds.spaceLocator(name = '%s_Up_Loc'%name)[0]
    cmds.move(upVector[0],upVector[1],upVector[2],upLocator)
    cmds.parent(upLocator,locGrp)

    for i in range(locatorCount):
        
        zeroString = '0'
        if i>9:
            zeroString = ''
            
        cmds.addAttr(driveCtrl,ln =  'drive%i'%(i+1) ,at = 'double',min = 0)
        cmds.setAttr ('%s.drive%i'%(driveCtrl,i+1),e = True ,keyable =  True)
        
        cmds.addAttr(driveCtrl,ln =  'initOffset%i'%(i+1) ,at = 'double')
        cmds.setAttr ('%s.initOffset%i'%(driveCtrl,i+1),e = True ,keyable =  True)
        
        cmds.addAttr(driveCtrl,ln =  'offset%i'%(i+1) ,at = 'double')
        cmds.setAttr ('%s.offset%i'%(driveCtrl,i+1),e = True ,keyable =  True)
        
        addOffsetPMA = cmds.createNode('plusMinusAverage',name = '%s_InitOffset_%s%i_PMA'%(name,zeroString,i+1))
        cmds.connectAttr('%s.initOffset%i'%(driveCtrl,i+1),'%s.input1D[0]'%addOffsetPMA)
        cmds.connectAttr('%s.offset%i'%(driveCtrl,i+1),'%s.input1D[1]'%addOffsetPMA)
    
        moPathLoc = cmds.spaceLocator(name = '%s_POC_%s%i_Loc'%(name,zeroString,i+1))[0]
        motionPathNode = cmds.createNode('motionPath',name = '%s_%s%i_MoPath'%(name,zeroString,i+1))
        cmds.connectAttr('%s.worldSpace[0]'%curveShape,'%s.geometryPath'%motionPathNode)
        cmds.setAttr('%s.worldUpType'%motionPathNode,1)
        cmds.connectAttr('%s.worldMatrix[0]'%upLocator,'%s.worldUpMatrix'%motionPathNode)
        
        cmds.connectAttr('%s.allCoordinates'%motionPathNode,'%s.translate'%moPathLoc)
        cmds.connectAttr('%s.rotate'%motionPathNode,'%s.rotate'%moPathLoc)
        
        offsetPMA = cmds.createNode('plusMinusAverage',name = '%s_offset_%s%i_PMA'%(name,zeroString,i+1))
        cmds.connectAttr('%s.drive%i'%(driveCtrl,i+1),'%s.input1D[0]'%offsetPMA)
        cmds.connectAttr('%s.output1D'%addOffsetPMA,'%s.input1D[1]'%offsetPMA)
        
        dampMD = cmds.createNode('multiplyDivide',name = '%s_Damp_%s%i_MD'%(name,zeroString,i+1))
        cmds.connectAttr('%s.output1D'%offsetPMA,'%s.input1X'%dampMD)
        
        cmds.connectAttr('%s.outputX'%dampMD,'%s.uValue'%motionPathNode)
        
        cmds.setAttr('%s.frontAxis'%motionPathNode,frontAxis)
        cmds.setAttr('%s.upAxis'%motionPathNode,upAxis)
        cmds.setAttr('%s.inverseFront'%motionPathNode,reverseFrontAxis)
        cmds.setAttr('%s.inverseUp'%motionPathNode,reverseUpAxis)
        cmds.parent(moPathLoc,locGrp)
        
    for i in range(len(wheelCrv)):
    
        zeroString = '0'
        if i>9:
            zeroString = ''
    
        wheelCrvInfo = cmds.createNode('curveInfo',name = '%s_Wheel_%s%i_CI'%(name,zeroString,i+1))
        cmds.connectAttr('%s.worldSpace[0]'%wheelCrv[i],'%s.inputCurve'%wheelCrvInfo)
        
        divideCircum = cmds.createNode('multiplyDivide',name = '%s_Circum_%s%i_MD'%(name,zeroString,i+1))
        cmds.setAttr('%s.operation'%divideCircum,2)
        cmds.connectAttr('%s.arcLength'%wheelCrvInfo,'%s.input1X'%divideCircum)
        cmds.connectAttr('%s.arcLength'%curveInfo,'%s.input2X'%divideCircum)
    
        cmds.addAttr(driveCtrl,ln =  'rotateMultiply%i'%(i+1) ,at = 'double')
        cmds.setAttr ('%s.rotateMultiply%i'%(driveCtrl,i+1),e = True ,keyable =  True)
        
        circumMult = cmds.createNode('multiplyDivide',name = '%s_RotateMult_%s%i_MD'%(name,zeroString,i+1))
        cmds.connectAttr('%s.outputX'%divideCircum,'%s.input1X'%circumMult)
        cmds.connectAttr('%s.rotateMultiply%i'%(driveCtrl,i+1),'%s.input2X'%circumMult)
        
        cmds.addAttr(driveCtrl,ln =  'outRotate%i'%(i+1) ,at = 'double')
        cmds.setAttr ('%s.rotateMultiply%i'%(driveCtrl,i+1),e = True ,keyable =  True)
    
    defJointGrp = cmds.group(empty = True,name = '%s_Def_Jnt_Grp'%name)
    
    cmds.select(cl = True)
    baseJoint = cmds.joint(name = '%s_Def_Main_Jnt'%name)
    cmds.parent(baseJoint,defJointGrp)
    skincluster = cmds.skinCluster(curve,baseJoint)[0]
    cmds.setAttr('%s.liw'%baseJoint, 0)
    
    curveItr = om.MItCurveCV(GenAPI.getDagPath(curve))
    
    cmds.select(cl = True)
    
    defJoints = []
    fkCtrls = []
    fkCtrlGrps = []
    
    allIKCtrlGrp = cmds.group(empty = True,name = '%s_IK_Ctrl_Grp'%name)
    allFKCtrlGrp = cmds.group(empty = True,name = '%s_FK_Ctrl_Grp'%name)
    
    i = 1
    while not curveItr.isDone():
    
        zeroString = '0'
        if i>9:
            zeroString = ''
        
        cv = curveItr.index()
        
        ikCtrlGrp = cmds.group(empty = True,name = '%s_IK_%s%i_Ctrl_Grp'%(name,zeroString,i))
        ikCtrl = cmds.circle(name = '%s_IK_%s%i_Ctrl'%(name,zeroString,i),r = (5 * controlScale))[0]
        cmds.parent(ikCtrl,ikCtrlGrp)
        cmds.parent(ikCtrlGrp,allIKCtrlGrp)
        
        fkCtrlGrp = cmds.group(empty = True,name = '%s_FK_%s%i_Ctrl_Grp'%(name,zeroString,i))
        fkCtrl = cmds.circle(name = '%s_FK_%s%i_Ctrl'%(name,zeroString,i),r = (10 * controlScale))[0]
        cmds.parent(fkCtrl,fkCtrlGrp)
        cmds.parent(fkCtrlGrp,allFKCtrlGrp)
        fkCtrls.append(fkCtrl)
        fkCtrlGrps.append(fkCtrlGrp)
        
        cmds.connectAttr('Drive_Ctrl.FKCtrlVis','%s.visibility'%fkCtrlGrp)
        cmds.connectAttr('Drive_Ctrl.IKCtrlVis','%s.visibility'%ikCtrlGrp)
        
        cmds.setAttr('%s.overrideEnabled'%ikCtrl,True)
        cmds.setAttr('%s.overrideColor'%ikCtrl,13)
        
        cmds.setAttr('%s.overrideEnabled'%fkCtrl,True)
        cmds.setAttr('%s.overrideColor'%fkCtrl,6)
        
        cmds.parentConstraint(fkCtrl,ikCtrlGrp,mo = True)
        
        cmds.select(cl = True)
        
        joint = cmds.joint(name = '%s_Def_%s%i_Jnt'%(name,zeroString,i),radius = 200)
        cmds.parent(joint,defJointGrp)
        cmds.parentConstraint(ikCtrl,joint,mo = True)
        
        cmds.select(cl = True)
        pointPos = curveItr.position(om.MSpace.kWorld)
        cmds.move(pointPos.x,pointPos.y,pointPos.z,joint,ws = True)
        
        cmds.move(pointPos.x,pointPos.y,pointPos.z,ikCtrlGrp,ws = True)
        cmds.move(pointPos.x,pointPos.y,pointPos.z,fkCtrlGrp,ws = True)
        
        cmds.skinCluster(skincluster,e = True , weight = 0,addInfluence = joint)
        defJoints.append(joint)
        
        i += 1
        curveItr.next()
     
    for joint in defJoints:
        cmds.setAttr('%s.liw'%joint, 0)
        
    for i in range(len(defJoints)):
        cmds.skinPercent( skincluster,'%s.cv[%i]'%(curve,i), transformValue=[(defJoints[i], 1)])
        
    for i in range(len(fkCtrls)):
        try:
            cmds.parentConstraint(fkCtrls[i],fkCtrlGrps[i+1],mo = True)     
        except:
            pass
Ejemplo n.º 52
0
def extrapFromWire(wire):

    curveShapeConnection = cmds.connectionInfo('%s.deformedWire[0]' % wire,
                                               sfd=True)
    curveShape = curveShapeConnection.split('.')[0]

    dagMembers = DeformerLib.WeightListTool.getDagMembers(wire)

    curvePath = GenAPI.getDagPath(curveShape)

    progressWin = UILib.ProgressWin()
    progressWin.setTitle('Extrap Skincluster from Wire')
    progressWin.itr = 5

    progressWin.inc = 1
    progressWin.progress()
    #creating clusters

    cvSelection = om.MSelectionList()

    cvItr = om.MItCurveCV(curvePath)

    clusters = []

    while not cvItr.isDone():

        cvSelection.clear()

        currentCV = cvItr.currentItem()

        cvSelection.add(curvePath, currentCV)
        om.MGlobal.setActiveSelectionList(cvSelection)

        cluster = cmds.cluster()
        clusters.append(cluster)

        cvItr.next()

    progressWin.inc = 2
    progressWin.message = 'extraping...'
    progressWin.progress()
    #getting weights from clusters

    allWeightLists = []

    for mesh in dagMembers:

        influenceWeightLists = []

        for cluster in clusters:

            currentWeightList = MeasuringLib.MeasuringTool.createWeigthListFromTransform(
                mesh, cluster[1])
            influenceWeightLists.append(currentWeightList)

        allWeightLists.append(influenceWeightLists)

    #delete clusters
    for cluster in clusters:
        cmds.delete(cluster[0])

    progressWin.inc = 3
    progressWin.progress()
    #create joints

    cmds.select(cl=True)

    joints = []

    cvItr.reset(curvePath)

    while not cvItr.isDone():

        cmds.select(cl=True)

        position = cvItr.position(om.MSpace.kWorld)

        currentJoint = cmds.joint()
        cmds.move(position.x, position.y, position.z, currentJoint)
        joints.append(currentJoint)

        cvItr.next()

    cmds.select(cl=True)

    baseJoint = cmds.joint()

    progressWin.inc = 4
    progressWin.progress()
    #create group for bind joints

    jointGroup = cmds.group(empty=True)
    cmds.parent(baseJoint, jointGroup)

    for joint in joints:

        cmds.parent(joint, jointGroup)

    progressWin.inc = 5
    progressWin.message = 'setting weights'
    progressWin.progress()
    #smooth bind

    inc = 0
    for mesh in dagMembers:

        progressWin = UILib.ProgressWin()
        progressWin.setTitle('Setting Weights for %s' % mesh)
        progressWin.itr = len(joints)

        skincluster = cmds.skinCluster(mesh, baseJoint)[0]
        skinningTool = SkinningTool(skincluster, mesh)

        cmds.setAttr('%s.liw' % baseJoint, 0)

        for i in range(len(joints)):

            cmds.skinCluster(skincluster,
                             e=True,
                             weight=0,
                             addInfluence=joints[i])
            cmds.setAttr('%s.liw' % joints[i], 0)

            skinningTool.setWeights(GenAPI.getDagPath(joints[i]),
                                    allWeightLists[inc][i])

            cmds.setAttr('%s.liw' % joints[i], 1)

            progressWin.inc = i
            progressWin.progress()

        inc += 1
        progressWin.end()
Ejemplo n.º 53
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)
Ejemplo n.º 54
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
Ejemplo n.º 55
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