three-text 0.2.0 → 0.2.2
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 +23 -22
- package/dist/index.cjs +3 -6
- package/dist/index.js +3 -6
- package/dist/index.min.cjs +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.umd.js +3 -6
- package/dist/index.umd.min.js +2 -2
- package/dist/p5/index.cjs +92 -13
- package/dist/p5/index.d.ts +8 -2
- package/dist/p5/index.js +92 -13
- package/dist/types/p5/index.d.ts +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ A high fidelity 3D font renderer and text layout engine for the web
|
|
|
17
17
|
|
|
18
18
|
**three-text** renders and formats text from TTF, OTF, and WOFF font files as 3D geometry. It uses [TeX](https://en.wikipedia.org/wiki/TeX)-based parameters for breaking text into paragraphs across multiple lines, and turns font outlines into 3D shapes on the fly, caching their geometries for low CPU overhead in languages with lots of repeating glyphs. Variable fonts are supported as static instances at a given axis coordinate
|
|
19
19
|
|
|
20
|
-
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
|
|
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)
|
|
21
21
|
|
|
22
22
|
Under the hood, three-text relies on [HarfBuzz](https://github.com/harfbuzz/harfbuzzjs) for text shaping, [Knuth-Plass](http://www.eprg.org/G53DOC/pdfs/knuth-plass-breaking.pdf) line breaking, [Liang](https://tug.org/docs/liang/liang-thesis.pdf) hyphenation, [libtess2](https://github.com/memononen/libtess2) (based on the [OpenGL Utility Library (GLU) tessellator](https://www.songho.ca/opengl/gl_tessellation.html) by Eric Veach) for removing overlaps and triangulation, bezier curve polygonization from Maxim Shemanarev's [Anti-Grain Geometry](https://web.archive.org/web/20060128212843/http://www.antigrain.com/research/adaptive_bezier/index.html), and [Visvalingam-Whyatt](https://hull-repository.worktribe.com/preview/376364/000870493786962263.pdf) [line simplification](https://bost.ocks.org/mike/simplify/).
|
|
23
23
|
|
|
@@ -25,12 +25,12 @@ Under the hood, three-text relies on [HarfBuzz](https://github.com/harfbuzz/harf
|
|
|
25
25
|
|
|
26
26
|
- [Overview](#overview)
|
|
27
27
|
- [Getting started](#getting-started)
|
|
28
|
-
- [Three.js](#threejs
|
|
29
|
-
- [
|
|
30
|
-
- [
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
33
|
-
- [Core
|
|
28
|
+
- [Three.js](#threejs)
|
|
29
|
+
- [p5.js](#p5js)
|
|
30
|
+
- [React Three Fiber](#react-three-fiber)
|
|
31
|
+
- [WebGL](#webgl)
|
|
32
|
+
- [WebGPU](#webgpu)
|
|
33
|
+
- [Core](#core)
|
|
34
34
|
- [Development and examples](#development-and-examples)
|
|
35
35
|
- [Architecture](#architecture)
|
|
36
36
|
- [Why three-text?](#why-three-text)
|
|
@@ -70,7 +70,7 @@ three-text has a framework-agnostic core that processes fonts and generates geom
|
|
|
70
70
|
- **`three-text/three/react`** - React Three Fiber component
|
|
71
71
|
- **`three-text/webgl`** - WebGL buffer utility
|
|
72
72
|
- **`three-text/webgpu`** - WebGPU buffer utility
|
|
73
|
-
- **`three-text/p5`** - p5.js
|
|
73
|
+
- **`three-text/p5`** - p5.js adapter
|
|
74
74
|
|
|
75
75
|
Choose the import that matches your stack. Most users will use `three-text/three` or `three-text/p5`
|
|
76
76
|
|
|
@@ -97,28 +97,29 @@ scene.add(mesh);
|
|
|
97
97
|
#### p5.js
|
|
98
98
|
|
|
99
99
|
```javascript
|
|
100
|
-
import
|
|
101
|
-
import { createP5Geometry } from 'three-text/p5';
|
|
100
|
+
import 'three-text/p5';
|
|
102
101
|
|
|
103
|
-
let
|
|
102
|
+
let font;
|
|
103
|
+
let textResult;
|
|
104
|
+
|
|
105
|
+
function preload() {
|
|
106
|
+
loadThreeTextShaper('/hb/hb.wasm');
|
|
107
|
+
font = loadThreeTextFont('/fonts/Font.woff');
|
|
108
|
+
}
|
|
104
109
|
|
|
105
110
|
async function setup() {
|
|
106
111
|
createCanvas(400, 400, WEBGL);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
font: '/fonts/Font.woff',
|
|
112
|
-
size: 72
|
|
112
|
+
textResult = await createThreeTextGeometry('Hello p5!', {
|
|
113
|
+
font: font,
|
|
114
|
+
size: 72,
|
|
115
|
+
depth: 30
|
|
113
116
|
});
|
|
114
|
-
|
|
115
|
-
textGeom = createP5Geometry(window, data);
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
function draw() {
|
|
119
120
|
background(200);
|
|
120
121
|
lights();
|
|
121
|
-
model(
|
|
122
|
+
if (textResult) model(textResult.geometry);
|
|
122
123
|
}
|
|
123
124
|
```
|
|
124
125
|
|
|
@@ -244,7 +245,7 @@ three-text/
|
|
|
244
245
|
│ │ └── ThreeText.tsx # React Three Fiber component
|
|
245
246
|
│ ├── webgl/ # WebGL buffer utility
|
|
246
247
|
│ ├── webgpu/ # WebGPU buffer utility
|
|
247
|
-
│ ├── p5/ # p5.js
|
|
248
|
+
│ ├── p5/ # p5.js adapter
|
|
248
249
|
│ ├── hyphenation/ # Language-specific hyphenation patterns
|
|
249
250
|
│ └── utils/ # Performance logging, data structures
|
|
250
251
|
├── examples/ # Demos for all adapters
|
|
@@ -961,7 +962,7 @@ The build generates multiple module formats for core and all adapters:
|
|
|
961
962
|
- `dist/three/react.js` - React component
|
|
962
963
|
- `dist/webgl/` - WebGL utility
|
|
963
964
|
- `dist/webgpu/` - WebGPU utility
|
|
964
|
-
- `dist/p5/` - p5.js
|
|
965
|
+
- `dist/p5/` - p5.js adapter
|
|
965
966
|
|
|
966
967
|
**Patterns:**
|
|
967
968
|
- `dist/patterns/` - Hyphenation patterns (ESM and UMD)
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* three-text v0.2.
|
|
2
|
+
* three-text v0.2.2
|
|
3
3
|
* Copyright (C) 2025 Countertype LLC
|
|
4
4
|
*
|
|
5
5
|
* This program is free software: you can redistribute it and/or modify
|
|
@@ -4173,7 +4173,7 @@ class Extruder {
|
|
|
4173
4173
|
const triangleIndices = triangulatedData.indices;
|
|
4174
4174
|
for (let i = 0; i < points.length; i += 2) {
|
|
4175
4175
|
vertices.push(points[i], points[i + 1], 0);
|
|
4176
|
-
normals.push(0, 0, 1);
|
|
4176
|
+
normals.push(0, 0, -1);
|
|
4177
4177
|
}
|
|
4178
4178
|
// Add triangle indices
|
|
4179
4179
|
for (let i = 0; i < triangleIndices.length; i++) {
|
|
@@ -6784,13 +6784,10 @@ class Text {
|
|
|
6784
6784
|
planeBounds.min.x = alignmentResult.adjustedBounds.min.x;
|
|
6785
6785
|
planeBounds.max.x = alignmentResult.adjustedBounds.max.x;
|
|
6786
6786
|
const finalScale = size / this.loadedFont.upem;
|
|
6787
|
-
// Scale vertices
|
|
6787
|
+
// Scale vertices only (normals are unit vectors, don't scale)
|
|
6788
6788
|
for (let i = 0; i < vertices.length; i++) {
|
|
6789
6789
|
vertices[i] *= finalScale;
|
|
6790
6790
|
}
|
|
6791
|
-
for (let i = 0; i < normals.length; i++) {
|
|
6792
|
-
normals[i] *= finalScale;
|
|
6793
|
-
}
|
|
6794
6791
|
planeBounds.min.x *= finalScale;
|
|
6795
6792
|
planeBounds.min.y *= finalScale;
|
|
6796
6793
|
planeBounds.min.z *= finalScale;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* three-text v0.2.
|
|
2
|
+
* three-text v0.2.2
|
|
3
3
|
* Copyright (C) 2025 Countertype LLC
|
|
4
4
|
*
|
|
5
5
|
* This program is free software: you can redistribute it and/or modify
|
|
@@ -4170,7 +4170,7 @@ class Extruder {
|
|
|
4170
4170
|
const triangleIndices = triangulatedData.indices;
|
|
4171
4171
|
for (let i = 0; i < points.length; i += 2) {
|
|
4172
4172
|
vertices.push(points[i], points[i + 1], 0);
|
|
4173
|
-
normals.push(0, 0, 1);
|
|
4173
|
+
normals.push(0, 0, -1);
|
|
4174
4174
|
}
|
|
4175
4175
|
// Add triangle indices
|
|
4176
4176
|
for (let i = 0; i < triangleIndices.length; i++) {
|
|
@@ -6781,13 +6781,10 @@ class Text {
|
|
|
6781
6781
|
planeBounds.min.x = alignmentResult.adjustedBounds.min.x;
|
|
6782
6782
|
planeBounds.max.x = alignmentResult.adjustedBounds.max.x;
|
|
6783
6783
|
const finalScale = size / this.loadedFont.upem;
|
|
6784
|
-
// Scale vertices
|
|
6784
|
+
// Scale vertices only (normals are unit vectors, don't scale)
|
|
6785
6785
|
for (let i = 0; i < vertices.length; i++) {
|
|
6786
6786
|
vertices[i] *= finalScale;
|
|
6787
6787
|
}
|
|
6788
|
-
for (let i = 0; i < normals.length; i++) {
|
|
6789
|
-
normals[i] *= finalScale;
|
|
6790
|
-
}
|
|
6791
6788
|
planeBounds.min.x *= finalScale;
|
|
6792
6789
|
planeBounds.min.y *= finalScale;
|
|
6793
6790
|
planeBounds.min.z *= finalScale;
|