void Awake() { // input points for a polygon2D contour List <Vector2> points = new List <Vector2>(); // When calling PopulateSquarePerimeter you should prefer // a factor of 4 for the 'res' argument. PopulateSquarePerimeter(points, 1000, 20); // construct Polygon2D Polygon2D polygon = Polygon2D.Contour(points.ToArray()); // construct Triangulation2D with Polygon2D and threshold angle (18f ~ 27f recommended) Triangulation2D triangulation = new Triangulation2D(polygon, 22.5f); // build a mesh from triangles in a Triangulation2D instance Mesh mesh = triangulation.Build(); // Initialize gameObject // assuming it starts out as an empty object gameObject.AddComponent <MeshFilter>(); // GetComponent<MeshFilter>().sharedMesh = mesh; //gameObject.GetComponent<MeshFilter>().sharedMesh = mesh; gameObject.GetComponent <MeshFilter>().mesh = mesh; // gameObject.AddComponent<MeshRenderer>(); //gameObject.AddComponent<MeshCollider>(); gameObject.SetActive(false); }
public void SetTriangulation(Triangulation2D triangulation) { var mesh = triangulation.Build(); GetComponent <MeshFilter>().sharedMesh = mesh; this.triangles = triangulation.Triangle2Ds; }
public Mesh Build(MeshSmoothingMethod method, int times = 5, float alpha = 0.2f, float beta = 0.5f) { var mesh = triangulation.Build( (Vertex2D v) => { float z = 0f; if (heightTable.ContainsKey(v)) { z = heightTable[v]; } return(new Vector3(v.Coordinate.x, v.Coordinate.y, -z)); } ); mesh = Symmetrize(mesh); switch (method) { case MeshSmoothingMethod.Laplacian: mesh = MeshSmoothing.LaplacianFilter(mesh, times); break; case MeshSmoothingMethod.HC: mesh = MeshSmoothing.HCFilter(mesh, times, alpha, beta); break; } network = VertexConnection.BuildNetwork(mesh.triangles); return(mesh); }