Function triangulateShape

  • Perform triangulation of a (2D) contour polygon with holes.

    Example

    ShapeUtils.triangulateShape( [
    new Vector2(10,0), // 0
    new Vector2(0,50), // 1
    new Vector2(60,60), // 2
    new Vector2(70,10) // 3
    ], [])
    // [ [ 1, 0, 3 ], [ 3, 2, 1 ] ]

    Returns

    The triangles over the contour (number[][3]). Each row is a triangle represented as a number[3] array where each value is an index in the contour array.

    Parameters

    • contour: Vector2[]

      2D polygon. An array of Vector2.

    • holes: Vector2[][]

      0 or more hole polygons. An array that holds arrays of Vector2s. Each array represents a single hole definition.

    Returns number[][]