Пример #1
0
        public void PWGraphNoiseRemapAndDebugNodes()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode(typeof(PWNodePerlinNoise2D), "perlin")
                        .NewNode(typeof(PWNodeCurve), "curve")
                        .NewNode(typeof(PWNodeDebugInfo), "debug")
                        .Link("perlin", "curve")
                        .Link("curve", "debug")
                        .Execute()
                        .GetGraph();

            var perlinNode = graph.FindNodeByName <PWNodePerlinNoise2D>("perlin");
            var curveNode  = graph.FindNodeByName <PWNodeCurve>("curve");
            var debugNode  = graph.FindNodeByName <PWNodeDebugInfo>("debug");

            //Assign a curve like this -> /\
            var curve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(.5f, 1), new Keyframe(1, 0));

            curveNode.curve = curve;

            graph.Process();

            var result = debugNode.obj as Sampler2D;

            Assert.That(result != null, "The perlin nose sampler was not properly given to the debug node");

            //compare all resulting sampler values to the naive interpretation of the curve remap
            result.Foreach((x, y, val) => {
                var expected = curve.Evaluate(perlinNode.output[x, y]);
                Assert.That(val == expected, "Bad value in result of noise remaping, got " + val + " but " + expected + " was expected");
            });
        }
Пример #2
0
        public void PWGraphNodesSimplePasses()
        {
            var allMainNodeInfos = PWNodeTypeProvider.GetAllowedNodesForGraph(PWGraphType.Main);

            var builder = PWGraphBuilder.NewGraph <PWMainGraph>();

            foreach (var mainTypes in allMainNodeInfos)
            {
                foreach (var nodeInfo in mainTypes.typeInfos)
                {
                    builder.NewNode(nodeInfo.type, nodeInfo.type.ToString());
                }
            }

            var graph = builder.Execute().GetGraph();

            foreach (var node in graph.nodes)
            {
                node.OnNodeUnitTest();
            }

            builder = PWGraphBuilder.NewGraph <PWMainGraph>();

            foreach (var type in PWNodeTypeProvider.GetExlusiveNodeTypesForGraph(PWGraphType.Biome))
            {
                builder.NewNode(type, type.ToString());
            }

            graph = builder.Execute().GetGraph();

            foreach (var node in graph.nodes)
            {
                node.OnNodeUnitTest();
            }
        }
Пример #3
0
        public void PWGraphLinkArrayToArray()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>().GetGraph();

            var input  = graph.FindNodeByType <PWNodeGraphInput>();
            var output = graph.FindNodeByType <PWNodeGraphOutput>();

            //create 5 links from first input node anchor to [1..5] output anchors
            for (int i = 0; i < 5; i++)
            {
                var inputAnchor  = input.outputAnchors.Last();
                var outputAnchor = output.inputAnchors.Last();

                graph.CreateLink(inputAnchor, outputAnchor);
            }

            Assert.That(input.outputAnchors.Count() == 1, "input node output anchors count: " + input.outputAnchors.Count() + ", expected to be 1");
            Assert.That(output.inputAnchors.Count() == 6, "output node input anchors count: " + output.inputAnchors.Count() + ", expected to be 6");

            var inputLinks  = input.GetOutputLinks().ToList();
            var outputLinks = output.GetInputLinks().ToList();

            Assert.That(inputLinks.Count == 5);
            Assert.That(outputLinks.Count == 5);

            Assert.That(inputLinks[0].toAnchor != inputLinks[1].toAnchor);
            Assert.That(outputLinks[0].toAnchor != outputLinks[1].toAnchor);
        }
Пример #4
0
        public void SliderNodeAnchorLinkedToAddNodeExecution()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode <PWNodeSlider>("s1")
                        .NewNode <PWNodeSlider>("s2")
                        .NewNode <PWNodeSlider>("s3")
                        .NewNode <PWNodeSlider>("s4")
                        .NewNode <PWNodeAdd>("add")
                        .Link("s1", "outValue", "add", "values")
                        .Link("s2", "outValue", "add", "values")
                        .Link("s3", 0, "add", 0)
                        .Link("s4", 0, "add", 0)
                        .Execute()
                        .GetGraph();

            var s1 = graph.FindNodeByName("s1");
            var s2 = graph.FindNodeByName("s2");
            var s3 = graph.FindNodeByName("s3");
            var s4 = graph.FindNodeByName("s4");

            var s1Link = s1.GetOutputLinks().First();
            var s2Link = s2.GetOutputLinks().First();
            var s3Link = s3.GetOutputLinks().First();
            var s4Link = s4.GetOutputLinks().First();

            //check if the links haven't been linked to the same anchor
            Assert.That(s1Link.toAnchor != s2Link.toAnchor);
            Assert.That(s2Link.toAnchor != s3Link.toAnchor);
            Assert.That(s3Link.toAnchor != s4Link.toAnchor);
            Assert.That(s4Link.toAnchor != s1Link.toAnchor);
        }
