private void OnValidate()//called whenever the script variable is changed in the inspector. { if (lacunarity <= 1) { lacunarity = 1; } if (octaves <= 1) { octaves = 1; } falloffMap = FalloffGen.GenerateFalloffMap(mapChunkSize); }
void OnValidate() { if (lacunarity < 1) { lacunarity = 1; } if (octaves < 0) { octaves = 0; } falloffMap = FalloffGen.GenerateFalloffMap(mapChunkSize); }
public void GenerateMap() { float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset); Color[] colourMap = new Color[mapWidth * mapHeight]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { if (useFallOff) { noiseMap[x, y] = Mathf.Clamp01(fallOffMap[x, y] - noiseMap[x, y]); } float currentHeight = noiseMap[x, y]; for (int i = 0; i < Regions.Length; i++) { if (currentHeight <= Regions[i].height) { colourMap[y * mapWidth + x] = Regions[i].colour; break; } } } } MapDisplay display = FindObjectOfType <MapDisplay>(); if (drawMode == DrawMode.NoiseMap) { display.drawTexture(TextureGen.textureFromHeightMap(noiseMap)); } else if (drawMode == DrawMode.ColourMap) { display.drawTexture(TextureGen.textureFromColourMap(colourMap, mapWidth, mapHeight)); } else if (drawMode == DrawMode.Mesh) { display.drawMesh(MeshGenerator.generateTerrainMesh(noiseMap, meshHeightMult, heightCurve, useFlatshading), TextureGen.textureFromColourMap(colourMap, mapWidth, mapHeight)); } else if (drawMode == DrawMode.FallOff) { display.drawTexture(TextureGen.textureFromHeightMap(FalloffGen.GenerateFallOffMap(mapWidth))); } }
private void OnValidate() { if (mapWidth < 1) { mapWidth = 1; } if (mapHeight < 1) { mapHeight = 1; } if (lacunarity < 1) { lacunarity = 1; } if (octaves < 0) { octaves = 0; } fallOffMap = FalloffGen.GenerateFallOffMap(mapWidth); }
public void DrawMapInEditor() { textureData.ApplyToMaterial(terrainMaterial); textureData.UpdateMeshHeight(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight); HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine, heightMapSettings, Vector2.zero); //Chooses to draw the raw or the coloured noise map if (drawMode == DrawMode.NoiseMap) { DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap)); } else if (drawMode == DrawMode.Mesh) { DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLevelOfDetail)); } else if (drawMode == DrawMode.FalloffMap) { DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGen.GenerateFalloffMap(meshSettings.numberOfVerticesPerLine), 0, 1))); } }
public void DrawMapInEditor() { MapData mapData = GenerateMapData(Vector2.zero); MapDisplay display = FindObjectOfType <MapDisplay>(); if (drawMode == DrawMode.NoiseMap) { display.DrawTexture(TextureGen.TextureFromHeightMap(mapData.heightMap)); } else if (drawMode == DrawMode.ColorMap) { display.DrawTexture(TextureGen.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize)); } else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MeshGen.GenerateMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD, useFlatShading), TextureGen.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize)); } else if (drawMode == DrawMode.FalloffMap) { display.DrawTexture(TextureGen.TextureFromHeightMap(FalloffGen.GenerateFalloffMap(mapChunkSize))); } }
MapData GenerateMapData(Vector2 centre) { float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, seed, noiseScale, octaves, persistance, lacunarity, centre + offset, normalizeMode); Color[] colourMap = new Color[mapChunkSize * mapChunkSize]; if (useFalloff) { if (falloffMap == null) { falloffMap = FalloffGen.GenerateFalloffMap(mapChunkSize); } for (int y = 0; y < mapChunkSize; y++) { for (int x = 0; x < mapChunkSize; x++) { if (useFalloff) { noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]); } float currentHeight = noiseMap[x, y]; for (int i = 0; i < regions.Length; i++) { if (currentHeight >= regions[i].height) { colourMap[y * (mapChunkSize) + x] = regions[i].colour; } else { break; } } } } } return(new MapData(noiseMap, colourMap)); }
private void Awake() { falloffMap = FalloffGen.GenerateFalloffMap(mapChunkSize); }
private void Awake() { fallOffMap = FalloffGen.GenerateFallOffMap(mapWidth); seed = Random.Range(1, 10000000); }