public static Texture2D GenerateTextureFromHeightMap(TerrainHeightMap heightMap) { Texture2D tex = new Texture2D(TerrainChunkObject.TERRAIN_CHUNK_TEXTURE_RESOLUTION_SIZE, TerrainChunkObject.TERRAIN_CHUNK_TEXTURE_RESOLUTION_SIZE); tex.filterMode = FilterMode.Point; for (int x = 0; x < tex.width; x++) { for (int y = 0; y < tex.height; y++) { Color c = new Color(); if (heightMap.GetFloat(x, y) > heightMap.highestFloat * 0.8f) { c = Color.white; } else if (heightMap.GetFloat(x, y) > heightMap.highestFloat * 0.65f) { c = new Color(0.65f, 0.65f, 0.65f); } else if (heightMap.GetFloat(x, y) < heightMap.highestFloat * 0.45f) { c = Color.blue; } else { c = Color.green; } c *= heightMap.GetFloat(x, y) / heightMap.totalStrength; tex.SetPixel(x, y, c); } } tex.Apply(); return tex; }
public static Vector3[] BuildVerticesFromHeightMap(TerrainHeightMap heightMap) { int size = TerrainChunkObject.TERRAIN_CHUNK_TILE_SIZE; Vector3[] vertices = new Vector3[((int)Mathf.Pow(size + 1, 2))]; for (int i = 0, z = 0; z <= size; z++) { for (int x = 0; x <= size; x++, i++) { float y = heightMap.GetFloat(x, z); vertices[i] = new Vector3(x, y, z); } } return vertices; }