public static Texture2D ToTexture2D(Heightmap heightmap) { var texture = new Texture2D(heightmap.Width, heightmap.Height, TextureFormat.ARGB32, false); for (int y = 0; y < heightmap.Height; y++) { for (int x = 0; x < heightmap.Width; x++) { float value = heightmap.GetAt(x, y); texture.SetPixel(x, heightmap.Height - y - 1, new Color(value, value, value)); } } texture.filterMode = FilterMode.Point; texture.Apply(); return(texture); }
private static Vector3[] GenerateVertices(Heightmap heightmap) { var vertices = new Vector3[heightmap.Values.Length]; int i = 0; for (int y = 0; y < heightmap.Height; y++) { for (int x = 0; x < heightmap.Width; x++) { var vertice = new Vector3(x * DistanceBetweenVertices, heightmap.GetAt(x, y) * MaxHeight, y * DistanceBetweenVertices); vertices[i++] = vertice; } } return(vertices); }