three-text 0.5.2 → 0.6.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/LICENSE_THIRD_PARTY +15 -0
- package/README.md +73 -42
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/three/react.d.ts +2 -0
- package/dist/types/core/types.d.ts +2 -33
- package/dist/types/vector/{core.d.ts → core/index.d.ts} +8 -7
- package/dist/types/vector/index.d.ts +22 -25
- package/dist/types/vector/react.d.ts +4 -3
- package/dist/types/vector/slug/SlugPacker.d.ts +2 -0
- package/dist/types/vector/slug/curveUtils.d.ts +6 -0
- package/dist/types/vector/slug/index.d.ts +8 -0
- package/dist/types/vector/slug/shaderStrings.d.ts +4 -0
- package/dist/types/vector/slug/slugGLSL.d.ts +21 -0
- package/dist/types/vector/slug/slugTSL.d.ts +13 -0
- package/dist/types/vector/slug/types.d.ts +30 -0
- package/dist/types/vector/slug/unpackVertices.d.ts +11 -0
- package/dist/types/vector/webgl/index.d.ts +7 -3
- package/dist/types/vector/webgpu/index.d.ts +4 -4
- package/dist/vector/core/index.cjs +856 -0
- package/dist/vector/core/index.d.ts +63 -0
- package/dist/vector/core/index.js +854 -0
- package/dist/vector/core.cjs +4419 -240
- package/dist/vector/core.d.ts +361 -71
- package/dist/vector/core.js +4406 -226
- package/dist/vector/index.cjs +5 -229
- package/dist/vector/index.d.ts +45 -396
- package/dist/vector/index.js +3 -223
- package/dist/vector/index2.cjs +287 -0
- package/dist/vector/index2.js +264 -0
- package/dist/vector/react.cjs +37 -8
- package/dist/vector/react.d.ts +6 -3
- package/dist/vector/react.js +18 -8
- package/dist/vector/slugTSL.cjs +252 -0
- package/dist/vector/slugTSL.js +231 -0
- package/dist/vector/webgl/index.cjs +131 -201
- package/dist/vector/webgl/index.d.ts +19 -44
- package/dist/vector/webgl/index.js +131 -201
- package/dist/vector/webgpu/index.cjs +100 -283
- package/dist/vector/webgpu/index.d.ts +16 -45
- package/dist/vector/webgpu/index.js +100 -283
- package/package.json +6 -1
- package/dist/types/vector/GlyphVectorGeometryBuilder.d.ts +0 -26
- package/dist/types/vector/LoopBlinnGeometry.d.ts +0 -68
- package/dist/types/vector/loopBlinnTSL.d.ts +0 -22
- package/dist/vector/loopBlinnTSL.cjs +0 -229
- package/dist/vector/loopBlinnTSL.js +0 -207
package/dist/vector/index.cjs
CHANGED
|
@@ -1,234 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var
|
|
3
|
+
require('./core/index.cjs');
|
|
4
|
+
var index = require('./index2.cjs');
|
|
5
|
+
require('three');
|
|
5
6
|
|
|
6
|
-
const CONTOUR_EPSILON = 0.001;
|
|
7
|
-
const CURVE_LINEARITY_EPSILON = 1e-5;
|
|
8
|
-
function nearlyEqual(a, b, epsilon) {
|
|
9
|
-
return Math.abs(a - b) < epsilon;
|
|
10
|
-
}
|
|
11
|
-
function extractContours(segments) {
|
|
12
|
-
const contours = [];
|
|
13
|
-
let contourVertices = [];
|
|
14
|
-
let contourSegments = [];
|
|
15
|
-
const pushCurrentContour = () => {
|
|
16
|
-
if (contourVertices.length < 3) {
|
|
17
|
-
contourVertices = [];
|
|
18
|
-
contourSegments = [];
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const first = contourVertices[0];
|
|
22
|
-
const last = contourVertices[contourVertices.length - 1];
|
|
23
|
-
if (nearlyEqual(first.x, last.x, CONTOUR_EPSILON) &&
|
|
24
|
-
nearlyEqual(first.y, last.y, CONTOUR_EPSILON)) {
|
|
25
|
-
contourVertices.pop();
|
|
26
|
-
}
|
|
27
|
-
if (contourVertices.length >= 3) {
|
|
28
|
-
contours.push({
|
|
29
|
-
vertices: contourVertices,
|
|
30
|
-
segments: contourSegments
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
contourVertices = [];
|
|
34
|
-
contourSegments = [];
|
|
35
|
-
};
|
|
36
|
-
for (const segment of segments) {
|
|
37
|
-
if (contourVertices.length === 0) {
|
|
38
|
-
contourVertices.push({ x: segment.p0x, y: segment.p0y }, { x: segment.p2x, y: segment.p2y });
|
|
39
|
-
contourSegments.push(segment);
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
const previousEnd = contourVertices[contourVertices.length - 1];
|
|
43
|
-
if (nearlyEqual(segment.p0x, previousEnd.x, CONTOUR_EPSILON) &&
|
|
44
|
-
nearlyEqual(segment.p0y, previousEnd.y, CONTOUR_EPSILON)) {
|
|
45
|
-
contourVertices.push({ x: segment.p2x, y: segment.p2y });
|
|
46
|
-
contourSegments.push(segment);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
pushCurrentContour();
|
|
50
|
-
contourVertices.push({ x: segment.p0x, y: segment.p0y }, { x: segment.p2x, y: segment.p2y });
|
|
51
|
-
contourSegments.push(segment);
|
|
52
|
-
}
|
|
53
|
-
pushCurrentContour();
|
|
54
|
-
return contours;
|
|
55
|
-
}
|
|
56
|
-
function triangulateContourFan(vertices, offsetX, offsetY, positions, indices) {
|
|
57
|
-
const baseIndex = positions.length / 3;
|
|
58
|
-
for (const vertex of vertices) {
|
|
59
|
-
positions.push(vertex.x + offsetX, vertex.y + offsetY, 0);
|
|
60
|
-
}
|
|
61
|
-
if (vertices.length < 3)
|
|
62
|
-
return 0;
|
|
63
|
-
for (let index = 1; index < vertices.length - 1; index++) {
|
|
64
|
-
indices.push(baseIndex, baseIndex + index, baseIndex + index + 1);
|
|
65
|
-
}
|
|
66
|
-
return vertices.length - 2;
|
|
67
|
-
}
|
|
68
|
-
function shouldSkipCurveSegment(segment) {
|
|
69
|
-
const dx = segment.p2x - segment.p0x;
|
|
70
|
-
const dy = segment.p2y - segment.p0y;
|
|
71
|
-
const lenSq = dx * dx + dy * dy;
|
|
72
|
-
if (lenSq <= 0)
|
|
73
|
-
return true;
|
|
74
|
-
const cross = (segment.p1x - segment.p0x) * dy - (segment.p1y - segment.p0y) * dx;
|
|
75
|
-
return Math.abs(cross) < CURVE_LINEARITY_EPSILON * lenSq;
|
|
76
|
-
}
|
|
77
|
-
function fillGlyphAttrs(center, idx, progress, lineIdx, baselineY, vertCount, gc, gi, gp, gl, gb) {
|
|
78
|
-
for (let v = 0; v < vertCount; v++) {
|
|
79
|
-
gc.push(center[0], center[1], center[2]);
|
|
80
|
-
gi.push(idx);
|
|
81
|
-
gp.push(progress);
|
|
82
|
-
gl.push(lineIdx);
|
|
83
|
-
gb.push(baselineY);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function packAttrs(gc, gi, gp, gl, gb) {
|
|
87
|
-
return {
|
|
88
|
-
glyphCenter: new Float32Array(gc),
|
|
89
|
-
glyphIndex: new Float32Array(gi),
|
|
90
|
-
glyphProgress: new Float32Array(gp),
|
|
91
|
-
glyphLineIndex: new Float32Array(gl),
|
|
92
|
-
glyphBaselineY: new Float32Array(gb)
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function buildVectorGeometry(input) {
|
|
96
|
-
const interiorPositions = [];
|
|
97
|
-
const interiorIndices = [];
|
|
98
|
-
const curvePositions = [];
|
|
99
|
-
const iGC = [], iGI = [], iGP = [], iGL = [], iGB = [];
|
|
100
|
-
const cGC = [], cGI = [], cGP = [], cGL = [], cGB = [];
|
|
101
|
-
const fGC = [], fGI = [], fGP = [], fGL = [], fGB = [];
|
|
102
|
-
const glyphCount = input.glyphs.length;
|
|
103
|
-
let contourCount = 0;
|
|
104
|
-
let interiorTriangleCount = 0;
|
|
105
|
-
let curveTriangleCount = 0;
|
|
106
|
-
const glyphRanges = [];
|
|
107
|
-
const fillPositions = new Float32Array(glyphCount * 12);
|
|
108
|
-
const fillIndices = new Uint32Array(glyphCount * 6);
|
|
109
|
-
for (let i = 0; i < glyphCount; i++) {
|
|
110
|
-
const glyph = input.glyphs[i];
|
|
111
|
-
const { minX, minY, maxX, maxY } = glyph.bounds;
|
|
112
|
-
const cx = glyph.offsetX + (minX + maxX) * 0.5;
|
|
113
|
-
const cy = glyph.offsetY + (minY + maxY) * 0.5;
|
|
114
|
-
const center = [cx, cy, 0];
|
|
115
|
-
const progress = glyphCount > 1 ? i / (glyphCount - 1) : 0;
|
|
116
|
-
const intIdxStart = interiorIndices.length;
|
|
117
|
-
const curveVertStart = curvePositions.length / 3;
|
|
118
|
-
const contours = extractContours(glyph.segments);
|
|
119
|
-
contourCount += contours.length;
|
|
120
|
-
for (const contour of contours) {
|
|
121
|
-
const intVertsBefore = interiorPositions.length / 3;
|
|
122
|
-
interiorTriangleCount += triangulateContourFan(contour.vertices, glyph.offsetX, glyph.offsetY, interiorPositions, interiorIndices);
|
|
123
|
-
const intVertsAfter = interiorPositions.length / 3;
|
|
124
|
-
fillGlyphAttrs(center, i, progress, glyph.lineIndex, glyph.baselineY, intVertsAfter - intVertsBefore, iGC, iGI, iGP, iGL, iGB);
|
|
125
|
-
for (const segment of contour.segments) {
|
|
126
|
-
if (shouldSkipCurveSegment(segment))
|
|
127
|
-
continue;
|
|
128
|
-
curvePositions.push(glyph.offsetX + segment.p0x, glyph.offsetY + segment.p0y, 0, glyph.offsetX + segment.p1x, glyph.offsetY + segment.p1y, 0, glyph.offsetX + segment.p2x, glyph.offsetY + segment.p2y, 0);
|
|
129
|
-
curveTriangleCount++;
|
|
130
|
-
fillGlyphAttrs(center, i, progress, glyph.lineIndex, glyph.baselineY, 3, cGC, cGI, cGP, cGL, cGB);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
glyphRanges.push({
|
|
134
|
-
interiorIndexStart: intIdxStart,
|
|
135
|
-
interiorIndexCount: interiorIndices.length - intIdxStart,
|
|
136
|
-
curveVertexStart: curveVertStart,
|
|
137
|
-
curveVertexCount: (curvePositions.length / 3) - curveVertStart
|
|
138
|
-
});
|
|
139
|
-
const fp = i * 12;
|
|
140
|
-
fillPositions[fp] = glyph.offsetX + minX;
|
|
141
|
-
fillPositions[fp + 1] = glyph.offsetY + minY;
|
|
142
|
-
fillPositions[fp + 2] = 0;
|
|
143
|
-
fillPositions[fp + 3] = glyph.offsetX + maxX;
|
|
144
|
-
fillPositions[fp + 4] = glyph.offsetY + minY;
|
|
145
|
-
fillPositions[fp + 5] = 0;
|
|
146
|
-
fillPositions[fp + 6] = glyph.offsetX + maxX;
|
|
147
|
-
fillPositions[fp + 7] = glyph.offsetY + maxY;
|
|
148
|
-
fillPositions[fp + 8] = 0;
|
|
149
|
-
fillPositions[fp + 9] = glyph.offsetX + minX;
|
|
150
|
-
fillPositions[fp + 10] = glyph.offsetY + maxY;
|
|
151
|
-
fillPositions[fp + 11] = 0;
|
|
152
|
-
fillGlyphAttrs(center, i, progress, glyph.lineIndex, glyph.baselineY, 4, fGC, fGI, fGP, fGL, fGB);
|
|
153
|
-
const fi = i * 6;
|
|
154
|
-
const fv = i * 4;
|
|
155
|
-
fillIndices[fi] = fv;
|
|
156
|
-
fillIndices[fi + 1] = fv + 1;
|
|
157
|
-
fillIndices[fi + 2] = fv + 2;
|
|
158
|
-
fillIndices[fi + 3] = fv;
|
|
159
|
-
fillIndices[fi + 4] = fv + 2;
|
|
160
|
-
fillIndices[fi + 5] = fv + 3;
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
interiorPositions: new Float32Array(interiorPositions),
|
|
164
|
-
interiorIndices: new Uint32Array(interiorIndices),
|
|
165
|
-
curvePositions: new Float32Array(curvePositions),
|
|
166
|
-
fillPositions,
|
|
167
|
-
fillIndices,
|
|
168
|
-
glyphRanges,
|
|
169
|
-
interiorGlyphAttrs: packAttrs(iGC, iGI, iGP, iGL, iGB),
|
|
170
|
-
curveGlyphAttrs: packAttrs(cGC, cGI, cGP, cGL, cGB),
|
|
171
|
-
fillGlyphAttrs: packAttrs(fGC, fGI, fGP, fGL, fGB),
|
|
172
|
-
planeBounds: input.planeBounds,
|
|
173
|
-
stats: {
|
|
174
|
-
glyphCount,
|
|
175
|
-
contourCount,
|
|
176
|
-
interiorTriangleCount,
|
|
177
|
-
curveTriangleCount
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
7
|
|
|
182
|
-
function wrapResult(coreResult, opts) {
|
|
183
|
-
const meshes = loopBlinnTSL.createVectorMeshes(coreResult.geometryData, {
|
|
184
|
-
color: opts.color,
|
|
185
|
-
positionNode: opts.positionNode,
|
|
186
|
-
colorNode: opts.colorNode,
|
|
187
|
-
center: opts.center,
|
|
188
|
-
});
|
|
189
|
-
return {
|
|
190
|
-
glyphs: coreResult.glyphs,
|
|
191
|
-
geometryData: coreResult.geometryData,
|
|
192
|
-
group: meshes.group,
|
|
193
|
-
interiorGeometry: meshes.interiorGeometry,
|
|
194
|
-
curveGeometry: meshes.curveGeometry,
|
|
195
|
-
fillGeometry: meshes.fillGeometry,
|
|
196
|
-
query: coreResult.query,
|
|
197
|
-
getLoadedFont: coreResult.getLoadedFont,
|
|
198
|
-
measureTextWidth: coreResult.measureTextWidth,
|
|
199
|
-
updateMaterials: meshes.updateMaterials,
|
|
200
|
-
async update(newOptions) {
|
|
201
|
-
const newCore = await coreResult.update(newOptions);
|
|
202
|
-
return wrapResult(newCore, { ...opts, ...newOptions });
|
|
203
|
-
},
|
|
204
|
-
dispose() {
|
|
205
|
-
meshes.dispose();
|
|
206
|
-
coreResult.dispose();
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
class Text {
|
|
211
|
-
static { this.setHarfBuzzPath = core.Text.setHarfBuzzPath; }
|
|
212
|
-
static { this.setHarfBuzzBuffer = core.Text.setHarfBuzzBuffer; }
|
|
213
|
-
static { this.init = core.Text.init; }
|
|
214
|
-
static { this.registerPattern = core.Text.registerPattern; }
|
|
215
|
-
static { this.preloadPatterns = core.Text.preloadPatterns; }
|
|
216
|
-
static { this.setMaxFontCacheMemoryMB = core.Text.setMaxFontCacheMemoryMB; }
|
|
217
|
-
static { this.enableWoff2 = core.Text.enableWoff2; }
|
|
218
|
-
static async create(options) {
|
|
219
|
-
const coreResult = await core.Text.create(options);
|
|
220
|
-
return wrapResult(coreResult, options);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
8
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
get: function () { return loopBlinnTSL.createVectorMeshes; }
|
|
227
|
-
});
|
|
228
|
-
Object.defineProperty(exports, 'loopBlinnFragment', {
|
|
229
|
-
enumerable: true,
|
|
230
|
-
get: function () { return loopBlinnTSL.loopBlinnFragment; }
|
|
231
|
-
});
|
|
232
|
-
exports.Text = Text;
|
|
233
|
-
exports.buildVectorGeometry = buildVectorGeometry;
|
|
234
|
-
exports.extractContours = extractContours;
|
|
9
|
+
exports.Text = index.Text;
|
|
10
|
+
exports.createSlugGLSLMesh = index.createSlugGLSLMesh;
|