Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clamping the spline length
#1
Hi,

Not sure if this is possible or if I'm just struggling, as the API doesn't really help all that much. I'm looking to clamp the length of a Bezier spline at runtime.

The user will drag a helper object and the aim is to draw a curve from the start point to this object up to a set distance, at which point the curve will stop drawing any further until the user drags out a shorter curve. I can see a Clamp method which doesn't appear to do anything, and I'm at a loss as to what the Extrapolate method does.

Any ideas?!

Thanks,

Ash
Reply
#2
Hi,
Here is a method I quickly coded that does what you want. It surely can be enhanced:

Code:
    private static bool RemoveExcess(CurvySpline spline, Vector3 terminatorWorldPosition)
    {
        if (spline.IsInitialized == false)
            return false;

        //The position at which the spline should stop
        Vector3 nearestSplinePointToTerminator;
        float terminatorTf = spline.GetNearestPointTF(terminatorWorldPosition, out nearestSplinePointToTerminator);
        //The index of the last segment to keep, all following segements are removed
        int terminatorSegmentIndex = spline.TFToSegmentIndex(terminatorTf);

        //remove all control points beyong the terminator
        int segmentsCount = spline.Count;
        for (int segmentIndex = segmentsCount - 1; segmentIndex >= terminatorSegmentIndex; segmentIndex--)
            spline.Delete(spline.Segments[segmentIndex].NextControlPoint);

        //Add the last control point
        spline.Add(nearestSplinePointToTerminator);

        return true;
    }
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Filling a closed spline dynamically rickgplus 1 53 04-16-2025, 08:56 AM
Last Post: _Aka_
  Disable a spline's gizmo when not selected or disabled. mikechr2000 1 191 02-03-2025, 09:34 AM
Last Post: _Aka_
Information Questions regarding spline colliders and collisions with rigidbodies Spyboticer 7 700 01-20-2025, 12:25 PM
Last Post: _Aka_
  Extrude mesh along spline. New and confused user GhostStalker 3 321 01-02-2025, 09:58 AM
Last Post: _Aka_

Forum Jump: