-
Notifications
You must be signed in to change notification settings - Fork 1
Triangulator Class
Creates a triangulation of the given polygon using ear-clipping. It stores each triangle as a set indices to the vertices that make it up. Runs in O(n^2)
Constructor takes in the shape that will be triangulated.
Creates the triangulation.
Returns the number of indices created.
outIndices should be an array of unsigned shorts. getIndices fills outIndices with the triangle indices.
The triangulator uses the ear-clipping algorithm to triangulate the shape. It begins at the first vertex in the shape. If the vertex is part of a convex corner of the shape a triangle is created from it, the point before it, and the point after. The corner is then removed from the list of points and the process is repeated on the next. All triangles are stored using indices into the shape, so a triangle made of indices 0,1,2 is made of up the points shape[0], shape[1], and shape[2].