Esempio n. 1
0
    public void drawMapInEditor()
    {
        textureData.applyToMaterial(terrainMaterial);
        textureData.updateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap heightMap = HeightMapGenerator.generateHeightmap(meshSettings.numVerticesPerLine, meshSettings.numVerticesPerLine, heightMapSettings, Vector2.zero);

        if (drawMode == DrawMode.NoiseMap)
        {
            drawTexture(TextureGenerator.textureFromHeightmap(heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            if (heightMapSettings.useFalloff)
            {
                float[,] falloff = FalloffGenerator.generateFalloffMap(meshSettings.numVerticesPerLine);
                for (int i = 0; i < heightMap.values.GetLength(0); i++)
                {
                    for (int j = 0; j < heightMap.values.GetLength(1); j++)
                    {
                        heightMap.values[i, j] = heightMap.values[i, j] * (1 - falloff[i, j]);
                    }
                }
            }
            drawMesh(MeshGenerator.generateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
        }
        else if (drawMode == DrawMode.Falloff)
        {
            drawTexture(TextureGenerator.textureFromHeightmap(new HeightMap(FalloffGenerator.generateFalloffMap(meshSettings.numVerticesPerLine), 0, 1)));
        }
    }
Esempio n. 2
0
    public void DrawMapInEditor()
    {
        MapData    mapData = GenerateMapData(Vector2.zero);
        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromNoiseMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(
                MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorLevelOfDetail),
                TextureGenerator.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize)
                );
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            if (falloffMode == FalloffMode.Square)
            {
                display.DrawTexture(TextureGenerator.TextureFromNoiseMap(FalloffGenerator.GenerateFalloffMap(mapChunkSize)));
            }
            else
            {
                display.DrawTexture(TextureGenerator.TextureFromNoiseMap(FalloffGenerator.GenerateCircularFalloffMap(mapChunkSize)));
            }
        }
    }
Esempio n. 3
0
    MapData GenerateMapData(Vector2 center)
    {
        mapGrid = new MapCell[mapChunkSize, mapChunkSize];
        if (falloffShape == FalloffShape.square)
        {
            falloffMap = FalloffGenerator.GenerateSquareFalloffMap(mapChunkSize);
        }
        else if (falloffShape == FalloffShape.circle)
        {
            falloffMap = FalloffGenerator.GenerateCircularFalloffMap(mapChunkSize);
        }

        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize, mapChunkSize, seed, noiseData.noiseScale, noiseData.octaves, noiseData.persistance, noiseData.lacunarity, center + noiseData.offset, noiseData.normalizeMode);


        for (int y = 0; y < mapChunkSize; y++)
        {
            for (int x = 0; x < mapChunkSize; x++)
            {
                if (useFalloff)
                {
                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]);
                }
                float currentHeight = noiseMap[x, y];
                mapGrid[x, y].height = currentHeight;
            }
        }

        return(new MapData(noiseMap));
    }
    void UpdatePreview()
    {
        FalloffGenerator generator = (FalloffGenerator)target;

        float[,] noiseMap = generator.Generate(120, 120);
        texture           = TextureGenerator.TextureFromHeightMap(noiseMap);
    }
Esempio n. 5
0
    MapData GenerateMapData(Vector2 center)
    {
        float [,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, noiseData.seed, noiseData.noiseScale, noiseData.octaves, noiseData.persistance, noiseData.lacunarity, center + noiseData.offset, noiseData.normalizeMode);

        if (terrainData.useFalloff)
        {
            if (falloffMap == null)
            {
                falloffMap = FalloffGenerator.GenerateFalloffMap(mapChunkSize + 2);
            }
            for (int y = 0; y < mapChunkSize + 2; y++)
            {
                for (int x = 0; x < mapChunkSize + 2; x++)
                {
                    if (terrainData.useFalloff)
                    {
                        noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]);
                    }
                }
            }
        }
        // textureData.UpdateMeshHeights(terrainMaterial, terrainData.minHeight, terrainData.maxHeight);

        return(new MapData(noiseMap));
    }