Пример #5
0
        public void PWGraphBuilderBiomeGraph()
        {
            var graph = PWGraphBuilder.NewGraph <PWBiomeGraph>()
                        .NewNode <PWNodeBiomeSurfaceColor>("c")
                        .NewNode <PWNodeBiomeSurfaceSwitch>("s")
                        .NewNode <PWNodeBiomeSurface>("surf")
                        .Link("s", "surf")
                        .Link("c", "s")
                        .Execute()
                        .GetGraph();

            var color      = graph.FindNodeByName("c");
            var surfSwitch = graph.FindNodeByName("s");
            var surf       = graph.FindNodeByName("surf");

            Assert.That(color.GetOutputLinks().Count() == 1);
            Assert.That(surfSwitch.GetInputLinks().Count() == 1);
            Assert.That(surfSwitch.GetOutputLinks().Count() == 1);
            Assert.That(surf.GetInputLinks().Count() == 1);

            var colorLink      = color.GetOutputLinks().First();
            var surfSwitchLink = surfSwitch.GetOutputLinks().First();

            Assert.That(colorLink.fromNode == color);
            Assert.That(colorLink.toNode == surfSwitch);
            Assert.That(surfSwitchLink.fromNode == surfSwitch);
            Assert.That(surfSwitchLink.toNode == surf);
        }
Пример #6
0
        public void PerlinNoiseNodeToDebugNodeParsedCommands()
        {
            var builder = PWGraphBuilder.NewGraph <PWMainGraph>()
                          .NewNode(typeof(PWNodePerlinNoise2D), "perlin")
                          .NewNode(typeof(PWNodeDebugInfo), "debug")
                          .Link("perlin", "debug");

            //list of the expected created commands
            List <PWGraphCommand> expectedCommands = new List <PWGraphCommand>()
            {
                new PWGraphCommand(typeof(PWNodePerlinNoise2D), "perlin"),
                new PWGraphCommand(typeof(PWNodeDebugInfo), "debug"),
                new PWGraphCommand("perlin", "debug"),
            };

            //get the commands as string
            var builderCommands = builder.GetCommands();

            for (int i = 0; i < expectedCommands.Count; i++)
            {
                //Parse the command and get the resulting command object
                PWGraphCommand cmd = PWGraphCLI.Parse(builderCommands[i]);

                Assert.That(cmd == expectedCommands[i]);
            }
        }
Пример #7
0
        public void EmptyGraph()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>().Execute().GetGraph();

            Assert.That(graph != null, "Null graph !");
            Assert.That(graph.inputNode != null, "Null graph input node while creating empty graph");
            Assert.That(graph.outputNode != null, "Null graph output node while creating empty graph");
        }
Пример #8
0
    void ImportGraphTextAsset(string path)
    {
        var file = Resources.Load <TextAsset>(path);

        PWGraphBuilder.FromGraph(biomeGraph)
        .ImportCommands(file.text.Split('\n'))
        .Execute();
    }
Пример #9
0
        public void PWGraphBuilderAddNode()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode <PWNodeBiome>("biome")
                        .Execute()
                        .GetGraph();

            Assert.That(graph.FindNodeByName <PWNodeBiome>("biome") != null);
        }
Пример #10
0
        public void PWGraphCreateNewNodeEventDisabled()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>().GetGraph();

            var add = graph.CreateNewNode(typeof(PWNodeAdd), new Vector2(42, -21), "add !", false);

            Assert.That(graph.nodes.Find(n => n == add) != null);
            Assert.That(add.rect.position == new Vector2(42, -21));
            Assert.That(add.name == "add !");
        }
Пример #11
0
        // +--------------+     +-------------+   +-----------+
        // | perlin noise +-----> noise remap +---> view noise|
        // +--------------+     +-------------+   +-----------+

        public static PWMainGraph       GenerateTestMainGraphWhitespaces()
        {
            return(PWGraphBuilder.NewGraph <PWMainGraph>()
                   .NewNode <PWNodePerlinNoise2D>("perlin noise")
                   .NewNode <PWNodeCurve>("noise remap")
                   .NewNode <PWNodeDebugInfo>("view noise")
                   .Link("perlin noise", "noise remap")
                   .Link("noise remap", "view noise")
                   .Execute()
                   .GetGraph() as PWMainGraph);
        }
Пример #12
0
        public void PWGraphImportMainWhiteSpaces()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>().GetGraph();

            var exampleGraph = TestUtils.GenerateTestMainGraphWhitespaces();

            exampleGraph.Export(tmpFilePath);

            graph.Import(tmpFilePath);

            CompareGraphs(exampleGraph, graph);
        }
Пример #13
0
        public void PWGraphImportBiome()
        {
            var graph = PWGraphBuilder.NewGraph <PWBiomeGraph>().GetGraph();

            var exampleGraph = TestUtils.GenerateTestBiomeGraph();

            exampleGraph.Export(tmpFilePath);

            graph.Import(tmpFilePath);

            CompareGraphs(exampleGraph, graph);
        }
Пример #14
0
        public void RemoveNodeWithoutEvents()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode <PWNodeSlider>("slider")
                        .Execute()
                        .GetGraph();

            var slider = graph.FindNodeByName("slider");

            graph.RemoveNode(slider, false);

            Assert.That(graph.nodes.Count == 2);
            Assert.That(graph.FindNodeByName("slider") == null);
        }
Пример #15
0
        public void FindNodeByName()
        {
            const string addNodeName     = "add";
            const string colorNodeName   = "c_o_l_o_r";
            const string textureNodeName = "   this is a texture ! ";

            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode(typeof(PWNodeAdd), addNodeName)
                        .NewNode(typeof(PWNodeColor), colorNodeName)
                        .NewNode(typeof(PWNodeTexture2D), textureNodeName)
                        .Execute()
                        .GetGraph();

            Assert.That(graph.FindNodeByName <PWNodeAdd>(addNodeName) != null, "add node was not found in the graph");
            Assert.That(graph.FindNodeByName <PWNodeColor>(colorNodeName) != null, "Color node was not found in the graph");
            Assert.That(graph.FindNodeByName <PWNodeTexture2D>(textureNodeName) != null, "Texture2D node was not found in the graph");
        }
Пример #16
0
        //                                                +----+
        //                                              +-> b1 +--+
        // +--------+      +--------+      +---------+  | +----+  | +----------+
        // | perlin +------> wlevel +------> bswitch +--+         +-> bblender |
        // +--------+      +--------+      +---------+  | +----+  | +----------+
        //                                              +-> b2 +--+
        //                                                +----+

        public static PWMainGraph       GenerateTestMainGraphBiomeSwitch()
        {
            return(PWGraphBuilder.NewGraph <PWMainGraph>()
                   .NewNode <PWNodePerlinNoise2D>("perlin")
                   .NewNode <PWNodeWaterLevel>("wlevel")
                   .NewNode <PWNodeBiomeSwitch>("bswitch")
                   .NewNode <PWNodeBiome>("b1")
                   .NewNode <PWNodeBiome>("b2")
                   .NewNode <PWNodeBiomeBlender>("bblender")
                   .Link("perlin", "wlevel")
                   .Link("wlevel", "bswitch")
                   .Link("bswitch", "outputBiomes", "b1", "inputBiomeData")
                   .Link("bswitch", "outputBiomes", "b2", "inputBiomeData")
                   .Link("b1", "bblender")
                   .Link("b2", "bblender")
                   .Execute()
                   .GetGraph() as PWMainGraph);
        }
Пример #17
0
        public void PWGraphSafeCreateLinkDuplicate()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode <PWNodeSlider>("slider")
                        .NewNode <PWNodeDebugInfo>("debug")
                        .Execute()
                        .GetGraph();

            var sliderAnchor = graph.FindNodeByName("slider").outputAnchors.First();
            var debugAnchor  = graph.FindNodeByName("debug").inputAnchors.First();

            graph.SafeCreateLink(sliderAnchor, debugAnchor);
            graph.SafeCreateLink(sliderAnchor, debugAnchor);

            Assert.That(sliderAnchor.linkCount == 1);
            Assert.That(debugAnchor.linkCount == 1);
            Assert.That(graph.nodeLinkTable.GetLinks().Count() == 1);
        }
