Exemple #1
0
    public void GenerateMap()
    {
        float[,] noiseMap = PerlinNoise.GenerateNoise(mapChankSize, seed, Scale, octaves, persistance, lacunarity, offset);
        Color[] colorMap = new Color[mapChankSize * mapChankSize];
        for (int y = 0; y < mapChankSize; y++)
        {
            for (int x = 0; x < mapChankSize; x++)
            {
                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < Regions.Length; i++)
                {
                    if (currentHeight <= Regions[i].height)
                    {
                        colorMap[y * mapChankSize + x] = Regions[i].color;
                        break;
                    }
                }
            }
        }
        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.PerlinNoise)
        {
            mapDisplay.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            mapDisplay.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapChankSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            mapDisplay.DrawMesh(MeshGeneration.GenerareTerrainMesh(noiseMap, heightMultipler, curve), TextureGenerator.TextureFromColorMap(colorMap, mapChankSize), !GenerationAllTime);
        }
    }
Exemple #2
0
    void GenerateMap()
    {
        map = new int[width, height];
        RandomFillMap();

        for (int i = 0; i < 5; i++)
        {
            SmoothMap();
        }

        ProcessMap();

        int borderSize = 1;

        int[,] borderedMap = new int[width + borderSize * 2, height + borderSize * 2];

        for (int x = 0; x < borderedMap.GetLength(0); x++)
        {
            for (int y = 0; y < borderedMap.GetLength(1); y++)
            {
                if (x >= borderSize && x < width + borderSize && y >= borderSize && y < height + borderSize)
                {
                    borderedMap[x, y] = map[x - borderSize, y - borderSize];
                }
                else
                {
                    borderedMap[x, y] = 1;
                }
            }
        }

        MeshGeneration meshGen = GetComponent <MeshGeneration>();

        meshGen.GenerateMesh(borderedMap, 1);
    }
Exemple #3
0
    private static void checkForDestroys()
    {
        /*
         * int i = -1;
         * for (Chunk chunk = InfiniteWorld.GetFromRemoveQueue(); chunk != null; chunk = InfiniteWorld.GetFromRemoveQueue())
         * {
         *  Destroy(chunk.chunk);
         *  i++;
         *  if (i >= 1) { break; }
         * }
         */

        for (Chunk chunk = MeshGeneration.GetFromRemoveQueue(); chunk != null; chunk = MeshGeneration.GetFromRemoveQueue())
        {
            if (chunk != null)
            {
                Destroy(chunk.chunk);
            }
        }

        /*
         * Chunk chunk = MeshGeneration.GetFromRemoveQueue();
         * if (chunk != null)
         * {
         *  Destroy(chunk.chunk);
         * }
         */
    }
Exemple #4
0
 void Start()
 {
     generadorManejadores = GameObject.FindGameObjectWithTag("GeneradorManejadores");
     malla                 = GameObject.FindGameObjectWithTag("Mesh");
     meshGeneration        = GameObject.FindGameObjectWithTag("Mesh").GetComponent <MeshGeneration>();
     manejadores           = this.gameObject;
     generacionManejadores = generadorManejadores.GetComponent <GeneracionManejadores>();
 }
Exemple #5
0
    void MeshDataThread(MapData mapData, int lod, Action <MeshData> callback)
    {
        MeshData meshData = MeshGeneration.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, lod, useFlatShading);

        lock (meshDataThreadInfoQueue) {
            meshDataThreadInfoQueue.Enqueue(new MapThreadInfo <MeshData> (callback, meshData));
        }
    }
Exemple #6
0
    void MeshDataThread(MapData mapData, Action <MeshData> callback, int LOD)
    {
        MeshData meshData = MeshGeneration.GenerateMesh(mapData.heightMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, LOD);

        lock (meshDataThreadInfoQueue)
        {
            meshDataThreadInfoQueue.Enqueue(new MapThreadInfo <MeshData>(callback, meshData));
        }
    }
