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
  Spline Controller Animate - Don't understand the Speed and TimeScale properties GenericJoe 11 674 Yesterday, 08:10 PM
Last Post: _Aka_
  Find if object is on spline path nciofi 1 52 07-10-2018, 09:23 AM
Last Post: _Aka_
  Spline Approximation List skyboard 2 79 07-01-2018, 11:02 PM
Last Post: _Aka_
  Freeing objects from a spline Renald 1 80 06-20-2018, 11:10 AM
Last Post: _Aka_

Forum Jump: