public void DrawMapInEditor() { textureData.ApplyToMaterial(terrainMaterial); textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight); HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, Vector2.zero); if (drawMode == DrawMode.NoiseMap) { DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap)); } else if (drawMode == DrawMode.Mesh) { DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD)); } else if (drawMode == DrawMode.FalloffMap) { DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1))); } }
public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, Vector2 sampleCentre) { float[,] values = Noise.GenerateNoiseMap(width, height, settings.noiseSettings, sampleCentre); AnimationCurve heightCurve_threadsafe = new AnimationCurve(settings.heightCurve.keys); float minValue = float.MaxValue; float maxValue = float.MinValue; if (settings.useFalloff) { if (falloffMap == null) { falloffMap = FalloffGenerator.GenerateFalloffMap(width); } } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { values [i, j] *= heightCurve_threadsafe.Evaluate(values [i, j] - (settings.useFalloff ? falloffMap[i, j] : 0)) * settings.heightMultiplier; if (values[i, j] > maxValue) { maxValue = values[i, j]; } if (values[i, j] < minValue) { minValue = values[i, j]; } } } return(new HeightMap(values, minValue, maxValue)); }