private float[,] Generate(int chunkSeed, int generationMethod, float roughness, float offsetX, float offsetY)
    {
        float[,] heightMap;
        switch ((int)generationMethod)
        {
        case 1:
            heightMap = MidpointDisplacement.GenerateHeightMap(chunkSize, chunkSeed, 0.5f, roughness);
            break;

        case 2:
            heightMap = DiamondSquare.GenerateHeightMap(chunkSize, chunkSeed, 0.5f, roughness);
            break;

        case 3:
            heightMap = SquareSquare.GenerateHeightMap(chunkSize, chunkSeed, roughness);
            break;

        /*
         * case 4:
         *      heightMap = Perlin.GenerateHeightMap (chunkSize, chunkSeed, offsetX, offsetY, perlin_Lacunarity, perlin_Persistance, perlin_Scale);
         *      break;
         */
        default:
            heightMap = null;
            break;
        }
        return(heightMap);
    }
    private void InitializeChunks()
    {
        float[,] heightMap = DiamondSquare.GenerateHeightMap(exponentialMapSize, noiseIntensity, seed);
        heightMap          = GaussianBlur.ApplyBlur(heightMap, 5);

        for (int z = 0; z < renderDistance; z++)
        {
            for (int x = 0; x < renderDistance; x++)
            {
                // Create new chunk
                var newChunk = new NChunk(CHUNK_WIDTH, CHUNK_HEIGHT, new Vector3Int(x * CHUNK_WIDTH, 0, z * CHUNK_WIDTH), this.transform);
                _loadedChunks[x, z] = newChunk;

                for (int vZ = 0; vZ < CHUNK_WIDTH; vZ++)
                {
                    for (int vX = 0; vX < CHUNK_WIDTH; vX++)
                    {
                        // TODO: Add cancel condition if v_X + (x * CHUNK_WIDTH) and v_Z + (z * CHUNK_WIDTH) are not inside heightmap
                        // Calculate y-value of voxel
                        int y = Mathf.Abs((int)heightMap[vX + (x * CHUNK_WIDTH), vZ + (z * CHUNK_WIDTH)]);

                        // Add voxels to chunk
                        _loadedChunks[x, z].Add(new NVoxel(new Vector3Int(vX, y, vZ), NBlockType.Grass));
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
    private void Initialize()
    {
        _mesh         = new Mesh();
        _vertexesList = new List <Vector3>();
        _triangleList = new List <int>();
        this.GetComponent <MeshFilter>().mesh = _mesh;

        _heightMap = DiamondSquare.GenerateHeightMap(8, 34);
        _heightMap = GaussianBlur.ApplyBlur(_heightMap, gaussRepeatAmount);
    }
        private void AddOctave()
        {
            float [,] secondOctave = DiamondSquare.GenerateHeightMap(_exponentialMapSize, _noiseIntensity, _seed);

            for (int z = 0; z < _mapSize; z++)
            {
                for (int x = 0; x < _mapSize; x++)
                {
                    _heightMap[x, z] += secondOctave[x, z];
                }
            }
        }
Exemplo n.º 5
0
    private void SetHeightMap()
    {
        float[,] tmpHeightMap = DiamondSquare.GenerateHeightMap(world);

        heightMap = new int[world.WorldAttributes.WorldSizeInBlocks, world.WorldAttributes.WorldSizeInBlocks];

        for (int x = 0; x < world.WorldAttributes.WorldSizeInBlocks; ++x)
        {
            for (int z = 0; z < world.WorldAttributes.WorldSizeInBlocks; ++z)
            {
                heightMap[x, z] = Mathf.RoundToInt(tmpHeightMap[x, z]
                                                   * world.WorldAttributes.BiomeAttributes[world.Bioms[x, z]].BiomeHeight
                                                   + world.WorldAttributes.BiomeAttributes[world.Bioms[x, z]].SolidGroundHeight);
            }
        }
    }
        private void OnGUI()
        {
            EditorGUILayout.LabelField("Diamond Square", EditorStyles.boldLabel);

            _gradient           = EditorGUILayout.GradientField("Gradient", _gradient);
            _seed               = EditorGUILayout.IntField("Seed", _seed);
            _exponentialMapSize = EditorGUILayout.IntSlider("Map Size (n-Factor)", _exponentialMapSize, 0, 10);
            _gaussRepeatTime    = EditorGUILayout.IntSlider("Gauss Apply count", _gaussRepeatTime, 0, 20);
            _noiseIntensity     = EditorGUILayout.IntField("Noise Intensity", _noiseIntensity);

            if (GUILayout.Button("Generate HeightMap"))
            {
                _heightMap = DiamondSquare.GenerateHeightMap(_exponentialMapSize, _noiseIntensity, _seed);
                _mapSize   = _heightMap.GetLength(0) - 1;
            }

            if (GUILayout.Button("Apply Blur"))
            {
                _heightMap = GaussianBlur.ApplyBlur(_heightMap, _gaussRepeatTime);
            }

            if (GUILayout.Button("Generate Mesh"))
            {
                GenerateMesh();
            }

            if (GUILayout.Button("Generate Terrain"))
            {
                GenerateTerrain();
            }

            if (GUILayout.Button("Delete Grid"))
            {
                DeleteGrid();
            }

            if (GUILayout.Button("Add Octave"))
            {
                AddOctave();
            }
        }