Esempio n. 1
0
        public CopyPasteGraph(Guid sourceGraphGuid, IEnumerable <GroupData> groups, IEnumerable <INode> nodes, IEnumerable <IEdge> edges, IEnumerable <IShaderProperty> properties, IEnumerable <IShaderProperty> metaProperties)
        {
            m_SourceGraphGuid = new SerializableGuid(sourceGraphGuid);

            foreach (var groupData in groups)
            {
                AddGroup(groupData);
            }

            foreach (var node in nodes)
            {
                AddNode(node);
                foreach (var edge in NodeUtils.GetAllEdges(node))
                {
                    AddEdge(edge);
                }
            }

            foreach (var edge in edges)
            {
                AddEdge(edge);
            }

            foreach (var property in properties)
            {
                AddProperty(property);
            }

            foreach (var metaProperty in metaProperties)
            {
                AddMetaProperty(metaProperty);
            }
        }
Esempio n. 2
0
        public CopyPasteGraph(IEnumerable <INode> nodes, IEnumerable <IEdge> edges)
        {
            foreach (var node in nodes)
            {
                AddNode(node);
                foreach (var edge in NodeUtils.GetAllEdges(node))
                {
                    AddEdge(edge);
                }
            }

            foreach (var edge in edges)
            {
                AddEdge(edge);
            }
        }
Esempio n. 3
0
        public CopyPasteGraph(string sourceGraphGuid, IEnumerable <GroupData> groups, IEnumerable <AbstractMaterialNode> nodes, IEnumerable <IEdge> edges, IEnumerable <ShaderInput> inputs, IEnumerable <AbstractShaderProperty> metaProperties, IEnumerable <ShaderKeyword> metaKeywords, IEnumerable <StickyNoteData> notes)
        {
            m_SourceGraphGuid = sourceGraphGuid;

            foreach (var groupData in groups)
            {
                AddGroup(groupData);
            }

            foreach (var stickyNote in notes)
            {
                AddNote(stickyNote);
            }

            foreach (var node in nodes)
            {
                if (!node.canCopyNode)
                {
                    throw new InvalidOperationException($"Cannot copy node {node.name} ({node.guid}).");
                }
                AddNode(node);
                foreach (var edge in NodeUtils.GetAllEdges(node))
                {
                    AddEdge(edge);
                }
            }

            foreach (var edge in edges)
            {
                AddEdge(edge);
            }

            foreach (var input in inputs)
            {
                AddInput(input);
            }

            foreach (var metaProperty in metaProperties)
            {
                AddMetaProperty(metaProperty);
            }

            foreach (var metaKeyword in metaKeywords)
            {
                AddMetaKeyword(metaKeyword);
            }
        }
Esempio n. 4
0
        public void TestCanConnectAndTraverseThreeNodesOnBaseMaterialGraph()
        {
            var graph = new GraphData();

            var outputNode = new TestableNode();

            graph.AddNode(outputNode);

            var middleNode = new TestableNode();

            graph.AddNode(middleNode);

            var inputNode = new TestableNode();

            graph.AddNode(inputNode);

            Assert.AreEqual(3, graph.GetNodes <AbstractMaterialNode>().Count());

            graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), middleNode.GetSlotReference(TestableNode.Input0));
            Assert.AreEqual(1, graph.edges.Count());

            graph.Connect(middleNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0));
            Assert.AreEqual(2, graph.edges.Count());

            var edgesOnMiddleNode = NodeUtils.GetAllEdges(middleNode);

            Assert.AreEqual(2, edgesOnMiddleNode.Count());

            outputNode.SetOverrideActiveState(AbstractMaterialNode.ActiveState.ExplicitActive);
            middleNode.SetOverrideActiveState(AbstractMaterialNode.ActiveState.ExplicitActive);
            inputNode.SetOverrideActiveState(AbstractMaterialNode.ActiveState.ExplicitActive);
            List <AbstractMaterialNode> result = new List <AbstractMaterialNode>();

            NodeUtils.DepthFirstCollectNodesFromNode(result, inputNode);
            Assert.AreEqual(3, result.Count);

            result.Clear();
            NodeUtils.DepthFirstCollectNodesFromNode(result, inputNode, NodeUtils.IncludeSelf.Exclude);
            Assert.AreEqual(2, result.Count);

            result.Clear();
            NodeUtils.DepthFirstCollectNodesFromNode(result, null);
            Assert.AreEqual(0, result.Count);
        }
Esempio n. 5
0
        public CopyPasteGraph(IEnumerable <GroupData> groups, IEnumerable <AbstractMaterialNode> nodes, IEnumerable <Edge> edges,
                              IEnumerable <ShaderInput> inputs, IEnumerable <AbstractShaderProperty> metaProperties, IEnumerable <ShaderKeyword> metaKeywords, IEnumerable <StickyNoteData> notes, bool keepOutputEdges = false)
        {
            if (groups != null)
            {
                foreach (var groupData in groups)
                {
                    AddGroup(groupData);
                }
            }

            if (notes != null)
            {
                foreach (var stickyNote in notes)
                {
                    AddNote(stickyNote);
                }
            }

            var nodeSet = new HashSet <AbstractMaterialNode>();

            if (nodes != null)
            {
                foreach (var node in nodes.Distinct())
                {
                    if (!node.canCopyNode)
                    {
                        throw new InvalidOperationException($"Cannot copy node {node.name} ({node.objectId}).");
                    }

                    nodeSet.Add(node);
                    AddNode(node);
                    foreach (var edge in NodeUtils.GetAllEdges(node))
                    {
                        AddEdge((Edge)edge);
                    }
                }
            }

            if (edges != null)
            {
                foreach (var edge in edges)
                {
                    AddEdge(edge);
                }
            }

            if (inputs != null)
            {
                foreach (var input in inputs)
                {
                    AddInput(input);
                }
            }

            if (metaProperties != null)
            {
                foreach (var metaProperty in metaProperties.Distinct())
                {
                    AddMetaProperty(metaProperty);
                }
            }

            if (metaKeywords != null)
            {
                foreach (var metaKeyword in metaKeywords.Distinct())
                {
                    AddMetaKeyword(metaKeyword);
                }
            }

            m_Edges = m_Edges
                      .Distinct()
                      .Where(edge => nodeSet.Contains(edge.inputSlot.node) || (keepOutputEdges && nodeSet.Contains(edge.outputSlot.node)))
                      .ToList();
        }