Exemple #7
0
    // generates the color of the terrain depending on height. Will also create monument valley-like mountains/vulcanos
    // Additionaly, spawns the waypoints at the right pos, and give it the proper height value and make sure if its walkable
    void GenerateTerrain()
    {
        Texture2D _texture = new Texture2D(width, length);

        _texture.wrapMode = TextureWrapMode.Clamp;

        Color[] colors = new Color[width * length];
        for (int w = 0; w < width; w++)
        {
            for (int l = 0; l < length; l++)
            {
                GameObject WP = Instantiate(wayPoint, new Vector3(), Quaternion.identity) as GameObject;
                if (noise[l, w] < 0.1)
                {
                    colors[w * length + l] = Color.red; // vulcano
                    float lavaHeight = 0.1f;
                    noise[l, w] = lavaHeight;
                }
                else if (noise[l, w] < 0.2)
                {
                    colors[w * length + l] = Color.gray; //mountain
                    float reverseValue = 0.2f - noise[l, w];
                    noise[l, w] = reverseValue;
                }
                // this part is added to make sure the edge of the mountains is also unwalkable. prevents the character from moving through the base of the wall
                else if (noise[l, w] < 0.21)
                {
                    colors[w * length + l] = new Color(0.5f, 0.2f, 0.2f); // brownish desert like
                }
                else if (noise[l, w] < 0.7)
                {
                    colors[w * length + l] = new Color(0.5f, 0.2f, 0.2f); // brownish desert like
                    WP.GetComponent <Waypoint>().walkable = true;
                }
                else if (noise[l, w] <= 0.9)
                {
                    colors[w * length + l] = new Color(0.9f, 0.8f, 0.2f);  // sand
                    WP.GetComponent <Waypoint>().walkable = true;
                }
                else
                {
                    colors[w * length + l] = Color.blue; //water
                    noise[l, w]            = 0.9f;
                }
                WP.transform.position       = new Vector3(l, -noise[l, w] * heightScale, w);
                GameManager.waypoints[l, w] = WP; // add the waypoint to the waypoint array
            }
        }
        _texture.SetPixels(colors);
        _texture.Apply();

        DrawPolygon(MeshGeneration.Generate(noise, heightScale), _texture);

        SpawnObjects();
    }
Exemple #8
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        MeshGeneration myScript = (MeshGeneration)target;

        if (GUILayout.Button("Generate"))
        {
            myScript.GenerateMesh();
        }
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        MeshGeneration myScript = (MeshGeneration)target;

        usingHeightMap = EditorGUILayout.Toggle("Using HeightMap", usingHeightMap);

        if (GUILayout.Button("Build Mesh"))
        {
            //myScript.CreateNewMesh();
            myScript.Generate(usingHeightMap);
        }
    }
    private static void checkForDestroys()
    {
        /*
         * int i = -1;
         * for (Chunk chunk = InfiniteWorld.GetFromRemoveQueue(); chunk != null; chunk = InfiniteWorld.GetFromRemoveQueue())
         * {
         *  Destroy(chunk.chunk);
         *  i++;
         *  if (i >= 1) { break; }
         * }
         */

        //for (int i = 0; i < destroysPerFrame; i++)
        //{

        Chunk chunk;// = MeshGeneration.GetFromRemoveQueue(); //; chunk != null; chunk = MeshGeneration.GetFromRemoveQueue()

        while ((chunk = MeshGeneration.GetFromRemoveQueue()) != null)
        {
            if (chunk.chunk == null)
            {
                unneededDeletes++;
                Debug.Log("unneeded deletes: " + unneededDeletes);
                continue;
            }
            //Debug.Log("asdklöfj: " + chunk);
            //Debug.Log("name: " + chunk.chunk.name);
            Destroy(chunk.chunk);
            // //Destroy(chunk.chunk);
            //chunk = MeshGeneration.GetFromRemoveQueue();
        }
        //}

        /*
         * for (int i = 0; i < destroysPerFrame; i++)
         * {
         *  Chunk chunk = MeshGeneration.GetFromRemoveQueue();
         *
         *  if (chunk.chunk != null)
         *  {
         *      Debug.Log("Removing " + chunk);
         *      Destroy(chunk.chunk);
         *  }
         *  else
         *  {
         *      break;
         *  }
         * }
         */
    }
Exemple #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            float a  = float.Parse(txt_a.Text);
            float b  = float.Parse(txt_b.Text);
            int   nv = int.Parse(txt_nv.Text);
            int   nh = int.Parse(txt_nh.Text);
            float k  = float.Parse(txt_k.Text);

            var a_parts = MeshGeneration.divideLength(a, nh, k);
            var b_parts = MeshGeneration.divideLength(b, nv, 1);

            ///node generation
            ThermoNode[][] nodes = MeshGeneration.GenerateNodes(a_parts, b_parts);
            //finite element generation
            List <HeatFElement> els = MeshGeneration.GenerateElements(nodes);

            drawMesh(a, b, els);
        }
Exemple #12
0
    public void DrawMap()
    {
        MapData mapData = GenerateChunkData(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay>(); //gets MapDisplay object

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap)); //draws the noisemap
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColourMap(mapData.colourMap, chunkSize, chunkSize)); //draws the colourmap
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGeneration.GenerateMesh(mapData.heightMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, editorLevelOfDetail), TextureGenerator.TextureFromColourMap(mapData.colourMap, chunkSize, chunkSize));
        }
    }
