/// <summary> /// Updates the <see cref="Generator"/> assigned to this instance based on the /// set <see cref="MapGeneratorType"/> and returns it. /// </summary> /// <returns>Generator if set, null if <see cref="MapGeneratorType.Custom"/> /// is set and no <see cref="CustomGenerator"/> is specified</returns> public void UpdateGenerator() { int seed = TerraConfig.GenerationSeed; Generator gen; switch (MapType) { case MapGeneratorType.Perlin: gen = new GradientNoise(seed).ScaleShift(0.5f, 0.5f); break; case MapGeneratorType.Fractal: gen = new PinkNoise(seed).ScaleShift(0.5f, 0.5f); break; case MapGeneratorType.Billow: gen = new BillowNoise(seed).ScaleShift(0.5f, 0.5f); break; case MapGeneratorType.Custom: if (Graph == null) { return; } gen = Graph.GetEndGenerator(); break; default: return; } _generator = gen; }
float GetNoiseValue(Vector3 square) { float noiseF = 0.0f; switch (m_Noise) { case NOISE.GRADIENT: //dont do this, init it only once! GradientNoise gnoise = new GradientNoise(m_Seed); //noise scale is for how fine graded the noise is. //we need a combination between fine and rough noise noiseF = gnoise.GetValue(square.y * m_NoiseScale, square.x * m_NoiseScale, square.z * m_NoiseScale); break; case NOISE.SIMPLEX: noiseF = ((float)Simplex.Noise.CalcPixel3D((int)(square.x * m_NoiseScale), (int)(square.y * m_NoiseScale), (int)(square.z * m_NoiseScale), 1.0f) * (1.0f / 256.0f) - 0.5f) * 2.0f; break; case NOISE.PERLIN: noiseF = noiseF = GetPerlinNoise(square.x * m_NoiseScale, square.y * m_NoiseScale, square.z * m_NoiseScale); break; } return(noiseF); }
// Use this for initialization void Start() { TreeBuilder = Instantiate(TreeBuilding); range [1] = new int[] { y_min, y_max }; if (size <= 0) { size = 10; } //Generator s = new ValueNoise(Random.Range (-9000, 9000), null); //int [] [] r = {new int[] {-size,size}, new int[] {-min,max}, new int[] {-size,size}}; //range = r; Generator s = new GradientNoise(UnityEngine.Random.Range(-9000, 9000)); a = new CubeThreader(cubeSize, s, range, surface, size, equilibrium, max, min, caves); //Creates numCubes new marching cubes and adds them to the list for (int i = -4; i < 5; i++) { for (int j = -4; j < 5; j++) { //Each cube should have a range of 30x30, with the cubes centered appropriately based on cubeNumber //Height limits can be changed but for now are constant //Range is not shifting properly when multiplied by i and j, it doent change inside range //This enures a square of cubes centered around the origin. Vector2 p = new Vector2(i, j); cubes.Add(p, false); a.addCubes(p); } } a.Run(); int count = 0; foreach (Vector2 posit in cubes.Keys) { if ((bool)cubes[posit] == false) { StartCoroutine(cube_Gen(posit)); } } //this.GetComponent<MeshRenderer> ().material.SetColor ("_Color", Color.red); StartCoroutine(wait()); //InvokeRepeating ("CheckAround", 10.0f, .5f); perlinNoises = a.noises; }