Skip to content

@bendyline/molen-materials ​

Molen materials: pixel grids, SVG and procedural material graphs (rungs 2-4). No three.js.

ts
import { /* … */ } from '@bendyline/molen-materials';

Interfaces ​

ApplyUvPaintOptions ​

Properties ​

dilationPx? ​
ts
optional dilationPx?: number;
maskToIslands? ​
ts
optional maskToIslands?: boolean;

BakedMaterial ​

Properties ​

meta ​
ts
meta: object;
alphaCoverage? ​
ts
optional alphaCoverage?: boolean;
alphaTest? ​
ts
optional alphaTest?: number;
filter ​
ts
filter: "nearest" | "linear";
slots ​
ts
slots: Partial<Record<MaterialSlot, RGBAImage>>;

BakedMaterialStore ​

Persistent storage for baked materials (e.g. IndexedDB), keyed by baker and document.

Methods ​

get() ​
ts
get(key): Promise<BakedMaterial | undefined>;
Parameters ​
key ​

string

Returns ​

Promise&lt;BakedMaterial | undefined&gt;

prune()? ​
ts
optional prune(keep): Promise<void>;

Delete every entry keep rejects: output from a baker that has since changed.

Parameters ​
keep ​

(key) => boolean

Returns ​

Promise&lt;void&gt;

set() ​
ts
set(key, material): Promise<void>;
Parameters ​
key ​

string

material ​

BakedMaterial

Returns ​

Promise&lt;void&gt;


MaterialBaker ​

Methods ​

bake() ​
Call Signature ​
ts
bake(kind, doc): Promise<BakedMaterial>;
Parameters ​
kind ​

"matgraph"

doc ​

MatGraphDoc

Returns ​

Promise&lt;BakedMaterial&gt;

Call Signature ​
ts
bake(kind, doc): Promise<BakedMaterial>;
Parameters ​
kind ​

"pixelgrid"

doc ​

PixelGridDoc

Returns ​

Promise&lt;BakedMaterial&gt;


MaterialBakeWorker ​

Methods ​

addEventListener() ​
ts
addEventListener(type, listener): void;
Parameters ​
type ​

"message" | "error"

listener ​

(event) => void

Returns ​

void

postMessage() ​
Call Signature ​
ts
postMessage(message): void;
Parameters ​
message ​

unknown

Returns ​

void

Call Signature ​
ts
postMessage(message, transfer): void;
Parameters ​
message ​

unknown

transfer ​

ArrayBuffer[]

Returns ​

void

removeEventListener()? ​
ts
optional removeEventListener(type, listener): void;
Parameters ​
type ​

"message" | "error"

listener ​

(event) => void

Returns ​

void

terminate()? ​
ts
optional terminate(): void;
Returns ​

void


MatGraphDoc ​

Properties ​

alphaCoverage? ​
ts
optional alphaCoverage?: boolean;

Filter base-color alpha as fractional surface coverage (e.g. fine metal mesh). Mutually exclusive with alphaTest. Rendered with mipmapped alpha blending.

alphaTest? ​
ts
optional alphaTest?: number;

Optional cutout threshold for the baked base-color alpha; omitted graphs remain opaque.

format ​
ts
format: "molen/matgraph@1";
nodes ​
ts
nodes: MatNode[];
outputs ​
ts
outputs: Partial<Record<MaterialSlot, string>>;
seed ​
ts
seed: number;
size ​
ts
size: [number, number];

PixelGridDoc ​

Properties ​

filter ​
ts
filter: "nearest" | "linear";
format ​
ts
format: "molen/pixelgrid@1";
palette ​
ts
palette: Record<string, string>;

Single-code-point key -> "transparent" or "#rrggbb"/"#rrggbbaa".

rows ​
ts
rows: string[];

Exactly size[1] rows of exactly size[0] characters.

