Spline Mesher - Pro
4.1.Data Points
The Spline Curve Mesher component holds data points for every Spline to control Scale, Roll, Vertex Colors and Conforming.
They can be modified using their respective editor tools, but can also be configured through script.
A data point has two components:
- Index: Its position on the spline
- Value: The actual value (depending on which data, the type varies)
| Index type | Description |
|---|---|
| Distance | The ‘t’ value used when interpolating is measured in game units. Values range from 0 (start of Spline) to GetLength() (end of Spline). |
| Knot | The ‘t’ value used when interpolating is defined by knot indices and a fractional value representing the normalized interpolation between the specific knot index and the next knot.
For example |
| Normalized | The ‘t’ value used when interpolating is normalized. Values range from 0 (start of Spline) to 1 (end of Spline). |
Example
The example below sets Scale data points along the spline and applies a sine wave value to it.
using System.Collections.Generic;
using sc.splinemesher.pro.runtime;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Splines;
public class SetScaleData : MonoBehaviour
{
public SplineCurveMesher splineMesher;
public float frequency = 0.1f;
public float amplitude = 1f;
public PathIndexUnit pathIndexUnit;
private void OnValidate()
{
if(!splineMesher) return;
int splineCount = splineMesher.SplineContainer.Splines.Count;
//One SplineData per spline
List<SplineData> scaleData = new List<SplineData>(splineCount);
for (int i = 0; i < splineCount; i++)
{
Spline spline = splineMesher.SplineContainer.Splines[i];
float length = spline.GetLength();
//One point every 2 units for this example
int pointCount = Mathf.CeilToInt(length / 2f);
//Holds the various data points
SplineData data = new SplineData
{
PathIndexUnit = pathIndexUnit
};
if (pathIndexUnit == PathIndexUnit.Knot)
{
//One point per knot
pointCount = spline.Count;
}
for (int j = 0; j < pointCount; j++)
{
//Normalized progress along spline
float t = j / (float)(pointCount-1);
float distance = t * length;
float index = 0;
switch (pathIndexUnit)
{
case PathIndexUnit.Distance: index = distance; break;
case PathIndexUnit.Normalized: index = t; break;
case PathIndexUnit.Knot: index = spline.ConvertIndexUnit(t, PathIndexUnit.Knot); break;
}
float scale = Mathf.Sin(distance * frequency) * amplitude;
scale = scale * 0.5f + 0.5f;
//Each data point has an 'index' to set its position along the spline
//And a 'value'. In this case a float3 for a 3D scale.
data.Add(index, new float3(scale));
}
scaleData.Add(data);
}
splineMesher.scaleData = scaleData;
splineMesher.Rebuild();
}
}
1 of 1 users found this section helpful
If you're familiar with this asset, please consider leaving a review!
Your support is what makes complementary updates possible!
