Exemple #1
0
        public static BezierSegment3D[] SegmentsFromPoints(Vector3[] points, float radiusScalar, bool closed = false)
        {
            if (points.Length < 3)
            {
                // Debug.LogWarning($"Ahoy Bezier - point count must be at least 3");
                return(new BezierSegment3D[0]);
            }
            int numSegments = closed ? points.Length : points.Length - 1;

            BezierSegment3D[] segments = new BezierSegment3D[numSegments];
            Vector3[]         tangents = closed ?
                                         CreateTangentsClosed(points, radiusScalar) :
                                         CreateTangentsOpen(points, radiusScalar);

            for (int pi = 0, ti = 0; pi < points.Length - 1; pi++, ti += 2)
            {
                segments[pi] = new BezierSegment3D(
                    points[pi],
                    tangents[ti],
                    tangents[ti + 1],
                    points[pi + 1]);
            }
            if (closed)
            {
                segments[segments.Length - 1] = new BezierSegment3D(
                    points[points.Length - 1],
                    tangents[tangents.Length - 2],
                    tangents[tangents.Length - 1],
                    points[0]);
            }
            return(segments);
        }
Exemple #2
0
 public static Vector3 Cubic(BezierSegment3D seg, float t)
 {
     return(new Vector3(
                Bezier.Cubic(seg.p0.x, seg.p1.x, seg.p2.x, seg.p3.x, t),
                Bezier.Cubic(seg.p0.y, seg.p1.y, seg.p2.y, seg.p3.y, t),
                Bezier.Cubic(seg.p0.z, seg.p1.z, seg.p2.z, seg.p3.z, t)));
 }
Exemple #3
0
        public static BezierSegment3D[] SegmentsFromPoses(Pose[] poses, float radiusScalar)
        {
            if (poses.Length < 2)
            {
                return(new BezierSegment3D[0]);
            }
            var segments = new BezierSegment3D[poses.Length - 1];

            for (int i = 0; i < poses.Length - 1; i++)
            {
                segments[i] = SegmentFromPoses(poses[i], poses[i + 1], radiusScalar);
            }
            return(segments);
        }
Exemple #4
0
        public static Vector3[] CreateDistributedPoints(BezierSegment3D segment, float maxDeltaPosition = 0.1f)
        {
            int numPoints = Mathf.CeilToInt(segment.length / maxDeltaPosition);

            if (numPoints > 5000 || numPoints < 1)
            {
                Debug.LogWarning($"Ahoy Bezier - max point count reached - 5000");
                numPoints = 5000;
            }

            var points = new Vector3[numPoints];

            for (int i = 0; i < numPoints; i++)
            {
                float t = (float)i / (numPoints - 1);
                points[i] = Cubic(segment, t);
            }
            return(points);
        }