Пример #18
0
        public void PWGraphBuilderLinkSimple()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode <PWNodePerlinNoise2D>("perlin")
                        .NewNode <PWNodeCircleNoiseMask>("mask")
                        .Link("perlin", "mask")
                        .Execute()
                        .GetGraph();

            var perlin = graph.FindNodeByName <PWNodePerlinNoise2D>("perlin");
            var mask   = graph.FindNodeByName <PWNodeCircleNoiseMask>("mask");

            var perlinAnchor = perlin.outputAnchors.First();
            var maskAnchor   = mask.inputAnchors.First();

            Assert.That(perlinAnchor.linkCount == 1);
            Assert.That(maskAnchor.linkCount == 1);
        }
Пример #19
0
        public void PerlinNoiseWithAttributesToDebugNodeExecution()
        {
            string perlinNodeName   = "perlin";
            var    perlinAttributes = new PWGraphCLIAttributes()
            {
                { "persistance", 2.4f }, { "octaves", 6 }
            };

            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode <PWNodePerlinNoise2D>(perlinNodeName, perlinAttributes)
                        .Execute()
                        .GetGraph();

            PWNodePerlinNoise2D perlinNode = graph.FindNodeByName(perlinNodeName) as PWNodePerlinNoise2D;

            Assert.That(perlinNode.octaves == 6, "Perlin node octaves expected to be 6 but was " + perlinNode.octaves);
            Assert.That(perlinNode.persistance == 2.4f, "Perlin node persistance expected to be 2.4 but was " + perlinNode.persistance);
        }
Пример #20
0
        PWMainGraph CreateTestGraph(out PWNodePerlinNoise2D perlinNode, out PWNodeDebugInfo debugNode)
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode(typeof(PWNodePerlinNoise2D), "perlin")
                        .NewNode(typeof(PWNodeDebugInfo), "debug")
                        .Link("perlin", "debug")
                        .Execute()
                        .GetGraph() as PWMainGraph;

            perlinNode = graph.FindNodeByName <PWNodePerlinNoise2D>("perlin");
            debugNode  = graph.FindNodeByName <PWNodeDebugInfo>("debug");

            graph.chunkSize     = 64;
            graph.step          = .5f;
            graph.chunkPosition = new Vector3(10, 42, -7);
            graph.seed          = 123456789;

            return(graph as PWMainGraph);
        }
Пример #21
0
        public void PWMainGraphPresets()
        {
            TextAsset[] mainGraphPresets = Resources.LoadAll <TextAsset>(mainGraphPresetPath);

            foreach (var mainGraphPreset in mainGraphPresets)
            {
                string[] commands = mainGraphPreset.text.Split('\n');

                var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                            .ImportCommands(commands)
                            .Execute()
                            .GetGraph();

                graph.UpdateComputeOrder();

                //TODO: process the graph and check output

                // Assert.That(graph.GetOutput< FinalTerrain >() != null)
            }
        }
Пример #22
0
        public void PWGraphLinkProcessSimple()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>()
                        .NewNode <PWNodeSlider>("slider")
                        .NewNode <PWNodeDebugInfo>("debug")
                        .Link("slider", "debug")
                        .Execute()
                        .GetGraph();

            var slider = graph.FindNodeByName <PWNodeSlider>("slider");
            var debug  = graph.FindNodeByName <PWNodeDebugInfo>("debug");

            slider.outValue = 0.42f;

            graph.name = "MyGraph !";

            graph.Process();

            Assert.That(debug.obj.Equals(0.42f));
        }
Пример #23
0
        public void PWGraphImport()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>().GetGraph();

            var exampleGraph = TestUtils.GenerateTestMainGraph();

            exampleGraph.Export(tmpFilePath);

            graph.Import(tmpFilePath);

            CompareGraphs(exampleGraph, graph);

            //Compare specific nodes:
            var exCurveNode  = exampleGraph.FindNodeByName <PWNodeSlider>("slider");
            var newCurveNode = graph.FindNodeByName <PWNodeSlider>("slider");

            Assert.That(exCurveNode.min == newCurveNode.min, "imported slider curve min (" + exCurveNode.min + ") != exported slider curve min (" + newCurveNode.min + ")");
            Assert.That(exCurveNode.max == newCurveNode.max, "imported slider curve max (" + exCurveNode.max + ") != exported slider curve max (" + newCurveNode.max + ")");
            Assert.That(exCurveNode.outValue == newCurveNode.outValue, "imported slider curve outValue (" + exCurveNode.outValue + ") != exported slider curve outValue (" + newCurveNode.outValue + ")");
        }
