three-text 0.2.18 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![TypeScript](https://img.shields.io/badge/built%20with-TypeScript-007acc.svg)](https://www.typescriptlang.org/)
5
5
  [![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3_or_later-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
6
6
 
7
- A high fidelity 3D font renderer and text layout engine for the web
7
+ High fidelity 3D mesh font geometry and text layout engine for the web
8
8
 
9
9
  ![Screenshot of three-text example file](https://countertype.com/assets/three-text/3D.png)
10
10
 
@@ -15,11 +15,7 @@ A high fidelity 3D font renderer and text layout engine for the web
15
15
  > [!CAUTION]
16
16
  > three-text is an alpha release and the API may break rapidly. This warning will last at least through the end of 2025. If API stability is important to you, consider pinning your version. Community feedback is encouraged; please open an issue if you have any suggestions or feedback, thank you
17
17
 
18
-
19
- text: `three-text is a 3D font geometry and text layout library for the web. Its supports TTF, OTF, and WOFF font files. For layout, it uses Tex-based parameters for breaking text into paragraphs across multiple lines and supports CJK and RTL scripts. three-text caches the geometries it generates for low CPU overhead in languages with lots of repeating glyphs. Variable fonts are supported as static instances at a given axis coordinate, and can be animated by re-drawing each frame with new coordinates. The library has a framework-agnostic core that returns raw vertex data, with lightweight adapters for Three.js, React Three Fiber, p5.js, WebGL and WebGPU. Under the hood, three-text relies on HarfBuzz for text shaping, Knuth-Plass line breaking, Liang hyphenation, libtess by Eric Veach for tessellation, curve polygonization from Maxim Shemanarev's Anti-Grain Geometry, and Visvalingam-Whyatt line simplification`,
20
-
21
-
22
- **three-text** is a 3D font geometry and text layout library for the web. It supports TTF, OTF, and WOFF font files. For layout, it uses [TeX](https://en.wikipedia.org/wiki/TeX)-based parameters for breaking text into paragraphs across multiple lines and supports CJK and RTL scripts. three-text caches the geometries it generates for low CPU overhead in languages with lots of repeating glyphs. Variable fonts are supported as static instances at a given axis coordinate, and can be animated by re-drawing each frame with new coordinates
18
+ **three-text** is a 3D mesh font geometry and text layout library for the web. It supports TTF, OTF, and WOFF font files. For layout, it uses [TeX](https://en.wikipedia.org/wiki/TeX)-based parameters for breaking text into paragraphs across multiple lines and supports CJK and RTL scripts. three-text caches the geometries it generates for low CPU overhead in languages with lots of repeating glyphs. Variable fonts are supported as static instances at a given axis coordinate, and can be animated by re-drawing each frame with new coordinates
23
19
 
24
20
  The library has a framework-agnostic core that returns raw vertex data, with lightweight adapters for [Three.js](https://threejs.org), [React Three Fiber](https://docs.pmnd.rs/react-three-fiber), [p5.js](https://p5js.org), [WebGL](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API), and [WebGPU](https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API)
25
21
 
@@ -556,7 +552,7 @@ const text = await Text.create({
556
552
 
557
553
  Values can be boolean (`true`/`false`) to enable or disable, or numeric for features accepting variant indices. Explicitly disabling a feature overrides the font's defaults
558
554
 
559
- Common tags include [`liga`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#liga) (ligatures), [`kern`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#kern) (kerning), [`calt`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ae#calt) (contextual alternates), and [`smcp`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt#smcp) (small capitals). Number styling uses [`lnum`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#lnum)/[`onum`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#onum)/[`tnum`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt#tnum). Stylistic alternates are [`ss01`-`ss20`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt#ss01--ss20) and [`cv01`-`cv99`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ae#cv01--cv99). Feature availability depends on the font
555
+ Common tags include [`liga`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#liga) (ligatures), [`calt`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ae#calt) (contextual alternates), [`tnum`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt#tnum) (tabular numbers), sylistic alternates [`ss01`-`ss20`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt#ss01--ss20) and character variants [`cv01`-`cv99`](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ae#cv01--cv99). Feature availability depends on the font
560
556
 
561
557
  ### Per-glyph attributes
562
558
 
@@ -566,13 +562,15 @@ For shader-based animations and interactive effects, the library can generate pe
566
562
  const text = await Text.create({
567
563
  text: 'Sample text',
568
564
  font: '/fonts/Font.ttf',
569
- separateGlyphsWithAttributes: true,
565
+ perGlyphAttributes: true,
570
566
  });
571
567
 
572
568
  // Geometry includes these vertex attributes:
573
569
  // - glyphCenter (vec3): center point of each glyph
574
570
  // - glyphIndex (float): sequential glyph index
575
571
  // - glyphLineIndex (float): line number
572
+ // - glyphProgress (float): normalized position (0..1) along text run
573
+ // - glyphBaselineY (float): Y coordinate of glyph baseline
576
574
  ```
577
575
 
578
576
  This option bypasses overlap-based clustering and adds vertex attributes suitable for per-character manipulation in vertex shaders. Each unique glyph is still tessellated only once and cached for reuse. The tradeoff is potential visual artifacts where glyphs actually overlap (tight kerning, cursive scripts)
@@ -736,6 +734,10 @@ Initializes HarfBuzz WebAssembly. Called automatically by `create()`, but can be
736
734
 
737
735
  Preloads hyphenation patterns for specified languages. Useful for avoiding async pattern loading during text rendering
738
736
 
737
+ ##### `Text.setMaxFontCacheMemoryMB(limitMB: number): void`
738
+
739
+ Sets an upper bound for the font cache, measured by the raw font buffer size, eviction is FIFO by insertion order
740
+
739
741
  #### Instance Methods
740
742
 
741
743
  The following methods are available on instances created by `Text.create()`:
@@ -753,7 +755,7 @@ Below are the most important configuration interfaces. For a complete list of al
753
755
  ```typescript
754
756
  interface TextOptions {
755
757
  text: string; // Text content to render
756
- font?: string | ArrayBuffer; // Font file path or buffer (TTF, OTF, or WOFF)
758
+ font: string | ArrayBuffer; // Font file path or buffer (TTF, OTF, or WOFF)
757
759
  size?: number; // Font size in scene units (default: 72)
758
760
  depth?: number; // Extrusion depth (default: 0)
759
761
  lineHeight?: number; // Line height multiplier (default: 1.0)
@@ -761,7 +763,7 @@ interface TextOptions {
761
763
  fontVariations?: { [key: string]: number }; // Variable font axis settings
762
764
  fontFeatures?: { [tag: string]: boolean | number }; // OpenType feature settings
763
765
  removeOverlaps?: boolean; // Override default overlap removal (auto-enabled for VF only)
764
- separateGlyphsWithAttributes?: boolean; // Force individual glyph tessellation and add shader attributes
766
+ perGlyphAttributes?: boolean; // Keep per-glyph identity and add per-glyph shader attributes
765
767
  color?: [number, number, number] | ColorOptions; // Text coloring (simple or complex)
766
768
  // Configuration for geometry generation and layout
767
769
  curveFidelity?: CurveFidelityConfig;
@@ -842,6 +844,8 @@ interface TextGeometryInfo {
842
844
  glyphCenter: Float32Array;
843
845
  glyphIndex: Float32Array;
844
846
  glyphLineIndex: Float32Array;
847
+ glyphProgress: Float32Array;
848
+ glyphBaselineY: Float32Array;
845
849
  };
846
850
  glyphs: GlyphGeometryInfo[];
847
851
  planeBounds: {