size ​
ts
size: [number, number];
slots ​
ts
slots: object;
baseColor ​
ts
baseColor: boolean;
emissive ​
ts
emissive: boolean;

RampStop ​

Properties ​

color ​
ts
color: string;
t ​
ts
t: number;

RGBAImage ​

Properties ​

data ​
ts
data: Uint8ClampedArray;

RGBA8, row-major, length = width * height * 4.

height ​
ts
height: number;
width ​
ts
width: number;

SvgMeta ​

Properties ​

rasterSize? ​
ts
optional rasterSize?: [number, number];

Output raster size; defaults to 512×512 (POT).


SvgWasmUrl ​

Structural stand-in for the global URL — this package declares no DOM or Node lib types, so a real URL (or anything else carrying an href) matches it.

Properties ​

href ​
ts
readonly href: string;

Type Aliases ​

MaterialSlot ​

ts
type MaterialSlot = "baseColor" | "roughness" | "metalness" | "normal" | "emissive" | "ao";

MatNode ​

ts
type MatNode = 
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object
  | NodeCommon & object;

SvgWasmSource ​

ts
type SvgWasmSource = ArrayBuffer | ArrayBufferView | SvgWasmUrl | string;

Where the resvg WASM module comes from: raw bytes (Uint8Array/ArrayBuffer) or a URL — a URL object or a plain string — that is fetched. Browsers and other non-Node runtimes must supply one; Node loads its own by default.

Functions ​

applyUvPaint() ​

ts
function applyUvPaint(
   painted, 
   islandMap, 
   opts?
): RGBAImage;

Full import: mask the painted image to the islands, then dilate to fill the gutters.

Parameters ​

painted ​

RGBAImage

islandMap ​

RGBAImage

opts? ​

ApplyUvPaintOptions

Returns ​

RGBAImage


bakeMatGraph() ​

ts
function bakeMatGraph(doc): BakedMaterial;

Bake a validated material graph into per-slot RGBA textures.

The document must have been through the schema (validateByKind('matgraph', doc)) so every parameter default is applied — an unvalidated document is rejected rather than baked into a silently wrong (usually flat) texture.

Parameters ​

doc ​

MatGraphDoc

Returns ​

BakedMaterial


bakePalette() ​

ts
function bakePalette(ref, size?): BakedMaterial | undefined;

Rung 1: a flat palette color → a solid baseColor texture. Accepts "palette:#rrggbb" or "#rrggbb".

Parameters ​

ref ​

string

size? ​

number

Returns ​

BakedMaterial | undefined


bakePixelGrid() ​

ts
function bakePixelGrid(doc): BakedMaterial;

Rasterize a pixel-grid document into every slot its slots block enables (rung 2). One char = one texel; nearest filter; transparent palette entries become an alphaTest cutout. Validation errors quote row/column.

The enabled slots share one image: nothing in the pipeline mutates a baked slot (the client copies the buffer into a DataTexture, the bake worker de-duplicates buffers before transfer, the PNG writer only reads), so one grid is rasterized once however many slots point at it.

Parameters ​

doc ​

PixelGridDoc

Returns ​

BakedMaterial


bakeSvg() ​

ts
function bakeSvg(svgText, meta?): Promise<BakedMaterial>;

Rasterize an SVG document to a baseColor texture. Requires initSvg() first outside Node.

Parameters ​

svgText ​

string

meta? ​

SvgMeta

Returns ​

Promise&lt;BakedMaterial&gt;


createImage() ​

ts
function createImage(width, height): RGBAImage;

Parameters ​

width ​

number

height ​

number

Returns ​

RGBAImage


createMaterialBakeWorkerPool() ​

ts
function createMaterialBakeWorkerPool(workers, options?): MaterialBaker & object;

A bounded caller-owned pool. One graph at a time per worker; dispose terminates owned workers.

Parameters ​

workers ​

readonly MaterialBakeWorker[]

options? ​
onTiming? ​

