Example #1
0
    def execute(self):
        targetMll = MllInterface(mesh=self.targetMesh)

        self.ensureTargetMeshLayers()

        previousLayerIds = [layerId for layerId, _ in targetMll.listLayers()]

        sourceMesh = self.sourceMesh
        if self.sourceModel is not None:
            self.sourceModel.saveTo(MllInterface.TARGET_REFERENCE_MESH)
            sourceMesh = MllInterface.TARGET_REFERENCE_MESH

        vertexTransferMode = self.vertexTransferModes[
            self.parent.controls.transferMode.getSelectedText()]

        sourceMll = MllInterface(mesh=sourceMesh)
        sourceMll.transferWeights(self.targetMesh,
                                  influencesMapping=self.mapper.mapping,
                                  vertexTransferMode=vertexTransferMode)

        if self.parent.controls.keepExistingLayers.getValue() != 1:
            for layerId in previousLayerIds:
                targetMll.deleteLayer(layerId)

        LayerDataModel.getInstance().updateLayerAvailability()
        LayerEvents.layerListModified.emit()
    def __init__(self):
        #: layers list
        self.layers = []
        self.mll = MllInterface()

        # a map [sourceInfluenceName] -> [destinationInfluenceName]
        self.mirrorInfluenceAssociationOverrides = {}
Example #3
0
 def get_data(self, check):
     self.ngs_weight_dict = {}
     self.vert_weight_dict = {}
     self.selection_vert = cmds.ls(os=True)
     if not self.selection_vert:
         return False
     if not check:
         self.ngs_influence = [("selected influence:",
                                self.mll.getCurrentPaintTarget())]
     else:
         self.ngs_influence = self.mll.listLayerInfluences(
             layerId=None, activeInfluences=True)
     self.mll = MllInterface()
     self.ngs_layer_id = self.mll.getCurrentLayer()
     self.ngs_vert_count = self.mll.getVertCount()
     self.vertex_list = cmds.ls(self.selection_vert, flatten=True)
     self.id_list = list(
         map(lambda x: x[x.find("[") + 1:x.find("]")], self.vertex_list))
     for influences in self.ngs_influence:
         influence_weights = self.mll.getInfluenceWeights(
             self.ngs_layer_id, influences[1])
         vert_weights = [influence_weights[int(i)] for i in self.id_list]
         self.ngs_weight_dict[influences] = influence_weights
         self.vert_weight_dict[influences] = vert_weights
     return True
Example #4
0
    def setUp(self):
        self.targetMesh = 'testMesh'
        self.numVerts = 169  # number of verts in our mesh
        self.mll = MllInterface()

        unittest.TestCase.setUp(self)
        openMayaFile('simplemirror.ma')
        cmds.hide("|y_axis")
        cmds.showHidden("|x_axis")

        self.mll.setCurrentMesh(self.targetMesh)
        self.mll.initLayers()
        self.mll.createLayer("original weights")

        self.model = ie.LayerData()
        self.layer = ie.Layer()
        self.layer.opacity = 1.0
        self.layer.enabled = True
        self.layer.mask = [0.0] * self.numVerts
        self.layer.mask[1] = 0.9
        self.layer.mask[5] = 0.5566
        self.layer.name = "imported layer"
        self.model.addLayer(self.layer)

        self.infl = ie.Influence()
        self.layer.addInfluence(self.infl)
        self.infl.influenceName = "x_axis|root|R_joint1"
        self.infl.logicalIndex = 666  # use nonsense value
        self.infl.weights = [0.1] * self.numVerts
        self.infl.weights[3] = 0.688
        self.infl.weights[4] = 0.345
Example #5
0
 def updateConfiguration(self):
     mll = MllInterface()
     mll.configureVertexMirrorMapping(
         mirrorAxis=self.mirrorAxis.getSelectedText(),
         vertexTransferMode=self.vertexTransferModes[
             self.transferMode.getSelectedText()])
     LayerEvents.mirrorConfigurationChanged.emit()
Example #6
0
 def __init__(self):
     self.mll = MllInterface()
     self.selection_name = []
     self.ngs_layer_id = -1
     self.ngs_influence = None
     self.ngs_weight_list = []
     self.ngs_vert_count = -1
     self.max_value = -1.0
     self.min_value = -1.0
Example #7
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 #8
0
 def __init__(self):
     self.layerListsUI = None
     self.layerDataAvailable = None
     self.mirrorCache = self.MirrorCacheStatus()
     self.mll = MllInterface()
     self.clipboard = WeightsClipboard(self.mll)
     
     MayaEvents.undoRedoExecuted.addHandler(self.updateLayerAvailability)
     MayaEvents.nodeSelectionChanged.addHandler(self.updateLayerAvailability)
     
     self.updateLayerAvailability()
