void Awake() { // Create random points int n = seed; points = new List <Vec3>(); switch (usedGenerator) { case Generator.Halton: for (int i = 0; i < pointNumber; i++) { // Random sparse distribution Vec3 temp = HaltonSequence.Halton2D(n, bases[0], bases[1]); points.Add(new Vec3(temp.X * boundaries[0] + transform.position.x, temp.Y * boundaries[1] + transform.position.y, transform.position.z)); n++; } break; case Generator.Poisson: RandGen.Init(seed); poissonGen = new PoissonDisk2D(minimalDistance, boundaries[0], boundaries[1], maxAttemp); poissonGen.BuildSample(pointNumber); foreach (Vec3 point in poissonGen) { points.Add(point); } break; default: throw new NotImplementedException(); } // Place camera var cam = Camera.main; cam.transform.position = new Vector3(boundaries[0] / 2.0f, boundaries[1] / 2.0f, -0.8f * Mathf.Max(boundaries)); }
// Use this for initialization void Awake() { RandGen.Init(seed); if (dim == Dimension.Two) { generator2D = new PoissonDisk2D(minimalDistance, boundaries[0], boundaries[1], maxAttemp); } else { generator3D = new PoissonDisk3D(minimalDistance, boundaries[0], boundaries[1], boundaries[2], maxAttemp); } // Place camera var cam = Camera.main; cam.transform.position = new Vector3(boundaries[0] / 2.0f, boundaries[1] / 2.0f, -0.8f * Mathf.Max(boundaries)); }
void Start() { // BUILDING --- --- BUILDING --- --- BUILDING System.DateTime previousTime = System.DateTime.Now; var points = new List <Vec3>(); int n = seed; RandGen.Init(seed); switch (usedGenerator) { case Generator.Halton: points = SphereSampler.Halton(pointNumber, seed, bases[0], bases[1]).ToList(); break; case Generator.Uniform: for (int i = 0; i < pointNumber; i++) { double phi = 2.0 * System.Math.PI * RandGen.NextDouble(); double theta = System.Math.Acos(2.0 * RandGen.NextDouble() - 1.0); points.Add(Geometry.SphericalToEuclidean(phi, theta)); n++; } break; case Generator.Fibonnaci: // points = SphereSampler.Fibonnaci(pointNumber, 0.8).ToList(); points = SphereSampler.Fibonnaci(pointNumber).ToList(); break; case Generator.Poisson: points = SphereSampler.Poisson(pointNumber, 0.1f).ToList(); Debug.Log(points.Count); break; } System.TimeSpan delta = System.DateTime.Now - previousTime; Debug.Log(string.Format("BUILDING *** {0} secondes OU {1} milliseconds *** BUILDING", delta.TotalSeconds, delta.TotalMilliseconds)); Debug.Log("Total generated points: " + points.Count); if (triangulate) { // INIT --- --- INIT --- --- INIT previousTime = System.DateTime.Now; sphereMeshUsed = new SphericalMesh <int, int>(points.Select(x => Geometry.StereographicProjection(x)).ToArray(), false); delta = System.DateTime.Now - previousTime; Debug.Log("***"); Debug.Log(string.Format("*** INIT *** {0} secondes OU {1} milliseconds *** INIT", delta.TotalSeconds, delta.TotalMilliseconds)); // TRIANGULATION --- --- TRIANGULATION --- --- TRIANGULATION previousTime = System.DateTime.Now; sphereMeshUsed.Construct(); delta = System.DateTime.Now - previousTime; Debug.Log("***"); Debug.Log(string.Format("*** TRIANGULATION *** {0} secondes OU {1} milliseconds *** TRIANGULATION", delta.TotalSeconds, delta.TotalMilliseconds)); // // START DEBUGTOOLS // // START DEBUGTOOLS // // START DEBUGTOOLS // var test = radius * sphereMeshUsed.RightMostEdge.Rot.Origin; // if (triangulationOnSphere) // { // test = radius * Geometry.InvStereographicProjection(sphereMeshUsed.RightMostEdge.Rot.Origin); // } // var newGo = GameObject.Instantiate(shape); // newGo.transform.SetParent(transform); // newGo.transform.position = test.AsVector3(); // newGo.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); // // Color // var meshR = newGo.GetComponent<MeshRenderer>(); // if (meshR != null) // { // meshR.materials[0].color = Color.blue; // } // var test2 = radius * sphereMeshUsed.RightMostEdge.Destination; // if (triangulationOnSphere) // { // test2 = radius * Geometry.InvStereographicProjection(sphereMeshUsed.RightMostEdge.Destination); // } // var newGo2 = GameObject.Instantiate(shape); // newGo2.transform.SetParent(transform); // newGo2.transform.position = test2.AsVector3(); // newGo2.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); // // Color // var meshR2 = newGo2.GetComponent<MeshRenderer>(); // if (meshR2 != null) // { // meshR2.materials[0].color = Color.red; // } // int i = 0; // foreach (QuadEdge<int> edge in baseEdge.RightEdges()) // { // var test3 = radius * edge.Destination; // if (triangulationOnSphere) // { // test3 = radius * Geometry.InvStereographicProjection(edge.Destination); // } // var newGo3 = GameObject.Instantiate(shape); // newGo3.transform.SetParent(transform); // newGo3.transform.position = test3.AsVector3(); // newGo3.transform.localScale = new Vector3(4.0f, 4.0f, 4.0f); // // Color // var meshR3 = newGo3.GetComponent<MeshRenderer>(); // if (meshR3 != null) // { // meshR3.materials[0].color = Color.yellow; // } // if (i >= 0) // { // break; // } // i++; // } // // END DEBUGTOOLS // // END DEBUGTOOLS // // END DEBUGTOOLS // DRAWING --- --- DRAWING --- --- DRAWING List <Vec3> triangles; if (triangulationOnSphere) { triangles = sphereMeshUsed.Triangles().ForEach(x => Geometry.InvStereographicProjection(x) * radius).ToList(); } else { // Remove first triangles triangles = sphereMeshUsed.Triangles().ForEach(x => x * radius).ToList(); } TriangleDrawer.DrawLine(triangles, transform, mat, Color.black, lineScale); TriangleDrawer.DrawFace(triangles, transform, mat, gradient); TriangleDrawer.DrawPoints(triangles, transform, shape, Color.red, scale); // Remove first face (reconstructed hole) // List<Face<int, int>> faces = sphereMeshUsed.Faces(FaceConfig.Voronoi, radius).Collection().Skip(1).ToList(); List <Face <int, int> > faces = sphereMeshUsed.Faces(FaceConfig.Voronoi, radius).ToList(); // // START DEBUGTOOLS // // START DEBUGTOOLS // // START DEBUGTOOLS // int i = 0; // foreach (QuadEdge<int> edge in sphereMeshUsed.RightMostEdge.Oprev.Sym.Lnext.Oprev.FaceLeftEdges()) // // foreach (QuadEdge<int> edge in sphereMeshUsed.RightMostEdge.Oprev.Rprev.EdgesFrom()) // { // var test3 = edge.Destination; // // test3 = radius * test3; // // if (triangulationOnSphere) // // { // // test3 = radius * Geometry.InvStereographicProjection(edge.Destination); // // } // var newGo3 = GameObject.Instantiate(shape); // newGo3.transform.SetParent(transform); // newGo3.transform.position = test3.AsVector3(); // newGo3.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); // // Color // var meshR3 = newGo3.GetComponent<MeshRenderer>(); // if (meshR3 != null) // { // meshR3.materials[0].color = Color.yellow; // } // if (i >= 1) // { // // Add fake point created // break; // } // else // { // test3 = Geometry.CircumCenter3D(Geometry.InvStereographicProjection(edge.RotSym.Origin), // Geometry.InvStereographicProjection(edge.RotSym.Destination), // Geometry.InvStereographicProjection(edge.RotSym.Oprev.Destination)); // Vec3 a = Geometry.InvStereographicProjection(edge.RotSym.Origin); // Vec3 b = Geometry.InvStereographicProjection(edge.RotSym.Destination); // Vec3 c = Geometry.InvStereographicProjection(edge.RotSym.Oprev.Destination); // Debug.Log(a); // Debug.Log(b); // Debug.Log(c); // Vec3 ca = c - a; // Vec3 ba = b - a; // Vec3 baca = Vec3.Cross(ba, ca); // Debug.Log(baca.SquaredMagnitude); // Debug.Log(test3); // var newGo31 = GameObject.Instantiate(shape); // newGo31.transform.SetParent(transform); // newGo31.transform.position = (radius * Geometry.InvStereographicProjection(edge.RotSym.Origin)).AsVector3(); // newGo31.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); // // Color // var meshR31 = newGo31.GetComponent<MeshRenderer>(); // if (meshR31 != null) // { // meshR31.materials[0].color = Color.grey; // } // var newGo32 = GameObject.Instantiate(shape); // newGo32.transform.SetParent(transform); // newGo32.transform.position = (radius * Geometry.InvStereographicProjection(edge.RotSym.Destination)).AsVector3(); // newGo32.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); // // Color // var meshR32 = newGo32.GetComponent<MeshRenderer>(); // if (meshR32 != null) // { // meshR32.materials[0].color = Color.grey; // } // var newGo33 = GameObject.Instantiate(shape); // newGo33.transform.SetParent(transform); // newGo33.transform.position = (radius * Geometry.InvStereographicProjection(edge.RotSym.Oprev.Destination)).AsVector3(); // newGo33.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); // // Color // var meshR33 = newGo33.GetComponent<MeshRenderer>(); // if (meshR33 != null) // { // meshR33.materials[0].color = Color.grey; // } // double invDistanceScaled = radius / test3.Magnitude; // test3 *= invDistanceScaled; // var newGo34 = GameObject.Instantiate(shape); // newGo34.transform.SetParent(transform); // newGo34.transform.position = test3.AsVector3(); // newGo34.transform.localScale = new Vector3(2.0f, 2.0f, 2.0f); // // Color // var meshR34 = newGo34.GetComponent<MeshRenderer>(); // if (meshR34 != null) // { // meshR34.materials[0].color = Color.green; // } // } // // if (!Geometry.Ccw(edge.Destination, edge.Lprev.Destination, edge.Lprev.Origin)) // // { // // Debug.Log("FOUND"); // // if (meshR3 != null) // // { // // meshR3.materials[0].color = Color.magenta; // // } // // } // i++; // } // // END DEBUGTOOLS // // END DEBUGTOOLS // // END DEBUGTOOLS if (triangulationOnSphere) { float nbCells = (float)faces.Count; int indcolor2 = 0; foreach (Face <int, int> face in faces) { var color = gradient.Evaluate(indcolor2 / nbCells); face.DrawFace(transform, mat, color, scale: radius); face.DrawLine(transform, mat, Color.white, lineScale, loop: true); face.DrawPoints(transform, shape, mat, Color.blue, 0.6f * scale); indcolor2++; // if (indcolor2 > 11) // { // break; // } } } } else { // DRAWING --- --- DRAWING --- --- DRAWING points = points.Select(x => x * radius).ToList(); int ptId = 0; foreach (Vec3 point in points) { var newGo = GameObject.Instantiate(shape); newGo.name = string.Format("Fibonnaci Sphere {0}", ptId.ToString()); newGo.transform.SetParent(transform); newGo.transform.position = point.AsVector3(); newGo.transform.localScale = new Vector3(scale, scale, scale); // Color var meshR = newGo.GetComponent <MeshRenderer>(); if (meshR != null) { meshR.materials[0].color = Color.black; } ptId++; } } }