ultra-text 1.0.1 → 1.0.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 +224 -1002
- package/dist/assets/{cpuSdf.worker-xS57yQbP.js → cpuSdf.worker--X1Qpmdp.js} +136 -47
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +67 -25
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +3 -2
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +152 -40
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +100 -276
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +47 -241
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.js +103 -58
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +224 -284
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +75 -151
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.js +27 -9
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +150 -48
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +369 -204
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +11 -3
- package/dist/slug/SlugMaterial.js +54 -10
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +16 -12
- package/dist/slug/coverage.js +194 -221
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +5 -1
- package/dist/slug/preprocessCore.js +118 -87
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +90 -44
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +75 -40
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.js +166 -193
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +5 -1453
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +6 -6
- package/dist/text/GlyphTextMaterial.d.ts +1 -1
- package/dist/text/GlyphTextMaterial.js +5 -5
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.js +7 -5
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +6 -1473
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +113 -40
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +9 -4
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +3 -1
- package/dist/windfoil/runtime.js +62 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/storage.d.ts +60 -2
- package/dist/windfoil/storage.js +142 -6
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +167 -43
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +471 -175
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +55 -30
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.js +59 -34
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +11 -11
- package/skills/ultra-text/references/three-tsl.md +2 -2
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
- package/dist/slug-vanilla.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
|
@@ -8,20 +8,15 @@
|
|
|
8
8
|
* encoded endpoint.
|
|
9
9
|
*/
|
|
10
10
|
const FAR_DISTANCE_SQUARED = 0x56bc75e2d63100000;
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
function assertInputs(alpha, width, height, pxRange) {
|
|
18
|
-
if (!(alpha instanceof Uint8Array) && !(alpha instanceof Uint8ClampedArray)) throw new TypeError("encodeSdfFromAlpha: alpha must be a Uint8Array or Uint8ClampedArray");
|
|
19
|
-
if (!Number.isInteger(width) || width <= 0) throw new RangeError("encodeSdfFromAlpha: width must be a positive integer");
|
|
20
|
-
if (!Number.isInteger(height) || height <= 0) throw new RangeError("encodeSdfFromAlpha: height must be a positive integer");
|
|
11
|
+
const LITTLE_ENDIAN = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
|
|
12
|
+
function assertInputs(pixels, width, height, pxRange, stride, name) {
|
|
13
|
+
if (!(pixels instanceof Uint8Array) && !(pixels instanceof Uint8ClampedArray)) throw new TypeError(`${name}: alpha must be a Uint8Array or Uint8ClampedArray`);
|
|
14
|
+
if (!Number.isInteger(width) || width <= 0) throw new RangeError(`${name}: width must be a positive integer`);
|
|
15
|
+
if (!Number.isInteger(height) || height <= 0) throw new RangeError(`${name}: height must be a positive integer`);
|
|
21
16
|
const pixelCount = width * height;
|
|
22
|
-
if (!Number.isSafeInteger(pixelCount)) throw new RangeError(
|
|
23
|
-
if (
|
|
24
|
-
if (!Number.isFinite(pxRange) || pxRange <= 0) throw new RangeError(
|
|
17
|
+
if (!Number.isSafeInteger(pixelCount)) throw new RangeError(`${name}: width * height exceeds the safe integer range`);
|
|
18
|
+
if (pixels.length !== pixelCount * stride) throw new RangeError(`${name}: alpha length ${pixels.length} does not match ${stride === 1 ? "width * height" : "width * height * 4"} (${pixelCount * stride})`);
|
|
19
|
+
if (!Number.isFinite(pxRange) || pxRange <= 0) throw new RangeError(`${name}: pxRange must be a positive finite number`);
|
|
25
20
|
return pixelCount;
|
|
26
21
|
}
|
|
27
22
|
let edtMinOut = 0;
|
|
@@ -149,28 +144,81 @@ function horizontalRowDistances(alpha, alphaRow, distances, distRow, width, firs
|
|
|
149
144
|
const lEnd = lCov < 0 ? a - 1 : mid < a + maxRadius - 1 ? mid : a + maxRadius - 1;
|
|
150
145
|
const rStart = rCov < 0 ? x + 1 : mid + 1 > x - maxRadius + 1 ? mid + 1 : x - maxRadius + 1;
|
|
151
146
|
for (let p = a, d = 1; p <= lEnd; p++, d++) distances[distRow + p] = sign * (d * d + lCost);
|
|
152
|
-
if (lEnd + 1 < rStart)
|
|
147
|
+
if (lEnd + 1 < rStart) {
|
|
148
|
+
const far = sign * FAR_DISTANCE_SQUARED;
|
|
149
|
+
if (rStart - lEnd <= 17) for (let p = lEnd + 1; p < rStart; p++) distances[distRow + p] = far;
|
|
150
|
+
else distances.fill(far, distRow + lEnd + 1, distRow + rStart);
|
|
151
|
+
}
|
|
153
152
|
for (let p = rStart, d = x + 1 - rStart; p <= x; p++, d--) distances[distRow + p] = sign * (d * d + rCost);
|
|
154
153
|
} else distances[distRow + x] = SEED_COST[coverage];
|
|
155
154
|
}
|
|
156
155
|
return lastNonZero;
|
|
157
156
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
157
|
+
function horizontalRgbaRowDistancesU32(u32, pixelRow, distances, distRow, width, firstNonZero, maxRadius) {
|
|
158
|
+
let lastNonZero = width - 1;
|
|
159
|
+
for (let x = 0; x < width; x++) {
|
|
160
|
+
const coverage = u32[pixelRow + x] >>> 24;
|
|
161
|
+
if (coverage === 0 || coverage === 255) {
|
|
162
|
+
const a = x;
|
|
163
|
+
if (x === 0 && firstNonZero > 0) x = firstNonZero - 1;
|
|
164
|
+
else while (x + 1 < width && u32[pixelRow + x + 1] >>> 24 === coverage) x++;
|
|
165
|
+
const isZero = coverage === 0;
|
|
166
|
+
if (isZero && x === width - 1) lastNonZero = a - 1;
|
|
167
|
+
const sign = isZero ? 1 : -1;
|
|
168
|
+
const lCov = a > 0 ? u32[pixelRow + a - 1] >>> 24 : -1;
|
|
169
|
+
const rCov = x + 1 < width ? u32[pixelRow + x + 1] >>> 24 : -1;
|
|
170
|
+
const lSc = lCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[lCov];
|
|
171
|
+
const rSc = rCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[rCov];
|
|
172
|
+
const lCost = lSc > 0 ? lSc : 0;
|
|
173
|
+
const rCost = rSc > 0 ? rSc : 0;
|
|
174
|
+
const mid = rCov < 0 ? x : lCov < 0 ? a - 1 : a + x - (rCost < lCost ? 1 : 0) >> 1;
|
|
175
|
+
const lEnd = lCov < 0 ? a - 1 : mid < a + maxRadius - 1 ? mid : a + maxRadius - 1;
|
|
176
|
+
const rStart = rCov < 0 ? x + 1 : mid + 1 > x - maxRadius + 1 ? mid + 1 : x - maxRadius + 1;
|
|
177
|
+
for (let p = a, d = 1; p <= lEnd; p++, d++) distances[distRow + p] = sign * (d * d + lCost);
|
|
178
|
+
if (lEnd + 1 < rStart) {
|
|
179
|
+
const far = sign * FAR_DISTANCE_SQUARED;
|
|
180
|
+
if (rStart - lEnd <= 17) for (let p = lEnd + 1; p < rStart; p++) distances[distRow + p] = far;
|
|
181
|
+
else distances.fill(far, distRow + lEnd + 1, distRow + rStart);
|
|
182
|
+
}
|
|
183
|
+
for (let p = rStart, d = x + 1 - rStart; p <= x; p++, d--) distances[distRow + p] = sign * (d * d + rCost);
|
|
184
|
+
} else distances[distRow + x] = SEED_COST[coverage];
|
|
185
|
+
}
|
|
186
|
+
return lastNonZero;
|
|
187
|
+
}
|
|
188
|
+
function horizontalRgbaRowDistances(rgba, rgbaRowBase, distances, distRow, width, firstNonZero, maxRadius) {
|
|
189
|
+
let lastNonZero = width - 1;
|
|
190
|
+
for (let x = 0; x < width; x++) {
|
|
191
|
+
const coverage = rgba[rgbaRowBase + (x << 2) + 3];
|
|
192
|
+
if (coverage === 0 || coverage === 255) {
|
|
193
|
+
const a = x;
|
|
194
|
+
if (x === 0 && firstNonZero > 0) x = firstNonZero - 1;
|
|
195
|
+
else while (x + 1 < width && rgba[rgbaRowBase + (x + 1 << 2) + 3] === coverage) x++;
|
|
196
|
+
const isZero = coverage === 0;
|
|
197
|
+
if (isZero && x === width - 1) lastNonZero = a - 1;
|
|
198
|
+
const sign = isZero ? 1 : -1;
|
|
199
|
+
const lCov = a > 0 ? rgba[rgbaRowBase + (a - 1 << 2) + 3] : -1;
|
|
200
|
+
const rCov = x + 1 < width ? rgba[rgbaRowBase + (x + 1 << 2) + 3] : -1;
|
|
201
|
+
const lSc = lCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[lCov];
|
|
202
|
+
const rSc = rCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[rCov];
|
|
203
|
+
const lCost = lSc > 0 ? lSc : 0;
|
|
204
|
+
const rCost = rSc > 0 ? rSc : 0;
|
|
205
|
+
const mid = rCov < 0 ? x : lCov < 0 ? a - 1 : a + x - (rCost < lCost ? 1 : 0) >> 1;
|
|
206
|
+
const lEnd = lCov < 0 ? a - 1 : mid < a + maxRadius - 1 ? mid : a + maxRadius - 1;
|
|
207
|
+
const rStart = rCov < 0 ? x + 1 : mid + 1 > x - maxRadius + 1 ? mid + 1 : x - maxRadius + 1;
|
|
208
|
+
for (let p = a, d = 1; p <= lEnd; p++, d++) distances[distRow + p] = sign * (d * d + lCost);
|
|
209
|
+
if (lEnd + 1 < rStart) {
|
|
210
|
+
const far = sign * FAR_DISTANCE_SQUARED;
|
|
211
|
+
if (rStart - lEnd <= 17) for (let p = lEnd + 1; p < rStart; p++) distances[distRow + p] = far;
|
|
212
|
+
else distances.fill(far, distRow + lEnd + 1, distRow + rStart);
|
|
213
|
+
}
|
|
214
|
+
for (let p = rStart, d = x + 1 - rStart; p <= x; p++, d--) distances[distRow + p] = sign * (d * d + rCost);
|
|
215
|
+
} else distances[distRow + x] = SEED_COST[coverage];
|
|
216
|
+
}
|
|
217
|
+
return lastNonZero;
|
|
218
|
+
}
|
|
219
|
+
function encodeSdf(pixels, width, height, pxRange, stride) {
|
|
220
|
+
const pixelCount = assertInputs(pixels, width, height, pxRange, stride, stride === 1 ? "encodeSdfFromAlpha" : "encodeSdfFromRgba");
|
|
221
|
+
const isRgba = stride === 4;
|
|
174
222
|
const encoded = new Uint8Array(pixelCount);
|
|
175
223
|
const scale255 = 255 / pxRange;
|
|
176
224
|
const clampSqDist = .25 * pxRange * pxRange * (1 + 1e-6);
|
|
@@ -196,7 +244,7 @@ function encodeSdfFromAlpha(alpha, width, height, pxRange) {
|
|
|
196
244
|
inside.fill(sentinel, 0, height);
|
|
197
245
|
outside.fill(0, 0, height);
|
|
198
246
|
const lastRow = height - 1;
|
|
199
|
-
const u32 = (
|
|
247
|
+
const u32 = (!isRgba || LITTLE_ENDIAN) && (pixels.byteOffset & 3) === 0 ? new Uint32Array(pixels.buffer, pixels.byteOffset, pixels.byteLength >>> 2) : null;
|
|
200
248
|
let anyNonZero = false;
|
|
201
249
|
let scanY = 0;
|
|
202
250
|
while (scanY < height) {
|
|
@@ -205,16 +253,35 @@ function encodeSdfFromAlpha(alpha, width, height, pxRange) {
|
|
|
205
253
|
let bandMaxX = -1;
|
|
206
254
|
let lastActiveY = -1;
|
|
207
255
|
for (; scanY < height; scanY++) {
|
|
208
|
-
const
|
|
256
|
+
const pixelRow = scanY * width;
|
|
209
257
|
let firstNonZero = 0;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
258
|
+
let lastNonZero = -1;
|
|
259
|
+
if (!isRgba) {
|
|
260
|
+
if (u32 !== null && (pixelRow & 3) === 0) {
|
|
261
|
+
const wStart = pixelRow >>> 2;
|
|
262
|
+
const wEnd = wStart + (width >>> 2);
|
|
263
|
+
let w = wStart;
|
|
264
|
+
while (w < wEnd && u32[w] === 0) w++;
|
|
265
|
+
firstNonZero = w - wStart << 2;
|
|
266
|
+
}
|
|
267
|
+
while (firstNonZero < width && pixels[pixelRow + firstNonZero] === 0) firstNonZero++;
|
|
268
|
+
if (firstNonZero < width) {
|
|
269
|
+
anyNonZero = true;
|
|
270
|
+
lastNonZero = horizontalRowDistances(pixels, pixelRow, distances, bandCount * distStride, width, firstNonZero, maxRadius);
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
const rgbaRowBase = pixelRow << 2;
|
|
274
|
+
if (u32 !== null) {
|
|
275
|
+
const pEnd = pixelRow + width;
|
|
276
|
+
let p = pixelRow;
|
|
277
|
+
while (p < pEnd && u32[p] >>> 24 === 0) p++;
|
|
278
|
+
firstNonZero = p - pixelRow;
|
|
279
|
+
} else while (firstNonZero < width && pixels[rgbaRowBase + (firstNonZero << 2) + 3] === 0) firstNonZero++;
|
|
280
|
+
if (firstNonZero < width) {
|
|
281
|
+
anyNonZero = true;
|
|
282
|
+
lastNonZero = u32 !== null ? horizontalRgbaRowDistancesU32(u32, pixelRow, distances, bandCount * distStride, width, firstNonZero, maxRadius) : horizontalRgbaRowDistances(pixels, rgbaRowBase, distances, bandCount * distStride, width, firstNonZero, maxRadius);
|
|
283
|
+
}
|
|
216
284
|
}
|
|
217
|
-
while (firstNonZero < width && alpha[alphaRow + firstNonZero] === 0) firstNonZero++;
|
|
218
285
|
if (firstNonZero === width) {
|
|
219
286
|
if (!skipEmptyRows) {
|
|
220
287
|
const distRow = bandCount * distStride;
|
|
@@ -227,8 +294,6 @@ function encodeSdfFromAlpha(alpha, width, height, pxRange) {
|
|
|
227
294
|
}
|
|
228
295
|
continue;
|
|
229
296
|
}
|
|
230
|
-
anyNonZero = true;
|
|
231
|
-
const lastNonZero = horizontalRowDistances(alpha, alphaRow, distances, bandCount * distStride, width, firstNonZero, maxRadius);
|
|
232
297
|
activeRows[bandCount++] = scanY;
|
|
233
298
|
lastActiveY = scanY;
|
|
234
299
|
if (firstNonZero < bandMinX) bandMinX = firstNonZero;
|
|
@@ -243,6 +308,7 @@ function encodeSdfFromAlpha(alpha, width, height, pxRange) {
|
|
|
243
308
|
return encoded;
|
|
244
309
|
}
|
|
245
310
|
const firstActiveY = activeRows[0];
|
|
311
|
+
const contiguousBand = lastActiveY - firstActiveY === bandCount - 1;
|
|
246
312
|
const bandMinY = skipEmptyRows ? firstActiveY > maxRadius ? firstActiveY - maxRadius : 0 : 0;
|
|
247
313
|
const bandMaxY = skipEmptyRows ? lastActiveY + maxRadius < lastRow ? lastActiveY + maxRadius : lastRow : lastRow;
|
|
248
314
|
const bandHeight = bandMaxY - bandMinY + 1;
|
|
@@ -256,12 +322,26 @@ function encodeSdfFromAlpha(alpha, width, height, pxRange) {
|
|
|
256
322
|
offset += distStride;
|
|
257
323
|
}
|
|
258
324
|
if (r === bandCount) continue;
|
|
259
|
-
const firstInSeed = activeRows[r];
|
|
325
|
+
const firstInSeed = contiguousBand ? firstActiveY + r : activeRows[r];
|
|
260
326
|
let lastInSeed = firstInSeed;
|
|
261
327
|
let firstNeg = -1;
|
|
262
328
|
let lastNeg = -1;
|
|
263
329
|
let negCount = 0;
|
|
264
|
-
for (; r < bandCount; r++, offset += distStride) {
|
|
330
|
+
if (contiguousBand) for (; r < bandCount; r++, offset += distStride) {
|
|
331
|
+
const distance = distances[offset];
|
|
332
|
+
if (distance >= clampSqDist) continue;
|
|
333
|
+
const y = firstActiveY + r;
|
|
334
|
+
lastInSeed = y;
|
|
335
|
+
if (distance >= 0) inside[y] = distance;
|
|
336
|
+
else {
|
|
337
|
+
inside[y] = 0;
|
|
338
|
+
outside[y] = -distance;
|
|
339
|
+
if (firstNeg < 0) firstNeg = y;
|
|
340
|
+
lastNeg = y;
|
|
341
|
+
negCount++;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
else for (; r < bandCount; r++, offset += distStride) {
|
|
265
345
|
const distance = distances[offset];
|
|
266
346
|
if (distance >= clampSqDist) continue;
|
|
267
347
|
const y = activeRows[r];
|
|
@@ -304,19 +384,28 @@ function encodeSdfFromAlpha(alpha, width, height, pxRange) {
|
|
|
304
384
|
const inSq = inside[y];
|
|
305
385
|
if (inSq < clampSqDist) encoded[idx] = 128 - Math.sqrt(inSq) * scale255 | 0;
|
|
306
386
|
}
|
|
307
|
-
|
|
387
|
+
if (lastNeg - firstNeg < 16) for (let c = firstNeg; c <= lastNeg; c++) outside[c] = 0;
|
|
388
|
+
else outside.fill(0, firstNeg, lastNeg + 1);
|
|
308
389
|
}
|
|
309
|
-
|
|
390
|
+
if (yEnd - yStart < 16) for (let c = yStart; c <= yEnd; c++) inside[c] = sentinel;
|
|
391
|
+
else inside.fill(sentinel, yStart, yEnd + 1);
|
|
310
392
|
}
|
|
311
393
|
}
|
|
312
394
|
if (scratchDistances.length > 45e5) scratchDistances = /* @__PURE__ */ new Float32Array(0);
|
|
313
395
|
return encoded;
|
|
314
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* @internal Equivalent to `encodeSdfFromAlpha(alphaOfRgba(rgba, width * height), ...)`,
|
|
399
|
+
* reading the alpha channel directly from packed RGBA bytes without an intermediate buffer.
|
|
400
|
+
*/
|
|
401
|
+
function encodeSdfFromRgba(rgba, width, height, pxRange) {
|
|
402
|
+
return encodeSdf(rgba, width, height, pxRange, 4);
|
|
403
|
+
}
|
|
315
404
|
// src/atlas/cpuSdf.worker.ts
|
|
316
405
|
const scope = globalThis;
|
|
317
406
|
scope.onmessage = ({ data }) => {
|
|
318
|
-
const result =
|
|
407
|
+
const result = encodeSdfFromRgba(data.rgba, data.width, data.height, data.pxRange);
|
|
319
408
|
scope.postMessage(result, [result.buffer]);
|
|
320
409
|
};
|
|
321
410
|
|
|
322
|
-
//# sourceMappingURL=cpuSdf.worker
|
|
411
|
+
//# sourceMappingURL=cpuSdf.worker--X1Qpmdp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cpuSdf.worker--X1Qpmdp.js","names":[],"sources":["../../src/atlas/cpuSdf.ts","../../src/atlas/cpuSdf.worker.ts"],"sourcesContent":["/**\n * A finite stand-in for infinity in the squared-distance grids.\n *\n * Keeping the sentinel finite avoids `Infinity - Infinity` while constructing\n * the lower envelope of parabolas. Its square root is far beyond any practical\n * atlas extent, so missing inside/outside pixels still saturate at the correct\n * encoded endpoint.\n */\nconst FAR_DISTANCE_SQUARED = 1e20\n\ntype AlphaPixels = Uint8Array | Uint8ClampedArray\n\nconst LITTLE_ENDIAN = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1\n\n/** The alpha byte of each RGBA pixel, as the encoder reads coverage. */\nexport function alphaOfRgba(rgba: Uint8ClampedArray, pixelCount: number): Uint8Array {\n const alpha = new Uint8Array(pixelCount)\n for (let source = 3, target = 0; target < pixelCount; source += 4, target++) {\n alpha[target] = rgba[source]!\n }\n return alpha\n}\n\nfunction assertInputs(\n pixels: AlphaPixels,\n width: number,\n height: number,\n pxRange: number,\n stride: 1 | 4,\n name: string,\n): number {\n if (!(pixels instanceof Uint8Array) && !(pixels instanceof Uint8ClampedArray)) {\n throw new TypeError(`${name}: alpha must be a Uint8Array or Uint8ClampedArray`)\n }\n if (!Number.isInteger(width) || width <= 0) {\n throw new RangeError(`${name}: width must be a positive integer`)\n }\n if (!Number.isInteger(height) || height <= 0) {\n throw new RangeError(`${name}: height must be a positive integer`)\n }\n\n const pixelCount = width * height\n if (!Number.isSafeInteger(pixelCount)) {\n throw new RangeError(`${name}: width * height exceeds the safe integer range`)\n }\n if (pixels.length !== pixelCount * stride) {\n throw new RangeError(\n `${name}: alpha length ${pixels.length} does not match ${stride === 1 ? 'width * height' : 'width * height * 4'} (${pixelCount * stride})`,\n )\n }\n if (!Number.isFinite(pxRange) || pxRange <= 0) {\n throw new RangeError(`${name}: pxRange must be a positive finite number`)\n }\n\n return pixelCount\n}\n\nlet edtMinOut = 0\nlet edtMaxOut = -1\n\n/**\n * Exact one-dimensional squared Euclidean distance transform.\n *\n * This is the lower-envelope algorithm from Felzenszwalb and Huttenlocher. It\n * runs in O(length), performs no allocations, and accepts non-zero seed costs\n * so fractional alpha coverage can place the glyph edge between pixel centres.\n * The envelope retains the original costs before writing back into the grid,\n * avoiding a copy of each column in both directions.\n */\nfunction edt1d(\n grid: Float32Array,\n startSeed: number,\n endSeed: number,\n outStart: number,\n outEnd: number,\n clampSqDist: number,\n maxRadius: number,\n): void {\n let first = startSeed\n while (first <= endSeed && grid[first]! >= clampSqDist) first++\n if (first > endSeed) {\n edtMinOut = outEnd + 1\n edtMaxOut = outStart - 1\n return\n }\n\n const firstCost = grid[first]!\n if (first === outStart) {\n let different = first + 1\n if (firstCost <= 1) {\n while (different <= endSeed && grid[different]! <= 1) different++\n } else {\n while (different <= endSeed && grid[different] === firstCost) different++\n }\n // A constant line or a line of immediate seeds (cost <= 1) is already its own distance transform.\n if (different > endSeed && endSeed >= outEnd) {\n edtMinOut = outStart\n edtMaxOut = outEnd\n return\n }\n }\n\n const parabolaIndices = scratchParabolaIndices\n const parabolaCosts = scratchParabolaCosts\n const parabolaOffsets = scratchParabolaOffsets\n const boundaries = scratchBoundaries\n let envelopeEnd = 0\n parabolaIndices[0] = first\n parabolaCosts[0] = firstCost\n parabolaOffsets[0] = firstCost + first * first\n\n for (let q = first + 1; q <= endSeed; q++) {\n let cost = grid[q]!\n if (cost >= clampSqDist) {\n while (q < endSeed && grid[q + 1]! >= clampSqDist) q++\n continue\n }\n if (cost <= 1 && grid[q - 1]! <= 1) {\n while (q < endSeed && grid[q + 1]! <= 1) q++\n cost = grid[q]!\n } else if (cost === grid[q - 1]!) {\n while (q < endSeed && grid[q + 1] === cost) q++\n }\n const costPlusQSquared = cost + q * q\n while (\n envelopeEnd > 0 &&\n costPlusQSquared - parabolaOffsets[envelopeEnd]! <=\n boundaries[envelopeEnd]! * (q - parabolaIndices[envelopeEnd]!)\n ) {\n envelopeEnd--\n }\n const twiceIntersection =\n (costPlusQSquared - parabolaOffsets[envelopeEnd]!) / (q - parabolaIndices[envelopeEnd]!)\n\n envelopeEnd++\n parabolaIndices[envelopeEnd] = q\n parabolaCosts[envelopeEnd] = cost\n parabolaOffsets[envelopeEnd] = costPlusQSquared\n boundaries[envelopeEnd] = twiceIntersection\n }\n\n const minOut = first - maxRadius > outStart ? first - maxRadius : outStart\n const lastSeed = parabolaIndices[envelopeEnd]!\n const maxOut = lastSeed + maxRadius < outEnd ? lastSeed + maxRadius : outEnd\n let b0 = minOut\n for (let e = 0; e <= envelopeEnd; e++) {\n const b1 = e === envelopeEnd ? maxOut : Math.floor(boundaries[e + 1]! * 0.5)\n if (b1 >= b0) {\n const nearest = parabolaIndices[e]!\n const cost = parabolaCosts[e]!\n const r0 = nearest - maxRadius\n const r1 = nearest + maxRadius\n const s1 = maxOut < b1 ? maxOut : b1\n const segStart = b0 > r0 ? b0 : r0\n const segEnd = s1 < r1 ? s1 : r1\n for (let q = segStart; q <= segEnd; q++) {\n const cur = grid[q]!\n if (cur <= 1) continue\n const delta = q - nearest\n const d = delta * delta + cost\n if (d < cur) grid[q] = d\n }\n b0 = b1 + 1\n if (b0 > maxOut) break\n }\n }\n edtMinOut = minOut\n edtMaxOut = maxOut\n}\n\nconst SEED_COST = Float32Array.from({ length: 256 }, (_, coverage) => {\n const edgeOffset = 0.5 - coverage / 255\n const sq = Math.fround(edgeOffset * edgeOffset)\n return coverage < 128 ? sq : -sq\n})\n\nlet scratchDistances = new Float32Array(0)\nlet scratchParabolaIndices = new Int32Array(0)\nlet scratchParabolaCosts = new Float32Array(0)\nlet scratchParabolaOffsets = new Float64Array(0)\nlet scratchBoundaries = new Float64Array(0)\nlet scratchInside = new Float32Array(0)\nlet scratchOutside = new Float32Array(0)\nlet scratchActiveRows = new Int32Array(0)\n\n/**\n * Alpha seeds cost less than 0.25. A closer seed therefore always beats a\n * farther seed in the same direction (squared integer distances differ by at\n * least one). Each empty or solid run is bounded by at most one seed on each\n * side, so one pass splits each run at its midpoint and fills both ends.\n */\nfunction horizontalRowDistances(\n alpha: AlphaPixels,\n alphaRow: number,\n distances: Float32Array,\n distRow: number,\n width: number,\n firstNonZero: number,\n maxRadius: number,\n): number {\n let lastNonZero = width - 1\n for (let x = 0; x < width; x++) {\n const coverage = alpha[alphaRow + x]!\n if (coverage === 0 || coverage === 255) {\n const a = x\n if (x === 0 && firstNonZero > 0) x = firstNonZero - 1\n else while (x + 1 < width && alpha[alphaRow + x + 1] === coverage) x++\n const isZero = coverage === 0\n if (isZero && x === width - 1) lastNonZero = a - 1\n const sign = isZero ? 1 : -1\n const lCov = a > 0 ? alpha[alphaRow + a - 1]! : -1\n const rCov = x + 1 < width ? alpha[alphaRow + x + 1]! : -1\n const lSc = lCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[lCov]!\n const rSc = rCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[rCov]!\n const lCost = lSc > 0 ? lSc : 0\n const rCost = rSc > 0 ? rSc : 0\n const mid = rCov < 0 ? x : lCov < 0 ? a - 1 : (a + x - (rCost < lCost ? 1 : 0)) >> 1\n const lEnd = lCov < 0 ? a - 1 : mid < a + maxRadius - 1 ? mid : a + maxRadius - 1\n const rStart = rCov < 0 ? x + 1 : mid + 1 > x - maxRadius + 1 ? mid + 1 : x - maxRadius + 1\n for (let p = a, d = 1; p <= lEnd; p++, d++) {\n distances[distRow + p] = sign * (d * d + lCost)\n }\n if (lEnd + 1 < rStart) {\n const far = sign * FAR_DISTANCE_SQUARED\n if (rStart - lEnd <= 17) {\n for (let p = lEnd + 1; p < rStart; p++) distances[distRow + p] = far\n } else {\n distances.fill(far, distRow + lEnd + 1, distRow + rStart)\n }\n }\n for (let p = rStart, d = x + 1 - rStart; p <= x; p++, d--) {\n distances[distRow + p] = sign * (d * d + rCost)\n }\n } else {\n distances[distRow + x] = SEED_COST[coverage]!\n }\n }\n return lastNonZero\n}\n\nfunction horizontalRgbaRowDistancesU32(\n u32: Uint32Array,\n pixelRow: number,\n distances: Float32Array,\n distRow: number,\n width: number,\n firstNonZero: number,\n maxRadius: number,\n): number {\n let lastNonZero = width - 1\n for (let x = 0; x < width; x++) {\n const coverage = u32[pixelRow + x]! >>> 24\n if (coverage === 0 || coverage === 255) {\n const a = x\n if (x === 0 && firstNonZero > 0) x = firstNonZero - 1\n else while (x + 1 < width && u32[pixelRow + x + 1]! >>> 24 === coverage) x++\n const isZero = coverage === 0\n if (isZero && x === width - 1) lastNonZero = a - 1\n const sign = isZero ? 1 : -1\n const lCov = a > 0 ? u32[pixelRow + a - 1]! >>> 24 : -1\n const rCov = x + 1 < width ? u32[pixelRow + x + 1]! >>> 24 : -1\n const lSc = lCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[lCov]!\n const rSc = rCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[rCov]!\n const lCost = lSc > 0 ? lSc : 0\n const rCost = rSc > 0 ? rSc : 0\n const mid = rCov < 0 ? x : lCov < 0 ? a - 1 : (a + x - (rCost < lCost ? 1 : 0)) >> 1\n const lEnd = lCov < 0 ? a - 1 : mid < a + maxRadius - 1 ? mid : a + maxRadius - 1\n const rStart = rCov < 0 ? x + 1 : mid + 1 > x - maxRadius + 1 ? mid + 1 : x - maxRadius + 1\n for (let p = a, d = 1; p <= lEnd; p++, d++) {\n distances[distRow + p] = sign * (d * d + lCost)\n }\n if (lEnd + 1 < rStart) {\n const far = sign * FAR_DISTANCE_SQUARED\n if (rStart - lEnd <= 17) {\n for (let p = lEnd + 1; p < rStart; p++) distances[distRow + p] = far\n } else {\n distances.fill(far, distRow + lEnd + 1, distRow + rStart)\n }\n }\n for (let p = rStart, d = x + 1 - rStart; p <= x; p++, d--) {\n distances[distRow + p] = sign * (d * d + rCost)\n }\n } else {\n distances[distRow + x] = SEED_COST[coverage]!\n }\n }\n return lastNonZero\n}\n\nfunction horizontalRgbaRowDistances(\n rgba: AlphaPixels,\n rgbaRowBase: number,\n distances: Float32Array,\n distRow: number,\n width: number,\n firstNonZero: number,\n maxRadius: number,\n): number {\n let lastNonZero = width - 1\n for (let x = 0; x < width; x++) {\n const coverage = rgba[rgbaRowBase + (x << 2) + 3]!\n if (coverage === 0 || coverage === 255) {\n const a = x\n if (x === 0 && firstNonZero > 0) x = firstNonZero - 1\n else while (x + 1 < width && rgba[rgbaRowBase + ((x + 1) << 2) + 3] === coverage) x++\n const isZero = coverage === 0\n if (isZero && x === width - 1) lastNonZero = a - 1\n const sign = isZero ? 1 : -1\n const lCov = a > 0 ? rgba[rgbaRowBase + ((a - 1) << 2) + 3]! : -1\n const rCov = x + 1 < width ? rgba[rgbaRowBase + ((x + 1) << 2) + 3]! : -1\n const lSc = lCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[lCov]!\n const rSc = rCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[rCov]!\n const lCost = lSc > 0 ? lSc : 0\n const rCost = rSc > 0 ? rSc : 0\n const mid = rCov < 0 ? x : lCov < 0 ? a - 1 : (a + x - (rCost < lCost ? 1 : 0)) >> 1\n const lEnd = lCov < 0 ? a - 1 : mid < a + maxRadius - 1 ? mid : a + maxRadius - 1\n const rStart = rCov < 0 ? x + 1 : mid + 1 > x - maxRadius + 1 ? mid + 1 : x - maxRadius + 1\n for (let p = a, d = 1; p <= lEnd; p++, d++) {\n distances[distRow + p] = sign * (d * d + lCost)\n }\n if (lEnd + 1 < rStart) {\n const far = sign * FAR_DISTANCE_SQUARED\n if (rStart - lEnd <= 17) {\n for (let p = lEnd + 1; p < rStart; p++) distances[distRow + p] = far\n } else {\n distances.fill(far, distRow + lEnd + 1, distRow + rStart)\n }\n }\n for (let p = rStart, d = x + 1 - rStart; p <= x; p++, d--) {\n distances[distRow + p] = sign * (d * d + rCost)\n }\n } else {\n distances[distRow + x] = SEED_COST[coverage]!\n }\n }\n return lastNonZero\n}\n\nfunction encodeSdf(\n pixels: AlphaPixels,\n width: number,\n height: number,\n pxRange: number,\n stride: 1 | 4,\n): Uint8Array {\n const pixelCount = assertInputs(\n pixels,\n width,\n height,\n pxRange,\n stride,\n stride === 1 ? 'encodeSdfFromAlpha' : 'encodeSdfFromRgba',\n )\n const isRgba = stride === 4\n const encoded = new Uint8Array(pixelCount)\n const scale255 = 255 / pxRange\n const clampSqDist = 0.25 * pxRange * pxRange * (1 + 1e-6)\n const skipEmptyRows = clampSqDist <= FAR_DISTANCE_SQUARED\n const maxRadius = skipEmptyRows ? Math.ceil(0.5 * pxRange + 1) : width > height ? width : height\n // Pad power-of-two widths by one 64-byte cache line (16 floats) so vertical\n // column gathers do not alias onto the same L1 cache set on every row.\n const distStride = (width & 63) === 0 ? width + 16 : width\n const requiredDistances = distStride * height\n if (scratchDistances.length < requiredDistances) {\n scratchDistances = new Float32Array(requiredDistances)\n }\n if (scratchParabolaIndices.length < height) {\n scratchParabolaIndices = new Int32Array(height)\n scratchParabolaCosts = new Float32Array(height)\n scratchParabolaOffsets = new Float64Array(height)\n scratchBoundaries = new Float64Array(height)\n scratchInside = new Float32Array(height)\n scratchOutside = new Float32Array(height)\n scratchActiveRows = new Int32Array(height)\n }\n const distances = scratchDistances\n const activeRows = scratchActiveRows\n const inside = scratchInside\n const outside = scratchOutside\n const sentinel = skipEmptyRows ? FAR_DISTANCE_SQUARED : clampSqDist\n inside.fill(sentinel, 0, height)\n outside.fill(0, 0, height)\n const lastRow = height - 1\n const u32 =\n (!isRgba || LITTLE_ENDIAN) && (pixels.byteOffset & 3) === 0\n ? new Uint32Array(pixels.buffer, pixels.byteOffset, pixels.byteLength >>> 2)\n : null\n\n let anyNonZero = false\n let scanY = 0\n while (scanY < height) {\n let bandCount = 0\n let bandMinX = width\n let bandMaxX = -1\n let lastActiveY = -1\n for (; scanY < height; scanY++) {\n const pixelRow = scanY * width\n let firstNonZero = 0\n let lastNonZero = -1\n if (!isRgba) {\n if (u32 !== null && (pixelRow & 3) === 0) {\n const wStart = pixelRow >>> 2\n const wEnd = wStart + (width >>> 2)\n let w = wStart\n while (w < wEnd && u32[w] === 0) w++\n firstNonZero = (w - wStart) << 2\n }\n while (firstNonZero < width && pixels[pixelRow + firstNonZero] === 0) firstNonZero++\n if (firstNonZero < width) {\n anyNonZero = true\n lastNonZero = horizontalRowDistances(\n pixels,\n pixelRow,\n distances,\n bandCount * distStride,\n width,\n firstNonZero,\n maxRadius,\n )\n }\n } else {\n const rgbaRowBase = pixelRow << 2\n if (u32 !== null) {\n const pEnd = pixelRow + width\n let p = pixelRow\n while (p < pEnd && u32[p]! >>> 24 === 0) p++\n firstNonZero = p - pixelRow\n } else {\n while (firstNonZero < width && pixels[rgbaRowBase + (firstNonZero << 2) + 3] === 0) {\n firstNonZero++\n }\n }\n if (firstNonZero < width) {\n anyNonZero = true\n lastNonZero =\n u32 !== null\n ? horizontalRgbaRowDistancesU32(\n u32,\n pixelRow,\n distances,\n bandCount * distStride,\n width,\n firstNonZero,\n maxRadius,\n )\n : horizontalRgbaRowDistances(\n pixels,\n rgbaRowBase,\n distances,\n bandCount * distStride,\n width,\n firstNonZero,\n maxRadius,\n )\n }\n }\n if (firstNonZero === width) {\n if (!skipEmptyRows) {\n const distRow = bandCount * distStride\n distances.fill(FAR_DISTANCE_SQUARED, distRow, distRow + width)\n activeRows[bandCount++] = scanY\n lastActiveY = scanY\n } else if (bandCount > 0 && scanY - lastActiveY >= 2 * maxRadius) {\n scanY++\n break\n }\n continue\n }\n activeRows[bandCount++] = scanY\n lastActiveY = scanY\n if (firstNonZero < bandMinX) bandMinX = firstNonZero\n if (lastNonZero > bandMaxX) bandMaxX = lastNonZero\n }\n\n if (bandCount === 0) break\n if (!anyNonZero) {\n const byte = 128 - Math.sqrt(FAR_DISTANCE_SQUARED) * scale255\n const fillByte = byte <= 0 ? 0 : byte | 0\n if (fillByte !== 0) encoded.fill(fillByte)\n if (scratchDistances.length > 4_500_000) scratchDistances = new Float32Array(0)\n return encoded\n }\n\n const firstActiveY = activeRows[0]!\n const contiguousBand = lastActiveY - firstActiveY === bandCount - 1\n const bandMinY = skipEmptyRows ? (firstActiveY > maxRadius ? firstActiveY - maxRadius : 0) : 0\n const bandMaxY = skipEmptyRows\n ? lastActiveY + maxRadius < lastRow\n ? lastActiveY + maxRadius\n : lastRow\n : lastRow\n const bandHeight = bandMaxY - bandMinY + 1\n const colStart = skipEmptyRows ? (bandMinX > maxRadius ? bandMinX - maxRadius : 0) : 0\n const colEnd = skipEmptyRows\n ? bandMaxX + maxRadius < width - 1\n ? bandMaxX + maxRadius\n : width - 1\n : width - 1\n\n for (let x = colStart; x <= colEnd; x++) {\n let r = 0\n let offset = x\n while (r < bandCount && distances[offset]! >= clampSqDist) {\n r++\n offset += distStride\n }\n if (r === bandCount) continue\n const firstInSeed = contiguousBand ? firstActiveY + r : activeRows[r]!\n let lastInSeed = firstInSeed\n let firstNeg = -1\n let lastNeg = -1\n let negCount = 0\n // Avoid activeRows[r] indirection when the vertical band has no skipped empty rows.\n if (contiguousBand) {\n for (; r < bandCount; r++, offset += distStride) {\n const distance = distances[offset]!\n if (distance >= clampSqDist) continue\n const y = firstActiveY + r\n lastInSeed = y\n if (distance >= 0) {\n inside[y] = distance\n } else {\n inside[y] = 0\n outside[y] = -distance\n if (firstNeg < 0) firstNeg = y\n lastNeg = y\n negCount++\n }\n }\n } else {\n for (; r < bandCount; r++, offset += distStride) {\n const distance = distances[offset]!\n if (distance >= clampSqDist) continue\n const y = activeRows[r]!\n lastInSeed = y\n if (distance >= 0) {\n inside[y] = distance\n } else {\n inside[y] = 0\n outside[y] = -distance\n if (firstNeg < 0) firstNeg = y\n lastNeg = y\n negCount++\n }\n }\n }\n let yStart = bandMinY\n let yEnd = bandMaxY\n if (negCount < bandHeight) {\n edt1d(inside, firstInSeed, lastInSeed, bandMinY, bandMaxY, clampSqDist, maxRadius)\n yStart = edtMinOut\n yEnd = edtMaxOut\n }\n const pureInEnd = firstNeg < 0 ? yEnd : firstNeg - 1\n let y = yStart\n let idx = y * width + x\n for (; y <= pureInEnd; y++, idx += width) {\n const inSq = inside[y]!\n if (inSq < clampSqDist) encoded[idx] = (128 - Math.sqrt(inSq) * scale255) | 0\n }\n if (firstNeg >= 0) {\n edt1d(\n outside,\n firstNeg > 0 ? firstNeg - 1 : 0,\n lastNeg < lastRow ? lastNeg + 1 : lastRow,\n firstNeg,\n lastNeg,\n clampSqDist,\n maxRadius,\n )\n for (; y <= lastNeg; y++, idx += width) {\n const inSq = inside[y]!\n if (inSq > 0) {\n if (inSq < clampSqDist) encoded[idx] = (128 - Math.sqrt(inSq) * scale255) | 0\n } else {\n const outSq = outside[y]!\n encoded[idx] = outSq >= clampSqDist ? 255 : (128 + Math.sqrt(outSq) * scale255) | 0\n }\n }\n for (; y <= yEnd; y++, idx += width) {\n const inSq = inside[y]!\n if (inSq < clampSqDist) encoded[idx] = (128 - Math.sqrt(inSq) * scale255) | 0\n }\n if (lastNeg - firstNeg < 16) {\n for (let c = firstNeg; c <= lastNeg; c++) outside[c] = 0\n } else {\n outside.fill(0, firstNeg, lastNeg + 1)\n }\n }\n if (yEnd - yStart < 16) {\n for (let c = yStart; c <= yEnd; c++) inside[c] = sentinel\n } else {\n inside.fill(sentinel, yStart, yEnd + 1)\n }\n }\n }\n\n if (scratchDistances.length > 4_500_000) scratchDistances = new Float32Array(0)\n return encoded\n}\n\n/**\n * Encode an alpha coverage mask as a single-channel signed distance field.\n *\n * The returned byte uses the conventional SDF encoding:\n *\n * - the edge is 0.5 (the nearest byte representation is 128),\n * - inside pixels are greater than 0.5,\n * - outside pixels are less than 0.5,\n * - `pxRange` pixels of signed distance span one encoded unit.\n *\n * Fractional source alpha is retained as a sub-pixel seed cost rather than\n * thresholded away. The two exact Euclidean distance transforms are O(width *\n * height); temporary storage is one grid plus O(height) scratch.\n */\nexport function encodeSdfFromAlpha(\n alpha: AlphaPixels,\n width: number,\n height: number,\n pxRange: number,\n): Uint8Array {\n return encodeSdf(alpha, width, height, pxRange, 1)\n}\n\n/**\n * @internal Equivalent to `encodeSdfFromAlpha(alphaOfRgba(rgba, width * height), ...)`,\n * reading the alpha channel directly from packed RGBA bytes without an intermediate buffer.\n */\nexport function encodeSdfFromRgba(\n rgba: AlphaPixels,\n width: number,\n height: number,\n pxRange: number,\n): Uint8Array {\n return encodeSdf(rgba, width, height, pxRange, 4)\n}\n","import { encodeSdfFromRgba } from './cpuSdf.js'\n\nconst scope = globalThis as unknown as {\n onmessage: (\n event: MessageEvent<{\n rgba: Uint8ClampedArray\n width: number\n height: number\n pxRange: number\n }>,\n ) => void\n postMessage: (value: Uint8Array, transfer: ArrayBuffer[]) => void\n}\n\n// The page reads the canvas and sends the RGBA pixels: encode directly without an alpha copy.\nscope.onmessage = ({ data }) => {\n const result = encodeSdfFromRgba(data.rgba, data.width, data.height, data.pxRange)\n scope.postMessage(result, [result.buffer as ArrayBuffer])\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,uBAAuB;AAI7B,MAAM,gBAAgB,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO;AAWzE,SAAS,aACP,QACA,OACA,QACA,SACA,QACA,MACQ;CACR,IAAI,EAAE,kBAAkB,eAAe,EAAE,kBAAkB,oBACzD,MAAM,IAAI,UAAU,GAAG,KAAK,kDAAkD;CAEhF,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GACvC,MAAM,IAAI,WAAW,GAAG,KAAK,mCAAmC;CAElE,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,UAAU,GACzC,MAAM,IAAI,WAAW,GAAG,KAAK,oCAAoC;CAGnE,MAAM,aAAa,QAAQ;CAC3B,IAAI,CAAC,OAAO,cAAc,UAAU,GAClC,MAAM,IAAI,WAAW,GAAG,KAAK,gDAAgD;CAE/E,IAAI,OAAO,WAAW,aAAa,QACjC,MAAM,IAAI,WACR,GAAG,KAAK,iBAAiB,OAAO,OAAO,kBAAkB,WAAW,IAAI,mBAAmB,qBAAqB,IAAI,aAAa,OAAO,EAC1I;CAEF,IAAI,CAAC,OAAO,SAAS,OAAO,KAAK,WAAW,GAC1C,MAAM,IAAI,WAAW,GAAG,KAAK,2CAA2C;CAG1E,OAAO;AACT;AAEA,IAAI,YAAY;AAChB,IAAI,YAAY;;;;;;;;;;AAWhB,SAAS,MACP,MACA,WACA,SACA,UACA,QACA,aACA,WACM;CACN,IAAI,QAAQ;CACZ,OAAO,SAAS,WAAW,KAAK,UAAW,aAAa;CACxD,IAAI,QAAQ,SAAS;EACnB,YAAY,SAAS;EACrB,YAAY,WAAW;EACvB;CACF;CAEA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AqB,CAAC;AAC1D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { atlasDevice, encodeGpuSdf, generateAtlasMips } from "./gpuAtlas.js";
|
|
2
2
|
import { createCanvas, isColorCandidate, waitForFonts } from "../dom/fontCanvas.js";
|
|
3
3
|
import { appendCursors, glyphPainter, measureGlyph, packShelves, slotOf } from "./rasterize.js";
|
|
4
|
-
import {
|
|
4
|
+
import { encodeSdfFromRgba } from "./cpuSdf.js";
|
|
5
5
|
import { Box2, DataTexture, RedFormat, UnsignedByteType, Vector2 } from "three/webgpu";
|
|
6
6
|
// src/atlas/appendAtlas.ts
|
|
7
7
|
/**
|
|
@@ -44,8 +44,8 @@ async function appendGlyphs(renderer, document, atlas, capture, options, signal)
|
|
|
44
44
|
if (!context) return null;
|
|
45
45
|
let lastFont = null;
|
|
46
46
|
const fresh = requests.map((request) => {
|
|
47
|
-
const
|
|
48
|
-
lastFont = font;
|
|
47
|
+
const glyph = measureGlyph(context, request, padding, shaping, isColorCandidate(request, colorGlyphs), lastFont);
|
|
48
|
+
lastFont = request.font;
|
|
49
49
|
return glyph;
|
|
50
50
|
});
|
|
51
51
|
fresh.sort((a, b) => b.height - a.height || b.width - a.width || (a.request.key < b.request.key ? -1 : a.request.key > b.request.key ? 1 : 0));
|
|
@@ -62,13 +62,13 @@ async function appendGlyphs(renderer, document, atlas, capture, options, signal)
|
|
|
62
62
|
canvas.width = scratch.width;
|
|
63
63
|
canvas.height = scratch.height;
|
|
64
64
|
painter.reset();
|
|
65
|
-
const paint = (fill) => {
|
|
66
|
-
context.clearRect(0, 0, scratch.width, scratch.height);
|
|
65
|
+
const paint = (fill, clear) => {
|
|
66
|
+
if (clear) context.clearRect(0, 0, scratch.width, scratch.height);
|
|
67
67
|
for (const glyph of candidates) painter.draw(glyph, false, fill);
|
|
68
68
|
return context.getImageData(0, 0, scratch.width, scratch.height).data;
|
|
69
69
|
};
|
|
70
|
-
const dark = paint("#000");
|
|
71
|
-
const { colored } = encodeColorBand(paint("#fff"), dark, scratch.width, scratch.height, 0, candidates);
|
|
70
|
+
const dark = paint("#000", false);
|
|
71
|
+
const { colored } = encodeColorBand(paint("#fff", true), dark, scratch.width, scratch.height, 0, candidates);
|
|
72
72
|
if (colored.some(Boolean)) return null;
|
|
73
73
|
}
|
|
74
74
|
let { x, y, rowHeight } = cursor;
|
|
@@ -105,15 +105,23 @@ async function appendGlyphs(renderer, document, atlas, capture, options, signal)
|
|
|
105
105
|
}
|
|
106
106
|
patchHeight += runs.at(-1).height;
|
|
107
107
|
if (patchWidth * patchHeight > PATCH_TEXELS) return null;
|
|
108
|
+
const samePatchSize = canvas.width === patchWidth && canvas.height === patchHeight;
|
|
108
109
|
canvas.width = patchWidth;
|
|
109
110
|
canvas.height = patchHeight;
|
|
110
111
|
painter.reset();
|
|
111
|
-
context.clearRect(0, 0, patchWidth, patchHeight);
|
|
112
|
-
for (const run of runs) for (const glyph of run.glyphs)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
if (candidates.length && samePatchSize) context.clearRect(0, 0, patchWidth, patchHeight);
|
|
113
|
+
for (const run of runs) for (const glyph of run.glyphs) {
|
|
114
|
+
const gx = glyph.x;
|
|
115
|
+
const gy = glyph.y;
|
|
116
|
+
glyph.x = gx - run.x;
|
|
117
|
+
glyph.y = gy - run.y + run.top;
|
|
118
|
+
try {
|
|
119
|
+
painter.draw(glyph, true);
|
|
120
|
+
} finally {
|
|
121
|
+
glyph.x = gx;
|
|
122
|
+
glyph.y = gy;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
117
125
|
const target = atlas.texture;
|
|
118
126
|
if (atlas.mode === "gpu") {
|
|
119
127
|
const live = target.sourceTexture;
|
|
@@ -132,6 +140,8 @@ async function appendGlyphs(renderer, document, atlas, capture, options, signal)
|
|
|
132
140
|
origin: [run.x, run.y]
|
|
133
141
|
}, [run.width, run.height]);
|
|
134
142
|
}).catch(() => null);
|
|
143
|
+
canvas.width = 0;
|
|
144
|
+
canvas.height = 0;
|
|
135
145
|
if (!field) return null;
|
|
136
146
|
field.destroy();
|
|
137
147
|
try {
|
|
@@ -144,26 +154,56 @@ async function appendGlyphs(renderer, document, atlas, capture, options, signal)
|
|
|
144
154
|
const image = target.image;
|
|
145
155
|
const bytes = image?.data instanceof Uint8Array && image.data.length === width * height ? image.data : void 0;
|
|
146
156
|
const pixels = context.getImageData(0, 0, patchWidth, patchHeight).data;
|
|
147
|
-
|
|
157
|
+
canvas.width = 0;
|
|
158
|
+
canvas.height = 0;
|
|
159
|
+
const field = encodeSdfFromRgba(pixels, patchWidth, patchHeight, padding);
|
|
148
160
|
signal.throwIfAborted();
|
|
149
161
|
if (bytes) for (const run of runs) for (let row = 0; row < run.height; row++) {
|
|
150
162
|
const from = (run.top + row) * patchWidth;
|
|
151
163
|
bytes.set(field.subarray(from, from + run.width), (run.y + row) * width + run.x);
|
|
152
164
|
}
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
try {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
165
|
+
const backend = renderer.backend;
|
|
166
|
+
const targetGpu = backend?.get?.(target)?.texture;
|
|
167
|
+
const queue = backend?.device?.queue;
|
|
168
|
+
if (targetGpu && typeof queue?.writeTexture === "function") try {
|
|
169
|
+
for (const run of runs) queue.writeTexture({
|
|
170
|
+
texture: targetGpu,
|
|
171
|
+
mipLevel: 0,
|
|
172
|
+
origin: [
|
|
173
|
+
run.x,
|
|
174
|
+
run.y,
|
|
175
|
+
0
|
|
176
|
+
]
|
|
177
|
+
}, field, {
|
|
178
|
+
offset: run.top * patchWidth,
|
|
179
|
+
bytesPerRow: patchWidth,
|
|
180
|
+
rowsPerImage: run.height
|
|
181
|
+
}, [
|
|
182
|
+
run.width,
|
|
183
|
+
run.height,
|
|
184
|
+
1
|
|
185
|
+
]);
|
|
186
|
+
if (target.generateMipmaps) backend.generateMipmaps?.(target);
|
|
161
187
|
} catch {
|
|
162
188
|
if (!bytes) return null;
|
|
163
189
|
target.needsUpdate = true;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
patch
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const patch = new DataTexture(field, patchWidth, patchHeight, RedFormat, UnsignedByteType);
|
|
193
|
+
patch.needsUpdate = true;
|
|
194
|
+
const autoMipmaps = target.mipmapsAutoUpdate;
|
|
195
|
+
try {
|
|
196
|
+
runs.forEach((run, index) => {
|
|
197
|
+
if (autoMipmaps) target.mipmapsAutoUpdate = index === runs.length - 1;
|
|
198
|
+
renderer.copyTextureToTexture(patch, target, new Box2(new Vector2(0, run.top), new Vector2(run.width, run.top + run.height)), new Vector2(run.x, run.y));
|
|
199
|
+
});
|
|
200
|
+
} catch {
|
|
201
|
+
if (!bytes) return null;
|
|
202
|
+
target.needsUpdate = true;
|
|
203
|
+
} finally {
|
|
204
|
+
if (autoMipmaps) target.mipmapsAutoUpdate = true;
|
|
205
|
+
patch.dispose();
|
|
206
|
+
}
|
|
167
207
|
}
|
|
168
208
|
}
|
|
169
209
|
const glyphs = new Map(atlas.glyphs);
|
|
@@ -179,6 +219,8 @@ async function appendGlyphs(renderer, document, atlas, capture, options, signal)
|
|
|
179
219
|
glyphs
|
|
180
220
|
};
|
|
181
221
|
} finally {
|
|
222
|
+
canvas.width = 0;
|
|
223
|
+
canvas.height = 0;
|
|
182
224
|
canvas.remove();
|
|
183
225
|
}
|
|
184
226
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appendAtlas.js","names":[],"sources":["../../src/atlas/appendAtlas.ts"],"sourcesContent":["import {\n Box2,\n DataTexture,\n RedFormat,\n UnsignedByteType,\n Vector2,\n type Texture,\n type WebGPURenderer,\n} from 'three/webgpu'\n\nimport type { DomSdfOptions, GlyphRequest, SdfAtlas } from '../types.js'\nimport { alphaOfRgba, encodeSdfFromAlpha } from './cpuSdf.js'\nimport { atlasDevice, encodeGpuSdf, generateAtlasMips, type AtlasGpuTexture } from './gpuAtlas.js'\nimport {\n appendCursors,\n createCanvas,\n glyphPainter,\n isColorCandidate,\n measureGlyph,\n packShelves,\n slotOf,\n waitForFonts,\n type MeasuredGlyph,\n} from './rasterize.js'\n\n/**\n * A larger patch is left to a full rebuild, which spreads its work better: the patch's exact\n * transform runs on the page's thread, where 2^18 texels (about twenty 96 px glyphs) take a\n * few milliseconds.\n */\nconst PATCH_TEXELS = 1 << 18\n\n/** The new glyphs of one atlas row and where they go: never a box that spans two rows. */\ninterface Run {\n readonly x: number\n readonly y: number\n /** First row of the run on the patch canvas, where the runs are stacked. */\n readonly top: number\n width: number\n height: number\n readonly glyphs: MeasuredGlyph[]\n}\n\n/**\n * @internal Draws the text glyphs of a `capture` that `atlas` lacks into the free text rows of\n * its live texture, so a rebuild keeps the texture and every material that samples it. Only\n * the new glyphs are measured and drawn, row by row of the atlas, on one small canvas, by the\n * full build's rules and slot formulas (`glyphPainter`, `slotOf`). Their distance field comes\n * from the atlas's own encoder, a jump flood of the patch alone for a GPU atlas and the exact\n * transform for a CPU one, so the new slots hold the bytes a full build would give them; each\n * row's box is then copied into the texture, whose mipmaps three regenerates, and a CPU\n * atlas's bytes follow.\n *\n * Resolves with the next wrapper: the same texture, colour layer, shape rows and `dispose`,\n * with the old slots and the new ones; its own cursor is recorded under its glyph map, so it\n * becomes the live one only when the caller commits that wrapper. Slots the capture no longer\n * uses stay in the texture until the next full build compacts it. Resolves `null`, having\n * written nothing the caller must undo, when the caller must rebuild in full instead: a shape,\n * a glyph that classifies as colour, an atlas without a cursor or with a lowered adaptive bake\n * size, a patch past its texel budget, or glyphs that do not fit. What an aborted patch already\n * copied lies in rows no slot samples, and the next patch overwrites it.\n */\nexport async function appendGlyphs(\n renderer: WebGPURenderer,\n document: Document,\n atlas: SdfAtlas,\n capture: readonly GlyphRequest[],\n options: Pick<DomSdfOptions, 'colorGlyphs' | 'bakeSize'>,\n signal: AbortSignal,\n): Promise<SdfAtlas | null> {\n const cursor = appendCursors.get(atlas.glyphs)\n const colorGlyphs = options.colorGlyphs ?? 'emoji'\n const requests = capture.filter((request) => !atlas.glyphs.has(request.key))\n if (\n cursor?.bakeSize !== (options.bakeSize ?? 96) ||\n cursor.colorGlyphs !== colorGlyphs ||\n cursor.width !== atlas.width ||\n cursor.height !== atlas.height ||\n !requests.length ||\n requests.some((request) => request.shape !== undefined)\n )\n return null\n const [, shapingModule] = await Promise.all([\n waitForFonts(document, requests, signal),\n requests.some((request) => request.shaping) ? import('../dom/browserShaping.js') : undefined,\n ])\n signal.throwIfAborted()\n const shaping = shapingModule?.setShapingContext\n const { width, height, bakeSize, pxRange: padding } = cursor\n const canvas = createCanvas(document)\n try {\n // A GPU patch reads at most a tiny candidate scratch pack and uploads the patch texture.\n const context = canvas.getContext('2d', {\n willReadFrequently: atlas.mode !== 'gpu',\n })\n if (!context) return null\n let lastFont: GlyphRequest['font'] | null = null\n const fresh = requests.map((request) => {\n const [glyph, font] = measureGlyph(\n context,\n request,\n padding,\n shaping,\n isColorCandidate(request, colorGlyphs),\n lastFont,\n )\n lastFont = font\n return glyph\n })\n fresh.sort(\n (a, b) =>\n b.height - a.height ||\n b.width - a.width ||\n (a.request.key < b.request.key ? -1 : a.request.key > b.request.key ? 1 : 0),\n )\n // The patch stacks its glyphs' rows, so it is never smaller than their summed area: a batch\n // past the budget is refused before its colour candidates are drawn and read back.\n let area = 0\n for (const glyph of fresh) area += glyph.width * glyph.height\n if (area > PATCH_TEXELS) return null\n const painter = glyphPainter(context, shaping, signal)\n\n // Colour candidates are classified as in a full build, on a pack of their own: one that\n // keeps its colour needs the colour band, which only a full build can grow.\n const candidates = fresh.filter((glyph) => isColorCandidate(glyph.request, colorGlyphs))\n if (candidates.length) {\n const scratch = packShelves(candidates, width, 1 << 14)\n if (!scratch) return null\n const { encodeColorBand } = await import('./colorGlyphs.js')\n signal.throwIfAborted()\n canvas.width = scratch.width\n canvas.height = scratch.height\n painter.reset()\n const paint = (fill: string): Uint8ClampedArray => {\n context.clearRect(0, 0, scratch.width, scratch.height)\n for (const glyph of candidates) painter.draw(glyph, false, fill)\n return context.getImageData(0, 0, scratch.width, scratch.height).data\n }\n const dark = paint('#000')\n const { colored } = encodeColorBand(\n paint('#fff'),\n dark,\n scratch.width,\n scratch.height,\n 0,\n candidates,\n )\n if (colored.some(Boolean)) return null\n }\n\n // The full build's shelf, continued from its last text row.\n let { x, y, rowHeight } = cursor\n const runs: Run[] = []\n let patchWidth = 0\n let patchHeight = 0\n for (const glyph of fresh) {\n if (x + glyph.width > width) {\n x = 0\n y += rowHeight\n rowHeight = 0\n }\n if (glyph.width > width || y + glyph.height > cursor.bottom) return null\n let run = runs.at(-1)\n if (run?.y !== y) {\n if (run) patchHeight += run.height\n runs.push((run = { x, y, top: patchHeight, width: 0, height: 0, glyphs: [] }))\n }\n glyph.x = x\n glyph.y = y\n run.glyphs.push(glyph)\n x += glyph.width\n run.width = x - run.x\n if (glyph.height > run.height) run.height = glyph.height\n if (glyph.height > rowHeight) rowHeight = glyph.height\n if (run.width > patchWidth) patchWidth = run.width\n }\n patchHeight += runs.at(-1)!.height\n if (patchWidth * patchHeight > PATCH_TEXELS) return null\n\n canvas.width = patchWidth\n canvas.height = patchHeight\n painter.reset()\n context.clearRect(0, 0, patchWidth, patchHeight)\n for (const run of runs) {\n for (const glyph of run.glyphs) {\n painter.draw({ ...glyph, x: glyph.x - run.x, y: glyph.y - run.y + run.top }, true)\n }\n }\n\n const target: Texture & { mipmapsAutoUpdate?: boolean; sourceTexture?: unknown } = atlas.texture\n if (atlas.mode === 'gpu') {\n // A patch takes the encoder its atlas was baked with. The jump flood and the exact\n // transform disagree by up to 25/255 of the range even at the edge, so a CPU patch\n // in a GPU atlas would draw its glyphs a shade off a full build's. The patch's field\n // and its copies into the live texture go out in one submission on the device's cached\n // passes, then three regenerates the texture's mips. A device that fails here leaves\n // the full build to fall back, as `auto` does, or to throw.\n const live = target.sourceTexture as AtlasGpuTexture | null | undefined\n if (!live) return null\n const field = await encodeGpuSdf(\n atlasDevice(renderer),\n { canvas, width: patchWidth, height: patchHeight, pxRange: padding },\n 1,\n (encoder, patch) => {\n for (const run of runs) {\n encoder.copyTextureToTexture(\n { texture: patch, origin: [0, run.top] },\n { texture: live, origin: [run.x, run.y] },\n [run.width, run.height],\n )\n }\n },\n ).catch(() => null)\n if (!field) return null\n field.destroy()\n try {\n if (live.mipLevelCount > 1) await generateAtlasMips(renderer, target)\n } catch {\n return null\n }\n signal.throwIfAborted()\n } else {\n // A CPU atlas keeps its bytes, which a later upload sends whole: they take the patch too.\n // (`mipmapsAutoUpdate` is r187's; r186 regenerates the mipmaps after every copy.)\n const image = target.image as { data?: unknown } | null\n const bytes =\n image?.data instanceof Uint8Array && image.data.length === width * height\n ? image.data\n : undefined\n const pixels = context.getImageData(0, 0, patchWidth, patchHeight).data\n const field = encodeSdfFromAlpha(\n alphaOfRgba(pixels, patchWidth * patchHeight),\n patchWidth,\n patchHeight,\n padding,\n )\n signal.throwIfAborted()\n\n // Everything from here on is synchronous, so a newer build cannot interleave its own patch.\n if (bytes) {\n for (const run of runs) {\n for (let row = 0; row < run.height; row++) {\n const from = (run.top + row) * patchWidth\n bytes.set(field.subarray(from, from + run.width), (run.y + row) * width + run.x)\n }\n }\n }\n const patch = new DataTexture(field, patchWidth, patchHeight, RedFormat, UnsignedByteType)\n patch.needsUpdate = true\n const autoMipmaps = target.mipmapsAutoUpdate\n try {\n runs.forEach((run, index) => {\n // Each copy regenerates the whole mip chain: only the last needs to.\n if (autoMipmaps) target.mipmapsAutoUpdate = index === runs.length - 1\n renderer.copyTextureToTexture(\n patch,\n target,\n new Box2(new Vector2(0, run.top), new Vector2(run.width, run.top + run.height)),\n new Vector2(run.x, run.y),\n )\n })\n } catch {\n // A renderer that cannot copy between textures uploads the atlas's bytes again, whole.\n if (!bytes) return null\n target.needsUpdate = true\n } finally {\n if (autoMipmaps) target.mipmapsAutoUpdate = true\n patch.dispose()\n }\n }\n\n const glyphs = new Map(atlas.glyphs)\n for (const glyph of fresh) {\n glyphs.set(\n glyph.request.key,\n slotOf(\n glyph,\n padding,\n bakeSize,\n width,\n height,\n false,\n isColorCandidate(glyph.request, colorGlyphs),\n ),\n )\n }\n appendCursors.set(glyphs, { ...cursor, x, y, rowHeight })\n return { ...atlas, glyphs }\n } finally {\n canvas.remove()\n }\n}\n"],"mappings":";;;;;;;;;;;AA8BA,IAAM,eAAe,KAAK;;;;;;;;;;;;;;;;;;;;AAgC1B,eAAsB,aACpB,UACA,UACA,OACA,SACA,SACA,QAC0B;CAC1B,MAAM,SAAS,cAAc,IAAI,MAAM,MAAM;CAC7C,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,WAAW,QAAQ,QAAQ,YAAY,CAAC,MAAM,OAAO,IAAI,QAAQ,GAAG,CAAC;CAC3E,IACE,QAAQ,cAAc,QAAQ,YAAY,OAC1C,OAAO,gBAAgB,eACvB,OAAO,UAAU,MAAM,SACvB,OAAO,WAAW,MAAM,UACxB,CAAC,SAAS,UACV,SAAS,MAAM,YAAY,QAAQ,UAAU,KAAA,CAAS,GAEtD,OAAO;CACT,MAAM,GAAG,iBAAiB,MAAM,QAAQ,IAAI,CAC1C,aAAa,UAAU,UAAU,MAAM,GACvC,SAAS,MAAM,YAAY,QAAQ,OAAO,IAAI,OAAO,8BAA8B,KAAA,CACrF,CAAC;CACD,OAAO,eAAe;CACtB,MAAM,UAAU,eAAe;CAC/B,MAAM,EAAE,OAAO,QAAQ,UAAU,SAAS,YAAY;CACtD,MAAM,SAAS,aAAa,QAAQ;CACpC,IAAI;EAEF,MAAM,UAAU,OAAO,WAAW,MAAM,EACtC,oBAAoB,MAAM,SAAS,MACrC,CAAC;EACD,IAAI,CAAC,SAAS,OAAO;EACrB,IAAI,WAAwC;EAC5C,MAAM,QAAQ,SAAS,KAAK,YAAY;GACtC,MAAM,CAAC,OAAO,QAAQ,aACpB,SACA,SACA,SACA,SACA,iBAAiB,SAAS,WAAW,GACrC,QACF;GACA,WAAW;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I,CAAC,OAAO,OAAO;IACnB,OAAO,cAAc;GACvB,UAAU;IACR,IAAI,aAAa,OAAO,oBAAoB;IAC5C,MAAM,QAAQ;GAChB;EACF;EAEA,MAAM,SAAS,IAAI,IAAI,MAAM,MAAM;EACnC,KAAK,MAAM,SAAS,OAClB,OAAO,IACL,MAAM,QAAQ,KACd,OACE,OACA,SACA,UACA,OACA,QACA,OACA,iBAAiB,MAAM,SAAS,WAAW,CAC7C,CACF;EAEF,cAAc,IAAI,QAAQ;GAAE,GAAG;GAAQ;GAAG;GAAG;EAAU,CAAC;EACxD,OAAO;GAAE,GAAG;GAAO;EAAO;CAC5B,UAAU;EACR,OAAO,OAAO;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"appendAtlas.js","names":[],"sources":["../../src/atlas/appendAtlas.ts"],"sourcesContent":["import {\n Box2,\n DataTexture,\n RedFormat,\n UnsignedByteType,\n Vector2,\n type Texture,\n type WebGPURenderer,\n} from 'three/webgpu'\n\nimport type { DomSdfOptions, GlyphRequest, SdfAtlas } from '../types.js'\nimport { encodeSdfFromRgba } from './cpuSdf.js'\nimport { atlasDevice, encodeGpuSdf, generateAtlasMips, type AtlasGpuTexture } from './gpuAtlas.js'\nimport {\n appendCursors,\n createCanvas,\n glyphPainter,\n isColorCandidate,\n measureGlyph,\n packShelves,\n slotOf,\n waitForFonts,\n type MeasuredGlyph,\n} from './rasterize.js'\n\n/**\n * A larger patch is left to a full rebuild, which spreads its work better: the patch's exact\n * transform runs on the page's thread, where 2^18 texels (about twenty 96 px glyphs) take a\n * few milliseconds.\n */\nconst PATCH_TEXELS = 1 << 18\n\n/** The new glyphs of one atlas row and where they go: never a box that spans two rows. */\ninterface Run {\n readonly x: number\n readonly y: number\n /** First row of the run on the patch canvas, where the runs are stacked. */\n readonly top: number\n width: number\n height: number\n readonly glyphs: MeasuredGlyph[]\n}\n\n/**\n * @internal Draws the text glyphs of a `capture` that `atlas` lacks into the free text rows of\n * its live texture, so a rebuild keeps the texture and every material that samples it. Only\n * the new glyphs are measured and drawn, row by row of the atlas, on one small canvas, by the\n * full build's rules and slot formulas (`glyphPainter`, `slotOf`). Their distance field comes\n * from the atlas's own encoder, a jump flood of the patch alone for a GPU atlas and the exact\n * transform for a CPU one, so the new slots hold the bytes a full build would give them; each\n * row's box is then copied into the texture, whose mipmaps three regenerates, and a CPU\n * atlas's bytes follow.\n *\n * Resolves with the next wrapper: the same texture, colour layer, shape rows and `dispose`,\n * with the old slots and the new ones; its own cursor is recorded under its glyph map, so it\n * becomes the live one only when the caller commits that wrapper. Slots the capture no longer\n * uses stay in the texture until the next full build compacts it. Resolves `null`, having\n * written nothing the caller must undo, when the caller must rebuild in full instead: a shape,\n * a glyph that classifies as colour, an atlas without a cursor or with a lowered adaptive bake\n * size, a patch past its texel budget, or glyphs that do not fit. What an aborted patch already\n * copied lies in rows no slot samples, and the next patch overwrites it.\n */\nexport async function appendGlyphs(\n renderer: WebGPURenderer,\n document: Document,\n atlas: SdfAtlas,\n capture: readonly GlyphRequest[],\n options: Pick<DomSdfOptions, 'colorGlyphs' | 'bakeSize'>,\n signal: AbortSignal,\n): Promise<SdfAtlas | null> {\n const cursor = appendCursors.get(atlas.glyphs)\n const colorGlyphs = options.colorGlyphs ?? 'emoji'\n const requests = capture.filter((request) => !atlas.glyphs.has(request.key))\n if (\n cursor?.bakeSize !== (options.bakeSize ?? 96) ||\n cursor.colorGlyphs !== colorGlyphs ||\n cursor.width !== atlas.width ||\n cursor.height !== atlas.height ||\n !requests.length ||\n requests.some((request) => request.shape !== undefined)\n )\n return null\n const [, shapingModule] = await Promise.all([\n waitForFonts(document, requests, signal),\n requests.some((request) => request.shaping) ? import('../dom/browserShaping.js') : undefined,\n ])\n signal.throwIfAborted()\n const shaping = shapingModule?.setShapingContext\n const { width, height, bakeSize, pxRange: padding } = cursor\n const canvas = createCanvas(document)\n try {\n // A GPU patch reads at most a tiny candidate scratch pack and uploads the patch texture.\n const context = canvas.getContext('2d', {\n willReadFrequently: atlas.mode !== 'gpu',\n })\n if (!context) return null\n let lastFont: GlyphRequest['font'] | null = null\n const fresh = requests.map((request) => {\n const glyph = measureGlyph(\n context,\n request,\n padding,\n shaping,\n isColorCandidate(request, colorGlyphs),\n lastFont,\n )\n lastFont = request.font\n return glyph\n })\n fresh.sort(\n (a, b) =>\n b.height - a.height ||\n b.width - a.width ||\n (a.request.key < b.request.key ? -1 : a.request.key > b.request.key ? 1 : 0),\n )\n // The patch stacks its glyphs' rows, so it is never smaller than their summed area: a batch\n // past the budget is refused before its colour candidates are drawn and read back.\n let area = 0\n for (const glyph of fresh) area += glyph.width * glyph.height\n if (area > PATCH_TEXELS) return null\n const painter = glyphPainter(context, shaping, signal)\n\n // Colour candidates are classified as in a full build, on a pack of their own: one that\n // keeps its colour needs the colour band, which only a full build can grow.\n const candidates = fresh.filter((glyph) => isColorCandidate(glyph.request, colorGlyphs))\n if (candidates.length) {\n const scratch = packShelves(candidates, width, 1 << 14)\n if (!scratch) return null\n const { encodeColorBand } = await import('./colorGlyphs.js')\n signal.throwIfAborted()\n canvas.width = scratch.width\n canvas.height = scratch.height\n painter.reset()\n const paint = (fill: string, clear: boolean): Uint8ClampedArray => {\n if (clear) context.clearRect(0, 0, scratch.width, scratch.height)\n for (const glyph of candidates) painter.draw(glyph, false, fill)\n return context.getImageData(0, 0, scratch.width, scratch.height).data\n }\n const dark = paint('#000', false)\n const { colored } = encodeColorBand(\n paint('#fff', true),\n dark,\n scratch.width,\n scratch.height,\n 0,\n candidates,\n )\n if (colored.some(Boolean)) return null\n }\n\n // The full build's shelf, continued from its last text row.\n let { x, y, rowHeight } = cursor\n const runs: Run[] = []\n let patchWidth = 0\n let patchHeight = 0\n for (const glyph of fresh) {\n if (x + glyph.width > width) {\n x = 0\n y += rowHeight\n rowHeight = 0\n }\n if (glyph.width > width || y + glyph.height > cursor.bottom) return null\n let run = runs.at(-1)\n if (run?.y !== y) {\n if (run) patchHeight += run.height\n runs.push((run = { x, y, top: patchHeight, width: 0, height: 0, glyphs: [] }))\n }\n glyph.x = x\n glyph.y = y\n run.glyphs.push(glyph)\n x += glyph.width\n run.width = x - run.x\n if (glyph.height > run.height) run.height = glyph.height\n if (glyph.height > rowHeight) rowHeight = glyph.height\n if (run.width > patchWidth) patchWidth = run.width\n }\n patchHeight += runs.at(-1)!.height\n if (patchWidth * patchHeight > PATCH_TEXELS) return null\n\n const samePatchSize = canvas.width === patchWidth && canvas.height === patchHeight\n canvas.width = patchWidth\n canvas.height = patchHeight\n painter.reset()\n if (candidates.length && samePatchSize) context.clearRect(0, 0, patchWidth, patchHeight)\n for (const run of runs) {\n for (const glyph of run.glyphs) {\n const gx = glyph.x\n const gy = glyph.y\n glyph.x = gx - run.x\n glyph.y = gy - run.y + run.top\n try {\n painter.draw(glyph, true)\n } finally {\n glyph.x = gx\n glyph.y = gy\n }\n }\n }\n\n const target: Texture & { mipmapsAutoUpdate?: boolean; sourceTexture?: unknown } = atlas.texture\n if (atlas.mode === 'gpu') {\n // A patch takes the encoder its atlas was baked with. The jump flood and the exact\n // transform disagree by up to 25/255 of the range even at the edge, so a CPU patch\n // in a GPU atlas would draw its glyphs a shade off a full build's. The patch's field\n // and its copies into the live texture go out in one submission on the device's cached\n // passes, then three regenerates the texture's mips. A device that fails here leaves\n // the full build to fall back, as `auto` does, or to throw.\n const live = target.sourceTexture as AtlasGpuTexture | null | undefined\n if (!live) return null\n const field = await encodeGpuSdf(\n atlasDevice(renderer),\n { canvas, width: patchWidth, height: patchHeight, pxRange: padding },\n 1,\n (encoder, patch) => {\n for (const run of runs) {\n encoder.copyTextureToTexture(\n { texture: patch, origin: [0, run.top] },\n { texture: live, origin: [run.x, run.y] },\n [run.width, run.height],\n )\n }\n },\n ).catch(() => null)\n canvas.width = 0\n canvas.height = 0\n if (!field) return null\n field.destroy()\n try {\n if (live.mipLevelCount > 1) await generateAtlasMips(renderer, target)\n } catch {\n return null\n }\n signal.throwIfAborted()\n } else {\n // A CPU atlas keeps its bytes, which a later upload sends whole: they take the patch too.\n // (`mipmapsAutoUpdate` is r187's; r186 regenerates the mipmaps after every copy.)\n const image = target.image as { data?: unknown } | null\n const bytes =\n image?.data instanceof Uint8Array && image.data.length === width * height\n ? image.data\n : undefined\n const pixels = context.getImageData(0, 0, patchWidth, patchHeight).data\n canvas.width = 0\n canvas.height = 0\n const field = encodeSdfFromRgba(pixels, patchWidth, patchHeight, padding)\n signal.throwIfAborted()\n\n // Everything from here on is synchronous, so a newer build cannot interleave its own patch.\n if (bytes) {\n for (const run of runs) {\n for (let row = 0; row < run.height; row++) {\n const from = (run.top + row) * patchWidth\n bytes.set(field.subarray(from, from + run.width), (run.y + row) * width + run.x)\n }\n }\n }\n const backend = (\n renderer as unknown as {\n backend?: {\n get?(texture: Texture): { texture?: unknown } | undefined\n generateMipmaps?(texture: Texture): void\n device?: {\n queue?: {\n writeTexture?(\n destination: {\n texture: unknown\n mipLevel?: number\n origin?: [number, number, number]\n },\n data: Uint8Array,\n dataLayout: { offset?: number; bytesPerRow: number; rowsPerImage?: number },\n size: [number, number, number],\n ): void\n }\n }\n }\n }\n ).backend\n const targetGpu = backend?.get?.(target)?.texture\n const queue = backend?.device?.queue\n if (targetGpu && typeof queue?.writeTexture === 'function') {\n try {\n for (const run of runs) {\n queue.writeTexture(\n { texture: targetGpu, mipLevel: 0, origin: [run.x, run.y, 0] },\n field,\n { offset: run.top * patchWidth, bytesPerRow: patchWidth, rowsPerImage: run.height },\n [run.width, run.height, 1],\n )\n }\n if (target.generateMipmaps) backend.generateMipmaps?.(target)\n } catch {\n if (!bytes) return null\n target.needsUpdate = true\n }\n } else {\n const patch = new DataTexture(field, patchWidth, patchHeight, RedFormat, UnsignedByteType)\n patch.needsUpdate = true\n const autoMipmaps = target.mipmapsAutoUpdate\n try {\n runs.forEach((run, index) => {\n // Each copy regenerates the whole mip chain: only the last needs to.\n if (autoMipmaps) target.mipmapsAutoUpdate = index === runs.length - 1\n renderer.copyTextureToTexture(\n patch,\n target,\n new Box2(new Vector2(0, run.top), new Vector2(run.width, run.top + run.height)),\n new Vector2(run.x, run.y),\n )\n })\n } catch {\n // A renderer that cannot copy between textures uploads the atlas's bytes again, whole.\n if (!bytes) return null\n target.needsUpdate = true\n } finally {\n if (autoMipmaps) target.mipmapsAutoUpdate = true\n patch.dispose()\n }\n }\n }\n\n const glyphs = new Map(atlas.glyphs)\n for (const glyph of fresh) {\n glyphs.set(\n glyph.request.key,\n slotOf(\n glyph,\n padding,\n bakeSize,\n width,\n height,\n false,\n isColorCandidate(glyph.request, colorGlyphs),\n ),\n )\n }\n appendCursors.set(glyphs, { ...cursor, x, y, rowHeight })\n return { ...atlas, glyphs }\n } finally {\n canvas.width = 0\n canvas.height = 0\n canvas.remove()\n }\n}\n"],"mappings":";;;;;;;;;;;AA8BA,IAAM,eAAe,KAAK;;;;;;;;;;;;;;;;;;;;AAgC1B,eAAsB,aACpB,UACA,UACA,OACA,SACA,SACA,QAC0B;CAC1B,MAAM,SAAS,cAAc,IAAI,MAAM,MAAM;CAC7C,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,WAAW,QAAQ,QAAQ,YAAY,CAAC,MAAM,OAAO,IAAI,QAAQ,GAAG,CAAC;CAC3E,IACE,QAAQ,cAAc,QAAQ,YAAY,OAC1C,OAAO,gBAAgB,eACvB,OAAO,UAAU,MAAM,SACvB,OAAO,WAAW,MAAM,UACxB,CAAC,SAAS,UACV,SAAS,MAAM,YAAY,QAAQ,UAAU,KAAA,CAAS,GAEtD,OAAO;CACT,MAAM,GAAG,iBAAiB,MAAM,QAAQ,IAAI,CAC1C,aAAa,UAAU,UAAU,MAAM,GACvC,SAAS,MAAM,YAAY,QAAQ,OAAO,IAAI,OAAO,8BAA8B,KAAA,CACrF,CAAC;CACD,OAAO,eAAe;CACtB,MAAM,UAAU,eAAe;CAC/B,MAAM,EAAE,OAAO,QAAQ,UAAU,SAAS,YAAY;CACtD,MAAM,SAAS,aAAa,QAAQ;CACpC,IAAI;EAEF,MAAM,UAAU,OAAO,WA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KACd,OACE,OACA,SACA,UACA,OACA,QACA,OACA,iBAAiB,MAAM,SAAS,WAAW,CAC7C,CACF;EAEF,cAAc,IAAI,QAAQ;GAAE,GAAG;GAAQ;GAAG;GAAG;EAAU,CAAC;EACxD,OAAO;GAAE,GAAG;GAAO;EAAO;CAC5B,UAAU;EACR,OAAO,QAAQ;EACf,OAAO,SAAS;EAChB,OAAO,OAAO;CAChB;AACF"}
|
package/dist/atlas/buildAtlas.js
CHANGED
|
@@ -39,13 +39,14 @@ async function withColorLayer(atlas, raster, renderer, options) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
var warnedGpuFallback = false;
|
|
42
|
-
async function buildSdfAtlas(renderer, raster, options = {}, provisional) {
|
|
42
|
+
async function buildSdfAtlas(renderer, raster, options = {}, provisional, preparedWorker) {
|
|
43
43
|
const mode = options.mode;
|
|
44
44
|
options.signal?.throwIfAborted();
|
|
45
45
|
const buildCpu = async () => {
|
|
46
46
|
const { buildCpuSdfAtlas } = await import("./cpuAtlas.js");
|
|
47
|
+
const worker = preparedWorker ? await preparedWorker : void 0;
|
|
47
48
|
options.signal?.throwIfAborted();
|
|
48
|
-
return retainAtlas(await buildCpuSdfAtlas(raster, options), options.signal);
|
|
49
|
+
return retainAtlas(await (worker ? buildCpuSdfAtlas(raster, options, worker) : buildCpuSdfAtlas(raster, options)), options.signal);
|
|
49
50
|
};
|
|
50
51
|
let atlas;
|
|
51
52
|
if (mode === "cpu") atlas = await buildCpu();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildAtlas.js","names":[],"sources":["../../src/atlas/buildAtlas.ts"],"sourcesContent":["import type { WebGPURenderer } from 'three/webgpu'\n\nimport type { BuildSdfAtlasOptions, RasterAtlas, SdfAtlas } from '../types.js'\nimport { buildGpuSdfAtlas } from './gpuAtlas.js'\n\nfunction retainAtlas(atlas: SdfAtlas, signal?: AbortSignal): SdfAtlas {\n if (signal?.aborted) {\n atlas.dispose()\n signal.throwIfAborted()\n }\n return atlas\n}\n\nasync function withColorLayer(\n atlas: SdfAtlas,\n raster: RasterAtlas,\n renderer: WebGPURenderer,\n options: BuildSdfAtlasOptions,\n): Promise<SdfAtlas> {\n if (!raster.colorBand) return atlas\n let colorLayer: SdfAtlas['colorLayer']\n try {\n const { createColorLayer } = await import('./colorGlyphs.js')\n options.signal?.throwIfAborted()\n colorLayer = createColorLayer(\n raster.colorBand,\n raster.width,\n options,\n renderer.getMaxAnisotropy(),\n )\n options.signal?.throwIfAborted()\n let disposed = false\n return {\n ...atlas,\n colorLayer,\n dispose() {\n if (disposed) return\n disposed = true\n try {\n atlas.dispose()\n } finally {\n colorLayer!.texture.dispose()\n }\n },\n }\n } catch (error) {\n try {\n atlas.dispose()\n } finally {\n colorLayer?.texture.dispose()\n }\n throw error\n }\n}\n\nlet warnedGpuFallback = false\n\n/** @internal Hook for overlapping GPU SDF validation with downstream geometry creation. */\nexport interface ProvisionalAtlasHook {\n stage(atlas: SdfAtlas): void\n rollback(): void\n}\n\n/**\n * Builds the retained single-channel SDF atlas from a packed glyph mask.\n *\n * `mode: 'gpu'` runs the WebGPU compute encoder and rethrows if a real WebGPU\n * backend is unavailable, if the device's limits cannot hold the passes, or if\n * the device reports an error for them; `'cpu'` runs the exact Euclidean\n * distance transform; the default `'auto'` tries the GPU path first and falls\n * back to the CPU encoder, warning once per page because the fallback is\n * 10-100× slower.\n * An aborted `signal` rejects with the abort reason and disposes any atlas\n * that was already produced. The caller owns the returned atlas.\n */\nexport function buildSdfAtlas(\n renderer: WebGPURenderer,\n raster: RasterAtlas,\n options?: BuildSdfAtlasOptions,\n): Promise<SdfAtlas>\n/** @internal */\nexport function buildSdfAtlas(\n renderer: WebGPURenderer,\n raster: RasterAtlas,\n options: BuildSdfAtlasOptions | undefined,\n provisional: ProvisionalAtlasHook | undefined,\n): Promise<SdfAtlas>\nexport async function buildSdfAtlas(\n renderer: WebGPURenderer,\n raster: RasterAtlas,\n options: BuildSdfAtlasOptions = {},\n provisional?: ProvisionalAtlasHook,\n): Promise<SdfAtlas> {\n const mode = options.mode\n options.signal?.throwIfAborted()\n\n const buildCpu = async (): Promise<SdfAtlas> => {\n const { buildCpuSdfAtlas } = await import('./cpuAtlas.js')\n options.signal?.throwIfAborted()\n return retainAtlas(await buildCpuSdfAtlas(raster, options), options.signal)\n }\n let atlas: SdfAtlas\n if (mode === 'cpu') atlas = await buildCpu()\n else {\n try {\n const built =\n provisional && !raster.colorBand && !options.mipmaps\n ? await buildGpuSdfAtlas(renderer, raster, options, (candidate) =>\n provisional.stage(candidate),\n )\n : await buildGpuSdfAtlas(renderer, raster, options)\n atlas = retainAtlas(built, options.signal)\n } catch (error) {\n provisional?.rollback()\n if (mode === 'gpu') throw error\n options.signal?.throwIfAborted()\n if (!warnedGpuFallback) {\n warnedGpuFallback = true\n console.warn('ultra-text: falling back to CPU SDF', error)\n }\n atlas = await buildCpu()\n }\n }\n // `SdfAtlas.shapeTop` names the rows of the monochrome shapes. The texture repeats it for\n // a material that is handed the texture without that field.\n if (atlas.shapeTop !== undefined) atlas.texture.userData['ultraShapeTop'] = atlas.shapeTop\n return withColorLayer(atlas, raster, renderer, options)\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"buildAtlas.js","names":[],"sources":["../../src/atlas/buildAtlas.ts"],"sourcesContent":["import type { WebGPURenderer } from 'three/webgpu'\n\nimport type { BuildSdfAtlasOptions, RasterAtlas, SdfAtlas } from '../types.js'\nimport type { PreparedCpuWorker } from './cpuWorker.js'\nimport { buildGpuSdfAtlas } from './gpuAtlas.js'\n\nfunction retainAtlas(atlas: SdfAtlas, signal?: AbortSignal): SdfAtlas {\n if (signal?.aborted) {\n atlas.dispose()\n signal.throwIfAborted()\n }\n return atlas\n}\n\nasync function withColorLayer(\n atlas: SdfAtlas,\n raster: RasterAtlas,\n renderer: WebGPURenderer,\n options: BuildSdfAtlasOptions,\n): Promise<SdfAtlas> {\n if (!raster.colorBand) return atlas\n let colorLayer: SdfAtlas['colorLayer']\n try {\n const { createColorLayer } = await import('./colorGlyphs.js')\n options.signal?.throwIfAborted()\n colorLayer = createColorLayer(\n raster.colorBand,\n raster.width,\n options,\n renderer.getMaxAnisotropy(),\n )\n options.signal?.throwIfAborted()\n let disposed = false\n return {\n ...atlas,\n colorLayer,\n dispose() {\n if (disposed) return\n disposed = true\n try {\n atlas.dispose()\n } finally {\n colorLayer!.texture.dispose()\n }\n },\n }\n } catch (error) {\n try {\n atlas.dispose()\n } finally {\n colorLayer?.texture.dispose()\n }\n throw error\n }\n}\n\nlet warnedGpuFallback = false\n\n/** @internal Hook for overlapping GPU SDF validation with downstream geometry creation. */\nexport interface ProvisionalAtlasHook {\n stage(atlas: SdfAtlas): void\n rollback(): void\n}\n\n/**\n * Builds the retained single-channel SDF atlas from a packed glyph mask.\n *\n * `mode: 'gpu'` runs the WebGPU compute encoder and rethrows if a real WebGPU\n * backend is unavailable, if the device's limits cannot hold the passes, or if\n * the device reports an error for them; `'cpu'` runs the exact Euclidean\n * distance transform; the default `'auto'` tries the GPU path first and falls\n * back to the CPU encoder, warning once per page because the fallback is\n * 10-100× slower.\n * An aborted `signal` rejects with the abort reason and disposes any atlas\n * that was already produced. The caller owns the returned atlas.\n */\nexport function buildSdfAtlas(\n renderer: WebGPURenderer,\n raster: RasterAtlas,\n options?: BuildSdfAtlasOptions,\n): Promise<SdfAtlas>\n/** @internal */\nexport function buildSdfAtlas(\n renderer: WebGPURenderer,\n raster: RasterAtlas,\n options: BuildSdfAtlasOptions | undefined,\n provisional: ProvisionalAtlasHook | undefined,\n preparedWorker?: PreparedCpuWorker | Promise<PreparedCpuWorker | null> | null,\n): Promise<SdfAtlas>\nexport async function buildSdfAtlas(\n renderer: WebGPURenderer,\n raster: RasterAtlas,\n options: BuildSdfAtlasOptions = {},\n provisional?: ProvisionalAtlasHook,\n preparedWorker?: PreparedCpuWorker | Promise<PreparedCpuWorker | null> | null,\n): Promise<SdfAtlas> {\n const mode = options.mode\n options.signal?.throwIfAborted()\n\n const buildCpu = async (): Promise<SdfAtlas> => {\n const { buildCpuSdfAtlas } = await import('./cpuAtlas.js')\n const worker = preparedWorker ? await preparedWorker : undefined\n options.signal?.throwIfAborted()\n return retainAtlas(\n await (worker\n ? buildCpuSdfAtlas(raster, options, worker)\n : buildCpuSdfAtlas(raster, options)),\n options.signal,\n )\n }\n let atlas: SdfAtlas\n if (mode === 'cpu') atlas = await buildCpu()\n else {\n try {\n const built =\n provisional && !raster.colorBand && !options.mipmaps\n ? await buildGpuSdfAtlas(renderer, raster, options, (candidate) =>\n provisional.stage(candidate),\n )\n : await buildGpuSdfAtlas(renderer, raster, options)\n atlas = retainAtlas(built, options.signal)\n } catch (error) {\n provisional?.rollback()\n if (mode === 'gpu') throw error\n options.signal?.throwIfAborted()\n if (!warnedGpuFallback) {\n warnedGpuFallback = true\n console.warn('ultra-text: falling back to CPU SDF', error)\n }\n atlas = await buildCpu()\n }\n }\n // `SdfAtlas.shapeTop` names the rows of the monochrome shapes. The texture repeats it for\n // a material that is handed the texture without that field.\n if (atlas.shapeTop !== undefined) atlas.texture.userData['ultraShapeTop'] = atlas.shapeTop\n return withColorLayer(atlas, raster, renderer, options)\n}\n"],"mappings":";;AAMA,SAAS,YAAY,OAAiB,QAAgC;CACpE,IAAI,QAAQ,SAAS;EACnB,MAAM,QAAQ;EACd,OAAO,eAAe;CACxB;CACA,OAAO;AACT;AAEA,eAAe,eACb,OACA,QACA,UACA,SACmB;CACnB,IAAI,CAAC,OAAO,WAAW,OAAO;CAC9B,IAAI;CACJ,IAAI;EACF,MAAM,EAAE,qBAAqB,MAAM,OAAO;EAC1C,QAAQ,QAAQ,eAAe;EAC/B,aAAa,iBACX,OAAO,WACP,OAAO,OACP,SACA,SAAS,iBAAiB,CAC5B;EACA,QAAQ,QAAQ,eAAe;EAC/B,IAAI,WAAW;EACf,OAAO;GACL,GAAG;GACH;GACA,UAAU;IACR,IAAI,UAAU;IACd,WAAW;IACX,IAAI;KACF,MAAM,QAAQ;IAChB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