Example #9
0
def initLayers(bndGrp, mesh):
    '''
    first step in setup
    bind bnds in bndGrp to mesh
    and set up ngSkinLayers
    '''
    # init skin layers
    mll = MllInterface()
    mll.setCurrentMesh(mesh.name())
    mll.initLayers()
    
    return mll
Example #10
0
    def __init__(self):
        self.layers = []
        self.mll = MllInterface()

        self.meshInfo = MeshInfo()

        self.influences = []

        # a map [sourceInfluenceName] -> [destinationInfluenceName]
        self.mirrorInfluenceAssociationOverrides = None

        self.skinClusterFn = None
 def testLoad2(self):
     openMayaFile('simplemirror.ma')
     mll = MllInterface()
     mll.setCurrentMesh('testMesh')
     mll.initLayers()
     mll.createLayer("Initial Weights")
     
     model = LayerData()
     model.loadFrom('testMesh')
     
     self.assertEqual(model.layers[0].name, "Initial Weights")
     self.assertEquals(model.layers[0].influences[0].influenceName, "|x_axis|root")
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.mll = MllInterface()

        self.setup = DuplicateLayers()
        self.setup.setMllInterface(self.mll)

        testUtils.openMayaFile("influence transfer.mb")

        self.mll.setCurrentMesh('sourceMesh')

        self.mll.initLayers()
Example #13
0
    def buildInfluenceMappingEngine(self, controls):
        '''
        builds influence transfer mapping, using parameters from UI
        '''

        mapping = TransferDataModel.buildInfluenceMappingEngine(self, controls)

        mapping.nameMatchRule.ignoreNamespaces = self.parent.controls.ignoreNamespaces.getValue(
        ) == 1

        mapping.rules = [mapping.distanceMatchRule, mapping.nameMatchRule]
        if self.sourceModel is not None:
            mapping.sourceInfluences = self.sourceModel.influences
        else:
            mapping.sourceInfluences = MllInterface(
                mesh=self.sourceMesh).listInfluenceInfo()

        mapping.destinationInfluences = MllInterface(
            mesh=self.targetMesh).listInfluenceInfo()

        mapping.mirrorMode = False
        return mapping
 def setUp(self):
     testUtils.openMayaFile("normalization.ma")
     
     self.mll = MllInterface()
     cmds.select("testMesh")
     self.mll.initLayers()
     self.mll.createLayer("initial weights")
     self.layer = self.mll.createLayer("second layer")
     self.mll.setCurrentLayer(self.layer)
     
     self.clipboard = WeightsClipboard(self.mll)
     
     self.newWeights = [0.5]*self.mll.getVertCount()
Example #15
0
    def buildInfluenceMappingEngine(self, controls):
        '''
        builds influence transfer mapping, using parameters from UI
        '''

        mapper = self.mapper = InfluenceMapping()
        mapper.mirrorMode = False
        self.mapper.distanceMatchRule.maxThreshold = float(
            controls.influenceDistanceError.getValue())

        mapper.nameMatchRule.ignoreNamespaces = controls.ignoreNamespaces.getValue(
        ) == 1

        mapper.rules = [mapper.distanceMatchRule, mapper.nameMatchRule]
        if self.sourceModel is not None:
            mapper.sourceInfluences = self.sourceModel.influences
        else:
            mapper.sourceInfluences = MllInterface(
                mesh=self.sourceMesh).listInfluenceInfo()

        mapper.destinationInfluences = MllInterface(
            mesh=self.targetMesh).listInfluenceInfo()

        return mapper
Example #16
0
    def __init__(self, surface_name):
        self.surface = surface_name
        self.stroke_id = None
        self.mode = 1
        self.value = 1
        self.volumeThreshold = -0.1

        self.mll = MllInterface()
        self.selection_name = cmds.ls(selection=True)
        self.mesh = cmds.listRelatives(self.selection_name[0], shapes=True)
        self.ngs_layer_id = self.mll.getCurrentLayer()
        self.ngs_influence = self.mll.getCurrentPaintTarget()
        self.ngs_weight_list = self.mll.getInfluenceWeights(
            self.ngs_layer_id, self.ngs_influence)
        self.max_value = max(self.ngs_weight_list)
        self.min_value = min(self.ngs_weight_list)
