Exemplo n.º 1
0
        void PropagateNodeSet(IndexSet nodeSet, bool forward = true, IEnumerable <Identifier> initialWavefront = null)
        {
            m_Wavefront.Clear();
            if (initialWavefront != null)
            {
                foreach (var id in initialWavefront)
                {
                    m_Wavefront.Push(id);
                }
            }
            else
            {
                foreach (var index in nodeSet)
                {
                    m_Wavefront.Push(m_Identifiers[index]);
                }
            }
            while (m_Wavefront.Count > 0)
            {
                var index = m_Wavefront.Pop();
                var node  = m_Graph.GetNodeFromTempId(index);
                if (node == null)
                {
                    continue;
                }

                // Loop through all nodes that the node feeds into.
                m_Slots.Clear();
                if (forward)
                {
                    node.GetOutputSlots(m_Slots);
                }
                else
                {
                    node.GetInputSlots(m_Slots);
                }
                foreach (var slot in m_Slots)
                {
                    m_Edges.Clear();
                    m_Graph.GetEdges(slot.slotReference, m_Edges);
                    foreach (var edge in m_Edges)
                    {
                        // We look at each node we feed into.
                        var connectedSlot     = forward ? edge.inputSlot : edge.outputSlot;
                        var connectedNodeGuid = connectedSlot.nodeGuid;
                        var connectedNode     = m_Graph.GetNodeFromGuid(connectedNodeGuid);

                        // If the input node is already in the set of time-dependent nodes, we don't need to process it.
                        if (nodeSet.Contains(connectedNode.tempId.index))
                        {
                            continue;
                        }

                        // Add the node to the set of time-dependent nodes, and to the wavefront such that we can process the nodes that it feeds into.
                        nodeSet.Add(connectedNode.tempId.index);
                        m_Wavefront.Push(connectedNode.tempId);
                    }
                }
            }
        }
Exemplo n.º 2
0
        Edge AddEdge(IEdge edge)
        {
            var sourceNode = m_Graph.GetNodeFromGuid(edge.outputSlot.nodeGuid);

            if (sourceNode == null)
            {
                Debug.LogWarning("Source node is null");
                return(null);
            }
            var sourceSlot = sourceNode.FindOutputSlot <MaterialSlot>(edge.outputSlot.slotId);

            var targetNode = m_Graph.GetNodeFromGuid(edge.inputSlot.nodeGuid);

            if (targetNode == null)
            {
                Debug.LogWarning("Target node is null");
                return(null);
            }
            var targetSlot = targetNode.FindInputSlot <MaterialSlot>(edge.inputSlot.slotId);

            var sourceNodeView = m_GraphView.nodes.ToList().OfType <MaterialNodeView>().FirstOrDefault(x => x.node == sourceNode);

            if (sourceNodeView != null)
            {
                var sourceAnchor = sourceNodeView.outputContainer.Children().OfType <ShaderPort>().FirstOrDefault(x => x.slot.Equals(sourceSlot));

                var targetNodeView = m_GraphView.nodes.ToList().OfType <MaterialNodeView>().FirstOrDefault(x => x.node == targetNode);
                var targetAnchor   = targetNodeView.inputContainer.Children().OfType <ShaderPort>().FirstOrDefault(x => x.slot.Equals(targetSlot));

                var edgeView = new Edge
                {
                    userData = edge,
                    output   = sourceAnchor,
                    input    = targetAnchor
                };
                edgeView.output.Connect(edgeView);
                edgeView.input.Connect(edgeView);
                m_GraphView.AddElement(edgeView);
                sourceNodeView.RefreshPorts();
                targetNodeView.RefreshPorts();
                sourceNodeView.UpdatePortInputTypes();
                targetNodeView.UpdatePortInputTypes();

                return(edgeView);
            }

            return(null);
        }
Exemplo n.º 3
0
        void PropagateNodeList(ICollection <INode> nodes, bool forward)
        {
            m_NodeWave.Clear();
            foreach (var node in nodes)
            {
                m_NodeWave.Push(node);
            }

            while (m_NodeWave.Count > 0)
            {
                var node = m_NodeWave.Pop();
                if (node == null)
                {
                    continue;
                }

                // Loop through all nodes that the node feeds into.
                m_Slots.Clear();
                if (forward)
                {
                    node.GetOutputSlots(m_Slots);
                }
                else
                {
                    node.GetInputSlots(m_Slots);
                }
                foreach (var slot in m_Slots)
                {
                    m_Edges.Clear();
                    m_Graph.GetEdges(slot.slotReference, m_Edges);
                    foreach (var edge in m_Edges)
                    {
                        // We look at each node we feed into.
                        var connectedSlot     = forward ? edge.inputSlot : edge.outputSlot;
                        var connectedNodeGuid = connectedSlot.nodeGuid;
                        var connectedNode     = m_Graph.GetNodeFromGuid(connectedNodeGuid);

                        // If the input node is already in the set, we don't need to process it.
                        if (nodes.Contains(connectedNode))
                        {
                            continue;
                        }

                        // Add the node to the set, and to the wavefront such that we can process the nodes that it feeds into.
                        nodes.Add(connectedNode);
                        m_NodeWave.Push(connectedNode);
                    }
                }
            }
        }