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
  Freewalk mode, then return to spline mythstified 6 401 11-09-2018, 08:20 AM
Last Post: sanaeerumey
  Creating a threaded pole along a spline? spedepasanen 1 199 08-14-2018, 12:25 PM
Last Post: _Aka_
  Generate Spline and Segments dynamically with a script?? mythstified 3 328 08-10-2018, 12:43 PM
Last Post: _Aka_
  Instantiating Prefab on the spline for infinite track hjk27 3 316 08-02-2018, 12:51 PM
Last Post: _Aka_

Forum Jump: