text-glyph-outlinesOfficial · by ShadereraGlyph outlines
Text from a font file as geometry: contours flattened to polylines with the original curves kept, fill triangles with holes cut correctly, and a closed extruded mesh with normals, each with per-glyph ranges so letters can move apart.
“Use the shaderera-plugins skill to add text-glyph-outlines to this film and wire it in, then run check and show me a still.”
- Type
- component · Typography
- Version
- 0.1.0 · published
- Licence
- MIT
- Built on
- No other plugins
- npm
- opentype.js 2.0.0
- earcut 3.2.3
- Used by
- Tags
- text, font, outlines, vector, triangulate, extrude, 3d text, mesh, typography, geometry
How to
use it.
Text from a font file as geometry: outlines, fill triangles and a closed extruded mesh.
import { extrude, glyphOutlines, loadFont, triangulate } from './type/outlines.ts'// in open: the file is parsed here, no host.io.font neededconst font = await loadFont(host, 'assets/fonts/IBMPlexSans-Medium.ttf')const word = glyphOutlines(font, 'SHADERERA', { size: 1, letterSpacing: 0.02 })// word.points: Float32Array of x, y; contour i is points [word.contours[i], word.contours[i + 1])// word.glyphs[6]: { x, advance, bounds, contours: [first, end), commands } for the second "E"const fill = triangulate(word) // { positions (x, y), indices, glyphs: [{ start, count }] }const solid = extrude(word, { depth: 0.15 }) // { positions, normals (x, y, z), indices, glyphs }// three.js, if the film uses it:// geometry.setAttribute('position', new THREE.BufferAttribute(solid.positions, 3))// geometry.setAttribute('normal', new THREE.BufferAttribute(solid.normals, 3))// geometry.setIndex(new THREE.BufferAttribute(solid.indices, 1))// solid.glyphs[i] is a draw range: one letter can move on its ownUnits: size is the em (1 by default), y up, origin at the baseline where the text starts; word.width, ascender and descender are in the same units for laying the text out. Curves are flattened in uniform steps so no point of the polyline strays more than tolerance (default size / 1000) from the true curve; commands keep the font's own quadratics (TrueType) or cubics (CFF), scaled and placed, for anyone who wants curves.
Winding: fill and caps are counter-clockwise seen from the outside (+z for triangulate), the front cap at z = 0 facing +z, the back cap at z = -depth. Side walls are flat-shaded per segment. Holes are found by winding and containment, not by the font's direction, so TrueType and CFF fonts both fill correctly. The solid is closed: every edge is shared by two triangles.
kerning (on by default) reads GPOS, else the kern table. variation: { wght: 700 } sets a variable font's axes. ligatures: true lets fi, fl and the like merge (off by default: one glyph per Latin character, so glyphs[i] is character i).
The same font, text and options always give the same bytes.
Limits: no bevel (walls are straight); no hinting; shaping is what opentype.js 2.0 gives (Latin, some Arabic and Thai substitutions, no mark positioning), so complex scripts may not come out right. Overlapping contours (fonts that keep overlaps) fill correctly but the solid gets walls inside it. Colour fonts give their plain outlines. opentype.d.ts declares only what this module uses; remove it if the project installs its own types. Installs opentype.js and earcut.
More in Typography
text-code-wallOfficial · by ShadereraCode wallThe project's own source as a wall of text that scrolls and jumps on the beat, glitched and scrambled, with a claim cut out of the middle.text-feature-captionsOfficial · by ShadereraFeature captionsHuge titles with a small note, several to a scene, swapping on the beat through ASCII noise, each placed anew in one of four layouts inside the safe area.text-glyph-morphOfficial · by ShadereraGlyph morphOne glyph outline or word morphing into another: contours resampled by arc length, paired outer to outer and hole to hole, a contour with no partner grown from a point, the in-between a pure function of k.text-kineticOfficial · by ShadereraKinetic typeCanvas2D text primitives: ASCII scramble, decode in and scramble out, horizontal band glitch, fit to width, hollow outlines, timecode.text-timed-cuesOfficial · by ShadereraTimed cuesLyrics, subtitles and word timings read from LRC (with word times), SRT, WebVTT and JSON (rows, cues or Whisper segments with words): the line and the word at t, times only.