Ejemplo n.º 1
0
    public void UpdatePoints()
    {
        // this is being run in the editor unless we change points and update it for some other reason...

        List <Vector2> polyPoints = new List <Vector2>(points.Count);

        for (int i = 0; i < points.Count; i++)
        {
            polyPoints.Add(points[i]);
        }
        GetComponent <PolygonCollider2D>().SetPath(0, polyPoints.ToArray());

        // then set the mesh

        List <int> tris = MeshTriangulator.Triangulate(points, isClockwise);

        if (!isClockwise)
        {
            tris.Reverse(); // otherwise the normals face the wrong way...
        }
        // Debug.Log("Found " + (tris.Count/3) + " triangles");
        Mesh mesh = new Mesh();

        mesh.SetVertices(points);
        mesh.SetTriangles(tris, 0);
        mesh.SetUVs(0, polyPoints); // use the 2d points calculated before
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        GetComponent <MeshFilter>().mesh = mesh;
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Splitting the mesh of the structure into triangles calling
 /// the static function Triangulate of MeshTriangulator and passing
 /// the structure transform
 /// </summary>
 void OnMouseDown()
 {
     MeshTriangulator.Triangulate(transform);
 }