Esempio n. 6
0
    /**
     * Method that generates the noise map and color map
     * @param center Center of the map
     */
    MapData GenerateMapData(Vector2 center)
    {
        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, noiseData.seed, noiseData.noiseScale, noiseData.octaves, noiseData.persistence, noiseData.lacunarity, center + noiseData.offset, noiseData.normalizeMode);

        if (terrainData.useFalloff)
        {
            if (falloffMap == null)
            {
                falloffMap = FalloffGenerator.GenerateFalloffMap(mapChunkSize + 2);
            }

            // Noise map generation based on the height map
            for (int y = 0; y < mapChunkSize + 2; y++)
            {
                for (int x = 0; x < mapChunkSize + 2; x++)
                {
                    // Apply the falloff map to the generated terrain
                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]);
                }
            }
        }

        textureData.UpdateMeshHeights(terrainMaterial, terrainData.MinHeight, terrainData.MaxHeight);

        return(new MapData(noiseMap));
    }
Esempio n. 7
0
    MapData GenerateMapData(Vector2 center)
    {
        // Generate Noisemap
        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, noiseData.seed, noiseData.noiseScale, noiseData.octaves, noiseData.persistance, noiseData.lacunarity, center + noiseData.offset, noiseData.normalizeMode);

        if (terrainData.useFalloff)
        {
            if (falloffMap == null)
            {
                falloffMap = FalloffGenerator.GenerateFalloffMap(mapChunkSize + 2);
            }

            for (int y = 0; y < mapChunkSize + 2; y++)
            {
                for (int x = 0; x < mapChunkSize + 2; x++)
                {
                    // Clamp to falloff map
                    if (terrainData.useFalloff)
                    {
                        noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]);
                    }
                }
            }
        }

        return(new MapData(noiseMap));
    }
Esempio n. 8
0
    private float[,] GenerateNoiseMap()
    {
        float[,] noiseMap =
            Noise.GenerateNoise(
                noiseData.mapWidth,
                noiseData.mapHeight,
                noiseData.seed,
                noiseData.noiseScale,
                noiseData.octaves,
                noiseData.persistance,
                noiseData.lacunarity,
                noiseData.offset);

        float[,] falloffMap =
            FalloffGenerator.GenerateFalloffMap(noiseData.mapWidth, noiseData.mapHeight);

        if (noiseData.falloff)
        {
            for (int y = 0; y < noiseData.mapHeight; y++)
            {
                for (int x = 0; x < noiseData.mapWidth; x++)
                {
                    noiseMap[x, y] = noiseMap[x, y] - falloffMap[x, y];
                }
            }
        }

        // noiseMap = falloffMap;

        return(noiseMap);
    }
Esempio n. 9
0
 public void ToSmall()
 {
     mapWidth   = 100;
     mapHeight  = 100;
     falloffMap = FalloffGenerator.GenerateFalloffMap(mapWidth, mapHeight);
     Generatemap();
 }
Esempio n. 10
0
    public void DrawMapInEditor()
    {
        if (newSeed)
        {
            heightMapSettings.noiseSettings.seed = rng.Next();
        }
        else
        {
            heightMapSettings.noiseSettings.seed = seed;
        }
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, Vector2.zero);

        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1)));
        }
    }
Esempio n. 11
0
    // When script variable is changed in inspector
    void OnValidate()
    {
        // Clamp values
        if (size < 1)
        {
            size = 1;
        }
        if (size < 1)
        {
            size = 1;
        }
        if (octaves < 1)
        {
            octaves = 1;
        }
        if (lacunarity < 1.0f)
        {
            lacunarity = 1.0f;
        }
        if (noiseScale < 0.0f)
        {
            noiseScale = 0.0f;
        }

        // Create the falloff map
        falloffMap = FalloffGenerator.GenerateFalloffMap(size, falloffPower, falloffDistance);
    }
    /// <summary>
    /// Draws the preview map in the scene.
    /// </summary>
    public void DrawMapInEditor()
    {
        // applies the texture settings to the material
        textureSettings.ApplyToMaterial(terrainMaterial);
        textureSettings.UpdateMeshHeights(terrainMaterial, heightMapSettings.MinHeight, heightMapSettings.MaxHeight);
        // generates a height map from the mesh, height map and noise settings at location (0, 0)
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.NumVertsPerLine, meshSettings.NumVertsPerLine, heightMapSettings, Vector2.zero);

        // draws a noise map on a texture
        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        // generates a mesh from the height map
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
        }
        // draws a falloff map on a texture
        else if (drawMode == DrawMode.FalloffMap)
        {
            // passes in a height map generated from the falloff generator
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.NumVertsPerLine), 0, 1)));
        }
    }
