def onOpacitySliderChange(self): ''' emits when opacity slider in the dialog changes value ''' currLayer = LayerDataModel.getInstance().getCurrentLayer() if currLayer is not None: cmds.ngSkinLayer(e=True,id=currLayer,opacity=self.dlg.layerOpacityValue.get())
def updateMirrorCacheStatus(self): def setStatus(newStatus, message, axis=None): change = newStatus != self.mirrorCache.isValid or self.mirrorCache.message != message or self.mirrorCache.mirrorAxis != axis self.mirrorCache.message = message self.mirrorCache.isValid = newStatus self.mirrorCache.mirrorAxis = axis if change: self.log.info("mirror cache status changed to %s." % self.mirrorCache.message) LayerEvents.mirrorCacheStatusChanged.emit() self.log.info("updating mirror cache status") if not self.layerDataAvailable: setStatus(False, "Layer Data is not available") return try: cacheInfo = cmds.ngSkinLayer(q=True, mirrorCacheInfo=True) if cacheInfo[0] == 'ok': setStatus(True, 'Mirror Data Initialized', cmds.ngSkinLayer(q=True, mirrorAxis=True)) else: setStatus(False, cacheInfo[1]) except: setStatus(False, 'Cache check failed')
def moveLayer(self, up=True): newIndex = cmds.ngSkinLayer(q=True, layerIndex=True) + (1 if up else -1) if newIndex < 0: newIndex = 0 cmds.ngSkinLayer(layerIndex=newIndex) LayerEvents.layerListModified.emit()
def isEnabled(self): ''' disable if reorder in given direction cannot happen ''' # do nothing if already disabled if not BaseLayerAction.isEnabled(self): return False try: currIndex = cmds.ngSkinLayer(q=True, layerIndex=True) if currIndex is None: return False # for "down", index has to be above 0 if not self.isUp: return currIndex > 0 # for "up", index has to be <parent.numChildren-1 parent = cmds.ngSkinLayer(q=True, parent=True) # python does not support values with query params #numChildren = cmds.ngSkinLayer(id=parent,q=True,nch=True) numChildren = mel.eval("ngSkinLayer -id %d -q -nch" % parent) return currIndex < (numChildren - 1) except: return False
def updateMirrorCacheStatus(self): def setStatus(newStatus,message,axis=None): change = newStatus != self.mirrorCache.isValid or self.mirrorCache.message != message or self.mirrorCache.mirrorAxis != axis self.mirrorCache.message = message self.mirrorCache.isValid = newStatus self.mirrorCache.mirrorAxis = axis if change: self.log.info("mirror cache status changed to %s." % self.mirrorCache.message) LayerEvents.mirrorCacheStatusChanged.emit() self.log.info("updating mirror cache status") if not self.layerDataAvailable: setStatus(False,"Layer Data is not available") return try: cacheInfo = cmds.ngSkinLayer(q=True,mirrorCacheInfo=True) if cacheInfo[0]=='ok': setStatus(True,'Mirror Data Initialized',cmds.ngSkinLayer(q=True,mirrorAxis=True)) else: setStatus(False,cacheInfo[1]) except : setStatus(False,'Cache check failed')
def exit(self, *args): """ exits tool and resets it to the ngSkinTools settings """ init_mel = Utils.createMelProcedure(ngLayerPaintCtxInitialize, [('string', 'mesh')], returnType='string') cmds.artUserPaintCtx("ngSkinToolsLayerPaintCtx", e=True, setValueCommand="ngLayerPaintCtxSetValue", initializeCmd=init_mel, finalizeCmd="ngLayerPaintCtxFinalize", value=self.defaultVal) cmds.rowColumnLayout(self.ng_radio_layout[0], e=True, enable=True) cmds.checkBox(self.ng_checkboxes[0], e=True, enable=True) cmds.checkBox(self.ng_checkboxes[1], e=True, enable=True) cmds.rowLayout(self.ng_slider_rows[0], e=True, enable=True) cmds.formLayout(self.radio_form, e=True, enable=False) cmds.button(self.floodButton, e=True, enable=False) cmds.rowLayout(self.intensity_row, e=True, enable=False) cmds.rowLayout(self.volume_row, e=True, enable=False) ng_paint_mode = [(self.ng_radio_buttons.index(i) + 1) for i in self.ng_radio_buttons if cmds.radioButton(i, q=True, select=True) is True] ng_intensity_value = cmds.floatSlider(self.ng_intensity[0], q=True, value=True) cmds.ngSkinLayer(paintOperation=ng_paint_mode[0], paintIntensity=ng_intensity_value)
def execute(self): data = LayerDataModel.getInstance() currLayer = data.getCurrentLayer() if currLayer is None or currLayer==0: return; self.dlg = LayerPropertiesDialog(newLayerMode=False) self.dlg.layerNameValue.set("Layer Properties") self.dlg.layerNameValue.set(data.getLayerName(currLayer)) initialOpacity = data.getLayerOpacity(currLayer) self.dlg.layerOpacityValue.set(initialOpacity) self.dlg.onOpacityChange.addHandler(self.onOpacitySliderChange) if self.dlg.execute()!=BaseDialog.BUTTON_OK: # dialog canceled: rollback changes and exit cmds.ngSkinLayer(e=True,id=currLayer,opacity=initialOpacity) return # dialog confirmed - apply changes data.setLayerName(currLayer,self.dlg.layerNameValue.get()) self.onExecuted.emit()
def volume_equalize(self, vert_id, value): """ i.e a volumetric match operation with a falloff. applies weight values inside the brush radius onto other vertices inside a spherical volume """ origin_vertex = '.'.join([self.selection_name[0], 'vtx[%s]']) % vert_id vertex_weight = self.ngs_weight_list[vert_id] v1 = cmds.pointPosition(origin_vertex) for i in range(len(self.ngs_weight_list)): target_weight = self.ngs_weight_list[i] if target_weight == vertex_weight: continue if i == vert_id: continue target_vertex = '.'.join([self.selection_name[0], 'vtx[%s]']) % i v2 = cmds.pointPosition(target_vertex) target_distance = sqrt((pow((v1[0] - v2[0]), 2)) + (pow((v1[1] - v2[1]), 2)) + (pow((v1[2] - v2[2]), 2))) if target_distance > (self.volumeThreshold * value): continue falloff = (self.volumeThreshold - target_distance) / self.volumeThreshold eq_weight = target_weight - (( (target_weight - vertex_weight) * value) * falloff) cmds.ngSkinLayer(paintIntensity=eq_weight) cmds.ngLayerPaintCtxSetValue(self.stroke_id, i, 1)
def execute(self): newIndex = cmds.ngSkinLayer(q=True,layerIndex=True)+(1 if self.isUp else -1) if newIndex<0: newIndex=0 cmds.ngSkinLayer(layerIndex=newIndex) self.updateEnabled() LayerEvents.layerListModified.emit() self.onExecuted.emit()
def setPaintMode(self, mode, intensity): ''' Sets paint mode (replace,add,..) and it's intensity :param mode: use :py:class:`PaintMode` constants for that ''' cmds.ngSkinLayer(paintOperation=mode, paintIntensity=intensity)
def paintCtxSetupProcedure(self, toolContext): # add and configure display nodes self.colorDisplayNode = cmds.ngSkinLayer(colorDisplayNode=1) self.updateColorDisplaySettings() cmds.ngSkinLayer(displayUpdate=True, paintingMode=1) self.updateHighlight()
def stroke_initialize(self): """ this function is executed before each brush stroke """ cmds.undoInfo(openChunk=True, undoName="paint stroke") get_stroke_id = ngLayerPaintCtxInitialize(self.mesh[0]) self.stroke_id = int(get_stroke_id.split(" ")[1]) cmds.ngSkinLayer(paintOperation=self.mode, paintIntensity=self.value) self.stroke_update() return self.surface, self.stroke_id
def layerOpacityChanged(self): currLayer = self.data.getCurrentLayer() if currLayer is not None: value = self.controls.layerOpacity.getValue() cmds.ngSkinLayer(e=True, id=currLayer, opacity=value) cmds.floatSlider(self.controls.sliderIntensity, e=True, value=value)
def layerSelectionChanged(self, *args): id = self.controls.layerDisplay.getSelectedID() if id is not None: cmds.ngSkinLayer(cl=id) #self.updateLayerList() self.updateInfluenceList() LayerEvents.layerSelectionChanged.emit() LayerEvents.currentLayerChanged.emit()
def layerSelectionChanged(self,*args): id = self.controls.layerDisplay.getSelectedID(); if id is not None: cmds.ngSkinLayer(cl=id) #self.updateLayerList() self.updateInfluenceList() LayerEvents.layerSelectionChanged.emit() LayerEvents.currentLayerChanged.emit()
def execute(self): influencesMapping = MllInterface.influencesMapToList(self.mapper.mapping) mirrorAxis = TransferWeightsTab.axisValues[self.mapper.distanceMatchRule.mirrorAxis] cmds.ngSkinLayer(initMirrorData=True, influencesMapping=influencesMapping, mirrorAxis=mirrorAxis) LayerDataModel.getInstance().mll.setManualMirrorInfluences(self.mapper.manualOverrides) LayerDataModel.getInstance().updateMirrorCacheStatus()
def execute(self): newIndex = cmds.ngSkinLayer(q=True, layerIndex=True) + (1 if self.isUp else -1) if newIndex < 0: newIndex = 0 cmds.ngSkinLayer(layerIndex=newIndex) self.updateEnabled() LayerEvents.layerListModified.emit() self.onExecuted.emit()
def gain_paint(self, vert_id, value): """ increases existing weight values but preserves empty weights """ vertex_weight = self.ngs_weight_list[vert_id] if vertex_weight == 0: return gain_weight = vertex_weight + (vertex_weight * value) gain_weight = min(gain_weight, 1) cmds.ngSkinLayer(paintIntensity=gain_weight) cmds.ngLayerPaintCtxSetValue(self.stroke_id, vert_id, 1)
def onOpacitySliderChange(self): ''' emits when opacity slider in the dialog changes value ''' currLayer = LayerDataModel.getInstance().getCurrentLayer() if currLayer is not None: cmds.ngSkinLayer(e=True, id=currLayer, opacity=self.dlg.layerOpacityValue.get())
def execute(self): influencesMapping = MllInterface.influencesMapToList( self.mapper.mapping) mirrorAxis = TransferWeightsTab.axisValues[ self.mapper.distanceMatchRule.mirrorAxis] cmds.ngSkinLayer(initMirrorData=True, influencesMapping=influencesMapping, mirrorAxis=mirrorAxis) LayerDataModel.getInstance().mll.setManualMirrorInfluences( self.mapper.manualOverrides) LayerDataModel.getInstance().updateMirrorCacheStatus()
def execInfluenceSelected(self, *args): id = self.controls.influenceDisplay.getSelectedID() if id is None: return if id == LayerUtils.PAINT_TARGET_MASK: cmds.ngSkinLayer(cpt="mask") else: cmds.ngSkinLayer(ci=id) #self.updateInfluenceList() LayerEvents.currentInfluenceChanged.emit() log.info("selected logical influence %d" % id)
def contrast_paint(self, vert_id, value): """ sharpens the edge of the active weight map """ vertex_weight = self.ngs_weight_list[vert_id] if not self.max_value > vertex_weight > self.min_value: return avg_value = (self.max_value + self.min_value) / 2 normalized_range = self.max_value - self.min_value dist_value = vertex_weight - avg_value modifier = norm.cdf(dist_value, loc=0, scale=(0.1 * normalized_range)) - vertex_weight contrast_weight = vertex_weight + (modifier * value) contrast_weight = max(self.min_value, min(contrast_weight, self.max_value)) cmds.ngSkinLayer(paintIntensity=contrast_weight) cmds.ngLayerPaintCtxSetValue(self.stroke_id, vert_id, 1)
def storeIntensitySettings(self): ''' stores intensity settings plugin-side ''' cmds.ngSkinLayer(paintOperation=PaintMode.PAINTMODE_REPLACE, paintIntensity=self.intensityReplace.get()) cmds.ngSkinLayer(paintOperation=PaintMode.PAINTMODE_ADD, paintIntensity=self.intensityAdd.get()) cmds.ngSkinLayer(paintOperation=PaintMode.PAINTMODE_SCALE, paintIntensity=self.intensityScale.get()) cmds.ngSkinLayer(paintOperation=PaintMode.PAINTMODE_SMOOTH, paintIntensity=self.intensitySmooth.get()) cmds.ngSkinLayer(paintOperation=PaintMode.PAINTMODE_SHARPEN, paintIntensity=self.intensitySharpen.get())
def getAvailableInfluences(self): result = [] layerInfluences = cmds.ngSkinLayer(q=True,listLayerInfluences=True) for index,i in enumerate(layerInfluences): if index%2!=0: result.append(i) return result
def getAvailableInfluences(self): result = [] layerInfluences = cmds.ngSkinLayer(q=True, listLayerInfluences=True) for index, i in enumerate(layerInfluences): if index % 2 != 0: result.append(i) return result
def execInfluenceSelected(self,*args): id = self.controls.influenceDisplay.getSelectedID(); if id is None: return if id==LayerUtils.PAINT_TARGET_MASK: cmds.ngSkinLayer(cpt="mask") else: cmds.ngSkinLayer(ci=id) #self.updateInfluenceList() LayerEvents.currentInfluenceChanged.emit() log.info("selected logical influence %d" % id)
def updateLayerList(self): if not self.data.layerDataAvailable: return layers = [] try: layers = cmds.ngSkinLayer(q=True, listLayers=True) currLayer = self.data.getCurrentLayer() except: pass newItems = [] argsPerLayer = 3 listIndex = 1 for i in xrange(len(layers) / argsPerLayer): layerID = int(layers[i * argsPerLayer]) layerName = layers[i * argsPerLayer + 1] indent = " " * int( layers[i * argsPerLayer + 2]) # indent, zero for base level enabled = "" if self.data.getLayerEnabled(layerID) else " [OFF]" newItems.append( IdToNameEntry(layerID, name=layerName, displayName=indent + layerName, suffix=enabled)) listIndex += 1 self.controls.layerDisplay.setItems(newItems, currLayer) LayerEvents.layerListUpdated.emit()
def updateInfluenceList(self): if not self.data.layerDataAvailable: return args = {} args['listLayerInfluences'] = True showAllInfluences = self.filterUi.radioAllInfluences.getValue() if not showAllInfluences: args['activeInfluences'] = True influences = cmds.ngSkinLayer(q=True,**args); currInfluence = LayerUtils.PAINT_TARGET_UNDEFINED if (len(influences)==0) else int(influences[0]) # first item in influences is current influence; # next is a list of pair "influence name", "influence id" filter = self.filterUi.createNameFilter() newItems = [] # append named targets if self.data.getCurrentLayer()>0: newItems.append(IdToNameEntry(LayerUtils.PAINT_TARGET_MASK, "[Layer Mask]")) names = influences[1::2] displayNames = InfluenceNameTransform().appendingOriginalName().transform(names) ids = map(int,influences[2::2]) for name,displayName,influenceId in zip(names,displayNames,ids): if filter.isMatch(displayName): newItems.append(IdToNameEntry(influenceId,name=name,displayName=displayName)) self.controls.influenceDisplay.setItems(newItems,currInfluence)
def updateLayerList(self): if not self.data.layerDataAvailable: return layers = [] try: layers = cmds.ngSkinLayer(q=True,listLayers=True); currLayer = self.data.getCurrentLayer() except: pass newItems = [] argsPerLayer = 3 listIndex = 1 for i in xrange(len(layers)/argsPerLayer): layerID = int(layers[i*argsPerLayer]) layerName = layers[i*argsPerLayer+1] indent = " "*int(layers[i*argsPerLayer+2]) # indent, zero for base level enabled = "" if self.data.getLayerEnabled(layerID) else " [OFF]" newItems.append(IdToNameEntry(layerID,name=layerName,displayName=indent+layerName,suffix=enabled)) listIndex+=1 self.controls.layerDisplay.setItems(newItems,currLayer) LayerEvents.layerListUpdated.emit()
def storeIntensitySettings(self): ''' stores intensity settings plugin-side ''' cmds.ngSkinLayer(paintOperation=PaintMode.PAINTMODE_REPLACE,paintIntensity=self.intensityReplace.get()) cmds.ngSkinLayer(paintOperation=PaintMode.PAINTMODE_ADD,paintIntensity=self.intensityAdd.get()) cmds.ngSkinLayer(paintOperation=PaintMode.PAINTMODE_SCALE,paintIntensity=self.intensityScale.get()) cmds.ngSkinLayer(paintOperation=PaintMode.PAINTMODE_SMOOTH,paintIntensity=self.intensitySmooth.get())
def ngSkinLayerCmd(self,*args,**kwargs): if self.mesh is not None: if self.mesh==self.TARGET_REFERENCE_MESH: kwargs['targetReferenceMesh'] = True else: args = (self.mesh,)+args self.log.info("ngSkinLayer %r %r",args,kwargs) return cmds.ngSkinLayer(*args,**kwargs)
def execInitMirrorData(self): kargs = {}; kargs["initMirrorData"] = True; kargs["influenceAssociationDistance"] = self.controls.influenceDistanceError.getValue() kargs["mirrorAxis"] = self.controls.mirrorAxis.getSelectedText() # create a comma-delimited prefix string, stripping away any spaces # that might be specified in the user input prefixes = self.controls.influencePrefixes.getValue() kargs["influenceAssociationPrefix"] = ",".join([prefix.strip() for prefix in prefixes.split(",")]) cmds.ngSkinLayer(**kargs) LayerDataModel.getInstance().updateMirrorCacheStatus() self.updateInfluenceList()
def ngSkinLayerCmd(self, *args, **kwargs): if self.mesh is not None: if self.mesh == self.TARGET_REFERENCE_MESH: kwargs['targetReferenceMesh'] = True else: args = (self.mesh, ) + args self.log.info("ngSkinLayer %r %r", args, kwargs) return cmds.ngSkinLayer(*args, **kwargs)
def getLayersCandidateFromSelection(self): ''' for given selection, returns mesh and skin cluster node names where skinLayer data is (or can be) attached. ''' try: return cmds.ngSkinLayer(q=True, ldt=True) except: return []
def getLayersCandidateFromSelection(self): ''' for given selection, returns mesh and skin cluster node names where skinLayer data is (or can be) attached. ''' try: return cmds.ngSkinLayer(q=True,ldt=True) except: return []
def configurePaintValues(self): ''' sets paint tool values from UI ''' oper,pvalue = self.getPaintModeValues() cmds.ngSkinLayer(paintOperation=oper,paintIntensity=pvalue.get()) 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, stampProfile=self.getSelectedBrushShape()) self.updateToTool()
def spread_paint(self, vert_id, value): """ smooth operation that only increases weight values """ vertex_weight = self.ngs_weight_list[vert_id] if vertex_weight >= self.max_value: return vertex_name = '.'.join([self.selection_name[0], 'vtx[%d]' % vert_id]) area_vertices = get_surrounding_verts(vertex_name) weight_list = [self.ngs_weight_list[int(x)] for x in area_vertices] weight_avg = sum(weight_list) / float(len(weight_list)) max_avg = max(weight_list) threshold = 0.01 / (value / 0.1) if weight_avg <= self.min_value and abs(weight_avg - vertex_weight) <= threshold: return weight_diff = abs(weight_avg - vertex_weight) spread_weight = vertex_weight + (weight_diff * value) spread_weight = min(spread_weight, max_avg) cmds.ngSkinLayer(paintIntensity=spread_weight) cmds.ngLayerPaintCtxSetValue(self.stroke_id, vert_id, 1)
def execInitMirrorData(self): kargs = {} kargs["initMirrorData"] = True kargs[ "influenceAssociationDistance"] = self.controls.influenceDistanceError.getValue( ) kargs["mirrorAxis"] = self.controls.mirrorAxis.getSelectedText() # create a comma-delimited prefix string, stripping away any spaces # that might be specified in the user input prefixes = self.controls.influencePrefixes.getValue() kargs["influenceAssociationPrefix"] = ",".join( [prefix.strip() for prefix in prefixes.split(",")]) cmds.ngSkinLayer(**kargs) LayerDataModel.getInstance().updateMirrorCacheStatus() self.updateInfluenceList()
def conceal_paint(self, vert_id, value): """ smooth operation that only lowers weight values """ vertex_weight = self.ngs_weight_list[vert_id] if vertex_weight <= self.min_value: return vertex_name = '{}.vtx[{}]'.format(self.selection_name[0], vert_id) area_vertices = get_surrounding_verts(vertex_name) weight_list = [self.ngs_weight_list[int(x)] for x in area_vertices] weight_avg = sum(weight_list) / float(len(weight_list)) min_avg = min(weight_list) threshold = 0.01 / (value / 0.1) if weight_avg >= self.max_value and abs(weight_avg - vertex_weight) <= threshold: return weight_diff = abs(weight_avg - vertex_weight) conceal_weight = vertex_weight * (1 - (weight_diff * value)) conceal_weight = max(conceal_weight, min_avg) cmds.ngSkinLayer(paintIntensity=conceal_weight) cmds.ngLayerPaintCtxSetValue(self.stroke_id, vert_id, 1)
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()
def ngSkinLayerCmd(self, *args, **kwargs): #import inspect #import sys #sys.__stderr__.write("\n".join(["stack: {1} ({2} in {3})".format(*i) for i in inspect.stack()])+"\n") if self.mesh is not None: if self.mesh == self.TARGET_REFERENCE_MESH: kwargs['targetReferenceMesh'] = True else: args = (self.mesh, ) + args # self.log.info("ngSkinLayer %r %r",args,kwargs) return cmds.ngSkinLayer(*args, **kwargs)
def isEnabled(self): ''' disable if reorder in given direction cannot happen ''' # do nothing if already disabled if not BaseLayerAction.isEnabled(self): return False try: currIndex = cmds.ngSkinLayer(q=True,layerIndex=True) except: return False # for "down", index has to be above 0 if not self.isUp: return currIndex>0 # for "up", index has to be <parent.numChildren-1 parent = cmds.ngSkinLayer(q=True,parent=True) # python does not support values with query params #numChildren = cmds.ngSkinLayer(id=parent,q=True,nch=True) numChildren = mel.eval("ngSkinLayer -id %d -q -nch" %parent) return currIndex<(numChildren-1)
def updateInfluenceList(self): influenceAssociations = cmds.ngSkinLayer(q=True, mirrorCacheInfluences=True) if influenceAssociations is None: influenceAssociations = [] self.items = [] while len(influenceAssociations) != 0: source = influenceAssociations.pop(0) destination = influenceAssociations.pop(0) automatic = int(influenceAssociations.pop(0)) == 0 item = self.findAssociation(self.items, destination, source, automatic) if item is not None: item.bidirectional = True else: item = InfluencesListEntry() item.source = source item.destination = destination item.bidirectional = False self.items.append(item) item.automatic = automatic def defaultSort(entry1, entry2): # priority for non-automatic entries if entry1.automatic != entry2.automatic: return 1 if entry1.automatic else -1 # priority for non-self references if entry1.isSelfReference() != entry2.isSelfReference(): return 1 if entry1.isSelfReference() else -1 # priority for bidirectional entries if entry1.bidirectional != entry2.bidirectional: return 1 if not entry1.bidirectional else -1 return cmp(entry1.source, entry2.source) self.items = sorted(self.items, defaultSort) newLabels = [] for i in self.items: newLabels.append(i.asLabel()) cmds.textScrollList(self.controls.influencesList, e=True, removeAll=True, append=newLabels)
def execute(self): data = LayerDataModel.getInstance() currLayer = data.getCurrentLayer() if currLayer is None or currLayer == 0: return self.dlg = LayerPropertiesDialog(newLayerMode=False) self.dlg.layerNameValue.set("Layer Properties") self.dlg.layerNameValue.set(data.getLayerName(currLayer)) initialOpacity = data.getLayerOpacity(currLayer) self.dlg.layerOpacityValue.set(initialOpacity) self.dlg.onOpacityChange.addHandler(self.onOpacitySliderChange) if self.dlg.execute() != BaseDialog.BUTTON_OK: # dialog canceled: rollback changes and exit cmds.ngSkinLayer(e=True, id=currLayer, opacity=initialOpacity) return # dialog confirmed - apply changes data.setLayerName(currLayer, self.dlg.layerNameValue.get()) self.onExecuted.emit()
def updateInfluenceList(self): influenceAssociations = cmds.ngSkinLayer(q=True,mirrorCacheInfluences=True) if influenceAssociations is None: influenceAssociations = [] self.items = [] while len(influenceAssociations)!=0: source = influenceAssociations.pop(0) destination = influenceAssociations.pop(0) automatic = int(influenceAssociations.pop(0))==0 item=self.findAssociation(self.items, destination, source,automatic) if item is not None: item.bidirectional = True else: item = InfluencesListEntry() item.source = source item.destination = destination item.bidirectional = False self.items.append(item) item.automatic = automatic def defaultSort(entry1,entry2): # priority for non-automatic entries if entry1.automatic!=entry2.automatic: return 1 if entry1.automatic else -1 # priority for non-self references if entry1.isSelfReference()!=entry2.isSelfReference(): return 1 if entry1.isSelfReference() else -1 # priority for bidirectional entries if entry1.bidirectional!=entry2.bidirectional: return 1 if not entry1.bidirectional else -1 return cmp(entry1.source, entry2.source) self.items = sorted(self.items,defaultSort) newLabels = [] for i in self.items: newLabels.append(i.asLabel()) cmds.textScrollList(self.controls.influencesList,e=True,removeAll=True,append=newLabels)
def updateHighlight(self, includeInfluence=True): ''' updates highlight - if painting, adds current influence to highlight ''' if cmds.currentCtx() != self.TOOL_PAINT: return if not LayerDataModel.getInstance().layerDataAvailable: return newHighlightItems = [] if includeInfluence: currentInfluence = cmds.ngSkinLayer(q=True, ci=True) # returns influence path, if current paint target has any if (len(currentInfluence) > 1): newHighlightItems.append(currentInfluence[1]) SelectHelper.replaceHighlight(newHighlightItems)
def updateHighlight(self,includeInfluence=True): ''' updates highlight - if painting, adds current influence to highlight ''' if cmds.currentCtx()!=self.TOOL_PAINT: return if not LayerDataModel.getInstance().layerDataAvailable: return newHighlightItems = [] if includeInfluence: currentInfluence = cmds.ngSkinLayer(q=True,ci=True) # returns influence path, if current paint target has any if (len(currentInfluence)>1): newHighlightItems.append(currentInfluence[1]) SelectHelper.replaceHighlight(newHighlightItems)
def doFlood(self): self.configurePaintValues() cmds.ngSkinLayer(paintFlood=True)
def removeLayer(self,id): cmds.ngSkinLayer(rm=True,id=id) LayerEvents.layerListModified.emit() LayerEvents.currentLayerChanged.emit()
def setLayerEnabled(self,layerId,enabled): cmds.ngSkinLayer(e=True,id=layerId,enabled=1 if enabled else 0)
def getCurrentLayer(self): return self.mll.getCurrentLayer() return cmds.ngSkinLayer(q=True,cl=True)
def layerOpacityChanged(self): currLayer = self.data.getCurrentLayer() if currLayer is not None: value = self.controls.layerOpacity.getValue() cmds.ngSkinLayer(e=True,id=currLayer,opacity=value) cmds.floatSlider(self.controls.sliderIntensity,e=True,value=value)
def layerNameChanged(self): currLayer = self.data.getCurrentLayer() if currLayer is not None: name = self.controls.layerName.getValue().strip() cmds.ngSkinLayer(e=True,id=currLayer,name=name) LayerEvents.nameChanged.emit()
def paintCtxCleanupProcedure(self,toolContext): cmds.ngSkinLayer(colorDisplayNode=0) cmds.ngSkinLayer(displayUpdate=True,paintingMode=0) self.updateHighlight(False)
def execute(self): cmds.ngSkinLayer(mtt=True)
def execute(self): cmds.ngSkinLayer(ttm=True)
def setCurrentLayer(self,id): cmds.ngSkinLayer(cl=id) LayerEvents.currentLayerChanged.emit()
def moveLayer(self,up=True): newIndex = cmds.ngSkinLayer(q=True,layerIndex=True)+(1 if up else -1) if newIndex<0: newIndex=0 cmds.ngSkinLayer(layerIndex=newIndex) LayerEvents.layerListModified.emit()
def setLayerName(self,id,name): cmds.ngSkinLayer(e=True,id=id,name=name) LayerEvents.nameChanged.emit()