/// <summary>
 /// Add a contour to the polygon.
 /// </summary>
 /// <param name="contour">The contour to insert.</param>
 /// <param name="hole">Treat contour as a hole.</param>
 public void Add(Contour contour, bool hole = false)
 {
     if (hole)
     {
         this.Add(contour, contour.FindInteriorPoint());
     }
     else
     {
         this.points.AddRange(contour.Points);
         this.segments.AddRange(contour.GetSegments());
     }
 }
        /// <summary>
        /// Add a contour to the polygon.
        /// </summary>
        /// <param name="contour">The contour to insert.</param>
        /// <param name="hole">Point inside the contour, making it a hole.</param>
        public void Add(Contour contour, Point hole)
        {
            this.points.AddRange(contour.Points);
            this.segments.AddRange(contour.GetSegments());

            this.holes.Add(hole);
        }
Exemple #3
0
    private static Mesh GetTriangleDotNetMesh(List <Vector2[]> poly_vertices)
    {
        var num_vxs = 0;

        foreach (var ring_vxs in poly_vertices)
        {
            num_vxs += ring_vxs.Length + 1;
        }

        var poly = new TriangleNet.Geometry.Polygon(num_vxs);

        // set vertices
        var ri = 0;

        foreach (var ring_vxs in poly_vertices)
        {
            var vxs_input = new List <TriangleNet.Geometry.Vertex>(ring_vxs.Length + 1);
            foreach (var vx in ring_vxs)
            {
                vxs_input.Add(new TriangleNet.Geometry.Vertex(vx.x, vx.y));
            }

            // add to poly
            bool is_hole = ri != 0;
            var  contour = new TriangleNet.Geometry.Contour(vxs_input);
            poly.Add(contour, is_hole);
            ++ri;
        }

        // triangulate
        var opts = new TriangleNet.Meshing.ConstraintOptions()
        {
            ConformingDelaunay = true
        };
        var tn_mesh = (TriangleNet.Mesh)poly.Triangulate(opts);

        // write
        var tri_vxs = new Vector3[tn_mesh.Triangles.Count * 3];
        var tri_ids = new int[tn_mesh.Triangles.Count * 3];
        int i       = 0;

        foreach (var tri in tn_mesh.Triangles)
        {
            tri_vxs[i + 0] = new Vector3((float)tri.GetVertex(0).x, (float)tri.GetVertex(0).y, 0);
            tri_vxs[i + 1] = new Vector3((float)tri.GetVertex(2).x, (float)tri.GetVertex(2).y, 0);
            tri_vxs[i + 2] = new Vector3((float)tri.GetVertex(1).x, (float)tri.GetVertex(1).y, 0);

            tri_ids[i + 0] = i + 0;
            tri_ids[i + 1] = i + 1;
            tri_ids[i + 2] = i + 2;

            i += 3;
        }

        // create mesh
        var m = new Mesh();

        // assign to mesh
        m.vertices  = tri_vxs;
        m.triangles = tri_ids;

        // recompute geometry
        // QUESTION why do we need bounds?
        m.RecalculateNormals();
        m.RecalculateBounds();

        return(m);
    }