示例#1
0
        public PrettyPolyPoint[] GetCubicBezier()
        {
            int len = points.Length;

            if (len <= 2)
            {
                return(points);
            }
            List <PrettyPolyPoint> newPoints = new List <PrettyPolyPoint>();

            for (int i = 0; i < len; i++)
            {
                if (!closed && i == len - 1)
                {
                    continue;
                }
                PrettyPolyPoint start = points[i];
                PrettyPolyPoint end   = points[(i + 1) % len];
                Vector3         cp1   = start.position + start.outTangent;
                Vector3         cp2   = end.position + end.inTangent;

                for (float j = 0; j < subdivisions; j++)
                {
                    float           t               = j / (float)subdivisions;
                    Vector3         pos             = Interpolate.CubicBezier(start.position, cp1, cp2, end.position, t);
                    PrettyPolyPoint prettyPolyPoint = new PrettyPolyPoint(pos);
                    prettyPolyPoint.color = Color.Lerp(start.color, end.color, t);
                    prettyPolyPoint.size  = Mathf.Lerp(start.size, end.size, t);
                    newPoints.Add(prettyPolyPoint);
                }
            }
            return(newPoints.ToArray());
        }