public void DrawMapInEditor() { textureData.ApplyToMaterial(terrainMaterial); textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.MinHeight, heightMapSettings.MaxHeight); HeightMap heightMap = HeightMapGenerator.GenerateHeightMap( meshSettings.NumVerticesPerLine, meshSettings.NumVerticesPerLine, heightMapSettings, Vector2.zero); switch (drawMode) { case DrawMode.NoiseMap: DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap)); break; case DrawMode.Mesh: DrawMesh( MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD)); break; case DrawMode.FalloffMap: DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FallOffGenerator.GenerateFalloffMap(meshSettings.NumVerticesPerLine), 0, 1))); break; case DrawMode.CanyonMap: DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(CanyonMapGenerator.GenerateCanyonMap(meshSettings.NumVerticesPerLine), 0, 1))); break; default: throw new ArgumentOutOfRangeException(); } }
public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, Vector2 sampleCenter) { float[,] values = Noise.GenerateNoiseMap(width, height, settings.NoiseSettings, sampleCenter); float[,] fallOff = new float[0, 0]; float[,] canyon = new float[0, 0]; if (settings.UseFalloffMap) { fallOff = FallOffGenerator.GenerateFalloffMap(width); } if (settings.UseCanyonMap) { canyon = CanyonMapGenerator.GenerateCanyonMap(width); } AnimationCurve heighCurveThreadSafe = new AnimationCurve(settings.HeightCurve.keys); float minValue = float.MaxValue; float maxValue = float.MinValue; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (settings.UseFalloffMap) { values[i, j] -= fallOff[i, j]; } if (settings.UseCanyonMap) { values[i, j] += canyon[i, j]; } values[i, j] *= heighCurveThreadSafe.Evaluate(values[i, j]) * 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)); }