예제 #1
0
    def _getTypedCollection(self, typeId):
        '''Get the first collection with the argument type ID.'''

        for col in nodeList.forwardListGenerator(self):
            if col.typeId() == typeId:
                return col
        return None
예제 #2
0
def nodeListChildren(node):
    """Utility function to iterate on children of a data model node.

    If the node has no children, an empty list is returned."""

    return nodeList.forwardListGenerator(node) if isinstance(
        node, nodeList.ListBase) else []
예제 #3
0
    def _getNamedCollection(self, typeName):
        '''Get the first collection with the argument type name.'''

        for col in nodeList.forwardListGenerator(self):
            if col.typeName() == typeName:
                return col
        return None
예제 #4
0
 def hasDefaultCollection(self):
     """ Get the default collection where newly created nodes are placed """
     defaultCollectionName = "_untitled_"
     for col in nodeList.forwardListGenerator(self):
         if col.name().startswith(defaultCollectionName):
             return True
     return False
예제 #5
0
    def apply(self):
        """Apply overrides for all collections in this render layer."""
        with profiler.ProfilerMgr('RenderLayer::applyOverrides'):
            for col in nodeList.forwardListGenerator(self):
                col.apply()
                RenderLayerSwitchObservable.getInstance().notifyRenderLayerSwitchObserver()

        self.needsApplyUpdate = False
예제 #6
0
 def getDefaultCollection(self):
     """ Get the default collection where newly created nodes are placed """
     defaultCollectionName = "_untitled_"
     for col in nodeList.forwardListGenerator(self):
         if col.name().startswith(defaultCollectionName):
             return col
     col = collection.create(defaultCollectionName)
     self.attachCollection(self.getFirstCollectionIndex(), col)
     return col
예제 #7
0
    def getCollectionByName(self, collectionName, nested=False):
        """ Look for an existing collection by name """
        if not collectionName:
            raise Exception(kInvalidCollectionName)

        for child in nodeList.forwardListGenerator(self):
            if child.name() == collectionName:
                return child
            elif nested and child.typeId() == typeIDs.collection:
                child2 = child.getCollectionByName(collectionName, True)
                if child2:
                    return child2

        raise Exception(kUnknownCollection % (collectionName, self.name()))
예제 #8
0
def memberTraversal(node):
    """Traverse render setup node children to determine layer membership.

    During the collection traversal to determine membership, we consider
    the isolate select state of the layer and of collections, and prune
    those collections that are not included by isolate select.

    If the node has no children, an empty list is returned."""

    # If the node has no children, return an empty list.
    if not isinstance(node, nodeList.ListBase):
        return []

    # If the node is not a collection, return its children.
    if not isinstance(node, collection.Collection):
        return nodeList.forwardListGenerator(node)

    # The node is a collection.  If it's disabled, return an empty list, else
    # return its children.
    return node.getCollections() if node.isEnabled() else []
예제 #9
0
 def getRenderLayers(self):
     return list(nodeList.forwardListGenerator(self))
예제 #10
0
    def _findPlug(self, attr, writeMode=False):
        """ Overridden from parent class, since for lights we 
		want to handle Render Setup overrides here.

		The method queries for the plug to use then reading or writing 
		a value from/to the light source. The plug to use is different 
		depending on if the light editor is in layer mode or not and 
		if the attribute has overrides applied or not.

		For example, if we are in layer mode and the attribute has an 
		override applied we want the value plug on the override node, 
		since we want to change the override value in that case.

		See the code comments below for the different cases we need
		to handle.

		"""
        # Find the ordinary plug on the light source
        plug = super(LightSource, self)._findPlug(attr, writeMode)
        if not plug:
            return None

        # Early out if we are in read mode, since we should
        # use the plug as is in that case
        if not writeMode:
            return plug

        # We are in write mode so we must find the right plug
        # to write to, depending on the light editor mode and
        # on the status of the active layer (if any)

        renderLayer = self.model.getRenderLayer()

        if renderLayer and self.model.allowOverride():
            # We are in render layer mode. This means that all changes should
            # be done in the form of overrides. If an override exists already
            # we use it, but otherwise we need to create one.

            # Check if an override is currently applied
            if plug.isDestination:
                source = plug.source()
                fn = om.MFnDependencyNode(source.node())
                if isinstance(fn.userNode(), applyOverrideModel.ApplyOverride):
                    # An apply override was found, so we should return
                    # the value plug on the corresponding override node
                    return fn.userNode().override()._getAttrValuePlug()

            # No override applied, so now we need to check if an override
            # exists but has not been applied yet.

            lightName = om.MFnDagNode(self.mayaHandle.object()).name()

            # Check if a collection for this light already exists
            collection = LightSource._findLightCollection(
                renderLayer, lightName)
            if collection is None:
                # Create it since it was not found
                collectionName = LIGHT_COLLECTION_PREFIX + lightName + LIGHT_COLLECTION_SUFFIX
                collection = renderLayer.lightsCollectionInstance(
                ).createCollection(collectionName)
                collection.getSelector().setStaticSelection(
                    self.getShapeName())

            # Check if the override for this attribute already exists
            override = None
            for ovr in nodeList.forwardListGenerator(collection):
                if ovr.attributeName() == attr.name:
                    override = ovr
                    break
            if not override:
                # Create it since it was not found
                overrideName = lightName + "_" + attr.name
                override = collection.createOverride(overrideName,
                                                     typeIDs.absOverride)
                override.finalize(self.getShapeName() + "." + attr.name)

                # Apply the override directly if the layer is active
                if renderLayer.isVisible():
                    selectedNodeNames = collection.getSelector(
                    ).getAbsoluteNames()
                    override.apply(selectedNodeNames)

            # Return the value plug for the override
            return override._getAttrValuePlug()

        else:
            # We are in global scene mode
            # If there are any overrides applied return the original
            # plug of the last override apply node. Otherwise just
            # return the light source plug
            if plug.isDestination:
                source = plug.source()
                fn = om.MFnDependencyNode(source.node())
                if isinstance(fn.userNode(), applyOverrideModel.ApplyOverride):
                    aoIter = fn.userNode()
                    for i in applyOverrideModel.reverseGenerator(
                            aoIter.getOriginalPlug()):
                        aoIter = i
                    return aoIter.getOriginalPlug()
            return plug
예제 #11
0
 def acceptImport(self):
     super(RenderLayer, self).acceptImport()
     for collection in nodeList.forwardListGenerator(self):
         collection.acceptImport()
예제 #12
0
 def hasCollection(self, collectionName):
     for collection in nodeList.forwardListGenerator(self):
         if collection.name() == collectionName:
             return True
     return False
예제 #13
0
 def getCollections(self):
     """ Get list of all existing Collections """
     return list(nodeList.forwardListGenerator(self))