Пример #24
0
        //test main graph
        //                +-----+
        //            +---> Add1+---+
        // +------+   |   +-----+   |   +-----+   +------+
        // |Slider+---+             +---> Add4+--->Debug1|
        // +------+   |   +-----+       +-----+   +------+
        //            +---> Add2+---+
        // +------+   |   +-----+   |   +------+
        // |Float +---+             +--->Debug2|
        // +------+   |   +-----+       +------+
        //            +---> Add3+
        //                +-----+

        public static PWMainGraph       GenerateTestMainGraph()
        {
            return(PWGraphBuilder.NewGraph <PWMainGraph>()
                   .NewNode(typeof(PWNodeSlider), "slider")
                   .NewNode(typeof(PWNodeConstant), "constant")
                   .NewNode(typeof(PWNodeAdd), "add1")
                   .NewNode(typeof(PWNodeAdd), "add2")
                   .NewNode(typeof(PWNodeAdd), "add3")
                   .NewNode(typeof(PWNodeAdd), "add4")
                   .NewNode(typeof(PWNodeDebugInfo), "debug1")
                   .NewNode(typeof(PWNodeDebugInfo), "debug2")
                   .Link("slider", "add1")
                   .Link("slider", "add2")
                   .Link("constant", "add2")
                   .Link("constant", "add3")
                   .Link("add1", "add4")
                   .Link("add4", "debug1")
                   .Link("add2", "debug2")
                   .Execute()
                   .GetGraph() as PWMainGraph);
        }
Пример #25
0
        public void PWGraphCreateLinkEventDisabled()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>().GetGraph();

            var slider = graph.CreateNewNode(typeof(PWNodeSlider), Vector2.zero);
            var add    = graph.CreateNewNode(typeof(PWNodeAdd), Vector2.zero);

            var sliderOut = slider.outputAnchors.First();
            var addIn     = add.inputAnchors.First();

            var link = graph.CreateLink(sliderOut, addIn, false);

            Assert.That(sliderOut.linkCount == 1);
            Assert.That(addIn.linkCount == 1);

            Assert.That(link == sliderOut.links.First());
            Assert.That(link == addIn.links.First());

            Assert.That(link.fromNode == slider);
            Assert.That(link.toNode == add);
        }
Пример #26
0
        public void PWGraphLinkArrayToArrayProcess()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>().GetGraph();

            var input  = graph.FindNodeByType <PWNodeGraphInput>();
            var output = graph.FindNodeByType <PWNodeGraphOutput>();

            input.SetMultiAnchor("outputValues", 5);

            var inputAnchors = input.outputAnchors.ToList();

            //Link input i anchor to output i anchor
            for (int i = 0; i < 5; i++)
            {
                var inputAnchor  = inputAnchors[i];
                var outputAnchor = output.inputAnchors.Last();

                graph.CreateLink(inputAnchor, outputAnchor);
            }

            int value = 42;

            foreach (var anchor in input.outputAnchors)
            {
                input.SetAnchorValue(anchor, value++);
            }

            graph.Process();

            value = 42;

            var outputAnchors = output.inputAnchors.ToList();

            for (int i = 0; i < 5; i++)
            {
                var anchor = outputAnchors[i];
                var val    = output.GetAnchorValue(anchor);
                Assert.That(val.Equals(value++));
            }
        }
Пример #27
0
        public void PerlinNoiseToDebugNodeExecution()
        {
            string perlinNodeName = "perlin";
            string debugNodeName  = "debug";
            var    graph          = PWGraphBuilder.NewGraph <PWMainGraph>()
                                    .NewNode <PWNodePerlinNoise2D>(perlinNodeName)
                                    .NewNode <PWNodeDebugInfo>(debugNodeName)
                                    .Link(perlinNodeName, debugNodeName)
                                    .Execute()
                                    .GetGraph();

            PWNodePerlinNoise2D perlinNode = graph.FindNodeByName(perlinNodeName) as PWNodePerlinNoise2D;
            PWNodeDebugInfo     debugNode  = graph.FindNodeByName(debugNodeName) as PWNodeDebugInfo;

            Assert.That(perlinNode != null, "Perlin node not found in the graph (using FindNodeByName)");
            Assert.That(debugNode != null, "Debug node not found in the graph (using FindNodeByName)");

            PWNodeLink link = perlinNode.GetOutputLinks().First();

            Assert.That(link != null, "Link can't be found in the graph");
            Assert.That(link.toNode == debugNode);
        }
