three-text 0.2.19 → 0.3.1
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 +11 -36
- package/dist/index.cjs +185 -336
- package/dist/index.d.ts +10 -39
- package/dist/index.js +185 -336
- package/dist/index.min.cjs +709 -729
- package/dist/index.min.js +706 -726
- package/dist/index.umd.js +185 -336
- package/dist/index.umd.min.js +710 -730
- package/dist/three/index.cjs +3 -1
- package/dist/three/index.d.ts +1 -12
- package/dist/three/index.js +3 -1
- package/dist/three/react.d.ts +5 -14
- package/dist/types/core/Text.d.ts +1 -4
- package/dist/types/core/cache/GlyphGeometryBuilder.d.ts +4 -7
- package/dist/types/core/cache/sharedCaches.d.ts +6 -7
- package/dist/types/core/geometry/Extruder.d.ts +0 -1
- package/dist/types/core/shaping/TextShaper.d.ts +1 -4
- package/dist/types/core/types.d.ts +5 -7
- package/dist/types/index.d.ts +1 -1
- package/dist/types/three/index.d.ts +1 -5
- package/dist/types/utils/Cache.d.ts +14 -0
- package/dist/types/webgl/index.d.ts +12 -0
- package/dist/types/webgpu/index.d.ts +10 -0
- package/dist/webgl/index.cjs +18 -0
- package/dist/webgl/index.d.ts +12 -0
- package/dist/webgl/index.js +18 -0
- package/dist/webgpu/index.cjs +80 -1
- package/dist/webgpu/index.d.ts +10 -0
- package/dist/webgpu/index.js +80 -1
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -348,19 +348,12 @@ The library converts bezier curves into line segments by recursively subdividing
|
|
|
348
348
|
In general, this step helps more with time to first render than ongoing interactions in the scene
|
|
349
349
|
|
|
350
350
|
```javascript
|
|
351
|
-
// Using the default configuration
|
|
352
|
-
const text = await Text.create({
|
|
353
|
-
text: 'Sample text',
|
|
354
|
-
font: '/fonts/Font.ttf',
|
|
355
|
-
size: 72,
|
|
356
|
-
});
|
|
357
|
-
|
|
358
351
|
const text = await Text.create({
|
|
359
352
|
text: 'Sample text',
|
|
360
353
|
font: '/fonts/Font.ttf',
|
|
361
354
|
curveFidelity: {
|
|
362
|
-
distanceTolerance: 0.2,
|
|
363
|
-
angleTolerance: 0.1,
|
|
355
|
+
distanceTolerance: 0.2,
|
|
356
|
+
angleTolerance: 0.1,
|
|
364
357
|
},
|
|
365
358
|
});
|
|
366
359
|
```
|
|
@@ -562,13 +555,15 @@ For shader-based animations and interactive effects, the library can generate pe
|
|
|
562
555
|
const text = await Text.create({
|
|
563
556
|
text: 'Sample text',
|
|
564
557
|
font: '/fonts/Font.ttf',
|
|
565
|
-
|
|
558
|
+
perGlyphAttributes: true,
|
|
566
559
|
});
|
|
567
560
|
|
|
568
561
|
// Geometry includes these vertex attributes:
|
|
569
562
|
// - glyphCenter (vec3): center point of each glyph
|
|
570
563
|
// - glyphIndex (float): sequential glyph index
|
|
571
564
|
// - glyphLineIndex (float): line number
|
|
565
|
+
// - glyphProgress (float): normalized position (0..1) along text run
|
|
566
|
+
// - glyphBaselineY (float): Y coordinate of glyph baseline
|
|
572
567
|
```
|
|
573
568
|
|
|
574
569
|
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)
|
|
@@ -712,7 +707,7 @@ mesh.geometry.dispose();
|
|
|
712
707
|
mesh.geometry = updated.geometry;
|
|
713
708
|
```
|
|
714
709
|
|
|
715
|
-
|
|
710
|
+
For most use cases, this is primarily an API convenience over calling `create()` again
|
|
716
711
|
|
|
717
712
|
Options merge at the top level - to remove a nested property like `layout.width`, pass `{ layout: { width: undefined } }`
|
|
718
713
|
|
|
@@ -761,9 +756,8 @@ interface TextOptions {
|
|
|
761
756
|
fontVariations?: { [key: string]: number }; // Variable font axis settings
|
|
762
757
|
fontFeatures?: { [tag: string]: boolean | number }; // OpenType feature settings
|
|
763
758
|
removeOverlaps?: boolean; // Override default overlap removal (auto-enabled for VF only)
|
|
764
|
-
|
|
759
|
+
perGlyphAttributes?: boolean; // Keep per-glyph identity and add per-glyph shader attributes
|
|
765
760
|
color?: [number, number, number] | ColorOptions; // Text coloring (simple or complex)
|
|
766
|
-
// Configuration for geometry generation and layout
|
|
767
761
|
curveFidelity?: CurveFidelityConfig;
|
|
768
762
|
geometryOptimization?: GeometryOptimizationOptions;
|
|
769
763
|
layout?: LayoutOptions;
|
|
@@ -842,6 +836,8 @@ interface TextGeometryInfo {
|
|
|
842
836
|
glyphCenter: Float32Array;
|
|
843
837
|
glyphIndex: Float32Array;
|
|
844
838
|
glyphLineIndex: Float32Array;
|
|
839
|
+
glyphProgress: Float32Array;
|
|
840
|
+
glyphBaselineY: Float32Array;
|
|
845
841
|
};
|
|
846
842
|
glyphs: GlyphGeometryInfo[];
|
|
847
843
|
planeBounds: {
|
|
@@ -898,30 +894,9 @@ interface TextRange {
|
|
|
898
894
|
|
|
899
895
|
## Memory management
|
|
900
896
|
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
The shared cache is handled automatically through an LRU (Least Recently Used) policy. The default cache size is 250MB, but you can configure it per text instance. Tessellated glyphs are cached to avoid expensive recomputation when the same characters (or clusters of overlapping characters) appear multiple times
|
|
904
|
-
|
|
905
|
-
```javascript
|
|
906
|
-
const text = await Text.create({
|
|
907
|
-
text: 'Hello world',
|
|
908
|
-
font: '/fonts/font.ttf',
|
|
909
|
-
size: 72,
|
|
910
|
-
maxCacheSizeMB: 1024, // Custom cache size in MB
|
|
911
|
-
});
|
|
912
|
-
|
|
913
|
-
// Check cache performance
|
|
914
|
-
const stats = text.getCacheStatistics();
|
|
915
|
-
console.log('Cache Statistics:', {
|
|
916
|
-
hitRate: stats.hitRate, // Cache hit percentage
|
|
917
|
-
memoryUsageMB: stats.memoryUsageMB, // Memory used in MB
|
|
918
|
-
size: stats.size, // Entries in cache
|
|
919
|
-
hits: stats.hits, // Cache hits
|
|
920
|
-
misses: stats.misses // Cache misses
|
|
921
|
-
});
|
|
922
|
-
```
|
|
897
|
+
Tessellated glyphs are cached in a shared global cache to avoid recomputation when the same characters appear multiple times. Fonts are also cached and persist for the application lifetime
|
|
923
898
|
|
|
924
|
-
|
|
899
|
+
When a text mesh is no longer needed, dispose of its geometry as you would any Three.js `BufferGeometry`:
|
|
925
900
|
|
|
926
901
|
```javascript
|
|
927
902
|
textMesh.geometry.dispose();
|