textureDir( ) → string
textures/ of the package this module ships in, wherever it is installed
f32(n: number) → buffer return buffer
| arg | type | description |
|---|
| n | number | |
get(b: buffer, i: number) → number return buffer
| arg | type | description |
|---|
| b | buffer | |
| i | number | |
put(b: buffer, i: number, v: number) → void
| arg | type | description |
|---|
| b | buffer | |
| i | number | |
| v | number | |
smooth(e0: number, e1: number, x: number) → number
| arg | type | description |
|---|
| e0 | number | |
| e1 | number | |
| x | number | |
blank(w: number, h: number) → Img
| arg | type | description |
|---|
| w | number | |
| h | number | |
load(path: string, size: number?) → Img
Decode an image file to float planes (0..1), at most `size` px on its longer side.
| arg | type | description |
|---|
| path | string | |
| size | number? | |
key(img: Img) → Img
Key the flat background out to alpha. The key colour is measured from the corners; its bright channels against its dark ones give how much of a pixel is background, the key is unmixed out of edge pixels so no fringe remains, and isolated specks are dropped.
sep(c: { number }) → number
| arg | type | description |
|---|
| c | { number } | |
fit(img: Img, w: number, h: number, margin: number?, flipV: boolean?) → Img
Crop to the cut-out's bounding box (alpha > 0.3) plus a small margin and resample to w x h (box filter), so the leaf fills its texture. `flipV` flips it top to bottom.
| arg | type | description |
|---|
| img | Img | |
| w | number | |
| h | number | |
| margin | number? | |
| flipV | boolean? | |
bleed(img: Img) → void
Fill fully transparent pixels with the colour of the nearest card pixels (dilation, then the card's mean), so filtering and mipmaps never pull a halo in.
grade(img: Img, gain: { number }?, sat: number?) → void
Multiply / lift the card's colour: `gain` { r, g, b } multiplies (in 0..1 sRGB), `sat` scales saturation around luma.
| arg | type | description |
|---|
| img | Img | |
| gain | { number }? | |
| sat | number? | |
normalFrom(img: Img, strength: number?) → buffer
A tangent-space normal map (green up) from the card's shading: brightness read as height, so veins and midribs gain relief. Flat outside the cut-out.
| arg | type | description |
|---|
| img | Img | |
| strength | number? | |
H(xx: number, yy: number) → number
| arg | type | description |
|---|
| xx | number | |
| yy | number | |
toBytes(img: Img) → buffer
The card as rgba8 bytes.
save(name: string, w: number, h: number, bytes: buffer, kind: string, wrap: string?) → any
Write rgba8 bytes as a texture asset in textures/ (PNG source kept). kind: "color" | "normalMap"; wrap "clamp" (cards) or "repeat" (tiles).
| arg | type | description |
|---|
| name | string | |
| w | number | |
| h | number | |
| bytes | buffer | |
| kind | string | |
| wrap | string? | |
regrade(name: string, opts: RegradeOpts) → void
Regrade a baked card's albedo in place: desaturate by `sat`, then gain each channel so the cut-out's mean lands on `target` (sRGB 0..255), and lift the tip end (v -> 1, the image's bottom rows) by `tipLift` with a slight warm shift. `maxValue` clamps every channel (default 245). Returns the new mean.
| arg | type | description |
|---|
| name | string | |
| opts | RegradeOpts | |
lumOf(r: number, g: number, b: number) → number return 0
| arg | type | description |
|---|
| r | number | |
| g | number | |
| b | number | |
shaped(i: number) → void
| arg | type | description |
|---|
| i | number | |
bake(name: string, srcPath: string, opts: BakeOpts?) → void
Bake one card: key the source picture, fit it to w x h, grade it, bleed the margin, save `<name>_albedo` and `<name>_normal`. Returns the texture names written.
| arg | type | description |
|---|
| name | string | |
| srcPath | string | |
| opts | BakeOpts? | |
⌬ Types
Img = { w: number, h: number, r: buffer, g: buffer, b: buffer, a: buffer }RegradeOpts = { target: { number }, sat: number?, tipLift: number?, maxValue: number? }BakeOpts = { w: number?, h: number?, margin: number?, flipV: boolean?, gain: { number }?, sat: number?, normalStrength: number? }