docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface IExtrudeShape

    Implement this class to create a customized shape that can be extruded along a Spline using the SplineMesh class.

    Some default shape implementations are available in the UnityEngine.Splines.ExtrusionShapes namespace.

    SplineMesh generates extruded mesh geometry in the following manner (pseudo-code):

    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. SplineMesh invokes this method once before each ring of vertices is calculated.

    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 t.

    float3 tangent

    The tangent on the Spline path being extruded along at t.

    float3 up

    The up vector on the Spline path being extruded along at t.

    Setup(ISpline, int)

    Implement this function to access information about the ISpline path being extruded and number of segments. SplineMesh invokes this method once prior to extruding the mesh.

    Declaration
    void Setup(ISpline path, int segmentCount)
    Parameters
    Type Name Description
    ISpline path

    The ISpline that this template is being extruded along.

    int segmentCount

    The total number of segments to be created on the extruded mesh. This is equivalent to the number of vertex "rings" that make up the mesh positions.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)