Пример #1
0
    private void GenerateMap()
    {
        hexagons = new Hexagon[width + 1, height + 1];
        float[,] perlinNoiseMap = PerlinNoise.GeneratePerlinNoiseMap(width, height, 4f, 4);

        for (int col = 0; col < width; col++)
        {
            for (int row = 0; row < height; row++)
            {
                float   latitude = perlinNoiseMap[col, row];
                Hexagon h        = new Hexagon(col, row);

                hexagons[col, row] = h;
                GameObject   HexagonGameObject = Instantiate(hexagonPrefab, h.GetPosition(), Quaternion.identity, this.transform);
                MeshRenderer meshRenderer      = HexagonGameObject.GetComponentInChildren <MeshRenderer>();

                for (int i = 0; i < materialHeightRanges.Length; i++)
                {
                    if (latitude <= materialHeightRanges[i])
                    {
                        meshRenderer.material = hexagonMaterials[i];
                        break;
                    }
                }
            }
        }
    }
Пример #2
0
    float[,] GetHeightMap()
    {
        int   width  = (int)(_width * Mathf.Pow(2, _detailLevel));
        int   height = (int)(_height * Mathf.Pow(2, _detailLevel));
        float scale  = _scale * Mathf.Pow(2, _detailLevel);

        return(PerlinNoise.GeneratePerlinNoiseMap(width, height, _seed, scale, _octaves, _persistence, _lacunarity, _offset));
    }
Пример #3
0
    public void GenerateMap()
    {
        float[,] heightMap = PerlinNoise.GeneratePerlinNoiseMap(_width, _height, _seed, _scale, _octaves, _persistence, _lacunarity, _offset);
        Color[] colorMap = GetColorMap(heightMap);

        switch (_drawMode)
        {
        case DrawMode.NoiseMap:
            _displayer.DrawTexture2D(TextureGenerator.TextureFromHeightMap(heightMap));
            break;

        case DrawMode.ColorsMap:
            _displayer.DrawTexture2D(TextureGenerator.TextureFromColorMap(colorMap, _width, _height));
            break;

        case DrawMode.Mesh:
            _displayer.DrawMesh(MeshGenerator.GeneratorTerrainMesh(heightMap, _maxMeshHeight, _heightCurve), TextureGenerator.TextureFromColorMap(colorMap, _width, _height));
            break;
        }
    }
    MapData GenerateMapData()
    {
        float[,] perlinNoiseMap = PerlinNoise.GeneratePerlinNoiseMap(mapChunkSize, mapChunkSize, noiseScale, seed, octaves, persistance, lacunarity, offset);

        Color[] colorMap = new Color[mapChunkSize * mapChunkSize];
        for (int y = 0; y < mapChunkSize; y++)
        {
            for (int x = 0; x < mapChunkSize; x++)
            {
                float currentHeight = perlinNoiseMap[x, y];
                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions[i].height)
                    {
                        colorMap[y * mapChunkSize + x] = regions[i].color;
                        break;
                    }
                }
            }
        }
        return(new MapData(perlinNoiseMap, colorMap));
    }