Example #1
0
        public void InitGraph(PWMainGraph graph)
        {
            if (graph != null)
            {
                this.graph = graph;
            }
            else
            {
                return;
            }

            graph.SetRealMode(true);
            chunkSize   = graph.chunkSize;
            graphOutput = graph.outputNode as PWNodeGraphOutput;
            graph.UpdateComputeOrder();
            if (!graph.IsRealMode())
            {
                terrainRoot = GameObject.Find("PWPreviewTerrain");
            }
            if (terrainRoot == null)
            {
                terrainRoot = GameObject.Find(PWConstants.realModeRootObjectName);
                if (terrainRoot == null)
                {
                    terrainRoot = new GameObject(PWConstants.realModeRootObjectName);
                    terrainRoot.transform.position = Vector3.zero;
                }
            }
            graph.ProcessOnce();
        }
Example #2
0
    public PWMainPresetScreen(PWMainGraph mainGraph)
    {
        this.mainGraph = mainGraph;

        //loading preset panel images
        preset2DSideViewTexture     = Resources.Load <Texture2D>("preview2DSideView");
        preset2DTopDownViewTexture  = Resources.Load <Texture2D>("preview2DTopDownView");
        preset3DPlaneTexture        = Resources.Load <Texture2D>("preview3DPlane");
        preset3DSphericalTexture    = Resources.Load <Texture2D>("preview3DSpherical");
        preset3DCubicTexture        = Resources.Load <Texture2D>("preview3DCubic");
        preset1DDensityFieldTexture = Resources.Load <Texture2D>("preview1DDensityField");
        preset2DDensityFieldTexture = Resources.Load <Texture2D>("preview2DDensityField");
        preset3DDensityFieldTexture = Resources.Load <Texture2D>("preview3DDensityField");
        // presetMeshTetxure = Resources.Load< Texture2D >("previewMesh");

        PresetCellList presets = new PresetCellList()
        {
            { "2D Terrains", preset2DSideViewTexture, "2D sideview procedural terrain", Build2DSideView, false },
            { "2D Terrains", preset2DTopDownViewTexture, "2D top down procedural terrain", Build2DTopDown, true },
            { "3D Terrains", preset3DPlaneTexture, "3D plane procedural terrain", Build3DPlanar, false },
            { "3D Terrains", preset3DSphericalTexture, "3D spherical procedural terrain", Build3DSpherical, false },
            { "3D Terrains", preset3DCubicTexture, "3D cubic procedural terrain", Build3DCubic, false },
            { "Density Fields", preset1DDensityFieldTexture, "1D float density field", Build1DDensity, false },
            { "Density Fields", preset2DDensityFieldTexture, "2D float density field", Build2DDensity, false },
            { "Density Fields", preset3DDensityFieldTexture, "3D float density field", Build3DDensity, false },
        };

        LoadPresetList(presets);
    }
Example #3
0
        //Warning: this will destroy all loaded chunks and regenerate them
        public void ReloadChunks()
        {
            if (EditorApplication.isPlaying || EditorApplication.isPaused)
            {
                Debug.LogError("[Editor Terrain Manager] can't reload chunks from the editor in play mode");
                return;
            }

            PWMainGraph mainGraph = graph as PWMainGraph;

            if (mainGraph != null)
            {
                //if the graph we have is not the same / have been modified since last generation, we replace it
                if (terrain.graph != null && terrain.graph.GetHashCode() != graph.GetHashCode())
                {
                    GameObject.DestroyImmediate(terrain.graph);
                }

                terrain.InitGraph(graph.Clone() as PWMainGraph);

                terrain.DestroyAllChunks();


                //updateChunks will regenerate all deleted chunks
                terrain.UpdateChunks();
            }
        }
