triangulateShape static method
dynamic
triangulateShape(
- dynamic contour,
- dynamic holes
Implementation
static triangulateShape(contour, holes) {
var vertices =
[]; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
List<num> holeIndices = []; // array of hole indices
var faces =
[]; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
removeDupEndPts(contour);
addContour(vertices, contour);
//
var holeIndex = contour.length;
holes.forEach(removeDupEndPts);
for (var i = 0; i < holes.length; i++) {
holeIndices.add(holeIndex);
holeIndex += holes[i].length;
addContour(vertices, holes[i]);
}
//
var triangles = Earcut.triangulate(vertices, holeIndices, null);
//
for (var i = 0; i < triangles.length; i += 3) {
faces.add(triangles.sublist(i, i + 3));
}
return faces;
}