From d045674fa1918dce03fef6e06f8e8b9b971c7c51 Mon Sep 17 00:00:00 2001 From: AlexZ005 Date: Sat, 21 Nov 2026 18:40:49 +0200 Subject: [PATCH 01/12] 102b-papercuts 2a: Set Shader Uniform drives colour and vector uniforms A vec2/vec3/vec4 uniform takes a wired vector, then a colour (sRGB to linear, as the compiler does for an authored colour), then the number in every component. Float uniforms unchanged. Leaf src/lib/uniformWrite.js keeps the shader compiler out of the boot chunk. Co-Authored-By: Claude Opus 5.5 --- .../editors/nodes/EffectNode.svelte | 8 ++ src/lib/ai/lookTools.js | 4 +- src/lib/flowRuntime.js | 8 +- src/lib/nodeDocs.js | 2 +- src/lib/nodes/families/logic.js | 4 +- src/lib/uniformWrite.js | 80 +++++++++++++++++++ tests/unit/uniformWrite.test.js | 52 ++++++++++++ 7 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 src/lib/uniformWrite.js create mode 100644 tests/unit/uniformWrite.test.js diff --git a/src/components/editors/nodes/EffectNode.svelte b/src/components/editors/nodes/EffectNode.svelte index 71459c4ac..7b0e3e474 100644 --- a/src/components/editors/nodes/EffectNode.svelte +++ b/src/components/editors/nodes/EffectNode.svelte @@ -22,6 +22,12 @@ + {#if data.type === 'setuniform'} + + + + {/if}
{#if data.type === 'lookat'} @@ -42,6 +48,8 @@

the name shown beside that param in the Shader editor

+ color + vector {:else if data.type === 'visibility'}
@@ -4017,23 +4009,7 @@ -
-

- This mesh is a rounded box ({roundOffer.width} x {roundOffer.height} x {roundOffer.depth} m, corner {roundOffer.radius} m). -

- { - const uuid = $selectedObject.uuid; - void import('$lib/roundedBoxConvert.js').then((m) => { - if (m.convertToRoundedBox(uuid)) geoTick++; - }); - }}>Convert to a rounded Box -
+ {#await import('./RoundedBoxOffer.svelte') then m} geoTick++} />{/await} {/if} {#if $selectedObject?.userData?.terrain && !multiCount} diff --git a/src/components/menu/RoundedBoxOffer.svelte b/src/components/menu/RoundedBoxOffer.svelte new file mode 100644 index 000000000..5a9b5133a --- /dev/null +++ b/src/components/menu/RoundedBoxOffer.svelte @@ -0,0 +1,26 @@ + + +
+

+ This mesh is a rounded box ({offer.width} x {offer.height} x {offer.depth} m, corner {offer.radius} m). +

+ { + void import('$lib/roundedBoxConvert.js').then((m) => { + if (m.convertToRoundedBox(uuid)) onconverted(); + }); + }}>Convert to a rounded Box +
From 149a9e703dc15a3293d8e4cad1daca1096b2ccce Mon Sep 17 00:00:00 2001 From: AlexZ005 Date: Sun, 22 Nov 2026 06:25:54 +0200 Subject: [PATCH 12/12] 102b: fog editing helpers in a lazy fogEdit.js; papercuts-102b suite hardening Script event check waits for the first pulse (the sandbox guest loads lazily) and uses a 4 s square wave (the flow tick rides rAF; a loaded headless page draws ~3 frames/s, so a 1 Hz wave aliased). Fog rows retry the section open, B's reload has a fallback wait. Co-Authored-By: Claude Opus 5.5 --- src/components/menu/scene/FogKindRows.svelte | 3 +- src/lib/fogEdit.js | 44 ++++++++++++++++++++ src/lib/fogModes.js | 40 +----------------- tests/e2e/papercuts-102b.test.cjs | 29 ++++++++----- tests/unit/fogModes.test.js | 3 +- 5 files changed, 68 insertions(+), 51 deletions(-) create mode 100644 src/lib/fogEdit.js diff --git a/src/components/menu/scene/FogKindRows.svelte b/src/components/menu/scene/FogKindRows.svelte index bb499c494..646b55a2a 100644 --- a/src/components/menu/scene/FogKindRows.svelte +++ b/src/components/menu/scene/FogKindRows.svelte @@ -8,7 +8,8 @@ import SliderRow from '../../ui/SliderRow.svelte'; import ThemedSelect from '../../ui/ThemedSelect.svelte'; import { editEnvSky } from '$lib/environment'; - import { fogKindOf, fogDensityOf, heightFogOf, fogKindPatch } from '$lib/fogModes.js'; + import { fogKindOf, fogDensityOf, heightFogOf } from '$lib/fogModes.js'; + import { fogKindPatch } from '$lib/fogEdit.js'; /** @type {{fog: any}} */ let { fog } = $props(); diff --git a/src/lib/fogEdit.js b/src/lib/fogEdit.js new file mode 100644 index 000000000..5d8fd6e8e --- /dev/null +++ b/src/lib/fogEdit.js @@ -0,0 +1,44 @@ +// 102b-papercuts: the EDITING half of fogModes.js (the boot keeps only what drawing a fog needs). Loaded by the +// lazy Fog kind rows and the unit tests. +import { fogKindOf, fogDensityOf, heightFogOf, FOG_DENSITY_DEFAULT, FOG_THICKNESS_DEFAULT } from './fogModes.js'; + +/** @typedef {import('./fogModes.js').FogKind} FogKind */ + +/** + * A patch that switches the kind, with the defaults the new kind needs (a density, a layer). Merged by + * mergeFogPatch like any fog edit; near / far are left as they were (they are an older build's fog). + * @param {any} fog @param {FogKind} kind + */ +export function fogKindPatch(fog, kind) { + if (kind === 'linear') return { kind: 'linear' }; + /** @type {Record} */ + const patch = { kind }; + if (!(Number(fog?.density) > 0)) patch.density = FOG_DENSITY_DEFAULT; + if (kind === 'height') { + if (!Number.isFinite(Number(fog?.base))) patch.base = 0; + if (!(Number(fog?.thickness) > 0)) patch.thickness = FOG_THICKNESS_DEFAULT; + } + return patch; +} + +/** + * The fraction of fog colour one point gets — the same maths the shader runs, for tests and probes. + * @param {any} fog @param {number} dist metres from the camera @param {number} camY @param {number} pointY + */ +export function fogFactorAt(fog, dist, camY, pointY) { + const kind = fogKindOf(fog); + if (kind === 'linear') { + const near = Number(fog?.near) || 0; + const far = Number(fog?.far) || 0; + const t = Math.min(1, Math.max(0, (dist - near) / Math.max(1e-6, far - near))); + return t * t * (3 - 2 * t); // smoothstep, as three + } + const d = fogDensityOf(fog); + if (kind === 'distance') return 1 - Math.exp(-d * d * dist * dist); + const h = /** @type {{base: number, thickness: number}} */ (heightFogOf(fog)); + const k = 1 / h.thickness; + const h0 = Math.max(camY - h.base, 0); + const h1 = Math.max(pointY - h.base, 0); + const f = Math.abs(h1 - h0) > 1e-3 ? (Math.exp(-k * h0) - Math.exp(-k * h1)) / (k * (h1 - h0)) : Math.exp(-k * h0); + return 1 - Math.exp(-d * dist * f); +} diff --git a/src/lib/fogModes.js b/src/lib/fogModes.js index d162ad730..50b1d5751 100644 --- a/src/lib/fogModes.js +++ b/src/lib/fogModes.js @@ -10,6 +10,7 @@ // into a valley fogs more than looking across it // // near / far stay in the document, so an older build (which only knows linear fog) still draws a fog. +// The editing half (switching kind, the shader maths for tests) is fogEdit.js, which only the lazy Fog rows load. /** @typedef {'linear' | 'distance' | 'height'} FogKind */ export const FOG_KINDS = /** @type {const} */ (['linear', 'distance', 'height']); @@ -44,45 +45,6 @@ export function heightFogParams(fog) { return h ? [h.base, 1 / h.thickness, 1, 0] : [0, 0, 0, 0]; } -/** - * A patch that switches the kind, with the defaults the new kind needs (a density, a layer). Merged by - * mergeFogPatch like any fog edit; near / far are left as they were (they are an older build's fog). - * @param {any} fog @param {FogKind} kind - */ -export function fogKindPatch(fog, kind) { - if (kind === 'linear') return { kind: 'linear' }; - /** @type {Record} */ - const patch = { kind }; - if (!(Number(fog?.density) > 0)) patch.density = FOG_DENSITY_DEFAULT; - if (kind === 'height') { - if (!Number.isFinite(Number(fog?.base))) patch.base = 0; - if (!(Number(fog?.thickness) > 0)) patch.thickness = FOG_THICKNESS_DEFAULT; - } - return patch; -} - -/** - * The fraction of fog colour one point gets — the same maths the shader runs, for tests and probes. - * @param {any} fog @param {number} dist metres from the camera @param {number} camY @param {number} pointY - */ -export function fogFactorAt(fog, dist, camY, pointY) { - const kind = fogKindOf(fog); - if (kind === 'linear') { - const near = Number(fog?.near) || 0; - const far = Number(fog?.far) || 0; - const t = Math.min(1, Math.max(0, (dist - near) / Math.max(1e-6, far - near))); - return t * t * (3 - 2 * t); // smoothstep, as three - } - const d = fogDensityOf(fog); - if (kind === 'distance') return 1 - Math.exp(-d * d * dist * dist); - const h = /** @type {{base: number, thickness: number}} */ (heightFogOf(fog)); - const k = 1 / h.thickness; - const h0 = Math.max(camY - h.base, 0); - const h1 = Math.max(pointY - h.base, 0); - const f = Math.abs(h1 - h0) > 1e-3 ? (Math.exp(-k * h0) - Math.exp(-k * h1)) / (k * (h1 - h0)) : Math.exp(-k * h0); - return 1 - Math.exp(-d * dist * f); -} - /** 102b: the shared height-fog uniform value [base, 1/thickness, on, 0] (fogShader.js puts it in every fog * material; a leaf here so the Cinematic view and environment.js can read and write it without the patch) */ export const HEIGHT_FOG = new Float32Array(4); diff --git a/tests/e2e/papercuts-102b.test.cjs b/tests/e2e/papercuts-102b.test.cjs index 4d18556ae..456f102e8 100644 --- a/tests/e2e/papercuts-102b.test.cjs +++ b/tests/e2e/papercuts-102b.test.cjs @@ -229,7 +229,8 @@ h.run(async () => { if (process.env.OUT) fs.writeFileSync(process.env.OUT + '/102b-saved.tpscene', Buffer.from(b64, 'base64')); // two-peer + reload: B reloads, rejoins, and has the rounded box (GLTF sync carries vertices + params) - await h.freshReload(B); + // a loaded machine can take longer than the helper's 30 s to boot the reloaded page + await h.freshReload(B).catch(() => B.page.waitForFunction(() => window.__tp?.test.v1 && !!window.__tp.test.v1.moduleSDK, null, { timeout: 120000 })); await h.answerRestore(B).catch(() => false); await h.eventually(() => B.page.evaluate(() => { let p; window.__tp.test.v1.peers.subscribe((x) => (p = x))(); const o = p?.openedPeers; return o ? (o.size ?? o.length ?? Object.keys(o).length) : 0; }), (n) => n >= 1, '3. B is back in the session after its reload', 60000); await h.eventually(() => geoOf(B.page, crate), (o) => o?.verts === 1764 && o.gp?.params?.radius === 0.2, '3. after the reload B has the rounded box with its radius (rows editable)', 60000); @@ -322,7 +323,7 @@ h.run(async () => { const scr = await exec(A, 'create_flow_nodes', { graph: 'scene', nodes: [ - { ref: 'tick', type: 'script', data: { code: 'return { hit: Math.floor(time * 2) % 2 === 0 };', outputs: [{ name: 'hit', type: 'event' }] } }, + { ref: 'tick', type: 'script', data: { code: 'return { hit: Math.floor(time / 2) % 2 === 0 };', outputs: [{ name: 'hit', type: 'event' }] } }, { ref: 'count', type: 'counter' } ], edges: [{ from: 'tick', fromHandle: 'hit', to: 'count', toHandle: 'pulse' }] @@ -330,12 +331,17 @@ h.run(async () => { console.log(" create_flow_nodes: " + JSON.stringify(scr).slice(0, 900)); const countId = scr?.created?.find?.((c) => c.ref === 'count')?.id ?? scr?.created?.[1]?.id; const counterOf = (page) => page.evaluate((id) => { let t; window.__tp.test.v1.flowTriggers.subscribe((x) => (t = x))(); return t?.[id]?.count ?? 0; }, countId); - const c0 = await counterOf(A.page); - await new Promise((r) => setTimeout(r, 4200)); - const c1 = await counterOf(A.page); - h.check(c1 - c0 >= 3 && c1 - c0 <= 5, '6. the Script event fires once per rising edge (a 1 Hz square wave over 4.2 s: +' + (c1 - c0) + ', 3..5)'); - const cb = await counterOf(B.page); - h.check(Math.abs(cb - c1) <= 1, '6. B counts it too (its own run of the same code: A ' + c1 + ', B ' + cb + ')'); + // the first Script on a page loads the sandbox guest (lazy): wait for the first pulse on each peer, then measure one window + for (const P of [A, B]) await h.eventually(() => counterOf(P.page), (n) => n >= 1, 'premise: ' + P.name + ' runs the Script (sandbox loaded, first pulse)', 60000); + // a 4 s square wave (2 s halves): the flow tick rides rAF, and a loaded headless page draws ~1-4 frames a + // second, so a faster wave would be sampled too coarsely to see every edge (that is aliasing, not a miss) + const fps = await A.page.evaluate(() => new Promise((r) => { let n = 0; const t0 = performance.now(); const f = () => { n++; if (performance.now() - t0 < 2000) requestAnimationFrame(f); else r(Math.round((n / 2) * 10) / 10); }; requestAnimationFrame(f); })); + console.log(' A draws ' + fps + ' frames/s'); + const [s0, t0] = [await counterOf(A.page), await counterOf(B.page)]; + await new Promise((r) => setTimeout(r, 12200)); + const [s1, t1] = [await counterOf(A.page), await counterOf(B.page)]; + h.check(s1 - s0 >= 2 && s1 - s0 <= 4, '6. the Script event fires once per rising edge (a 4 s square wave over 12.2 s: +' + (s1 - s0) + ', 2..4)'); + h.check(t1 - t0 >= 2 && t1 - t0 <= 4, '6. B counts it too (its own run of the same code: +' + (t1 - t0) + ')'); // ---- 7. an effect that acts on nothing console.log('\n=== 7. acts on nothing ==='); @@ -365,8 +371,11 @@ h.run(async () => { await h.eventually(() => envOf(B), (e) => JSON.stringify(e).includes('"kind":"height"'), '8. B reads a height fog back (get_environment)', 20000); const fb = await fogOn(B.page); h.check(fb.exp2 && Math.abs(fb.density - 0.05) < 1e-6, '8. B draws it as a distance-integrated fog (FogExp2, density 0.05): ' + short(fb)); - await A.page.evaluate(() => window.__tp.test.v1.openSceneSection('Fog')); - await A.page.waitForSelector('#fog-kind', { timeout: 15000 }).catch(() => {}); + // the Fog rows are a lazy chunk: under load the section can need a second ask and longer than 15 s + for (let i = 0; i < 4; i++) { + await A.page.evaluate(() => window.__tp.test.v1.openSceneSection('Fog')); + if (await A.page.waitForSelector('#fog-kind', { timeout: 15000 }).then(() => true, () => false)) break; + } const kindRow = await A.page.evaluate(() => ({ there: !!document.getElementById('fog-kind'), tip: document.getElementById('fog-kind')?.getAttribute('title') ?? document.getElementById('fog-kind')?.closest('[title]')?.getAttribute('title') ?? '', base: !!document.getElementById('fog-base'), near: !!document.getElementById('fog-near') })); h.check(kindRow.there && kindRow.base && !kindRow.near, '8. the Fog rows show Kind + Ground height, and hide Near/Far for a height fog: ' + short(kindRow)); const picked = await exec(A, 'set_sky', { fog: { kind: 'linear', near: 5, far: 60 } }); diff --git a/tests/unit/fogModes.test.js b/tests/unit/fogModes.test.js index a0e969115..798f66121 100644 --- a/tests/unit/fogModes.test.js +++ b/tests/unit/fogModes.test.js @@ -1,7 +1,8 @@ // 102b-papercuts (scout row 18): real distance and height fog import { describe, it, expect } from 'vitest'; import * as THREE from 'three'; -import { fogKindOf, fogDensityOf, heightFogOf, heightFogParams, fogKindPatch, fogFactorAt } from '../../src/lib/fogModes.js'; +import { fogKindOf, fogDensityOf, heightFogOf, heightFogParams } from '../../src/lib/fogModes.js'; +import { fogKindPatch, fogFactorAt } from '../../src/lib/fogEdit.js'; import { HEIGHT_FOG, setHeightFog } from '../../src/lib/fogModes.js'; import { installHeightFog } from '../../src/lib/fogShader.js'; import { mergeFogPatch } from '../../src/lib/fogReach.js';