Example #1
0
 def execute(newLayer):
     """ Switch to given RenderLayer """
     SwitchVisibleRenderLayerCmd.newLayer = newLayer
     with undo.CtxMgr(kSwitchVisibleRenderLayer % newLayer.name()):
         with namespace.RootNamespaceGuard():
             cmds.renderSetupSwitchVisibleRenderLayer()
     SwitchVisibleRenderLayerCmd.newLayer = None
Example #2
0
 def execute(cls, applicable):
     """ Applies an applicable (collection/override) after the layer was already set visible. """
     cls.applicable = applicable
     with undo.CtxMgr("Apply %s" % applicable.name()):
         with namespace.RootNamespaceGuard():
             cmds.renderSetupPostApply()
     cls.applicable = None
Example #3
0
def moveModel(modelToMove, destinationModel, destinationPosition):
    ''' Helper method to move a model from a location to antoher location '''
    with undo.CtxMgr(
            'Move %s to %s at position %d' %
        (modelToMove.name(), destinationModel.name(), destinationPosition)):
        sourceModel = modelToMove.parent()
        sourceModel.detachChild(modelToMove)
        destinationModel.attachChild(destinationPosition, modelToMove)
Example #4
0
    def getCorrespondingCollection(self, nodeName, selectedCollectionName):
        """ 
            The behavior is to look for Render Settings attribute to add the override
            in the Render Settings collection if it exists, then to use the selected
            collection; otherwise, to create a new collection containing the override.
        """
        
        # Search if the node is part of the render settings node list
        if collection.RenderSettingsCollection.containsNodeName(nodeName):
            return self.renderSettingsCollectionInstance()

        # Search if the node is part of the AOV selector list
        if collection.AOVCollection.containsNodeName(nodeName):
            aovCol = self.aovCollectionInstance()
            # Look for a child collection whose selection contains the node            
            for childColl in aovCol.getCollections():
                if childColl and childColl.containsNodeName(nodeName):
                    return childColl
                    
            # If it doesn't exist, create a new child node
            with undo.CtxMgr(kCreateAOVChildCollection % self.name()):
                # Create a new AOV child collection and put it last in the list
                callbacks = rendererCallbacks.getCallbacks(rendererCallbacks.CALLBACKS_TYPE_AOVS)
                aovName = callbacks.getAOVName(nodeName)
                coll = collection.create(aovName, collection.AOVChildCollection.kTypeId, aovName=aovName)
                aovCol.appendChild(coll)
                return coll

        coll = self.getCollectionByName(selectedCollectionName, True) if selectedCollectionName else None
        if coll:
            return coll
        
        selectorType = selector.SimpleSelector.kTypeName
        filterType, customFilter = selector.Filters.getFiltersFor(cmds.objectType(nodeName))
        def predicate(col):
            sel = col.getSelector()
            return sel.kTypeName == selectorType and \
                sel.getPattern() == "" and \
                len(sel.staticSelection) == 1 and nodeName in sel.staticSelection and \
                sel.getFilterType() == filterType and \
                (filterType != selector.Filters.kCustom or sel.getCustomFilterValue() == customFilter)
        def creator():
            col = collection.create(nodeName+"_col")
            col.setSelectorType(selectorType)
            sel = col.getSelector()
            sel.staticSelection.set([nodeName])
            sel.setFilterType(filterType)
            sel.setCustomFilterValue(customFilter)
            return col
        return self.findCollection(predicate, creator)
Example #5
0
    def renderSettingsCollectionInstance(self):
        """ Get the render settings collection instance for this render layer,
            creating it if it doesn't exists. """

        # Check if we already have a render settings on the list
        # We can only have zero or one lights collections so pick the first
        # one we find. It is always among the first ones on the list so this 
        # search is quick.
        settings = self._getTypedCollection(collection.RenderSettingsCollection.kTypeId)
        if not settings:
            with undo.CtxMgr(kCreateRenderSettingsCollection % self.name()):
                # Create a new render settings collection and put it first in the list
                settings = collection.create("RenderSettingsCollection", collection.RenderSettingsCollection.kTypeId)
                self.attachCollection(0, settings)

        return settings
Example #6
0
    def aovCollectionInstance(self):
        """ Get the AOV collection instance for this render layer,
            creating it if it doesn't exists as long as renderer 
            callbacks are registered for the current renderer. """

        # Check if we already have an AOV collection in the list
        # We can only have zero or one AOV collections so pick the first
        # one we find. It is always among the first ones on the list so this 
        # search is quick.
        aovCollection = self._getTypedCollection(collection.AOVCollection.kTypeId)
        if not aovCollection and not rendererCallbacks.getCallbacks(rendererCallbacks.CALLBACKS_TYPE_AOVS) is None:
            with undo.CtxMgr(kCreateAOVCollection % self.name()):
                # Create a new AOV collection and put it first in the list
                aovCollection = collection.create("AOVCollection", collection.AOVCollection.kTypeId)
                settings = self._getTypedCollection(collection.RenderSettingsCollection.kTypeId)
                self.attachCollection(0 if settings is None else 1, aovCollection)

        return aovCollection
Example #7
0
    def lightsCollectionInstance(self):
        """ Get the lights collection instance for this render layer,
            creating it if it doesn't exists. """

        # Check if we already have a lights collection on the list
        # We can only have zero or one lights collections so pick the first
        # one we find. It is always among the first ones on the list so this 
        # search is quick.
        lights = self._getTypedCollection(collection.LightsCollection.kTypeId)
        if not lights:
            # Create a new light collection and put it first in the list
            with undo.CtxMgr(kCreateLightsCollection % self.name()):
                lights = collection.create("lightsCollection", collection.LightsCollection.kTypeId)
                settings = self._getTypedCollection(collection.RenderSettingsCollection.kTypeId)
                aovCollection = self._getTypedCollection(collection.AOVCollection.kTypeId)
                self.attachCollection(0 if settings is None and aovCollection is None else \
                                      2 if not settings is None and not aovCollection is None else 1, lights)

        return lights
Example #8
0
    def attachCollection(self, pos, child):
        """ Attach a collection at a specific position """
        
        # This method appends the child collection to the requested position 
        # with the exception of 'special' collections which have dedicated 
        # positions. The collection order should always be: 
        # 1) the RenderSettings collection, 
        # 2) the AOV collection, 
        # 3) the Lights collection, 
        # and finally any 'normal' collections.

        colNames = [collection.RenderSettingsCollection.kTypeName,
                    collection.AOVCollection.kTypeName,
                    collection.LightsCollection.kTypeName]

                    
        hasCol = [t for t in colNames if self._getNamedCollection(t) is not None]
        
        # Error if a special collection child is already created.
        if child.typeName() in hasCol:
            raise Exception(kCollectionUnicity % child.typeName())

        if child.typeName() not in colNames:
            # If child is not a special collection, insert it after all special
            # collections.
            pos = max(len(hasCol), pos)
        else:
            # If child is a special collection, insert it as soon as possible.
            pos = 0
            for colName in colNames:
                if child.typeName() == colName:
                    break
                else:
                    if colName in hasCol:
                        pos += 1

        with undo.CtxMgr(kAttachCollection % (child.name(), self.name(), pos)):
            nodeList.insert(self, pos, child)
            self._collectionAttached(child)