Custom paint
Draw your own triangles for a node.
ts
import { Painter, TrianglesPaint } from "willow";Painter
ts
class PainterThe view onto the render pipeline passed to a node's custom-paint function. Only valid while the function runs: using a stored Painter later raises InvalidStateError.
Painter: properties
| Member | Description |
|---|---|
readonly node: Node | The node whose custom-paint function is running. |
Painter: methods
| Member | Description |
|---|---|
worldTransform(): Array<float> | The node's world transform as six numbers [a, b, c, d, tx, ty]. A point (x, y) maps to (a * x + c * y + tx, b * x + d * y + ty). The camera is applied after painting. |
isBuildingCache(): boolean | True when this paint pass is building a cached subtree (CacheAsTree): skip transient or animated content that should not be folded into the cache. |
paintDefault(): void | Draws the node's normal content (sprite, mesh, text, particles) so custom geometry can be added alongside it. Containers draw nothing. |
appendTriangles(triangles: TrianglesPaint): void | Draws one batch of triangles. Vertices are copied; the arrays may be reused after. |
TrianglesPaint
ts
class TrianglesPaintOne batch of textured triangles for Painter.appendTriangles. Vertex positions are in world space: write them through Painter.worldTransform().
TrianglesPaint: constructors
ts
new TrianglesPaint(vertices: Float32Array | Array<float>, indices: Array<int>)Creates a batch from flat vertex data (eight numbers per vertex: x, y, u, v, r, g, b, a, colour channels 0.0 to 1.0) and a triangle list (three vertex indices per triangle).
TrianglesPaint: properties
| Member | Description |
|---|---|
vertices: Float32Array | Array<float> | Flat vertex data, eight numbers per vertex in order: x, y, u, v, r, g, b, a. |
indices: Array<int> | Triangle list: three vertex indices per triangle. |
texture?: Texture | TextureRegion | Image sampled by the triangles; omit to draw vertex colours only. |
blendMode?: string | Blend mode name such as "normal" or "add" (same names as Node.blendMode). |
renderLayer: int | Render layer, 0 to 255. Defaults to 0. |
globalOrder: int | Secondary draw-order key within the render layer. Defaults to 0. |