Esempio n. 1
0
    def saveShadingEngine(shadingEngineObj, storagePlug):
        '''Save a connection to the shading engine node in the storage plug.

        This function unconditionally connects the shading engine to the
        storage plug.  It also stores the name of the shading engine as a full
        name with the namespace path in the storage plug's node, if the shading
        engine is not in the main scene.'''

        # Store the shading engine message attribute
        fnEngine = OpenMaya.MFnDependencyNode(shadingEngineObj)
        enginePlug = fnEngine.findPlug('message', False)
        utils.connect(enginePlug, storagePlug)

        # Deal with fact that material might be in a referenced file.
        storageNode = storagePlug.node()
        storageStrPlug = plug.findPlug(storageNode,
                                       MaterialOverride.kShadingEngineNameLong)

        if fnEngine.isFromReferencedFile:
            if storageStrPlug is None:
                properties = {'type': 'String', 'connectable': False}
                storageStrPlug = plug.Plug.createAttribute(
                    storageNode, MaterialOverride.kShadingEngineNameLong,
                    MaterialOverride.kShadingEngineNameShort, properties,
                    plug.kNotUndoable)

            storageStrPlug.value = fnEngine.name()
        elif storageStrPlug is not None:
            # Remove dynamic attribute.
            fn = OpenMaya.MFnDependencyNode(storageNode)
            fn.removeAttribute(storageStrPlug.plug.attribute())
Esempio n. 2
0
    def decode(self, encodedData):
        nodes = {}  # Avoid creating several time the same node
        for (key, value) in encodedData.items():
            (nodeName, attrName) = plug.Plug.getNames(key)
            node = None
            if nodeName in nodes:
                node = nodes[nodeName]
            else:
                try:
                    node = commonUtils.nameToNode(nodeName)
                    OpenMaya.MFnDependencyNode(node)
                except:
                    node = None
                nodes[nodeName] = node

            if node is None:
                # No guarantee that the default node exist
                OpenMaya.MGlobal.displayWarning(kDefaultNodeMissing % nodeName)
            else:
                plg = plug.findPlug(nodeName, attrName)
                if plg is None:
                    OpenMaya.MGlobal.displayWarning(kDefaultNodeAttrMissing %
                                                    (nodeName, attrName))
                else:
                    plg.value = value
Esempio n. 3
0
def canOverride(nodeName, attrName):
    ''' The method checks if an override could be 'applied' to the specified node/attribute '''
    # This function is called in TrenderSetup.cpp.  Note that we are
    # not verifying the connectable status of the plug, assuming render
    # setup can connect even to unconnectable plugs.
    plg = plug.findPlug(nodeName, attrName)
    return plg is not None \
           and plg.isOvrSupported() \
           and not plg.isLocked \
           and not commonUtils.isNodeInstance(plg.node(), override.Override)
Esempio n. 4
0
def hasOverrideApplied(nodeName, attrName):
    ''' The method checks if the specified node/attribute has an override applied'''
    # This function is called in TrenderSetup.cpp.
    plg = plug.findPlug(nodeName, attrName)
    if plg:
        # Check if this is an override nodes. They can't be overridden but they will have connections
        # to apply override nodes by design, and will return false positives below
        if commonUtils.isNodeInstance(plg.node(), override.Override):
            return False

        def _hasOverrideApplied(mplug):
            # Check if a value override is applied
            src = utils.plugSrc(mplug)
            if src and commonUtils.isNodeInstance(src.node(),
                                                  applyOverride.ApplyOverride):
                return True
            # Check if a connection override is applied
            dst = utils.plugDst(mplug)
            for d in (dst if dst else []):
                if commonUtils.isNodeInstance(d.node(),
                                              applyOverride.ApplyOverride):
                    return True

        # Check the attribute
        if _hasOverrideApplied(plg.plug):
            return True
        # Check any child attributes
        if plg.plug.isCompound:
            for idx in range(0, plg.plug.numChildren()):
                if _hasOverrideApplied(plg.plug.child(idx)):
                    return True
        # Check any parent attribute
        elif plg.plug.isChild:
            if _hasOverrideApplied(plg.plug.parent()):
                return True
    return False
Esempio n. 5
0
    def _srcStrPlug(self):
        '''Return a plug.Plug handle to the string representation of the
        source, if it exists, else None.'''

        return plug.findPlug(self._node, self._srcStrAttrNameLong)