Esempio n. 13
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(Vector2.zero);

        textureData.UpdateMeshHeights(
            terrainMaterial, terrainData.minHeight, terrainData.maxHeight);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(
                                    mapData.heightMap)
                                );
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(
                MeshGenerator.GenerateTerrainMesh(
                    mapData.heightMap, terrainData.meshHeightMultiplier,
                    terrainData.meshHeightCurve, editorPreviewLOD,
                    terrainData.useFlatShading
                    )
                );
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(
                                    FalloffGenerator.GenerateFalloffMap(mapChunkSize))
                                );
        }
    }
Esempio n. 14
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap heightMap;

        if (eastSettings != null && westSettings != null && westLocation != null && westLocation != null)
        {
            Region east = new Region(eastSettings, eastLocationPos);
            Region west = new Region(westSettings, westLocationPos);
            heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings, new Region(heightMapSettings, east, west, Vector3.zero, power), Vector2.zero);
        }
        else
        {
            heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings, heightMapSettings, Vector2.zero);
        }

        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1)));
        }
    }
    public void DrawMapInEditor()
    {
        GenerarMeshTerreno();
        GenerarMapaColores();
        //Obtenemos el script MapDisplay que esta en nuestro mismo GameObject
        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        if (modoDibujo == ModoDibujo.MapaRuido)
        {
            mapDisplay.DibujarTextura(TextureGenerator.TextureFromHeigthMap(mapaRuido));
        }
        else if (modoDibujo == ModoDibujo.MapaColores)
        {
            mapDisplay.DibujarTextura(GeneradorTextura.TextureFromColourMap(mapaColores, dimensionMapa, dimensionMapa));
        }
        else if (modoDibujo == ModoDibujo.Mesh)
        {
            //mapDisplay.DibujarMesh2(mesh, TextureGenerator.TextureFromHeigthMap(mapaRuido));
            mapDisplay.DibujarMesh2(mesh, TextureGenerator.TextureFromColourMap(mapaColores, dimensionMapa, dimensionMapa));
        }
        else if (modoDibujo == ModoDibujo.MapaFalloff)
        {
            mapDisplay.DibujarTextura(GeneradorTextura.TextureFromHeigthMap(FalloffGenerator.GenerateFalloffMap(dimensionMapa)));
        }
    }
Esempio n. 16
0
 public void ToMedium()
 {
     mapWidth   = 200;
     mapHeight  = 200;
     falloffMap = FalloffGenerator.GenerateFalloffMap(mapWidth, mapHeight);
     Generatemap();
 }
Esempio n. 17
0
    public void DrawMap()
    {
        var display = GetComponent <MapDisplay>();

        var noiseMap = Noise.GenerateNoiseMap(meshSize, meshSize, seed, scale, octaves, amplitude, frequency, offsets);

        if (useFalloff)
        {
            var falloffData = FalloffGenerator.GenerateFalloffMap(meshSize);
            for (int y = 0; y < meshSize; y++)
            {
                for (int x = 0; x < meshSize; x++)
                {
                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffData[x, y]);
                }
            }
        }

        switch (drawMode)
        {
        case DrawMode.NoiseMap:
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap, layers));
            break;

        case DrawMode.Mesh:
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap, layers));
            display.DrawMesh(MeshGenerator.GenerateTerrianMesh(noiseMap, meshHeightMulti, lod, heightAdjuestCurve));
            break;

        case DrawMode.FalloffMap:
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FalloffGenerator.GenerateFalloffMap(meshSize), layers));
            break;
        }
    }
