Example #1
0
        /// <summary>
        /// Triangulates the shape and adds all of the points (in triangle list layout) to the provided output.
        /// </summary>
        /// <param name="output">The output list.</param>
        public void Triangulate(IList <Vector2> output, Vector2 offset, float scale = 1.0f)
        {
            Points.Reverse();
            SweepContext tcx = new SweepContext();

            tcx.AddPoints(Points);

            // Hole edges
            foreach (Shape h in Holes)
            {
                tcx.AddHole(h.Points);
            }

            tcx.InitTriangulation();
            Sweep sweep = new Sweep();

            sweep.Triangulate(tcx);

            List <Triangle> triangles = tcx.GetTriangles();

            foreach (Triangle tri in triangles)
            {
                //tri.ReversePointFlow();
                output.Add(((Vector2)tri.Points[0] * scale) + offset);
                output.Add(((Vector2)tri.Points[2] * scale) + offset);
                output.Add(((Vector2)tri.Points[1] * scale) + offset);
            }
        }
Example #2
0
        public void Triangulate(SweepContext tcx)
        {
            _nodes = new List <Node>();

            tcx.InitTriangulation();
            tcx.CreateAdvancingFront(_nodes);

            // Sweep points; build mesh
            SweepPoints(tcx);

            // Clean up
            FinalizationPolygon(tcx);
        }
Example #3
0
        /// <summary>
        /// Triangulates the shape and adds all of the triangles to the provided output.
        /// </summary>
        /// <param name="output">The output list.</param>
        public void Triangulate(IList <Triangle> output)
        {
            SweepContext tcx = new SweepContext();

            tcx.AddPoints(Points);

            foreach (Shape p in Holes)
            {
                tcx.AddHole(p.Points);
            }

            tcx.InitTriangulation();
            Sweep sweep = new Sweep();

            sweep.Triangulate(tcx);

            List <Triangle> triangles = tcx.GetTriangles();

            foreach (Triangle tri in triangles)
            {
                output.Add(tri);
            }
        }