MapData GenerateMapData(Vector2 center)
    {
        var offset = new Float2 {
            x = noiseData.Offset.x + center.x,
            y = noiseData.Offset.y + center.y
        };

        float[,] noiseMap = Noise.GenerateNoiseMap(MapChunkSize + 2, MapChunkSize + 2, noiseData.Seed,
                                                   noiseData.NoiseScale, noiseData.OctavesNumber, noiseData.Persistance, noiseData.Lacunarity,
                                                   offset, noiseData.NormalizeMode);

        if (terrainData.UseFalloff)
        {
            if (_falloffMap == null)
            {
                _falloffMap = FallofGenerator.GenerateFalloffMap(MapChunkSize + 2);
            }

            //Assignation of color to regions (loop through the noiseMap)
            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.UpdateMeshHeight(TerrainMaterial, terrainData.MinHeight, terrainData.MaxHeight);

        return(new MapData(noiseMap));
    }
Example #2
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(new Vector2(0, 0));        //pass the position zero

        MapDisplayBehaviour display = FindObjectOfType <MapDisplayBehaviour> ();

        if (Mode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.HeightMap));
        }
        if (Mode == DrawMode.ColorMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColorMap(mapData.ColorMap, MAP_CHUNK_SIZE,
                                                                     MAP_CHUNK_SIZE));
        }
        if (Mode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.HeightMap, MeshHeightMultiplier,
                                                               MeshHeightCurve, EditorPreviewLOD),
                             TextureGenerator.TextureFromColorMap(mapData.ColorMap, MAP_CHUNK_SIZE, MAP_CHUNK_SIZE));
        }
        if (Mode == DrawMode.FalloffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(
                                    FallofGenerator.GenerateFalloffMap(MAP_CHUNK_SIZE)));
        }
    }
Example #3
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.MinHeight, heightMapSettings.MaxHeight);
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.NumberOfVerticesPerLine,
                                                                   meshSettings.NumberOfVerticesPerLine, heightMapSettings, Vector2.zero);

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

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

        case DrawMode.FallofMap:
            DrawTexture(
                TextureGenerator.TextureFromHeightMap(
                    new HeightMap(FallofGenerator.GenerateFallofMap(meshSettings.NumberOfVerticesPerLine), 0, 1)));
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Example #4
0
    public void DrawMapInEditor()
    {
        //Used to store prefab objects in edit mode and delete them when changes are made (is a bit buggy)
        if (_biomeContainer != null)
        {
            DestroyImmediate(_biomeContainer.gameObject);
        }
        _biomeContainer = new GameObject("DELETE ME IF MANY OF ME").transform;

        //Apply material to mesh
        _textureData.ApplyToMaterial(_terrainMaterial);
        _textureData.UpdateMeshHeights(_terrainMaterial, _heightMapSettings.MinHeight, _heightMapSettings.MaxHeight);

        //Generate the heightmap for the chunk at origin
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(_meshSettings.NumVertsPerLine, _meshSettings.NumVertsPerLine, _heightMapSettings, _chunkCoord);

        Vector2 sampleCenter = _chunkCoord * _meshSettings.MeshWorldSize / _meshSettings.MeshScale;

        float[,] noise1 = Noise.GenerateNoiseMap(_meshSettings.NumVertsPerLine * _noiseViewSize, _meshSettings.NumVertsPerLine * _noiseViewSize, 1, _noiseSettingsData_1.NoiseSettingsDataMerge, _chunkCoord);
        noise1          = Noise.Clamp(noise1, _noiseSettingsData_1);
        float[,] noise2 = Noise.GenerateNoiseMap(_meshSettings.NumVertsPerLine * _noiseViewSize, _meshSettings.NumVertsPerLine * _noiseViewSize, 1, _noiseSettingsData_2.NoiseSettingsDataMerge, _chunkCoord);
        noise2          = Noise.Clamp(noise2, _noiseSettingsData_2);

        float[,] noise = _noiseMergeType == NoiseMergeType.ONLY_FIRST ? noise1 : noise2;



        if (_drawMode == DrawMode.NOISE_MAP)
        {
            DrawTexture(TextureGenerator.TextureFromNoise(noise));
        }
        else if (_drawMode == DrawMode.MESH)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.heightMap, _meshSettings, _editorPreviewLevelOfDetail));
        }
        else if (_drawMode == DrawMode.FALL_OF_MAP)
        {
            float[,] fallOf = (new HeightMap(FallofGenerator.GenerateFallofMap(_meshSettings.NumVertsPerLine), 1, 1).heightMap);
            DrawTexture(TextureGenerator.TextureFromNoise(fallOf));
        }
        else if (_drawMode == DrawMode.BIOME)
        {
            MeshData meshData = MeshGenerator.GenerateTerrainMesh(heightMap.heightMap, _meshSettings, _editorPreviewLevelOfDetail);
            DrawMesh(meshData);
            PrefabSpawner    prefabSpawner = new PrefabSpawner();
            List <SpawnInfo> spawnInfo     = prefabSpawner.SpawnOnChunk(2, 0, _biome, heightMap, meshData, _meshSettings, new Vector2(sampleCenter.x, -sampleCenter.y), _chunkCoord);
            prefabSpawner.SpawnSpawnInfo(spawnInfo, _biomeContainer, true);
        }
        else if (_drawMode == DrawMode.MAP)
        {
            TextureChunkData data = TextureGenerator.DrawMap(_meshSettings.NumVertsPerLine * _noiseViewSize, _mapSettings, new Vector2(sampleCenter.x, -sampleCenter.y), _chunkCoord);
            DrawTexture(TextureGenerator.TextureFromColorMap(data.colorMap, data.width, data.height));
        }
    }
    void OnValidate()
    {
        if (lacunarity < 1)
        {
            lacunarity = 1;
        }
        if (octaves < 0)
        {
            octaves = 0;
        }

        falloffMap = FallofGenerator.GenerateFalloffMap(mapChunkSize);
    }