Esempio n. 18
0
 public void ToLarge()
 {
     mapWidth   = 255;
     mapHeight  = 255;
     falloffMap = FalloffGenerator.GenerateFalloffMap(mapWidth, mapHeight);
     Generatemap();
 }
Esempio n. 19
0
 /// <summary>
 /// Creates two different noise maps
 /// NoiseMap2 : Breaks up the clean edges of each noise map
 ///          : Will subtract and add to the original noise map
 ///
 /// NoiseMap3 : Breaks up the original noise map by subtrating large chunks
 /// </summary>
 private float[,] GenerateWorlds(float[,] noiseMap, int _width, int _height, int seed, Vector2 offset, bool useErode,
                                 bool useFalloff, bool useBreakUp)
 {
     float[,] falloffMap = FalloffGenerator.GenerateFalloffMap(_width, _height);
     float[,] noiseMap2  = Noise.GenerateNoiseMap(_width, _height, seed, 14, 2, 5, 2, offset);
     float[,] noiseMap3  = Noise.GenerateNoiseMap(_width, _height, seed, 60, 4, 0.1f, 0.1f, offset);
     for (int y = 0; y < _height; y++)
     {
         for (int x = 0; x < _width; x++)
         {
             if (useErode && noiseMap[x, y] > noiseMap2[x, y])
             {
                 noiseMap[x, y] -= noiseMap2[x, y] / 10;
             }
             if (useFalloff)
             {
                 noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]);
             }
             if (useBreakUp)
             {
                 noiseMap[x, y] -= Mathf.Clamp01(noiseMap[x, y] - noiseMap3[x, y]);
             }
             if (useErode && noiseMap[x, y] > noiseMap2[x, y] && noiseMap[x, y] < 0.67)
             {
                 noiseMap[x, y] += noiseMap2[x, y] / 6;
             }
         }
     }
     return(noiseMap);
 }
Esempio n. 20
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(
            meshSettings.numVertsPerLine,
            meshSettings.numVertsPerLine,
            heightMapSettings,
            Vector2.zero
            );

        switch (drawMode)
        {
        case DrawMode.NoiseMap:
            DrawTexture(TextureGenerator.TextureFromeHeightMap(heightMap));
            break;

        case DrawMode.Mesh:
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
            break;

        case DrawMode.FallofMap:
            DrawTexture(TextureGenerator.TextureFromeHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1)));
            break;
        }
    }
Esempio n. 21
0
    public void GenerateMap()
    {
        int seed = (worldSeed != "") ? ((int.TryParse(worldSeed, out int i))? i : worldSeed.GetHashCode()) : UnityEngine.Random.Range(int.MinValue, int.MaxValue);

        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize, mapChunkSize, seed, noiseScale, octaves, persistance, lacunarity);
        Debug.Log("World generated with seed: " + seed.ToString());
        if (useFalloff)
        {
            for (int y = 0; y < mapChunkSize; y++)
            {
                for (int x = 0; x < mapChunkSize; x++)
                {
                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]);
                }
            }
        }

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawNoiseMap(noiseMap);
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(noiseMap, meshHeightMultiplier, meshHeightCurve, levelOfDetail, true));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            display.DrawNoiseMap(FalloffGenerator.GenerateFalloffMap(mapChunkSize));
        }
        newMapGenerated?.Invoke();
    }
Esempio n. 22
0
    private void Awake()
    {
        playersGO = GameObject.FindGameObjectsWithTag("Player");

        if (NetworkManager.singleton.playerPrefab.GetComponent <PlayerSetup>().isServer)
        {
            isHost = true;
        }

        //mapChunkSize = 241;
        //MapData.mapChunkSize = mapChunkSize;

        falloffMap = FalloffGenerator.GenerateFalloffMap(mapChunkSize);
        if (isHost)
        {
            seed = Random.Range(int.MinValue, int.MaxValue);
            NetworkManager.singleton.playerPrefab.GetComponent <PlayerSetup>().mapSeed = seed;
        }
        else
        {
            for (int i = 0; i < playersGO.Length; ++i)
            {
                if (playersGO[i].GetComponent <PlayerSetup>().isServer)
                {
                    seed = playersGO[i].GetComponent <PlayerSetup>().mapSeed;
                    break;
                }
            }
        }

        MapData.seed = seed;
        GenerateMap();

        MapData.regions = this.regions;
    }
