Example #1
0
    def __paste__(self, weightsCalculator):
        if self.copiedWeights == None:
            raise MessageException("Nothing to paste")

        if self.mll.getVertCount() != len(self.copiedWeights):
            raise MessageException(
                "Could not paste weights - vertex count does not match")

        prevWeights = self.getPaintTargetWeights(self.influence)
        vertSelection = self.mll.getVertexSelectionWeights()
        newWeights = weightsCalculator(prevWeights)
        if newWeights is None:
            return
        if vertSelection is not None:
            for i in range(len(vertSelection)):
                newWeights[i] = newWeights[i] * vertSelection[i] + prevWeights[
                    i] * (1 - vertSelection[i])

        if self.influence == NamedPaintTarget.MASK:
            self.mll.setLayerMask(self.layer, newWeights)
        if self.influence == NamedPaintTarget.DUAL_QUATERNION:
            self.mll.setDualQuaternionWeights(self.layer, newWeights)
        else:
            self.mll.setInfluenceWeights(self.layer, self.influence,
                                         newWeights)
Example #2
0
    def copy(self):
        self.copiedWeights = self.getPaintTargetWeights(self.influence)

        log.debug("copied weights: %r" % self.copiedWeights)
        if len(self.copiedWeights) == 0:
            self.copiedWeights = None
            raise MessageException("Nothing copied")
Example #3
0
    def addMirrorInfluenceAssociationOverride(self,
                                              sourceInfluence,
                                              destinationInfluence=None,
                                              selfReference=False,
                                              bidirectional=True):
        '''
        Adds mirror influence association override, similar to UI of "Add influences association".
        Self reference creates a source<->source association, bidirectional means that destination->source 
        link is added as well
        '''

        if self.mirrorInfluenceAssociationOverrides is None:
            self.mirrorInfluenceAssociationOverrides = {}

        if selfReference:
            self.mirrorInfluenceAssociationOverrides[
                sourceInfluence] = sourceInfluence
            return

        if destinationInfluence is None:
            raise MessageException("destination influence must be specified")

        self.mirrorInfluenceAssociationOverrides[
            sourceInfluence] = destinationInfluence

        if bidirectional:
            self.mirrorInfluenceAssociationOverrides[
                destinationInfluence] = sourceInfluence
Example #4
0
 def initFromSelection(self):
     items = cmds.ls(sl=True)
     if items==None or len(items)!=2:
         raise MessageException("select two skinned meshes to perform this operation")
     
     self.setSourceFromMesh(items[0])
     self.setDestinationFromMesh(items[1])
Example #5
0
    def getLogicalInfluenceIndex(self, influenceName):
        try:
            path = Utils.getDagPathForNode(influenceName)
        except:
            raise MessageException("Could not find influence '%s' in %s" %
                                   (influenceName, self.skinCluster))

        return self.fn.indexForInfluenceObject(path)
Example #6
0
    def paste(self, replace):
        if self.copiedWeights == None:
            raise MessageException("Nothing to paste")

        if self.mll.getVertCount() != len(self.copiedWeights):
            raise MessageException(
                "Could not paste weights - vertex count does not match")

        newWeights = self.copiedWeights
        if not replace:
            prevWeights = self.getPaintTargetWeights(self.influence)
            newWeights = [a + b for a, b in zip(newWeights, prevWeights)]

        if self.influence == LayerUtils.PAINT_TARGET_MASK:
            self.mll.setLayerMask(self.layer, newWeights)
        else:
            self.mll.setInfluenceWeights(self.layer, self.influence,
                                         newWeights)
Example #7
0
    def execute(self):
        meshes = cmds.ls(sl=True)
        if meshes == None or len(meshes) != 2:
            raise MessageException(
                "select two skinned meshes with layers initialized to perform this operation"
            )

        for mesh in meshes:
            if not MllInterface(mesh=meshes[0]).getLayersAvailable():
                raise MessageException(
                    "'%s' is not a valid selection (no skin layers available)"
                    % mesh)

        from ngSkinTools.ui.initTransferWindow import TransferWeightsWindow
        window = TransferWeightsWindow.getInstance()
        window.showWindow()
        window.content.dataModel.setSourceMesh(meshes[0])
        window.content.dataModel.setDestinationMesh(meshes[1])
Example #8
0
    def __paste__(self, weightsCalculator):
        if self.copiedWeights == None:
            raise MessageException("Nothing to paste")

        if self.mll.getVertCount() != len(self.copiedWeights):
            raise MessageException(
                "Could not paste weights - vertex count does not match")

        newWeights = weightsCalculator()
        if newWeights is None:
            return

        if self.influence == NamedPaintTarget.MASK:
            self.mll.setLayerMask(self.layer, newWeights)
        if self.influence == NamedPaintTarget.DUAL_QUATERNION:
            self.mll.setDualQuaternionWeights(self.layer, newWeights)
        else:
            self.mll.setInfluenceWeights(self.layer, self.influence,
                                         newWeights)
