Interface IExtrudeShape
Implement this class to create a customized shape that can be extruded along a Spline using the
Spline
Some default shape implementations are available in the Unity
Spline
extrudeShape.Setup(spline, numberOfSegments);
for(int i = 0; i < numberOfSegments; ++i)
{
float t = i / (numberOfSegments - 1);
extrudeShape.SetSegment(i, t, splinePositionAtT, splineTangentAtT, splineUpAtT);
for(int n = 0; n < extrudeShape.SideCount; ++n)
vertices.Add(extrudeShape.GetPosition(n / (extrudeShape.SideCount - 1), n));
}
This example IExtrudeShape implementation creates a tube.
Namespace: UnityEngine .Splines
Assembly: Unity.Splines.dll
Syntax
public interface IExtrudeShape
Examples
// While not strictly necessary, marking the class as Serializable means that
// this can be edited in the Inspector.
[Serializable]
public class Circle : IExtrudeShape
{
[SerializeField, Min(2)]
int m_Sides = 8;
float m_Rads;
// We only need to calculate the radians step once, so do it in the Setup method.
public void Setup(ISpline path, int segmentCount)
{
m_Rads = math.radians(360f / SideCount);
}
public float2 GetPosition(float t, int index)
{
return new float2(math.cos(index * m_Rads), math.sin(index * m_Rads));
}
public int SideCount
{
get => m_Sides;
set => m_Sides = value;
}
}
Properties
SideCount
How many vertices make up a single ring around the mesh.
Declaration
int SideCount { get; }
Property Value
Type | Description |
---|---|
int | How many vertices make up a revolution for each segment of the extruded mesh. |
Methods
GetPosition(float, int)
This method is responsible for returning a 2D position of the template shape for each vertex of a single
ring around the extruded mesh.
Note that both interpolation t
and index
are provided as a convenience.
Declaration
float2 GetPosition(float t, int index)
Parameters
Type | Name | Description |
---|---|---|
float | t | The normalized interpolation [0...1] for a vertex around an extruded ring. |
int | index | The index of the vertex in the extruded ring. |
Returns
Type | Description |
---|---|
float2 | A 2D position interpolated along a template shape to be extruded. This value will be converted to a 3D point and rotated to align with the spline at the current segment index. |
SetSegment(int, float, float3, float3, float3)
Implement this function to access information about the spline path being extruded for each segment.
Spline
Declaration
void SetSegment(int index, float t, float3 position, float3 tangent, float3 up)
Parameters
Type | Name | Description |
---|---|---|
int | index | The segment index for the current vertex ring. |
float | t | The normalized interpolation ratio corresponding to the segment index. Equivalent to index divided by segmentCount - 1. |
float3 | position | The position on the Spline path being extruded along at |
float3 | tangent | The tangent on the Spline path being extruded along at |
float3 | up | The up vector on the Spline path being extruded along at |
Setup(ISpline, int)
Implement this function to access information about the ISpline path being extruded and
number of segments. Spline
Declaration
void Setup(ISpline path, int segmentCount)