Skip to content

A tool for creation/editing splines with different basis matrices and generating procedural meshes in Unity.

License

Notifications You must be signed in to change notification settings

akihiko47/Parametric-Curves-And-Splines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

〰️SPLINES〰️

banner

In this repository, I have implemented a tool for creating and editing splines. The scripts give easy access to points on curve and the ability to get the position, tangent, normal and binormal at the desired point of the curve.

Installation 🔧

There are 2 ways:

  • import Splines.unitypackage via Assets-Import Package
  • clone/download this repository and move the Assets/Scripts/Curves folder to your Unity project's Assets folder

Curve types 🌫️

The Curve class implements 3 matrices for different curve types. You can switch between types in real time using curves redactor.

  1. Bézier
  2. B-spline
  3. Cardinal

curves

Redactor 🖌️

The redactor allows you to see the curve, normals, tangents and binormals. You can also change the location of control points and reset them. Redactor is automatically connected to a GameObject that has a Spline component.

redactor

Usage 🎮

You can see a simple example of how to use it in the Curve Animator file. This script animates object along spline. Curve information can be accesed using P() method of Spline class.

spline.P(
   t,
   out Vector3 vertex,
   out Vector3 tangent, 
   out Vector3 normal, 
   out Vector3 binormal, 
   bool inWorld = false
);

where: t - position of point on curve [0 -> spline.GetMaxPointInd()] inWorld - get point information (vertex, tangent, normal, binormal) in world space. Default is local space.

Mesh Generator 📜

You can attach Mesh Generator script to GameObject for procedural plane mesh generation. The mesh will be generated with all necessary information (normals, tangents, uvs) as well as with rounded ends. You can control width of the mesh and generation step. Note that this works better with 2D normals setting turned on.

road

Mesh Animation 🎞️

Mesh Generator script allows you to animate mesh generation. You can specify animation time and call it with AnimateMeshGeneration() method of MeshGenerator class.

animation

Normals calculation 📐

You have two options to choose from:

  1. 3D normals. They are calculated using Frenet normal algorithm (a rather naive approach), so they are not well suited for mesh generation.
  2. 2D normals. They lock one coordinate, but allow you to rotate normals. These normals are more uniform, so they are better for generating meshes (roads for example).

Thank you for reading this 😊!

About

A tool for creation/editing splines with different basis matrices and generating procedural meshes in Unity.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages