[WIP] Easy to use and simple spline tool

Hi all. I’ve used almost all the spline tools on the asset store and to be honest they all annoy me for a number of reasons. Some are hard to set up. Some are hard to place and edit points in 3D space. Some just break if you look at them long enough. And the the rest are so complicated or obtuse it takes a rocket scientist to actually use them.

I’ve decided to take matters into my own hands and I started building a simple spline tool. The goal of this tool is to:

  • Make spline creation simple and easy
  • Make editing a spline (moving points, adding points, inserting points, deleting points, etc) simple.
  • Build an intuitive interface so that you can easily understand where the spline is in 3D space. (I’m basing this on the Homeworld interface, if you haven’t played it, play it!).
  • Build it robust. Working with undo and redo. Making it so that it never breaks and never gets null exceptions even when points are deleted etc.
  • Make it fast! No alloc, no GC at runtime.

Here’s a short video of how it’s going. Let me know if this is something you’d like to use and I’ll see if I can make it available in future when it’s more complete.

3 Likes

Nice work!

Wow thanks, handsome stranger.

More progress on my new spline tool.

Features demonstrated in this video:
Bezier curves
Different control modes for points (point, mirrored, aligned, free)
Multi point selection with drag select
Flatten selection
Move selection

Adding the usual spline functionality.

Cube moving at consistent speed
5496268--563524--83726149_546394216244271_1197667874055913472_n.gif

Credit to VoxelMatt for help on this too.

Playing around with this new spline tool, I built a logo in about 3 minutes. I actually forgot to write the N at first, so I inserted it using the insert feature, I then realised I wrote the N in the wrong place between E and S, doh! Not to worry though, I cut E and S out using shift drag select and ctrl X and then pasted them to the end using ctrl V! I love it when a plan comes together!

1 Like

Focus, simply hit ‘F’.

This is one cool feature I haven’t seen in SuperSplines or some of the other spline editors.

Runtime editing of a spline, and not breaking the position of all the spline objects. (And 100% alloc/GC free)

5499235--563857--EditingWhileMoving.gif

2 Likes

Could this be the greatest spline system ever built?

2 Likes

Another minor but still annoyance with other spline tools fixed. Editing control points now intelligently selects which control point to manipulate based on your input and the spline around it.

Finalising the code interface for my new spline tool:

public interface ISpline
{
    SplineResult GetResultAtT(float splineT);
    SplineResult GetResultAtDistance(float splineDistance);
    SplineResult GetResultAtSegmentT(int segmentIndex, float segmentT);
    SplineResult GetResultAtSegmentDistance(int segmentIndex, float segmentT);
    SplineResult GetResultClosestTo(Vector3 point);
    SplineResult GetResultClosestTo(Ray ray);
    SplineResult GetResultAtWorldDistanceFrom(float startSplineDistance, float worldDistance, float stepSplineDistance);
}
public struct SplineResult
{
    public float t; // 0 - 1 along spline
    public float length; // real world length of the spline
    public float distance; // real world distance along spline before wrapping
    public float loopDistance; // real world distance along spline after wrapping
    public bool isLoop; // is the spline looped
    public int lapCount; // number of times looped distance

    public Vector3 position => segmentResult.position;
    public Vector3 tangent => segmentResult.tangent;

    public bool AtEnd => !isLoop && Mathf.Approximately( t, 1 );
    public bool AtStart => !isLoop && Mathf.Approximately( t, 0 );

    public SegmentResult segmentResult;
}
public struct SegmentResult
{
    public int index;
    public float t;
    public float distance;
    public float length;
    public Vector3 position;
    public Vector3 tangent;

    public bool AtSegmentEnd => Mathf.Approximately( t, 1 );
    public bool AtSegmentStart => Mathf.Approximately( t, 0 );
}

that’s it, super simple.

I have been working on the interface and making some really nice little tools that allow you to set and edit multiple nodes in the spline at once. Here’s an example of setting the X position on 4 nodes at the same time.

Here’s my first attempt using my spline tool in production on my new mini golf game.

2 Likes

I have to get onto actually building my game. But that gives me a good opportunity to battle test this new spline tool. You may not see many more updates in the near future but I’ll still be chipping away at it and may post updates from time to time.

1 Like

it does look like a good spline tool.

can the nodes be edited in code ?

Yep. SetNode(int index, SplineNode node)

Can you add object placement along the spline? and random object placement.
And align to terrain? or mesh

Thanks

SetNode(int index, SplineNode node)

so first you create a node (position, type etc) and then you set it for spline?
am I understanding this right?

I’ll probably add projection onto physics so you can project onto meshes or terrain using that.

As for moving and placement on the spline, That’ll be up to you using the interface provided. Here’s an example script of an object placed along a spline at a distance (world distance):

SplineResult result = spline.GetResultAtDistance( distance );
myGameObject.position = result.position;
myGameObject.rotation = Quaternion.LookRotation( result.tangent, Vector3.up );

You could place objects randomly by randomising the distance argument passed into GetResultAtDistance()

to move the object along the spline you would add to the distance variable each update.

distance += speed;

I over simplified before. There are multiple ways to add and change nodes:

You can create a new node:
SplineNode node = new SplineNode( worldPosition, control1, control2 ); // control1 and control2 are relative to worldPosition

from there you can either update an already existing node using:

spline.SetNode( int index, node );

you can append or prepend a node to the spline using:

spline.AppendNode( node );
spline.PrependNode( node );

you can also insert the new node using:

spline.InsertNode( int index, node );

And finally you can create a new node on the spline without changing the curve of the spline by using:

int newNodeIndex = spline.InsertNode( float distance );

this will create a new node at that point on the spline and set the controls of the previous and next nodes such that the spline is the exact same shape it was before the node was added.

2 Likes

So after all that, I see this in the latest unity update…

I wish there was more details about this new generic spline from unity.