I have the following code to try and triangulate a grid:
for _, vertice in vertexes do
if vertice % 2 <= 0 then continue end
local bPoint = vertice + 1
local cPoint = (TILE_SIZE / TILE_RESOLUTION) + 1
EditableMesh:AddTriangle(vertice, bPoint, cPoint)
end
Where b is the next point, and c is the point diagonal to (vertice or a).
It skips over every 2nd vertice to avoid duplicate triangles from being created
for x = 1,#grid do
for y = 1,#grid[x] do
if x == #grid then continue end
if y == #grid[x] then continue end
-- First triangle
local vertex = grid[x][y]
local vertex2 = grid[x+1][y]
local vertex3 = grid[x+1][y+1]
mesh:AddTriangle(vertex, vertex3, vertex2)
-- Second triangle
vertex2 = grid[x][y+1]
mesh:AddTriangle(vertex3, vertex, vertex2)
end
end
My old script might help you, the grid is a 2d array that contains the vertices