Example #17
0
    def setUp(self):
        unittest.TestCase.setUp(self)
        testUtils.openMayaFile("normalization.ma")
        self.mll = mll = MllInterface()
        mll.setCurrentMesh("testMesh")
        mll.initLayers()
        mll.createLayer("initial weights")
        mll.createLayer("second layer")

        HeadlessDataHost.HANDLE.addReference(self)

        self.exportName = os.path.join(
            tempfile.gettempdir(),
            'layersTestData_%d.xml' % random.randint(0, 1024 * 1024))
        self.assertTrue(not os.path.exists(self.exportName),
                        'target file already exists')
    def testDefectXmlImportIssue(self):
        openMayaFile("defect-xml-import-fails/mirror_association_issues.ma")

        importer = XmlImporter()
        data = importer.process(getTestFileContents("defect-xml-import-fails/mirror_weighting_manual_layers.xml"))
        
        
        mll = MllInterface()
        mll.setCurrentMesh("pSphere1")
        
        
        overrides = mll.listManualMirrorInfluenceAssociations()
        self.assertEqual(len(overrides), 0)
        
        data.saveTo("pSphere1")
        
        overrides = mll.listManualMirrorInfluenceAssociations()
        self.assertEqual(len(overrides), 1)
Example #19
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 #20
0
def removeLayersFromSelection():
    mll = MllInterface()
    target = mll.getTargetInfo()
    if target is None:
        return

    def asList(arg):
        if arg is None:
            return []
        return arg


    # delete any ngSkinTools deformers from the history, and find upstream stuff from given skinCluster.
    mesh,skinCluster = target
    hist = asList(cmds.listHistory(mesh))+asList(cmds.listHistory(skinCluster,future=True,levels=1))

    cmds.delete([i for i in hist if cmds.nodeType(i) in ('ngSkinLayerDisplay','ngSkinLayerData')])

    LayerDataModel.getInstance().updateLayerAvailability()
    selectionState.selectionInfo.dropCache()
Example #21
0
    def configurePaintValues(self):
        '''
        sets paint tool values from UI
        '''
        oper, pvalue = self.getPaintModeValues()
        cmds.ngSkinLayer(paintOperation=oper,
                         paintIntensity=pvalue.get(),
                         paintMirror=self.controls.mirroredMode.isChecked())

        from ngSkinTools import selectionState
        if self.controls.mirroredMode.isChecked(
        ) and selectionState.getLayersAvailable():
            self.parentWindow.tabMirror.influenceMappingConfiguration.updateSelectionsInfluenceMapping(
            )

        MllInterface().setPaintOptionRedistributeWeight(
            self.controls.redistributeWeightSetting.isChecked())

        if cmds.artUserPaintCtx(self.TOOL_PAINT, exists=True):
            # internally, use maya's "replace" brush with intensity of 1.0
            cmds.artUserPaintCtx(
                self.TOOL_PAINT,
                e=True,
                selectedattroper='absolute',
                value=1.0,
                opacity=1.0,
                brushfeedback=False,
                accopacity=False,
                usepressure=self.controls.stylusPressureOnOff.isChecked(),
                stampProfile=self.getSelectedBrushShape())

            if self.controls.stylusPressureOnOff.isChecked():
                try:
                    cmds.artUserPaintCtx(self.TOOL_PAINT,
                                         e=True,
                                         mappressure=self.controls.
                                         stylusPressureMode.getSelectedText())
                except:
                    pass

        self.updateToTool()
Example #22
0
    def __init__(self):
        self.mll = MllInterface()
        self.ngs_vert_count = -1
        self.ngs_layer_id = -1
        self.intensity = -1
        self.ngs_influence = None
        self.vert_weight_dict = {}
        self.vert_weight_list = []
        self.ngs_weight_dict = {}
        self.ngs_weight_list = []
        self.new_weight_list = []
        self.selection_vert = []
        self.vertex_list = []
        self.id_list = []

        self.modes = {
            "max": self.vert_max,
            "min": self.vert_min,
            "avg": self.vert_avg,
            "first": self.vert_first,
            "last": self.vert_last
        }
Example #23
0
def save_weights(weight_dir, geo_list=[]):

    """
    save geometry weights for character
    """

    for obj in geo_list:
        # save dir and save file

        weight_file = os.path.join(weight_dir, obj + '.json')

        layerData = LayerData()
        try:
            layerData.loadFrom(obj + 'Shape')
        except:
            try:
                mll = MllInterface()
                mll.setCurrentMesh(obj+'Shape')
                ass = mll.initLayers()
                layer = mll.createLayer('Base Weights')
            except:
                pass
        exporter = JsonExporter()
        jsonContents = exporter.process(layerData)
        # string "jsonContents" can now be saved to an external file

        with open(weight_file, 'w') as f:
            f.write(jsonContents)
            #json.dump(jsonContents, f)
        # save skin weight file

        #mc.select(obj)
        #bSkinSaver2.bSaveSkinValues(weight_file)

        print "Saved to: " + weight_file
        mc.select(d=True)
Example #24
0
 def onManualOverridesChanged():
     mll = MllInterface()
     mll.setManualMirrorInfluences(
         self.influencesManualMapping.manualOverrides)
     self.previewInfluenceMapping()