Esempio n. 23
0
    // Each island has it's own perlin noise map
    // TODO: Try islands with varying width and heigth
    public Island generateIsland(Vector2Int origin, int size, int islandIndex)
    {
        float[,] noiseMap   = NoiseGenerator.GenerateNoiseMap(size, size, seed, scale, octaves, persistance, lacunarity, Vector2.zero, NoiseGenerator.NormalizeMode.Global);
        float[,] falloffMap = FalloffGenerator.GenerateFalloffMap(size);

        List <TileData> tiles = new List <TileData>();

        for (int j = 0; j < size; j++)
        {
            for (int i = 0; i < size; i++)
            {
                float value = Mathf.Clamp01(noiseMap[i, j] - falloffMap[i, j]); // Get value by subtracting falloff from noise
                // If this is above a certain value then add a tile
                if (value > heightMapCutoff)
                {
                    TileData tile = new TileData(origin.x + i, origin.y + j, TileType.Ground);
                    tile.island = islandIndex;
                    tiles.Add(tile);
                }
            }
        }

        Island island = new Island()
        {
            origin = origin,
            size   = size,
            tiles  = tiles.ToArray(),
            index  = islandIndex
        };

        return(island);
    }
Esempio n. 24
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh
                (MeshGenerator.GenerateTerrainMesh
                    (mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD),
                TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FalloffGenerator.GenerateFalloffMap(mapChunkSize)));
        }
    }
Esempio n. 25
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial,
                                      heightMapSettings.minHeight, heightMapSettings.maxHeight);

        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(
            meshSettings.numVerticesPerLine,
            meshSettings.numVerticesPerLine,
            heightMapSettings,
            Vector2.zero
            );

        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(
                         heightMap.values,
                         editorPreviewLOD,
                         meshSettings
                         )
                     );
        }
        else
        {
            float[,] values = FalloffGenerator.GenerateFalloffMap(meshSettings.numVerticesPerLine);
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(values, 0, 1)));
        }
    }
Esempio n. 26
0
    /// <summary>
    ///  This function is used to preview all changes made to the map generating functionality in the editor
    /// </summary>
    public void drawMapInEditor()
    {
        //Generate the mapData centered around the origin
        MapData mapData = generateMapData(Vector2.zero);

        //Get the mapDisplay script
        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        //If the NOISEMAP enum has been selected, we display the noisemap in the editor
        if (drawMode == DrawMode.NOISEMAP)
        {
            //Generate the texture for the heightmap
            Texture2D texture = TextureGenerator.textureFromHeightMap(mapData.heightMap);
            //Apply the generated texture to the plane game object in map display
            mapDisplay.drawTexture(texture);

            //If the MESH enum has been selected, we generate the mesh in the editor
        }
        else if (drawMode == DrawMode.MESH)
        {
            //Generate the meshData necessary for the mesh
            MeshData meshData = MeshGenerator.generateTerrainMesh(mapData.heightMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, editorLOD, terrainData.useFlatShading);
            //Apply the mesh to the mesh game object in map display
            mapDisplay.drawMesh(meshData);

            //If the FALLOFFMAP enum has been selected, we draw a black-and-white texture similar to the noisemap
        }
        else if (drawMode == DrawMode.FALLOFFMAP)
        {
            falloffMap = FalloffGenerator.generateFalloffMap(mapChunkSize + 2, falloffCurveA, falloffCurveB);
            Texture2D texture = TextureGenerator.textureFromHeightMap(falloffMap);
            mapDisplay.drawTexture(texture);
        }
    }
