libtess2 is a library for tessellation. It is the GLU libtess refactored and compiled to ActionScript 3 via Adobe CrossBridge. The usual Flash drawing API is based on vector graphics, which means that complex polygons can be rendered easily. All that is required is to inform the Flash player how the shape is and, under the hood, math curves and functions are used to achieve the desired result.

When working with the GPU, it’s not possible to easily draw complex polygons using curves and math functions, all information must be converted to triangles first. Since the GPU only understands triangles, in order to render a complex polygon (e.g. a a square with a role in the middle) a developer must put together a set of triangles to represent that. That process is know as tessellation. libtess2 is a library for tessellation. It is able to tessellate a complex polygon, returning an array of vertex data used to create the polygon.


var pathOuter:Vector. = Vector.([0, 0,   200, 0,  200, 200, 0, 200]);
var pathInner:Vector. = Vector.([50, 50, 150, 50, 150, 150, 50, 150]);

var t:Tesselator = new Tesselator();
t.newTess(1024 * 1024);
t.addContour(pathOuter, pathOuter.length / 2, 2);
t.addContour(pathInner, pathInner.length / 2, 2);
t.tesselate(Tesselator.WINDING_ODD, Tesselator.ELEMENT_TYPE_POLYGONS, 3, 2);
var vertices:Vector. = t.getVertices();
var vertexCount:int = t.getVertexCount();
var elements:Vector. = t.getElements();
var elementCount:int = t.getElementCount();
Misc . URL.