Options
All
  • Public
  • Public/Protected
  • All
Menu

A helper class used to construct triangulated polygon meshes Allow to add padding and a specific depth value.

param poly

Closed polygon to be processed and converted to a mesh (array of points or PIXI Polygon)

param options

Various options : normalizing, offsetting, add depth, ...

Hierarchy

  • PolygonMesher

Index

Constructors

Properties

options: Object
vertices: number[] = []

Polygon mesh vertices

indices: number[] = []

Polygon mesh indices

#scaled: Object = {}

Contains some options values scaled by the constant factor

#geometry: Geometry = null

Polygon mesh geometry

#polygonNodeTree: { poly: number[]; nPoly: number[]; children: any[] } = null

Contain the polygon tree node object, containing the main forms and its holes and sub-polygons

Type declaration

  • poly: number[]
  • nPoly: number[]
  • children: any[]
#nbPass: number

Contains the the number of offset passes required to compute the polygon

_defaultOptions: Object = ...

Default options values

Methods

  • triangulate(geometry: Geometry): Geometry
  • Execute the triangulation to create indices

    Parameters

    • geometry: Geometry

      A geometry to update

    Returns Geometry

    The resulting geometry

  • #computePolygonMesh(points: number[]): void
  • Create the polygon mesh

    Parameters

    • points: number[]

    Returns void

  • #updateVertices(vertices: number[]): void
  • Update vertices and add depth

    Parameters

    • vertices: number[]

    Returns void

  • #updatePolygonNodeTree(): true | void
  • Create the polygon by generating the edges and the interior of the polygon if an offset != 0, and just activate a fast triangulation if offset = 0

    Returns true | void

  • #createOffsetPolygon(offsetter: ClipperOffset, node: any, pass?: number): void
  • Recursively create offset polygons in successive passes

    Parameters

    • offsetter: ClipperOffset

      ClipperLib offsetter

    • node: any

      A polygon node object to offset

    • pass: number = 0

    Returns void

  • #flattenVertices(path: IntPoint[], depth: number): number[]
  • Flatten a ClipperLib path to array of numbers

    Parameters

    • path: IntPoint[]

      path to convert

    • depth: number

      depth to add to the flattened vertices

    Returns number[]

    flattened array of points

  • #normalize(poly: number[]): number[]
  • Normalize polygon coordinates and put result into nPoly property.

    Parameters

    • poly: number[]

      the poly to normalize

    Returns number[]

    the normalized poly array

  • #triangulateFast(): void
  • Fast triangulation of the polygon node tree

    Returns void

  • #triangulateTree(): void
  • Recursive triangulation of the polygon node tree

    Returns void

  • #triangulateNode(node: any, indices?: number[]): number[]
  • Triangulate a node and its children recursively to compose a mesh with multiple levels of depth

    Parameters

    • node: any

      The polygon node tree to triangulate

    • indices: number[] = []

    Returns number[]

    An array of indices, result of the triangulation

  • #updateGeometry(): Geometry
  • Updating or creating the PIXI.Geometry that will be used by the mesh

    Returns Geometry

  • #emptyGeometry(): any
  • Empty the geometry, or if geometry is null, create an empty geometry.

    Returns any

  • #createGeometry(vertices: number[], depth?: number[], indices?: number[]): Geometry
  • Create a new Geometry from provided buffers

    Parameters

    • vertices: number[]

      provided vertices array (interleaved or not)

    • depth: number[] = undefined
    • indices: number[] = ...

    Returns Geometry

    the new PIXI.Geometry constructed from the provided buffers

  • getClipperPathFromPoints(poly: number[] | Polygon, dimension?: number): number[]
  • Convert a flat points array into a 2 dimensional ClipperLib path

    Parameters

    • poly: number[] | Polygon

      PIXI.Polygon or points flat array.

    • dimension: number = 2

    Returns number[]

    The clipper lib path.