Esempio n. 27
0
    public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, MeshSettings meshSettings, Vector2 sampleCenter)
    {
        float[,] values     = Noise.GenerateNoiseMap(width, height, settings.noiseSettings, sampleCenter);
        float[,] falloffMap = FalloffGenerator.GenerateFallofMap(meshSettings.numVertsPerLine);

        // create a new animation curve for each mesh so that weird spikes dont be spiky (fixes an animation curve 'optamization')
        AnimationCurve heightCurve_threadsafe = new AnimationCurve(settings.heightCurve.keys);

        float minValue = float.MaxValue;
        float maxValue = float.MinValue;

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                if (settings.useFalloff)
                {
                    values[i, j] = Mathf.Clamp01(values[i, j] - falloffMap[i, j]);
                }
                values[i, j] *= heightCurve_threadsafe.Evaluate(values[i, j]) * settings.heightMultiplier;

                if (values[i, j] > maxValue)
                {
                    maxValue = values[i, j];
                }
                if (values[i, j] < minValue)
                {
                    minValue = values[i, j];
                }
            }
        }

        return(new HeightMap(values, minValue, maxValue));
    }
Esempio n. 28
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, Vector2.zero);
        HeatMap   heatMap   = HeatMapGenerator.GenerateHeatMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMap, heatMapSettings, Vector2.zero);
        TreeMap   treeMap   = TreeMapGenerator.generateVegetationMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMap, heatMap, treeMapSettings, Vector2.zero);

        DestroyTrees();          //temporary fix

        if (drawMode == DrawMode.HeightMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh2(heightMap.values, meshSettings, editorPreviewLOD, heatMap.values));
            DrawTrees(heightMap.values, meshSettings, treeMap.values);
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1)));
        }
        else if (drawMode == DrawMode.HeatMap)
        {
            DrawTexture(TextureGenerator.TextureColorizedFromHeatMap(heatMap));
        }
        else if (drawMode == DrawMode.TreeMap)
        {
            DrawTexture(TextureGenerator.TextureFromTreeMap(treeMap));
        }
    }
Esempio n. 29
0
    public void GenerateMap()
    {
        Random.InitState(mapSeed);//seed
        terrainMesh = terrainObject.GetComponent<MeshFilter>().mesh;
        fallOffMap = FalloffGenerator.GenerateFalloffMap(chuckSize);
        float[,] noisemap = Noise.GenerateNoiseMap(chuckSize, chuckSize, mapSeed, noiseScale, ocataves, presitance, lacunarity, offset);
        for (int y = 0; y < chuckSize; y++)
        {
            for (int x = 0; x < chuckSize; x++)
            {
                if (useFallOffs)
                {
                    if (fallOffMap == null)
                    {
                        fallOffMap = FalloffGenerator.GenerateFalloffMap(chuckSize);
                    }
                    noisemap[x, y] = Mathf.Clamp01(noisemap[x, y] - fallOffMap[x, y]);
                }
            }
        }
        MapDisplay display = FindObjectOfType<MapDisplay>();
        display.DrawMesh(MeshGenerator.GenerateTerrainMesh(noisemap, meshHeightMultiplier, meshHeightCurve, editorPrevieuwLOD, flatShading,GetComponent<MapGenerator>()), TextureGenerator.TextureFromColourMap(collorMap, chuckSize, chuckSize));

        Invoke("ColorMap", 1);
    }
Esempio n. 30
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);

        ChunkBorderInfo chunkBorderInfo = new ChunkBorderInfo(false, FalloffGenerator.Corner.TOPLEFT, false, FalloffGenerator.Edge.TOP);
        HeightMap       heightMap       = HeightMapGenerator.GenerateHeightMap(meshSettings.numberVerticesPerLine, meshSettings.numberVerticesPerLine, heightMapSettings, mapRulesSettings, Vector2.zero, chunkBorderInfo);

        CleanScene();

        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numberVerticesPerLine, mapRulesSettings), 0, 1)));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
        }
        else if (drawMode == DrawMode.Map)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
            DrawMap();
        }
    }