public void Initialize(int width, int height, Material baseMaterial) { id = GetInstanceID(); Region dummyheightMap = RegionGenerator.GenerateRegion(width, height, heightSettings, Vector2.zero, true); TerrainMaterial = Instantiate <Material>(baseMaterial); textureSettings.ApplyToMaterial(TerrainMaterial); textureSettings.UpdateMeshHeights(TerrainMaterial, dummyheightMap.minValue, dummyheightMap.maxValue); }
public RouteManager() { if (_region == null) { _region = RegionGenerator.Create("San Antonio", "STX"); } //if (_sim == null) // _sim = new FleetSimulator(_region); }
static void Main(string[] args) { RegionGenerator gR = new RegionGenerator(); //gR.GenerateSimulationRegions(); //gR.GenerateSimulationRegions(10, 20, 1, 1, 50); //gR.GenerateSimulationRegions(40, 9, 12, 20, 100); //gR.GenerateSimulationRegions(new RegionGenerator.ErlangDistribution(30, 40), new RegionGenerator.ErlangDistribution(10, 40), 100); gR.GenerateSimulationRegions(new RegionGenerator.ErlangDistribution(10, 20), new RegionGenerator.ErlangDistribution(1, 1), 75); }
public string Get() { var cityGenerator = new CityGenerator(); if (!cityGenerator.Generate()) { return("Error"); } var factoryGenerator = new FactoryGenerator(); if (!factoryGenerator.Generate()) { return("Error"); } var utilityGenerator = new UtilityGenerator(); if (!utilityGenerator.Generate()) { return("Error"); } var regionGenerator = new RegionGenerator(); if (!regionGenerator.Generate()) { return("Error"); } var containerGenerator = new ContainerGenerator(); if (!containerGenerator.Generate()) { return("Error"); } var tripGenerator = new TripGenerator(); if (!tripGenerator.Generate()) { return("Error"); } return("Success"); }
public void DrawPreviewInEditor() { Region heightMap = RegionGenerator.GenerateRegion(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, offset, true); textureSettings.ApplyToMaterial(terrainMaterial); textureSettings.UpdateMeshHeights(terrainMaterial, heightMap.minValue, heightMap.maxValue); switch (drawMode) { case DrawMode.Mesh: DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD)); break; case DrawMode.NoiseMap: DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap)); break; } }
public void CutHole(RegionGenerator region) { region.CutMesh(transform.position, radius); }
/// <summary> /// Gets a 3x3 square surrounded by a border so a blur kernel can be applied correctly /// The center 'pixel' will represent the biome value for this whole chunk /// </summary> /// <param name="coord"></param> /// <param name="worldSettings"></param> /// <param name="extraBorderSize"></param> /// <returns></returns> private static Region GetBiomeMap(Vector2 coord, WorldSettings worldSettings, out int extraBorderSize) { // Based on max edge-smoothing kernel width, determine how many extra points we need to grab outside of this area to calculate smoothing correctly at edge of chunk float worldSmoothing = worldSettings.globalBiomeSettings.heightMapEdgeSmoothing; float maxSmoothing = worldSmoothing; foreach (BiomeSettings biome in worldSettings.biomes) { float biomeSmoothing = worldSmoothing * biome.heightMapEdgeSmoothingModifier; if (biomeSmoothing > maxSmoothing) { maxSmoothing = biomeSmoothing; } } float[] maxBlurKernel = StandardDeviation.GetKernel(maxSmoothing); extraBorderSize = maxBlurKernel.Length;// / 2; int biomeRegionSize = 3 + (2 * extraBorderSize); Vector2 biomeRegionStartPoint = new Vector2(coord.x - 1 - extraBorderSize, coord.y - 1 - extraBorderSize); return(worldSettings.biomeMapSettings == null ? new Region(new float[biomeRegionSize, biomeRegionSize], 0, 0) : RegionGenerator.GenerateRegion(biomeRegionSize, biomeRegionSize, worldSettings.biomeMapSettings, biomeRegionStartPoint)); }
public static ChunkData GenerateChunkData(Vector2 startPoint, Vector2 chunkCoord, WorldSettings worldSettings) { int width = worldSettings.meshSettings.numVertsPerLine; int height = worldSettings.meshSettings.numVertsPerLine; int extraBorderSize; Region biomeMap = GetBiomeMap(chunkCoord, worldSettings, out extraBorderSize); Region worldHeightMap = worldSettings.globalHeightMapSettings == null ? new Region(new float[width, height], 0, 0) : RegionGenerator.GenerateRegion(width, height, worldSettings.globalHeightMapSettings, startPoint); float[,] combinedHeightMap = new float[width, height]; List <int> activeBiomes = new List <int>(); MinMaxFloat minMax = new MinMaxFloat(); Material material = null; float worldEdgeSmoothing = worldSettings.globalBiomeSettings.heightMapEdgeSmoothing; // Add global world height for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { combinedHeightMap[x, y] += worldHeightMap.values[x, y]; } } //string debug = ""; // Add biome height foreach (BiomeSettings biome in worldSettings.biomes) { // @TODO: apply masking to materials/texturing, too (one material/shader for entire world?) if (material == null) { material = biome.TerrainMaterial; } Region heightMap = RegionGenerator.GenerateRegion(width, height, biome.heightSettings, startPoint); /* * if (Mathf.Approximately(biome.worldMapBiomeValue, 0f) && startPoint.x >= -150 && startPoint.x <= -50 && startPoint.y >= -150 && startPoint.y <= -50) * { * debug = "chunkPosition" + startPoint + " "; * } */ float[,] biomeBlurMask = CalculateBlurredBiomeMask(biomeMap.values, width, height, biome.worldMapBiomeValue, worldEdgeSmoothing * biome.heightMapEdgeSmoothingModifier);//, debug); minMax.AddValue(heightMap.minValue + worldHeightMap.minValue); minMax.AddValue(heightMap.maxValue + worldHeightMap.maxValue); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float biomeBlurValue = biomeBlurMask[x, y]; if (biomeBlurValue <= 0) { continue; } activeBiomes.Add(biome.id); combinedHeightMap[x, y] += heightMap.values[x, y] * biomeBlurValue; } } } return(new ChunkData { heightMap = new Region(combinedHeightMap, minMax.Min, minMax.Max), material = material }); }
public void Generate(int Seed, int Level, int Regions) { transform.ClearChildrenImmediately(); if (engine == null) { Load(); } { System.Random random = new System.Random(Seed); List <BlockId[]> map = new List <BlockId[]>(); int height = 0; List <RegionGenerator> validGenerators = new List <RegionGenerator>(); //<Generate Start> var start_unit = new BlockId[] { BlockId.Solid }; for (int i = 0; i < 20; i++) { map.Add(start_unit); } //<End> for (int region_id = 0; region_id < Regions; region_id++) { try { int seed = random.Next(); float max = 0; foreach (RegionGenerator function in functions) { if (function.CanAttach(height)) { validGenerators.Add(function); function.Init(seed); max += function.Probability(Level); } } if (validGenerators.Count == 0) { break; } float point = (float)random.NextDouble() * max; RegionGenerator f = null; foreach (RegionGenerator function in validGenerators) { point -= function.Probability(Level); if (point <= 0) { f = function; break; } } validGenerators.Clear(); PythonTuple output = f.Generate(Level, height); List region = (List)output[0]; height = (int)output[1]; List <BlockId> l = new List <BlockId>(); foreach (List column in region) { foreach (int obj in column) { l.Add((BlockId)obj); } map.Add(l.ToArray()); l.Clear(); } } catch { } } //<Generate End> BlockId[] end_unit = new BlockId[height + 1]; BlockId[] finish_unit = new BlockId[height + 4]; for (int i = 0; i < height; i++) { end_unit[i] = BlockId.Space; finish_unit[i] = BlockId.Space; } end_unit[height] = BlockId.Solid; finish_unit[height] = BlockId.Solid; finish_unit[height + 1] = BlockId.Space; finish_unit[height + 2] = BlockId.Space; finish_unit[height + 3] = BlockId.Finish; for (int i = 0; i < 30; i++) { if (i == 15) { map.Add(finish_unit); } else { map.Add(end_unit); } } //<End> Map = map.ToArray(); Write(Map); } OnGenerated.Invoke(); }
private void GenerateMapRegions() { var noiseMap = Noise.GenerateNoiseMap(regionMapSettings); mapData.RegionMap = RegionGenerator.GenerateRegionMap(noiseMap, mapData.HeightMap, forrestry, forrestHeightBounds); }