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 Teddy(List <Vector2> points) { var polygon = Polygon2D.Contour(points.ToArray()); triangulation = new Triangulation2D(polygon, 0f); Init(triangulation); }
void Build() { points = Utils2D.Constrain(points, threshold); var polygon = Polygon2D.Contour(points.ToArray()); var vertices = polygon.Vertices; if (vertices.Length < 3) { return; // error } var triangulation = new Triangulation2D(polygon, angle); var go = Instantiate(prefab); go.transform.SetParent(transform, false); go.GetComponent <DemoMesh>().SetTriangulation(triangulation); Clear(); }