コード例 #1
0
 def findCandidatePlug(sourceNode, destinationPlug):
     """ Return a plug to the first matching attribute in the candidate list.
     If no attribute is found, None is returned."""
     for attr in DragAndDropBehavior.kAttributeCandidates:
         plg = plug.Plug(sourceNode, attr)
         if plg.plug:
             destPlg = plug.Plug(destinationPlug)
             if plg.accepts(destPlg):
                 return plg.plug
     return None
コード例 #2
0
	def attributeHidden(self, column):
		attr = self.attributes.findAttributeByIndex(column)
		if attr:
			plg = plugModule.Plug(self.getShape(), attr.name)
			if plg.isValid:
				return plg.attribute().hidden
		return True
コード例 #3
0
ファイル: applyOverride.py プロジェクト: SouthAngel/vimSet
    def handleSetOverride(self, overriddenPlug, autoKeyed):
        """Handle a set override request.

        This is the chain of responsibility handler that sets (writes) the
        override value.  It assumes that canHandleSetOverride has returned
        true for this node.

        If autoKeyed is True, autoKeyframe will be given the override
        attribute that ultimately receives the value, so that a keyframe
        will be set on the override (or the original) if the autoKeyframe
        conditions to set a keyframe are met."""

        if self.isEnabled():
            self.setOverrideValue(overriddenPlug, autoKeyed)
        else:
            # Override is disabled, therefore apply override is disabled as
            # well: forward to next handler in the chain, if it exists,
            # else write to original, which will succeed because
            # canHandleSetOverride returned true.
            original = self.getOriginalPlug()
            previous = connectedSrc(original)
            if previous:
                # Forward to next handler in the chain.
                previous.handleSetOverride(overriddenPlug, autoKeyed)
            else:
                # Write to original.
                # Apply override nodes obtain all values in ui units because of the unit conversion nodes (if any)
                # => the original plug (that belongs to the apply override node) must be in ui units
                autoKey.setValue(original, plug.Plug(overriddenPlug).uiUnitValue, autoKeyed)
コード例 #4
0
    def connectAttrToAttr(self, sourcePlug, destinationPlug, force):
        """ Handle connection requests from source attribute to destination attribute. """

        if destinationPlug.isDestination and not force:
            # The destination is already connected and we're not allowed to break it
            # There is nothing we can do so early out here
            return

        sourceNode = sourcePlug.node()
        fnSourceNode = OpenMaya.MFnDependencyNode(sourceNode)
        fnDestinationNode = OpenMaya.MFnDependencyNode(destinationPlug.node())

        # If an explicit source attribute is given we think the user
        # wants to connect to that specific node.attribute.
        # If the node types doesn't match don't try to guess the right connection,
        # instead give an error message.
        # One exception is for material override where we can try to find the
        # shading engine for the source node.

        # Handle connection overrides node
        if fnDestinationNode.typeId == ConnectionOverride.kTypeId:
            # The value attribute is the only user connectable attribute
            if destinationPlug.partialName(
                    useLongNames=True) == ConnectionOverride.kAttrValueLong:
                DragAndDropBehavior.connect(sourcePlug, destinationPlug)

        # Handle shader overrides node
        elif fnDestinationNode.typeId == ShaderOverride.kTypeId:
            # The override attribute is the only user connectable attribute
            if destinationPlug.partialName(
                    useLongNames=True) == ConnectionOverride.kAttrValueLong:
                # Source must be a surface shader
                if DragAndDropBehavior.isMatchingClass(sourceNode,
                                                       "shader/surface"):
                    DragAndDropBehavior.connect(sourcePlug, destinationPlug)
                else:
                    DragAndDropBehavior.raiseWarning(
                        DragAndDropBehavior.kErrorMsg_NoSurfaceShader +
                        " (%s)" % fnSourceNode.name())

        # Handle material overrides node
        elif fnDestinationNode.typeId == MaterialOverride.kTypeId:
            # The value attribute is the only user connectable attribute
            if destinationPlug.partialName(
                    useLongNames=True) == ConnectionOverride.kAttrValueLong:
                # For material override we ignore which plug was given on the source node,
                # we just want the shading group for the source node.
                # Find the shading group for this node (searching downstream if needed)
                sgNode = DragAndDropBehavior.findNode(
                    sourceNode,
                    typeId=OpenMaya.MFn.kShadingEngine,
                    acceptor=lambda obj: OpenMaya.MFnDependencyNode(obj).name(
                    ) not in self.kNodeSearchIgnoreList)
                if sgNode:
                    sourcePlug = plug.Plug(sgNode, 'message').plug
                    DragAndDropBehavior.connect(sourcePlug, destinationPlug)
                else:
                    DragAndDropBehavior.raiseWarning(
                        DragAndDropBehavior.kErrorMsg_NoShadingGroupFound +
                        " (%s)" % fnSourceNode.name())
コード例 #5
0
 def finalize(self, ovrValuePlug):
     # Create the "original" plug by cloning the attribute of the given plug
     plg = plug.Plug(ovrValuePlug)
     # We don't want the clone attribute to be undoable (because it will break
     # the undo/redo for switch render layer)
     plg.cloneAttribute(self.thisMObject(),
                        ApplyConnectionOverride.kOriginalLong,
                        ApplyConnectionOverride.kOriginalShort,
                        plug.kNotUndoable)
     return self.getOriginalPlug() is not None
コード例 #6
0
ファイル: autoKey.py プロジェクト: SouthAngel/vimSet
def setValue(mPlug, value, autoKey):
    """Set the argument value on the argument plug, setting an
    autoKeyframe on that attribute, if autoKey is True.

    The plug argument must be an MPlug."""

    if autoKey:
        cmds.autoKeyframe(edit=True, addAttr=mPlug.name())

    plug.Plug(mPlug).value = value
コード例 #7
0
    def onAttributeChanged(self, msg, plg, otherPlug, clientData):
        if msg & OpenMaya.MNodeMessage.kAttributeSet:
            # Plug itself might be overridden, or its parent might be
            # overridden.
            plugs = [plg]
            if plg.isChild:
                plugs.append(plg.parent())

            for p in plugs:
                # Get rid of uninteresting plugs as quickly as possible.
                #
                # 1) Overridden plug is connected, by definition.
                if not p.isConnected:
                    continue

                # 2) If plug's node is a render setup node, not interesting.
                nodeFn = OpenMaya.MFnDependencyNode(p.node())
                if typeIDs.isRenderSetupType(nodeFn.typeId):
                    continue

                # Check if the plug is connected to an apply override node.
                src = utils.plugSrc(p)
                if src is None:
                    continue

                node = OpenMaya.MFnDependencyNode(src.node()).userNode()

                if not isinstance(node, applyOverride.ApplyOverride):
                    continue

                # Query the autoKeyer only if a plug is interesting.
                # Autokeyer should not be listening during undo / redo,
                # only when the attribute is initially set.
                if 'autoKeyedAttr' not in locals():
                    inUndoRedo = OpenMaya.MGlobal.isUndoing() or \
                                 OpenMaya.MGlobal.isRedoing()
                    autoKeyedAttr = set() if inUndoRedo else autoKey.autoKeyed(
                    )

                autoKeyed = p.name() in autoKeyedAttr

                # At this point we know the node can handle the override.
                # No need to call ApplyValueOverride.canHandleSetOverride
                # to validate, because that method has been called by
                # isPassiveOutput, which returned true to allow the
                # attribute to be changed and therefore end up in this
                # notification.
                node.handleSetOverride(p, autoKeyed)
                # all plugs between override and target plug should never be dirty
                plug.Plug(p).value

                break
コード例 #8
0
ファイル: utils.py プロジェクト: SouthAngel/vimSet
def transferPlug(src, dst):
    """ Transfer the connection or value set on plug 'src' on to the plug 'dst'."""
    if _isDestination(src):
        # src is connected
        # so transfer the connection
        _transferConnectedPlug(src, dst)
    else:
        # src is not connected
        # Break any connection on dst and then
        # transfer value instead
        if dst.isDestination:
            disconnectDst(dst)
        plug.Plug(dst).copyValue(src)
コード例 #9
0
ファイル: applyOverride.py プロジェクト: SouthAngel/vimSet
    def setOverrideValue(self, overriddenPlug, autoKeyed):
        def computeOutput(orig, mult, offset):
            return orig * mult + offset

        # Get our current offset value.
        offset0 = plug.Plug(self.getOffsetPlug()).value

        # Get our current output value, and the desired output value.
        # This is the line we wanted to write, but the output doesn't seem
        # to change when the parent (compound) attribute is written to.
        # outValue0 = plug.Plug(self.getOutputPlug()).value

        # Instead, repeat the output computation from compute().
        orig = plug.Plug(self.getOriginalPlug()).value
        mult = plug.Plug(self.getMultiplyPlug()).value

        outValue0 = map(computeOutput, orig, mult, offset0) if \
                  isinstance(orig, list) else \
                  computeOutput(orig, mult, offset0)

        # Apply override nodes obtain all values in ui units because of the unit conversion nodes (if any)
        # => all values must be read and computation must be performed in ui units
        ovrPlg = plug.Plug(overriddenPlug)
        outValue1 = ovrPlg.uiUnitValue

        # Compute the new offset, and set it onto the override.
        def computeOffset(out1, out0, offset0):
            return out1 - out0 + offset0

        offset1 = map(computeOffset, outValue1, outValue0, offset0) if \
                  isinstance(outValue0, list) else \
                  computeOffset(outValue1, outValue0, offset0)

        # convert to internal units since autoKey.setValue expects internal units
        offset1 = plug.toInternalUnits(ovrPlg.type, offset1)
        autoKey.setValue(self.override()._getOffsetPlug(), offset1, autoKeyed)
コード例 #10
0
 def encode(self):
     attrs = {}
     for name in self.getNodes():
         node = commonUtils.nameToNode(name)
         nodeFn = None
         try:
             nodeFn = OpenMaya.MFnDependencyNode(node)
         except:
             # No guarantee that the default node exist
             OpenMaya.MGlobal.displayWarning(kDefaultNodeMissing % name)
         else:
             for attrIdx in xrange(nodeFn.attributeCount()):
                 plg = plug.Plug(node, nodeFn.attribute(attrIdx))
                 if plg.type is not plug.Plug.kInvalid and plg.name not in self._plugsToIgnore:
                     attrs[plg.name] = plg.value
     return attrs
コード例 #11
0
def transferPlug(src, dst):
    """ Transfer the connection or value set on plug 'src' on to the plug 'dst'."""

    # Adapted from utils.transferPlug.  We turn reference edits on when
    # restoring the original only for connected attributes, not setAttr:
    # render setup should not create spurious setAttr edits when restoring
    # unconnected attributes of referenced nodes.  These should simply
    # revert back to the value in the reference file, or to any
    # previously-existing reference edit.
    if utils._isDestination(src):
        # src is connected so transfer the connection.
        _transferConnectedPlug(src, dst)
    else:
        # src is not connected.  Break any connection on dst and then
        # transfer value instead.
        if dst.isDestination:
            utils.disconnectDst(dst)
        plug.Plug(dst).copyValue(src)
コード例 #12
0
    def _getTemplateArgs(cls, obj):
        '''Returns a dictionary mapping the template arg name to its replacement for the input MObject 
        to create a shading node override for.
        Keys are : ('propertyType', 'propertyValue', 'cgType', 'hlslType', 'glslType')
        => {propertyType} in the fragment template will be replaced by its mapped value, and so on.'''

        plg = plug.Plug(
            OpenMaya.MFnDependencyNode(obj).userNode().getOriginalPlug())

        keys = ('propertyType', 'propertyValue', 'cgType', 'hlslType',
                'glslType')
        values = ApplyOverrideShadingNodeOverride._plugTypeToTemplateArgs[plg.type] \
            if not plg.isVector else \
            { 2 : ('float2', '0,0', 'float2', 'float2', 'vec2'),
              3 : ('float3', '0,0,0', 'float3', 'float3', 'vec3')}[len(plg.type)]

        args = {key: value for key, value in itertools.izip(keys, values)}
        args['fragmentName'] = cls.__name__ + str(
            args['propertyType']) + "Fragment"
        return args
コード例 #13
0
    def _dropCb(self, dragControl, dropControl, messages, x, y, dragType):
        # Create override.  We are expecting a node.plug string as the
        # first element of the messages list.
        if not messages or not isinstance(messages[0], basestring):
            return

        tokens = messages[0].split('.')
        attrName = tokens[-1]
        nodeName = tokens[0]

        model = self.item().model
        relative = not self.isAbsoluteMode()

        ov = model.createRelativeOverride(nodeName, attrName) if relative \
             else model.createAbsoluteOverride(nodeName, attrName)

        if relative and isinstance(ov, override.AbsOverride):
            # We asked for relative, got absolute.  Warn the user.
            rsPlug = modelPlug.Plug(nodeName, attrName)
            msg = kRelativeWarning % (attrName, rsPlug.localizedTypeString())
            cmds.warning(msg)
コード例 #14
0
	def attributeType(self, column):
		attr = self.attributes.findAttributeByIndex(column)
		if not attr:
			return plugModule.Plug.kInvalid
		plug = commonUtils.findPlug(self.getShape(), attr.name)
		return plugModule.Plug(plug).type if plug else plugModule.Plug.kInvalid
コード例 #15
0
    def connectNodeToAttr(self, sourceNode, destinationPlug, force):
        """ Handle connection requests from source node to destination attribute. """

        if destinationPlug.isDestination and not force:
            # The destination is already connected and we're not allowed to break it
            # There is nothing we can do so early out here
            return

        fnSourceNode = OpenMaya.MFnDependencyNode(sourceNode)
        fnDestinationNode = OpenMaya.MFnDependencyNode(destinationPlug.node())

        # No explicit source attribute is given so we need to guess what
        # attribute to use. Also if the source node type doesn't match in this
        # case we try to find a matching node downstream.
        # If no valid node or attribute is found we fail with an error message.

        # Handle connection overrides node
        if fnDestinationNode.typeId == ConnectionOverride.kTypeId:
            # The value attribute is the only user connectable attribute
            if destinationPlug.partialName(
                    useLongNames=True) == ConnectionOverride.kAttrValueLong:
                # Search for a valid source plug.
                sourcePlug = DragAndDropBehavior.findCandidatePlug(
                    sourceNode, destinationPlug)
                if sourcePlug:
                    DragAndDropBehavior.connect(sourcePlug, destinationPlug)
                else:
                    DragAndDropBehavior.raiseWarning(
                        DragAndDropBehavior.kErrorMsg_NoAttributeFound +
                        " (%s)" % fnSourceNode.name())

        # Handle shader overrides node
        elif fnDestinationNode.typeId == ShaderOverride.kTypeId:
            # The value attribute is the only user connectable attribute
            if destinationPlug.partialName(
                    useLongNames=True) == ConnectionOverride.kAttrValueLong:
                # Find the surface shader for this node (searching downstream if needed)
                surfaceShaderNode = DragAndDropBehavior.findNode(
                    sourceNode,
                    acceptor=lambda obj: DragAndDropBehavior.isMatchingClass(
                        obj, classificationString="shader/surface"))
                if surfaceShaderNode:
                    # Search for a valid source plug
                    sourcePlug = DragAndDropBehavior.findCandidatePlug(
                        surfaceShaderNode, destinationPlug)
                    if sourcePlug:
                        DragAndDropBehavior.connect(sourcePlug,
                                                    destinationPlug)
                    else:
                        DragAndDropBehavior.raiseWarning(
                            DragAndDropBehavior.kErrorMsg_NoAttributeFound +
                            " (%s)" % OpenMaya.MFnDependencyNode(
                                surfaceShaderNode).name())
                else:
                    DragAndDropBehavior.raiseWarning(
                        DragAndDropBehavior.kErrorMsg_NoSurfaceShaderFound +
                        " (%s)" % fnSourceNode.name())

        # Handle material overrides node
        elif fnDestinationNode.typeId == MaterialOverride.kTypeId:
            # The value attribute is the only user connectable attribute
            if destinationPlug.partialName(
                    useLongNames=True) == ConnectionOverride.kAttrValueLong:
                # Find the shading group for this node (searching downstream if needed)
                sgNode = DragAndDropBehavior.findNode(
                    sourceNode,
                    typeId=OpenMaya.MFn.kShadingEngine,
                    acceptor=lambda obj: OpenMaya.MFnDependencyNode(obj).name(
                    ) not in self.kNodeSearchIgnoreList)
                if sgNode:
                    sourcePlug = plug.Plug(sgNode, 'message').plug
                    DragAndDropBehavior.connect(sourcePlug, destinationPlug)
                else:
                    DragAndDropBehavior.raiseWarning(
                        DragAndDropBehavior.kErrorMsg_NoShadingGroupFound +
                        " (%s)" % fnSourceNode.name())
コード例 #16
0
	def _setPlugValue(self, plug, value):
		""" Set the value of a plug. """
		plugHandle = plugModule.Plug(plug)
		plugHandle.value = value
コード例 #17
0
	def _getPlugValue(self, plug):
		""" Get the value of a plug. """
		plugHandle = plugModule.Plug(plug)
		return plugHandle.value