API reference

Triangulator Class

Provides methods for triangulating polygons and clipping polygons with holes.

Static Methods

TriangulatePoints ( vertices , holes , outVertices , outIndices )
Triangulates a set of points using the ear clipping algorithm.
This method uses unsafe code to interface with native functions for optimal performance.
The triangulation algorithm expects polygons to be defined in a consistent winding order. Edge cases such as self-intersecting polygons or degenerate triangles may produce unexpected results. The method allocates new arrays for the output parameters on each call.
Signature
static unsafe void TriangulatePoints(List< Vector2 > vertices, List< List< Vector2 > > holes, out Vector2[] outVertices, out int[] outIndices)
Parameters
vertices: List< Vector2 >  The list of vertices that define the outline of a polygon to triangulate. Must not be null or empty, and should contain at least 3 vertices for a valid polygon.
holes: List< List< Vector2 > >  The list of internal polygon holes that should not be triangulated. Can be null if no holes are present. If provided, must not contain null lists, and each hole should contain at least 3 vertices.
outVertices: out Vector2[]  The list of vertices created from the triangulation. Will be populated with the triangulated mesh vertices.
outIndices: out int[]  The list of indices created from the triangulation. Will be populated with triangle indices referencing the output vertices.
Returns
unsafe void
Throws
ArgumentNullException  Thrown when vertices is null, or when holes contains a null list. ArgumentException  Thrown when vertices is empty, or when any hole list is empty.