public void DrawMapInEditor() { textureData.ApplyToMaterial(terrainMaterial); textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight); ChunkBorderInfo chunkBorderInfo = new ChunkBorderInfo(false, FalloffGenerator.Corner.TOPLEFT, false, FalloffGenerator.Edge.TOP); HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numberVerticesPerLine, meshSettings.numberVerticesPerLine, heightMapSettings, mapRulesSettings, Vector2.zero, chunkBorderInfo); CleanScene(); if (drawMode == DrawMode.NoiseMap) { DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap)); } else if (drawMode == DrawMode.FalloffMap) { DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numberVerticesPerLine, mapRulesSettings), 0, 1))); } else if (drawMode == DrawMode.Mesh) { DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD)); } else if (drawMode == DrawMode.Map) { DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD)); DrawMap(); } }
public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, MapRulesSettings mapRules, Vector2 sampleCenter, ChunkBorderInfo borderInfo) { float[,] values = Noise.GenerateNoiseMap(width, height, settings.noiseSettings, sampleCenter); AnimationCurve heightCurveThreadSafe = new AnimationCurve(settings.heightCurve.keys); float minValue = float.MaxValue; float maxValue = float.MinValue; if (mapRules.useFalloff) { float[,] falloffMap; if (mapRules.useFalloff) { if (mapRules.maxMapSizeInChunks.x <= 1 && mapRules.maxMapSizeInChunks.y <= 1) { falloffMap = FalloffGenerator.GenerateFalloffMap(width, mapRules); } else if (borderInfo.isCorner) { falloffMap = FalloffGenerator.GenerateCornerFalloffMap(width, mapRules, borderInfo.corner); } else if (borderInfo.isEdge) { falloffMap = FalloffGenerator.GenerateEdgeFalloffMap(width, mapRules, borderInfo.edge); } else { falloffMap = new float[width, height]; } } else { falloffMap = new float[width, height]; } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { values[i, j] = Mathf.Clamp01(values[i, j] - falloffMap[i, j]); values[i, j] *= heightCurveThreadSafe.Evaluate(values[i, j]) * settings.heightMultiplier; if (values[i, j] > maxValue) { maxValue = values[i, j]; } if (values[i, j] < minValue) { minValue = values[i, j]; } } } } else { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { values[i, j] = Mathf.Clamp01(values[i, j]); values[i, j] *= heightCurveThreadSafe.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)); }