The tess2.js library performs polygon boolean operations and tesselation to triangles and convex polygons. It is a port of libtess2, which is turn is a cleaned up version of the stock GLU tesselator. The original code was written Eric Veach in 1994. The greatest thing about tess2.js is that it handles all kinds of input like self-intersecting polygons or any nomber of holes and contours.
npm install tess2 --save
var Tess2 = ;// Define inputvar ca = 00 100 510;var cb = 02 102 106 06;var contours = cacb;// Tesselatevar res = Tess2;// Use verticesfor var i = 0; i < resverticeslength; i += 2;// Use trianglesfor var i = 0; i < reselementslength; i += 3var a = reselementsi b = reselementsi+1 c = reselementsi+2;;
Further reading: http://www.glprogramming.com/red/chapter11.html
Browser / AMD / etc
build/tess2.js works with RequireJS, CommonJS, or "no-module" patterns, like a simple script tag:
To build the UMD file, enter the following:
npm run build