Taos API Reference
    Preparing search index...

    Module text

    Engine-general SDF text rendering, reusable by any game (not just the geo map).

    Classes - Render Graph

    SdfTextPass

    Abstract base class for a render graph pass.

    Classes - Other

    ShelfPacker

    Packs same-ish-height rectangles left-to-right into shelves of a fixed-width atlas, growing the height as needed. Simple and good enough for a one-shot glyph set (not online repacking).

    Interfaces

    SdfTextDeps
    SdfTextOutputs
    SdfGlyphDraw

    A procedurally-drawn glyph (e.g. an icon) added to the atlas alongside the font glyphs: a code point to register it under (use a private-use point, 0xE000+) and a Canvas2D drawer that fills it in white, centered at (cx, cy) within radius r px. Rasterized + SDF'd exactly like a letter.

    SdfFontOptions
    AtlasGlyph

    One glyph's place in the atlas + its typesetting metrics, all in atlas pixels.

    FontMetrics

    A rasterized font: per-code-point glyphs + vertical metrics + the atlas size for UV normalizing.

    GlyphQuad

    One glyph quad: corner positions relative to the text origin (px, y-down) + atlas UVs (0..1).

    LaidOutLine

    A laid-out single line: the glyph quads (origin = pen start on the baseline) + extents.

    GlyphTrailTables

    CPU-precomputed font/word tables uploaded to GPU storage buffers so the particle glyph_trail shader can typeset words along trails without doing any string layout on the GPU. All metrics stay in atlas pixels; the shader scales them to world units.

    LabelBox

    A label's screen AABB + priority. Lower rank = more important (placed first).

    PlacedGlyph

    A glyph positioned on a road: the center of its quad + the tangent angle (radians, y-down).

    Variables

    GLYPH_FLOATS

    Floats per glyph instance: center(2) + halfSize(2) + rot(2) + uvRect(4) + color(4).

    Functions

    edt2d

    In-place 2D squared-distance transform of a width×height grid (0 = seed, INF = empty).

    computeSdf

    Signed-distance field of an alpha-coverage bitmap (width×height, values 0..1), encoded to 0..255 with 128 ≈ the glyph edge and radius controlling the spread. Inside the glyph reads above 0.5 (normalized), outside below — matching the shader's smoothstep(0.5, …).

    createSdfFontAtlas

    Rasterizes a font into an SDF atlas texture (r8unorm) + FontMetrics. Browser-only (Canvas 2D). One glyph at a time: draw padded, read its alpha, distance-transform it, shelf-pack the SDF into one big Uint8Array, then upload. Metrics place each glyph quad relative to the pen baseline.

    layoutLine

    Lays out one line of text. The origin is the pen start on the baseline; glyph quads are placed left-to-right by advance, y-up extents given by each glyph's offset. Missing glyphs are skipped but still advance by a space's width (or 0) so spacing degrades gracefully. UVs are normalized to the atlas size so the caller can swap atlas resolutions freely.

    buildGlyphTrailTables

    Lays out each word once (CPU) into flat tables the GPU glyph_trail particle node uploads as storage buffers. Per glyph it stores the atlas UV rect plus the quad's center + half-extents (all atlas px, baseline-relative, y-down); the shader places each glyph by arc length along a particle's trail and scales px → world. Words with no drawable glyphs contribute an empty run.

    declutter

    Greedy declutter: in ascending rank order, keep a label if its (padded) box doesn't overlap any already-kept box; otherwise drop it. Returns the kept ids in placement order. O(n²) — fine for the few-hundred candidates a viewport holds after frustum culling; swap for a grid if it ever isn't. Ties on rank break by id for deterministic output.

    placeGlyphsAlongLine

    Places a line of glyphs along a road polyline. Each glyph is sampled at its center's arc length, oriented to the local tangent. The text is centered on the polyline and, if the run would read right-to-left overall (tangent pointing left), the whole polyline is reversed first so labels stay upright. Returns null when the road is shorter than the text (caller skips it).