Пример #28
0
        //Test biome graph
        // +----+      +----+
        // | c1 +------> s1 +----+
        // +----+      +----+    |
        //                       |
        // +----+      +----+    |  +------+
        // | c2 +------> s2 +-------> surf |
        // +----+      +----+    |  +------+
        //                       |
        // +----+      +----+    |
        // | c3 +------> s3 +----+
        // +----+      +----+
        // c*: PWNodeBiomeSurfaceColor, s*: PWNodeBiomeSurfaceSwitch, surf: PWNodeBiomeSurface

        public static PWBiomeGraph      GenerateTestBiomeGraph()
        {
            return(PWGraphBuilder.NewGraph <PWBiomeGraph>()
                   .NewNode <PWNodeBiomeSurfaceColor>("c1")
                   .NewNode <PWNodeBiomeSurfaceColor>("c2")
                   .NewNode <PWNodeBiomeSurfaceColor>("c3")
                   .NewNode <PWNodeBiomeSurfaceSwitch>("s1")
                   .NewNode <PWNodeBiomeSurfaceSwitch>("s2")
                   .NewNode <PWNodeBiomeSurfaceSwitch>("s3")
                   .NewNode <PWNodeBiomeSurface>("surf")
                   .Link("s1", "surf")
                   .Link("s2", "surf")
                   .Link("s3", "surf")
                   .Link("c1", "s1")
                   .Link("c2", "s2")
                   .Link("c3", "s3")
                   .Custom(g => {
                (g as PWBiomeGraph).surfaceType = BiomeSurfaceType.Color;
            })
                   .Execute()
                   .GetGraph() as PWBiomeGraph);
        }
Пример #29
0
        public void PWGraphExportImportDuplicateNodeNames()
        {
            var graph = PWGraphBuilder.NewGraph <PWMainGraph>().GetGraph();

            var s1 = graph.CreateNewNode <PWNodeSlider>(Vector2.zero, "slider");
            var s2 = graph.CreateNewNode <PWNodeSlider>(Vector2.zero, "slider");
            var s3 = graph.CreateNewNode <PWNodeSlider>(Vector2.zero, "slider");

            var add = graph.CreateNewNode <PWNodeAdd>(Vector2.zero);

            graph.SafeCreateLink(s1.outputAnchors.First(), add.inputAnchors.Last());
            graph.SafeCreateLink(s2.outputAnchors.First(), add.inputAnchors.Last());
            graph.SafeCreateLink(s3.outputAnchors.First(), add.inputAnchors.Last());

            graph.Export(tmpFilePath);

            var importedGraph = PWGraphBuilder.NewGraph <PWMainGraph>().GetGraph();

            importedGraph.Import(tmpFilePath);

            CompareGraphs(graph, importedGraph);
        }
Пример #30
0
        public void SliderNodeToAddNodeWithAnchorLink()
        {
            var builder = PWGraphBuilder.NewGraph <PWMainGraph>()
                          .NewNode <PWNodeSlider>("s1")
                          .NewNode <PWNodeSlider>("s2")
                          .NewNode <PWNodeSlider>("s3")
                          .NewNode <PWNodeSlider>("s4")
                          .NewNode <PWNodeAdd>("add")
                          .Link("s1", "outValue", "add", "values")
                          .Link("s2", "outValue", "add", "values")
                          .Link("s3", 1, "add", 1)
                          .Link("s4", 1, "add", 1);

            var expectedCommands = new List <PWGraphCommand>()
            {
                new PWGraphCommand(typeof(PWNodeSlider), "s1"),
                new PWGraphCommand(typeof(PWNodeSlider), "s2"),
                new PWGraphCommand(typeof(PWNodeSlider), "s3"),
                new PWGraphCommand(typeof(PWNodeSlider), "s4"),
                new PWGraphCommand(typeof(PWNodeAdd), "add"),
                new PWGraphCommand("s1", "outValue", "add", "values"),
                new PWGraphCommand("s2", "outValue", "add", "values"),
                new PWGraphCommand("s3", 1, "add", 1),
                new PWGraphCommand("s4", 1, "add", 1),
            };

            var commands = builder.GetCommands();

            for (int i = 0; i < expectedCommands.Count; i++)
            {
                //Parse the command and get the resulting command object
                PWGraphCommand cmd = PWGraphCLI.Parse(commands[i]);

                Assert.That(cmd == expectedCommands[i]);
            }
        }