@ascii-fx/three 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amir Abushanab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @ascii-fx/three
2
+
3
+ Three.js adapter. `AsciiPass` post-processes a scene through the exact matcher **on Three's own GPUDevice** — zero readback — and composites straight to the canvas. Requires `THREE.WebGPURenderer` (r170–r185 verified): exactly matching a WebGL renderer would need per-frame GPU→CPU readback, so it is not supported (spec §30).
4
+
5
+ ```ts
6
+ import * as THREE from 'three/webgpu'
7
+ import { AsciiPass } from '@ascii-fx/three'
8
+
9
+ const renderer = new THREE.WebGPURenderer({ canvas })
10
+ await renderer.init()
11
+
12
+ const pass = new AsciiPass({ profile, renderer, columns: 160, color: 'full' })
13
+ await pass.init()
14
+
15
+ function frame() {
16
+ pass.render(scene, camera) // instead of renderer.render(scene, camera)
17
+ requestAnimationFrame(frame)
18
+ }
19
+ pass.set({ columns: 180 })
20
+ pass.pointer.set(x01, y01)
21
+ pass.setInteraction({ type: 'wave' })
22
+ ```
23
+
24
+ Color handling (spec §28): render targets hold linear-light values, so the pass sRGB-encodes before quantization. With pure 0/1 scene colors this is exact (the conformance test uses that); midtones can differ ±1 byte across GPUs in the encode — a source-side conversion, not matcher variance. Tone mapping is not applied to render targets; treat the RT as the match source.
25
+
26
+ `AsciiGlyphs` (experimental): instanced plane-per-cell renderer with a TSL node material sampling the profile atlas — glyph ids/colors as instanced attributes via `updateFromFrame(frame)` (CPU hop in v1; a zero-readback bridge from the GPU cell buffer is planned), transforms in the standard `instanceMatrix` for effects.
@@ -0,0 +1,38 @@
1
+ import { InstancedMesh } from 'three';
2
+ import { MeshBasicNodeMaterial } from 'three/webgpu';
3
+ import type { AsciiFrame, AsciiProfile } from '@ascii-fx/core';
4
+ export interface AsciiGlyphsOptions {
5
+ profile: AsciiProfile;
6
+ columns: number;
7
+ rows: number;
8
+ /** World-space cell height. Default 1. */
9
+ cellSize?: number;
10
+ }
11
+ /**
12
+ * Instanced 3D glyph renderer (spec §8 'instances', §30): one plane instance
13
+ * per cell, glyph/colors as instanced attributes, atlas sampled via TSL.
14
+ * Instance transforms live in the standard instanceMatrix so effects can
15
+ * animate them (GPU-side via node materials, or CPU-side via setMatrixAt).
16
+ *
17
+ * v1 data path: populate from a captured AsciiFrame (`updateFromFrame`).
18
+ * A zero-readback bridge from the GPU cell buffer is a planned optimization.
19
+ */
20
+ export declare class AsciiGlyphs {
21
+ readonly mesh: InstancedMesh;
22
+ readonly material: MeshBasicNodeMaterial;
23
+ readonly columns: number;
24
+ readonly rows: number;
25
+ private readonly aGlyph;
26
+ private readonly aFg;
27
+ private readonly aBg;
28
+ private readonly aVisible;
29
+ private readonly aUseBackground;
30
+ private readonly atlasTexture;
31
+ private readonly profileFingerprint;
32
+ private readonly glyphCount;
33
+ private readonly blankGlyph;
34
+ constructor(options: AsciiGlyphsOptions);
35
+ /** Load glyph ids and colors from a matched frame (same grid dimensions). */
36
+ updateFromFrame(frame: AsciiFrame): void;
37
+ dispose(): void;
38
+ }
@@ -0,0 +1,68 @@
1
+ import { RenderTarget } from 'three';
2
+ import type { Camera, Object3D } from 'three';
3
+ import type { WebGPURenderer } from 'three/webgpu';
4
+ import type { AsciiFrame, AsciiProfile } from '@ascii-fx/core';
5
+ import type { AsciiPointer, FitMode, InteractionOptions, StreamMatchOptions } from '@ascii-fx/gpu';
6
+ export interface AsciiPassOptions extends StreamMatchOptions {
7
+ profile: AsciiProfile;
8
+ renderer: WebGPURenderer;
9
+ /** Render-target resolution; defaults to the renderer's drawing buffer size. */
10
+ width?: number;
11
+ height?: number;
12
+ fit?: FitMode;
13
+ clearColor?: readonly [number, number, number, number];
14
+ interaction?: InteractionOptions | null;
15
+ }
16
+ /**
17
+ * Fullscreen ASCII postprocessing for THREE.WebGPURenderer (spec §30):
18
+ * scene → render target → exact structural-v1 compute on Three's own
19
+ * GPUDevice → one-draw atlas composite straight to the canvas.
20
+ *
21
+ * The render target holds linear-light values, so the source is sRGB-encoded
22
+ * before matching (§28). Usage:
23
+ *
24
+ * ```ts
25
+ * const pass = new AsciiPass({ profile, renderer, columns: 160 })
26
+ * await pass.init()
27
+ * pass.render(scene, camera) // instead of renderer.render(...)
28
+ * ```
29
+ */
30
+ export declare class AsciiPass {
31
+ readonly renderTarget: RenderTarget;
32
+ readonly pointer: AsciiPointer;
33
+ private readonly rendererRef;
34
+ private readonly profile;
35
+ private matchOpts;
36
+ private fit;
37
+ private clearColor;
38
+ private interaction;
39
+ private pointerX;
40
+ private pointerY;
41
+ private velX;
42
+ private velY;
43
+ private readonly t0;
44
+ private readonly drawSize;
45
+ private engine?;
46
+ private stream?;
47
+ private device?;
48
+ private disposed;
49
+ constructor(options: AsciiPassOptions);
50
+ /** Compile pipelines on the renderer's device. Call once after renderer.init(). */
51
+ init(): Promise<void>;
52
+ /** Update matcher/composite options (spec §2: `ascii.set({...})`). */
53
+ set(options: Partial<StreamMatchOptions & {
54
+ fit: FitMode;
55
+ clearColor: readonly [number, number, number, number];
56
+ }>): void;
57
+ setInteraction(interaction: InteractionOptions | null): void;
58
+ setSize(width: number, height: number): void;
59
+ grid(): {
60
+ columns: number;
61
+ rows: number;
62
+ } | null;
63
+ /** Render the scene through the ASCII pipeline to the canvas. */
64
+ render(scene: Object3D, camera: Camera): void;
65
+ /** Explicit readback of the matched frame (spec §33). */
66
+ captureFrame(): Promise<AsciiFrame>;
67
+ dispose(): void;
68
+ }
@@ -0,0 +1,2 @@
1
+ export { AsciiPass, type AsciiPassOptions } from './asciiPass.js';
2
+ export { AsciiGlyphs, type AsciiGlyphsOptions } from './asciiGlyphs.js';
package/dist/index.js ADDED
@@ -0,0 +1,342 @@
1
+ // src/asciiPass.ts
2
+ import { RenderTarget, Vector2 } from "three";
3
+ import { AsciiEngine } from "@ascii-fx/gpu";
4
+
5
+ // src/internals.ts
6
+ var backendOf = (renderer) => renderer.backend;
7
+ function getDevice(renderer) {
8
+ const device = backendOf(renderer)?.device;
9
+ if (!device) {
10
+ throw new Error(
11
+ "AsciiPass requires an initialized THREE.WebGPURenderer \u2014 `await renderer.init()` first. WebGL renderers are unsupported: exact matching would require per-frame GPU\u2192CPU readback (spec \xA730)."
12
+ );
13
+ }
14
+ return device;
15
+ }
16
+ function getCanvasContext(renderer) {
17
+ const context = backendOf(renderer)?.context;
18
+ if (!context) {
19
+ throw new Error(
20
+ "Could not access the WebGPU canvas context via renderer.backend (supported: three r170\u2013r185)."
21
+ );
22
+ }
23
+ return context;
24
+ }
25
+ function getGpuTexture(renderer, texture2) {
26
+ const data = backendOf(renderer)?.get?.(texture2);
27
+ const gpuTexture = data?.texture;
28
+ if (!gpuTexture) {
29
+ throw new Error(
30
+ "Could not access the render target GPU texture via renderer.backend \u2014 render to the target once first (supported: three r170\u2013r185)."
31
+ );
32
+ }
33
+ return gpuTexture;
34
+ }
35
+
36
+ // src/asciiPass.ts
37
+ var AsciiPass = class {
38
+ renderTarget;
39
+ pointer;
40
+ rendererRef;
41
+ profile;
42
+ matchOpts;
43
+ fit;
44
+ clearColor;
45
+ interaction;
46
+ pointerX = 0.5;
47
+ pointerY = 0.5;
48
+ velX = 0;
49
+ velY = 0;
50
+ t0 = performance.now();
51
+ drawSize = new Vector2();
52
+ engine;
53
+ stream;
54
+ device;
55
+ disposed = false;
56
+ constructor(options) {
57
+ const { profile, renderer, width, height, fit, clearColor, interaction, ...match } = options;
58
+ this.profile = profile;
59
+ this.rendererRef = renderer;
60
+ this.matchOpts = match;
61
+ this.fit = fit;
62
+ this.clearColor = clearColor;
63
+ this.interaction = interaction ?? null;
64
+ const size = renderer.getDrawingBufferSize(this.drawSize);
65
+ this.renderTarget = new RenderTarget(
66
+ width ?? Math.max(1, size.x),
67
+ height ?? Math.max(1, size.y)
68
+ );
69
+ this.pointer = {
70
+ set: (x, y) => {
71
+ this.pointerX = x;
72
+ this.pointerY = y;
73
+ },
74
+ setVelocity: (x, y) => {
75
+ this.velX = x;
76
+ this.velY = y;
77
+ }
78
+ };
79
+ }
80
+ /** Compile pipelines on the renderer's device. Call once after renderer.init(). */
81
+ async init() {
82
+ if (this.disposed) throw new Error("AsciiPass.init() called after dispose().");
83
+ if (this.stream) return;
84
+ const device = getDevice(this.rendererRef);
85
+ const engine = await AsciiEngine.create(device, this.profile);
86
+ if (this.disposed) {
87
+ engine.destroy();
88
+ return;
89
+ }
90
+ try {
91
+ const stream = await engine.createStream(navigator.gpu.getPreferredCanvasFormat());
92
+ if (this.disposed) {
93
+ stream.destroy();
94
+ engine.destroy();
95
+ return;
96
+ }
97
+ this.device = device;
98
+ this.engine = engine;
99
+ this.stream = stream;
100
+ } catch (error) {
101
+ engine.destroy();
102
+ throw error;
103
+ }
104
+ }
105
+ /** Update matcher/composite options (spec §2: `ascii.set({...})`). */
106
+ set(options) {
107
+ const { fit, clearColor, ...match } = options;
108
+ if (fit !== void 0) this.fit = fit;
109
+ if (clearColor !== void 0) this.clearColor = clearColor;
110
+ this.matchOpts = { ...this.matchOpts, ...match };
111
+ }
112
+ setInteraction(interaction) {
113
+ this.interaction = interaction;
114
+ }
115
+ setSize(width, height) {
116
+ this.renderTarget.setSize(width, height);
117
+ }
118
+ grid() {
119
+ return this.stream?.grid() ?? null;
120
+ }
121
+ /** Render the scene through the ASCII pipeline to the canvas. */
122
+ render(scene, camera) {
123
+ if (this.disposed) return;
124
+ const stream = this.stream;
125
+ if (!stream || !this.device) {
126
+ throw new Error(
127
+ "AsciiPass.render() called before init() \u2014 `await pass.init()` after creating the pass."
128
+ );
129
+ }
130
+ const renderer = this.rendererRef;
131
+ const prev = renderer.getRenderTarget();
132
+ renderer.setRenderTarget(this.renderTarget);
133
+ renderer.render(scene, camera);
134
+ renderer.setRenderTarget(prev);
135
+ const srcTexture = getGpuTexture(renderer, this.renderTarget.texture);
136
+ stream.configure(srcTexture, this.renderTarget.width, this.renderTarget.height, {
137
+ srgbEncode: true,
138
+ alpha: "ignore",
139
+ ...this.matchOpts
140
+ });
141
+ const cenc = this.device.createCommandEncoder();
142
+ stream.encodeMatch(cenc);
143
+ this.device.queue.submit([cenc.finish()]);
144
+ const size = renderer.getDrawingBufferSize(this.drawSize);
145
+ stream.syncView({ width: size.x, height: size.y, fit: this.fit, clearColor: this.clearColor });
146
+ stream.syncFx(
147
+ {
148
+ interaction: this.interaction,
149
+ pointerX: this.pointerX * size.x,
150
+ pointerY: this.pointerY * size.y,
151
+ velX: this.velX,
152
+ velY: this.velY,
153
+ time: (performance.now() - this.t0) / 1e3
154
+ },
155
+ size.x,
156
+ size.y
157
+ );
158
+ const enc = this.device.createCommandEncoder();
159
+ stream.encodeComposite(enc, getCanvasContext(renderer).getCurrentTexture().createView());
160
+ this.device.queue.submit([enc.finish()]);
161
+ }
162
+ /** Explicit readback of the matched frame (spec §33). */
163
+ async captureFrame() {
164
+ if (!this.stream)
165
+ throw new Error("AsciiPass.captureFrame() requires init() and at least one render().");
166
+ return this.stream.captureFrame();
167
+ }
168
+ dispose() {
169
+ if (this.disposed) return;
170
+ this.disposed = true;
171
+ this.renderTarget.dispose();
172
+ this.stream?.destroy();
173
+ this.engine?.destroy();
174
+ }
175
+ };
176
+
177
+ // src/asciiGlyphs.ts
178
+ import {
179
+ DataTexture,
180
+ InstancedBufferAttribute,
181
+ InstancedMesh,
182
+ LinearFilter,
183
+ LinearMipmapLinearFilter,
184
+ Matrix4,
185
+ PlaneGeometry,
186
+ RedFormat,
187
+ UnsignedByteType
188
+ } from "three";
189
+ import { MeshBasicNodeMaterial } from "three/webgpu";
190
+ import { add, attribute, div, float, floor, mix, mod, mul, texture, uv, vec2 } from "three/tsl";
191
+ import { FLAG_TRANSPARENT, blankGlyphId, unpackB, unpackG, unpackR } from "@ascii-fx/core";
192
+ var AsciiGlyphs = class {
193
+ mesh;
194
+ material;
195
+ columns;
196
+ rows;
197
+ aGlyph;
198
+ aFg;
199
+ aBg;
200
+ aVisible;
201
+ aUseBackground;
202
+ atlasTexture;
203
+ profileFingerprint;
204
+ glyphCount;
205
+ blankGlyph;
206
+ constructor(options) {
207
+ const { profile, columns, rows } = options;
208
+ const cellSize = options.cellSize ?? 1;
209
+ this.columns = columns;
210
+ this.rows = rows;
211
+ this.profileFingerprint = profile.fingerprint;
212
+ this.glyphCount = profile.glyphCount;
213
+ this.blankGlyph = blankGlyphId(profile);
214
+ const { atlas } = profile;
215
+ const aspect = atlas.cellWidth / atlas.cellHeight;
216
+ const count = columns * rows;
217
+ const geometry = new PlaneGeometry(cellSize * aspect, cellSize);
218
+ this.aGlyph = new InstancedBufferAttribute(new Float32Array(count), 1);
219
+ this.aFg = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
220
+ this.aBg = new InstancedBufferAttribute(new Float32Array(count * 3), 3);
221
+ this.aVisible = new InstancedBufferAttribute(new Float32Array(count).fill(1), 1);
222
+ this.aUseBackground = new InstancedBufferAttribute(new Float32Array(count).fill(1), 1);
223
+ geometry.setAttribute("aGlyph", this.aGlyph);
224
+ geometry.setAttribute("aFg", this.aFg);
225
+ geometry.setAttribute("aBg", this.aBg);
226
+ geometry.setAttribute("aVisible", this.aVisible);
227
+ geometry.setAttribute("aUseBackground", this.aUseBackground);
228
+ this.atlasTexture = new DataTexture(
229
+ atlas.data,
230
+ atlas.width,
231
+ atlas.height,
232
+ RedFormat,
233
+ UnsignedByteType
234
+ );
235
+ this.atlasTexture.flipY = false;
236
+ this.atlasTexture.magFilter = LinearFilter;
237
+ this.atlasTexture.minFilter = LinearMipmapLinearFilter;
238
+ this.atlasTexture.generateMipmaps = true;
239
+ this.atlasTexture.needsUpdate = true;
240
+ this.material = new MeshBasicNodeMaterial();
241
+ const n = {
242
+ add,
243
+ attribute,
244
+ div,
245
+ float,
246
+ floor,
247
+ mix,
248
+ mod,
249
+ mul,
250
+ texture,
251
+ uv,
252
+ vec2
253
+ };
254
+ const id = n.attribute("aGlyph");
255
+ const col = n.mod(id, n.float(atlas.columns));
256
+ const row = n.floor(n.div(id, n.float(atlas.columns)));
257
+ const tile = n.vec2(
258
+ n.add(n.mul(col, n.float(atlas.pitchWidth)), n.float(atlas.padding)),
259
+ n.add(n.mul(row, n.float(atlas.pitchHeight)), n.float(atlas.padding))
260
+ );
261
+ const guv = n.add(n.mul(n.uv(), n.vec2(1, -1)), n.vec2(0, 1));
262
+ const texel = n.add(tile, n.mul(guv, n.vec2(atlas.cellWidth, atlas.cellHeight)));
263
+ const auv = n.div(texel, n.vec2(atlas.width, atlas.height));
264
+ const alpha = n.texture(this.atlasTexture, auv).r;
265
+ const foreground = n.attribute("aFg");
266
+ const useBackground = n.attribute("aUseBackground");
267
+ const cellColor = n.mix(n.attribute("aBg"), foreground, alpha);
268
+ this.material.colorNode = n.mix(foreground, cellColor, useBackground);
269
+ this.material.opacityNode = n.mul(
270
+ n.attribute("aVisible"),
271
+ n.mix(alpha, n.float(1), useBackground)
272
+ );
273
+ this.material.transparent = true;
274
+ this.material.depthWrite = false;
275
+ this.mesh = new InstancedMesh(geometry, this.material, count);
276
+ this.mesh.frustumCulled = false;
277
+ const m = new Matrix4();
278
+ const cw = cellSize * aspect;
279
+ for (let cy = 0; cy < rows; cy++) {
280
+ for (let cx = 0; cx < columns; cx++) {
281
+ m.makeTranslation((cx - (columns - 1) / 2) * cw, ((rows - 1) / 2 - cy) * cellSize, 0);
282
+ this.mesh.setMatrixAt(cy * columns + cx, m);
283
+ }
284
+ }
285
+ this.mesh.instanceMatrix.needsUpdate = true;
286
+ }
287
+ /** Load glyph ids and colors from a matched frame (same grid dimensions). */
288
+ updateFromFrame(frame) {
289
+ if (frame.profile.fingerprint !== this.profileFingerprint) {
290
+ throw new Error(
291
+ `Frame profile "${frame.profile.id}" (${frame.profile.fingerprint.slice(0, 12)}\u2026) does not match AsciiGlyphs profile (${this.profileFingerprint.slice(0, 12)}\u2026).`
292
+ );
293
+ }
294
+ if (frame.columns !== this.columns || frame.rows !== this.rows) {
295
+ throw new Error(
296
+ `Frame grid ${frame.columns}\xD7${frame.rows} does not match AsciiGlyphs grid ${this.columns}\xD7${this.rows}.`
297
+ );
298
+ }
299
+ const n = this.columns * this.rows;
300
+ const g = this.aGlyph.array;
301
+ const fg = this.aFg.array;
302
+ const bg = this.aBg.array;
303
+ const visible = this.aVisible.array;
304
+ const useBackground = this.aUseBackground.array;
305
+ for (let i = 0; i < n; i++) {
306
+ const transparent = (frame.flags[i] & FLAG_TRANSPARENT) !== 0;
307
+ const glyphId = frame.glyphIds[i];
308
+ if (glyphId >= this.glyphCount) {
309
+ throw new Error(
310
+ `Frame cell ${i} references glyph ${glyphId}, but the profile has ${this.glyphCount} glyphs.`
311
+ );
312
+ }
313
+ g[i] = transparent ? this.blankGlyph : glyphId;
314
+ visible[i] = transparent ? 0 : 1;
315
+ useBackground[i] = frame.colorMode === "foreground" ? 0 : 1;
316
+ const fgc = frame.foreground?.[i];
317
+ const bgc = frame.background?.[i];
318
+ fg[i * 3] = fgc !== void 0 ? unpackR(fgc) / 255 : 1;
319
+ fg[i * 3 + 1] = fgc !== void 0 ? unpackG(fgc) / 255 : 1;
320
+ fg[i * 3 + 2] = fgc !== void 0 ? unpackB(fgc) / 255 : 1;
321
+ bg[i * 3] = bgc !== void 0 ? unpackR(bgc) / 255 : 0;
322
+ bg[i * 3 + 1] = bgc !== void 0 ? unpackG(bgc) / 255 : 0;
323
+ bg[i * 3 + 2] = bgc !== void 0 ? unpackB(bgc) / 255 : 0;
324
+ }
325
+ this.aGlyph.needsUpdate = true;
326
+ this.aFg.needsUpdate = true;
327
+ this.aBg.needsUpdate = true;
328
+ this.aVisible.needsUpdate = true;
329
+ this.aUseBackground.needsUpdate = true;
330
+ }
331
+ dispose() {
332
+ this.mesh.dispose();
333
+ this.mesh.geometry.dispose();
334
+ this.material.dispose();
335
+ this.atlasTexture.dispose();
336
+ }
337
+ };
338
+ export {
339
+ AsciiGlyphs,
340
+ AsciiPass
341
+ };
342
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/asciiPass.ts","../src/internals.ts","../src/asciiGlyphs.ts"],"sourcesContent":["import { RenderTarget, Vector2 } from 'three'\nimport type { Camera, Object3D } from 'three'\nimport type { WebGPURenderer } from 'three/webgpu'\nimport type { AsciiFrame, AsciiProfile } from '@ascii-fx/core'\nimport { AsciiEngine, AsciiStream } from '@ascii-fx/gpu'\nimport type { AsciiPointer, FitMode, InteractionOptions, StreamMatchOptions } from '@ascii-fx/gpu'\nimport { getCanvasContext, getDevice, getGpuTexture } from './internals.js'\n\nexport interface AsciiPassOptions extends StreamMatchOptions {\n profile: AsciiProfile\n renderer: WebGPURenderer\n /** Render-target resolution; defaults to the renderer's drawing buffer size. */\n width?: number\n height?: number\n fit?: FitMode\n clearColor?: readonly [number, number, number, number]\n interaction?: InteractionOptions | null\n}\n\n/**\n * Fullscreen ASCII postprocessing for THREE.WebGPURenderer (spec §30):\n * scene → render target → exact structural-v1 compute on Three's own\n * GPUDevice → one-draw atlas composite straight to the canvas.\n *\n * The render target holds linear-light values, so the source is sRGB-encoded\n * before matching (§28). Usage:\n *\n * ```ts\n * const pass = new AsciiPass({ profile, renderer, columns: 160 })\n * await pass.init()\n * pass.render(scene, camera) // instead of renderer.render(...)\n * ```\n */\nexport class AsciiPass {\n readonly renderTarget: RenderTarget\n readonly pointer: AsciiPointer\n\n private readonly rendererRef: WebGPURenderer\n private readonly profile: AsciiProfile\n private matchOpts: StreamMatchOptions\n private fit: FitMode | undefined\n private clearColor: readonly [number, number, number, number] | undefined\n private interaction: InteractionOptions | null\n private pointerX = 0.5\n private pointerY = 0.5\n private velX = 0\n private velY = 0\n private readonly t0 = performance.now()\n private readonly drawSize = new Vector2()\n\n private engine?: AsciiEngine\n private stream?: AsciiStream\n private device?: GPUDevice\n private disposed = false\n\n constructor(options: AsciiPassOptions) {\n const { profile, renderer, width, height, fit, clearColor, interaction, ...match } = options\n this.profile = profile\n this.rendererRef = renderer\n this.matchOpts = match\n this.fit = fit\n this.clearColor = clearColor\n this.interaction = interaction ?? null\n const size = renderer.getDrawingBufferSize(this.drawSize)\n this.renderTarget = new RenderTarget(\n width ?? Math.max(1, size.x),\n height ?? Math.max(1, size.y),\n )\n this.pointer = {\n set: (x: number, y: number) => {\n this.pointerX = x\n this.pointerY = y\n },\n setVelocity: (x: number, y: number) => {\n this.velX = x\n this.velY = y\n },\n }\n }\n\n /** Compile pipelines on the renderer's device. Call once after renderer.init(). */\n async init(): Promise<void> {\n if (this.disposed) throw new Error('AsciiPass.init() called after dispose().')\n if (this.stream) return\n const device = getDevice(this.rendererRef)\n const engine = await AsciiEngine.create(device, this.profile)\n if (this.disposed) {\n engine.destroy()\n return\n }\n try {\n const stream = await engine.createStream(navigator.gpu.getPreferredCanvasFormat())\n if (this.disposed) {\n stream.destroy()\n engine.destroy()\n return\n }\n this.device = device\n this.engine = engine\n this.stream = stream\n } catch (error) {\n engine.destroy()\n throw error\n }\n }\n\n /** Update matcher/composite options (spec §2: `ascii.set({...})`). */\n set(\n options: Partial<\n StreamMatchOptions & { fit: FitMode; clearColor: readonly [number, number, number, number] }\n >,\n ): void {\n const { fit, clearColor, ...match } = options\n if (fit !== undefined) this.fit = fit\n if (clearColor !== undefined) this.clearColor = clearColor\n this.matchOpts = { ...this.matchOpts, ...match }\n }\n\n setInteraction(interaction: InteractionOptions | null): void {\n this.interaction = interaction\n }\n\n setSize(width: number, height: number): void {\n this.renderTarget.setSize(width, height)\n }\n\n grid(): { columns: number; rows: number } | null {\n return this.stream?.grid() ?? null\n }\n\n /** Render the scene through the ASCII pipeline to the canvas. */\n render(scene: Object3D, camera: Camera): void {\n if (this.disposed) return\n const stream = this.stream\n if (!stream || !this.device) {\n throw new Error(\n 'AsciiPass.render() called before init() — `await pass.init()` after creating the pass.',\n )\n }\n const renderer = this.rendererRef\n\n const prev = renderer.getRenderTarget()\n renderer.setRenderTarget(this.renderTarget)\n renderer.render(scene, camera)\n renderer.setRenderTarget(prev)\n\n const srcTexture = getGpuTexture(renderer, this.renderTarget.texture)\n stream.configure(srcTexture, this.renderTarget.width, this.renderTarget.height, {\n srgbEncode: true,\n alpha: 'ignore',\n ...this.matchOpts,\n })\n\n const cenc = this.device.createCommandEncoder()\n stream.encodeMatch(cenc)\n this.device.queue.submit([cenc.finish()])\n\n const size = renderer.getDrawingBufferSize(this.drawSize)\n stream.syncView({ width: size.x, height: size.y, fit: this.fit, clearColor: this.clearColor })\n stream.syncFx(\n {\n interaction: this.interaction,\n pointerX: this.pointerX * size.x,\n pointerY: this.pointerY * size.y,\n velX: this.velX,\n velY: this.velY,\n time: (performance.now() - this.t0) / 1000,\n },\n size.x,\n size.y,\n )\n const enc = this.device.createCommandEncoder()\n stream.encodeComposite(enc, getCanvasContext(renderer).getCurrentTexture().createView())\n this.device.queue.submit([enc.finish()])\n }\n\n /** Explicit readback of the matched frame (spec §33). */\n async captureFrame(): Promise<AsciiFrame> {\n if (!this.stream)\n throw new Error('AsciiPass.captureFrame() requires init() and at least one render().')\n return this.stream.captureFrame()\n }\n\n dispose(): void {\n if (this.disposed) return\n this.disposed = true\n this.renderTarget.dispose()\n this.stream?.destroy()\n this.engine?.destroy() // engine resources only — the device belongs to Three\n }\n}\n","// Access to WebGPURenderer backend internals. Three does not yet expose the\n// GPUDevice / canvas context / texture handles publicly; these accessors are\n// the supported-in-practice interop points, verified against r170–r185.\nimport type { Texture } from 'three'\nimport type { WebGPURenderer } from 'three/webgpu'\n\ninterface BackendLike {\n device?: GPUDevice\n context?: GPUCanvasContext\n get?: (object: unknown) => { texture?: GPUTexture } | undefined\n}\n\nconst backendOf = (renderer: WebGPURenderer): BackendLike | undefined =>\n (renderer as unknown as { backend?: BackendLike }).backend\n\nexport function getDevice(renderer: WebGPURenderer): GPUDevice {\n const device = backendOf(renderer)?.device\n if (!device) {\n throw new Error(\n 'AsciiPass requires an initialized THREE.WebGPURenderer — `await renderer.init()` first. ' +\n 'WebGL renderers are unsupported: exact matching would require per-frame GPU→CPU readback (spec §30).',\n )\n }\n return device\n}\n\nexport function getCanvasContext(renderer: WebGPURenderer): GPUCanvasContext {\n const context = backendOf(renderer)?.context\n if (!context) {\n throw new Error(\n 'Could not access the WebGPU canvas context via renderer.backend (supported: three r170–r185).',\n )\n }\n return context\n}\n\nexport function getGpuTexture(renderer: WebGPURenderer, texture: Texture): GPUTexture {\n const data = backendOf(renderer)?.get?.(texture)\n const gpuTexture = data?.texture\n if (!gpuTexture) {\n throw new Error(\n 'Could not access the render target GPU texture via renderer.backend — render to the target once first ' +\n '(supported: three r170–r185).',\n )\n }\n return gpuTexture\n}\n","import {\n DataTexture,\n InstancedBufferAttribute,\n InstancedMesh,\n LinearFilter,\n LinearMipmapLinearFilter,\n Matrix4,\n PlaneGeometry,\n RedFormat,\n UnsignedByteType,\n} from 'three'\nimport { MeshBasicNodeMaterial } from 'three/webgpu'\nimport { add, attribute, div, float, floor, mix, mod, mul, texture, uv, vec2 } from 'three/tsl'\nimport type { AsciiFrame, AsciiProfile } from '@ascii-fx/core'\nimport { FLAG_TRANSPARENT, blankGlyphId, unpackB, unpackG, unpackR } from '@ascii-fx/core'\n\nexport interface AsciiGlyphsOptions {\n profile: AsciiProfile\n columns: number\n rows: number\n /** World-space cell height. Default 1. */\n cellSize?: number\n}\n\n/**\n * Instanced 3D glyph renderer (spec §8 'instances', §30): one plane instance\n * per cell, glyph/colors as instanced attributes, atlas sampled via TSL.\n * Instance transforms live in the standard instanceMatrix so effects can\n * animate them (GPU-side via node materials, or CPU-side via setMatrixAt).\n *\n * v1 data path: populate from a captured AsciiFrame (`updateFromFrame`).\n * A zero-readback bridge from the GPU cell buffer is a planned optimization.\n */\nexport class AsciiGlyphs {\n readonly mesh: InstancedMesh\n readonly material: MeshBasicNodeMaterial\n readonly columns: number\n readonly rows: number\n\n private readonly aGlyph: InstancedBufferAttribute\n private readonly aFg: InstancedBufferAttribute\n private readonly aBg: InstancedBufferAttribute\n private readonly aVisible: InstancedBufferAttribute\n private readonly aUseBackground: InstancedBufferAttribute\n private readonly atlasTexture: DataTexture\n private readonly profileFingerprint: string\n private readonly glyphCount: number\n private readonly blankGlyph: number\n\n constructor(options: AsciiGlyphsOptions) {\n const { profile, columns, rows } = options\n const cellSize = options.cellSize ?? 1\n this.columns = columns\n this.rows = rows\n this.profileFingerprint = profile.fingerprint\n this.glyphCount = profile.glyphCount\n this.blankGlyph = blankGlyphId(profile)\n const { atlas } = profile\n const aspect = atlas.cellWidth / atlas.cellHeight\n const count = columns * rows\n\n const geometry = new PlaneGeometry(cellSize * aspect, cellSize)\n this.aGlyph = new InstancedBufferAttribute(new Float32Array(count), 1)\n this.aFg = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3)\n this.aBg = new InstancedBufferAttribute(new Float32Array(count * 3), 3)\n this.aVisible = new InstancedBufferAttribute(new Float32Array(count).fill(1), 1)\n this.aUseBackground = new InstancedBufferAttribute(new Float32Array(count).fill(1), 1)\n geometry.setAttribute('aGlyph', this.aGlyph)\n geometry.setAttribute('aFg', this.aFg)\n geometry.setAttribute('aBg', this.aBg)\n geometry.setAttribute('aVisible', this.aVisible)\n geometry.setAttribute('aUseBackground', this.aUseBackground)\n\n this.atlasTexture = new DataTexture(\n atlas.data as Uint8Array<ArrayBuffer>,\n atlas.width,\n atlas.height,\n RedFormat,\n UnsignedByteType,\n )\n this.atlasTexture.flipY = false\n this.atlasTexture.magFilter = LinearFilter\n this.atlasTexture.minFilter = LinearMipmapLinearFilter\n this.atlasTexture.generateMipmaps = true\n this.atlasTexture.needsUpdate = true\n\n this.material = new MeshBasicNodeMaterial()\n // @types/three cannot yet type composed TSL node graphs; the runtime API\n // is stable, so the graph is built through a single contained cast.\n /* eslint-disable @typescript-eslint/no-explicit-any */\n const n = {\n add,\n attribute,\n div,\n float,\n floor,\n mix,\n mod,\n mul,\n texture,\n uv,\n vec2,\n } as unknown as Record<\n | 'add'\n | 'attribute'\n | 'div'\n | 'float'\n | 'floor'\n | 'mix'\n | 'mod'\n | 'mul'\n | 'texture'\n | 'uv'\n | 'vec2',\n (...args: any[]) => any\n >\n /* eslint-enable @typescript-eslint/no-explicit-any */\n const id = n.attribute('aGlyph')\n const col = n.mod(id, n.float(atlas.columns))\n const row = n.floor(n.div(id, n.float(atlas.columns)))\n const tile = n.vec2(\n n.add(n.mul(col, n.float(atlas.pitchWidth)), n.float(atlas.padding)),\n n.add(n.mul(row, n.float(atlas.pitchHeight)), n.float(atlas.padding)),\n )\n // PlaneGeometry uv has v=0 at the bottom; the atlas is y-down: flip v.\n const guv = n.add(n.mul(n.uv(), n.vec2(1, -1)), n.vec2(0, 1))\n const texel = n.add(tile, n.mul(guv, n.vec2(atlas.cellWidth, atlas.cellHeight)))\n const auv = n.div(texel, n.vec2(atlas.width, atlas.height))\n const alpha = n.texture(this.atlasTexture, auv).r\n const foreground = n.attribute('aFg')\n const useBackground = n.attribute('aUseBackground')\n const cellColor = n.mix(n.attribute('aBg'), foreground, alpha)\n this.material.colorNode = n.mix(foreground, cellColor, useBackground)\n this.material.opacityNode = n.mul(\n n.attribute('aVisible'),\n n.mix(alpha, n.float(1), useBackground),\n )\n this.material.transparent = true\n this.material.depthWrite = false\n\n this.mesh = new InstancedMesh(geometry, this.material, count)\n this.mesh.frustumCulled = false\n const m = new Matrix4()\n const cw = cellSize * aspect\n for (let cy = 0; cy < rows; cy++) {\n for (let cx = 0; cx < columns; cx++) {\n m.makeTranslation((cx - (columns - 1) / 2) * cw, ((rows - 1) / 2 - cy) * cellSize, 0)\n this.mesh.setMatrixAt(cy * columns + cx, m)\n }\n }\n this.mesh.instanceMatrix.needsUpdate = true\n }\n\n /** Load glyph ids and colors from a matched frame (same grid dimensions). */\n updateFromFrame(frame: AsciiFrame): void {\n if (frame.profile.fingerprint !== this.profileFingerprint) {\n throw new Error(\n `Frame profile \"${frame.profile.id}\" (${frame.profile.fingerprint.slice(0, 12)}…) does not match ` +\n `AsciiGlyphs profile (${this.profileFingerprint.slice(0, 12)}…).`,\n )\n }\n if (frame.columns !== this.columns || frame.rows !== this.rows) {\n throw new Error(\n `Frame grid ${frame.columns}×${frame.rows} does not match AsciiGlyphs grid ${this.columns}×${this.rows}.`,\n )\n }\n const n = this.columns * this.rows\n const g = this.aGlyph.array as Float32Array\n const fg = this.aFg.array as Float32Array\n const bg = this.aBg.array as Float32Array\n const visible = this.aVisible.array as Float32Array\n const useBackground = this.aUseBackground.array as Float32Array\n for (let i = 0; i < n; i++) {\n const transparent = (frame.flags[i] & FLAG_TRANSPARENT) !== 0\n const glyphId = frame.glyphIds[i]\n if (glyphId >= this.glyphCount) {\n throw new Error(\n `Frame cell ${i} references glyph ${glyphId}, but the profile has ${this.glyphCount} glyphs.`,\n )\n }\n g[i] = transparent ? this.blankGlyph : glyphId\n visible[i] = transparent ? 0 : 1\n useBackground[i] = frame.colorMode === 'foreground' ? 0 : 1\n const fgc = frame.foreground?.[i]\n const bgc = frame.background?.[i]\n fg[i * 3] = fgc !== undefined ? unpackR(fgc) / 255 : 1\n fg[i * 3 + 1] = fgc !== undefined ? unpackG(fgc) / 255 : 1\n fg[i * 3 + 2] = fgc !== undefined ? unpackB(fgc) / 255 : 1\n bg[i * 3] = bgc !== undefined ? unpackR(bgc) / 255 : 0\n bg[i * 3 + 1] = bgc !== undefined ? unpackG(bgc) / 255 : 0\n bg[i * 3 + 2] = bgc !== undefined ? unpackB(bgc) / 255 : 0\n }\n this.aGlyph.needsUpdate = true\n this.aFg.needsUpdate = true\n this.aBg.needsUpdate = true\n this.aVisible.needsUpdate = true\n this.aUseBackground.needsUpdate = true\n }\n\n dispose(): void {\n // The mesh's own dispose releases its instanced attributes (instanceMatrix et al.);\n // without it their GPU buffers wait on backend WeakMap GC.\n this.mesh.dispose()\n this.mesh.geometry.dispose()\n this.material.dispose()\n this.atlasTexture.dispose()\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc,eAAe;AAItC,SAAS,mBAAgC;;;ACQzC,IAAM,YAAY,CAAC,aAChB,SAAkD;AAE9C,SAAS,UAAU,UAAqC;AAC7D,QAAM,SAAS,UAAU,QAAQ,GAAG;AACpC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,iBAAiB,UAA4C;AAC3E,QAAM,UAAU,UAAU,QAAQ,GAAG;AACrC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,cAAc,UAA0BA,UAA8B;AACpF,QAAM,OAAO,UAAU,QAAQ,GAAG,MAAMA,QAAO;AAC/C,QAAM,aAAa,MAAM;AACzB,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,SAAO;AACT;;;ADbO,IAAM,YAAN,MAAgB;AAAA,EACZ;AAAA,EACA;AAAA,EAEQ;AAAA,EACA;AAAA,EACT;AAAA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ice(renderer: WebGPURenderer): GPUDevice;
4
+ export declare function getCanvasContext(renderer: WebGPURenderer): GPUCanvasContext;
5
+ export declare function getGpuTexture(renderer: WebGPURenderer, texture: Texture): GPUTexture;
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@ascii-fx/three",
3
+ "version": "0.2.0",
4
+ "description": "Three.js adapter for ASCII FX: AsciiPass postprocessing for WebGPURenderer and an instanced AsciiGlyphs renderer.",
5
+ "keywords": [
6
+ "ascii",
7
+ "ascii-art",
8
+ "ascii-fx",
9
+ "postprocessing",
10
+ "three",
11
+ "threejs",
12
+ "webgpu"
13
+ ],
14
+ "homepage": "https://github.com/Amir-Abushanab/ascii-fx#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/Amir-Abushanab/ascii-fx/issues"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Amir Abushanab (https://github.com/Amir-Abushanab)",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/Amir-Abushanab/ascii-fx.git",
23
+ "directory": "packages/three"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "type": "module",
29
+ "sideEffects": false,
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ }
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "dependencies": {
40
+ "@ascii-fx/core": "0.2.0",
41
+ "@ascii-fx/gpu": "0.2.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/three": "0.185.4",
45
+ "@webgpu/types": "^0.1.71",
46
+ "three": "0.185.1",
47
+ "tsup": "^8.5.1",
48
+ "typescript": "^7.0.2"
49
+ },
50
+ "peerDependencies": {
51
+ "three": ">=0.170.0"
52
+ },
53
+ "engines": {
54
+ "node": ">=22"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup && tsc -p tsconfig.build.json",
58
+ "typecheck": "tsc --noEmit"
59
+ }
60
+ }