void CreateNewBiome() { outputBiome = new BiomeData(); outputBiome.isWaterless = false; outputBiome.biomeTreeStartPoint = this; }
void CreateNewBiomeData() { outputBiome = new BiomeData(); outputBiome.isWaterless = true; outputBiome.biomeSwitchGraphStartPoint = this; }
public void OnGUI(BiomeData biomeData) { bbList.listFoldout = EditorGUILayout.Foldout(bbList.listFoldout, "Biome blending list"); int length = bbList.blendEnabled.GetLength(0); int foldoutSize = 16; int leftPadding = 10; base.OnGUI(new Rect()); if (bbList.listFoldout) { float biomeSamplerNameWidth = BiomeSamplerName.GetNames().Max(n => EditorStyles.label.CalcSize(new GUIContent(n)).x); Rect r = GUILayoutUtility.GetRect(length * foldoutSize + biomeSamplerNameWidth, length * foldoutSize); using (DefaultGUISkin.Get()) { GUIStyle coloredLabel = new GUIStyle(EditorStyles.label); for (int i = 0; i < bbList.blendEnabled.GetLength(0); i++) { Rect labelRect = r; labelRect.y += i * foldoutSize; labelRect.x += leftPadding; GUI.Label(labelRect, biomeData.GetBiomeKey(i), coloredLabel); Rect toggleRect = r; toggleRect.size = new Vector2(foldoutSize, foldoutSize); toggleRect.y += i * foldoutSize; toggleRect.x += leftPadding + biomeSamplerNameWidth; bbList.blendEnabled[i] = GUI.Toggle(toggleRect, bbList.blendEnabled[i], GUIContent.none); } } } }
public override void OnNodeEnable() { outputBiome = new BiomeData(); outputBiome.isWaterless = false; outputBiome.biomeSwitchGraphStartPoint = this; }
public static void GenerateCaveFauna(VoxelHandle CaveFloor, BiomeData Biome, ChunkGeneratorSettings Settings) { var spawnLikelihood = (Settings.Overworld.Difficulty.CombatModifier + 0.1f); foreach (var animalType in Biome.Fauna) { if (!(MathFunctions.Random.NextDouble() < animalType.SpawnProbability * spawnLikelihood)) { continue; } var lambdaAnimalType = animalType; if (!GameSettings.Current.FogofWar) { EntityFactory.CreateEntity <GameComponent>(lambdaAnimalType.Name, CaveFloor.WorldPosition + new Vector3(0.5f, 1.5f, 0.5f)); } else { Settings.World.ComponentManager.RootComponent.AddChild(new SpawnOnExploredTrigger(Settings.World.ComponentManager, CaveFloor) { EntityToSpawn = lambdaAnimalType.Name, SpawnLocation = CaveFloor.WorldPosition + new Vector3(0.5f, 1.5f, 0.5f) }); } break; // Prevent spawning multiple animals in same spot. } }
private static void GenerateCaveFlora(VoxelHandle CaveFloor, BiomeData Biome, ChunkGeneratorSettings Settings) { foreach (var floraType in Biome.Vegetation) { if (!MathFunctions.RandEvent(floraType.SpawnProbability)) continue; if (Settings.NoiseGenerator.Noise(CaveFloor.Coordinate.X / floraType.ClumpSize, floraType.NoiseOffset, CaveFloor.Coordinate.Z / floraType.ClumpSize) < floraType.ClumpThreshold) continue; var plantSize = MathFunctions.Rand() * floraType.SizeVariance + floraType.MeanSize; var lambdaFloraType = floraType; if (!GameSettings.Default.FogofWar) EntityFactory.CreateEntity<GameComponent>( lambdaFloraType.Name, CaveFloor.WorldPosition + new Vector3(0.5f, 1.0f, 0.5f), Blackboard.Create("Scale", plantSize)); else Settings.World.ComponentManager.RootComponent.AddChild(new SpawnOnExploredTrigger(Settings.World.ComponentManager, CaveFloor) { EntityToSpawn = lambdaFloraType.Name, SpawnLocation = CaveFloor.WorldPosition + new Vector3(0.5f, 1.0f, 0.5f), BlackboardData = Blackboard.Create("Scale", plantSize) }); break; // Don't risk spawning multiple plants in the same spot. } }
public override void OnNodeProcess() { CreateTemperatureMapIfNotExists(); UpdateTemperatureMap(); outputBiome = inputBiomeData; }
public void RequestPrefabData(Vector3[] mesh, MapData map, BiomeData biome, Action <PreFabData> callback) { ThreadStart threadStart = delegate { PrefabDataThread(mesh, map, biome, callback); }; new Thread(threadStart).Start(); }
public void PrefabDataThread(Vector3[] mesh, MapData map, BiomeData biome, Action <PreFabData> callback) { PreFabData data = biome.generatePrefabMap(mesh, map, terrainData.maxHeight, terrainData.minHeight); lock (prefabDataInfoQueue) { prefabDataInfoQueue.Enqueue(new MapThreadInfo <PreFabData>(callback, data)); } }
public void SimpleSwitchGraphBuild() { PWMainGraph graph = TestUtils.GenerateTestMainGraphBiomeSwitch(); BiomeData bd = new BiomeData(); var wlevel = graph.FindNodeByName("wlevel"); var bswitch = graph.FindNodeByName <PWNodeBiomeSwitch>("bswitch"); var b1 = graph.FindNodeByName <PWNodeBiome>("b1"); var b2 = graph.FindNodeByName <PWNodeBiome>("b2"); bd.biomeSwitchGraphStartPoint = wlevel; PartialBiome p1 = new PartialBiome(); PartialBiome p2 = new PartialBiome(); b1.outputBiome = p1; b2.outputBiome = p2; //setup the switch values var sd = bswitch.switchList.switchDatas; sd[0].min = 0; sd[0].max = 5; sd[0].name = "1"; sd[0].samplerName = BiomeSamplerName.terrainHeight; sd[1].min = 5; sd[1].max = 10; sd[1].name = "2"; sd[1].samplerName = BiomeSamplerName.terrainHeight; Sampler2D terrainHeight = new Sampler2D(32, 1); terrainHeight.min = 0; terrainHeight.max = 10; bd.UpdateSamplerValue(BiomeSamplerName.terrainHeight, terrainHeight); BiomeSwitchGraph switchGraph = new BiomeSwitchGraph(); switchGraph.BuildGraph(bd); Assert.That(switchGraph.isBuilt == true); var values = new BiomeSwitchValues(); values[0] = 4.0f; Assert.That(switchGraph.FindBiome(values).id == p1.id); values[0] = 0f; Assert.That(switchGraph.FindBiome(values).id == p1.id); values[0] = 5f; Assert.That(switchGraph.FindBiome(values).id == p1.id); values[0] = 6.0f; Assert.That(switchGraph.FindBiome(values).id == p2.id); values[0] = 10f; Assert.That(switchGraph.FindBiome(values).id == p2.id); }
/// <summary> /// Displays GUI elements for the "Textures" foldout under /// the detail tab /// </summary> private void Detail_Texture(BiomeData biome) { //Use textures if (_config.Details != null) { var detailSubList = AddSubListIfNeeded(biome); ReorderableListGUI.ListField(detailSubList.MaterialsList); } }
/// <summary> /// Displays GUI elements for the "Object Placement" tab /// </summary> private void Detail_Object(BiomeData biome) { //Use objects list if (_config.Details != null) { var detailSubList = AddSubListIfNeeded(biome); ReorderableListGUI.ListField(detailSubList.ObjectsList); } }
public void RequestMapData(Vector2 center, BiomeData biome, Action <MapData> callback) { biome.texture.UpdateMeshHeights(terrainData.minHeight, terrainData.maxHeight); ThreadStart threadStart = delegate { MapDataThread(center, callback); }; new Thread(threadStart).Start(); }
public bool orientAndPlace(int xTL, int yTL, float height, GameObjectData[,] placements, bool[,,] rules, int index, int width, System.Random rand, GameObjectData nonce) { //oversight assumes left to right up to down placement int minX = Mathf.Min(placementRadius * maxScaling, placements.GetLength(1) - xTL); for (int i = 1; i <= minX; i++) { if (placements[i + xTL, yTL] != null) { minX = i; } } float minScale = placementRadius == 0 ? 1000000 : Mathf.Min((float)minX / placementRadius, (float)(placements.GetLength(0) - yTL) / placementRadius); if (minScale < minScaling) { placements[xTL, yTL] = nonce; return(false); } float scale = BiomeData.Range(rand, minScaling, Mathf.Min(minScale, maxScaling)); Vector3 position = new Vector3(((float)(xTL + placementRadius / 2)), height - 1, ((float)(yTL + placementRadius / 2))); Vector3 scaling = new Vector3(scale, scale, scale); for (int i = xTL; i <= placementRadius; i++) { for (int j = xTL; j <= placementRadius; j++) { placements[i, j] = nonce; } } for (int i = Mathf.Max(xTL - width, 0); i < Mathf.Min(xTL + placementRadius * scale + width, placements.GetLength(0)); i++) { for (int j = Mathf.Max(yTL - width, 0); j < Mathf.Min(yTL + placementRadius * scale + width, placements.GetLength(0)); j++) { rules[i, j, index] = false; } } float angle = BiomeData.Range(rand, 0, 360f); placements[xTL, yTL] = new GameObjectData(); placements[xTL, yTL].rotation = Quaternion.AngleAxis(angle, Vector3.up); placements[xTL, yTL].gamePiece = prefab; placements[xTL, yTL].placeable = true; placements[xTL, yTL].position = position; placements[xTL, yTL].scale = scaling; return(true); }
void LoadBiomeTexture2DArray(BiomeData biomeData, bool forceReload) { if (biomeData == null) { return; } string assetFilePath = System.IO.Path.Combine(GetGraphPath(), GetGraphName() + "-Albedo"); outputBlendedBiomeTerrain.terrainTextureArray = PWAssets.GenerateOrLoadBiomeTexture2DArray(biomeData.biomeTree, assetFilePath); }
public override void OnNodeProcess() { UpdateWetnessMap(); if (inputBiomeData != null) { inputBiomeData.UpdateSamplerValue(BiomeSamplerName.wetness, wetnessMap); } outputBiomData = inputBiomeData; }
public override void ReplaceGround(BiomeData bd, Block[, ,] blocks) { for (int x = 0; x < blocks.GetLength(0); x++) for (int y = 0; y < blocks.GetLength(1); y++) if (this.SuitableSampleAverage(bd, x, y)) for (int z = 0; z < blocks.GetLength(2); z++) if (blocks[x, y, z] == Block.GrassBlock) blocks[x, y, z] = Block.SandGrassBlock; base.ReplaceGround(bd, blocks); }
public void UpdateBiomeRepartitionPreview(BiomeData biomeData) { if (bsl.sampler == null || biomeRepartitionPreview == null) { return; } float min = bsl.sampler.min; float max = bsl.sampler.max; float range = max - min; //clear the current texture: for (int x = 0; x < previewTextureWidth; x++) { biomeRepartitionPreview.SetPixel(x, 0, Color.white); } localCoveragePercent = 0; int i = 0; foreach (var switchData in switchDatas) { float switchMin = Mathf.Max(switchData.min, min); float switchMax = Mathf.Min(switchData.max, max); float rMin = ((switchMin - min) / range) * previewTextureWidth; float rMax = ((switchMax - min) / range) * previewTextureWidth; localCoveragePercent += (rMax - rMin) / previewTextureWidth * 100; //Clamp values to image size: rMin = Mathf.Clamp(rMin, 0, biomeRepartitionPreview.width); rMax = Mathf.Clamp(rMax, 0, biomeRepartitionPreview.width); for (int x = (int)rMin; x < (int)rMax; x++) { biomeRepartitionPreview.SetPixel(x, 0, switchData.color); } i++; } //add water if there is and if switch mode is height: if (biomeData != null && !biomeData.isWaterless && bsl.samplerName == BiomeSamplerName.terrainHeight) { float rMax = (biomeData.waterLevel / range) * previewTextureWidth; rMax = Mathf.Clamp(rMax, 0, biomeRepartitionPreview.width); for (int x = 0; x < rMax; x++) { biomeRepartitionPreview.SetPixel(x, 0, Color.blue); } } biomeRepartitionPreview.Apply(); }
public GenerationContext() { DensityMap = new float[5, 33, 5]; DepthMap = new float[5, 1, 5]; MainNoiseMap = new float[5, 33, 5]; MinLimitMap = new float[5, 33, 5]; MaxLimitMap = new float[5, 33, 5]; SurfaceMap = new float[16, 1, 16]; Biomes = new BiomeData[16, 16]; Rand = null; }
/// <summary> /// Gets the offset for the given condition manager, recursively checking any parent managers we have /// </summary> /// <param name="manager">The condition manager to check</param> /// <param name="data">The <see cref="BiomeData"/> to use</param> /// <returns>The aggregated offset</returns> private static float GetOffset(GameConditionManager manager, BiomeData data) { // Add up all the various offsets we have: var num = manager.ActiveConditions.Sum(condition => data.GetBiomeConditionTemperatureOffset(condition)); if (manager.Parent != null) { num += GetOffset(manager.Parent, data); } return(num); }
private BiomeData queryBiomAt(int x, int y, int size, float[,] heights, float[,] temps, float[,] rainfalls) { BiomeData toReturn = new BiomeData(); int centerIndex = size / 2; toReturn.height = heights[centerIndex, centerIndex]; toReturn.temperature = getTemp(temps[centerIndex, centerIndex], toReturn.height); toReturn.rainfall = rainfalls[centerIndex, centerIndex]; toReturn.biomeType = getBiomeType(toReturn.temperature, toReturn.rainfall, toReturn.height); toReturn.geographyType = getGeographyType(toReturn.height); return(toReturn); }
void BuildBiomeSwitchGraph() { BiomeData biomeData = GetBiomeData(); if (biomeData == null) { Debug.LogError("[PWBiomeBlender] Can't access to partial biome data, did you forgot the BiomeGraph in a biome node ?"); return; } biomeData.biomeSwitchGraph.BuildGraph(biomeData); }
/// <summary> /// Adds the passed biome to <see cref="_biomeDetails"/> if it is /// not in there already. Returns the associated /// <see cref="DetailSubList" />. /// </summary> private DetailSubList AddSubListIfNeeded(BiomeData biome) { var subList = GetDetailListsFor(biome); if (subList.Equals(default(DetailSubList))) { subList = new DetailSubList(_config, biome.Details); _biomeDetails.Add(new KeyValuePair <BiomeData, DetailSubList>(biome, subList)); } return(subList); }
public Material getMaterialForBiome(BiomeData biome) { for (int i = 0; i < biomes.Length; i++) { if (biomes[i].type == biome.biomeType) { return(biomes[i].material); } } return(biomes[0].material); }
public override void OnNodeEnable() { outputBiome = new BiomeData(); outputBiome.isWaterless = false; outputBiome.biomeSwitchGraphStartPoint = this; delayedChanges.BindCallback(delayedUpdateKey, (unused) => { UpdateWaterMap(); NotifyReload(); }); }
/// <summary> /// The detail lists from <see cref="_biomeDetails"/> that /// have the passed biome as a key. /// </summary> /// <returns>Detail sub list if found, default(<see cref="DetailSubList"/>) otherwise</returns> private DetailSubList GetDetailListsFor(BiomeData biome) { foreach (var kv in _biomeDetails) { if (kv.Key == biome) { return(kv.Value); } } return(default(DetailSubList)); }
private void Start() { // Load BlockData from Json BlockData BlockInJson = JsonUtility.FromJson <BlockData>(jsonFile.text); foreach (BlockDataSingle bd in BlockInJson.blockdata) { bds.Add(bd); string TIDList = bd.GetTextureID(0).ToString(); for (int i = 1; i < 6; i++) { TIDList = TIDList + ", " + bd.GetTextureID(i); } Debug.Log("Found Block: " + bd.Name + " Solid: " + bd.Render + " TID: " + TIDList + " EBD: " + bd.ExtraBlockData.Length); } blockdata = bds.ToArray(); // Load BiomeData from Json BiomeData BiomeInJson = JsonUtility.FromJson <BiomeData>(jsonFile2.text); int index = 0; foreach (BiomeDataSingle bd in BiomeInJson.biomedata) { Debug.Log("Found Biome: " + bd.Name + " SGH: " + bd.SolidGroundHeight + " TH: " + bd.TerrainHeight + " TS: " + bd.TerrainScale); biomedata[index, 0] = bd.SolidGroundHeight; biomedata[index, 1] = bd.TerrainHeight; biomedata[index, 2] = bd.TerrainScale; structuredata[index, 0] = bd.StructureScale; structuredata[index, 1] = bd.StructureThreshold; structuredata[index, 2] = bd.StructurePlacementScale; structuredata[index, 3] = bd.StructurePlacementThreshold; structuredata[index, 4] = bd.maxStructureHeight; structuredata[index, 5] = bd.minStructureHeight; index++; } blockdata = bds.ToArray(); // Actual Game-Stuff LoadHeightmap(); LoadIslandMap(); heightmap = ArrayMultiply(heightmap, IslandMap); Random.InitState(seed); SpawnPosition = new Vector3(VoxelData.WorldSizeBlocks / 2, VoxelData.ChunkHeight - 50, VoxelData.WorldSizeBlocks / 2); GenerateWorld(); LastChunk = getChunkCoord(Player.position); //snap.setupsnap(this); //StartCoroutine(Iconset()); }
public override void Generate(IWorld world, ChunkPos pos, BlockData[,,] blocks, Quaternion[,,] rotations, byte[,] heightMap, GenerationHelper helper, GenerationContext context) { BiomeData biome = context.Biomes[8, 8]; Random random = new Random(pos.X ^ pos.Z ^ helper.Seed); BlockData plantBlock = world.BlockDataTable.GetBlock(m_PlantBlock); int height = random.Next(m_MaxPlantHeightDelta) + m_MinPlantHeight; int count = random.Next(m_PlantType switch { PlantType.Grass => biome.GrassPerChunk, PlantType.Flower => biome.FlowersPerChunk, PlantType.Cacti => biome.CactiPerChunk, PlantType.Mushroom => biome.MushroomsPerChunk, _ => throw new NotImplementedException() });
internal List <BiomeData> GetBiomeData() { if (this.TechToCopy != TechType.None && !BiomeData.Any()) { // This will load the games distribution data and then return the biome distribution list for the techtype you tried to copy from if it has one. LootDistributionData data = LootDistributionData.Load("Balance/EntityDistributions"); if (data.GetPrefabData(CraftData.GetClassIdForTechType(TechToCopy), out SrcData srcData)) { return(srcData.distribution); } } return(BiomeData ?? new List <BiomeData>()); }
public override void OnNodeGUI() { var biomes = inputBiomes.GetValues <Biome>(); BiomeData biomeData = null; if (biomes.Count == 0 || biomes.First() == null) { EditorGUILayout.LabelField("biomes not connected !"); } else { biomeData = biomes.First().biomeDataReference; EditorGUIUtility.labelWidth = 120; maxBiomeBlendCount = EditorGUILayout.IntField("max blended biomes", maxBiomeBlendCount); } if (biomeData != null) { if ((biomePreviewFoldout = EditorGUILayout.Foldout(biomePreviewFoldout, "Biome id map"))) { if (biomeData.biomeIds != null) { PWGUI.BiomeMap2DPreview(biomeData, needUpdate || forceReload || biomeReloadRequested); } //TODO: biome 3D preview } } else { EditorGUILayout.LabelField("no biome data"); } if (biomeCoverageRecap = EditorGUILayout.Foldout(biomeCoverageRecap, "Biome coverage recap")) { foreach (var biomeCoverageKP in biomeData.biomeTree.GetBiomeCoverage()) { if (biomeCoverageKP.Value > 0) { EditorGUILayout.LabelField(biomeCoverageKP.Key.ToString(), (biomeCoverageKP.Value * 100).ToString("F2") + "%"); } } //TODO: exloit the biome switch tree datas } if (outputBlendedBiomeTerrain.terrainTextureArray == null || forceReload || GetReloadRequestType() == typeof(PWNodeBiomeSurface)) { LoadBiomeTexture2DArray(biomeData, false); } }
public override void MouseDown(TileMouseState e) { if (!_isRightDown && !_isLeftDown) { _currentBiome = Biomes.FirstOrDefault(b=>b.Biome== _wvm.MorphBiomeTarget); _startPoint = e.Location; _dirtLayer = (int)_wvm.CurrentWorld.GroundLevel; _rockLayer = (int)_wvm.CurrentWorld.RockLevel; _wvm.CheckTiles = new bool[_wvm.CurrentWorld.TilesWide * _wvm.CurrentWorld.TilesHigh]; } _isLeftDown = (e.LeftButton == MouseButtonState.Pressed); _isRightDown = (e.RightButton == MouseButtonState.Pressed); CheckDirectionandDraw(e.Location); }
public override void MouseDown(TileMouseState e) { if (!_isRightDown && !_isLeftDown) { _currentBiome = Biomes.FirstOrDefault(b => b.Biome == _wvm.MorphBiomeTarget); _startPoint = e.Location; _dirtLayer = (int)_wvm.CurrentWorld.GroundLevel; _rockLayer = (int)_wvm.CurrentWorld.RockLevel; _wvm.CheckTiles = new bool[_wvm.CurrentWorld.TilesWide * _wvm.CurrentWorld.TilesHigh]; } _isLeftDown = (e.LeftButton == MouseButtonState.Pressed); _isRightDown = (e.RightButton == MouseButtonState.Pressed); CheckDirectionandDraw(e.Location); }
public static BiomeData Load(ConfigNode node) { BiomeData biomeData = new BiomeData(ConfigNodeUtil.ParseValue<string>(node, "name")); biomeData.landCount = ConfigNodeUtil.ParseValue<int>(node, "landCount"); biomeData.waterCount = ConfigNodeUtil.ParseValue<int>(node, "waterCount"); foreach (ConfigNode location in node.GetNodes("LAND_LOCATION")) { Vector2d v = new Vector2d(); v.y = ConfigNodeUtil.ParseValue<double>(location, "lat"); v.x = ConfigNodeUtil.ParseValue<double>(location, "lon"); biomeData.landLocations.Add(v); } foreach (ConfigNode location in node.GetNodes("WATER_LOCATION")) { Vector2d v = new Vector2d(); v.y = ConfigNodeUtil.ParseValue<double>(location, "lat"); v.x = ConfigNodeUtil.ParseValue<double>(location, "lon"); biomeData.waterLocations.Add(v); } return biomeData; }
IEnumerable<YieldInstruction> LoadBodyInfo(CelestialBody body) { if (body == null || body.pqsController == null || !body.ocean || bodyInfo.ContainsKey(body)) { yield break; } Dictionary<string, BiomeData> biomeData = new Dictionary<string, BiomeData>(); int biomeCount = body.BiomeMap.Attributes.Length; float startTime = Time.realtimeSinceStartup; float timeStep = 0.01f; int maxCount = 1000; int w = 4096; int h = 2048; int bu = 0; int bv = 0; LoggingUtil.LogInfo(this, "Starting background load of " + body.name + " biome data."); int count = 0; for (int i = 0; i < w; i++) { bu = (bu + 977) % w; double lonRads = 2.0 * Math.PI * ((bu + 0.5) / w); double cosLon = Math.Cos(lonRads); double sinLon = Math.Sin(lonRads); for (int j = 0; j < h; j++) { count++; bv = (bv + 239) % h; double latRads = Math.PI * (0.5 - (bv + 0.5) / h); double cosLat = Math.Cos(latRads); double sinLat = Math.Sin(latRads); // Get biome data string biome = body.BiomeMap.GetAtt(latRads, lonRads).name.Replace(" ", ""); BiomeData bd; biomeData.TryGetValue(biome, out bd); if (bd == null) { bd = biomeData[biome] = new BiomeData(biome); } if (bd.landCount + bd.waterCount < maxCount || bd.landLocations.Count < 3 || bd.waterLocations.Count < 3) { Vector3d radialVector = new Vector3d(cosLat * cosLon, sinLat, cosLat * sinLon); double height = body.pqsController.GetSurfaceHeight(radialVector) - body.pqsController.radius; if (height > 0.0) { bd.landCount++; if (bd.landLocations.Count < 3) { double lon = lonRads * 180.0 / Math.PI; double lat = latRads * 180.0 / Math.PI; if (!bd.landLocations.Any(v => Math.Abs(v.x - lon) < 2.0 || Math.Abs(v.y - lat) < 2.0)) { bd.landLocations.Add(new Vector2d(lon, latRads * 180.0 / Math.PI)); } } } else { bd.waterCount++; if (bd.waterLocations.Count < 3) { double lon = lonRads * 180.0 / Math.PI; double lat = latRads * 180.0 / Math.PI; if (!bd.waterLocations.Any(v => Math.Abs(v.x - lon) < 2.0 || Math.Abs(v.y - lat) < 2.0)) { bd.waterLocations.Add(new Vector2d(lon, latRads * 180.0 / Math.PI)); } } } } // Take a break if (Time.realtimeSinceStartup >= startTime + timeStep) { yield return null; startTime = Time.realtimeSinceStartup; } } // Check for completion after every "row" if (biomeData.Count == biomeCount && biomeData.All(pair => pair.Value.landCount + pair.Value.waterCount >= maxCount && pair.Value.landLocations.Count >= 3 && pair.Value.waterLocations.Count >= 3)) { break; } } // Build a color => name map Dictionary<string, string> nameMap = new Dictionary<string, string>(); for (int i = 0; i < body.BiomeMap.Attributes.Length; i++) { nameMap[body.BiomeMap.Attributes[i].mapColor.ToString()] = body.BiomeMap.Attributes[i].name; } // Save the biomData that was collected bodyInfo[body] = biomeData; LoggingUtil.LogInfo(this, "Completed background load of " + body.name + " biome data."); }
void ConstructGround( int numPoints, float start, float width, float depth, int seed, BiomeData biome ) { int oldSeed = UnityEngine.Random.seed; UnityEngine.Random.seed = seed; var splineSource = Instantiate(rageSplinePrefab, Vector3.zero + Vector3.forward * depth, Quaternion.identity) as RageSpline; splineSource.transform.parent = transform; var rs = splineSource as IRageSpline; rs.SetFillColor1(biome.color); int nextItem = Random.Range(1,biome.spawnDensity); rs.SetPoint(0, Vector3.right * (start + width) + Vector3.down * 20); rs.SetPoint(1, Vector3.right * (start) + Vector3.down * 20); rs.SetVertexCount(1000); Vector3 lastPoint = Vector3.zero; for(int i = 0; i <= numPoints; i++){ float pos = i * (width / (float)numPoints); float height = biome.heightEnvelope.Evaluate(i/(float)numPoints) * biome.heightRange * (fracNoise.HybridMultifractal(pos/numPoints, 0+ 212, 0)*0.2f + fracNoiseBig.RidgedMultifractal(pos/2000, 0, 0.5f, 1.2f) ); var point = (pos + start) * Vector3.right + Vector3.up * height; rs.AddPoint(2+i,point + Vector3.up * 40,-Vector3.right*20, Vector3.right*20,0,false); if(i > 0 ){ if(biome.spawnables.Count > 0 && biome.spawnDensity > 0 && --nextItem == 0){ nextItem = Random.Range(1,biome.spawnDensity); float d = Random.value; Instantiate (biome.spawnables[Random.Range (0, biome.spawnables.Count)], Vector3.Lerp(lastPoint, point, Random.value) - Vector3.up * (d * 60 -30) - Vector3.forward * (d * 18 - 8) , Quaternion.identity); } var col =new GameObject().AddComponent<BoxCollider>(); col.center = new Vector3(0.5f,-5f,0f); col.size = new Vector3(1,10,1); col.transform.localScale = (point - lastPoint).magnitude * Vector3.right + Vector3.forward * 20 + Vector3.up; col.transform.right = point - lastPoint; col.transform.position = lastPoint; col.transform.parent = transform; col.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast"); } lastPoint = point; } rs.RefreshMesh(); UnityEngine.Random.seed = oldSeed; }