def instance(): if ExportListener._instance is None: import maya.app.renderSetup.model.renderSetup as renderSetup assert renderSetup.hasInstance( ), "Should not create an ExportListener instance without Render Setup instance." ExportListener._instance = ExportListener() return ExportListener._instance
def _updateCollections(self): if renderSetup.hasInstance(): lightName = om.MFnDagNode(self.mayaHandle.object()).name() renderLayers = renderSetup.instance().getRenderLayers() for renderLayer in renderLayers: col = LightSource._findLightCollection(renderLayer, lightName) if col: col.getSelector().setStaticSelection(self.getShapeName())
def renderSetupPreDelete(self): """Called just before the render setup node is deleted. Unregisters from visible render layer and attribute change observation.""" # Called from aboutToDelete, so not guaranteed we have an instance. if renderSetup.hasInstance(): rs = renderSetup.instance() if rs.hasActiveLayerObserver(self.onRenderLayerChanged): rs.removeActiveLayerObserver(self.onRenderLayerChanged) self.removeAttributeChangeObservation()
def __init__(self): super(OverriddenAttributeManager, self).__init__() self._cbId = None # Register to observe creation / destruction of render setup. renderSetup.addObserver(self) # Register to observe visible render layer changes. if renderSetup.hasInstance(): self.renderSetupAdded() # If we're already in a layer other than master, observe attribute # changes. if not isDefaultRenderLayerVisible(): self.addAttributeChangeObservation()
def nameChanged(self, oldName): # Check in each render layer if a collection for this light source exists. # If so we need to update it to use the new name if renderSetup.hasInstance(): renderLayers = renderSetup.instance().getRenderLayers() for renderLayer in renderLayers: col = LightSource._findLightCollection(renderLayer, oldName) if col: # Rename the collection and reset its static selection to match the new name newLightName = om.MFnDagNode( self.mayaHandle.object()).name() newCollectionName = LIGHT_COLLECTION_PREFIX + newLightName + LIGHT_COLLECTION_SUFFIX col.setName(newCollectionName) col.getSelector().setStaticSelection(self.getShapeName()) # Call parent class super(LightSource, self).nameChanged(oldName)
def _isMemberOfVisibleLayer(self): """ Check if the light source is a member of the visible layer. """ # If no render setuo active the light is always visible if not renderSetup.hasInstance(): return True visibleLayer = renderSetup.instance().getVisibleRenderLayer() # All lights are always members of default layer if visibleLayer is renderSetup.instance().getDefaultRenderLayer(): return True legacyLayerName = visibleLayer._getLegacyNodeName() legacyLayerPlug = commonUtils.nameToPlug(legacyLayerName + ".renderInfo") if not legacyLayerPlug: return True # The light source is a member if the shape node or any parent node is # connected to the legacy render layer plug # # NOTE: # Lights does not support instancing so we don't need to travers all # dag paths here. If we ever add support for instancing light sources # this needs to change. # path = om.MDagPath.getAPathTo(self.shapeHandle.object()) while (path.length() > 0): # Check if the node is connected to the render layer fnNode = om.MFnDependencyNode(path.node()) arrayPlug = fnNode.findPlug("renderLayerInfo", False) numElements = arrayPlug.evaluateNumElements() for i in range(numElements): elemPlug = arrayPlug.elementByLogicalIndex(i) if elemPlug.isDestination and elemPlug.source( ) == legacyLayerPlug: return True # Move to parent node path.pop(1) return False
def _syncLegacyRenderLayers(layerName): # Suspend and resume undo logging around this callback # It will be called for any changes to the data model as well as the undo of any changes so # it does not need to handle undo itself. with undo.SuspendUndo(): # Update visibility as required import maya.app.renderSetup.model.renderSetup as renderSetupModel # Make sure the render setup system is still in use # This function is called deferred and the system might have been # shut down before we reach this point if not renderSetupModel.hasInstance(): return renderLayers = renderSetupModel.instance().getRenderLayers() for renderLayer in renderLayers: # When called during a file reference load / unload, node names # are surprisingly returned as absolute names, qualified with a # leading colon. Make sure name matching handles this. if renderLayer.name().lstrip(':') == layerName.lstrip(':') \ and renderLayer.isVisible(): renderLayer._updateLegacyRenderLayerVisibility() break
def openEditor(self, layer=None): defaultLayer = renderSetup.instance().getDefaultRenderLayer( ) if renderSetup.hasInstance() else None layer = layer if layer is not None and layer != defaultLayer else None return openEditorUI(layer)
def openEditorUI(layer=None, restore=False): """ Opens the editor window, creating it if needed """ global _editorInstance if restore == True: parent = mui.MQtUtil.getCurrentParent() mode = Editor.EDITOR_GLOBAL_MODE if layer is None else Editor.EDITOR_LAYER_MODE # Make sure to not reuse an editor that has been disposed # Should never happen, but in case something goes wrong # when the editor is closed this is an extra security check # to resolve that situation if _editorInstance and _editorInstance.centralWidget.disposed: _editorInstance.dispose() _editorInstance = None # Create editor instance if it doesn't exists if not _editorInstance: # Make sure render setup plugin is loaded cmds.loadPlugin("renderSetup", quiet=True) # Create the editor _editorInstance = Editor() _editorInstance.setObjectName('MayaLightEditorWindow') # Monitor changes to the editor for active border highlighting _editorInstance.visibilityChanged.connect( theLightEditorUI.visibilityUpdate) if layer and renderSetup.hasInstance( ) and mode == Editor.EDITOR_LAYER_MODE and not layer.isVisible(): # Make sure the layer is visible if we are in layer mode renderSetup.instance().switchToLayer(layer) _editorInstance.setEditorMode(mode, layer) # Since the light editor does not reopen, but opens a new one everytime. # Delete the old control state so that it doesn't have a false representation of the # control and creates a MAYA-71701 controlStateName = _editorInstance.objectName() + 'WorkspaceControl' hasState = cmds.workspaceControlState(controlStateName, q=True, exists=True) if hasState: cmds.workspaceControlState(controlStateName, remove=True) if restore == True: mixinPtr = mui.MQtUtil.findControl(_editorInstance.objectName()) mui.MQtUtil.addWidgetToMayaLayout(long(mixinPtr), long(parent)) else: _editorInstance.show( dockable=True, retain=False, plugins="renderSetup", uiScript= 'import maya.app.renderSetup.views.lightEditor.editor as editor\neditor.openEditorUI(restore=True)', closeCallback= 'import maya.app.renderSetup.views.lightEditor.editor as editor\neditor.editorClosed()' ) _editorInstance.visibilityChanged.emit() return _editorInstance
def _removeLayerObserver(self): if renderSetup.hasInstance() and self._layerObserverAdded: renderSetup.instance().removeActiveLayerObserver( self._onRenderLayerChangeCB) self._layerObserverAdded = False
def _addLayerObserver(self): if renderSetup.hasInstance() and not self._layerObserverAdded: renderSetup.instance().addActiveLayerObserver( self._onRenderLayerChangeCB) self._layerObserverAdded = True
def isDefaultRenderLayerVisible(): return not renderSetup.hasInstance() or \ renderSetup.instance().getDefaultRenderLayer().isVisible()
def isActive(self): return renderSetupModel.hasInstance() and \ renderSetupModel.instance().getDefaultRenderLayer().isVisible() and \ cmds.window('unifiedRenderGlobalsWindow', exists=True) and \ cmds.window('unifiedRenderGlobalsWindow', query=True, visible=True)
def _model(self): return renderSetupModel.instance().getDefaultRenderLayer( ) if renderSetupModel.hasInstance() else None
def removeActiveLayerObserver(self): if self._isActiveLayerObserver and renderSetupModel.hasInstance(): renderSetupModel.instance().removeActiveLayerObserver( self._onRenderLayerChangeCB) self._isActiveLayerObserver = False
def addActiveLayerObserver(self): if not self._isActiveLayerObserver and renderSetupModel.hasInstance(): renderSetupModel.instance().addActiveLayerObserver( self._onRenderLayerChangeCB) self._isActiveLayerObserver = True