ultra-text 1.0.0 → 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 +267 -962
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +69 -26
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +5 -15
- 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 +164 -50
- 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.d.ts +7 -6
- package/dist/atlas/gpuAtlas.js +206 -247
- 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 +59 -125
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +2 -0
- package/dist/atlas/rasterize.js +104 -144
- 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 +263 -272
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.d.ts +26 -0
- package/dist/dom/DomSlug.js +564 -0
- package/dist/dom/DomSlug.js.map +1 -0
- package/dist/dom/SlugText.d.ts +18 -0
- package/dist/dom/SlugText.js +94 -0
- package/dist/dom/SlugText.js.map +1 -0
- package/dist/dom/Text.js +4 -67
- package/dist/dom/Text.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.d.ts +2 -0
- package/dist/dom/fontCanvas.js +119 -0
- package/dist/dom/fontCanvas.js.map +1 -0
- package/dist/dom/layoutSignature.js +156 -27
- 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 +563 -243
- 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/textHost.d.ts +11 -0
- package/dist/dom/textHost.js +68 -0
- package/dist/dom/textHost.js.map +1 -0
- 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 +13 -4
- package/dist/slug/SlugMaterial.js +82 -12
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +17 -13
- package/dist/slug/coverage.js +195 -222
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -3
- package/dist/slug/preprocessCore.js +149 -95
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +94 -46
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +40 -0
- package/dist/slug/standaloneRuntime.js +175 -0
- package/dist/slug/standaloneRuntime.js.map +1 -0
- package/dist/slug/truetype.d.ts +22 -0
- package/dist/slug/truetype.js +467 -0
- package/dist/slug/truetype.js.map +1 -0
- 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 -0
- package/dist/slug-vanilla.js +13 -0
- package/dist/slug.d.ts +21 -0
- package/dist/slug.js +19 -0
- package/dist/text/GlyphTextMaterial.d.ts +11 -11
- package/dist/text/GlyphTextMaterial.js +102 -33
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +5 -4
- package/dist/text/SdfTextMaterial.js +29 -9
- 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/types.d.ts +63 -14
- package/dist/vanilla.d.ts +13 -360
- package/dist/vanilla.js +8 -1402
- package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
- package/dist/windfoil/WindfoilMaterial.js +8 -1
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/abortable.d.ts +2 -0
- package/dist/windfoil/abortable.js +26 -0
- package/dist/windfoil/abortable.js.map +1 -0
- package/dist/windfoil/color.js +2 -1
- package/dist/windfoil/color.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +3 -20
- package/dist/windfoil/coverage.js +7 -20
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/emoji.js +1 -1
- package/dist/windfoil/emoji.js.map +1 -1
- package/dist/windfoil/emojiMetrics.js +1 -1
- package/dist/windfoil/emojiMetrics.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +204 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +14 -10
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/layerNormalization.d.ts +1 -1
- package/dist/windfoil/layerNormalization.js +1 -1
- package/dist/windfoil/layerNormalization.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/outlineValidation.d.ts +86 -0
- package/dist/windfoil/outlineValidation.js +65 -0
- package/dist/windfoil/outlineValidation.js.map +1 -0
- package/dist/windfoil/preprocess.js +3 -2
- package/dist/windfoil/preprocess.js.map +1 -1
- package/dist/windfoil/preprocessCore.d.ts +5 -85
- package/dist/windfoil/preprocessCore.js +218 -209
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.js +1 -1
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +5 -2
- package/dist/windfoil/runtime.js +63 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeResources.js +2 -1
- package/dist/windfoil/shapeResources.js.map +1 -1
- package/dist/windfoil/shapes.js +1 -1
- package/dist/windfoil/skirt.d.ts +22 -0
- package/dist/windfoil/skirt.js +20 -0
- package/dist/windfoil/skirt.js.map +1 -0
- package/dist/windfoil/storage.d.ts +62 -4
- package/dist/windfoil/storage.js +143 -28
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +3 -3
- package/dist/windfoil/trace/contours.js +228 -137
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -7
- package/dist/windfoil/trace/fit.js +668 -376
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +60 -35
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +15 -3
- package/dist/windfoil/tracedOutlines.d.ts +37 -1
- package/dist/windfoil/tracedOutlines.js +228 -64
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +60 -11
- package/skills/ultra-text/SKILL.md +114 -0
- package/skills/ultra-text/references/frameworks.md +43 -0
- package/skills/ultra-text/references/three-tsl.md +78 -0
- package/skills/ultra-text/references/vanilla-webgpu.md +96 -0
- package/dist/assets/cpuSdf.worker-Du9o8q4p.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
package/dist/text/geometry.d.ts
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function needsRunMotion(snapshot: DomLayoutSnapshot): boolean;
|
|
5
|
-
export declare function createGlyphGeometry(snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array): {
|
|
6
|
-
geometry: InstancedBufferGeometry;
|
|
7
|
-
maxSequence: number;
|
|
8
|
-
};
|
|
9
|
-
export declare function updateGlyphGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array): number | null;
|
|
10
|
-
export declare function glyphContentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionOrdinals?: Float32Array): boolean;
|
|
11
|
-
export declare function updateGlyphContent(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array, checked?: boolean): number | null;
|
|
12
|
-
/** True when a rectangle batch has the same instance count and attribute layout. */
|
|
13
|
-
export declare function rectContentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, receiveShadow: boolean): boolean;
|
|
14
|
-
/** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */
|
|
15
|
-
export declare function updateRectGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, receiveShadow: boolean): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Builds one instanced rectangle batch for a shadow-receiver state: pass
|
|
18
|
-
* `receiveShadow: true` for the lit batch, `false` for the plain one.
|
|
19
|
-
* Returns null when the snapshot has no rectangles in that bucket — callers
|
|
20
|
-
* must handle the empty case instead of creating a zero-instance mesh.
|
|
21
|
-
*/
|
|
22
|
-
export declare function createRectGeometry(snapshot: DomLayoutSnapshot, receiveShadow: boolean): InstancedBufferGeometry | null;
|
|
1
|
+
export { needsRunMotion } from './geometryUtils.js';
|
|
2
|
+
export { createGlyphGeometry, glyphContentFits, updateGlyphContent, updateGlyphGeometry, } from './glyphGeometry.js';
|
|
3
|
+
export { createRectGeometry, rectContentFits, updateRectGeometry } from './rectGeometry.js';
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import { type InstancedBufferGeometry } from 'three/webgpu';
|
|
1
|
+
import { type InstancedBufferAttribute, type InstancedBufferGeometry } from 'three/webgpu';
|
|
2
2
|
import type { DomLayoutSnapshot, GlyphLayout } from '../types.js';
|
|
3
|
+
/** Four element stores: V8 inlines this, where `TypedArray.set` from a tuple is ~2x slower per item. */
|
|
4
|
+
export declare function put4(target: Float32Array, offset: number, source: readonly number[]): void;
|
|
5
|
+
export declare const attrOf: <T extends Float32Array | Uint16Array | Uint8Array>(geometry: InstancedBufferGeometry, name: string) => (InstancedBufferAttribute & {
|
|
6
|
+
array: T;
|
|
7
|
+
}) | undefined;
|
|
8
|
+
export declare function instanceAttribute(geometry: InstancedBufferGeometry, name: string, itemSize: number): boolean;
|
|
9
|
+
/** Whether a snapshot needs shared animation centres and drawable ordinals. */
|
|
10
|
+
export declare function needsRunMotion(snapshot: DomLayoutSnapshot): boolean;
|
|
11
|
+
/** Whether any glyph in a snapshot carries inline text decorations. */
|
|
12
|
+
export declare function hasDecorations(snapshot: DomLayoutSnapshot): boolean;
|
|
3
13
|
export declare function setUnitQuad(geometry: InstancedBufferGeometry): void;
|
|
4
14
|
export declare function byte(value: number): number;
|
|
5
15
|
/**
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { Box3, Float32BufferAttribute, Sphere, Uint16BufferAttribute } from "three/webgpu";
|
|
2
2
|
// src/text/geometryUtils.ts
|
|
3
|
+
/** Four element stores: V8 inlines this, where `TypedArray.set` from a tuple is ~2x slower per item. */
|
|
4
|
+
function put4(target, offset, source) {
|
|
5
|
+
target[offset] = source[0];
|
|
6
|
+
target[offset + 1] = source[1];
|
|
7
|
+
target[offset + 2] = source[2];
|
|
8
|
+
target[offset + 3] = source[3];
|
|
9
|
+
}
|
|
10
|
+
var attrOf = (geometry, name) => geometry.getAttribute(name);
|
|
11
|
+
function instanceAttribute(geometry, name, itemSize) {
|
|
12
|
+
const attribute = attrOf(geometry, name);
|
|
13
|
+
return attribute?.itemSize === itemSize && attribute.count === geometry.instanceCount;
|
|
14
|
+
}
|
|
15
|
+
/** Whether a snapshot needs shared animation centres and drawable ordinals. */
|
|
16
|
+
function needsRunMotion(snapshot) {
|
|
17
|
+
return snapshot.textShaping === "browser" || snapshot.glyphs.some((glyph) => glyph.motionOrigin !== void 0);
|
|
18
|
+
}
|
|
19
|
+
/** Whether any glyph in a snapshot carries inline text decorations. */
|
|
20
|
+
function hasDecorations(snapshot) {
|
|
21
|
+
for (const glyph of snapshot.glyphs) if (glyph.decorations && glyph.decorations.length > 0) return true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
3
24
|
var UNIT_QUAD_POSITIONS = new Float32Array([
|
|
4
25
|
0,
|
|
5
26
|
0,
|
|
@@ -64,6 +85,6 @@ function setBounds(geometry, width, height, padding, minZ, maxZ) {
|
|
|
64
85
|
box.max.set(width + padding, height + padding, maxZ + padding);
|
|
65
86
|
box.getBoundingSphere(geometry.boundingSphere ??= new Sphere());
|
|
66
87
|
}
|
|
67
|
-
export { byte, metaSize, setBounds, setUnitQuad, writeMeta };
|
|
88
|
+
export { attrOf, byte, hasDecorations, instanceAttribute, metaSize, needsRunMotion, put4, setBounds, setUnitQuad, writeMeta };
|
|
68
89
|
|
|
69
90
|
//# sourceMappingURL=geometryUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometryUtils.js","names":[],"sources":["../../src/text/geometryUtils.ts"],"sourcesContent":["import {\n Box3,\n Float32BufferAttribute,\n type InstancedBufferGeometry,\n Sphere,\n Uint16BufferAttribute,\n} from 'three/webgpu'\n\nimport type { DomLayoutSnapshot, GlyphLayout } from '../types.js'\n\nconst UNIT_QUAD_POSITIONS = new Float32Array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0])\nconst UNIT_QUAD_NORMALS = new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1])\nconst UNIT_QUAD_INDICES = new Uint16Array([0, 1, 2, 0, 2, 3])\n\n// No `uv`: every graph here derives its own texture coordinates from the\n// instanced rect attributes, so the unit quad only needs position and the\n// normal that the lit shadow receiver samples with.\nexport function setUnitQuad(geometry: InstancedBufferGeometry): void {\n geometry.setAttribute('position', new Float32BufferAttribute(UNIT_QUAD_POSITIONS, 3))\n geometry.setAttribute('normal', new Float32BufferAttribute(UNIT_QUAD_NORMALS, 3))\n geometry.setIndex(new Uint16BufferAttribute(UNIT_QUAD_INDICES, 1))\n}\n\nexport function byte(value: number): number {\n return value <= 0 ? 0 : value >= 1 ? 255 : (value * 255 + 0.5) | 0\n}\n\n/**\n * `sdfMeta` gains a third component, the switch em, only on size-switch layouts. A switched\n * layout keeps it even when empty: retained materials read three components, and a pipeline\n * built over a two-wide empty batch would outlive the batch it is later updated with.\n */\nexport function metaSize(snapshot: DomLayoutSnapshot): 2 | 3 {\n return snapshot.sizeSwitched || snapshot.glyphs.some((glyph) => glyph.switchEm !== undefined)\n ? 3\n : 2\n}\n\nexport function writeMeta(\n target: Float32Array,\n index: number,\n size: number,\n glyph: GlyphLayout,\n): void {\n const o = index * size\n target[o] = glyph.sequence\n target[o + 1] = glyph.z\n if (size === 3) target[o + 2] = glyph.switchEm ?? 0\n}\n\nexport function setBounds(\n geometry: InstancedBufferGeometry,\n width: number,\n height: number,\n padding: number,\n minZ: number,\n maxZ: number,\n): void {\n const box = (geometry.boundingBox ??= new Box3())\n box.min.set(-padding, -padding, minZ - padding)\n box.max.set(width + padding, height + padding, maxZ + padding)\n box.getBoundingSphere((geometry.boundingSphere ??= new Sphere()))\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"geometryUtils.js","names":[],"sources":["../../src/text/geometryUtils.ts"],"sourcesContent":["import {\n Box3,\n Float32BufferAttribute,\n type InstancedBufferAttribute,\n type InstancedBufferGeometry,\n Sphere,\n Uint16BufferAttribute,\n} from 'three/webgpu'\n\nimport type { DomLayoutSnapshot, GlyphLayout } from '../types.js'\n\n/** Four element stores: V8 inlines this, where `TypedArray.set` from a tuple is ~2x slower per item. */\nexport function put4(target: Float32Array, offset: number, source: readonly number[]): void {\n target[offset] = source[0]!\n target[offset + 1] = source[1]!\n target[offset + 2] = source[2]!\n target[offset + 3] = source[3]!\n}\n\nexport const attrOf = <T extends Float32Array | Uint16Array | Uint8Array>(\n geometry: InstancedBufferGeometry,\n name: string,\n): (InstancedBufferAttribute & { array: T }) | undefined =>\n geometry.getAttribute(name) as (InstancedBufferAttribute & { array: T }) | undefined\n\nexport function instanceAttribute(\n geometry: InstancedBufferGeometry,\n name: string,\n itemSize: number,\n): boolean {\n const attribute = attrOf(geometry, name)\n return attribute?.itemSize === itemSize && attribute.count === geometry.instanceCount\n}\n\n/** Whether a snapshot needs shared animation centres and drawable ordinals. */\nexport function needsRunMotion(snapshot: DomLayoutSnapshot): boolean {\n return (\n snapshot.textShaping === 'browser' ||\n snapshot.glyphs.some((glyph) => glyph.motionOrigin !== undefined)\n )\n}\n\n/** Whether any glyph in a snapshot carries inline text decorations. */\nexport function hasDecorations(snapshot: DomLayoutSnapshot): boolean {\n for (const glyph of snapshot.glyphs) {\n if (glyph.decorations && glyph.decorations.length > 0) return true\n }\n return false\n}\n\nconst UNIT_QUAD_POSITIONS = new Float32Array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0])\nconst UNIT_QUAD_NORMALS = new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1])\nconst UNIT_QUAD_INDICES = new Uint16Array([0, 1, 2, 0, 2, 3])\n\n// No `uv`: every graph here derives its own texture coordinates from the\n// instanced rect attributes, so the unit quad only needs position and the\n// normal that the lit shadow receiver samples with.\nexport function setUnitQuad(geometry: InstancedBufferGeometry): void {\n geometry.setAttribute('position', new Float32BufferAttribute(UNIT_QUAD_POSITIONS, 3))\n geometry.setAttribute('normal', new Float32BufferAttribute(UNIT_QUAD_NORMALS, 3))\n geometry.setIndex(new Uint16BufferAttribute(UNIT_QUAD_INDICES, 1))\n}\n\nexport function byte(value: number): number {\n return value <= 0 ? 0 : value >= 1 ? 255 : (value * 255 + 0.5) | 0\n}\n\n/**\n * `sdfMeta` gains a third component, the switch em, only on size-switch layouts. A switched\n * layout keeps it even when empty: retained materials read three components, and a pipeline\n * built over a two-wide empty batch would outlive the batch it is later updated with.\n */\nexport function metaSize(snapshot: DomLayoutSnapshot): 2 | 3 {\n return snapshot.sizeSwitched || snapshot.glyphs.some((glyph) => glyph.switchEm !== undefined)\n ? 3\n : 2\n}\n\nexport function writeMeta(\n target: Float32Array,\n index: number,\n size: number,\n glyph: GlyphLayout,\n): void {\n const o = index * size\n target[o] = glyph.sequence\n target[o + 1] = glyph.z\n if (size === 3) target[o + 2] = glyph.switchEm ?? 0\n}\n\nexport function setBounds(\n geometry: InstancedBufferGeometry,\n width: number,\n height: number,\n padding: number,\n minZ: number,\n maxZ: number,\n): void {\n const box = (geometry.boundingBox ??= new Box3())\n box.min.set(-padding, -padding, minZ - padding)\n box.max.set(width + padding, height + padding, maxZ + padding)\n box.getBoundingSphere((geometry.boundingSphere ??= new Sphere()))\n}\n"],"mappings":";;;AAYA,SAAgB,KAAK,QAAsB,QAAgB,QAAiC;CAC1F,OAAO,UAAU,OAAO;CACxB,OAAO,SAAS,KAAK,OAAO;CAC5B,OAAO,SAAS,KAAK,OAAO;CAC5B,OAAO,SAAS,KAAK,OAAO;AAC9B;AAEA,IAAa,UACX,UACA,SAEA,SAAS,aAAa,IAAI;AAE5B,SAAgB,kBACd,UACA,MACA,UACS;CACT,MAAM,YAAY,OAAO,UAAU,IAAI;CACvC,OAAO,WAAW,aAAa,YAAY,UAAU,UAAU,SAAS;AAC1E;;AAGA,SAAgB,eAAe,UAAsC;CACnE,OACE,SAAS,gBAAgB,aACzB,SAAS,OAAO,MAAM,UAAU,MAAM,iBAAiB,KAAA,CAAS;AAEpE;;AAGA,SAAgB,eAAe,UAAsC;CACnE,KAAK,MAAM,SAAS,SAAS,QAC3B,IAAI,MAAM,eAAe,MAAM,YAAY,SAAS,GA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 -0,0 +1,9 @@
|
|
|
1
|
+
import { InstancedBufferGeometry } from 'three/webgpu';
|
|
2
|
+
import type { DomLayoutSnapshot, SdfAtlas } from '../types.js';
|
|
3
|
+
export declare function createGlyphGeometry(snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array): {
|
|
4
|
+
geometry: InstancedBufferGeometry;
|
|
5
|
+
maxSequence: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function updateGlyphGeometry(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array): number | null;
|
|
8
|
+
export declare function glyphContentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionOrdinals?: Float32Array): boolean;
|
|
9
|
+
export declare function updateGlyphContent(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot, atlas: SdfAtlas, motionPadding: number, motionOrdinals?: Float32Array, checked?: boolean): number | null;
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { attrOf, byte, instanceAttribute, metaSize, needsRunMotion, setBounds, setUnitQuad } from "./geometryUtils.js";
|
|
2
|
+
import { InstancedBufferAttribute, InstancedBufferGeometry } from "three/webgpu";
|
|
3
|
+
// src/text/glyphGeometry.ts
|
|
4
|
+
function shapeOrdinals(snapshot) {
|
|
5
|
+
const glyphs = snapshot.glyphs;
|
|
6
|
+
if (!glyphs.some((glyph) => glyph.shapeGroup !== void 0)) return void 0;
|
|
7
|
+
const out = new Float32Array(glyphs.length);
|
|
8
|
+
let ordinal = -1, previous;
|
|
9
|
+
for (let index = 0; index < glyphs.length; index++) {
|
|
10
|
+
const glyph = glyphs[index];
|
|
11
|
+
if (glyph.shapeGroup === void 0 || glyph.shapeGroup !== previous) ordinal++;
|
|
12
|
+
previous = glyph.shapeGroup;
|
|
13
|
+
out[index] = glyph.motionOrigin?.[2] ?? ordinal;
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
var clamp16 = (v) => Math.min(65535, Math.max(0, v));
|
|
18
|
+
function writeDirty4(arr, o, a, b, c, d, dirty, slot) {
|
|
19
|
+
if (arr[o] !== a || arr[o + 1] !== b || arr[o + 2] !== c || arr[o + 3] !== d) {
|
|
20
|
+
arr[o] = a;
|
|
21
|
+
arr[o + 1] = b;
|
|
22
|
+
arr[o + 2] = c;
|
|
23
|
+
arr[o + 3] = d;
|
|
24
|
+
if (dirty[slot + 1] < 0) dirty[slot] = o;
|
|
25
|
+
dirty[slot + 1] = o + 4;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function writeGlyphBatch(snapshot, atlas, rects, clips, metadata, metaItemSize, runMotion, motionOrdinals, uvRects, trims, colors, maxCount = Infinity, dirty) {
|
|
29
|
+
const glyphs = snapshot.glyphs;
|
|
30
|
+
const total = glyphs.length;
|
|
31
|
+
const shaped = snapshot.textShaping === "browser";
|
|
32
|
+
const invBakeSize = 1 / atlas.bakeSize;
|
|
33
|
+
const atlasGlyphs = atlas.glyphs;
|
|
34
|
+
const packUvs = uvRects !== void 0 && colors !== void 0;
|
|
35
|
+
const hasTrims = trims !== void 0 && trims !== null;
|
|
36
|
+
let count = 0;
|
|
37
|
+
let maxSequence = 0;
|
|
38
|
+
let minZ = 0;
|
|
39
|
+
let maxZ = 0;
|
|
40
|
+
let prevKey;
|
|
41
|
+
let prevSlot;
|
|
42
|
+
let prevUvSlot;
|
|
43
|
+
let pu0 = 0;
|
|
44
|
+
let pv1 = 0;
|
|
45
|
+
let pu1 = 0;
|
|
46
|
+
let pv0 = 0;
|
|
47
|
+
let pt0 = 0;
|
|
48
|
+
let pt1 = 0;
|
|
49
|
+
let pt2 = 0;
|
|
50
|
+
let pt3 = 0;
|
|
51
|
+
let prevColor;
|
|
52
|
+
let c0 = 0;
|
|
53
|
+
let c1 = 0;
|
|
54
|
+
let c2 = 0;
|
|
55
|
+
let c3 = 0;
|
|
56
|
+
let prevClip;
|
|
57
|
+
let fc0 = 0;
|
|
58
|
+
let fc1 = 0;
|
|
59
|
+
let fc2 = 0;
|
|
60
|
+
let fc3 = 0;
|
|
61
|
+
if (dirty) for (let i = 0; i < 14; i += 2) {
|
|
62
|
+
dirty[i] = 0;
|
|
63
|
+
dirty[i + 1] = -1;
|
|
64
|
+
}
|
|
65
|
+
for (let ordinal = 0; ordinal < total; ordinal++) {
|
|
66
|
+
const glyph = glyphs[ordinal];
|
|
67
|
+
const gKey = glyph.glyphKey;
|
|
68
|
+
const slot = gKey === prevKey ? prevSlot : (prevKey = gKey, prevSlot = atlasGlyphs.get(gKey));
|
|
69
|
+
if (!slot) continue;
|
|
70
|
+
if (count >= maxCount) return [
|
|
71
|
+
-1,
|
|
72
|
+
0,
|
|
73
|
+
0,
|
|
74
|
+
0
|
|
75
|
+
];
|
|
76
|
+
const index = count++;
|
|
77
|
+
const offset = index * 4;
|
|
78
|
+
const scale = glyph.fontSize * invBakeSize;
|
|
79
|
+
const scaleX = shaped && slot.advance > 0 ? glyph.advance / slot.advance : scale;
|
|
80
|
+
const baseline = glyph.lineBottom + (glyph.baselineOffset ?? slot.descent * scale);
|
|
81
|
+
const rawR0 = glyph.originX + slot.planeX0 * scaleX;
|
|
82
|
+
const rawR1 = baseline + slot.planeY0 * scale;
|
|
83
|
+
const rawR2 = glyph.originX + slot.planeX1 * scaleX;
|
|
84
|
+
const rawR3 = baseline + slot.planeY1 * scale;
|
|
85
|
+
if (dirty) writeDirty4(rects, offset, Math.fround(rawR0), Math.fround(rawR1), Math.fround(rawR2), Math.fround(rawR3), dirty, 0);
|
|
86
|
+
else {
|
|
87
|
+
rects[offset] = rawR0;
|
|
88
|
+
rects[offset + 1] = rawR1;
|
|
89
|
+
rects[offset + 2] = rawR2;
|
|
90
|
+
rects[offset + 3] = rawR3;
|
|
91
|
+
}
|
|
92
|
+
const clip = glyph.clip;
|
|
93
|
+
if (clip !== prevClip) {
|
|
94
|
+
prevClip = clip;
|
|
95
|
+
fc0 = dirty ? Math.fround(clip[0]) : clip[0];
|
|
96
|
+
fc1 = dirty ? Math.fround(clip[1]) : clip[1];
|
|
97
|
+
fc2 = dirty ? Math.fround(clip[2]) : clip[2];
|
|
98
|
+
fc3 = dirty ? Math.fround(clip[3]) : clip[3];
|
|
99
|
+
}
|
|
100
|
+
if (dirty) writeDirty4(clips, offset, fc0, fc1, fc2, fc3, dirty, 2);
|
|
101
|
+
else {
|
|
102
|
+
clips[offset] = fc0;
|
|
103
|
+
clips[offset + 1] = fc1;
|
|
104
|
+
clips[offset + 2] = fc2;
|
|
105
|
+
clips[offset + 3] = fc3;
|
|
106
|
+
}
|
|
107
|
+
const mOff = index * metaItemSize;
|
|
108
|
+
if (packUvs) {
|
|
109
|
+
if (slot !== prevUvSlot) {
|
|
110
|
+
prevUvSlot = slot;
|
|
111
|
+
pu0 = slot.u0 * 65535 + .5 | 0;
|
|
112
|
+
pv1 = slot.v1 * 65535 + .5 | 0;
|
|
113
|
+
pu1 = slot.u1 * 65535 + .5 | 0;
|
|
114
|
+
pv0 = slot.v0 * 65535 + .5 | 0;
|
|
115
|
+
const s = hasTrims ? slot.support : void 0;
|
|
116
|
+
pt0 = s ? clamp16(Math.floor(s.u0 * 65535)) : pu0;
|
|
117
|
+
pt1 = s ? clamp16(Math.ceil(s.v1 * 65535)) : pv1;
|
|
118
|
+
pt2 = s ? clamp16(Math.ceil(s.u1 * 65535)) : pu1;
|
|
119
|
+
pt3 = s ? clamp16(Math.floor(s.v0 * 65535)) : pv0;
|
|
120
|
+
}
|
|
121
|
+
const color = glyph.color;
|
|
122
|
+
if (color !== prevColor) {
|
|
123
|
+
prevColor = color;
|
|
124
|
+
c0 = byte(color[0]);
|
|
125
|
+
c1 = byte(color[1]);
|
|
126
|
+
c2 = byte(color[2]);
|
|
127
|
+
c3 = byte(color[3]);
|
|
128
|
+
}
|
|
129
|
+
if (dirty) {
|
|
130
|
+
writeDirty4(uvRects, offset, pu0, pv1, pu1, pv0, dirty, 6);
|
|
131
|
+
if (hasTrims) writeDirty4(trims, offset, pt0, pt1, pt2, pt3, dirty, 10);
|
|
132
|
+
writeDirty4(colors, offset, c0, c1, c2, c3, dirty, 8);
|
|
133
|
+
const m0 = Math.fround(glyph.sequence);
|
|
134
|
+
const m1 = Math.fround(glyph.z);
|
|
135
|
+
const m2 = metaItemSize === 3 ? Math.fround(glyph.switchEm ?? 0) : 0;
|
|
136
|
+
if (metadata[mOff] !== m0 || metadata[mOff + 1] !== m1 || metaItemSize === 3 && metadata[mOff + 2] !== m2) {
|
|
137
|
+
metadata[mOff] = m0;
|
|
138
|
+
metadata[mOff + 1] = m1;
|
|
139
|
+
if (metaItemSize === 3) metadata[mOff + 2] = m2;
|
|
140
|
+
if (dirty[5] < 0) dirty[4] = mOff;
|
|
141
|
+
dirty[5] = mOff + metaItemSize;
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
uvRects[offset] = pu0;
|
|
145
|
+
uvRects[offset + 1] = pv1;
|
|
146
|
+
uvRects[offset + 2] = pu1;
|
|
147
|
+
uvRects[offset + 3] = pv0;
|
|
148
|
+
if (hasTrims) {
|
|
149
|
+
trims[offset] = pt0;
|
|
150
|
+
trims[offset + 1] = pt1;
|
|
151
|
+
trims[offset + 2] = pt2;
|
|
152
|
+
trims[offset + 3] = pt3;
|
|
153
|
+
}
|
|
154
|
+
colors[offset] = c0;
|
|
155
|
+
colors[offset + 1] = c1;
|
|
156
|
+
colors[offset + 2] = c2;
|
|
157
|
+
colors[offset + 3] = c3;
|
|
158
|
+
metadata[mOff] = glyph.sequence;
|
|
159
|
+
metadata[mOff + 1] = glyph.z;
|
|
160
|
+
if (metaItemSize === 3) metadata[mOff + 2] = glyph.switchEm ?? 0;
|
|
161
|
+
}
|
|
162
|
+
} else if (dirty) {
|
|
163
|
+
const m0 = Math.fround(glyph.sequence);
|
|
164
|
+
if (metadata[mOff] !== m0) {
|
|
165
|
+
metadata[mOff] = m0;
|
|
166
|
+
if (dirty[5] < 0) dirty[4] = mOff;
|
|
167
|
+
dirty[5] = mOff + 1;
|
|
168
|
+
}
|
|
169
|
+
} else metadata[mOff] = glyph.sequence;
|
|
170
|
+
if (runMotion) {
|
|
171
|
+
const rOff = index * 3;
|
|
172
|
+
const origin = glyph.motionOrigin;
|
|
173
|
+
if (dirty) {
|
|
174
|
+
const rx = Math.fround(origin ? origin[0] : (rects[offset] + rects[offset + 2]) * .5);
|
|
175
|
+
const ry = Math.fround(origin ? origin[1] : (rects[offset + 1] + rects[offset + 3]) * .5);
|
|
176
|
+
const rz = Math.fround(origin ? origin[2] : motionOrdinals?.[ordinal] ?? ordinal);
|
|
177
|
+
if (runMotion[rOff] !== rx || runMotion[rOff + 1] !== ry || runMotion[rOff + 2] !== rz) {
|
|
178
|
+
runMotion[rOff] = rx;
|
|
179
|
+
runMotion[rOff + 1] = ry;
|
|
180
|
+
runMotion[rOff + 2] = rz;
|
|
181
|
+
if (dirty[13] < 0) dirty[12] = rOff;
|
|
182
|
+
dirty[13] = rOff + 3;
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
runMotion[rOff] = origin ? origin[0] : (rects[offset] + rects[offset + 2]) * .5;
|
|
186
|
+
runMotion[rOff + 1] = origin ? origin[1] : (rects[offset + 1] + rects[offset + 3]) * .5;
|
|
187
|
+
runMotion[rOff + 2] = origin ? origin[2] : motionOrdinals?.[ordinal] ?? ordinal;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
|
|
191
|
+
if (glyph.z < minZ) minZ = glyph.z;
|
|
192
|
+
if (glyph.z > maxZ) maxZ = glyph.z;
|
|
193
|
+
}
|
|
194
|
+
return [
|
|
195
|
+
count,
|
|
196
|
+
maxSequence,
|
|
197
|
+
minZ,
|
|
198
|
+
maxZ
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
var dirtyBounds = /* @__PURE__ */ new Int32Array(14);
|
|
202
|
+
function flushAttributeUpdate(attribute, dirtyStart, dirtyEnd) {
|
|
203
|
+
if (!attribute) return;
|
|
204
|
+
if (attribute.version === 0) {
|
|
205
|
+
attribute.needsUpdate = true;
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (dirtyEnd <= dirtyStart) return;
|
|
209
|
+
let start = dirtyStart;
|
|
210
|
+
let end = dirtyEnd;
|
|
211
|
+
for (const range of attribute.updateRanges) {
|
|
212
|
+
if (range.count < 0) {
|
|
213
|
+
start = 0;
|
|
214
|
+
end = attribute.array.length;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
if (range.start < start) start = range.start;
|
|
218
|
+
const rangeEnd = range.start + range.count;
|
|
219
|
+
if (rangeEnd > end) end = rangeEnd;
|
|
220
|
+
}
|
|
221
|
+
attribute.clearUpdateRanges();
|
|
222
|
+
attribute.addUpdateRange(start, end - start);
|
|
223
|
+
attribute.needsUpdate = true;
|
|
224
|
+
}
|
|
225
|
+
function createGlyphGeometry(snapshot, atlas, motionPadding, motionOrdinals) {
|
|
226
|
+
const hasRunMotion = needsRunMotion(snapshot);
|
|
227
|
+
motionOrdinals ??= hasRunMotion ? shapeOrdinals(snapshot) : void 0;
|
|
228
|
+
const total = snapshot.glyphs.length;
|
|
229
|
+
const rects = new Float32Array(total * 4);
|
|
230
|
+
const uvRects = new Uint16Array(total * 4);
|
|
231
|
+
const clips = new Float32Array(total * 4);
|
|
232
|
+
const colors = new Uint8Array(total * 4);
|
|
233
|
+
const meta = metaSize(snapshot);
|
|
234
|
+
const metadata = new Float32Array(total * meta);
|
|
235
|
+
const runMotion = hasRunMotion || motionOrdinals ? new Float32Array(total * 3) : null;
|
|
236
|
+
const trims = runMotion ? null : new Uint16Array(total * 4);
|
|
237
|
+
const [count, maxSequence, minZ, maxZ] = writeGlyphBatch(snapshot, atlas, rects, clips, metadata, meta, runMotion, motionOrdinals, uvRects, trims, colors);
|
|
238
|
+
const geometry = new InstancedBufferGeometry();
|
|
239
|
+
geometry.name = "ultra-text instanced glyph quads";
|
|
240
|
+
setUnitQuad(geometry);
|
|
241
|
+
for (const [name, array, size, normalized] of [
|
|
242
|
+
[
|
|
243
|
+
"sdfRect",
|
|
244
|
+
rects,
|
|
245
|
+
4,
|
|
246
|
+
false
|
|
247
|
+
],
|
|
248
|
+
[
|
|
249
|
+
"sdfUvRect",
|
|
250
|
+
uvRects,
|
|
251
|
+
4,
|
|
252
|
+
true
|
|
253
|
+
],
|
|
254
|
+
[
|
|
255
|
+
"sdfClip",
|
|
256
|
+
clips,
|
|
257
|
+
4,
|
|
258
|
+
false
|
|
259
|
+
],
|
|
260
|
+
[
|
|
261
|
+
"sdfColor",
|
|
262
|
+
colors,
|
|
263
|
+
4,
|
|
264
|
+
true
|
|
265
|
+
],
|
|
266
|
+
[
|
|
267
|
+
"sdfMeta",
|
|
268
|
+
metadata,
|
|
269
|
+
meta,
|
|
270
|
+
false
|
|
271
|
+
],
|
|
272
|
+
[
|
|
273
|
+
"sdfRunMotion",
|
|
274
|
+
runMotion,
|
|
275
|
+
3,
|
|
276
|
+
false
|
|
277
|
+
],
|
|
278
|
+
[
|
|
279
|
+
"sdfTrim",
|
|
280
|
+
trims,
|
|
281
|
+
4,
|
|
282
|
+
true
|
|
283
|
+
]
|
|
284
|
+
]) if (array) geometry.setAttribute(name, new InstancedBufferAttribute(count === total ? array : array.subarray(0, count * size), size, normalized));
|
|
285
|
+
geometry.instanceCount = count;
|
|
286
|
+
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ);
|
|
287
|
+
return {
|
|
288
|
+
geometry,
|
|
289
|
+
maxSequence
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function updateGlyphGeometry(geometry, snapshot, atlas, motionPadding, motionOrdinals) {
|
|
293
|
+
const instanceCount = geometry.instanceCount;
|
|
294
|
+
if (snapshot.glyphs.length < instanceCount) return null;
|
|
295
|
+
const rectAttribute = attrOf(geometry, "sdfRect");
|
|
296
|
+
const clipAttribute = attrOf(geometry, "sdfClip");
|
|
297
|
+
const metaAttribute = attrOf(geometry, "sdfMeta");
|
|
298
|
+
if (!rectAttribute || !clipAttribute || !metaAttribute) return null;
|
|
299
|
+
motionOrdinals ??= needsRunMotion(snapshot) ? shapeOrdinals(snapshot) : void 0;
|
|
300
|
+
const runAttribute = attrOf(geometry, "sdfRunMotion");
|
|
301
|
+
const [count, maxSequence, minZ, maxZ] = writeGlyphBatch(snapshot, atlas, rectAttribute.array, clipAttribute.array, metaAttribute.array, metaAttribute.itemSize, runAttribute ? runAttribute.array : null, motionOrdinals, void 0, void 0, void 0, instanceCount, dirtyBounds);
|
|
302
|
+
if (count !== instanceCount) return null;
|
|
303
|
+
flushAttributeUpdate(rectAttribute, dirtyBounds[0], dirtyBounds[1]);
|
|
304
|
+
flushAttributeUpdate(clipAttribute, dirtyBounds[2], dirtyBounds[3]);
|
|
305
|
+
flushAttributeUpdate(metaAttribute, dirtyBounds[4], dirtyBounds[5]);
|
|
306
|
+
flushAttributeUpdate(runAttribute, dirtyBounds[12], dirtyBounds[13]);
|
|
307
|
+
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ);
|
|
308
|
+
return maxSequence;
|
|
309
|
+
}
|
|
310
|
+
function drawableGlyphCountMatches(snapshot, atlas, expectedCount) {
|
|
311
|
+
let count = 0;
|
|
312
|
+
for (const glyph of snapshot.glyphs) if (atlas.glyphs.has(glyph.glyphKey) && ++count > expectedCount) return false;
|
|
313
|
+
return count === expectedCount;
|
|
314
|
+
}
|
|
315
|
+
function glyphContentFits(geometry, snapshot, atlas, motionOrdinals) {
|
|
316
|
+
const instanceCount = geometry.instanceCount;
|
|
317
|
+
if (snapshot.glyphs.length < instanceCount) return false;
|
|
318
|
+
for (const name of [
|
|
319
|
+
"sdfRect",
|
|
320
|
+
"sdfUvRect",
|
|
321
|
+
"sdfClip",
|
|
322
|
+
"sdfColor"
|
|
323
|
+
]) if (!instanceAttribute(geometry, name, 4)) return false;
|
|
324
|
+
if (!instanceAttribute(geometry, "sdfMeta", metaSize(snapshot))) return false;
|
|
325
|
+
const run = attrOf(geometry, "sdfRunMotion");
|
|
326
|
+
const wantsRun = needsRunMotion(snapshot) || !!motionOrdinals;
|
|
327
|
+
const trim = attrOf(geometry, "sdfTrim");
|
|
328
|
+
return (wantsRun ? run?.itemSize === 3 && run.count === instanceCount && trim === void 0 : run === void 0 && (trim === void 0 || instanceAttribute(geometry, "sdfTrim", 4))) && drawableGlyphCountMatches(snapshot, atlas, instanceCount);
|
|
329
|
+
}
|
|
330
|
+
function updateGlyphContent(geometry, snapshot, atlas, motionPadding, motionOrdinals, checked) {
|
|
331
|
+
motionOrdinals ??= needsRunMotion(snapshot) ? shapeOrdinals(snapshot) : void 0;
|
|
332
|
+
if (!checked && !glyphContentFits(geometry, snapshot, atlas, motionOrdinals)) return null;
|
|
333
|
+
const rectAttribute = attrOf(geometry, "sdfRect");
|
|
334
|
+
const uvAttribute = attrOf(geometry, "sdfUvRect");
|
|
335
|
+
const clipAttribute = attrOf(geometry, "sdfClip");
|
|
336
|
+
const colorAttribute = attrOf(geometry, "sdfColor");
|
|
337
|
+
const metaAttribute = attrOf(geometry, "sdfMeta");
|
|
338
|
+
const trimAttribute = attrOf(geometry, "sdfTrim");
|
|
339
|
+
const runAttribute = attrOf(geometry, "sdfRunMotion");
|
|
340
|
+
const [, maxSequence, minZ, maxZ] = writeGlyphBatch(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);
|
|
341
|
+
flushAttributeUpdate(rectAttribute, dirtyBounds[0], dirtyBounds[1]);
|
|
342
|
+
flushAttributeUpdate(clipAttribute, dirtyBounds[2], dirtyBounds[3]);
|
|
343
|
+
flushAttributeUpdate(metaAttribute, dirtyBounds[4], dirtyBounds[5]);
|
|
344
|
+
flushAttributeUpdate(uvAttribute, dirtyBounds[6], dirtyBounds[7]);
|
|
345
|
+
flushAttributeUpdate(colorAttribute, dirtyBounds[8], dirtyBounds[9]);
|
|
346
|
+
flushAttributeUpdate(trimAttribute, dirtyBounds[10], dirtyBounds[11]);
|
|
347
|
+
flushAttributeUpdate(runAttribute, dirtyBounds[12], dirtyBounds[13]);
|
|
348
|
+
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ);
|
|
349
|
+
return maxSequence;
|
|
350
|
+
}
|
|
351
|
+
export { createGlyphGeometry, glyphContentFits, updateGlyphContent, updateGlyphGeometry };
|
|
352
|
+
|
|
353
|
+
//# 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 {\n attrOf,\n byte,\n instanceAttribute,\n metaSize,\n needsRunMotion,\n setBounds,\n setUnitQuad,\n} from './geometryUtils.js'\n\nimport type { DomLayoutSnapshot, GlyphLayout, GlyphSlot, SdfAtlas } from '../types.js'\n\nfunction shapeOrdinals(snapshot: DomLayoutSnapshot): Float32Array | undefined {\n const glyphs = snapshot.glyphs\n if (!glyphs.some((glyph) => glyph.shapeGroup !== undefined)) return undefined\n const out = new Float32Array(glyphs.length)\n let ordinal = -1,\n previous: number | undefined\n for (let index = 0; index < glyphs.length; index++) {\n const glyph = glyphs[index]!\n if (glyph.shapeGroup === undefined || glyph.shapeGroup !== previous) ordinal++\n previous = glyph.shapeGroup\n out[index] = glyph.motionOrigin?.[2] ?? ordinal\n }\n return out\n}\n\nconst clamp16 = (v: number): number => Math.min(65535, Math.max(0, v))\n\nfunction writeDirty4(\n arr: Float32Array | Uint16Array | Uint8Array,\n o: number,\n a: number,\n b: number,\n c: number,\n d: number,\n dirty: Int32Array,\n slot: number,\n): void {\n if (arr[o] !== a || arr[o + 1] !== b || arr[o + 2] !== c || arr[o + 3] !== d) {\n arr[o] = a\n arr[o + 1] = b\n arr[o + 2] = c\n arr[o + 3] = d\n if (dirty[slot + 1]! < 0) dirty[slot] = o\n dirty[slot + 1] = o + 4\n }\n}\n\nfunction writeGlyphBatch(\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 maxCount = Infinity,\n dirty?: Int32Array,\n): [number, number, number, number] {\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 !== undefined && trims !== null\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 if (dirty) {\n for (let i = 0; i < 14; i += 2) {\n dirty[i] = 0\n dirty[i + 1] = -1\n }\n }\n\n for (let ordinal = 0; ordinal < total; ordinal++) {\n const glyph = glyphs[ordinal]!\n const gKey = glyph.glyphKey\n const slot =\n gKey === prevKey ? prevSlot : ((prevKey = gKey), (prevSlot = atlasGlyphs.get(gKey)))\n if (!slot) continue\n if (count >= maxCount) return [-1, 0, 0, 0]\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 rawR0 = glyph.originX + slot.planeX0 * scaleX\n const rawR1 = baseline + slot.planeY0 * scale\n const rawR2 = glyph.originX + slot.planeX1 * scaleX\n const rawR3 = baseline + slot.planeY1 * scale\n if (dirty) {\n writeDirty4(\n rects,\n offset,\n Math.fround(rawR0),\n Math.fround(rawR1),\n Math.fround(rawR2),\n Math.fround(rawR3),\n dirty,\n 0,\n )\n } else {\n rects[offset] = rawR0\n rects[offset + 1] = rawR1\n rects[offset + 2] = rawR2\n rects[offset + 3] = rawR3\n }\n\n const clip = glyph.clip\n if (clip !== prevClip) {\n prevClip = clip\n fc0 = dirty ? Math.fround(clip[0]) : clip[0]\n fc1 = dirty ? Math.fround(clip[1]) : clip[1]\n fc2 = dirty ? Math.fround(clip[2]) : clip[2]\n fc3 = dirty ? Math.fround(clip[3]) : clip[3]\n }\n if (dirty) {\n writeDirty4(clips, offset, fc0, fc1, fc2, fc3, dirty, 2)\n } else {\n clips[offset] = fc0\n clips[offset + 1] = fc1\n clips[offset + 2] = fc2\n clips[offset + 3] = fc3\n }\n\n const mOff = index * metaItemSize\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 if (dirty) {\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(glyph.sequence)\n const m1 = Math.fround(glyph.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 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 colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n metadata[mOff] = glyph.sequence\n metadata[mOff + 1] = glyph.z\n if (metaItemSize === 3) metadata[mOff + 2] = glyph.switchEm ?? 0\n }\n } else if (dirty) {\n const m0 = Math.fround(glyph.sequence)\n if (metadata[mOff] !== m0) {\n metadata[mOff] = m0\n if (dirty[5]! < 0) dirty[4] = mOff\n dirty[5] = mOff + 1\n }\n } else {\n metadata[mOff] = glyph.sequence\n }\n\n if (runMotion) {\n const rOff = index * 3\n const origin = glyph.motionOrigin\n if (dirty) {\n const rx = Math.fround(origin ? origin[0] : (rects[offset]! + rects[offset + 2]!) * 0.5)\n const ry = Math.fround(origin ? origin[1] : (rects[offset + 1]! + rects[offset + 3]!) * 0.5)\n const rz = Math.fround(origin ? origin[2] : (motionOrdinals?.[ordinal] ?? ordinal))\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 } else {\n runMotion[rOff] = origin ? origin[0] : (rects[offset]! + rects[offset + 2]!) * 0.5\n runMotion[rOff + 1] = origin ? origin[1] : (rects[offset + 1]! + rects[offset + 3]!) * 0.5\n runMotion[rOff + 2] = origin ? origin[2] : (motionOrdinals?.[ordinal] ?? ordinal)\n }\n }\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 }\n return [count, maxSequence, minZ, maxZ]\n}\n\nconst dirtyBounds = new Int32Array(14)\n\nfunction flushAttributeUpdate(\n attribute: InstancedBufferAttribute | undefined,\n dirtyStart: number,\n dirtyEnd: number,\n): void {\n if (!attribute) return\n if (attribute.version === 0) {\n attribute.needsUpdate = true\n return\n }\n if (dirtyEnd <= dirtyStart) return\n let start = dirtyStart\n let end = dirtyEnd\n for (const range of attribute.updateRanges) {\n if (range.count < 0) {\n start = 0\n end = attribute.array.length\n break\n }\n if (range.start < start) start = range.start\n const rangeEnd = range.start + range.count\n if (rangeEnd > end) end = rangeEnd\n }\n attribute.clearUpdateRanges()\n attribute.addUpdateRange(start, end - start)\n attribute.needsUpdate = true\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 motionOrdinals ??= hasRunMotion ? shapeOrdinals(snapshot) : undefined\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 [count, maxSequence, minZ, maxZ] = writeGlyphBatch(\n snapshot,\n atlas,\n rects,\n clips,\n metadata,\n meta,\n runMotion,\n motionOrdinals,\n uvRects,\n trims,\n colors,\n )\n\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced glyph quads'\n setUnitQuad(geometry)\n for (const [name, array, size, normalized] of [\n ['sdfRect', rects, 4, false],\n ['sdfUvRect', uvRects, 4, true],\n ['sdfClip', clips, 4, false],\n ['sdfColor', colors, 4, true],\n ['sdfMeta', metadata, meta, false],\n ['sdfRunMotion', runMotion, 3, false],\n ['sdfTrim', trims, 4, true],\n ] as const) {\n if (array)\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 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 motionOrdinals ??= needsRunMotion(snapshot) ? shapeOrdinals(snapshot) : undefined\n const runAttribute = attrOf<Float32Array>(geometry, 'sdfRunMotion')\n const [count, maxSequence, minZ, maxZ] = writeGlyphBatch(\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 undefined,\n undefined,\n instanceCount,\n dirtyBounds,\n )\n if (count !== instanceCount) return null\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(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return maxSequence\n}\n\nfunction drawableGlyphCountMatches(\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n expectedCount: number,\n): boolean {\n let count = 0\n for (const glyph of snapshot.glyphs) {\n if (atlas.glyphs.has(glyph.glyphKey) && ++count > expectedCount) return false\n }\n return count === expectedCount\n}\n\nexport function glyphContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n atlas: SdfAtlas,\n motionOrdinals?: Float32Array,\n): boolean {\n const instanceCount = geometry.instanceCount\n if (snapshot.glyphs.length < instanceCount) return false\n for (const name of ['sdfRect', 'sdfUvRect', 'sdfClip', 'sdfColor']) {\n if (!instanceAttribute(geometry, name, 4)) 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 layoutFits && drawableGlyphCountMatches(snapshot, atlas, instanceCount)\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 motionOrdinals ??= needsRunMotion(snapshot) ? shapeOrdinals(snapshot) : undefined\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 const [, maxSequence, minZ, maxZ] = writeGlyphBatch(\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 )\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(geometry, snapshot.width, snapshot.height, motionPadding, minZ, maxZ)\n return maxSequence\n}\n"],"mappings":";;;AAaA,SAAS,cAAc,UAAuD;CAC5E,MAAM,SAAS,SAAS;CACxB,IAAI,CAAC,OAAO,MAAM,UAAU,MAAM,eAAe,KAAA,CAAS,GAAG,OAAO,KA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ACf,UACA,WACF;CACA,qBAAqB,eAAe,YAAY,IAAK,YAAY,EAAG;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,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,MAAM,IAAI;CAC9E,OAAO;AACT"}
|
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,97 @@
|
|
|
1
|
+
import { attrOf, byte, instanceAttribute, put4, setBounds, setUnitQuad } 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
|
+
function writeRectBatch(snapshot, receiveShadow, rects, colors, radii, depths) {
|
|
10
|
+
let index = 0;
|
|
11
|
+
let minZ = 0;
|
|
12
|
+
let maxZ = 0;
|
|
13
|
+
for (const item of snapshot.rects) {
|
|
14
|
+
if (item.receiveShadow !== receiveShadow) continue;
|
|
15
|
+
const offset = index * 4;
|
|
16
|
+
put4(rects, offset, item.rect);
|
|
17
|
+
colors[offset] = byte(item.color[0]);
|
|
18
|
+
colors[offset + 1] = byte(item.color[1]);
|
|
19
|
+
colors[offset + 2] = byte(item.color[2]);
|
|
20
|
+
colors[offset + 3] = byte(item.color[3]);
|
|
21
|
+
radii[index] = item.radius;
|
|
22
|
+
depths[index] = item.z;
|
|
23
|
+
if (item.z < minZ) minZ = item.z;
|
|
24
|
+
if (item.z > maxZ) maxZ = item.z;
|
|
25
|
+
index++;
|
|
26
|
+
}
|
|
27
|
+
return [minZ, maxZ];
|
|
28
|
+
}
|
|
29
|
+
/** True when a rectangle batch has the same instance count and attribute layout. */
|
|
30
|
+
function rectContentFits(geometry, snapshot, receiveShadow) {
|
|
31
|
+
if (snapshot.rects.length < geometry.instanceCount) return false;
|
|
32
|
+
if (!instanceAttribute(geometry, "sdfRect", 4) || !instanceAttribute(geometry, "sdfColor", 4) || !instanceAttribute(geometry, "sdfRadius", 1) || !instanceAttribute(geometry, "sdfZ", 1)) return false;
|
|
33
|
+
return rectCountFor(snapshot, receiveShadow) === geometry.instanceCount;
|
|
34
|
+
}
|
|
35
|
+
/** Rewrites a same-count rectangle batch. Returns false without writing when it does not fit. */
|
|
36
|
+
function updateRectGeometry(geometry, snapshot, receiveShadow) {
|
|
37
|
+
if (!rectContentFits(geometry, snapshot, receiveShadow)) return false;
|
|
38
|
+
const [minZ, maxZ] = writeRectBatch(snapshot, receiveShadow, attrOf(geometry, "sdfRect").array, attrOf(geometry, "sdfColor").array, attrOf(geometry, "sdfRadius").array, attrOf(geometry, "sdfZ").array);
|
|
39
|
+
for (const name of [
|
|
40
|
+
"sdfRect",
|
|
41
|
+
"sdfColor",
|
|
42
|
+
"sdfRadius",
|
|
43
|
+
"sdfZ"
|
|
44
|
+
]) attrOf(geometry, name).needsUpdate = true;
|
|
45
|
+
setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Builds one instanced rectangle batch for a shadow-receiver state: pass
|
|
50
|
+
* `receiveShadow: true` for the lit batch, `false` for the plain one.
|
|
51
|
+
* Returns null when the snapshot has no rectangles in that bucket — callers
|
|
52
|
+
* must handle the empty case instead of creating a zero-instance mesh.
|
|
53
|
+
*/
|
|
54
|
+
function createRectGeometry(snapshot, receiveShadow) {
|
|
55
|
+
const count = rectCountFor(snapshot, receiveShadow);
|
|
56
|
+
if (count === 0) return null;
|
|
57
|
+
const rects = new Float32Array(count * 4);
|
|
58
|
+
const colors = new Uint8Array(count * 4);
|
|
59
|
+
const radii = new Float32Array(count);
|
|
60
|
+
const depths = new Float32Array(count);
|
|
61
|
+
const [minZ, maxZ] = writeRectBatch(snapshot, receiveShadow, rects, colors, radii, depths);
|
|
62
|
+
const geometry = new InstancedBufferGeometry();
|
|
63
|
+
geometry.name = receiveShadow ? "ultra-text instanced shadow-receiving DOM rects" : "ultra-text instanced DOM rects";
|
|
64
|
+
setUnitQuad(geometry);
|
|
65
|
+
for (const [name, array, size, normalized] of [
|
|
66
|
+
[
|
|
67
|
+
"sdfRect",
|
|
68
|
+
rects,
|
|
69
|
+
4,
|
|
70
|
+
false
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
"sdfColor",
|
|
74
|
+
colors,
|
|
75
|
+
4,
|
|
76
|
+
true
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
"sdfRadius",
|
|
80
|
+
radii,
|
|
81
|
+
1,
|
|
82
|
+
false
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"sdfZ",
|
|
86
|
+
depths,
|
|
87
|
+
1,
|
|
88
|
+
false
|
|
89
|
+
]
|
|
90
|
+
]) geometry.setAttribute(name, new InstancedBufferAttribute(array, size, normalized));
|
|
91
|
+
geometry.instanceCount = count;
|
|
92
|
+
setBounds(geometry, snapshot.width, snapshot.height, 0, minZ, maxZ);
|
|
93
|
+
return geometry;
|
|
94
|
+
}
|
|
95
|
+
export { createRectGeometry, rectContentFits, updateRectGeometry };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=rectGeometry.js.map
|