Example #4
0
        public void SimpleSwitchGraphBuild()
        {
            PWMainGraph graph = TestUtils.GenerateTestMainGraphBiomeSwitch();
            BiomeData   bd    = new BiomeData();

            var wlevel  = graph.FindNodeByName("wlevel");
            var bswitch = graph.FindNodeByName <PWNodeBiomeSwitch>("bswitch");
            var b1      = graph.FindNodeByName <PWNodeBiome>("b1");
            var b2      = graph.FindNodeByName <PWNodeBiome>("b2");

            bd.biomeSwitchGraphStartPoint = wlevel;

            PartialBiome p1 = new PartialBiome();
            PartialBiome p2 = new PartialBiome();

            b1.outputBiome = p1;
            b2.outputBiome = p2;

            //setup the switch values
            var sd = bswitch.switchList.switchDatas;

            sd[0].min         = 0;
            sd[0].max         = 5;
            sd[0].name        = "1";
            sd[0].samplerName = BiomeSamplerName.terrainHeight;
            sd[1].min         = 5;
            sd[1].max         = 10;
            sd[1].name        = "2";
            sd[1].samplerName = BiomeSamplerName.terrainHeight;

            Sampler2D terrainHeight = new Sampler2D(32, 1);

            terrainHeight.min = 0;
            terrainHeight.max = 10;

            bd.UpdateSamplerValue(BiomeSamplerName.terrainHeight, terrainHeight);

            BiomeSwitchGraph switchGraph = new BiomeSwitchGraph();

            switchGraph.BuildGraph(bd);

            Assert.That(switchGraph.isBuilt == true);

            var values = new BiomeSwitchValues();

            values[0] = 4.0f;
            Assert.That(switchGraph.FindBiome(values).id == p1.id);
            values[0] = 0f;
            Assert.That(switchGraph.FindBiome(values).id == p1.id);
            values[0] = 5f;
            Assert.That(switchGraph.FindBiome(values).id == p1.id);

            values[0] = 6.0f;
            Assert.That(switchGraph.FindBiome(values).id == p2.id);
            values[0] = 10f;
            Assert.That(switchGraph.FindBiome(values).id == p2.id);
        }
Example #5
0
        public void PWNodeAPIGetNodesAttachedToAnchor()
        {
            PWMainGraph graph = TestUtils.GenerateTestMainGraph();

            var add4Node   = graph.FindNodeByName("add4");
            var add1Node   = graph.FindNodeByName("add1");
            var debug1Node = graph.FindNodeByName("debug1");

            var add4NodeInAnchor  = add4Node.inputAnchors.First();
            var add4NodeOutAnchor = add4Node.outputAnchors.First();

            List <PWNode> add4InputNodes  = add4Node.GetNodesAttachedToAnchor(add4NodeInAnchor).ToList();
            List <PWNode> add4OutputNodes = add4Node.GetNodesAttachedToAnchor(add4NodeOutAnchor).ToList();

            Assert.That(add4InputNodes[0] == add1Node, "add4 input node was " + add4InputNodes[0] + ", " + add1Node + " expected");
            Assert.That(add4OutputNodes[0] == debug1Node, "add4 output node was " + add4OutputNodes[0] + ", " + debug1Node + " expected");
        }
Example #6
0
        public void GetNodeChildsRecursive()
        {
            PWMainGraph mainGraph = TestUtils.GenerateTestMainGraphBiomeSwitch();

            var wlevel = mainGraph.FindNodeByName("wlevel");

            var recursiveNodesFromC2 = mainGraph.GetNodeChildsRecursive(wlevel);

            //check for duplicates
            Assert.That(recursiveNodesFromC2.Count == recursiveNodesFromC2.Distinct().Count());

            //check for compute order:
            for (int i = 0; i < recursiveNodesFromC2.Count - 1; i++)
            {
                var node1 = recursiveNodesFromC2[i];
                var node2 = recursiveNodesFromC2[i + 1];

                Assert.That(node1.computeOrder <= node2.computeOrder, "Nodes from GetNodeChildsRecursive are not computeOrder sorted");
            }
        }
Example #7
0
        public void PWNodeAPIGetNodesAttachedToAnchorArray()
        {
            PWMainGraph graph = TestUtils.GenerateTestMainGraph();

            var add2Node   = graph.FindNodeByName("add2");
            var sliderNode = graph.FindNodeByName("slider");
            var debug2Node = graph.FindNodeByName("debug2");

            var add2NodeInputAnchor  = add2Node.inputAnchors.First();
            var add2NodeOutputAnchor = add2Node.outputAnchors.First();

            List <PWNode> inputNodes  = add2Node.GetNodesAttachedToAnchor(add2NodeInputAnchor).ToList();
            List <PWNode> outputNodes = add2Node.GetNodesAttachedToAnchor(add2NodeOutputAnchor).ToList();

            Assert.That(inputNodes.Count == 1);
            Assert.That(inputNodes[0] == sliderNode);

            Assert.That(outputNodes.Count == 1);
            Assert.That(outputNodes[0] == debug2Node);
        }