public override void OnUpdate(float elapsed) { if (GetKey(Key.Enter).Pressed) { time = 0; dir = true; Noise.Seed(); } time += 0.01f * (dir ? 1 : -1); if (time <= 0 || time >= 360) { dir = !dir; } for (int i = 0; i < ScreenWidth; i++) { for (int j = 0; j < ScreenHeight; j++) { float x = (float)i / ScreenWidth; float y = (float)j / ScreenWidth; float noise = Noise.Calculate(x, y, time); noise = noise / 2 + 1; Pixel p = Pixel.FromHsv(noise * time * 360, noise, noise * 0.8f); Draw(i, j, p); } } }
// Use this for initialization void OnEnable() { EdgeCollider2D collider = GetComponent <EdgeCollider2D> (); LineRenderer lr = GetComponent <LineRenderer> (); Vector2[] Points = new Vector2[PlanetVertexCount + Overdraw]; lr.positionCount = (PlanetVertexCount + Overdraw); for (int i = 0; i < PlanetVertexCount + Overdraw; i++) { Points [i] = RotateVector(new Vector2(0, Height + Noises.Sum((Noise) => Noise.Calculate(i))), (360f * i) / PlanetVertexCount + 180f) * 0.5f; lr.SetPosition(i, Points [i]); } collider.points = Points; }
/*void OnValidate(){ * GenerateMesh(); * }*/ void GenerateMesh() { if (resolution == 0) { return; } //var verticesTwo = new List<Vector3>(); var colors = new List <Color>(); var triangles = new List <int>(); var trianglesTwo = new List <int>(); var trianglesAll = new List <int>(); var vertices = new List <Vector3>(); var verticesCollider = new List <Vector3>(); var axisA = new Vector3(Vector3.up.y, Vector3.up.z, Vector3.up.x); var axisB = Vector3.Cross(Vector3.up, axisA); noise = new Noise(noiseSettings); circularGradient = new CircularGradient(new Vector3(size / 2, 0, size / 2), circularGradientSettings); colorGenerator = new ColorGenerator(colorSettings); detailsGenerator = new DetailsGenerator(detailsSettings, size, new Vector2(0, -(size * 2))); detailPoints = detailsGenerator.ComputedPoints(); //Debug.Log(detailPoints[0].Length); int i = 0; for (int z = 0; z < size; z++) { for (int x = 0; x < size; x++) { Vector3 sercent = new Vector3((float)x / size - 1, 0, (float)z / size - 1); float elevation = noise.Calculate(sercent.x + seed, sercent.z + seed) * circularGradient.Calculate(x, z); float elevationNormalized = Mathf.Clamp01(elevation / (noiseSettings.rougness + circularGradientSettings.rougness)); colors.Add(colorGenerator.Calculate(elevationNormalized)); Vector3 point = Vector3.up + (x - .5f) * 2 * axisA + (z - .5f) * 2 * axisB; point.y = elevation; verticesCollider.Add(point); point.y += Random.Range(-1f, 1f) * lowPolyEffect; point.x += Random.Range(-1f, 1f) * lowPolyEffect; point.z += Random.Range(-1f, 1f) * lowPolyEffect; vertices.Add(point); //verticesTwo.Add(point); i++; } } i = 0; for (int z = 0; z < size; z++) { for (int x = 0; x < size; x++) { if (x != size - 1 && z != size - 1) { triangles.Add(i); triangles.Add(i + size + 1); triangles.Add(i + size); // triangles.Add(i); // triangles.Add(i+1); // triangles.Add(i+size+1); trianglesTwo.Add(i); trianglesTwo.Add(i + 1); trianglesTwo.Add(i + size + 1); } i++; } } islandMesh.GenerateMesh(vertices.ToArray(), triangles.ToArray(), colors.ToArray()); islandMesh2.GenerateMesh(vertices.ToArray(), trianglesTwo.ToArray(), colors.ToArray()); trianglesAll.AddRange(triangles); trianglesAll.AddRange(trianglesTwo); if (!meshCollider.sharedMesh) { meshCollider.sharedMesh = new Mesh(); } var colliderMesh = meshCollider.sharedMesh; colliderMesh.vertices = verticesCollider.ToArray(); colliderMesh.triangles = trianglesAll.ToArray(); colliderMesh.RecalculateNormals(); meshCollider.sharedMesh = colliderMesh; navMeshSurface.BuildNavMesh(); }