public void CreateWaterMap(Object stateInfo) { PerlinNoise perlinNoise = new PerlinNoise(rndPerlinOne); waterMap = perlinNoise.GenerateNoiseMap(waterSmoothPasses, scatteredWater, 10f, false, loadingInfo, true, rndPerlinOne, worldWidth, worldHeight); perlinOneCompleted = true; }
public void WipeMap() { foreach (var hex in _hexes) { if (hex != null) { Destroy(hex.gameObject); } } _hexes = new DraftHexPrefab[HexCountX, HexCountY]; _waterHexes = new List <DraftHexPrefab>(); _landHexes = new List <DraftHexPrefab>(); _mountains = new List <DraftHexPrefab>(); _springs = new List <DraftHexPrefab>(); _rndPerlin = PerlinNoise.GenerateNoiseMap(HexCountX * HexCountY, 1, Seed, NoiseScale, Octaves, Persistance, Lacunarity, Offset); HexContainer.ResetScale(); //CameraController.ResetCamera(); _mapIsGenerated = false; _invertSwap = false; SubContainerLeft.position = _leftPartPos; SubContainerRight.position = _rightPartPos; }
public void CreateRiverMap(Object stateInfo) { PerlinNoise perlinNoise = new PerlinNoise(rndPerlinTwo); treeMap = perlinNoise.GenerateNoiseMap(treeSmoothPasses, scatteredTrees, 10f, false, loadingInfo, false, rndPerlinTwo, worldWidth, worldHeight); perlinTwoCompleted = true; }
public override float[,] GenerateHeightMap(int resolution) { float[,] heightMap = PerlinNoise.GenerateNoiseMap(resolution, resolution, this.octaves, this.persistence, this.lacunarity, Random.Range(0, 10000), new Vector2(0, 0), scale); LerpHeightMap(heightMap); return(heightMap); }
public MapData GenerateMapData() { if (RNG == null) { RNG = new RandomNumberGenerator(Seed); // used for editor } RNG = new RandomNumberGenerator(Seed); float[,] noiseMap = PerlinNoise.GenerateNoiseMap(MapChunkSize, RNG, NoiseScale, Octaves, Persistance, Lacunarity, Offset); // Apply region colors to noise map Color[] colorMap = new Color[MapChunkSize * MapChunkSize]; for (int y = 0; y < MapChunkSize; y++) { for (int x = 0; x < MapChunkSize; x++) { float currentHeight = noiseMap[x, y]; for (int i = 0; i < Regions.Length; i++) { if (currentHeight <= Regions[i].Height) { colorMap[y * MapChunkSize + x] = Regions[i].Color; break; } } } } MapData mapData = new MapData(noiseMap, colorMap); return(mapData); }
private float[,] GenerateLand(int resolution) { float[,] heightMap = PerlinNoise.GenerateNoiseMap(resolution, resolution, 4, 0.4f, 0.6f, Random.Range(0, 10000), new Vector2(0, 0), 2f); LerpHeightMap(heightMap); return(heightMap); }
void GenerateIsland() { float[,] noiseMap = PerlinNoise.GenerateNoiseMap(width, height, seed, scale, octaves, persistance, lacunarity); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (noiseMap[x, y] < waterFrequency) { water.SetTile(new Vector3Int(x - width / 2, y - height / 2, 0), tiles[2]); } else if (noiseMap[x, y] < waterFrequency + 0.05f) { map.SetTile(new Vector3Int(x - width / 2, y - height / 2, 0), tiles[1]); } else if (noiseMap[x, y] > 0.80f) { collision.SetTile(new Vector3Int(x - width / 2, y - height / 2, 0), tiles[4]); } else if (noiseMap[x, y] > 0.60f) { collision.SetTile(new Vector3Int(x - width / 2, y - height / 2, 0), tiles[3]); } else { map.SetTile(new Vector3Int(x - width / 2, y - height / 2, 0), tiles[0]); } } } }
private void BlendEdges() { if (BlendingValue == 0) { return; } int edge = BlendingValue / 2; int j = 0; DraftHexPrefab[,] edgeHexes = new DraftHexPrefab[HexCountY, BlendingValue]; float[,] edgeHeights = new float[HexCountY, BlendingValue]; float[] avg = new float[HexCountY]; float[,] rndMap = PerlinNoise.GenerateNoiseMap(HexCountY, BlendingValue, Seed, NoiseScale / 833, Octaves, Persistance, Lacunarity, Offset); for (int i = 0; i < HexCountY; i++) { for (int g = 0; g < BlendingValue; g++) { rndMap[i, g] = Mathf.Lerp(5, 10, rndMap[i, g]); // => Random.Range(5, 10) } } for (int i = 0; i < HexCountY; i++) { for (int k = 0; k < BlendingValue; k++) { if (k < edge) { j = k; } else { j = HexCountX + edge - k - 1; } edgeHexes[i, k] = _hexes[j, i]; edgeHeights[i, k] = _heights[j, i]; avg[i] += _heights[j, i]; } } for (int x = 0; x < HexCountY; x++) { for (int y = 0; y < BlendingValue; y++) { avg[y] = avg[y] / BlendingValue; float height = edgeHeights[x, y]; height -= (height - avg[y]) / rndMap[x, y]; edgeHexes[x, y].Height.text = (height * 1000).ToString("0"); var color = edgeHexes[x, y].BGImage.color; color.a = LerpAlpha(height); edgeHexes[x, y].BGImage.color = color; //edgeHexes[x, y].BGImage.color = new Color(0, 0, 0, 1); ///debug } } }
/// <summary> /// Initializes a new instance of the <see cref="World"/> class. /// Not directly done in World constructor, so that the 'load from world' World constructer can use the same function. /// </summary> /// <param name="width">Width in number of tiles</param> /// <param name="height">Height in number of tiles</param> void SetUpWorld(int width, int height) { jobQueue = new JobQueue(); characters = new List <Character>(); installedObjects = new List <InstalledObject>(); rooms = new List <Room>(); inventoryManager = new InventoryManager(); // Add the 'world' room rooms.Add(new Room()); // Set width & height Width = width; Height = height; // Create new tile array. Default size: 100 * 100 = 10,000 tiles tiles = new Tile[width, height]; // Get Perlin noise map float[,] noiseMap = PerlinNoise.GenerateNoiseMap(width, height, 0, 25, 5, 0.5f, 5, new Vector2(0, 0)); // Instantiate tiles and adding them to the tiles array for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { tiles[x, y] = new Tile(this, x, y); // Add bodies of water to the world if (noiseMap[x, y] <= 0.075f) { tiles[x, y].Type = TileType.Oil; } else if (noiseMap[x, y] <= 0.25f) { tiles[x, y].Type = TileType.Water; } else if (noiseMap[x, y] <= 0.3f) { tiles[x, y].Type = TileType.Sand; } tiles[x, y].RegisterTileTypeChangedCallback(OnTileChanged); // Add tile to room number 0 (the world itself) tiles[x, y].room = rooms[0]; } } Debug.Log("World created with: " + width * height + " tiles -- width: " + width + ", height: " + height); // Create new dictionary of baseInstalledObjects installedBaseObjects = new Dictionary <string, InstalledObject>(); installedJobBaseObjects = new Dictionary <string, Job>(); CreateBaseInstalledObjects(); }
public void GenerateMap() { int minSize = Mathf.Min(mapWidth, mapHeight); //Get the smaller size for the FalloffGenerator float[,] noiseMap = PerlinNoise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset); Color[] colourMap = new Color[mapWidth * mapHeight]; falloffMap = FalloffGenerator.GenerateFalloffMap(minSize); //Loop through the map and apply heights for (int x = 0; x < mapWidth; x++) { for (int y = 0; y < mapHeight; y++) { if (useFalloff) //If using Falloff to create islands, subtract the falloff map and clamp between 0-1 values { noiseMap[x, y] = Mathf.Clamp(noiseMap[x, y] - falloffMap[x, y], 0, 1); } float height = noiseMap[x, y]; //Loop through the Biomes for (int i = 0; i < biomes.Length; i++) { if (height <= biomes[i].height) { colourMap[y * mapWidth + x] = biomes[i].colour; break; } } } } if (renderMode == RenderMode.Noise) { terrainMap.RenderMap(TextureMaker.TextureFromHeightMap(noiseMap)); } else if (renderMode == RenderMode.Colour) { terrainMap.RenderMap(TextureMaker.TextureFromColourMap(colourMap, mapWidth, mapHeight)); } else if (renderMode == RenderMode.Mesh) { terrainMap.RenderMesh(TerrainMeshGenerator.GenerateTerrainMesh(noiseMap, heightMultiplier), TextureMaker.TextureFromColourMap(colourMap, mapWidth, mapHeight)); } GeneratePlants(800); }
public void GenerateMap() { float[,] noiseMap = PerlinNoise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset); // Create colormap => one color for each point in the noise map Color[] colorMap = new Color[mapWidth * mapHeight]; // Loop through all values in the noise map for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { // Store the current height value at this point/coordinate float currentHeight = noiseMap[x, y]; // Loop through all different regions for (int i = 0; i < regions.Length; i++) { // If the current height value belongs to a region => set the color equal to that region's color if (currentHeight <= regions[i].height) { // Save the color colorMap[y * mapWidth + x] = regions[i].color; break; } } } } // Get reference of the MapDisplay MapDisplay mapDisplay = FindObjectOfType <MapDisplay>(); // Display the perlin noise map or color map => depending on the drawmode selected if (drawMode == DrawMode.NoiseMap) { mapDisplay.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap)); } else if (drawMode == DrawMode.ColorMap) { mapDisplay.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapWidth, mapHeight)); } }
MapData GenerateMapData(Vector2 centre) { float[,] noiseMap = PerlinNoise.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, seed, noiseScale, octaves, persistance, lacunarity, centre + offset, normalizeMode); /* * if (!useFalloff) * { * noiseMap = PerlinNoise.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, seed, noiseScale, octaves, persistance, lacunarity, centre + offset, normalizeMode); * } * else * { * //mapChunkSize = 241; * noiseMap = PerlinNoise.GenerateNoiseMap(mapChunkSize, mapChunkSize, seed, noiseScale, octaves, persistance, lacunarity, centre + offset, normalizeMode); * } */ Color[] colourMap = new Color[mapChunkSize * mapChunkSize]; 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]; for (int i = 0; i < regions.Length; i++) { if (currentHeight >= regions [i].height) { colourMap [y * mapChunkSize + x] = regions [i].colour; } else { break; } } } } return(new MapData(noiseMap, colourMap)); }
private void GenerateForest() { var forestMap = PerlinNoise.GenerateNoiseMap(HexCountX, HexCountY, Seed, NoiseScale / 10, Octaves, Persistance, Lacunarity * 20, Offset * 4); float forestP = 0.5f; float forestP2 = 0.6f; for (int i = 0; i < HexCountY; i += 3) { for (int j = 0; j < HexCountX; j += 3) { var hex = _hexes[j, i]; var hexInfo = hex.InfoScript; if (hexInfo.Biome == "grass") { if (forestMap[j, i] <= forestP) { hexInfo.IsForest = true; hex.Forest.SetActive(true); foreach (var neighbor in hexInfo.Neighbors) { var neighborInfo = neighbor.InfoScript; int x = neighborInfo.X; int y = neighborInfo.Y; if (neighborInfo.Biome == "grass") { if (forestMap[x, y] <= forestP2) { neighborInfo.IsForest = true; neighbor.Forest.SetActive(true); } } } } } } } }
/// <summary> /// Drawing the perlin noise map to a mesh and instantiating trees to specific pixel colour ranges. /// </summary> /// <param name="treeTypeIndex"></param> public void DrawNoiseMap(int index) { float[,] perlinNoise = PerlinNoise.GenerateNoiseMap(meshWidth, meshLength, seed, noiseScale, octaves, persistance, lacunarity, offset); int width = perlinNoise.GetLength(0); int length = perlinNoise.GetLength(1); Texture2D texture = new Texture2D(width, length); Color[] colourMap = new Color[width * length]; for (int y = 0; y < length; y++) { for (int x = 0; x < width; x++) { colourMap[y * width + x] = Color.Lerp(Color.black, Color.white, perlinNoise[x, y]); float currentRange = perlinNoise[x, y]; if (currentRange >= Trees[index].startRange && currentRange <= Trees[index].endRange) { GameObject tree = Instantiate(Trees[index].tree, new Vector3(((x - (meshWidth / 2)) * (meshWidth / 5)), 1, ((y - (meshLength / 2))) * (meshLength / 5)), Trees[index].tree.transform.rotation); Trees[index].spawnedTrees.Add(tree); if (Trees[index].spawnedTrees.Count > 0) { tree.transform.parent = Trees[index].spawnedTrees[0].transform; } } } } texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.SetPixels(colourMap); texture.Apply(); textureRenderer.sharedMaterial.mainTexture = texture; textureRenderer.transform.localScale = new Vector3(width, 1, length); }
public void GenerateMap() { if (newSeed) { seed = Random.Range(0, 100000); } float[,] noiseMap = PerlinNoise.GenerateNoiseMap(seed, chunkSize, chunkSize, scale, octaves, persistance, lacunarity, offset); switch (drawMode) { case DrawType.heightMap: FindObjectOfType <NoiseDisplay>().DrawHeightMap(noiseMap); break; case DrawType.colorMap: FindObjectOfType <NoiseDisplay>().DrawColorMap(noiseMap, regions); break; case DrawType.terrain: FindObjectOfType <NoiseDisplay>().DrawMesh(TerrainMeshGenerator.CreateTerrain(noiseMap, heightMultiplier, meshHeightCurve, LOD), noiseMap, regions); break; } }
private float[,] GenerateBiomeMap(int mapSize, PerlinNoise perlinNoise) { return(perlinNoise.GenerateNoiseMap(mapSize)); }
public void Generate() { WipeMap(); HexContainer.ResetScale(); _temperaturesRnd = PerlinNoise.GenerateNoiseMap(HexCountX, HexCountY, Seed, NoiseScale / 8, Octaves, Persistance, Lacunarity * 8, Offset * 2); _humidity = PerlinNoise.GenerateNoiseMap(HexCountX, HexCountY, Seed, NoiseScale / 15, Octaves, Persistance, Lacunarity * 15, Offset * 3); _heights = PerlinNoise.GenerateNoiseMap(HexCountX, HexCountY, Seed, NoiseScale, Octaves, Persistance, Lacunarity, Offset); _heightsForMedian = new List <float>(); float HexHeight = _hexWidth * Mathf.Sqrt(3) / 2; _mountainsLevel = (1 - MountainsPercent) * 1000; for (int i = 0; i < HexCountY; i++) { for (int j = 0; j < HexCountX; j++) { var hex = Instantiate(HexPrefab, Vector3.zero, Quaternion.identity); hex.gameObject.name = "HEX " + i + "." + j; _heightsForMedian.Add(_heights[j, i] * 1000); hex.InfoScript.Height = _heights[j, i] * 1000; hex.Height.text = string.Format("{0:0}", _heights[j, i] * 1000); if (hex.Height.text == "1000") /// { hex.Height.text = "999"; } float t = GenerateTemperature(j, i); hex.InfoScript.Temperature = t; hex.Temperature.text = t.ToString("0.00"); float hum = _humidity[j, i]; hex.InfoScript.Humidity = hum; hex.Humidity.text = hum.ToString("0.00"); CreateBiome(hex); Vector3 pos = FirstHexPos.position; pos.x += j * _hexWidth + 0.5f * _hexWidth * (i % 2); pos.y -= i * HexHeight; hex.transform.position = pos; if (j < HexCountX / 2) { hex.transform.SetParent(SubContainerLeft); } else { hex.transform.SetParent(SubContainerRight); } hex.InfoScript.X = j; hex.InfoScript.Y = i; _hexes[j, i] = hex; } } BlendEdges(); FindNeighbors(); GenerateOcean(); DetectIslands(); GenerateShelves(); TweakMountains(); GenerateHills(); GenerateForest(); //GenerateSprings(); //GenerateRivers(); ScaleMap(); _mapIsGenerated = true; }