using System.Windows.Media.Media3D;
using System.Windows.Media;
using System.Windows;

namespace SurfacePlot3D.Members
{
    public class RibbonText : GeometryTextBase
    {
        public MeshGeometry3D Mesh3D { get; set; } = new MeshGeometry3D();

        protected override void ProcessFigure(CircularList<Point> list, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures)
        {
            int offset = vertices.Count;
            for (int i = 0; i <= list.Count; i++)
            {
                Point pt = list[i];
                vertices.Add(new Point3D(pt.X, pt.Y, 0));
                vertices.Add(new Point3D(pt.X, pt.Y, -Depth));
                textures.Add(new Point((double)i / list.Count, 0));
                textures.Add(new Point((double)i / list.Count, 1));
                if (i < list.Count)
                {
                    indices.Add(offset + i * 2 + 0);
                    indices.Add(offset + i * 2 + 2);
                    indices.Add(offset + i * 2 + 1);
                    indices.Add(offset + i * 2 + 1);
                    indices.Add(offset + i * 2 + 2);
                    indices.Add(offset + i * 2 + 3);
                }
            }

            Mesh3D.Positions = vertices;
            Mesh3D.TriangleIndices = indices;
            Mesh3D.TextureCoordinates = textures;
        }
    }
}