Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closest Spline & control points loop in both directions
#9
Please look at the screenshot below. I cannot understand why is this happening. 
I am getting the nearest segment, and then I try to get next and previous control point. Next one is represented by green sphere, and previous is yellow sphere. 

Notice what is happening when input world position is exactly at first CP position (CP0000).

[Image: IinsYhT.gif]

Code:
public override void DrawGizmos () {

            if (GizmoContext.InSelection(this))
            {
                var nearestPointTf = spline.GetNearestPointTF(transform.position, out var output, out var nearestSegment, out var nearestPointLocalF, 0, -1, Space.World);
                Draw.WireSphere(output, 0.5f, Color.black);
           
                var nextControlPoint = spline.GetNextControlPoint(nearestSegment);
                Draw.WireSphere(nextControlPoint.transform.position, 0.4f, Color.green);
           
                var prevControlPoint = spline.GetPreviousControlPoint(nearestSegment);
                Draw.WireSphere(prevControlPoint.transform.position, 0.4f, Color.yellow);   
            }
        }

Basically i would like to traverse all the controlpoints in both directions starting from any given world position.

Also, nearestSegment is also giving me inconsistent results. 

black sphere: nearest point on a spline
blue sphere: nearest segment
yellow sphere: previous control point from closest segment
green shpehe: next control point from closest segment
transform handle: world point that I am using to calculate everything


[Image: 2tNXnQI.png]
[Image: Ymko2eR.png]
[Image: NWhHUKV.png]
Reply


Messages In This Thread
RE: Beginner's questions - Closest spline & closest point on spline - by nehvaleem - 01-29-2021, 02:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 3 11 04-02-2024, 02:24 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_

Forum Jump: