예제 #1
0
        public static void DepthFirstCollectNodesFromNode(List <AbstractMaterialNode> nodeList, AbstractMaterialNode node,
                                                          IncludeSelf includeSelf = IncludeSelf.Include, List <KeyValuePair <ShaderKeyword, int> > keywordPermutation = null)
        {
            // no where to start
            if (node == null)
            {
                return;
            }

            // already added this node
            if (nodeList.Contains(node))
            {
                return;
            }

            IEnumerable <int> ids;

            // If this node is a keyword node and we have an active keyword permutation
            // The only valid port id is the port that corresponds to that keywords value in the active permutation
            if (node is KeywordNode keywordNode && keywordPermutation != null)
            {
                var valueInPermutation = keywordPermutation.Where(x => x.Key == keywordNode.keyword).FirstOrDefault();
                ids = new int[] { keywordNode.GetSlotIdForPermutation(valueInPermutation) };
            }
예제 #2
0
        public static void CollectNodesNodeFeedsInto(List <AbstractMaterialNode> nodeList, AbstractMaterialNode node, IncludeSelf includeSelf = IncludeSelf.Include)
        {
            if (node == null)
            {
                return;
            }

            if (nodeList.Contains(node))
            {
                return;
            }

            foreach (var slot in node.GetOutputSlots <ISlot>())
            {
                foreach (var edge in node.owner.GetEdges(slot.slotReference))
                {
                    var inputNode = node.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid);
                    CollectNodesNodeFeedsInto(nodeList, inputNode);
                }
            }
            if (includeSelf == IncludeSelf.Include)
            {
                nodeList.Add(node);
            }
        }
예제 #3
0
        public static void DepthFirstCollectNodesFromNode <T>(List <T> nodeList, T node, IncludeSelf includeSelf = IncludeSelf.Include, List <int> slotIds = null)
            where T : AbstractMaterialNode
        {
            // no where to start
            if (node == null)
            {
                return;
            }

            // already added this node
            if (nodeList.Contains(node))
            {
                return;
            }

            IEnumerable <int> ids;

            if (slotIds == null)
            {
                ids = node.GetInputSlots <ISlot>().Select(x => x.id);
            }
            else
            {
                ids = node.GetInputSlots <ISlot>().Where(x => slotIds.Contains(x.id)).Select(x => x.id);
            }

            foreach (var slot in ids)
            {
                foreach (var edge in node.owner.GetEdges(node.GetSlotReference(slot)))
                {
                    var outputNode = node.owner.GetNodeFromGuid(edge.outputSlot.nodeGuid) as T;
                    if (outputNode != null)
                    {
                        DepthFirstCollectNodesFromNode(nodeList, outputNode);
                    }
                }
            }

            if (includeSelf == IncludeSelf.Include)
            {
                nodeList.Add(node);
            }
        }
예제 #4
0
        public static void DepthFirstCollectNodesFromNode(List <INode> nodeList, INode node, IncludeSelf includeSelf = IncludeSelf.Include, List <int> slotIds = null)
        {
            // no where to start
            if (node == null)
            {
                return;
            }

            // already added this node
            if (nodeList.Contains(node))
            {
                return;
            }

            var ids = node.GetInputSlots <ISlot>().Select(x => x.id);

            if (slotIds != null)
            {
                ids = node.GetInputSlots <ISlot>().Where(x => slotIds.Contains(x.id)).Select(x => x.id);
            }

            foreach (var slot in ids)
            {
                foreach (var edge in node.owner.GetEdges(node.GetSlotReference(slot)))
                {
                    var outputNode = node.owner.GetNodeFromGuid(edge.outputSlot.nodeGuid);
                    DepthFirstCollectNodesFromNode(nodeList, outputNode);
                }
            }

            if (includeSelf == IncludeSelf.Include)
            {
                nodeList.Add(node);
            }
        }