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;
    }
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  animating points on a spline Antonio 11 18 09-17-2023, 09:55 AM
Last Post: _Aka_
  Getting object on spline Position when Spline has coordinates larger than 2000 velikizlivuk 5 8 09-05-2023, 01:01 PM
Last Post: velikizlivuk
  Spline.Length not updated unless I add a point to spline (or modify it) first. _RicO 3 6 08-26-2023, 08:41 AM
Last Post: _Aka_
  Raise spline events during edit mode arcadeperfect 3 6 08-24-2023, 08:38 AM
Last Post: _Aka_

Forum Jump: