Drawing Spline Runtime

DrawingSpline

While working on my runtime editor, I periodically received user requests about the ability to draw runtime splines. I recently finished this feature and would like to share some of my findings. I have also attached a project you can download and use in your work. Download

The first problem I had to solve was displaying thin lines. Fortunately, I already had some experience in this area, so after some research, I chose a spline mesh component and a wireframe material with a coordinate mask.

M_SplineMasterPreview

M_SplineMasterDomain

M_SplineMasterUsing

Since we have the material, let’s draw a debug line with the duration. To do this, I created an actor that builds a line and destroys itself with a given delay.

DrawDebugLine

Next, let’s display some spline in runtime — for example, a circle.

(You can see the function of constructing a circle by downloading the project.)

DrawCircle

I use the ‘AcquireSplineMeshComponent’ function to reuse existing components instead of creating new ones.

Then I remove extra components:

To change the radius:

The next step is to draw a spline by points.
To display the spline, I use the same functions above.
On start I turn on inputs to receive mouse events. When finished, I turn off the inputs, trim the last point, and update spline meshes.

If Left Shift is pressed, the next point will be linear.

While drawing, I update the last spline point position and the last two spline meshes every tick.

This is enough to draw a spline at runtime.
However, much more can be achieved:

I will add additional material about working with splines.

  • How to edit a spline using points and bezier curves.
  • How to control the visibility of a spline.
  • How to work with spline collisions.
  • Meshes along a spline with offset

These and other features are implemented in my Runtime Editor:

5 Likes

Torus:

Torus

Example Project:
DrawLineExampleWithThickness.zip (1.0 MB)

1 Like