Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Changelog

## 0.2.0 — Rendering upgrade

A big step up in how exhibits look, in the live viewer, in Studio and in standalone HTML exports. No changes to the `.decoder.json` format: existing exhibits render with the new engine as they are.

### Materials

- Richer physical materials across the library: brushed and anisotropic metals, clear-coated paint and plastics, sapphire glass with a thin anti-reflective film, and wet-looking tissue.
- Iridescence uses Three.js's supported thickness range, so the effect is consistent across browsers.
- Organ tissue stays opaque by default on software WebGL, so the heart reads correctly on machines without a GPU. Material overrides in an exhibit still win.

### Lighting and the viewer

- AgX tone mapping, a studio environment for reflections, soft key-light shadows and a contact shadow fitted to each model.
- A subtle bloom pass for emissive parts.
- Section views now draw a machined cap over the cut face instead of showing hollow geometry.
- Disassembly guides are drawn as real 3D rods with seated rings, so they stay visible on high-density screens and in small thumbnails.

### Effects and geometry

- Flow, flame and particle effects have new procedural textures and follow their paths more smoothly.
- More detailed procedural geometry for several part types, and matching updates to the vector illustrations.

### Path tracing (Studio)

- Deeper light bounces for metal and glass, fewer fireflies, sharper output on high-density screens and no tile seams on the first frame. Studio now converges to 128 samples.

### Tooling

- `scripts/capture-gpu-showcase.ts` captures matched stills and a disassembly video from the standalone viewer. It checks the browser's actual WebGL renderer and refuses to save anything unless it is running on a physical GPU, so captures are never mistaken for software renders.
- The export checks now wait for playback to start rather than sampling once, which keeps them reliable on software WebGL.

### Photos

Rendered with software WebGL (SwiftShader). Hardware GPU shots are still to come.

<img src="docs/media/v0.2.0-espresso.webp" alt="The espresso machine in cutaway view, with a brass boiler, glossy black group head and see-through shell" width="100%">

<img src="docs/media/v0.2.0-engine.webp" alt="The four-stroke engine pulled apart, with 3D guide rods showing where each part seats" width="49%"> <img src="docs/media/v0.2.0-watch.webp" alt="The mechanical watch pulled apart, with gold and blue gears and guide rods back to the case" width="49%">

### Known limits

- Side-by-side comparisons so far were rendered with software WebGL (SwiftShader). A comparison on physical GPU hardware is still to come.

## 0.1.0

First public release.
Binary file added docs/media/v0.2.0-engine.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/media/v0.2.0-espresso.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/media/v0.2.0-watch.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "primitive-decoder",
"version": "0.1.0",
"version": "0.2.0",
"description": "Local-first procedural system visualisation engine",
"license": "Apache-2.0",
"repository": {
Expand Down Expand Up @@ -33,7 +33,8 @@
"files": [
"lib",
"skills",
"THIRD_PARTY_NOTICES.md"
"THIRD_PARTY_NOTICES.md",
"CHANGELOG.md"
],
"engines": {
"node": ">=22.12"
Expand Down
118 changes: 118 additions & 0 deletions scripts/capture-gpu-showcase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* Capture matched standalone exhibit views and an engine disassembly video on a physical GPU.
* Run `npm run bundle:standalone`, then `npx tsx scripts/capture-gpu-showcase.ts [output-directory]`.
* Install Playwright Chromium and FFmpeg first, or use CHROMIUM_PATH for an installed Chromium.
*/
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { chromium, type Page } from 'playwright';
import { BUILTIN_EXHIBITS } from '../src/projects/index';
import { DecoderSDK } from '../src/sdk/index';

const output = resolve(process.argv[2] ?? 'showcase-captures');
const exhibitIds = ['espresso_machine', 'mechanical_watch', 'four_stroke_engine'];
const fourStroke = 'four_stroke_engine';
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

async function loadHardwareExhibit(page: Page, file: string): Promise<string> {
await page.goto(pathToFileURL(file).href);
const gpu = await page.evaluate(() => {
const canvas = document.querySelector<HTMLCanvasElement>('#viewport canvas');
const gl = canvas?.getContext('webgl2');
if (!gl) return 'WebGL2 unavailable';
const debug = gl.getExtension('WEBGL_debug_renderer_info');
if (!debug) return 'GPU identity unavailable';
return String(gl.getParameter(debug.UNMASKED_RENDERER_WEBGL));
});
if (
!gpu.trim() ||
/SwiftShader|llvmpipe|lavapipe|softpipe|software|basic render|unavailable/i.test(gpu) ||
/^(ANGLE|WebKit WebGL|WebGL|unknown)$/i.test(gpu)
) {
throw new Error(`A physical WebGL2 GPU is required. Chromium reported ${gpu}.`);
}
if (!(await page.locator('#play').isEnabled())) {
throw new Error(await page.locator('#status').innerText());
}
return gpu;
}

async function updateSlider(page: Page, id: '#timeline' | '#explosion', value: number): Promise<void> {
await page.locator(id).evaluate((input: HTMLInputElement, next) => {
input.value = String(next);
input.dispatchEvent(new Event('input'));
}, value);
}

async function main() {
const browser = await chromium.launch({
executablePath: process.env.CHROMIUM_PATH || undefined,
args: ['--ignore-gpu-blocklist', '--enable-gpu-rasterization'],
});
const sdk = new DecoderSDK();
const tempDir = mkdtempSync(join(tmpdir(), 'decoder-gpu-shots-'));
try {
for (const id of exhibitIds) {
const project = BUILTIN_EXHIBITS.find((exhibit) => exhibit.id === id);
if (!project) throw new Error(`Missing built-in exhibit ${id}.`);
const file = join(tempDir, `${id}.html`);
writeFileSync(file, sdk.exportFormat(project, 'html'), 'utf8');
const context = await browser.newContext({
viewport: { width: 1440, height: 900 },
deviceScaleFactor: 2,
offline: true,
});
try {
const page = await context.newPage();
const gpu = await loadHardwareExhibit(page, file);
console.log(`[${id}] ${gpu}`);
mkdirSync(output, { recursive: true });
await updateSlider(page, '#timeline', project.simulation.cycleDuration * 0.35);
await wait(400);
const viewport = page.locator('#viewport');
await viewport.screenshot({ path: join(output, `${id}-assembled-gpu.png`) });
await updateSlider(page, '#explosion', 0.62);
await wait(1200);
await viewport.screenshot({ path: join(output, `${id}-exploded-gpu.png`) });
} finally {
await context.close();
}
}

const context = await browser.newContext({
viewport: { width: 1280, height: 720 },
offline: true,
recordVideo: { dir: tempDir, size: { width: 1280, height: 720 } },
});
const page = await context.newPage();
const video = page.video();
try {
await loadHardwareExhibit(page, join(tempDir, `${fourStroke}.html`));
await page.click('#play');
const steps = 90;
for (let frame = 0; frame <= steps; frame++) {
const phase = frame / steps;
const explosion = Math.min(0.78, 0.44 * (1 - Math.cos(phase * Math.PI * 2)));
await updateSlider(page, '#explosion', explosion);
await wait(55);
}
await wait(700);
} finally {
await context.close();
}
if (!video) throw new Error('Browser video recording was unavailable.');
await video.saveAs(join(output, `${fourStroke}-disassembly-gpu.webm`));
console.log(`Saved GPU captures in ${output}`);
} finally {
await browser.close();
sdk.dispose();
rmSync(tempDir, { recursive: true, force: true });
}
}

main().catch((error) => {
console.error(error instanceof Error ? error.message : error);
process.exitCode = 1;
});
10 changes: 8 additions & 2 deletions scripts/verify-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ async function verify(browser: Browser, file: string, webgl: boolean): Promise<R

const t0 = await time();
await page.click('#play');
await wait(1500);
checks.playAdvances = (await page.locator('#play').innerText()) === 'Pause' && (await time()) > t0;
// Software WebGL (SwiftShader) can take a few seconds to draw the first
// frames of the heavier exhibits, so poll rather than sample once.
let advanced = false;
for (let waited = 0; waited < 5000 && !advanced; waited += 250) {
await wait(250);
advanced = (await time()) > t0;
}
checks.playAdvances = (await page.locator('#play').innerText()) === 'Pause' && advanced;
await page.click('#play');
const pausedAt = await time();
const pausedOutputs = await outputs();
Expand Down
Loading
Loading