/// <summary> /// Grows the minerals on the map. /// </summary> /// <param name="map">The map where the minerals spawn</param> /// <param name="biomeMap">The biome map attached to the previous map.</param> public void GrowAll (TileType[, ] map, BiomeType[, ] biomeMap) { NoiseGenerator gen = new NoiseGenerator (); while (availableMinerals.Count > 0) { MineralInfo mineral = availableMinerals.Dequeue(); gen.Reset(); for (int x = 0; x < map.GetLength(0); x ++) { int y = (mineral.minHeight > 0 ? mineral.minHeight : 0); int maxY = (mineral.maxHeight < map.GetLength(1) ? mineral.maxHeight : map.GetLength(1)); for (; y < maxY; y ++) { if (IsTileCompatible(biomeMap, x, y, mineral.compatibleBiomes) && (mineral.rarity < (int) gen.PerlinNoise(x, y, 10, 100, 1))) PlaceMinerals(map, x, y, mineral.minerals); } } } }
void GenerateMesh() { float start_time = Time.time; NoiseGenerator gen = new NoiseGenerator(); noise = gen.generateNoise(width,width,100); MeshBuilder builder = new MeshBuilder(); Vector3 offset = new Vector3(0, 0, 0); for(int x = 0;x< width;x++){ for(int z=0;z< width;z++){ offset.z+= spacing; offset.y = noise[x * width + z] * Random.Range(-3,3); bool tri = x > 0 && z > 0; BuildQuadForGrid(builder,offset,new Vector2((1f/width)*x,(1f/width)*z),tri,width); } offset.x+= spacing; offset.z = 0; } if (terrainMesh != null) { Mesh mesh = builder.CreateMesh(); mesh.RecalculateNormals(); terrainMesh.sharedMesh = mesh; } float diff = Time.time - start_time; Debug.Log("ProceduralTerrain was generated in " + diff + " seconds."); }
private NoiseGenerator InitializeMountains(int width, int height) { var generator = new NoiseGenerator(seed, width, height); generator.Settings.Frequency = 0.006; generator.Settings.Persistence = 0.65; generator.Settings.Octaves = 8; generator.Settings.Amplitude = 0.65; generator.Settings.CloudCoverage = 0; generator.Settings.CloudDensity = 1; return generator; }
private static void CreateSkyBox() { NoiseGenerator noise = new NoiseGenerator(); Texture2D texture = noise.GenerateTexture(1080, 720, 10000f); texture.wrapMode = TextureWrapMode.Repeat; for (int i = 0; i <= Random.Range(2000, 3500); i++) { float f = Random.value; if (f >= 0.1) { texture.SetPixel(Random.Range(0, texture.width), Random.Range(0, texture.height), Color.white); } else { int x = Random.Range(0, texture.width); int y = Random.Range(0, texture.height); texture.SetPixel(x, y, Color.white); texture.SetPixel(x + 1, y, Color.white); texture.SetPixel(x, y + 1, Color.white); texture.SetPixel(x + 1, y + 1, Color.white); } } texture.Apply(); GameObject camera = Camera.main.gameObject; Skybox skybox = camera.GetComponent<Skybox>(); if (skybox == null) { skybox = camera.AddComponent<Skybox>(); } skybox.material = new Material(Shader.Find("RenderFX/Skybox")); skybox.material.SetTexture("_FrontTex", texture); skybox.material.SetTexture("_BackTex", texture); skybox.material.SetTexture("_LeftTex", texture); skybox.material.SetTexture("_RightTex", texture); skybox.material.SetTexture("_UpTex", texture); skybox.material.SetTexture("_DownTex", texture); }
public void SetNoiseGenerator(NoiseGenerator noise) { _noise = noise; }
public VoxelChunk GenerateChunk(Vector3 origin, int chunkSizeX, int chunkSizeY, int chunkSizeZ, ComponentManager components, ContentManager content, GraphicsDevice graphics) { float waterHeight = SeaLevel; VoxelChunk c = new VoxelChunk(Manager, origin, 1, Manager.ChunkData.GetChunkID(origin + new Vector3(0.5f, 0.5f, 0.5f)), chunkSizeX, chunkSizeY, chunkSizeZ) { ShouldRebuild = true, ShouldRecalculateLighting = true }; Voxel voxel = c.MakeVoxel(0, 0, 0); for (int x = 0; x < chunkSizeX; x++) { for (int z = 0; z < chunkSizeZ; z++) { Vector2 v = new Vector2(x + origin.X, z + origin.Z) / PlayState.WorldScale; Overworld.Biome biome = Overworld.Map[(int)MathFunctions.Clamp(v.X, 0, Overworld.Map.GetLength(0) - 1), (int)MathFunctions.Clamp(v.Y, 0, Overworld.Map.GetLength(1) - 1)].Biome; BiomeData biomeData = BiomeLibrary.Biomes[biome]; Vector2 pos = new Vector2(x + origin.X, z + origin.Z) / PlayState.WorldScale; float hNorm = Overworld.GetValue(Overworld.Map, pos, Overworld.ScalarFieldType.Height); float h = MathFunctions.Clamp(hNorm * chunkSizeY, 0.0f, chunkSizeY - 2); int stoneHeight = (int)Math.Max(h - 2, 1); for (int y = 0; y < chunkSizeY; y++) { voxel.GridPosition = new Vector3(x, y, z); if (y == 0) { voxel.Type = VoxelLibrary.GetVoxelType("Bedrock"); continue; } if (y <= stoneHeight && stoneHeight > 1) { voxel.Type = VoxelLibrary.GetVoxelType(biomeData.SubsurfVoxel); voxel.Health = VoxelLibrary.GetVoxelType(biomeData.SubsurfVoxel).StartingHealth; } else if ((y == (int)h || y == stoneHeight) && hNorm > waterHeight) { if (biomeData.ClumpGrass && NoiseGenerator.Noise(pos.X / biomeData.ClumpSize, 0, pos.Y / biomeData.ClumpSize) > biomeData.ClumpTreshold) { voxel.Type = VoxelLibrary.GetVoxelType(biomeData.GrassVoxel); voxel.Health = VoxelLibrary.GetVoxelType(biomeData.GrassVoxel).StartingHealth; } else if (!biomeData.ClumpGrass) { voxel.Type = VoxelLibrary.GetVoxelType(biomeData.GrassVoxel); voxel.Health = VoxelLibrary.GetVoxelType(biomeData.GrassVoxel).StartingHealth; } else { voxel.Type = VoxelLibrary.GetVoxelType(biomeData.SoilVoxel); voxel.Health = VoxelLibrary.GetVoxelType(biomeData.SoilVoxel).StartingHealth; } } else if (y > h && y > 0) { voxel.Type = VoxelLibrary.GetVoxelType("empty"); } else if (hNorm < waterHeight) { voxel.Type = VoxelLibrary.GetVoxelType(biomeData.ShoreVoxel); voxel.Health = VoxelLibrary.GetVoxelType(biomeData.ShoreVoxel).StartingHealth; } else { voxel.Type = VoxelLibrary.GetVoxelType(biomeData.SoilVoxel); voxel.Health = VoxelLibrary.GetVoxelType(biomeData.SoilVoxel).StartingHealth; } } } } GenerateOres(c, components, content, graphics); GenerateCaves(c); GenerateWater(c); GenerateLava(c); c.ShouldRebuildWater = true; return(c); }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); selectedMapGenerator = (MapGeneratorV3.MapGenerators)EditorGUILayout.EnumPopup("Choose your Map Generator: ", selectedMapGenerator); if (GUILayout.Button("Generate")) { IGenerator gen = null; if (model.UseRandomSeed) { model.Seed = System.DateTime.Now.ToString(); } switch (selectedMapGenerator) { case MapGeneratorV3.MapGenerators.NoiseGenerator: gen = new NoiseGenerator(model.Increment, model.Seed); break; case MapGeneratorV3.MapGenerators.RandomGenerator: gen = new RandomGenerator(model.LandMasses, model.NumberOfAdjacents, model.Variance, model.NumberOfSmoothings, model.Seed); break; case MapGeneratorV3.MapGenerators.Random2DGenerator: gen = new Random2DGenerator(model.Increment, model.NumberOfAdjacents, model.NumberOfSmoothings, model.LandMasses, model.Seed); break; case MapGeneratorV3.MapGenerators.RandomOutOfPlaceGenerator: gen = new RandomOutOfPlaceGenerator(model.LandMasses, model.NumberOfAdjacents, model.Variance, model.NumberOfSmoothings, model.Seed); break; case MapGeneratorV3.MapGenerators.Random2DOutOfPlaceGenerator: gen = new Random2DOutOfPlaceGenerator(model.LandMasses, model.NumberOfAdjacents, model.Variance, model.NumberOfSmoothings, model.Seed); break; case MapGeneratorV3.MapGenerators.NoiseRandomGenerator: gen = new NoiseRandomGenerator(model.FloorIncrement, model.RandomAmplitude, model.Increment, model.Seed); break; } mapGenerator.GenerateMap(gen); } switch (selectedMapGenerator) { case MapGeneratorV3.MapGenerators.NoiseGenerator: EditorGUILayout.LabelField("Noise Generator"); model.Increment = EditorGUILayout.Slider("Increment", model.Increment, 0f, 0.1f); break; case MapGeneratorV3.MapGenerators.RandomGenerator: case MapGeneratorV3.MapGenerators.RandomOutOfPlaceGenerator: EditorGUILayout.LabelField("Random Generator"); model.LandMasses = EditorGUILayout.Slider("Land Masses", model.LandMasses, 0f, 1f); model.NumberOfAdjacents = EditorGUILayout.IntSlider("NumberOfAdjacents", model.NumberOfAdjacents, 10, 20); model.Variance = EditorGUILayout.IntSlider("Variance", model.Variance, 0, 5); model.NumberOfSmoothings = EditorGUILayout.IntField("Number of Smoothings", model.NumberOfSmoothings); break; case MapGeneratorV3.MapGenerators.Random2DGenerator: case MapGeneratorV3.MapGenerators.Random2DOutOfPlaceGenerator: EditorGUILayout.LabelField("Random2D Generator"); model.LandMasses = EditorGUILayout.Slider("Land Masses", model.LandMasses, 0f, 1f); model.NumberOfAdjacents = EditorGUILayout.IntSlider("NumberOfAdjacents", model.NumberOfAdjacents, 0, 9); model.NumberOfSmoothings = EditorGUILayout.IntField("Number of Smoothings", model.NumberOfSmoothings); model.Increment = EditorGUILayout.Slider("Increment", model.Increment, 0f, 0.1f); break; case MapGeneratorV3.MapGenerators.NoiseRandomGenerator: EditorGUILayout.LabelField("Noise Generator"); model.Increment = EditorGUILayout.Slider("Increment", model.Increment, 0f, 0.5f); model.FloorIncrement = EditorGUILayout.Slider("Floor Increment", model.FloorIncrement, 0f, 0.5f); model.RandomAmplitude = EditorGUILayout.Slider("Random Amplitude", model.RandomAmplitude, -2f, 2f); break; } model.UseRandomSeed = EditorGUILayout.Toggle("Use random Seed", model.UseRandomSeed); model.Seed = EditorGUILayout.TextField("Seed", model.Seed); if (GUILayout.Button("Mesh")) { mapGenerator.CreateMesh(); } if (EditorGUI.EndChangeCheck()) { SceneView.RepaintAll(); } }
public ParticleAcceleratorControlMenu(ParticleAcceleratorBoundUserInterface owner) { _greyScaleShader = IoCManager.Resolve <IPrototypeManager>().Index <ShaderPrototype>("Greyscale").Instance(); Owner = owner; _drawNoiseGenerator = new NoiseGenerator(NoiseGenerator.NoiseType.Fbm); _drawNoiseGenerator.SetFrequency(0.5f); var resourceCache = IoCManager.Resolve <IResourceCache>(); var font = resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13); var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png"); MouseFilter = MouseFilterMode.Stop; _alarmControlAnimation = new Animation { Length = TimeSpan.FromSeconds(1), AnimationTracks = { new AnimationTrackControlProperty { Property = nameof(Control.Visible), KeyFrames = { new AnimationTrackProperty.KeyFrame(true, 0), new AnimationTrackProperty.KeyFrame(false, 0.75f), } } } }; var back = new StyleBoxTexture { Texture = panelTex, Modulate = Color.FromHex("#25252A"), }; back.SetPatchMargin(StyleBox.Margin.All, 10); var back2 = new StyleBoxTexture(back) { Modulate = Color.FromHex("#202023") }; AddChild(new PanelContainer { PanelOverride = back, MouseFilter = MouseFilterMode.Pass }); _stateSpinBox = new SpinBox { Value = 0, }; _stateSpinBox.IsValid = StrengthSpinBoxValid; _stateSpinBox.InitDefaultButtons(); _stateSpinBox.ValueChanged += PowerStateChanged; _stateSpinBox.LineEditDisabled = true; _offButton = new Button { ToggleMode = false, Text = "Off", StyleClasses = { StyleBase.ButtonOpenRight }, }; _offButton.OnPressed += args => owner.SendEnableMessage(false); _onButton = new Button { ToggleMode = false, Text = "On", StyleClasses = { StyleBase.ButtonOpenLeft }, }; _onButton.OnPressed += args => owner.SendEnableMessage(true); var closeButton = new TextureButton { StyleClasses = { "windowCloseButton" }, SizeFlagsHorizontal = SizeFlags.ShrinkEnd }; closeButton.OnPressed += args => Close(); var serviceManual = new Label { SizeFlagsHorizontal = SizeFlags.ShrinkCenter, StyleClasses = { StyleBase.StyleClassLabelSubText }, Text = Loc.GetString("Refer to p.132 of service manual") }; _drawLabel = new Label(); var imgSize = new Vector2(32, 32); AddChild(new VBoxContainer { Children = { new MarginContainer { MarginLeftOverride = 2, MarginTopOverride = 2, Children = { new Label { Text = Loc.GetString("Mark 2 Particle Accelerator"), FontOverride = font, FontColorOverride = StyleNano.NanoGold, }, new MarginContainer { MarginRightOverride = 8, Children = { closeButton } } } }, new PanelContainer { PanelOverride = new StyleBoxFlat { BackgroundColor = StyleNano.NanoGold }, CustomMinimumSize = (0, 2), },
//Examine a cell public static void UpdateTerrain(Vector3 CubePosition) { //index for triange calc int index = 0; //grab the terrain generator for additional values TerrainGeneration tG = FindObjectOfType <TerrainGeneration>(); //grab the noise generator NoiseGenerator nG = FindObjectOfType <NoiseGenerator>(); //new cube Cube cube = new Cube(); //init the arrays cube.Init(); //size of the cube cube.Size = tG.ChunkSize / (float)tG.VoxelsPerAxis; //corner bit poattern positions (clockwise - bottom then top) byte[] b = { 0, 4, 5, 1, 2, 6, 7, 3 }; //world positions of all corners for (int x = 0; x < 8; x++) { //return the bit val of first 3 bits in byte to cover all indicies Vector3 ind = new Vector3(BitVal(b[x], 3), BitVal(b[x], 2), BitVal(b[x], 1)); /* * (0, 0, 0) * (X, 0, 0) * (X, 0, X) * (0, 0, X) * (0, X, 0) * (X, X, 0) * (X, X, X) * (0, X, X) */ cube.CornerPos[x] = IndexFromCube(ind.x, ind.y, ind.z); } tG.cubeGizmo = cube; //calculte the density value at each corner voxel //generate density values for w in the cube vector nG.GenerateDensityValue(cube); //Classify each vertex as inside or outside of the iso value for (int i = 0; i < 8; i++) { //bit OR to add values when under the isoSurface if (cube.CornerPos[i].w < tG.ISOValue) { index |= (int)(Mathf.Pow(2f, i)); } } /* * // Depreciated for code below this - however this makes it easier to understand and is how its shown in Paul Bourke's explaination (http://paulbourke.net/geometry/polygonise/) - so left in for reference * * //determine what verts are inside our isoValue * Vector3[] vertList = new Vector3[12]; * * float ISO = tG.ISOValue; * * // Cube is entirely in/out of the surface - skip the rest * if (Lookup.EdgeTable[index] != 0) * { * // Find the vertices where the surface intersects the cube * if ((Lookup.EdgeTable[index] & 1) != 0) { vertList[0] = VertexInterp(ISO, cube.CornerPos[0], cube.CornerPos[1]); } //B * if ((Lookup.EdgeTable[index] & 2) != 0) { vertList[1] = VertexInterp(ISO, cube.CornerPos[1], cube.CornerPos[2]); } * if ((Lookup.EdgeTable[index] & 4) != 0) { vertList[2] = VertexInterp(ISO, cube.CornerPos[2], cube.CornerPos[3]); } //A * if ((Lookup.EdgeTable[index] & 8) != 0) { vertList[3] = VertexInterp(ISO, cube.CornerPos[3], cube.CornerPos[0]); } * if ((Lookup.EdgeTable[index] & 16) != 0) { vertList[4] = VertexInterp(ISO, cube.CornerPos[4], cube.CornerPos[5]); } * if ((Lookup.EdgeTable[index] & 32) != 0) { vertList[5] = VertexInterp(ISO, cube.CornerPos[5], cube.CornerPos[6]); } * if ((Lookup.EdgeTable[index] & 64) != 0) { vertList[6] = VertexInterp(ISO, cube.CornerPos[6], cube.CornerPos[7]); } * if ((Lookup.EdgeTable[index] & 128) != 0) { vertList[7] = VertexInterp(ISO, cube.CornerPos[7], cube.CornerPos[4]); } * if ((Lookup.EdgeTable[index] & 256) != 0) { vertList[8] = VertexInterp(ISO, cube.CornerPos[0], cube.CornerPos[4]); } * if ((Lookup.EdgeTable[index] & 512) != 0) { vertList[9] = VertexInterp(ISO, cube.CornerPos[1], cube.CornerPos[5]); } * if ((Lookup.EdgeTable[index] & 1024) != 0) { vertList[10] = VertexInterp(ISO, cube.CornerPos[2], cube.CornerPos[6]); } * if ((Lookup.EdgeTable[index] & 2048) != 0) { vertList[11] = VertexInterp(ISO, cube.CornerPos[3], cube.CornerPos[7]); } * } * * * // Create triangles for current cube configuration * int ntriang = 0; * for (int i = 0; Lookup.TriTable[index,i] != -1; i += 3) * { * Triangle triangle = new Triangle * { * // triangle.Init(); * a = vertList[Lookup.TriTable[index, i]], * b = vertList[Lookup.TriTable[index, i + 1]], * c = vertList[Lookup.TriTable[index, i + 2]] * }; * ntriang++; * * nG.CalculateNormal(triangle); * */ //!Shorthand of the above using an additional lookup table to find the correct edge table!// // Create triangles for current cube configuration for (int i = 0; Lookup.TriTable[index, i] != -1; i += 3) { // Get indices of corner points A and B for each of the three edges // of the cube that need to be joined to form the triangle. int a0 = Lookup.cornerIndexAFromEdge[Lookup.TriTable[index, i]]; int b0 = Lookup.cornerIndexBFromEdge[Lookup.TriTable[index, i]]; int a1 = Lookup.cornerIndexAFromEdge[Lookup.TriTable[index, i + 1]]; int b1 = Lookup.cornerIndexBFromEdge[Lookup.TriTable[index, i + 1]]; int a2 = Lookup.cornerIndexAFromEdge[Lookup.TriTable[index, i + 2]]; int b2 = Lookup.cornerIndexBFromEdge[Lookup.TriTable[index, i + 2]]; Triangle tri; tri.a = VertexInterp(cube.CornerPos[a0], cube.CornerPos[b0]); tri.b = VertexInterp(cube.CornerPos[a1], cube.CornerPos[b1]); tri.c = VertexInterp(cube.CornerPos[a2], cube.CornerPos[b2]); //add the triangle to our list if (tri.a != null) { tG.tris.Add(tri); } } //get a bit value from a certain byte float BitVal(byte _byte, int bitNumber) { bool bit = (_byte & (1 << bitNumber - 1)) != 0; //return the cube size if bit is true return(bit ? cube.Size : 0); } //Linearly interpolate the position where an isosurface cuts //an edge between two vertices, each with their own scalar value Vector3 VertexInterp(Vector4 v1, Vector4 v2) { float t = (tG.ISOValue - v1.w) / (v2.w - v1.w); Vector3 v1_1 = new Vector3(v1.x, v1.y, v1.z); Vector3 v2_1 = new Vector3(v2.x, v2.y, v2.z); return(v1_1 + t * (v2_1 - v1_1)); } //return the vertex index Vector4 IndexFromCube(float x, float y, float z) { Vector3 offset = new Vector3(x, y, z); return(CubePosition + offset - Vector3.one * (cube.Size / 2f)); } }
private void OnEnable() { _noiseGenerator = (NoiseGenerator)target; }
public Color[,] PreGeneratedColorMap() { return(NoiseGenerator.ColorMap(mapWidth, mapHeight, seed, scale, octaves, persistance, lacunarity, offset, WaterLevel, gameObject.GetComponent <MapColor>())); }
public static Color[,] ColorMap(int mapWidth, int mapHeight, int seed, float scale, int octaves, float persistance, float lacunarity, Vector2 offset, float WaterLevel, MapColor colors) { float[,] heightMap = new float[mapWidth, mapHeight]; float[,] temparatureMap = new float[mapWidth, mapHeight]; Color[,] writingColorMap = new Color[mapWidth, mapHeight]; heightMap = NoiseGenerator.GenerateNoiseMap(mapWidth, mapHeight, seed, scale, octaves, persistance, lacunarity, offset + new Vector2((colors.LoadedChunk.x + colors.FakePosX) * mapWidth, (colors.LoadedChunk.y + colors.FakePosY) * mapHeight)); temparatureMap = NoiseGenerator.TempMap(mapWidth, mapHeight, heightMap, colors); for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { Color BeachColor = new Color(Mathf.Lerp(colors.TeamperateBeach.r, colors.TopicalBeach.r, 1 - temparatureMap[x, y]), Mathf.Lerp(colors.TeamperateBeach.g, colors.TopicalBeach.g, 1 - temparatureMap[x, y]), Mathf.Lerp(colors.TeamperateBeach.b, colors.TopicalBeach.b, 1 - temparatureMap[x, y])); BeachColor.r = BeachColor.r + heightMap[x, y] - WaterLevel; BeachColor.g = BeachColor.g + heightMap[x, y] - WaterLevel; BeachColor.b = BeachColor.b + heightMap[x, y] - WaterLevel; Color OceanColor = new Color((colors.Ocean.r + heightMap[x, y]) - WaterLevel, (colors.Ocean.g + heightMap[x, y]) - WaterLevel, (colors.Ocean.b + heightMap[x, y]) - WaterLevel); Color SeaColor = new Color((colors.Sea.r + heightMap[x, y]) - WaterLevel, (colors.Sea.g + heightMap[x, y]) - WaterLevel, (colors.Sea.b + heightMap[x, y]) - WaterLevel); Color UnEditedGrass = new Color(Mathf.Lerp(colors.Cold.r, colors.Wet.r, 1 - temparatureMap[x, y]), Mathf.Lerp(colors.Cold.g, colors.Wet.g, 1 - temparatureMap[x, y]), Mathf.Lerp(colors.Cold.b, colors.Wet.b, 1 - temparatureMap[x, y])); if (heightMap[x, y] >= WaterLevel) { if (heightMap[x, y] > colors.DryLevel) { if (heightMap[x, y] > colors.MoutainLevel) { writingColorMap[x, y] = new Color(Mathf.Lerp(colors.WetRock.r, colors.ColdRock.r, heightMap[x, y]) - colors.RockDryness, Mathf.Lerp(colors.WetRock.g, colors.ColdRock.g, heightMap[x, y]) - colors.RockDryness, Mathf.Lerp(colors.WetRock.b, colors.ColdRock.b, heightMap[x, y]) - colors.RockDryness); } else { if (temparatureMap[x, y] < 0.40f) { writingColorMap[x, y] = colors.DrySand; } else { writingColorMap[x, y] = new Color(Mathf.Lerp(UnEditedGrass.r, colors.Dry.r, heightMap[x, y]), Mathf.Lerp(UnEditedGrass.g, colors.Dry.g, heightMap[x, y]), Mathf.Lerp(UnEditedGrass.b, colors.Dry.b, heightMap[x, y])); } } } else { writingColorMap[x, y] = UnEditedGrass; } } else { if (temparatureMap[x, y] > colors.GlobalIceMapping) { writingColorMap[x, y] = colors.Ice; } else { if (heightMap[x, y] > colors.BeachLevel) { writingColorMap[x, y] = NoiseGenerator.ColorLerp(BeachColor, SeaColor, 1 - (heightMap[x, y] - colors.BeachLevel) / (WaterLevel - colors.BeachLevel)); } else { if (heightMap[x, y] > colors.SeaLevel) { writingColorMap[x, y] = NoiseGenerator.ColorLerp(SeaColor, OceanColor, 1 - (heightMap[x, y] - colors.SeaLevel) / (colors.BeachLevel - colors.SeaLevel)); } else { writingColorMap[x, y] = OceanColor; } } } } } } for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { if (temparatureMap[x, y] > colors.GlobalSnowMapping && heightMap[x, y] > WaterLevel) { writingColorMap[x, y] = colors.Snow; } } } return(writingColorMap); }
//Performs the same functionality as a NoiseGenerator object without having to have an instance of NoiseGenerator, useful for //a single use noise generation public static int generateNoise(int x, int y, int z, float scale, int max) { NoiseGenerator noiseGenerator = new NoiseGenerator(scale, max); return(noiseGenerator.generateNoise(x, y, z)); }
public AsteroidEditorTab(Content content, Editors editors, SpherifiedCubeGenerator spherifiedCubeGenerator, EntityController entityController, NoiseGenerator noiseGenerator) { this.Texture = content.DebugTexture; this.Editors = editors; this.AsteroidBluePrint = new AsteroidBluePrint(); this.CraterBluePrints = new List <CraterBluePrint>(); this.SpherifiedCubeGenerator = spherifiedCubeGenerator; this.EntityController = entityController; this.NoiseGenerator = noiseGenerator; this.CraterBluePrints.Add(new CraterBluePrint()); }
public NoiseGeneratorTests() { NoiseGenerator.SetDefaultVectorTable(); }
float NoisePlane(Vector3 point, float noiseHeight) { return(point.y + NoiseGenerator.sampleNoise2D(new Vector2(point.x, point.z) * 0.05f) * noiseHeight); }
public ChunkGenerator(int seed) { noiseGenerator = new NoiseGenerator(seed); }
public float[,] Erode(int seed, float[,] heightMap, int heightMapIndex) { System.Random prng = new System.Random(seed); int width = heightMap.GetLength(0) - 1; int height = heightMap.GetLength(1) - 1; float minHeightValue = float.MaxValue; float maxHeightValue = float.MinValue; for (int i = 0; i < iterationCount; i++) { Vector2 position = new Vector2(prng.Next(1, width - 1), prng.Next(1, height - 1)); Particle particle = new Particle(position, startVolume); for (int l = 0; l < particleLifetime; l++) { Vector2 currentPosition = particle.GetPosition(); int curX = (int)currentPosition.x; int curY = (int)currentPosition.y; float currentHeight = heightMap[curX, curY]; Vector2 gradient = CalculatePointGradient(heightMap, currentPosition.x, currentPosition.y); Vector2 speed = particle.GetSpeed() + gradient / particle.GetVolume(); if (speed.magnitude == 0) { break; } Vector2 nextPosition = currentPosition + speed; bool outOfHeightMap = nextPosition.x < 1 || nextPosition.x >= width || nextPosition.y < 1 || nextPosition.y >= height; if (outOfHeightMap) { break; } float nextHeight = heightMap[(int)nextPosition.x, (int)nextPosition.y]; float heightDiff = currentHeight - nextHeight; float capasity = particle.GetVolume() * speed.magnitude * heightDiff; if (capasity < 0) { capasity = 0f; } float capasityDiff = capasity - particle.GetSediment() * depositionRate; heightMap[curX, curY] -= capasityDiff; if (heightMap[curX, curY] > maxHeightValue) { maxHeightValue = heightMap[curX, curY]; } if (heightMap[curX, curY] < minHeightValue) { minHeightValue = heightMap[curX, curY]; } particle.SetSediment(particle.GetSediment() + capasityDiff); particle.SetSpeed(speed); particle.SetPosition(nextPosition); particle.SetVolume(particle.GetVolume() * (1 - evaporationRate)); if (debug) { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); float sphereHeight = heightMap[(int)currentPosition.x, (int)currentPosition.y] * FindObjectOfType <MapGenerator>().heightMultiplier; sphere.transform.position = new Vector3(currentPosition.x, sphereHeight, currentPosition.y); sphere.transform.localScale = Vector3.one * particle.GetVolume() * 0.4f; sphere.GetComponent <Renderer>().sharedMaterial.color = Color.red; } } } NoiseGenerator.SetMaxValue(heightMapIndex, maxHeightValue); NoiseGenerator.SetMinValue(heightMapIndex, minHeightValue); return(heightMap); }
public void GenerateCaves(VoxelChunk chunk) { Vector3 origin = chunk.Origin; int chunkSizeX = chunk.SizeX; int chunkSizeY = chunk.SizeY; int chunkSizeZ = chunk.SizeZ; BiomeData biome = BiomeLibrary.Biomes[Overworld.Biome.Cave]; List <Voxel> neighbors = new List <Voxel>(); Voxel vUnder = chunk.MakeVoxel(0, 0, 0); for (int x = 0; x < chunkSizeX; x++) { for (int z = 0; z < chunkSizeZ; z++) { int h = chunk.GetFilledVoxelGridHeightAt(x, chunk.SizeY - 1, z); for (int i = 0; i < CaveLevels.Count; i++) { int y = CaveLevels[i]; if (y <= 0 || y >= h - 1) { continue; } Vector3 vec = new Vector3(x, y, z) + chunk.Origin; double caveNoise = CaveNoise.GetValue((x + origin.X) * CaveNoiseScale * CaveFrequencies[i], (y + origin.Y) * CaveNoiseScale * 3.0f, (z + origin.Z) * CaveNoiseScale * CaveFrequencies[i]); double heightnoise = NoiseGenerator.Noise((x + origin.X) * NoiseScale * CaveFrequencies[i], (y + origin.Y) * NoiseScale * 3.0f, (z + origin.Z) * NoiseScale * CaveFrequencies[i]); int caveHeight = Math.Min(Math.Max((int)(heightnoise * 5), 1), 3); if (caveNoise > CaveSize) { bool waterFound = false; for (int dy = 0; dy < caveHeight; dy++) { int index = chunk.Data.IndexAt(x, y - dy, z); chunk.GetNeighborsManhattan(x, y - dy, z, neighbors); if (neighbors.Any(v => v.WaterLevel > 0)) { waterFound = true; } if (waterFound) { break; } chunk.Data.Types[index] = 0; } if (!waterFound && caveNoise > CaveSize * 1.8f && y - caveHeight > 0) { int indexunder = chunk.Data.IndexAt(x, y - caveHeight, z); chunk.Data.Types[indexunder] = (byte)VoxelLibrary.GetVoxelType(biome.GrassVoxel).ID; chunk.Data.Health[indexunder] = (byte)VoxelLibrary.GetVoxelType(biome.GrassVoxel).StartingHealth; chunk.Data.IsExplored[indexunder] = false; foreach (VegetationData veg in biome.Vegetation) { if (!MathFunctions.RandEvent(veg.SpawnProbability)) { continue; } if (NoiseGenerator.Noise(vec.X / veg.ClumpSize, veg.NoiseOffset, vec.Y / veg.ClumpSize) < veg.ClumpThreshold) { continue; } vUnder.GridPosition = new Vector3(x, y - 1, z); if (!vUnder.IsEmpty && vUnder.TypeName == biome.GrassVoxel) { vUnder.Type = VoxelLibrary.GetVoxelType(biome.SoilVoxel); float offset = veg.VerticalOffset; if (vUnder.RampType != RampType.None) { offset -= 0.25f; } float treeSize = MathFunctions.Rand() * veg.SizeVariance + veg.MeanSize; GameComponent entity = EntityFactory.CreateEntity <GameComponent>(veg.Name, chunk.Origin + new Vector3(x, y, z) + new Vector3(0, treeSize * offset, 0), Blackboard.Create("Scale", treeSize)); entity.GetRootComponent().SetActiveRecursive(false); entity.GetRootComponent().SetVisibleRecursive(false); if (GameSettings.Default.FogofWar) { ExploredListener listener = new ExploredListener( PlayState.ComponentManager, entity, PlayState.ChunkManager, vUnder); } } } } foreach (FaunaData animal in biome.Fauna) { if (y <= 0 || !(PlayState.Random.NextDouble() < animal.SpawnProbability)) { continue; } var entity = EntityFactory.CreateEntity <GameComponent>(animal.Name, chunk.Origin + new Vector3(x, y, z) + Vector3.Up * 1.0f); entity.GetRootComponent().SetActiveRecursive(false); entity.GetRootComponent().SetVisibleRecursive(false); if (GameSettings.Default.FogofWar) { ExploredListener listener = new ExploredListener(PlayState.ComponentManager, entity, PlayState.ChunkManager, chunk.MakeVoxel(x, y, z)); } break; } } } } } }
public float[,] PreGeneratedHeightMap() { return(NoiseGenerator.GenerateNoiseMap(mapWidth, mapHeight, seed, scale, octaves, persistance, lacunarity, offset + new Vector2((LoadedChunk.x + FakePosX) * mapWidth, (LoadedChunk.y + FakePosY) * mapHeight))); }
public bool tick(GameTime time) { TimeSpan timeSpan; if (!this.reachedFinish && (this.livesLeft > 0 || this.gameMode == 2) && (double)this.screenDarkness > 0.0) { double screenDarkness = (double)this.screenDarkness; timeSpan = time.ElapsedGameTime; double num = (double)timeSpan.Milliseconds * (1.0 / 500.0); this.screenDarkness = (float)(screenDarkness - num); } int num1 = this.track.ElementAt <Point>(6).X == 0 ? 9999 : this.track.ElementAt <Point>(6).Y *this.tileSize + (this.track.ElementAt <Point>(6).X == 3 ? (int)-(double)this.speedAccumulator : (this.track.ElementAt <Point>(6).X == 4 ? (int)((double)this.speedAccumulator - 16.0) : 0)); if (this.respawnCounter <= 0 || this.track[6].X == 0 || (this.obstacles[6].X == 1 || this.obstacles[7].X == 1)) { double speedAccumulator1 = (double)this.speedAccumulator; timeSpan = time.ElapsedGameTime; double num2 = (double)timeSpan.Milliseconds * (double)this.speed; this.speedAccumulator = (float)(speedAccumulator1 + num2); num1 = this.track.ElementAt <Point>(6).X == 0 ? 9999 : this.track.ElementAt <Point>(6).Y *this.tileSize + (this.track.ElementAt <Point>(6).X == 3 ? (int)-(double)this.speedAccumulator : (this.track.ElementAt <Point>(6).X == 4 ? (int)((double)this.speedAccumulator - 16.0) : 0)); if ((double)this.speedAccumulator >= (double)this.tileSize) { if (!this.isJumping && this.movingOnSlope == 0 && Game1.random.NextDouble() < 0.5) { this.minecartBumpOffset = (float)Game1.random.Next(1, 3); } if ((this.totalMotion + 1) % 1000 == 0) { Game1.playSound("newArtifact"); } else if ((this.totalMotion + 1) % 100 == 0) { Game1.playSound("Pickup_Coin15"); } this.totalMotion = this.totalMotion + 1; if (this.totalMotion > Game1.minecartHighScore) { Game1.minecartHighScore = this.totalMotion; } if (this.distanceToTravel != -1 && this.totalMotion >= this.distanceToTravel + this.screenWidth / this.tileSize) { if (!this.reachedFinish) { Game1.playSound("reward"); } this.reachedFinish = true; } this.track.RemoveAt(0); this.ceiling.RemoveAt(0); this.obstacles.RemoveAt(0); if (this.distanceToTravel == -1 || this.totalMotion < this.distanceToTravel) { double num3 = NoiseGenerator.Noise(this.totalMotion, this.noiseSeed); Point point = Point.Zero; if (num3 > this.heightChangeThreshold && this.lastNoiseValue <= this.heightChangeThreshold) { this.currentTrackY = Math.Max(this.currentTrackY - Game1.random.Next(1, 2), -6); } else if (num3 < this.heightChangeThreshold && this.lastNoiseValue >= this.heightChangeThreshold) { this.currentTrackY = Math.Min(this.currentTrackY + Game1.random.Next(1, this.currentTrackY <= -3 ? 6 : 3), 4); } else if (Math.Abs(num3 - this.lastNoiseValue) > this.heightFluctuationsThreshold) { this.currentTrackY = this.track[this.track.Count - 1].X != 0 ? Math.Max(Math.Min(4, this.currentTrackY + Game1.random.Next(-3, 3)), -6) : Math.Max(-6, Math.Min(6, this.currentTrackY + Game1.random.Next(1, 1))); } if (num3 < -0.5) { bool flag = false; for (int index = 0; index < 4 - (Game1.random.NextDouble() < 0.1 ? 1 : 0); ++index) { if (this.track[this.track.Count - 1 - index].X != 0) { flag = true; break; } } point = !flag ? new Point(Game1.random.Next(1, 3), Game1.random.NextDouble() >= 0.5 || this.currentTrackY >= 6 ? this.currentTrackY + 1 : this.currentTrackY) : new Point(0, 999); } else { point = new Point(Game1.random.Next(1, 3), this.currentTrackY); } if (this.track[this.track.Count - 1].X == 0 && point.X != 0) { point.Y = Math.Min(6, point.Y + 1); } if (point.Y == this.track[this.track.Count - 1].Y - 1) { this.track.RemoveAt(this.track.Count - 1); this.track.Add(new Point(3, this.currentTrackY + 1)); } else if (point.Y == this.track[this.track.Count - 1].Y + 1) { point.X = 4; } this.track.Add(point); this.ceiling.Add(new Point(Game1.random.Next(200), Math.Min(this.currentTrackY - 5 + this.ytileOffset, Math.Max(0, this.ceiling.Last <Point>().Y + (Game1.random.NextDouble() < 0.15 ? Game1.random.Next(-1, 2) : 0))))); bool flag1 = false; for (int index = 0; index < 2; ++index) { if (this.track[this.track.Count - 1 - index].X == 0 || this.track[this.track.Count - 1 - index - 1].Y != this.track[this.track.Count - 1 - index].Y) { flag1 = true; break; } } if (!flag1 && Game1.random.NextDouble() < this.obstacleOccurance && (this.currentTrackY > -2 && this.track.Last <Point>().X != 3) && this.track.Last <Point>().X != 4) { this.obstacles.Add(new Point(1, this.currentTrackY)); } else { this.obstacles.Add(Point.Zero); } this.lastNoiseValue = num3; } else { this.track.Add(new Point(Game1.random.Next(1, 3), this.currentTrackY)); this.ceiling.Add(new Point(Game1.random.Next(200), this.ceiling.Last <Point>().Y)); this.obstacles.Add(Point.Zero); this.lakeDecor.Add(new Point(Game1.random.Next(2), Game1.random.Next(this.ytileOffset + 1, this.screenHeight / this.tileSize))); } this.speedAccumulator = this.speedAccumulator % (float)this.tileSize; } double speedAccumulator2 = (double)this.lakeSpeedAccumulator; timeSpan = time.ElapsedGameTime; double num4 = (double)timeSpan.Milliseconds * ((double)this.speed / 4.0); this.lakeSpeedAccumulator = (float)(speedAccumulator2 + num4); if ((double)this.lakeSpeedAccumulator >= (double)this.tileSize) { this.lakeSpeedAccumulator = this.lakeSpeedAccumulator % (float)this.tileSize; this.lakeDecor.RemoveAt(0); this.lakeDecor.Add(new Point(Game1.random.Next(2), Game1.random.Next(this.ytileOffset + 3, this.screenHeight / this.tileSize))); } double backBgPosition = (double)this.backBGPosition; timeSpan = time.ElapsedGameTime; double num5 = (double)timeSpan.Milliseconds * ((double)this.speed / 5.0); this.backBGPosition = (float)(backBgPosition + num5); this.backBGPosition = this.backBGPosition % 96f; double midBgPosition = (double)this.midBGPosition; timeSpan = time.ElapsedGameTime; double num6 = (double)timeSpan.Milliseconds * ((double)this.speed / 4.0); this.midBGPosition = (float)(midBgPosition + num6); this.midBGPosition = this.midBGPosition % 96f; double waterFallPosition = (double)this.waterFallPosition; timeSpan = time.ElapsedGameTime; double num7 = (double)timeSpan.Milliseconds * ((double)this.speed * 6.0 / 5.0); this.waterFallPosition = (float)(waterFallPosition + num7); if ((double)this.waterFallPosition > (double)(this.screenWidth * 3 / 2)) { this.waterFallPosition = this.waterFallPosition % (float)(this.screenWidth * 3 / 2); this.waterfallWidth = Game1.random.Next(6); } } else { int respawnCounter = this.respawnCounter; timeSpan = time.ElapsedGameTime; int milliseconds = timeSpan.Milliseconds; this.respawnCounter = respawnCounter - milliseconds; this.mineCartYPosition = (float)num1; } if ((double)Math.Abs(this.mineCartYPosition - (float)num1) <= 6.0 && (double)this.minecartDY >= 0.0 && this.movingOnSlope == 0) { if ((double)this.minecartDY > 0.0) { this.mineCartYPosition = (float)num1; this.minecartDY = 0.0f; if (Game1.soundBank != null) { Game1.soundBank.GetCue("parry").Play(); this.minecartLoop = Game1.soundBank.GetCue("minecartLoop"); this.minecartLoop.Play(); } this.isJumping = false; this.reachedJumpApex = false; this.createSparkShower(); } if (this.track[6].X == 3) { this.movingOnSlope = 1; this.createSparkShower(); } else if (this.track[6].X == 4) { this.movingOnSlope = 2; this.createSparkShower(); } } else if (!this.isJumping && (double)Math.Abs(this.mineCartYPosition - (float)num1) <= 6.0 && (this.track[6].X == 3 || this.track[6].X == 4)) { this.mineCartYPosition = (float)num1; if ((double)this.mineCartYPosition == (double)num1 && this.track[6].X == 3) { this.movingOnSlope = 1; if (this.respawnCounter <= 0) { this.createSparkShower(Game1.random.Next(2)); } } else if ((double)this.mineCartYPosition == (double)num1 && this.track[6].X == 4) { this.movingOnSlope = 2; if (this.respawnCounter <= 0) { this.createSparkShower(Game1.random.Next(2)); } } this.minecartDY = 0.0f; } else { this.movingOnSlope = 0; this.minecartDY = this.minecartDY + (!this.reachedJumpApex && this.isJumping || (double)this.mineCartYPosition == (double)num1 ? 0.0f : 0.21f); if ((double)this.minecartDY > 0.0) { this.minecartDY = Math.Min(this.minecartDY, 9f); } if ((double)this.minecartDY > 0.0 || (double)this.minecartPositionBeforeJump - (double)this.mineCartYPosition <= (double)this.maxJumpHeight) { this.mineCartYPosition = this.mineCartYPosition + this.minecartDY; } } if ((double)this.minecartDY > 0.0 && this.minecartLoop != null && this.minecartLoop.IsPlaying) { this.minecartLoop.Stop(AudioStopOptions.Immediate); } if (this.reachedFinish) { double mineCartXoffset = (double)this.mineCartXOffset; double speed = (double)this.speed; timeSpan = time.ElapsedGameTime; double milliseconds = (double)timeSpan.Milliseconds; double num2 = speed * milliseconds; this.mineCartXOffset = (float)(mineCartXoffset + num2); if (Game1.random.NextDouble() < 0.25) { this.createSparkShower(); } } if ((double)this.mineCartXOffset > (double)(this.screenWidth - 6 * this.tileSize + this.tileSize)) { switch (this.gameMode) { case 0: double screenDarkness1 = (double)this.screenDarkness; timeSpan = time.ElapsedGameTime; double num8 = (double)timeSpan.Milliseconds / 2000.0; this.screenDarkness = (float)(screenDarkness1 + num8); if ((double)this.screenDarkness >= 1.0) { if (Game1.mine != null) { Game1.mine.mineLevel += 3; Game1.warpFarmer("UndergroundMine", 16, 16, false); Game1.fadeToBlackAlpha = 1f; } return(true); } break; case 3: double screenDarkness2 = (double)this.screenDarkness; timeSpan = time.ElapsedGameTime; double num9 = (double)timeSpan.Milliseconds / 2000.0; this.screenDarkness = (float)(screenDarkness2 + num9); if ((double)this.screenDarkness >= 1.0) { this.reachedFinish = false; this.currentTheme = (this.currentTheme + 1) % 6; this.levelsBeat = this.levelsBeat + 1; if (this.levelsBeat == 6) { if (!Game1.player.hasOrWillReceiveMail("JunimoKart")) { Game1.addMailForTomorrow("JunimoKart", false, false); } this.unload(); Game1.currentMinigame = (IMinigame)null; DelayedAction.playSoundAfterDelay("discoverMineral", 1000); Game1.drawObjectDialogue(Game1.content.LoadString("Strings\\StringsFromCSFiles:MineCart.cs.12106")); break; } this.setUpTheme(this.currentTheme); this.restartLevel(); break; } break; } } if ((double)this.speedAccumulator >= (double)(this.tileSize / 2) && ((int)((double)this.mineCartYPosition / (double)this.tileSize) == this.obstacles[7].Y || (int)((double)this.mineCartYPosition / (double)this.tileSize - (double)(this.tileSize - 1)) == this.obstacles[7].Y)) { switch (this.obstacles[7].X) { case 1: Game1.playSound("woodWhack"); this.mineCartYPosition = (float)this.screenHeight; break; case 2: Game1.playSound("money"); this.obstacles.RemoveAt(6); this.obstacles.Insert(6, Point.Zero); break; } } if ((double)this.mineCartYPosition > (double)this.screenHeight) { this.mineCartYPosition = -999999f; this.livesLeft = this.livesLeft - 1; Game1.playSound("fishEscape"); if (this.gameMode == 0 && (double)this.livesLeft < 0.0) { this.mineCartYPosition = 999999f; this.livesLeft = this.livesLeft + 1; double screenDarkness3 = (double)this.screenDarkness; timeSpan = time.ElapsedGameTime; double num2 = (double)timeSpan.Milliseconds * (1.0 / 1000.0); this.screenDarkness = (float)(screenDarkness3 + num2); if ((double)this.screenDarkness >= 1.0) { if (Game1.player.health > 1) { Game1.player.health = 1; Game1.drawObjectDialogue(Game1.content.LoadString("Strings\\StringsFromCSFiles:MineCart.cs.12108")); } else { Game1.player.health = 0; } return(true); } } else if (this.gameMode == 4 || this.gameMode == 3 && this.livesLeft < 0) { if (this.gameMode == 3) { this.levelsBeat = 0; this.setUpTheme(5); } this.restartLevel(); } else { this.respawnCounter = 1400; this.minecartDY = 0.0f; this.isJumping = false; this.reachedJumpApex = false; if (this.gameMode == 2) { this.totalMotion = 0; } } } this.minecartBumpOffset = Math.Max(0.0f, this.minecartBumpOffset - 0.5f); for (int index = this.sparkShower.Count - 1; index >= 0; --index) { this.sparkShower[index].dy += 0.105f; this.sparkShower[index].x += this.sparkShower[index].dx; this.sparkShower[index].y += this.sparkShower[index].dy; // ISSUE: explicit reference operation // ISSUE: variable of a reference type Color& local1 = @this.sparkShower[index].c; double num2 = 0.0; double val1_1 = 0.0; timeSpan = time.TotalGameTime; double val2_1 = Math.Sin((double)timeSpan.Milliseconds / (20.0 * Math.PI / (double)this.sparkShower[index].dx)) * (double)byte.MaxValue; double num3 = Math.Max(val1_1, val2_1); int num4 = (int)(byte)(num2 + num3); // ISSUE: explicit reference operation (^ local1).B = (byte)num4; if (this.reachedFinish) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Color& local2 = @this.sparkShower[index].c; double num5 = 0.0; double val1_2 = 0.0; timeSpan = time.TotalGameTime; double val2_2 = Math.Sin((double)(timeSpan.Milliseconds + 50) / (20.0 * Math.PI / (double)this.sparkShower[index].dx)) * (double)byte.MaxValue; double num6 = Math.Max(val1_2, val2_2); int num7 = (int)(byte)(num5 + num6); // ISSUE: explicit reference operation (^ local2).R = (byte)num7; // ISSUE: explicit reference operation // ISSUE: variable of a reference type Color& local3 = @this.sparkShower[index].c; double num10 = 0.0; double val1_3 = 0.0; timeSpan = time.TotalGameTime; double val2_3 = Math.Sin((double)(timeSpan.Milliseconds + 100) / (20.0 * Math.PI / (double)this.sparkShower[index].dx)) * (double)byte.MaxValue; double num11 = Math.Max(val1_3, val2_3); int num12 = (int)(byte)(num10 + num11); // ISSUE: explicit reference operation (^ local3).G = (byte)num12; if ((int)this.sparkShower[index].c.R == 0) { this.sparkShower[index].c.R = byte.MaxValue; } if ((int)this.sparkShower[index].c.G == 0) { this.sparkShower[index].c.G = byte.MaxValue; } } if ((double)this.sparkShower[index].y > (double)this.screenHeight) { this.sparkShower.RemoveAt(index); } } return(false); }
/// <summary> /// Initializes terrain. /// Applies Noise function to map the height. /// Random by default but will produce same results if seed is provided. /// </summary> private void InitTerrain() { NoiseGenerator generator; if (this.seed == null) { generator = new NoiseGenerator(70, 4, 0.2f, null); } else { generator = new NoiseGenerator(70, 4, 0.2f, (uint)this.seed.Value); } int vertexCount = 128; int count = vertexCount * vertexCount; this.heights = new float[vertexCount, vertexCount]; float[] vertices = new float[count * 3]; float[] normals = new float[count * 3]; float[] textureCoords = new float[count * 2]; this.indices = new int[6 * (vertexCount - 1) * (vertexCount - 1)]; int vertexPointer = 0; for (int i = 0; i < vertexCount; i++) { for (int j = 0; j < vertexCount; j++) { // Position vertices[vertexPointer * 3] = (float)j / ((float)vertexCount - 1) * Size; float height = this.GetHeight(j, i, generator); vertices[(vertexPointer * 3) + 1] = height; this.heights[j, i] = height; vertices[(vertexPointer * 3) + 2] = (float)i / ((float)vertexCount - 1) * Size; // Normals Vector3 normal = this.CalculateNormal(j, i, generator); normals[vertexPointer * 3] = normal.X; normals[(vertexPointer * 3) + 1] = normal.Y; normals[(vertexPointer * 3) + 2] = normal.Z; // Texture Coords textureCoords[vertexPointer * 2] = (float)j / ((float)vertexCount - 1) * Size; textureCoords[(vertexPointer * 2) + 1] = (float)i / ((float)vertexCount - 1) * Size; vertexPointer++; } } int pointer = 0; for (int gz = 0; gz < vertexCount - 1; gz++) { for (int gx = 0; gx < vertexCount - 1; gx++) { int topLeft = (gz * vertexCount) + gx; int topRight = topLeft + 1; int bottomLeft = ((gz + 1) * vertexCount) + gx; int bottomRight = bottomLeft + 1; this.indices[pointer++] = topLeft; this.indices[pointer++] = bottomLeft; this.indices[pointer++] = topRight; this.indices[pointer++] = topRight; this.indices[pointer++] = bottomLeft; this.indices[pointer++] = bottomRight; } } this.terrainVertices = new VertexPositionNormalTexture[count]; for (int i = 0; i < count; i++) { float posX = vertices[i * 3]; float posY = vertices[i * 3 + 1]; float posZ = vertices[i * 3 + 2]; this.terrainVertices[i].Position = new Vector3(posX, posY, posZ); float normX = normals[i * 3]; float normY = normals[i * 3 + 1]; float normZ = normals[i * 3 + 2]; this.terrainVertices[i].Normal = new Vector3(normX, normY, normZ); float textureX = textureCoords[i * 2]; float textureY = textureCoords[i * 2 + 1]; this.terrainVertices[i].TextureCoordinate = new Vector2(textureX, textureY); } this.effect = new BasicEffect(this.device); this.effect.TextureEnabled = true; this.effect.Texture = this.texture; // Light green this.effect.SpecularColor = Color.LightGreen.ToVector3() / 5f; this.effect.SpecularPower = 30; Light.Sunlight(this.effect, this.effect.SpecularColor); // Very light green this.effect.AmbientLightColor = Color.LightGreen.ToVector3() / 15f; this.effect.PreferPerPixelLighting = true; this.effect.FogEnabled = true; this.effect.FogStart = FogStart; this.effect.FogEnd = FogEnd; this.effect.FogColor = FogColor; }
//Initialize all variables to their default values public override void Initialize() { modtimer = 0; Instance = this; Tiles.Monolith.CelestialMonolithTE.ResetTEs(); if (Dimensions.SGAPocketDim.WhereAmI == null) { downedSpaceBoss = false; } if (SGAmod.cachedata == false) { portalcanmovein = false; oretypesprehardmode = new int[4] { TileID.Copper, TileID.Iron, TileID.Silver, TileID.Gold }; oretypeshardmode = new int[3] { TileID.Cobalt, TileID.Mythril, TileID.Adamantite }; NightmareHardcore = 0; dungeonlevel = 0; //highestDimDungeonFloor = 0; Main.invasionSize = 0; customInvasionUp = false; downedCustomInvasion = false; downedSPinky = false; downedTPD = false; downedSpiderQueen = false; downedHarbinger = false; downedWraiths = 0; downedMurk = 0; craftwarning = 0; tidalCharmUnlocked = false; GennedVirulent = false; downedMurklegacy = false; downedCaliburnGuardians = 0; downedCaliburnGuardiansPoints = 0; downedCaliburnGuardianHardmode = false; downedCirno = false; downedSharkvern = false; darknessVision = false; overalldamagedone = 0; downedCratrosity = false; downedCratrosityPML = false; downedHellion = 0; sharkvernMessage = false; downedPrismBanshee = 0; tf2cratedrops = false; tf2quest = 0; bossprgressor = 0; SnapCooldown = 0; WorldIsNovus = true; for (int f = 0; f < CaliburnAlterCoordsX.Length; f++) { CaliburnAlterCoordsX[f] = 0; CaliburnAlterCoordsY[f] = 0; } WorldIsTin = WorldGen.oreTier1 != TileID.Copper; int x = 0; for (x = 0; x < questvars.Length; x++) { questvars[x] = 0; } if (!Main.dedServ) { Item c0decrown = new Item(); c0decrown.SetDefaults(mod.ItemType("CelestialCrown")); Main.armorHeadLoaded[c0decrown.headSlot] = true; Main.armorHeadTexture[c0decrown.headSlot] = SGAmod.RadSuitHeadTex; } } WorldNoise = new NoiseGenerator(Main.worldName.GetHashCode()); WorldNoise.Amplitude = 1; WorldNoise.Octaves = 4; WorldNoise.Persistence = 0.750; WorldNoise.Frequency *= 1.25; SGAmod.cachedata = false; }
/// <summary> /// Gets the height at the specified position on the terrain /// </summary> /// <param name="x"> /// The x coordinate /// </param> /// <param name="z"> /// The z coordinate /// </param> /// <param name="generator"> /// The perlin noise height generator /// </param> /// <returns> /// The <see cref="float"/>. /// </returns> private float GetHeight(int x, int z, NoiseGenerator generator) { return(generator.GenerateNoise(x, z)); }
void OnEnable() { noise = (NoiseGenerator)target; }
private void OnValidate() { fallOffMap = NoiseGenerator.GenerateFalloffMap(chunkSize, settings.falloffDistance, settings.falloffHardness); }
public void GenerateVegetation(VoxelChunk chunk, ComponentManager components, ContentManager content, GraphicsDevice graphics) { int waterHeight = (int)(SeaLevel * chunk.SizeY); bool updated = false; Voxel v = chunk.MakeVoxel(0, 0, 0); Voxel vUnder = chunk.MakeVoxel(0, 0, 0); for (int x = 0; x < chunk.SizeX; x++) { for (int z = 0; z < chunk.SizeZ; z++) { Vector2 vec = new Vector2(x + chunk.Origin.X, z + chunk.Origin.Z) / PlayState.WorldScale; Overworld.Biome biome = Overworld.Map[(int)MathFunctions.Clamp(vec.X, 0, Overworld.Map.GetLength(0) - 1), (int)MathFunctions.Clamp(vec.Y, 0, Overworld.Map.GetLength(1) - 1)].Biome; BiomeData biomeData = BiomeLibrary.Biomes[biome]; int y = chunk.GetFilledVoxelGridHeightAt(x, chunk.SizeY - 1, z); if (!chunk.IsCellValid(x, (int)(y - chunk.Origin.Y), z)) { continue; } v.GridPosition = new Vector3(x, y, z); if (!v.IsEmpty || chunk.Data.Water[v.Index].WaterLevel != 0 || y <= waterHeight) { continue; } foreach (VegetationData veg in biomeData.Vegetation) { if (y <= 0) { continue; } if (!MathFunctions.RandEvent(veg.SpawnProbability)) { continue; } if (NoiseGenerator.Noise(vec.X / veg.ClumpSize, veg.NoiseOffset, vec.Y / veg.ClumpSize) < veg.ClumpThreshold) { continue; } int yh = chunk.GetFilledVoxelGridHeightAt(x, y, z); if (yh > 0) { vUnder.GridPosition = new Vector3(x, yh - 1, z); if (!vUnder.IsEmpty && vUnder.TypeName == biomeData.GrassVoxel) { vUnder.Type = VoxelLibrary.GetVoxelType(biomeData.SoilVoxel); updated = true; float offset = veg.VerticalOffset; if (vUnder.RampType != RampType.None) { offset -= 0.25f; } float treeSize = MathFunctions.Rand() * veg.SizeVariance + veg.MeanSize; EntityFactory.CreateEntity <Body>(veg.Name, chunk.Origin + new Vector3(x, y, z) + new Vector3(0, treeSize * offset, 0), Blackboard.Create("Scale", treeSize)); } } break; } } } if (updated) { chunk.ShouldRebuild = true; } }
IEnumerator GetSamplesAsync(SampleRegion i) { NoiseOptions options = NoiseConfig.options[i.options]; NoiseOptions drift = new NoiseOptions(); if (options.driftMapId != -1) { drift = NoiseConfig.options[options.driftMapId]; } int h_rate = 2; if (Config.Interpolation == InterpolationLevel.Off) { h_rate = 1; } int sampleX = (i.region.sizeX / (i.sampleRate * h_rate)) + 1; int sampleY = (i.region.sizeY / i.sampleRate) + 1; int sampleZ = (i.region.sizeZ / (i.sampleRate * h_rate)) + 1; if (i.samples == null || i.samples.Length != sampleX * sampleY * sampleZ) { i.samples = new float[sampleX, sampleY, sampleZ]; } for (int z = 0; z < sampleZ; z++) { for (int x = 0; x < sampleX; x++) { Vector2 location = new Vector2 ( (x * i.sampleRate + (i.region.min.x / 2f)) * i.zoom.x, (z * i.sampleRate + (i.region.min.z / 2f)) * i.zoom.z ); float driftMap = 0f; if (options.driftMapId != -1) { driftMap = NoiseGenerator.Sum ( NoiseConfig.driftMapMethod, location, drift.frequency.value, drift.octaves, drift.lacunarity, drift.persistance ); } for (int y = 0; y < sampleY; y++) { // x and z are calculated above Vector3 position = new Vector3 ( location.x, (y * i.sampleRate + i.region.min.y) * i.zoom.y, location.y ); // with drift i.samples[x, y, z] = NoiseGenerator.Sum( i.method, position, options.drift != 0f ? Mathf.Lerp( options.frequency.value, driftMap > 0f ? options.frequency.max * options.driftScale : options.frequency.min, Mathf.Abs(driftMap)) : options.frequency.value, options.octaves, options.lacunarity, options.persistance ); } } } i.sampled = true; yield return(null); }
static Quaternion NoiseRotation(NoiseGenerator ng, int seed, Vector3 angles) { return(ng.Rotation(seed, angles.x, angles.y, angles.z)); }
protected double Noise(double x) { return(NoiseGenerator.Generate(x)); }
public static float GetAbundance(AbundanceRequest request) { try { var northing = Utilities.Deg2Rad(Utilities.fixLat(request.Latitude)); var easting = Utilities.Deg2Rad(Utilities.fixLong(request.Longitude)); var body = FlightGlobals.Bodies.FirstOrDefault(b => b.flightGlobalsIndex == request.BodyId); var biome = Utilities.GetBiome(northing, easting, body); var seed = GenerateAbundanceSeed(request, biome, body); var biomeName = GetDefaultSituation(request.ResourceType); if (biome != null) { biomeName = biome.name; } //We need to determine our data set for randomization. //Is there biome data? DistributionData distro = null; var biomeConfigs = BiomeResources.Where( r => r.PlanetName == body.bodyName && r.BiomeName == biomeName && r.ResourceName == request.ResourceName && r.ResourceType == (int)request.ResourceType).ToList(); var planetConfigs = PlanetaryResources.Where( r => r.PlanetName == body.bodyName && r.ResourceName == request.ResourceName && r.ResourceType == (int)request.ResourceType).ToList(); var globalConfigs = GlobalResources.Where( r => r.ResourceName == request.ResourceName && r.ResourceType == (int)request.ResourceType).ToList(); //Extrapolate based on matching overrides if (biomeConfigs.Any()) { distro = GetBestResourceData(biomeConfigs); seed *= 2; } else if (planetConfigs.Any()) { distro = GetBestResourceData(planetConfigs); seed *= 3; } else if (globalConfigs.Any()) { distro = GetBestResourceData(globalConfigs); seed *= 4; } else { return 0f; } var rand = new Random(seed); //Our Simplex noise: var noiseSeed = new int[8]; for (var ns = 0; ns < 8; ns++) { noiseSeed[ns] = rand.Next(); } var spx = new NoiseGenerator(noiseSeed); var noiseX = (float) northing * distro.Variance / 10f; var noiseY = (float)easting * distro.Variance / 10f; var noiseZ = (rand.Next(100)) / 100f; var noise = spx.noise(noiseX, noiseY, noiseZ); var presenceRoll = rand.Next(100); var isPresent = (presenceRoll <= distro.PresenceChance); if (!isPresent) return 0f; //Abundance begins with a starting range. var min = (int)(distro.MinAbundance * 1000); var max = (int)(distro.MaxAbundance * 1000); //In case someone is silly if (min > max) max = min + 1; var abundance = (rand.Next(min, max))/1000f; var baseAbuncance = abundance; var minAbundance = Math.Max(0.01f,min)/1000f; //Applies to all but interplanetary if (request.ResourceType != HarvestTypes.Interplanetary) { //Lets add some noise... float swing = abundance*(distro.Variance/100f); abundance = abundance - swing + (swing*noise*2); //You should only be able to hit zero if someohe sets their //variance >= 100 if (abundance < 0) abundance = 0; } //Altitude band - only applies to atmospheric and interplanetary if ( (request.ResourceType == HarvestTypes.Atmospheric || request.ResourceType == HarvestTypes.Interplanetary) && distro.HasVariableAltitude()) { var rad = body.Radius; var ideal = ((rad*distro.MinAltitude) + (rad*distro.MaxAltitude))/2; //print("REGO: IDEAL = " + ideal); var range = rand.Next((int)(rad * distro.MinRange), (int)(rad * distro.MaxRange)); var diff = Math.Abs(ideal - request.Altitude); var rangePerc = diff / range; var modifier = 1d - rangePerc; abundance *= (float)modifier; } if (abundance <= Utilities.FLOAT_TOLERANCE) return 0f; //Now for our return scenarios. var trueAbundance = abundance / 100; baseAbuncance = baseAbuncance / 100; minAbundance = minAbundance / 100; //Biome unlocked or no lock check if (!request.CheckForLock || RegolithScenario.Instance.gameSettings.IsBiomeUnlocked(request.BodyId, biomeName)) { return trueAbundance; } //Planet unlocked else if (RegolithScenario.Instance.gameSettings.IsPlanetUnlocked(request.BodyId)) { return baseAbuncance; } //Default is just our basic data else { return minAbundance; } } catch (Exception e) { print("[REGO] - Error in - RegolithResourceMap_GetAbundance - " + e.Message); return 0f; } }
private NoiseGenerator InitializeTerrainSpawners(int width, int height) { var generator = new NoiseGenerator(seed, width, height); generator.Settings.Frequency = 0.01; generator.Settings.Persistence = 0.85; generator.Settings.Octaves = 8; generator.Settings.Amplitude = 0.5; generator.Settings.CloudCoverage = 1.25; generator.Settings.CloudDensity = 0.36; //generator.Settings.Frequency = 0.008; //generator.Settings.Persistence = 1; //generator.Settings.Octaves = 8; //generator.Settings.Amplitude = 1; //generator.Settings.CloudCoverage = 3; //generator.Settings.CloudDensity = 0.125; return generator; }
public void GenerateCaves(VoxelChunk chunk, WorldManager world) { Vector3 origin = chunk.Origin; BiomeData biome = BiomeLibrary.GetBiome("Cave"); for (int x = 0; x < VoxelConstants.ChunkSizeX; x++) { for (int z = 0; z < VoxelConstants.ChunkSizeZ; z++) { var topVoxel = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle( chunk, new LocalVoxelCoordinate(x, VoxelConstants.ChunkSizeY - 1, z))); for (int i = 0; i < CaveLevels.Count; i++) { int y = CaveLevels[i]; if (y <= 0 || y >= topVoxel.Coordinate.Y) { continue; } Vector3 vec = new Vector3(x, y, z) + chunk.Origin; double caveNoise = CaveNoise.GetValue((x + origin.X) * CaveNoiseScale * CaveFrequencies[i], (y + origin.Y) * CaveNoiseScale * 3.0f, (z + origin.Z) * CaveNoiseScale * CaveFrequencies[i]); double heightnoise = NoiseGenerator.Noise((x + origin.X) * NoiseScale * CaveFrequencies[i], (y + origin.Y) * NoiseScale * 3.0f, (z + origin.Z) * NoiseScale * CaveFrequencies[i]); int caveHeight = Math.Min(Math.Max((int)(heightnoise * 5), 1), 3); if (!(caveNoise > CaveSize)) { continue; } bool invalidCave = false; for (int dy = 0; dy < caveHeight; dy++) { if (y - dy <= 0) { continue; } var voxel = new VoxelHandle(chunk, new LocalVoxelCoordinate(x, y - dy, z)); foreach (var coord in VoxelHelpers.EnumerateAllNeighbors(voxel.Coordinate)) { VoxelHandle v = new VoxelHandle(Manager.ChunkData, coord); if (v.IsValid && (v.WaterCell.WaterLevel > 0 || v.SunColor > 0)) { invalidCave = true; break; } } if (!invalidCave) { voxel.RawSetType(VoxelLibrary.emptyType); } else { break; } } if (!invalidCave && caveNoise > CaveSize * 1.8f && y - caveHeight > 0) { GenerateCaveVegetation(chunk, x, y, z, caveHeight, biome, vec, world, NoiseGenerator); GenerateCaveFauna(chunk, world, biome, y - caveHeight, x, z); } } } } /* * // Second pass sets the caves to empty as needed * for (int x = 0; x < VoxelConstants.ChunkSizeX; x++) * { * for (int y = 0; y < VoxelConstants.ChunkSizeY; y++) * { * for (int z = 0; z < VoxelConstants.ChunkSizeZ; z++) * { * VoxelHandle handle = new VoxelHandle(chunk, new LocalVoxelCoordinate(x, y, z)); * if (handle.Type == magicCube) * { * handle.RawSetType(VoxelLibrary.emptyType); * } * } * } * } */ }
public VoxelChunk GenerateChunk(Vector3 origin, WorldManager World) { float waterHeight = SeaLevel + 1.0f / VoxelConstants.ChunkSizeY; VoxelChunk c = new VoxelChunk(Manager, origin, GlobalVoxelCoordinate.FromVector3(origin).GetGlobalChunkCoordinate()); for (int x = 0; x < VoxelConstants.ChunkSizeX; x++) { for (int z = 0; z < VoxelConstants.ChunkSizeZ; z++) { Vector2 v = new Vector2(x + origin.X, z + origin.Z) / WorldScale; var biome = Overworld.Map[(int)MathFunctions.Clamp(v.X, 0, Overworld.Map.GetLength(0) - 1), (int)MathFunctions.Clamp(v.Y, 0, Overworld.Map.GetLength(1) - 1)].Biome; BiomeData biomeData = BiomeLibrary.Biomes[biome]; Vector2 pos = new Vector2(x + origin.X, z + origin.Z) / WorldScale; float hNorm = Overworld.LinearInterpolate(pos, Overworld.Map, Overworld.ScalarFieldType.Height); float h = MathFunctions.Clamp(hNorm * VoxelConstants.ChunkSizeY, 0.0f, VoxelConstants.ChunkSizeY - 2); int stoneHeight = (int)(MathFunctions.Clamp((int)(h - (biomeData.SoilLayer.Depth + (Math.Sin(v.X) + Math.Cos(v.Y)))), 1, h)); int currentSubsurfaceLayer = 0; int depthWithinSubsurface = 0; for (int y = VoxelConstants.ChunkSizeY - 1; y >= 0; y--) { var voxel = new VoxelHandle(c, new LocalVoxelCoordinate(x, y, z)); if (y == 0) { voxel.RawSetType(VoxelLibrary.GetVoxelType("Bedrock")); voxel.Health = 255; // ? continue; } if (y <= stoneHeight && stoneHeight > 1) { voxel.RawSetType(VoxelLibrary.GetVoxelType(biomeData.SubsurfaceLayers[currentSubsurfaceLayer].VoxelType)); depthWithinSubsurface++; if (depthWithinSubsurface > biomeData.SubsurfaceLayers[currentSubsurfaceLayer].Depth) { depthWithinSubsurface = 0; currentSubsurfaceLayer++; if (currentSubsurfaceLayer > biomeData.SubsurfaceLayers.Count - 1) { currentSubsurfaceLayer = biomeData.SubsurfaceLayers.Count - 1; } } } else if ((y == (int)h || y == stoneHeight) && hNorm > waterHeight) { if (biomeData.ClumpGrass && NoiseGenerator.Noise(pos.X / biomeData.ClumpSize, 0, pos.Y / biomeData.ClumpSize) > biomeData.ClumpTreshold) { voxel.RawSetType(VoxelLibrary.GetVoxelType(biomeData.SoilLayer.VoxelType)); if (!String.IsNullOrEmpty(biomeData.GrassDecal)) { var decal = GrassLibrary.GetGrassType(biomeData.GrassDecal); voxel.RawSetGrass(decal.ID); } } else if (!biomeData.ClumpGrass) { voxel.RawSetType(VoxelLibrary.GetVoxelType(biomeData.SoilLayer.VoxelType)); if (!String.IsNullOrEmpty(biomeData.GrassDecal)) { var decal = GrassLibrary.GetGrassType(biomeData.GrassDecal); voxel.RawSetGrass(decal.ID); } } else { voxel.RawSetType(VoxelLibrary.GetVoxelType(biomeData.SoilLayer.VoxelType)); } } else if (y > h && y > 0) { voxel.RawSetType(VoxelLibrary.emptyType); } else if (hNorm <= waterHeight) { voxel.RawSetType(VoxelLibrary.GetVoxelType(biomeData.ShoreVoxel)); } else { voxel.RawSetType(VoxelLibrary.GetVoxelType(biomeData.SoilLayer.VoxelType)); } } } } GenerateWater(c); GenerateLava(c); UpdateSunlight(c, 255); return(c); }
void UpdateMaps() { altitudeMapGen = FindObjectOfType <AltitudeMap> (); noiseGen = FindObjectOfType <NoiseGenerator> (); altitudeMapGen.UpdateMap(); }
public void GenerateSurfaceLife(VoxelChunk Chunk) { var waterHeight = (int)(SeaLevel * VoxelConstants.ChunkSizeY); for (var x = 0; x < VoxelConstants.ChunkSizeX; ++x) { for (var z = 0; z < VoxelConstants.ChunkSizeZ; ++z) { var biomeData = GetBiomeAt(new Vector2(x + Chunk.Origin.X, z + Chunk.Origin.Z)); var topVoxel = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle( Chunk, new LocalVoxelCoordinate(x, VoxelConstants.ChunkSizeY - 1, z))); if (!topVoxel.IsValid || topVoxel.Coordinate.Y == 0 || topVoxel.Coordinate.Y >= 60) // Lift to some kind of generator settings? { continue; } var above = VoxelHelpers.GetVoxelAbove(topVoxel); if (above.IsValid && above.WaterCell.WaterLevel != 0) { continue; } foreach (var animal in biomeData.Fauna) { if (MathFunctions.RandEvent(animal.SpawnProbability)) { EntityFactory.CreateEntity <Body>(animal.Name, topVoxel.WorldPosition + Vector3.Up * 1.5f); break; } } if (topVoxel.Type.Name != biomeData.SoilLayer.VoxelType) { continue; } foreach (VegetationData veg in biomeData.Vegetation) { if (topVoxel.GrassType == 0) { continue; } if (MathFunctions.RandEvent(veg.SpawnProbability) && NoiseGenerator.Noise(topVoxel.Coordinate.X / veg.ClumpSize, veg.NoiseOffset, topVoxel.Coordinate.Z / veg.ClumpSize) >= veg.ClumpThreshold) { topVoxel.RawSetType(VoxelLibrary.GetVoxelType(biomeData.SoilLayer.VoxelType)); var treeSize = MathFunctions.Rand() * veg.SizeVariance + veg.MeanSize; var tree = EntityFactory.CreateEntity <Plant>(veg.Name, topVoxel.WorldPosition + new Vector3(0.5f, 1.0f, 0.5f), Blackboard.Create("Scale", treeSize)); break; } } } } }