Esempio n. 1
0
    /// <summary>
    /// Gets the height map data.
    /// </summary>
    /// <returns>The height map data.</returns>
    /// <param name="w">The width.</param>
    /// <param name="h">The height.</param>
    public override float[,] GetHeightmapData(int w, int h, int x, int z)
    {
        heightMapBuilder = new LibNoise.Noise2D(w, h, perlinNoiseGenerator);
        heightMapBuilder.GeneratePlanar(left, right, top, bottom);

        return(heightMapBuilder.GetData());
    }
Esempio n. 2
0
    /// <summary>
    /// Gets the height map data.
    /// </summary>
    /// <returns>The height map data.</returns>
    /// <param name="w">The width.</param>
    /// <param name="h">The height.</param>
    public override float[,] GetHeightmapData(int w, int h, int x, int z)
    {
        heightMapBuilder = new Noise2D(w, h, finalTerrain);
        heightMapBuilder.GeneratePlanar(left, right, top, bottom);

        return(heightMapBuilder.GetData());
    }
Esempio n. 3
0
    void RandomizeTerrainHeights()
    {
        int noiseSeed   = Random.Range(0, int.MaxValue);
        var noiseMap    = new LibNoise.Noise2D(m_TerrainData.heightmapWidth, m_TerrainData.heightmapHeight);
        var noiseModule = new LibNoise.Generator.Perlin();

        // Configure the noise parameters
        noiseModule.OctaveCount = 20;
        noiseModule.Persistence = 0.45f;
        noiseModule.Seed        = noiseSeed;
        noiseMap.Generator      = noiseModule;

        // Generate the noise map
        noiseMap.GeneratePlanar(-1.5f, 1.5, -1.5, 1.5f, true);

        // Get a two-dimensional array of heights from the noise map
        float borderHeight = m_TerrainBorderHeight / m_TerrainData.size.y;

        float[,] heights = noiseMap.GetData();

        // Loop through every "pixel" and set the height to a random value
        for (int x = 0; x < m_TerrainData.heightmapWidth; x++)
        {
            for (int y = 0; y < m_TerrainData.heightmapHeight; y++)
            {
                // Divide the height by 2 so it doesn't flow over the top of the arena
                heights[x, y] /= 2f;

                // Fill in flat areas with random noise
                if (heights[x, y] <= borderHeight &&
                    heights[x, y] >= borderHeight / 2)
                {
                    float newHeight = Random.Range(0f, borderHeight / 2);
                    heights[x, y] = Mathf.Lerp(heights[x, y], newHeight, 0.5f);
                }

                // Update the maxHeight variable if the current height point breaks the previous record
                if (heights[x, y] > m_MaxHeight)
                {
                    m_MaxHeight = heights[x, y];
                }
            }
        }

        // Debug.Log("Max Height: " + m_MaxHeight);

        // Store the result back into terrainData
        m_TerrainData.SetHeights(0, 0, heights);
    }