Skip to content
Shapemetry

Model - Textures

API reference for src/schema/textures, src/validate/textures on @huukhanhnguyen/model, reachable from ..

See the Guide for the ModelJSON / evaluate pipeline.

API reference

Signatures are generated from the live package .d.ts - not hand-written.

Formula

type

Affine resample (rotate degrees about the tile center, scale, offset) with toroidal bilinear sampling — the tile stays a tile. Rotation happens in tile (u/v) space: on a rectangular tile it shears physically, same trade-off as every u/v-space op.

type Formula
// = (u: number, v: number, t: number, k: number) => number

ImageBuffer

type

type ImageBuffer
// = {
    /** Pixel dimensions — rectangular tiles are first-class (a 215×65 brick
     *  face keeps square physical pixels; `height` derives from the declared
     *  lengthX/lengthY aspect by default). u spans 0..1 over `width`, v over
     *  `height`. */
    width: number;
    height: number;
    /** 1 = scalar field, 4 = RGBA (0..1 floats). */
    channels: 1 | 4;
    data: Float32Array;
    /** Physical mm of ONE tile — the chain's DECLARED `lengthX`/`lengthY`
     *  builtin parameters. Attached by evaluateTexture only when declared/
     *  overridden; absent = the consumer's fallback applies (material tile,
     *  then 1000). */
    tileWidth?: number;
    tileHeight?: number;
    /** Sampling — only when the chain declared wrap/filter/uvSet. */
    wrap?: "repeat" | "clamp" | "mirror";
    filter?: "linear" | "nearest";
    uvSet?: 0 | 1;
}

textureErrors

function

textureErrors(model: ModelJSON): RegistryError[]

TextureScope

type

type TextureScope
// = {
    /** The CURRENT chain's own parameter values (its `parameters` lane,
     *  possibly rebound by a caller's argsOverride) — a texture is a function
     *  and sees ONLY its own inputs, never the host model's parameters.
     *  Numbers feed formulas; string values (wrap/filter) are sampling-only. */
    params: Record<string, number | string>;
    /** Sibling texture chains, for `blend`/`warp`/`channels` cross-references. */
    textures: Chain[];
    /** Own-parameter values for a cross-referenced sibling chain — each
     *  referenced chain evaluates with ITS OWN signature's defaults, not the
     *  referencing chain's params. Absent → referenced chains see {}. */
    paramsOf?: (chain: Chain) => Record<string, number | string>;
    /** Bitmap registry for the `image` source — decoded pixels by url,
     *  pre-loaded OUTSIDE the sync resolve (Store scan / editor upload).
     *  Absent or unknown url → image fails with a clear error. */
    imageOf?: (url: string) => TextureData | undefined;
    /** Intra-resolve memo: a chain referenced from several places (a shared
     *  height feeding both color and normal) evaluates once per resolve. */
    cache?: Map<string, ImageBuffer>;
}
Last updated: 📖 1 min readEdit on GitHub