Example #9
0
 def __detectSkinCluster(self,mesh):
     mll = MllInterface()
     mll.setCurrentMesh(mesh)
     try:
         _,skinCluster = mll.getTargetInfo()
     except TypeError:
         raise MessageException("cannot find skin cluster attached to %s" % mesh)
     
     log.info("detected skin cluster %s on mesh %s" % (skinCluster, mesh))
     return skinCluster
Example #10
0
 def execSetCurrentSelection(self,*args):
     '''
     handler for "<<" button
     '''
     selList = om.MSelectionList()
     om.MGlobal.getActiveSelectionList(selList)
     sel = self.parseSelectionList(selList)
     if len(sel)<1:
         raise MessageException("No vertices selected")
     self.setSelection(sel)
Example #11
0
    def execRelax(self, *args):
        '''
            relax button click handler. this is where it actually 
            executes skin relax, whoop-tee-doo.
        '''
        try:

            args = {}
            args['numSteps'] = self.controls.numSteps.getValue()
            args['stepSize'] = self.controls.stepSize.getValue()
            
            # do we need soft selection?
            self.controls.softSelection.addToArgs(args)
            
                
            # do we need volume association?
            if self.controls.useVolumeAssociation.getValue():
                args['abv'] = 1
                args['avr'] = self.controls.volumeAssociationRadius.getValue()

            # add selection+highlight as arguments
            # we need highlight as second argument because
            # other meshes for simulation might be included only through highlight.
            #
            # This will never be an empty list as we tested for vertex selection available earlier
            def makeList(listOrNull):
                if listOrNull is None:
                    return []
                return listOrNull
            
            objects = makeList(cmds.ls(sl=True)) + makeList(cmds.ls(hl=True))
            
            if len(objects) == 0:
                raise MessageException("Nothing is selected")
            
            # execute stuff  
            try:
                cmds.waitCursor(state=True)
                cmds.ngSkinRelax(objects, **args)
            finally:
                cmds.waitCursor(state=False)
                
            Utils.refreshPaintWeightsTool()
            
        except MessageException, err:
            raise err
Example #12
0
    def saveOption(varName,value):
        '''
        saves option via optionVar
        '''

        # variable does not exist, attempt to save it
        key=None
        if isinstance(value,float):
            key='fv'
        elif isinstance(value,int):
            key='iv'
        elif isinstance(value,basestring):
            key='sv'
        else:
            raise MessageException("could not save option %s: invalid value %r" % (varName,value))
        
        cmds.optionVar(**{key:(varName,value)})
    def execute(self):
        layerListsUi = LayerDataModel.getInstance().layerListsUI

        setup = DuplicateLayers()
        setup.setMllInterface(LayerDataModel.getInstance().mll)

        layers = layerListsUi.getSelectedLayers()
        if len(layers) == 0:
            raise MessageException('No layers selected')

        for layer in reversed(layers):
            setup.addLayer(layer)
        setup.execute()

        LayerDataModel.getInstance().mll.setCurrentLayer(
            setup.duplicateIds[-1])

        LayerEvents.layerListModified.emit()
Example #14
0
    def execClosestJointAssign(self):
        '''
        runs 'assign from closest joint' operation
        '''
        args = {}
        args['bnj'] = True
        # by nearest joint

        # restrict influence list?
        if self.controls.rdioUseListerInfluences.getValue():
            # add include joints
            selInfluences = self.parentWindow.targetUI.getSelectedInfluences()
            if len(selInfluences) == 0:
                raise MessageException('no influences selected')

            args['ij'] = '/'.join(selInfluences)

        args['intensity'] = self.controls.cjIntensity.getIntensity()

        self.controls.cjSoftSelection.addToArgs(args)
        self.execAssignWeights(args)
Example #15
0
    def getFullNodePath(nodeName):
        result = cmds.ls(nodeName, l=True)
        if result is None or len(result) == 0:
            raise MessageException("node %s was not found" % nodeName)

        return result[0]
Example #16
0
 def execPreview(self,*args):
     sel = self.getSelectionStrings()
     if len(sel)<1:
         raise MessageException("Nothing to select")
     
     cmds.select(sel)
Example #17
0
def getMayaMainWindow():
    for widget in qt.widgets.qApp.topLevelWidgets():
        if widget.objectName()=='MayaWindow':
            return widget
    raise MessageException('QT Main window could not be detected')