ultra-text 1.0.1 → 1.0.3
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 +339 -1039
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js +466 -0
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
- package/dist/atlas/appendAtlas.js +97 -31
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +4 -3
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/colorGlyphs.d.ts +0 -10
- package/dist/atlas/colorGlyphs.js +97 -155
- package/dist/atlas/colorGlyphs.js.map +1 -1
- package/dist/atlas/colorTexture.d.ts +1 -0
- package/dist/atlas/colorTexture.js +64 -0
- package/dist/atlas/colorTexture.js.map +1 -0
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +14 -7
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +235 -68
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +11 -3
- package/dist/atlas/cpuWorker.js +179 -22
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +188 -287
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +257 -0
- package/dist/atlas/gpuCommon.js +845 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +226 -249
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +329 -158
- 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 +1065 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +72 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +167 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +295 -0
- package/dist/atlas/vanillaGpuHelpers.js +354 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +243 -297
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +94 -165
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/Text.d.ts +4 -1
- package/dist/dom/Text.js +5 -1
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/browserShaping.js +31 -14
- package/dist/dom/browserShaping.js.map +1 -1
- package/dist/dom/clusters.js +13 -2
- package/dist/dom/clusters.js.map +1 -1
- package/dist/dom/cssEffects.d.ts +4 -0
- package/dist/dom/cssEffects.js +72 -0
- package/dist/dom/cssEffects.js.map +1 -0
- package/dist/dom/domAnalytic.d.ts +53 -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.d.ts +16 -0
- package/dist/dom/fontCanvas.js +31 -13
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +175 -57
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/markup.d.ts +10 -0
- package/dist/dom/markup.js +16 -1
- package/dist/dom/markup.js.map +1 -1
- package/dist/dom/pretextLayout.js +78 -28
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +891 -484
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/snapshotsEqual.d.ts +7 -0
- package/dist/dom/snapshotsEqual.js +68 -0
- package/dist/dom/snapshotsEqual.js.map +1 -0
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +105 -28
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textTransform.d.ts +13 -1
- package/dist/dom/textTransform.js +31 -13
- package/dist/dom/textTransform.js.map +1 -1
- package/dist/dom/tone.js +91 -44
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +17 -3
- package/dist/slug/SlugMaterial.js +98 -26
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/cff.d.ts +5 -0
- package/dist/slug/cff.js +780 -0
- package/dist/slug/cff.js.map +1 -0
- package/dist/slug/coverage.d.ts +19 -15
- package/dist/slug/coverage.js +380 -225
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -2
- package/dist/slug/preprocessCore.js +199 -148
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +113 -74
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +112 -67
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +356 -255
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +410 -0
- package/dist/slug/vanillaCore.js +1630 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +7 -1454
- package/dist/slug.d.ts +2 -2
- package/dist/slug.js +7 -7
- package/dist/text/GlyphTextMaterial.d.ts +6 -1
- package/dist/text/GlyphTextMaterial.js +16 -12
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/RectMaterial.js +6 -10
- package/dist/text/RectMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +9 -3
- package/dist/text/SdfTextMaterial.js +125 -38
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -79
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +16 -1
- package/dist/text/geometryUtils.js +83 -8
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +434 -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 +101 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +23 -1
- package/dist/text/reflow.js +223 -94
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/text/tone.js +2 -2
- package/dist/text/tone.js.map +1 -1
- package/dist/types.d.ts +23 -7
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +7 -1474
- package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
- package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
- package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
- package/dist/windfoil/WindfoilMaterial.js +71 -8
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/compositeGeometry.js +12 -5
- package/dist/windfoil/compositeGeometry.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +10 -2
- package/dist/windfoil/coverage.js +147 -59
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +17 -2
- package/dist/windfoil/geometry.js +220 -57
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +8 -8
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +57 -29
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +2 -0
- package/dist/windfoil/preprocessCore.js +69 -37
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.d.ts +1 -1
- package/dist/windfoil/requests.js +11 -4
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/resolveOutline.d.ts +9 -0
- package/dist/windfoil/resolveOutline.js +20 -0
- package/dist/windfoil/resolveOutline.js.map +1 -0
- package/dist/windfoil/runtime.d.ts +4 -1
- package/dist/windfoil/runtime.js +69 -63
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeGeometry.js +80 -34
- package/dist/windfoil/shapeGeometry.js.map +1 -1
- package/dist/windfoil/sizeSwitch.d.ts +1 -1
- package/dist/windfoil/sizeSwitch.js +13 -8
- package/dist/windfoil/sizeSwitch.js.map +1 -1
- package/dist/windfoil/storage.d.ts +78 -6
- package/dist/windfoil/storage.js +166 -11
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/svg/curves.d.ts +20 -0
- package/dist/windfoil/svg/curves.js +145 -42
- package/dist/windfoil/svg/curves.js.map +1 -1
- package/dist/windfoil/svg/document.js +10 -1
- package/dist/windfoil/svg/document.js.map +1 -1
- package/dist/windfoil/svg/pathConverter.js +66 -50
- package/dist/windfoil/svg/pathConverter.js.map +1 -1
- package/dist/windfoil/svg/pathData.d.ts +9 -0
- package/dist/windfoil/svg/pathData.js +142 -109
- package/dist/windfoil/svg/pathData.js.map +1 -1
- package/dist/windfoil/svg/winding.js +34 -10
- package/dist/windfoil/svg/winding.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +256 -62
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +915 -265
- 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/traceOutline.worker.d.ts +24 -0
- package/dist/windfoil/trace/traceWorker.d.ts +13 -0
- package/dist/windfoil/trace/traceWorker.js +192 -0
- package/dist/windfoil/trace/traceWorker.js.map +1 -0
- package/dist/windfoil/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +393 -103
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +48 -29
- package/skills/ultra-text/SKILL.md +9 -10
- package/skills/ultra-text/references/frameworks.md +46 -2
- package/skills/ultra-text/references/three-tsl.md +27 -25
- package/skills/ultra-text/references/vanilla-webgpu.md +5 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js +0 -322
- 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
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { atlasRootOf } from "../dom/markup.js";
|
|
2
|
+
import { attrOf, byte, flushAttributeUpdate, instanceAttribute, isDomSnapshot, metaSize, needsRunMotion, setBounds, setUnitQuad, writeDirty4 } from "./geometryUtils.js";
|
|
3
|
+
import { InstancedBufferAttribute, InstancedBufferGeometry } from "three/webgpu";
|
|
4
|
+
// src/text/glyphGeometry.ts
|
|
5
|
+
var prevBatchCache = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
var clamp16 = (v) => Math.min(65535, Math.max(0, v));
|
|
7
|
+
var batchSummary = [
|
|
8
|
+
0,
|
|
9
|
+
0,
|
|
10
|
+
0,
|
|
11
|
+
0
|
|
12
|
+
];
|
|
13
|
+
function writeGlyphBatchFresh(snapshot, atlas, rects, clips, metadata, metaItemSize, runMotion, motionOrdinals, uvRects, trims, colors, cache) {
|
|
14
|
+
const glyphs = snapshot.glyphs;
|
|
15
|
+
const total = glyphs.length;
|
|
16
|
+
const shaped = snapshot.textShaping === "browser";
|
|
17
|
+
const invBakeSize = 1 / atlas.bakeSize;
|
|
18
|
+
const atlasGlyphs = atlas.glyphs;
|
|
19
|
+
const hasTrims = trims !== null;
|
|
20
|
+
const groupMotion = !!runMotion && !motionOrdinals && needsRunMotion(snapshot);
|
|
21
|
+
let groupRepeats = 0;
|
|
22
|
+
let previousGroup;
|
|
23
|
+
let count = 0;
|
|
24
|
+
let maxSequence = 0;
|
|
25
|
+
let minZ = 0;
|
|
26
|
+
let maxZ = 0;
|
|
27
|
+
let prevKey;
|
|
28
|
+
let prevSlot;
|
|
29
|
+
let prevUvSlot;
|
|
30
|
+
let pu0 = 0;
|
|
31
|
+
let pv1 = 0;
|
|
32
|
+
let pu1 = 0;
|
|
33
|
+
let pv0 = 0;
|
|
34
|
+
let pt0 = 0;
|
|
35
|
+
let pt1 = 0;
|
|
36
|
+
let pt2 = 0;
|
|
37
|
+
let pt3 = 0;
|
|
38
|
+
let prevColor;
|
|
39
|
+
let c0 = 0;
|
|
40
|
+
let c1 = 0;
|
|
41
|
+
let c2 = 0;
|
|
42
|
+
let c3 = 0;
|
|
43
|
+
let prevClip;
|
|
44
|
+
let fc0 = 0;
|
|
45
|
+
let fc1 = 0;
|
|
46
|
+
let fc2 = 0;
|
|
47
|
+
let fc3 = 0;
|
|
48
|
+
const dom = isDomSnapshot(snapshot);
|
|
49
|
+
const root = dom ? atlasRootOf(atlasGlyphs) : null;
|
|
50
|
+
const flags = (shaped ? 1 : 0) | (runMotion !== null ? 2 : 0) | metaItemSize << 2;
|
|
51
|
+
for (let ordinal = 0; ordinal < total; ordinal++) {
|
|
52
|
+
const glyph = glyphs[ordinal];
|
|
53
|
+
if (groupMotion) {
|
|
54
|
+
const group = glyph.shapeGroup;
|
|
55
|
+
if (group !== void 0 && group === previousGroup) groupRepeats++;
|
|
56
|
+
previousGroup = group;
|
|
57
|
+
}
|
|
58
|
+
const gKey = glyph.glyphKey;
|
|
59
|
+
const slot = gKey === prevKey ? prevSlot : (prevKey = gKey, prevSlot = atlasGlyphs.get(gKey));
|
|
60
|
+
if (!slot) continue;
|
|
61
|
+
const index = count++;
|
|
62
|
+
const offset = index * 4;
|
|
63
|
+
const scale = glyph.fontSize * invBakeSize;
|
|
64
|
+
const scaleX = shaped && slot.advance > 0 ? glyph.advance / slot.advance : scale;
|
|
65
|
+
const baseline = glyph.lineBottom + (glyph.baselineOffset ?? slot.descent * scale);
|
|
66
|
+
const ox = glyph.originX;
|
|
67
|
+
const r0 = ox + slot.planeX0 * scaleX;
|
|
68
|
+
const r1 = baseline + slot.planeY0 * scale;
|
|
69
|
+
const r2 = ox + slot.planeX1 * scaleX;
|
|
70
|
+
const r3 = baseline + slot.planeY1 * scale;
|
|
71
|
+
rects[offset] = r0;
|
|
72
|
+
rects[offset + 1] = r1;
|
|
73
|
+
rects[offset + 2] = r2;
|
|
74
|
+
rects[offset + 3] = r3;
|
|
75
|
+
const clip = glyph.clip;
|
|
76
|
+
if (clip !== prevClip) {
|
|
77
|
+
prevClip = clip;
|
|
78
|
+
fc0 = clip[0];
|
|
79
|
+
fc1 = clip[1];
|
|
80
|
+
fc2 = clip[2];
|
|
81
|
+
fc3 = clip[3];
|
|
82
|
+
}
|
|
83
|
+
clips[offset] = fc0;
|
|
84
|
+
clips[offset + 1] = fc1;
|
|
85
|
+
clips[offset + 2] = fc2;
|
|
86
|
+
clips[offset + 3] = fc3;
|
|
87
|
+
if (slot !== prevUvSlot) {
|
|
88
|
+
prevUvSlot = slot;
|
|
89
|
+
pu0 = slot.u0 * 65535 + .5 | 0;
|
|
90
|
+
pv1 = slot.v1 * 65535 + .5 | 0;
|
|
91
|
+
pu1 = slot.u1 * 65535 + .5 | 0;
|
|
92
|
+
pv0 = slot.v0 * 65535 + .5 | 0;
|
|
93
|
+
const s = hasTrims ? slot.support : void 0;
|
|
94
|
+
pt0 = s ? clamp16(Math.floor(s.u0 * 65535)) : pu0;
|
|
95
|
+
pt1 = s ? clamp16(Math.ceil(s.v1 * 65535)) : pv1;
|
|
96
|
+
pt2 = s ? clamp16(Math.ceil(s.u1 * 65535)) : pu1;
|
|
97
|
+
pt3 = s ? clamp16(Math.floor(s.v0 * 65535)) : pv0;
|
|
98
|
+
}
|
|
99
|
+
uvRects[offset] = pu0;
|
|
100
|
+
uvRects[offset + 1] = pv1;
|
|
101
|
+
uvRects[offset + 2] = pu1;
|
|
102
|
+
uvRects[offset + 3] = pv0;
|
|
103
|
+
if (hasTrims) {
|
|
104
|
+
trims[offset] = pt0;
|
|
105
|
+
trims[offset + 1] = pt1;
|
|
106
|
+
trims[offset + 2] = pt2;
|
|
107
|
+
trims[offset + 3] = pt3;
|
|
108
|
+
}
|
|
109
|
+
const color = glyph.color;
|
|
110
|
+
if (color !== prevColor) {
|
|
111
|
+
prevColor = color;
|
|
112
|
+
c0 = byte(color[0]);
|
|
113
|
+
c1 = byte(color[1]);
|
|
114
|
+
c2 = byte(color[2]);
|
|
115
|
+
c3 = byte(color[3]);
|
|
116
|
+
}
|
|
117
|
+
colors[offset] = c0;
|
|
118
|
+
colors[offset + 1] = c1;
|
|
119
|
+
colors[offset + 2] = c2;
|
|
120
|
+
colors[offset + 3] = c3;
|
|
121
|
+
const mOff = index * metaItemSize;
|
|
122
|
+
const seq = glyph.sequence;
|
|
123
|
+
const z = glyph.z;
|
|
124
|
+
metadata[mOff] = seq;
|
|
125
|
+
metadata[mOff + 1] = z;
|
|
126
|
+
if (metaItemSize === 3) metadata[mOff + 2] = glyph.switchEm ?? 0;
|
|
127
|
+
if (runMotion) {
|
|
128
|
+
const rOff = index * 3;
|
|
129
|
+
const origin = glyph.motionOrigin;
|
|
130
|
+
const motionIndex = origin?.[2] ?? motionOrdinals?.[ordinal] ?? ordinal - groupRepeats;
|
|
131
|
+
runMotion[rOff] = origin ? origin[0] : (r0 + r2) * .5;
|
|
132
|
+
runMotion[rOff + 1] = origin ? origin[1] : (r1 + r3) * .5;
|
|
133
|
+
runMotion[rOff + 2] = motionIndex;
|
|
134
|
+
}
|
|
135
|
+
if (seq > maxSequence) maxSequence = seq;
|
|
136
|
+
if (z < minZ) minZ = z;
|
|
137
|
+
if (z > maxZ) maxZ = z;
|
|
138
|
+
}
|
|
139
|
+
if (dom && count === total) prevBatchCache.set(cache, [
|
|
140
|
+
glyphs,
|
|
141
|
+
root,
|
|
142
|
+
atlas.bakeSize,
|
|
143
|
+
flags
|
|
144
|
+
]);
|
|
145
|
+
else prevBatchCache.delete(cache);
|
|
146
|
+
batchSummary[0] = count;
|
|
147
|
+
batchSummary[1] = maxSequence;
|
|
148
|
+
batchSummary[2] = minZ;
|
|
149
|
+
batchSummary[3] = maxZ;
|
|
150
|
+
}
|
|
151
|
+
function writeGlyphBatchDirty(snapshot, atlas, rects, clips, metadata, metaItemSize, runMotion, motionOrdinals, uvRects, trims, colors, maxCount, dirty, cache) {
|
|
152
|
+
const glyphs = snapshot.glyphs;
|
|
153
|
+
const total = glyphs.length;
|
|
154
|
+
const shaped = snapshot.textShaping === "browser";
|
|
155
|
+
const invBakeSize = 1 / atlas.bakeSize;
|
|
156
|
+
const atlasGlyphs = atlas.glyphs;
|
|
157
|
+
const packUvs = uvRects !== void 0 && colors !== void 0;
|
|
158
|
+
const hasTrims = trims !== null;
|
|
159
|
+
const groupMotion = !!runMotion && !motionOrdinals && needsRunMotion(snapshot);
|
|
160
|
+
let groupRepeats = 0;
|
|
161
|
+
let previousGroup;
|
|
162
|
+
let count = 0;
|
|
163
|
+
let maxSequence = 0;
|
|
164
|
+
let minZ = 0;
|
|
165
|
+
let maxZ = 0;
|
|
166
|
+
let prevKey;
|
|
167
|
+
let prevSlot;
|
|
168
|
+
let prevUvSlot;
|
|
169
|
+
let pu0 = 0;
|
|
170
|
+
let pv1 = 0;
|
|
171
|
+
let pu1 = 0;
|
|
172
|
+
let pv0 = 0;
|
|
173
|
+
let pt0 = 0;
|
|
174
|
+
let pt1 = 0;
|
|
175
|
+
let pt2 = 0;
|
|
176
|
+
let pt3 = 0;
|
|
177
|
+
let prevColor;
|
|
178
|
+
let c0 = 0;
|
|
179
|
+
let c1 = 0;
|
|
180
|
+
let c2 = 0;
|
|
181
|
+
let c3 = 0;
|
|
182
|
+
let prevClip;
|
|
183
|
+
let fc0 = 0;
|
|
184
|
+
let fc1 = 0;
|
|
185
|
+
let fc2 = 0;
|
|
186
|
+
let fc3 = 0;
|
|
187
|
+
const dom = isDomSnapshot(snapshot);
|
|
188
|
+
const root = dom ? atlasRootOf(atlasGlyphs) : null;
|
|
189
|
+
const flags = (shaped ? 1 : 0) | (runMotion !== null ? 2 : 0) | metaItemSize << 2;
|
|
190
|
+
const prev = dom ? prevBatchCache.get(cache) : void 0;
|
|
191
|
+
let canSkip = prev?.[1] === root && prev[2] === atlas.bakeSize && prev[3] === flags;
|
|
192
|
+
const prevGlyphs = canSkip ? prev[0] : void 0;
|
|
193
|
+
for (let i = 0; i < 14; i += 2) {
|
|
194
|
+
dirty[i] = 0;
|
|
195
|
+
dirty[i + 1] = -1;
|
|
196
|
+
}
|
|
197
|
+
for (let ordinal = 0; ordinal < total; ordinal++) {
|
|
198
|
+
const glyph = glyphs[ordinal];
|
|
199
|
+
if (groupMotion) {
|
|
200
|
+
const group = glyph.shapeGroup;
|
|
201
|
+
if (group !== void 0 && group === previousGroup) groupRepeats++;
|
|
202
|
+
previousGroup = group;
|
|
203
|
+
}
|
|
204
|
+
if (canSkip && count === ordinal && ordinal < prevGlyphs.length && glyph === prevGlyphs[ordinal]) {
|
|
205
|
+
if (count >= maxCount) {
|
|
206
|
+
prevBatchCache.delete(cache);
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
count++;
|
|
210
|
+
if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
|
|
211
|
+
if (glyph.z < minZ) minZ = glyph.z;
|
|
212
|
+
if (glyph.z > maxZ) maxZ = glyph.z;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const gKey = glyph.glyphKey;
|
|
216
|
+
const slot = gKey === prevKey ? prevSlot : (prevKey = gKey, prevSlot = atlasGlyphs.get(gKey));
|
|
217
|
+
if (!slot) {
|
|
218
|
+
canSkip = false;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (count >= maxCount) {
|
|
222
|
+
prevBatchCache.delete(cache);
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
const index = count++;
|
|
226
|
+
const offset = index * 4;
|
|
227
|
+
const scale = glyph.fontSize * invBakeSize;
|
|
228
|
+
const scaleX = shaped && slot.advance > 0 ? glyph.advance / slot.advance : scale;
|
|
229
|
+
const baseline = glyph.lineBottom + (glyph.baselineOffset ?? slot.descent * scale);
|
|
230
|
+
const ox = glyph.originX;
|
|
231
|
+
const r0 = Math.fround(ox + slot.planeX0 * scaleX);
|
|
232
|
+
const r1 = Math.fround(baseline + slot.planeY0 * scale);
|
|
233
|
+
const r2 = Math.fround(ox + slot.planeX1 * scaleX);
|
|
234
|
+
const r3 = Math.fround(baseline + slot.planeY1 * scale);
|
|
235
|
+
writeDirty4(rects, offset, r0, r1, r2, r3, dirty, 0);
|
|
236
|
+
const clip = glyph.clip;
|
|
237
|
+
if (clip !== prevClip) {
|
|
238
|
+
prevClip = clip;
|
|
239
|
+
fc0 = Math.fround(clip[0]);
|
|
240
|
+
fc1 = Math.fround(clip[1]);
|
|
241
|
+
fc2 = Math.fround(clip[2]);
|
|
242
|
+
fc3 = Math.fround(clip[3]);
|
|
243
|
+
}
|
|
244
|
+
writeDirty4(clips, offset, fc0, fc1, fc2, fc3, dirty, 2);
|
|
245
|
+
const mOff = index * metaItemSize;
|
|
246
|
+
const seq = glyph.sequence;
|
|
247
|
+
const z = glyph.z;
|
|
248
|
+
if (packUvs) {
|
|
249
|
+
if (slot !== prevUvSlot) {
|
|
250
|
+
prevUvSlot = slot;
|
|
251
|
+
pu0 = slot.u0 * 65535 + .5 | 0;
|
|
252
|
+
pv1 = slot.v1 * 65535 + .5 | 0;
|
|
253
|
+
pu1 = slot.u1 * 65535 + .5 | 0;
|
|
254
|
+
pv0 = slot.v0 * 65535 + .5 | 0;
|
|
255
|
+
const s = hasTrims ? slot.support : void 0;
|
|
256
|
+
pt0 = s ? clamp16(Math.floor(s.u0 * 65535)) : pu0;
|
|
257
|
+
pt1 = s ? clamp16(Math.ceil(s.v1 * 65535)) : pv1;
|
|
258
|
+
pt2 = s ? clamp16(Math.ceil(s.u1 * 65535)) : pu1;
|
|
259
|
+
pt3 = s ? clamp16(Math.floor(s.v0 * 65535)) : pv0;
|
|
260
|
+
}
|
|
261
|
+
const color = glyph.color;
|
|
262
|
+
if (color !== prevColor) {
|
|
263
|
+
prevColor = color;
|
|
264
|
+
c0 = byte(color[0]);
|
|
265
|
+
c1 = byte(color[1]);
|
|
266
|
+
c2 = byte(color[2]);
|
|
267
|
+
c3 = byte(color[3]);
|
|
268
|
+
}
|
|
269
|
+
writeDirty4(uvRects, offset, pu0, pv1, pu1, pv0, dirty, 6);
|
|
270
|
+
if (hasTrims) writeDirty4(trims, offset, pt0, pt1, pt2, pt3, dirty, 10);
|
|
271
|
+
writeDirty4(colors, offset, c0, c1, c2, c3, dirty, 8);
|
|
272
|
+
const m0 = Math.fround(seq);
|
|
273
|
+
const m1 = Math.fround(z);
|
|
274
|
+
const m2 = metaItemSize === 3 ? Math.fround(glyph.switchEm ?? 0) : 0;
|
|
275
|
+
if (metadata[mOff] !== m0 || metadata[mOff + 1] !== m1 || metaItemSize === 3 && metadata[mOff + 2] !== m2) {
|
|
276
|
+
metadata[mOff] = m0;
|
|
277
|
+
metadata[mOff + 1] = m1;
|
|
278
|
+
if (metaItemSize === 3) metadata[mOff + 2] = m2;
|
|
279
|
+
if (dirty[5] < 0) dirty[4] = mOff;
|
|
280
|
+
dirty[5] = mOff + metaItemSize;
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
const m0 = Math.fround(seq);
|
|
284
|
+
if (metadata[mOff] !== m0) {
|
|
285
|
+
metadata[mOff] = m0;
|
|
286
|
+
if (dirty[5] < 0) dirty[4] = mOff;
|
|
287
|
+
dirty[5] = mOff + 1;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (runMotion) {
|
|
291
|
+
const rOff = index * 3;
|
|
292
|
+
const origin = glyph.motionOrigin;
|
|
293
|
+
const motionIndex = origin?.[2] ?? motionOrdinals?.[ordinal] ?? ordinal - groupRepeats;
|
|
294
|
+
const rx = Math.fround(origin ? origin[0] : (r0 + r2) * .5);
|
|
295
|
+
const ry = Math.fround(origin ? origin[1] : (r1 + r3) * .5);
|
|
296
|
+
const rz = Math.fround(motionIndex);
|
|
297
|
+
if (runMotion[rOff] !== rx || runMotion[rOff + 1] !== ry || runMotion[rOff + 2] !== rz) {
|
|
298
|
+
runMotion[rOff] = rx;
|
|
299
|
+
runMotion[rOff + 1] = ry;
|
|
300
|
+
runMotion[rOff + 2] = rz;
|
|
301
|
+
if (dirty[13] < 0) dirty[12] = rOff;
|
|
302
|
+
dirty[13] = rOff + 3;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (seq > maxSequence) maxSequence = seq;
|
|
306
|
+
if (z < minZ) minZ = z;
|
|
307
|
+
if (z > maxZ) maxZ = z;
|
|
308
|
+
}
|
|
309
|
+
if (dom && count === total) prevBatchCache.set(cache, [
|
|
310
|
+
glyphs,
|
|
311
|
+
root,
|
|
312
|
+
atlas.bakeSize,
|
|
313
|
+
flags
|
|
314
|
+
]);
|
|
315
|
+
else prevBatchCache.delete(cache);
|
|
316
|
+
batchSummary[0] = count;
|
|
317
|
+
batchSummary[1] = maxSequence;
|
|
318
|
+
batchSummary[2] = minZ;
|
|
319
|
+
batchSummary[3] = maxZ;
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
var dirtyBounds = /* @__PURE__ */ new Int32Array(14);
|
|
323
|
+
function setInstancedAttr(geometry, name, array, count, total, size, normalized) {
|
|
324
|
+
geometry.setAttribute(name, new InstancedBufferAttribute(count === total ? array : array.subarray(0, count * size), size, normalized));
|
|
325
|
+
}
|
|
326
|
+
function createGlyphGeometry(snapshot, atlas, motionPadding, motionOrdinals) {
|
|
327
|
+
const hasRunMotion = needsRunMotion(snapshot);
|
|
328
|
+
const total = snapshot.glyphs.length;
|
|
329
|
+
const rects = new Float32Array(total * 4);
|
|
330
|
+
const uvRects = new Uint16Array(total * 4);
|
|
331
|
+
const clips = new Float32Array(total * 4);
|
|
332
|
+
const colors = new Uint8Array(total * 4);
|
|
333
|
+
const meta = metaSize(snapshot);
|
|
334
|
+
const metadata = new Float32Array(total * meta);
|
|
335
|
+
const runMotion = hasRunMotion || motionOrdinals ? new Float32Array(total * 3) : null;
|
|
336
|
+
const trims = runMotion ? null : new Uint16Array(total * 4);
|
|
337
|
+
const geometry = new InstancedBufferGeometry();
|
|
338
|
+
writeGlyphBatchFresh(snapshot, atlas, rects, clips, metadata, meta, runMotion, motionOrdinals, uvRects, trims, colors, geometry);
|
|
339
|
+
const count = batchSummary[0];
|
|
340
|
+
const maxSequence = batchSummary[1];
|
|
341
|
+
const minZ = batchSummary[2];
|
|
342
|
+
const maxZ = batchSummary[3];
|
|
343
|
+
geometry.name = "ultra-text instanced glyph quads";
|
|
344
|
+
setUnitQuad(geometry);
|
|
345
|
+
setInstancedAttr(geometry, "sdfRect", rects, count, total, 4, false);
|
|
346
|
+
setInstancedAttr(geometry, "sdfUvRect", uvRects, count, total, 4, true);
|
|
347
|
+
setInstancedAttr(geometry, "sdfClip", clips, count, total, 4, false);
|
|
348
|
+
setInstancedAttr(geometry, "sdfColor", colors, count, total, 4, true);
|
|
349
|
+
setInstancedAttr(geometry, "sdfMeta", metadata, count, total, meta, false);
|
|
350
|
+
if (runMotion) setInstancedAttr(geometry, "sdfRunMotion", runMotion, count, total, 3, false);
|
|
351
|
+
if (trims) setInstancedAttr(geometry, "sdfTrim", trims, count, total, 4, true);
|
|
352
|
+
geometry.instanceCount = count;
|
|
353
|
+
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ);
|
|
354
|
+
return {
|
|
355
|
+
geometry,
|
|
356
|
+
maxSequence
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function updateGlyphGeometry(geometry, snapshot, atlas, motionPadding, motionOrdinals) {
|
|
360
|
+
const instanceCount = geometry.instanceCount;
|
|
361
|
+
if (snapshot.glyphs.length < instanceCount) return null;
|
|
362
|
+
const rectAttribute = attrOf(geometry, "sdfRect");
|
|
363
|
+
const clipAttribute = attrOf(geometry, "sdfClip");
|
|
364
|
+
const metaAttribute = attrOf(geometry, "sdfMeta");
|
|
365
|
+
if (!rectAttribute || !clipAttribute || !metaAttribute) return null;
|
|
366
|
+
const runAttribute = attrOf(geometry, "sdfRunMotion");
|
|
367
|
+
if (!writeGlyphBatchDirty(snapshot, atlas, rectAttribute.array, clipAttribute.array, metaAttribute.array, metaAttribute.itemSize, runAttribute ? runAttribute.array : null, motionOrdinals, void 0, null, void 0, instanceCount, dirtyBounds, geometry) || batchSummary[0] !== instanceCount) {
|
|
368
|
+
prevBatchCache.delete(geometry);
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
flushAttributeUpdate(rectAttribute, dirtyBounds[0], dirtyBounds[1]);
|
|
372
|
+
flushAttributeUpdate(clipAttribute, dirtyBounds[2], dirtyBounds[3]);
|
|
373
|
+
flushAttributeUpdate(metaAttribute, dirtyBounds[4], dirtyBounds[5]);
|
|
374
|
+
flushAttributeUpdate(runAttribute, dirtyBounds[12], dirtyBounds[13]);
|
|
375
|
+
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, batchSummary[2], batchSummary[3]);
|
|
376
|
+
return batchSummary[1];
|
|
377
|
+
}
|
|
378
|
+
function drawableGlyphCountMatches(geometry, snapshot, atlas, expectedCount) {
|
|
379
|
+
let count = 0;
|
|
380
|
+
const glyphs = snapshot.glyphs;
|
|
381
|
+
const total = glyphs.length;
|
|
382
|
+
const atlasGlyphs = atlas.glyphs;
|
|
383
|
+
const prev = isDomSnapshot(snapshot) ? prevBatchCache.get(geometry) : void 0;
|
|
384
|
+
const prevGlyphs = prev?.[1] === atlasRootOf(atlasGlyphs) && prev[0].length === total && total === expectedCount ? prev[0] : void 0;
|
|
385
|
+
let prevKey;
|
|
386
|
+
let prevHas = false;
|
|
387
|
+
if (prevGlyphs !== void 0) for (let i = 0; i < total; i++) {
|
|
388
|
+
const glyph = glyphs[i];
|
|
389
|
+
if (glyph === prevGlyphs[i]) {
|
|
390
|
+
count++;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const key = glyph.glyphKey;
|
|
394
|
+
if ((key === prevKey ? prevHas : (prevKey = key, prevHas = atlasGlyphs.has(key))) && ++count > expectedCount) return false;
|
|
395
|
+
}
|
|
396
|
+
else for (let i = 0; i < total; i++) {
|
|
397
|
+
const key = glyphs[i].glyphKey;
|
|
398
|
+
if ((key === prevKey ? prevHas : (prevKey = key, prevHas = atlasGlyphs.has(key))) && ++count > expectedCount) return false;
|
|
399
|
+
}
|
|
400
|
+
return count === expectedCount;
|
|
401
|
+
}
|
|
402
|
+
function glyphContentFits(geometry, snapshot, atlas, motionOrdinals, skipDrawableCheck) {
|
|
403
|
+
const instanceCount = geometry.instanceCount;
|
|
404
|
+
if (snapshot.glyphs.length < instanceCount) return false;
|
|
405
|
+
if (!instanceAttribute(geometry, "sdfRect", 4) || !instanceAttribute(geometry, "sdfUvRect", 4) || !instanceAttribute(geometry, "sdfClip", 4) || !instanceAttribute(geometry, "sdfColor", 4)) return false;
|
|
406
|
+
if (!instanceAttribute(geometry, "sdfMeta", metaSize(snapshot))) return false;
|
|
407
|
+
const run = attrOf(geometry, "sdfRunMotion");
|
|
408
|
+
const wantsRun = needsRunMotion(snapshot) || !!motionOrdinals;
|
|
409
|
+
const trim = attrOf(geometry, "sdfTrim");
|
|
410
|
+
return (wantsRun ? run?.itemSize === 3 && run.count === instanceCount && trim === void 0 : run === void 0 && (trim === void 0 || instanceAttribute(geometry, "sdfTrim", 4))) && (Boolean(skipDrawableCheck && snapshot.glyphs.length === instanceCount) || drawableGlyphCountMatches(geometry, snapshot, atlas, instanceCount));
|
|
411
|
+
}
|
|
412
|
+
function updateGlyphContent(geometry, snapshot, atlas, motionPadding, motionOrdinals, checked) {
|
|
413
|
+
if (!checked && !glyphContentFits(geometry, snapshot, atlas, motionOrdinals)) return null;
|
|
414
|
+
const rectAttribute = attrOf(geometry, "sdfRect");
|
|
415
|
+
const uvAttribute = attrOf(geometry, "sdfUvRect");
|
|
416
|
+
const clipAttribute = attrOf(geometry, "sdfClip");
|
|
417
|
+
const colorAttribute = attrOf(geometry, "sdfColor");
|
|
418
|
+
const metaAttribute = attrOf(geometry, "sdfMeta");
|
|
419
|
+
const trimAttribute = attrOf(geometry, "sdfTrim");
|
|
420
|
+
const runAttribute = attrOf(geometry, "sdfRunMotion");
|
|
421
|
+
writeGlyphBatchDirty(snapshot, atlas, rectAttribute.array, clipAttribute.array, metaAttribute.array, metaAttribute.itemSize, runAttribute ? runAttribute.array : null, motionOrdinals, uvAttribute.array, trimAttribute ? trimAttribute.array : null, colorAttribute.array, Infinity, dirtyBounds, geometry);
|
|
422
|
+
flushAttributeUpdate(rectAttribute, dirtyBounds[0], dirtyBounds[1]);
|
|
423
|
+
flushAttributeUpdate(clipAttribute, dirtyBounds[2], dirtyBounds[3]);
|
|
424
|
+
flushAttributeUpdate(metaAttribute, dirtyBounds[4], dirtyBounds[5]);
|
|
425
|
+
flushAttributeUpdate(uvAttribute, dirtyBounds[6], dirtyBounds[7]);
|
|
426
|
+
flushAttributeUpdate(colorAttribute, dirtyBounds[8], dirtyBounds[9]);
|
|
427
|
+
flushAttributeUpdate(trimAttribute, dirtyBounds[10], dirtyBounds[11]);
|
|
428
|
+
flushAttributeUpdate(runAttribute, dirtyBounds[12], dirtyBounds[13]);
|
|
429
|
+
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, batchSummary[2], batchSummary[3]);
|
|
430
|
+
return batchSummary[1];
|
|
431
|
+
}
|
|
432
|
+
export { createGlyphGeometry, glyphContentFits, updateGlyphContent, updateGlyphGeometry };
|
|
433
|
+
|
|
434
|
+
//# sourceMappingURL=glyphGeometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glyphGeometry.js","names":[],"sources":["../../src/text/glyphGeometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { atlasRootOf } from '../dom/markup.js'\nimport {\n attrOf,\n byte,\n flushAttributeUpdate,\n instanceAttribute,\n isDomSnapshot,\n metaSize,\n needsRunMotion,\n setBounds,\n setUnitQuad,\n writeDirty4,\n} from './geometryUtils.js'\n\nimport type { DomLayoutSnapshot, GlyphLayout, GlyphSlot, SdfAtlas } from '../types.js'\n\nconst prevBatchCache = new WeakMap<\n InstancedBufferGeometry,\n readonly [readonly GlyphLayout[], ReadonlyMap<string, unknown>, number, number]\n>()\n\nconst clamp16 = (v: number): number => Math.min(65535, Math.max(0, v))\n\nconst batchSummary: [number, number, number, number] = [0, 0, 0, 0]\n\nfunction writeGlyphBatchFresh(\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n rects: Float32Array,\n clips: Float32Array,\n metadata: Float32Array,\n metaItemSize: number,\n runMotion: Float32Array | null,\n motionOrdinals: Float32Array | undefined,\n uvRects: Uint16Array,\n trims: Uint16Array | null,\n colors: Uint8Array,\n cache: InstancedBufferGeometry,\n): void {\n const glyphs = snapshot.glyphs\n const total = glyphs.length\n const shaped = snapshot.textShaping === 'browser'\n const invBakeSize = 1 / atlas.bakeSize\n const atlasGlyphs = atlas.glyphs\n const hasTrims = trims !== null\n const groupMotion = !!runMotion && !motionOrdinals && needsRunMotion(snapshot)\n let groupRepeats = 0\n let previousGroup: number | undefined\n let count = 0\n let maxSequence = 0\n let minZ = 0\n let maxZ = 0\n let prevKey: string | undefined\n let prevSlot: GlyphSlot | undefined\n let prevUvSlot: GlyphSlot | undefined\n let pu0 = 0\n let pv1 = 0\n let pu1 = 0\n let pv0 = 0\n let pt0 = 0\n let pt1 = 0\n let pt2 = 0\n let pt3 = 0\n let prevColor: GlyphLayout['color'] | undefined\n let c0 = 0\n let c1 = 0\n let c2 = 0\n let c3 = 0\n let prevClip: GlyphLayout['clip'] | undefined\n let fc0 = 0\n let fc1 = 0\n let fc2 = 0\n let fc3 = 0\n const dom = isDomSnapshot(snapshot)\n const root = dom ? atlasRootOf(atlasGlyphs) : null\n const flags = (shaped ? 1 : 0) | (runMotion !== null ? 2 : 0) | (metaItemSize << 2)\n\n for (let ordinal = 0; ordinal < total; ordinal++) {\n const glyph = glyphs[ordinal]!\n // The source ordinal includes missing atlas slots. Each consecutive shape group counts once.\n if (groupMotion) {\n const group = glyph.shapeGroup\n if (group !== undefined && group === previousGroup) groupRepeats++\n previousGroup = group\n }\n const gKey = glyph.glyphKey\n const slot =\n gKey === prevKey ? prevSlot : ((prevKey = gKey), (prevSlot = atlasGlyphs.get(gKey)))\n if (!slot) continue\n const index = count++\n const offset = index * 4\n\n const scale = glyph.fontSize * invBakeSize\n const scaleX = shaped && slot.advance > 0 ? glyph.advance / slot.advance : scale\n // Range.getBoundingClientRect() reports the text box, not the line box, so\n // lineBottom already sits on the descender line: adding half the CSS\n // leading back on top of it lifted every glyph off its baseline.\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? slot.descent * scale)\n const ox = glyph.originX\n const r0 = ox + slot.planeX0 * scaleX\n const r1 = baseline + slot.planeY0 * scale\n const r2 = ox + slot.planeX1 * scaleX\n const r3 = baseline + slot.planeY1 * scale\n rects[offset] = r0\n rects[offset + 1] = r1\n rects[offset + 2] = r2\n rects[offset + 3] = r3\n\n const clip = glyph.clip\n if (clip !== prevClip) {\n prevClip = clip\n fc0 = clip[0]\n fc1 = clip[1]\n fc2 = clip[2]\n fc3 = clip[3]\n }\n clips[offset] = fc0\n clips[offset + 1] = fc1\n clips[offset + 2] = fc2\n clips[offset + 3] = fc3\n\n if (slot !== prevUvSlot) {\n prevUvSlot = slot\n pu0 = (slot.u0 * 65535 + 0.5) | 0\n pv1 = (slot.v1 * 65535 + 0.5) | 0\n pu1 = (slot.u1 * 65535 + 0.5) | 0\n pv0 = (slot.v0 * 65535 + 0.5) | 0\n const s = hasTrims ? slot.support : undefined\n pt0 = s ? clamp16(Math.floor(s.u0 * 65535)) : pu0\n pt1 = s ? clamp16(Math.ceil(s.v1 * 65535)) : pv1\n pt2 = s ? clamp16(Math.ceil(s.u1 * 65535)) : pu1\n pt3 = s ? clamp16(Math.floor(s.v0 * 65535)) : pv0\n }\n uvRects[offset] = pu0\n uvRects[offset + 1] = pv1\n uvRects[offset + 2] = pu1\n uvRects[offset + 3] = pv0\n if (hasTrims) {\n trims[offset] = pt0\n trims[offset + 1] = pt1\n trims[offset + 2] = pt2\n trims[offset + 3] = pt3\n }\n const color = glyph.color\n if (color !== prevColor) {\n prevColor = color\n c0 = byte(color[0])\n c1 = byte(color[1])\n c2 = byte(color[2])\n c3 = byte(color[3])\n }\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n\n const mOff = index * metaItemSize\n const seq = glyph.sequence\n const z = glyph.z\n metadata[mOff] = seq\n metadata[mOff + 1] = z\n if (metaItemSize === 3) metadata[mOff + 2] = glyph.switchEm ?? 0\n\n if (runMotion) {\n const rOff = index * 3\n const origin = glyph.motionOrigin\n const motionIndex = origin?.[2] ?? motionOrdinals?.[ordinal] ?? ordinal - groupRepeats\n runMotion[rOff] = origin ? origin[0] : (r0 + r2) * 0.5\n runMotion[rOff + 1] = origin ? origin[1] : (r1 + r3) * 0.5\n runMotion[rOff + 2] = motionIndex\n }\n if (seq > maxSequence) maxSequence = seq\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n }\n if (dom && count === total) prevBatchCache.set(cache, [glyphs, root!, atlas.bakeSize, flags])\n else prevBatchCache.delete(cache)\n batchSummary[0] = count\n batchSummary[1] = maxSequence\n batchSummary[2] = minZ\n batchSummary[3] = maxZ\n}\n\nfunction writeGlyphBatchDirty(\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n rects: Float32Array,\n clips: Float32Array,\n metadata: Float32Array,\n metaItemSize: number,\n runMotion: Float32Array | null,\n motionOrdinals: Float32Array | undefined,\n uvRects: Uint16Array | undefined,\n trims: Uint16Array | null,\n colors: Uint8Array | undefined,\n maxCount: number,\n dirty: Int32Array,\n cache: InstancedBufferGeometry,\n): boolean {\n const glyphs = snapshot.glyphs\n const total = glyphs.length\n const shaped = snapshot.textShaping === 'browser'\n const invBakeSize = 1 / atlas.bakeSize\n const atlasGlyphs = atlas.glyphs\n const packUvs = uvRects !== undefined && colors !== undefined\n const hasTrims = trims !== null\n const groupMotion = !!runMotion && !motionOrdinals && needsRunMotion(snapshot)\n let groupRepeats = 0\n let previousGroup: number | undefined\n let count = 0\n let maxSequence = 0\n let minZ = 0\n let maxZ = 0\n let prevKey: string | undefined\n let prevSlot: GlyphSlot | undefined\n let prevUvSlot: GlyphSlot | undefined\n let pu0 = 0\n let pv1 = 0\n let pu1 = 0\n let pv0 = 0\n let pt0 = 0\n let pt1 = 0\n let pt2 = 0\n let pt3 = 0\n let prevColor: GlyphLayout['color'] | undefined\n let c0 = 0\n let c1 = 0\n let c2 = 0\n let c3 = 0\n let prevClip: GlyphLayout['clip'] | undefined\n let fc0 = 0\n let fc1 = 0\n let fc2 = 0\n let fc3 = 0\n const dom = isDomSnapshot(snapshot)\n const root = dom ? atlasRootOf(atlasGlyphs) : null\n const flags = (shaped ? 1 : 0) | (runMotion !== null ? 2 : 0) | (metaItemSize << 2)\n const prev = dom ? prevBatchCache.get(cache) : undefined\n let canSkip = prev?.[1] === root && prev[2] === atlas.bakeSize && prev[3] === flags\n const prevGlyphs = canSkip ? prev![0] : undefined\n for (let i = 0; i < 14; i += 2) {\n dirty[i] = 0\n dirty[i + 1] = -1\n }\n\n for (let ordinal = 0; ordinal < total; ordinal++) {\n const glyph = glyphs[ordinal]!\n if (groupMotion) {\n const group = glyph.shapeGroup\n if (group !== undefined && group === previousGroup) groupRepeats++\n previousGroup = group\n }\n if (\n canSkip &&\n count === ordinal &&\n ordinal < prevGlyphs!.length &&\n glyph === prevGlyphs![ordinal]\n ) {\n if (count >= maxCount) {\n prevBatchCache.delete(cache)\n return false\n }\n count++\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n continue\n }\n const gKey = glyph.glyphKey\n const slot =\n gKey === prevKey ? prevSlot : ((prevKey = gKey), (prevSlot = atlasGlyphs.get(gKey)))\n if (!slot) {\n canSkip = false\n continue\n }\n if (count >= maxCount) {\n prevBatchCache.delete(cache)\n return false\n }\n const index = count++\n const offset = index * 4\n\n const scale = glyph.fontSize * invBakeSize\n const scaleX = shaped && slot.advance > 0 ? glyph.advance / slot.advance : scale\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? slot.descent * scale)\n const ox = glyph.originX\n const r0 = Math.fround(ox + slot.planeX0 * scaleX)\n const r1 = Math.fround(baseline + slot.planeY0 * scale)\n const r2 = Math.fround(ox + slot.planeX1 * scaleX)\n const r3 = Math.fround(baseline + slot.planeY1 * scale)\n writeDirty4(rects, offset, r0, r1, r2, r3, dirty, 0)\n\n const clip = glyph.clip\n if (clip !== prevClip) {\n prevClip = clip\n fc0 = Math.fround(clip[0])\n fc1 = Math.fround(clip[1])\n fc2 = Math.fround(clip[2])\n fc3 = Math.fround(clip[3])\n }\n writeDirty4(clips, offset, fc0, fc1, fc2, fc3, dirty, 2)\n\n const mOff = index * metaItemSize\n const seq = glyph.sequence\n const z = glyph.z\n if (packUvs) {\n if (slot !== prevUvSlot) {\n prevUvSlot = slot\n pu0 = (slot.u0 * 65535 + 0.5) | 0\n pv1 = (slot.v1 * 65535 + 0.5) | 0\n pu1 = (slot.u1 * 65535 + 0.5) | 0\n pv0 = (slot.v0 * 65535 + 0.5) | 0\n const s = hasTrims ? slot.support : undefined\n pt0 = s ? clamp16(Math.floor(s.u0 * 65535)) : pu0\n pt1 = s ? clamp16(Math.ceil(s.v1 * 65535)) : pv1\n pt2 = s ? clamp16(Math.ceil(s.u1 * 65535)) : pu1\n pt3 = s ? clamp16(Math.floor(s.v0 * 65535)) : pv0\n }\n const color = glyph.color\n if (color !== prevColor) {\n prevColor = color\n c0 = byte(color[0])\n c1 = byte(color[1])\n c2 = byte(color[2])\n c3 = byte(color[3])\n }\n writeDirty4(uvRects, offset, pu0, pv1, pu1, pv0, dirty, 6)\n if (hasTrims) writeDirty4(trims, offset, pt0, pt1, pt2, pt3, dirty, 10)\n writeDirty4(colors, offset, c0, c1, c2, c3, dirty, 8)\n const m0 = Math.fround(seq)\n const m1 = Math.fround(z)\n const m2 = metaItemSize === 3 ? Math.fround(glyph.switchEm ?? 0) : 0\n if (\n metadata[mOff] !== m0 ||\n metadata[mOff + 1] !== m1 ||\n (metaItemSize === 3 && metadata[mOff + 2] !== m2)\n ) {\n metadata[mOff] = m0\n metadata[mOff + 1] = m1\n if (metaItemSize === 3) metadata[mOff + 2] = m2\n if (dirty[5]! < 0) dirty[4] = mOff\n dirty[5] = mOff + metaItemSize\n }\n } else {\n const m0 = Math.fround(seq)\n if (metadata[mOff] !== m0) {\n metadata[mOff] = m0\n if (dirty[5]! < 0) dirty[4] = mOff\n dirty[5] = mOff + 1\n }\n }\n\n if (runMotion) {\n const rOff = index * 3\n const origin = glyph.motionOrigin\n const motionIndex = origin?.[2] ?? motionOrdinals?.[ordinal] ?? ordinal - groupRepeats\n const rx = Math.fround(origin ? origin[0] : (r0 + r2) * 0.5)\n const ry = Math.fround(origin ? origin[1] : (r1 + r3) * 0.5)\n const rz = Math.fround(motionIndex)\n if (runMotion[rOff] !== rx || runMotion[rOff + 1] !== ry || runMotion[rOff + 2] !== rz) {\n runMotion[rOff] = rx\n runMotion[rOff + 1] = ry\n runMotion[rOff + 2] = rz\n if (dirty[13]! < 0) dirty[12] = rOff\n dirty[13] = rOff + 3\n }\n }\n if (seq > maxSequence) maxSequence = seq\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n }\n if (dom && count === total) prevBatchCache.set(cache, [glyphs, root!, atlas.bakeSize, flags])\n else prevBatchCache.delete(cache)\n batchSummary[0] = count\n batchSummary[1] = maxSequence\n batchSummary[2] = minZ\n batchSummary[3] = maxZ\n return true\n}\n\nconst dirtyBounds = new Int32Array(14)\n\nfunction setInstancedAttr(\n geometry: InstancedBufferGeometry,\n name: string,\n array: Float32Array | Uint16Array | Uint8Array,\n count: number,\n total: number,\n size: number,\n normalized: boolean,\n): void {\n geometry.setAttribute(\n name,\n new InstancedBufferAttribute(\n count === total ? array : array.subarray(0, count * size),\n size,\n normalized,\n ),\n )\n}\n\nexport function createGlyphGeometry(\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionPadding: number,\n motionOrdinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n const hasRunMotion = needsRunMotion(snapshot)\n const total = snapshot.glyphs.length\n const rects = new Float32Array(total * 4)\n const uvRects = new Uint16Array(total * 4)\n const clips = new Float32Array(total * 4)\n const colors = new Uint8Array(total * 4)\n const meta = metaSize(snapshot)\n const metadata = new Float32Array(total * meta)\n const runMotion = hasRunMotion || motionOrdinals ? new Float32Array(total * 3) : null\n const trims = runMotion ? null : new Uint16Array(total * 4)\n const geometry = new InstancedBufferGeometry()\n writeGlyphBatchFresh(\n snapshot,\n atlas,\n rects,\n clips,\n metadata,\n meta,\n runMotion,\n motionOrdinals,\n uvRects,\n trims,\n colors,\n geometry,\n )\n const count = batchSummary[0]\n const maxSequence = batchSummary[1]\n const minZ = batchSummary[2]\n const maxZ = batchSummary[3]\n\n geometry.name = 'ultra-text instanced glyph quads'\n setUnitQuad(geometry)\n setInstancedAttr(geometry, 'sdfRect', rects, count, total, 4, false)\n setInstancedAttr(geometry, 'sdfUvRect', uvRects, count, total, 4, true)\n setInstancedAttr(geometry, 'sdfClip', clips, count, total, 4, false)\n setInstancedAttr(geometry, 'sdfColor', colors, count, total, 4, true)\n setInstancedAttr(geometry, 'sdfMeta', metadata, count, total, meta, false)\n if (runMotion) setInstancedAttr(geometry, 'sdfRunMotion', runMotion, count, total, 3, false)\n if (trims) setInstancedAttr(geometry, 'sdfTrim', trims, count, total, 4, true)\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return { geometry, maxSequence }\n}\n\nexport function updateGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionPadding: number,\n motionOrdinals?: Float32Array,\n): number | null {\n const instanceCount = geometry.instanceCount\n if (snapshot.glyphs.length < instanceCount) return null\n const rectAttribute = attrOf<Float32Array>(geometry, 'sdfRect')\n const clipAttribute = attrOf<Float32Array>(geometry, 'sdfClip')\n const metaAttribute = attrOf<Float32Array>(geometry, 'sdfMeta')\n if (!rectAttribute || !clipAttribute || !metaAttribute) return null\n const runAttribute = attrOf<Float32Array>(geometry, 'sdfRunMotion')\n const ok = writeGlyphBatchDirty(\n snapshot,\n atlas,\n rectAttribute.array,\n clipAttribute.array,\n metaAttribute.array,\n metaAttribute.itemSize,\n runAttribute ? runAttribute.array : null,\n motionOrdinals,\n undefined,\n null,\n undefined,\n instanceCount,\n dirtyBounds,\n geometry,\n )\n if (!ok || batchSummary[0] !== instanceCount) {\n prevBatchCache.delete(geometry)\n return null\n }\n\n flushAttributeUpdate(rectAttribute, dirtyBounds[0]!, dirtyBounds[1]!)\n flushAttributeUpdate(clipAttribute, dirtyBounds[2]!, dirtyBounds[3]!)\n flushAttributeUpdate(metaAttribute, dirtyBounds[4]!, dirtyBounds[5]!)\n flushAttributeUpdate(runAttribute, dirtyBounds[12]!, dirtyBounds[13]!)\n setBounds(\n geometry,\n snapshot.width,\n snapshot.height,\n motionPadding,\n batchSummary[2],\n batchSummary[3],\n )\n return batchSummary[1]\n}\n\nfunction drawableGlyphCountMatches(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n expectedCount: number,\n): boolean {\n let count = 0\n const glyphs = snapshot.glyphs\n const total = glyphs.length\n const atlasGlyphs = atlas.glyphs\n const prev = isDomSnapshot(snapshot) ? prevBatchCache.get(geometry) : undefined\n const prevGlyphs =\n prev?.[1] === atlasRootOf(atlasGlyphs) && prev[0].length === total && total === expectedCount\n ? prev[0]\n : undefined\n let prevKey: string | undefined\n let prevHas = false\n if (prevGlyphs !== undefined) {\n for (let i = 0; i < total; i++) {\n const glyph = glyphs[i]!\n if (glyph === prevGlyphs[i]) {\n count++\n continue\n }\n const key = glyph.glyphKey\n const has = key === prevKey ? prevHas : ((prevKey = key), (prevHas = atlasGlyphs.has(key)))\n if (has && ++count > expectedCount) return false\n }\n } else {\n for (let i = 0; i < total; i++) {\n const key = glyphs[i]!.glyphKey\n const has = key === prevKey ? prevHas : ((prevKey = key), (prevHas = atlasGlyphs.has(key)))\n if (has && ++count > expectedCount) return false\n }\n }\n return count === expectedCount\n}\n\nexport function glyphContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionOrdinals?: Float32Array,\n skipDrawableCheck?: boolean,\n): boolean {\n const instanceCount = geometry.instanceCount\n if (snapshot.glyphs.length < instanceCount) return false\n if (\n !instanceAttribute(geometry, 'sdfRect', 4) ||\n !instanceAttribute(geometry, 'sdfUvRect', 4) ||\n !instanceAttribute(geometry, 'sdfClip', 4) ||\n !instanceAttribute(geometry, 'sdfColor', 4)\n ) {\n return false\n }\n if (!instanceAttribute(geometry, 'sdfMeta', metaSize(snapshot))) return false\n const run = attrOf(geometry, 'sdfRunMotion')\n const wantsRun = needsRunMotion(snapshot) || !!motionOrdinals\n const trim = attrOf(geometry, 'sdfTrim')\n const layoutFits = wantsRun\n ? run?.itemSize === 3 && run.count === instanceCount && trim === undefined\n : run === undefined && (trim === undefined || instanceAttribute(geometry, 'sdfTrim', 4))\n return (\n layoutFits &&\n (Boolean(skipDrawableCheck && snapshot.glyphs.length === instanceCount) ||\n drawableGlyphCountMatches(geometry, snapshot, atlas, instanceCount))\n )\n}\n\nexport function updateGlyphContent(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionPadding: number,\n motionOrdinals?: Float32Array,\n checked?: boolean,\n): number | null {\n if (!checked && !glyphContentFits(geometry, snapshot, atlas, motionOrdinals)) return null\n const rectAttribute = attrOf<Float32Array>(geometry, 'sdfRect')!\n const uvAttribute = attrOf<Uint16Array>(geometry, 'sdfUvRect')!\n const clipAttribute = attrOf<Float32Array>(geometry, 'sdfClip')!\n const colorAttribute = attrOf<Uint8Array>(geometry, 'sdfColor')!\n const metaAttribute = attrOf<Float32Array>(geometry, 'sdfMeta')!\n const trimAttribute = attrOf<Uint16Array>(geometry, 'sdfTrim')\n const runAttribute = attrOf<Float32Array>(geometry, 'sdfRunMotion')\n writeGlyphBatchDirty(\n snapshot,\n atlas,\n rectAttribute.array,\n clipAttribute.array,\n metaAttribute.array,\n metaAttribute.itemSize,\n runAttribute ? runAttribute.array : null,\n motionOrdinals,\n uvAttribute.array,\n trimAttribute ? trimAttribute.array : null,\n colorAttribute.array,\n Infinity,\n dirtyBounds,\n geometry,\n )\n flushAttributeUpdate(rectAttribute, dirtyBounds[0]!, dirtyBounds[1]!)\n flushAttributeUpdate(clipAttribute, dirtyBounds[2]!, dirtyBounds[3]!)\n flushAttributeUpdate(metaAttribute, dirtyBounds[4]!, dirtyBounds[5]!)\n flushAttributeUpdate(uvAttribute, dirtyBounds[6]!, dirtyBounds[7]!)\n flushAttributeUpdate(colorAttribute, dirtyBounds[8]!, dirtyBounds[9]!)\n flushAttributeUpdate(trimAttribute, dirtyBounds[10]!, dirtyBounds[11]!)\n flushAttributeUpdate(runAttribute, dirtyBounds[12]!, dirtyBounds[13]!)\n setBounds(\n geometry,\n snapshot.width,\n snapshot.height,\n motionPadding,\n batchSummary[2],\n batchSummary[3],\n )\n return batchSummary[1]\n}\n"],"mappings":";;;;AAiBA,IAAM,iCAAiB,IAAI,QAGzB;AAEF,IAAM,WAAW,MAAsB,KAAK,IAAI,OAAO,KAAK,IAAI,GAAG,CAAC,CAAC;AAErE,IAAM,eAAiD;CAAC;CAAG;CAAG;CAAG;AAAC;AAElE,SAAS,qBACP,UACA,OACA,OACA,OACA,UACA,cACA,WACA,gBACA,SACA,OACA,QACA,OACM;CACN,MAAM,SAAS,SAAS;CACxB,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,SAAS,gBAAgB;CACxC,MAAM,cAAc,IAAI,MAAM;CAC9B,MAAM,cAAc,MAAM;CAC1B,MAAM,WAAW,UAAU;CAC3B,MAAM,cAAc,CAAC,CAAC,aAAa,CAAC,kBAAkB,eAAe,QAAQ;CAC7E,IAAI,eAAe;CACnB,IAAI;CACJ,IAAI,QAAQ;CACZ,IAAI,cAAc;CAClB,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI,MAAM;CACV,IAAI;CACJ,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI;CACJ,IA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G;CACpE,qBAAqB,eAAe,YAAY,IAAK,YAAY,EAAG;CACpE,qBAAqB,eAAe,YAAY,IAAK,YAAY,EAAG;CACpE,qBAAqB,aAAa,YAAY,IAAK,YAAY,EAAG;CAClE,qBAAqB,gBAAgB,YAAY,IAAK,YAAY,EAAG;CACrE,qBAAqB,eAAe,YAAY,KAAM,YAAY,GAAI;CACtE,qBAAqB,cAAc,YAAY,KAAM,YAAY,GAAI;CACrE,UACE,UACA,SAAS,OACT,SAAS,QACT,eACA,aAAa,IACb,aAAa,EACf;CACA,OAAO,aAAa;AACtB"}
|
package/dist/text/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createRectMaterial } from './RectMaterial.js';
|
|
2
2
|
export { SdfTextMaterial } from './SdfTextMaterial.js';
|
|
3
|
-
export { createGlyphGeometry
|
|
3
|
+
export { createGlyphGeometry } from './glyphGeometry.js';
|
|
4
|
+
export { createRectGeometry } from './rectGeometry.js';
|
|
4
5
|
export { reflowSnapshot } from './reflow.js';
|
|
5
6
|
export type { SdfTextMaterialOptions } from './SdfTextMaterial.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InstancedBufferGeometry } from 'three/webgpu';
|
|
2
|
+
import type { DomLayoutSnapshot } from '../types.js';
|
|
3
|
+
/** True when a rectangle batch has the same instance count and attribute layout. */
|
|
4
|
+
export declare function rectContentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, receiveShadow: boolean): boolean;
|
|
5
|
+
/** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */
|
|
6
|
+
export declare function updateRectGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, receiveShadow: boolean): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Builds one instanced rectangle batch for a shadow-receiver state: pass
|
|
9
|
+
* `receiveShadow: true` for the lit batch, `false` for the plain one.
|
|
10
|
+
* Returns null when the snapshot has no rectangles in that bucket — callers
|
|
11
|
+
* must handle the empty case instead of creating a zero-instance mesh.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createRectGeometry(snapshot: DomLayoutSnapshot, receiveShadow: boolean): InstancedBufferGeometry | null;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { attrOf, byte, flushAttributeUpdate, instanceAttribute, put4, setBounds, setUnitQuad, writeDirty4 } from "./geometryUtils.js";
|
|
2
|
+
import { InstancedBufferAttribute, InstancedBufferGeometry } from "three/webgpu";
|
|
3
|
+
// src/text/rectGeometry.ts
|
|
4
|
+
function rectCountFor(snapshot, receiveShadow) {
|
|
5
|
+
let count = 0;
|
|
6
|
+
for (const rect of snapshot.rects) if (rect.receiveShadow === receiveShadow) count++;
|
|
7
|
+
return count;
|
|
8
|
+
}
|
|
9
|
+
var dirtyBounds = /* @__PURE__ */ new Int32Array(8);
|
|
10
|
+
function markDirty(slot, start, count) {
|
|
11
|
+
if (dirtyBounds[slot + 1] < 0) dirtyBounds[slot] = start;
|
|
12
|
+
dirtyBounds[slot + 1] = start + count;
|
|
13
|
+
}
|
|
14
|
+
function writeDirtyScalar(array, index, value, slot) {
|
|
15
|
+
if (Object.is(array[index], Math.fround(value))) return;
|
|
16
|
+
array[index] = value;
|
|
17
|
+
markDirty(slot, index, 1);
|
|
18
|
+
}
|
|
19
|
+
function writeRectBatch(snapshot, receiveShadow, rects, colors, radii, depths, trackChanges = false) {
|
|
20
|
+
let index = 0;
|
|
21
|
+
let minZ = 0;
|
|
22
|
+
let maxZ = 0;
|
|
23
|
+
for (const item of snapshot.rects) {
|
|
24
|
+
if (item.receiveShadow !== receiveShadow) continue;
|
|
25
|
+
const offset = index * 4;
|
|
26
|
+
const color = item.color;
|
|
27
|
+
const r = byte(color[0]), g = byte(color[1]), b = byte(color[2]), a = byte(color[3]);
|
|
28
|
+
if (trackChanges) {
|
|
29
|
+
const rect = item.rect;
|
|
30
|
+
if (!Object.is(rects[offset], Math.fround(rect[0])) || !Object.is(rects[offset + 1], Math.fround(rect[1])) || !Object.is(rects[offset + 2], Math.fround(rect[2])) || !Object.is(rects[offset + 3], Math.fround(rect[3]))) {
|
|
31
|
+
put4(rects, offset, rect);
|
|
32
|
+
markDirty(0, offset, 4);
|
|
33
|
+
}
|
|
34
|
+
writeDirty4(colors, offset, r, g, b, a, dirtyBounds, 2);
|
|
35
|
+
writeDirtyScalar(radii, index, item.radius, 4);
|
|
36
|
+
writeDirtyScalar(depths, index, item.z, 6);
|
|
37
|
+
} else {
|
|
38
|
+
put4(rects, offset, item.rect);
|
|
39
|
+
colors[offset] = r;
|
|
40
|
+
colors[offset + 1] = g;
|
|
41
|
+
colors[offset + 2] = b;
|
|
42
|
+
colors[offset + 3] = a;
|
|
43
|
+
radii[index] = item.radius;
|
|
44
|
+
depths[index] = item.z;
|
|
45
|
+
}
|
|
46
|
+
if (item.z < minZ) minZ = item.z;
|
|
47
|
+
if (item.z > maxZ) maxZ = item.z;
|
|
48
|
+
index++;
|
|
49
|
+
}
|
|
50
|
+
return [minZ, maxZ];
|
|
51
|
+
}
|
|
52
|
+
/** True when a rectangle batch has the same instance count and attribute layout. */
|
|
53
|
+
function rectContentFits(geometry, snapshot, receiveShadow) {
|
|
54
|
+
if (snapshot.rects.length < geometry.instanceCount) return false;
|
|
55
|
+
if (!instanceAttribute(geometry, "sdfRect", 4) || !instanceAttribute(geometry, "sdfColor", 4) || !instanceAttribute(geometry, "sdfRadius", 1) || !instanceAttribute(geometry, "sdfZ", 1)) return false;
|
|
56
|
+
return rectCountFor(snapshot, receiveShadow) === geometry.instanceCount;
|
|
57
|
+
}
|
|
58
|
+
/** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */
|
|
59
|
+
function updateRectGeometry(geometry, snapshot, receiveShadow) {
|
|
60
|
+
if (!rectContentFits(geometry, snapshot, receiveShadow)) return false;
|
|
61
|
+
const rects = attrOf(geometry, "sdfRect");
|
|
62
|
+
const colors = attrOf(geometry, "sdfColor");
|
|
63
|
+
const radii = attrOf(geometry, "sdfRadius");
|
|
64
|
+
const depths = attrOf(geometry, "sdfZ");
|
|
65
|
+
dirtyBounds.fill(-1);
|
|
66
|
+
const [minZ, maxZ] = writeRectBatch(snapshot, receiveShadow, rects.array, colors.array, radii.array, depths.array, true);
|
|
67
|
+
flushAttributeUpdate(rects, dirtyBounds[0], dirtyBounds[1]);
|
|
68
|
+
flushAttributeUpdate(colors, dirtyBounds[2], dirtyBounds[3]);
|
|
69
|
+
flushAttributeUpdate(radii, dirtyBounds[4], dirtyBounds[5]);
|
|
70
|
+
flushAttributeUpdate(depths, dirtyBounds[6], dirtyBounds[7]);
|
|
71
|
+
setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Builds one instanced rectangle batch for a shadow-receiver state: pass
|
|
76
|
+
* `receiveShadow: true` for the lit batch, `false` for the plain one.
|
|
77
|
+
* Returns null when the snapshot has no rectangles in that bucket — callers
|
|
78
|
+
* must handle the empty case instead of creating a zero-instance mesh.
|
|
79
|
+
*/
|
|
80
|
+
function createRectGeometry(snapshot, receiveShadow) {
|
|
81
|
+
const count = rectCountFor(snapshot, receiveShadow);
|
|
82
|
+
if (count === 0) return null;
|
|
83
|
+
const rects = new Float32Array(count * 4);
|
|
84
|
+
const colors = new Uint8Array(count * 4);
|
|
85
|
+
const radii = new Float32Array(count);
|
|
86
|
+
const depths = new Float32Array(count);
|
|
87
|
+
const [minZ, maxZ] = writeRectBatch(snapshot, receiveShadow, rects, colors, radii, depths);
|
|
88
|
+
const geometry = new InstancedBufferGeometry();
|
|
89
|
+
geometry.name = receiveShadow ? "ultra-text instanced shadow-receiving DOM rects" : "ultra-text instanced DOM rects";
|
|
90
|
+
setUnitQuad(geometry);
|
|
91
|
+
geometry.setAttribute("sdfRect", new InstancedBufferAttribute(rects, 4, false));
|
|
92
|
+
geometry.setAttribute("sdfColor", new InstancedBufferAttribute(colors, 4, true));
|
|
93
|
+
geometry.setAttribute("sdfRadius", new InstancedBufferAttribute(radii, 1, false));
|
|
94
|
+
geometry.setAttribute("sdfZ", new InstancedBufferAttribute(depths, 1, false));
|
|
95
|
+
geometry.instanceCount = count;
|
|
96
|
+
setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ);
|
|
97
|
+
return geometry;
|
|
98
|
+
}
|
|
99
|
+
export { createRectGeometry, rectContentFits, updateRectGeometry };
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=rectGeometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rectGeometry.js","names":[],"sources":["../../src/text/rectGeometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\n\nimport type { DomLayoutSnapshot } from '../types.js'\nimport {\n attrOf,\n byte,\n flushAttributeUpdate,\n instanceAttribute,\n put4,\n setBounds,\n setUnitQuad,\n writeDirty4,\n} from './geometryUtils.js'\n\nfunction rectCountFor(snapshot: DomLayoutSnapshot, receiveShadow: boolean): number {\n let count = 0\n for (const rect of snapshot.rects) if (rect.receiveShadow === receiveShadow) count++\n return count\n}\n\n// One range per attribute. Multiple edits before a draw accumulate in the attribute itself.\nconst dirtyBounds = new Int32Array(8)\n\nfunction markDirty(slot: number, start: number, count: number): void {\n if (dirtyBounds[slot + 1]! < 0) dirtyBounds[slot] = start\n dirtyBounds[slot + 1] = start + count\n}\n\nfunction writeDirtyScalar(array: Float32Array, index: number, value: number, slot: number): void {\n if (Object.is(array[index], Math.fround(value))) return\n array[index] = value\n markDirty(slot, index, 1)\n}\n\nfunction writeRectBatch(\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n rects: Float32Array,\n colors: Uint8Array,\n radii: Float32Array,\n depths: Float32Array,\n trackChanges = false,\n): [number, number] {\n let index = 0\n let minZ = 0\n let maxZ = 0\n for (const item of snapshot.rects) {\n if (item.receiveShadow !== receiveShadow) continue\n const offset = index * 4\n const color = item.color\n const r = byte(color[0]),\n g = byte(color[1]),\n b = byte(color[2]),\n a = byte(color[3])\n if (trackChanges) {\n const rect = item.rect\n if (\n !Object.is(rects[offset], Math.fround(rect[0])) ||\n !Object.is(rects[offset + 1], Math.fround(rect[1])) ||\n !Object.is(rects[offset + 2], Math.fround(rect[2])) ||\n !Object.is(rects[offset + 3], Math.fround(rect[3]))\n ) {\n put4(rects, offset, rect)\n markDirty(0, offset, 4)\n }\n writeDirty4(colors, offset, r, g, b, a, dirtyBounds, 2)\n writeDirtyScalar(radii, index, item.radius, 4)\n writeDirtyScalar(depths, index, item.z, 6)\n } else {\n put4(rects, offset, item.rect)\n colors[offset] = r\n colors[offset + 1] = g\n colors[offset + 2] = b\n colors[offset + 3] = a\n radii[index] = item.radius\n depths[index] = item.z\n }\n if (item.z < minZ) minZ = item.z\n if (item.z > maxZ) maxZ = item.z\n index++\n }\n return [minZ, maxZ]\n}\n\n/** True when a rectangle batch has the same instance count and attribute layout. */\nexport function rectContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n): boolean {\n if (snapshot.rects.length < geometry.instanceCount) return false\n if (\n !instanceAttribute(geometry, 'sdfRect', 4) ||\n !instanceAttribute(geometry, 'sdfColor', 4) ||\n !instanceAttribute(geometry, 'sdfRadius', 1) ||\n !instanceAttribute(geometry, 'sdfZ', 1)\n ) {\n return false\n }\n return rectCountFor(snapshot, receiveShadow) === geometry.instanceCount\n}\n\n/** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */\nexport function updateRectGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n): boolean {\n if (!rectContentFits(geometry, snapshot, receiveShadow)) return false\n const rects = attrOf<Float32Array>(geometry, 'sdfRect')!\n const colors = attrOf<Uint8Array>(geometry, 'sdfColor')!\n const radii = attrOf<Float32Array>(geometry, 'sdfRadius')!\n const depths = attrOf<Float32Array>(geometry, 'sdfZ')!\n dirtyBounds.fill(-1)\n const [minZ, maxZ] = writeRectBatch(\n snapshot,\n receiveShadow,\n rects.array,\n colors.array,\n radii.array,\n depths.array,\n true,\n )\n flushAttributeUpdate(rects, dirtyBounds[0]!, dirtyBounds[1]!)\n flushAttributeUpdate(colors, dirtyBounds[2]!, dirtyBounds[3]!)\n flushAttributeUpdate(radii, dirtyBounds[4]!, dirtyBounds[5]!)\n flushAttributeUpdate(depths, dirtyBounds[6]!, dirtyBounds[7]!)\n setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ)\n return true\n}\n\n/**\n * Builds one instanced rectangle batch for a shadow-receiver state: pass\n * `receiveShadow: true` for the lit batch, `false` for the plain one.\n * Returns null when the snapshot has no rectangles in that bucket — callers\n * must handle the empty case instead of creating a zero-instance mesh.\n */\nexport function createRectGeometry(\n snapshot: DomLayoutSnapshot,\n receiveShadow: boolean,\n): InstancedBufferGeometry | null {\n const count = rectCountFor(snapshot, receiveShadow)\n if (count === 0) return null\n const rects = new Float32Array(count * 4)\n const colors = new Uint8Array(count * 4)\n const radii = new Float32Array(count)\n const depths = new Float32Array(count)\n const [minZ, maxZ] = writeRectBatch(snapshot, receiveShadow, rects, colors, radii, depths)\n\n const geometry = new InstancedBufferGeometry()\n geometry.name = receiveShadow\n ? 'ultra-text instanced shadow-receiving DOM rects'\n : 'ultra-text instanced DOM rects'\n setUnitQuad(geometry)\n geometry.setAttribute('sdfRect', new InstancedBufferAttribute(rects, 4, false))\n geometry.setAttribute('sdfColor', new InstancedBufferAttribute(colors, 4, true))\n geometry.setAttribute('sdfRadius', new InstancedBufferAttribute(radii, 1, false))\n geometry.setAttribute('sdfZ', new InstancedBufferAttribute(depths, 1, false))\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ)\n return geometry\n}\n"],"mappings":";;;AAcA,SAAS,aAAa,UAA6B,eAAgC;CACjF,IAAI,QAAQ;CACZ,KAAK,MAAM,QAAQ,SAAS,OAAO,IAAI,KAAK,kBAAkB,eAAe;CAC7E,OAA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