This is a Lua wrapper around poly2tri. It provides fast, stable Constrained Delauney Triangulation of convex or concave polygons with or without holes. Fork of lua-poly2tri
If you like the extension you can support me on patreon. It will help me make more items for defold.
1) Add defold-poly2tri in your own project as a Defold library dependency. Open your game.project file and in the dependencies field under project add: https://github.com/d954mas/defold-poly2tri/archive/refs/tags/1.0.0.zip
local vertices = {0, 0, 0, 200, 200, 200, 200, 0}
local holes = {
{10, 10, 50, 10, 10, 50},
{100, 10, 175, 10, 175, 100, 100, 50, 10, 100},
{10, 175, 150, 100, 190, 175}
}
local triangles = poly2tri.triangulate(verts, holes)
The output will be a table where each entry is a table consisting of 6 numbers (3 vertices).
There are limitations based on the underlying poly2tri library.
It might be useful to clean up your polygon data using something like clipper.