Example #25
0
    def __init__(self):
        self.mll = MllInterface()
        self.ng_color_set = ""
        self.check_color_set = 'checkSetBlue'
        self.mo = MapOperations()
        self.radio_text = 'Mode:'
        self.conceal = 'Conceal'
        self.spread = 'Spread'
        self.contrast = 'Contrast'
        self.gain = "Gain"
        self.volume = "Volume EQ"
        self.defaultOp = 'Conceal'
        self.select_mode = True
        self.intensityField = 'Intensity'
        self.defaultVal = 1
        self.shrinkButton = 'Shrink Map'
        self.growButton = 'Grow Map'
        self.floodButton = 'Quick Flood'
        self.exitButton = 'Exit Tool'
        self.matchButton = 'Match Brush'

        self.dividerEQ = "dividerEQ"
        self.editMenuEQ = 'Vertex Equalizer Tool'

        self.extra_check = "Use Extra Brushes"
        self.extra_frame = "Extra Tools"
        self.radio_form = "radio_form"
        self.intensity_label = "Intensity:"
        self.volume_label = "Volume:"
        self.intensity_row = "intensity_row"
        self.volume_row = "threshold_row"
        self.extra_field = "extra_field"
        self.extra_slider = "extra_slider"
        self.volume_field = "volume_field"
        self.volume_slider = "volume_slider"
        self.mode_collection = "mode_collection"
        self.button_form = "button_form"
        # self.brush_display_check = "Draw Brush while painting"
        # self.default_brush_display = cmds.artUserPaintCtx(outwhilepaint=True, q=True)

        self.ui_paths = {
            "paint_tab":
            "MayaWindow|horizontalSplit|tabLayout|formLayout|scrollLayout|columnLayout",
            "paint_buttons":
            "MayaWindow|horizontalSplit|tabLayout|formLayout|formLayout|button",
            "mode_radio":
            "MayaWindow|horizontalSplit|tabLayout|formLayout|scrollLayout|columnLayout|frameLayout"
            "|columnLayout|formLayout|rowColumnLayout|radioButton",
            "mode_layout":
            "MayaWindow|horizontalSplit|tabLayout|formLayout|scrollLayout|columnLayout"
            "|frameLayout|columnLayout|formLayout|rowColumnLayout",
            "intensity_slider":
            "MayaWindow|horizontalSplit|tabLayout|formLayout|scrollLayout|columnLayout|frameLayout"
            "|columnLayout|formLayout|rowLayout|floatSlider",
            "slider_rows":
            "MayaWindow|horizontalSplit|tabLayout|formLayout|scrollLayout|columnLayout|frameLayout"
            "|columnLayout|formLayout|rowLayout",
            "checkboxes":
            "MayaWindow|horizontalSplit|tabLayout|formLayout|scrollLayout|columnLayout|frameLayout"
            "|columnLayout|formLayout|columnLayout|checkBox",
            "EA_menu":
            "MayaWindow|horizontalSplit|formLayout|menuBarLayout|menu"
        }

        self.ng_radio_layout = get_target_control(self.ui_paths["mode_layout"])
        self.ng_radio_buttons = get_target_control(self.ui_paths["mode_radio"])
        self.ng_intensity = get_target_control(
            self.ui_paths["intensity_slider"])
        self.ng_checkboxes = get_target_control(self.ui_paths["checkboxes"])
        self.ng_slider_rows = get_target_control(self.ui_paths["slider_rows"])
        self.ng_paint_buttons = get_target_control(
            self.ui_paths["paint_buttons"])
        self.ng_menu = get_target_control(self.ui_paths["EA_menu"])
Example #26
0
 def __init__(self):
     self.layerDataAvailable = None
     self.mll = MllInterface()
     self.clipboard = WeightsClipboard(self.mll)
Example #27
0
 def ensureTargetMeshLayers(self):
     targetMll = MllInterface(mesh=self.targetMesh)
     if not targetMll.getLayersAvailable():
         targetMll.initLayers()
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.mll = MllInterface()
Example #29
0
#    and conditions defined by EULA.
#
#    A copy of EULA can be found in file 'LICENSE.txt', which is part
#    of this source code package.
#
'''
Cached information about current selection
'''
from ngSkinTools.log import getLogger
from ngSkinTools.mllInterface import MllInterface
from ngSkinTools.stateStore import CachedValue
from ngSkinTools.ui.events import Signal, LayerEvents, MayaEvents

log = getLogger('selectionState')

mll = MllInterface()

# container for mirror related state
mirrorInfo = CachedValue('mirrorInfo', lambda: {
    'axis': mll.getMirrorAxis(),
})

# container for primary selection data
selectionInfo = CachedValue(
    'selectionInfo', lambda: {
        'target': mll.getTargetInfo(),
        'layersAvailable': mll.getLayersAvailable(),
    })


def getLayersAvailable():