Polygon and Mesh
Filled shapes and raw triangle meshes.
ts
import { Polygon, Mesh } from "willow";Polygon
ts
class Polygon extends NodeExtends Node.
Filled polygon backed by one vertex-coloured mesh.
Polygon: constructors
ts
new Polygon(points: Float32Array | Array<float>, color: Color)points is a flat [x0, y0, x1, y1...] array (at least 3 points).
Polygon: properties
| Member | Description |
|---|---|
readonly color: Color | Solid fill colour (0xRRGGBBAA, always 8 digits, a 6-digit literal is read as A=0x00, fully transparent). |
Polygon: methods
| Member | Description |
|---|---|
setPoints(points: Float32Array | Array<float>, color?: Color): void | Replaces this polygon's vertices and, optionally, its colour. Same point/colour shape as the constructor. |
setColor(color: Color): void | Equivalent to polygon.color = color. Solid fill colour. |
Polygon: static methods
| Member | Description |
|---|---|
static regular(sides: int, radius: float, color: Color): Polygon | Creates a solid-colour regular polygon with sides vertices centred at the polygon origin. |
static star(points: int, outerRadius: float, innerRadius: float, color: Color): Polygon | Creates a solid-colour star polygon with points outer points, alternating outerRadius/innerRadius. |
static circle(radius: float, color: Color): Polygon | Creates a solid-colour circle, approximated as a 32-segment regular polygon, Equivalent to Polygon.regular(32, radius, color). |
static triangle(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: Color): Polygon | Creates a solid-colour triangle from three arbitrary points. A thin wrapper over the general Polygon(points, color) constructor for exactly 3 points. |
static textured(texture: Texture | TextureRegion, points: Float32Array | Array<float>): Polygon | Creates a textured polygon mesh. Points form an arbitrary simple polygon triangulated via ear-clipping; texture coordinates are normalized from the polygon bounding box to the texture region. |
Mesh
ts
class Mesh extends NodeExtends Node.
Untextured mesh. Vertices use x, y, u, v, r, g, b, a stride order.
Mesh: constructors
ts
new Mesh(vertices: Float32Array | Array<float>, indices: Uint16Array | Array<int>)vertices uses x, y, u, v, r, g, b, a stride order; indices are triangle-list vertex indices.
Mesh: properties
| Member | Description |
|---|---|
tint: Color | Colour tint, a Color, default Color.WHITE. It multiplies the vertex colours at draw time, so a colour change does not rebuild the vertex buffer. |
Mesh: methods
| Member | Description |
|---|---|
setVertices(vertices: Float32Array | Array<float>): void | Replaces this mesh's vertex buffer. Same x, y, u, v, r, g, b, a stride order as the constructor. |
setIndices(indices: Uint16Array | Array<int>): void | Replaces this mesh's triangle-list index buffer. |
invalidateBounds(): void | Forces this mesh's cached bounds to be recomputed on next use, after an out-of-band vertex edit. |