Example #6
0
    //Automatically called whenever one of the script var has been changed by the inspector
    void OnValidate()
    {
        if (Lacunarity < 1)
        {
            Lacunarity = 1;
        }

        if (OctavesNumber < 0)
        {
            OctavesNumber = 0;
        }

        _falloffMap = FallofGenerator.GenerateFalloffMap(MAP_CHUNK_SIZE);
    }
    //Automatically called whenever one of the script var has been changed by the inspector
    void OnValidate()
    {
        if (Lacunarity < 1)
        {
            Lacunarity = 1;
        }

        if (OctavesNumber < 0)
        {
            OctavesNumber = 0;
        }

        _falloffMap = FallofGenerator.GenerateFalloffMap(MapChunkSize);
    }
	public void DrawMapInEditor ()
	{
		MapData mapData = GenerateMapData (new Vector2(0,0));//pass the position zero

		MapDisplayBehaviour display = FindObjectOfType<MapDisplayBehaviour> ();
		if (Mode == DrawMode.NoiseMap) {
			display.DrawTexture (TextureGenerator.TextureFromHeightMap (mapData.HeightMap));
		}
		if (Mode == DrawMode.Mesh) {
			display.DrawMesh (MeshGenerator.GenerateTerrainMesh (mapData.HeightMap, 
				terrainData.MeshHeightMultiplier, terrainData.MeshHeightCurve, EditorPreviewLOD, 
				terrainData.UseFlatShading));
		}
		if (Mode == DrawMode.FalloffMap) {
			display.DrawTexture (TextureGenerator.TextureFromHeightMap (
				FallofGenerator.GenerateFalloffMap (MapChunkSize)));
		}
	}
    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.ColorMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD), TextureGenerator.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FallofGenerator.GenerateFalloffMap(mapChunkSize)));
        }
    }
Example #10
0
 void Awake()
 {
     _falloffMap = FallofGenerator.GenerateFalloffMap(MAP_CHUNK_SIZE);
 }
Example #11
0
 void Awake()
 {
     _falloffMap = FallofGenerator.GenerateFalloffMap(MapChunkSize);
 }