(milliseconds) => void

Returns ​

MaterialBaker & object


dilate() ​

ts
function dilate(img, px): RGBAImage;

Push opaque colors outward into transparent gutters by px rings (nearest-valid flood).

Parameters ​

img ​

RGBAImage

px ​

number

Returns ​

RGBAImage


fbm() ​

ts
function fbm(
   base, 
   x, 
   y, 
   seed, 
   octaves, 
   lacunarity, 
   gain
): number;

Fractal Brownian motion over a base noise.

Parameters ​

base ​

(x, y, seed) => number

x ​

number

y ​

number

seed ​

number

octaves ​

number

lacunarity ​

number

gain ​

number

Returns ​

number


gradientNoise() ​

ts
function gradientNoise(
   x, 
   y, 
   seed
): number;

Gradient (Perlin-style) noise remapped to [0,1]; used for the "simplex" node kind.

Parameters ​

x ​

number

y ​

number

seed ​

number

Returns ​

number


initSvg() ​

ts
function initSvg(wasm?): Promise<void>;

Initialize the resvg WASM runtime. Idempotent: the first successful call wins and later calls (with or without a source) resolve against it.

Parameters ​

wasm? ​

SvgWasmSource

Explicit WASM source — bytes (Uint8Array/ArrayBuffer) or a URL to fetch (a URL or a string). Required in the browser and in any other non-Node runtime; omit it in Node to load the copy shipped with @resvg/resvg-wasm.

Returns ​

Promise&lt;void&gt;


installMaterialBakeWorker() ​

ts
function installMaterialBakeWorker(port): void;

Validated graph documents in, exactly the synchronous baker's pixels out.

Parameters ​

port ​

Pick&lt;MaterialBakeWorker, "postMessage" | "addEventListener"&gt;

Returns ​

void


maskToIslands() ​

ts
function maskToIslands(painted, islandMap): RGBAImage;

Clip a painted image to the island map: pixels outside any island become transparent.

Parameters ​

painted ​

RGBAImage

islandMap ​

RGBAImage

Returns ​

RGBAImage


materialBakerFingerprint() ​

ts
function materialBakerFingerprint(): string;

Identifies the rasterizers' current output, so stored results from a changed baker are never served. Computed in this thread; worker bakers run the same bundled code.

Returns ​

string


rectIslandMap() ​

ts
function rectIslandMap(
   width, 
   height, 
   x0, 
   y0, 
   x1, 
   y1
): RGBAImage;

A trivial island map for tests/demos: a filled rectangle island on a transparent background.

Parameters ​

width ​

number

height ​

number

x0 ​

number

y0 ​

number

x1 ​

number

y1 ​

number

Returns ​

RGBAImage


registerMaterialSchemas() ​

ts
function registerMaterialSchemas(): void;

Register the material schemas into the shared registry (idempotent).

Returns ​

void


valueNoise() ​

ts
function valueNoise(
   x, 
   y, 
   seed
): number;

Value noise in [0,1].

Parameters ​

x ​

number

y ​

number

seed ​

number

Returns ​

number


withBakedMaterialStore() ​

ts
function withBakedMaterialStore(baker, store): MaterialBaker;

Serve bakes from store when this baker has produced them before (on any earlier visit), and store new results. Store failures fall back to baking; they never fail a material.

Parameters ​

baker ​

MaterialBaker

store ​

BakedMaterialStore

Returns ​

MaterialBaker


worley() ​

ts
function worley(
   x, 
   y, 
   seed, 
   jitter, 
   output
): number;

Worley/cellular noise: distance to the nearest jittered feature point.

Parameters ​

x ​

number

y ​

number

seed ​

number

jitter ​

number

output ​

"f1" | "f2" | "f2-f1"

Returns ​

number

37 guides · 36 schema formats · 41 API entry points · 10 samples. API, CLI and schema pages are generated from the shipped build.