Exemple #13
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay> ();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGeneration.TextureFromHeightMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGeneration.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGeneration.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD, useFlatShading), TextureGeneration.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.FallOffMap)
        {
            display.DrawTexture(TextureGeneration.TextureFromHeightMap(FallOffGenerator.GenerateFallOffMap(mapChunkSize)));
        }
    }
    private static void xdirFunction(int xdir, int3 offset, Chunk[, ,] chunks)
    {
        if (xdir >= 1)
        {
            for (int i = 0; i < xdir; i++)
            {
                ChunkWorldPositionOffset.x += 1;
                for (int x = 0; x < worldChunkSize.x; x++)
                {
                    for (int y = 0; y < worldChunkSize.y; y++)
                    {
                        for (int z = 0; z < worldChunkSize.z; z++)
                        {
                            if (x == 0)
                            {
                                MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]);
                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x + 1, y, z].AddChunkDrawdataToMeshQueue));
                            }
                            if (x == worldChunkSize.x - 1)
                            {
                                int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z);

                                WorldInitializer.chunkArray[x, y, z] = new Chunk(pos, offset);
                                ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue));
                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x - 1, y, z].AddChunkDrawdataToMeshQueue));
                            }
                            else
                            {
                                chunks[x, y, z] = chunks[x + 1, y, z];
                            }

                            /*
                             * //newstuff after this
                             *
                             * if (x == worldChunkSize.x - 1)
                             * {
                             *
                             * }
                             */
                        }
                    }
                }
            }
        }

        else if (xdir <= -1)
        {
            for (int i = 0; i > xdir; i--)
            {
                ChunkWorldPositionOffset.x -= 1;
                for (int x = worldChunkSize.x - 1; x >= 0; x--)
                {
                    for (int y = worldChunkSize.y - 1; y >= 0; y--)
                    {
                        for (int z = worldChunkSize.z - 1; z >= 0; z--)
                        {
                            if (x == (worldChunkSize.x - 1))
                            {
                                MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]);

                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x - 1, y, z].AddChunkDrawdataToMeshQueue));
                            }
                            if (x == 0)
                            {
                                int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z);
                                WorldInitializer.chunkArray[x, y, z] = new Chunk(pos, offset);
                                ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue));
                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x + 1, y, z].AddChunkDrawdataToMeshQueue));
                            }
                            else
                            {
                                chunks[x, y, z] = chunks[x - 1, y, z];
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #15
0
 private void Awake()
 {
     meshGeneration = GetComponent<MeshGeneration>();
 }
    private static List <Chunk> zdirFunction(int zdir, int3 offset)
    {
        List <Chunk> chunksToBeDrawn = new List <Chunk>();

        if (zdir >= 1)
        {
            for (int i = 0; i < zdir; i++)
            {
                ChunkWorldPositionOffset.z += 1;
                for (int x = 0; x < worldChunkSize.x; x++)
                {
                    for (int y = 0; y < worldChunkSize.y; y++)
                    {
                        for (int z = 0; z < worldChunkSize.z; z++)
                        {
                            if (z == 0)
                            {
                                //MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]);
                                MeshGeneration.AddToRemoveQueue(WorldInitializer.getChunk(x, y, z));

                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z + 1].AddChunkDrawdataToMeshQueue));
                            }
                            else if (z == worldChunkSize.z - 1)
                            {
                                int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z);

                                WorldInitializer.setChunk(x, y, z, new Chunk(pos, offset));
                                if (!WorldInitializer.getChunk(x, y, z).anyNonAir)
                                {
                                    continue;
                                }
                                chunksToBeDrawn.Add(WorldInitializer.getChunk(x, y, z));

                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue));

                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z - 1].AddChunkDrawdataToMeshQueue));
                            }
                            else
                            {
                                //chunks[x, y, z] = chunks[x, y, z + 1];
                                WorldInitializer.setChunk(x, y, z, WorldInitializer.getChunk(x, y, z + 1));
                            }
                        }
                    }
                }
            }
        }
        else if (zdir <= -1)
        {
            for (int i = 0; i > zdir; i--)
            {
                ChunkWorldPositionOffset.z -= 1;
                for (int x = worldChunkSize.x - 1; x >= 0; x--)
                {
                    for (int y = worldChunkSize.y - 1; y >= 0; y--)
                    {
                        for (int z = worldChunkSize.z - 1; z >= 0; z--)
                        {
                            if (z == (worldChunkSize.z - 1))
                            {
                                //MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]);
                                MeshGeneration.AddToRemoveQueue(WorldInitializer.getChunk(x, y, z));


                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z - 1].AddChunkDrawdataToMeshQueue));
                            }
                            else if (z == 0)
                            {
                                int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z);
                                WorldInitializer.setChunk(x, y, z, new Chunk(pos, offset));
                                if (!WorldInitializer.getChunk(x, y, z).anyNonAir)
                                {
                                    continue;
                                }
                                chunksToBeDrawn.Add(WorldInitializer.getChunk(x, y, z));
                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue));
                                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z + 1].AddChunkDrawdataToMeshQueue));
                            }
                            else
                            {
                                //chunks[x, y, z] = chunks[x, y, z - 1];
                                WorldInitializer.setChunk(x, y, z, WorldInitializer.getChunk(x, y, z - 1));
                            }
                        }
                    }
                }
            }
        }
        return(chunksToBeDrawn);
    }