← Commit history
export-wiki guide: rewrite for the current publish path (README.html, not an auto-rendered asset), add the three tscircuit-specific sandbox traps, the diagnosis + measurement traps, and the GLB helper scripts
6 files changed
+601−406
export-wiki.md+211−202@@ -1,241 +1,250 @@-# adom-tsci/export-wiki — publishing a tscircuit molecule to the Adom Wiki+# adom-tsci/export-wiki — publishing a tscircuit board to the Adom Wiki **Read this before running `adom-tsci export-wiki` on any project.**-The CLI is deliberately opinionated: it ships the interactive 3D-viewer, the source bundle, the plan.md, AND a comprehensive body-markdown to the wiki page in one shot. Skipping any of those pieces-makes the page useless to a future viewer (human or AI) — the goal-is "another agent can pick up exactly where this one left off" with-nothing missing. -## What the CLI does, in order+> **Read `wiki-readme-html` from the [Adom Wiki Skill Pack](https://wiki.adom.inc/adom/adom-wiki-skillpack)+> first.** It owns the generic readme.html contract: the sandbox shims, the+> size budget, the `readme-height` protocol, the shadowing rule, theming. This+> guide covers only what is specific to shipping a **tscircuit board** through+> that contract, and defers to it everywhere else.++## Current state of the tooling (2026-08-20)++**`adom-tsci export-wiki` cannot upload.** It shells out to+`adom-wiki asset upload --asset-type tsci-viewer`, and `adom-wiki` has no+`asset` pillar any more (file-bearing verbs are now `repo push`,+`release upload`, `page attach`). Use `--no-upload` for the staging half —+which is still correct — and push the files yourself.++The older text of this guide described the wiki auto-rendering an iframe+section from a `tsci-viewer` asset. That is not what happens. Current pages+push `viewer/` as ordinary repo files and embed it from a hand-written+`README.html`, which the wiki renders in preference to `README.md`.++## What a board page ships ```-adom-tsci export-wiki [<project>] --slug <wiki-slug> \- --page-type molecules \- --label "Live 3D viewer" \- [--rebuild] [--texture-resolution N] [--no-upload]+README.html the page body; embeds the viewer (see wiki-readme-html)+README.md plain-text source of record+board.glb Z-UP, for the wiki's own native 3D viewer+pcb.svg schematic.svg picked up by the native Symbol & Footprint section+viewer/ the self-contained adom-tsci viewer bundle+plan.md the brief and every decision made against it+<slug>-source.tar.gz full project source+docs/hero.png 16:10, 1920x1200 ``` -1. **Confirms `dist/lib/index/circuit.json` exists.** Skip-rebuild is- the default — `bunx tsci build` can take 10 minutes on dense- boards. Pass `--rebuild` to force.-- **Fallback-dist search** (1.3.91+): if the in-place dist is missing,- the CLI looks for an existing dist at known parallel locations- before erroring out. Order: `~/project/adom-tsci-projects/<basename>/dist`,- `~/project/adom-tsci/examples/<basename>/dist`,- `~/project/tscircuit-projects/<basename>/dist`. Picks the freshest- by `circuit.json` mtime. Many canonical molecules live in two- places (the example-library copy and the local scratch-build- copy); only one has a fresh dist at any given moment, and there's- no reason to spend 10 minutes rebuilding when the other copy is- already there.-- **The reflex when a build seems missing:** `ls- ~/project/adom-tsci-projects/<name>/dist/lib/index/circuit.json`- FIRST. Only rebuild if neither copy has a fresh dist. The CLI does- this automatically now, but the same rule applies to any AI helper- debugging "why doesn't this project have a dist?" — search before- rebuilding.-2. **Resolves the GLB.** Default = `dist/lib/index/3d.glb` (1024-px- texture). Pass `--texture-resolution N` to rebake at higher res- (4096 typical for 100–200 mm boards; first bake ~75 s, cache hit- ~190 ms).-3. **Stages the viewer bundle** at `/tmp/adom-tsci-export-<slug>/`:- - `index.html` — `shell.html` rewritten for static hosting (fetch- monkeypatch, walkthrough autoplay, all `glb`-style URLs- remapped to relative paths).- - `js/adom-3d-viewer.min.js`, `js/tscircuit-alphabet.js`,- `js/environmentSpecular.env`, `adom.css`, `favicon.svg` —- embedded into the binary, copied out at staging time.- - `3d.glb`, `circuit.json`, `walkthrough.json`, `pcb.svg`,- `schematic.svg` — the project's build artifacts.-4. **Tarballs the viewer bundle** as- `<slug>-tsci-viewer.tar.gz`. Uploads via `adom-wiki asset upload- --asset-type tsci-viewer`. The wiki extracts to- `/static/<page-type-plural>/<slug>/tsci-viewer/<label-slug>/` and- auto-renders an iframe section on the page.-5. **Builds a separate source bundle** at- `/tmp/<slug>-source.tar.gz` containing every file an agent would- need to recreate the molecule:- - `lib/` (recursive)- - `package.json`- - `tscircuit.config.json`- - `tsconfig.json`- - `walkthrough.json`- - `.npmrc`- - **`plan.md`** (or `PLAN.md`) — the design brief. Required by- convention; see "plan.md" below.- - `README.md` (if present)- Excluded: `dist/` (build output) and `node_modules/` (deps).- Uploaded as a `file` asset.-6. **Uploads `plan.md` standalone** as a separate `file` asset so the- wiki can render a one-click link to it without untar.--Failures on steps 5 / 6 are non-fatal — the viewer publish in step 4-is the load-bearing one and lands first. If a transient wiki failure-blocks the source-bundle upload, the CLI emits a hint with the retry-command.--## Walkthrough autoplay--The static export of `shell.html` registers a small bootstrapper that-**fires `walkthroughStart()` ~2 s after the page loads**. This is on-by default for the wiki context — the walkthrough is the canonical-"tour the board" experience for an external viewer who isn't going-to know to click anything. It can be opted out with-`?autoplay=off` on the iframe URL if a future wiki template wants to-defer firing it.--The walkthrough is loaded from `walkthrough.json` in the bundle. If-the project has no `walkthrough.json`, the autoplay no-ops gracefully-(no walkthroughStart call until the array is populated). Generate-one with:+## The three tscircuit-specific traps++Everything else in the sandbox is `wiki-readme-html`'s territory.++### 1. `board.glb` must be Z-up; `viewer/3d.glb` must not++glTF is Y-up by spec and that is what tscircuit emits — `Box0` spans about+±0.7 in **Y**, which is the board thickness. Two consumers, two conventions:++| file | consumer | needs |+|---|---|---|+| `viewer/3d.glb` | the adom-tsci viewer | **Y-up** — it rotates at runtime (`zUp: true` + `applyGlbZUpTransform`) |+| `board.glb` | the wiki's native 3D Model viewer | **Z-up** — it consumes the raw file |++Publish an unrotated `board.glb` and the wiki stands your board on edge like a+wall, which reads as a modelling error rather than a convention mismatch.+Rotate both and the tsci viewer double-rotates. The wiki viewer also looks+from −Y, so a board whose connector edge is at +X faces away; composing 180°+about Z is usually wanted. ```bash-adom-tsci walkthrough-gen # auto-generate from circuit.json+node scripts/glb-make-zup.mjs <pristine.glb> board.glb 180 ``` -…or hand-edit `walkthrough.json` directly. The `_meta` block has a-`do_not_edit_by_hand` field — set it to a plausible-looking string-(e.g. "Hand-edited intentionally") to keep `walkthrough-gen` from-overwriting your edits.+Verify by rotating probe vectors, not by squinting: `+Y → +Z`, and the+bounding box should come out with its thin axis on Z. -## plan.md — the design brief+### 2. The viewer bundle is 13 MB, and `render/` 413s over ~4 MB -**Every molecule publish should include `plan.md` at the project-root.** plan.md is the original prompt the project was authored from,-plus the refinements that came out during build. It carries forward-to the wiki so a future agent skimming the page can answer:+`wiki-readme-html` gives you the document-level size budget. This is the+per-file one: any single file served through+`https://wiki.adom.inc/<owner>/<slug>/render/<path>` over roughly 4 MB returns+`{"error":"File too large to render"}`. A `<script src>` cannot surface that;+it just fails. -- What was the user actually asking for?-- What design decisions were made and why?-- What's intentionally out of scope?+Ship `adom-3d-viewer.min.js` as 3.5 MB parts and reassemble client-side: -If the project doesn't have a plan.md when you run `export-wiki`,-**create one before publishing**. Reconstruct it from the original-prompt + the design conversation; check it into the project root.-Skeleton:+```bash+split -b 3500000 -d js/adom-3d-viewer.min.js js/adom-3d-viewer.min.js.part+cat js/adom-3d-viewer.min.js.part* | cmp - js/adom-3d-viewer.min.js # always verify+``` -```markdown-# Plan — <Project Name>+Two rules in the loader: -## Original prompt+- **Reassemble as BYTES, never text.** A multi-byte character can straddle a+ split boundary; decoding per part corrupts it. Concatenate `Uint8Array`s,+ then `new TextDecoder('utf-8').decode(all)` once.+- **Inject with `script.textContent`, not a blob URL.** `script-src` allows+ `'unsafe-inline'` but not `blob:`. -> <copy the user's first ask verbatim>+### 3. GLB textures must be `data:` URIs, and externalising them does not work -## Refinements during the build+`wiki-readme-html` already says `blob:` images are blocked. The tscircuit-+specific sting: Babylon's glTF loader blobs every bufferView-backed image, and+this failure **throws** rather than degrading, killing the entire model load: -- <each meaningful refinement, one bullet per>+```+Unable to load from ./3d.glb: /textures/0: … blob:null/… - Fallback texture was used+``` -## Hardware decisions+The obvious fix — write the images out as sibling `.png` files and point the+GLB at them — **does not work either**, because Babylon still blobs a relative+URI in a null-origin document. `data:` URIs are the only accepted form. -- <each component choice with rationale>+```bash+node scripts/glb-datauri-textures.mjs <in.glb> viewer/3d.glb+```++Costs about 8% file size, and the script prunes the vacated bufferViews while+remapping every accessor.++## One more, if your page has both viewers++A hardware page renders the wiki's own native 3D viewer from `board.glb` above+your README. If your README's viewer iframe starts pulling 15 MB at the same+time, the native viewer's ~2.8 MB fetch is starved and it gives up with+*"Failed to load model — taking too long"*. The file is fine. Wait for `load`+plus ~2.5 s before arming the `IntersectionObserver` that loads your iframe. -## Out of scope (deliberate)+Prefer auto-load-on-scroll over a click-to-load poster: a poster cannot be+driven by a synthetic click from outside the sandboxed frame, so it is+untestable in a ralph loop, and a still with a button on it reads as broken to+anyone who does not realise it is a button. -- <what was explicitly NOT built and why>+## Diagnosing a blank 3D tab -## Build → publish workflow+If the viewer is blank, the storage shim from `wiki-readme-html` is missing or+ran late. Confirm that before chasing anything else: +```js+const s = viewer.getScene(), e = viewer.getEngine()+;({ lights: s.lights.map(l => l.name), env: !!s.environmentTexture,+ loops: e.activeRenderLoops.length, cam: String(viewer.getCamera()) })+// healthy: ["light","spotLight"], true, 1, "Name: adomCamera, type: ArcRotateCamera"+// broken: [], false, 0, "null" ``` -(See `adom-tsci-projects/Brianna-LED-Nameplate/plan.md` for a full-example.)+Two things about the broken state that waste hours if you do not know them:++- **`viewer.getCamera()` returning `null` silently kills the walkthrough.**+ `walkthroughFlyTo` opens with `if (!scene || !cam) return;`, so every camera+ fly bails on line 4 while the step counter and narration keep advancing. It+ presents as "the walkthrough animates nothing", which is a different bug+ than the one you actually have.+- **A `typeof window !== "undefined"` guard is not enough.** `window` exists in+ a sandboxed iframe; the *origin* is null, so the property read itself throws.+ The shipped bundle still has one unguarded read+ (`localStorage.getItem("adom_camera_mode")`) behind exactly that wrong guard.+ Tracked in [`adom/wiki#60`](https://wiki.adom.inc/adom/wiki/issues/60).++## Measurement traps++Both of these produce confident wrong conclusions about a viewer.++- **`engine.getFps()` lies.** It reports 60 while `scene.render()` has never+ been called once. Count real frames instead:+ ```js+ let n = 0; scene.onAfterRenderObservable.add(() => n++)+ await new Promise(r => setTimeout(r, 1200)) // n === 0 -> nothing is drawing+ ```+- **An occluded window has rAF at zero.** `setTimeout` keeps running, so a+ walkthrough advances its steps and narration while the camera sits perfectly+ still — indistinguishable from a broken tween. Check `document.hidden`+ before believing any animation measurement, and either foreground the window+ (`pup_raise_os_window`) or force frames with+ `for (let i = 0; i < 90; i++) scene.render()`.++## Publish sequence -The CLI uploads `plan.md` standalone (one-click link on the page)-AND inside the source bundle (preserved alongside the rest of the-project source).+```bash+bunx tsci build lib/index.tsx --glbs --svgs --3d-png --pcb-png+adom-tsci lint++adom-tsci export-wiki . --slug <slug> --page-type molecules --no-upload+mkdir -p wiki-page/viewer && cp -r /tmp/adom-tsci-export-<slug>/* wiki-page/viewer/++node scripts/glb-datauri-textures.mjs <rebake.glb> wiki-page/viewer/3d.glb+node scripts/glb-make-zup.mjs <rebake.glb> wiki-page/board.glb 180+split -b 3500000 -d wiki-page/viewer/js/adom-3d-viewer.min.js \+ wiki-page/viewer/js/adom-3d-viewer.min.js.part+# + the storage shim and the part-loader patch in viewer/index.html+# + README.html per wiki-readme-html++adom-wiki page create <slug> --type hardware --kind molecule --org adom \+ --title "..." --brief "..." --because "..." \+ --headline "..." --subhead "..." --screenshot docs/hero.png --no-chrome \+ --source tscircuit --version 1.0.0++cd wiki-page+adom-wiki repo push <owner>/<slug> --message "..." \+ $(find . -type f | sed 's|^\./||' | sed 's/^/--files /' | tr '\n' ' ')+``` -## The body markdown — comprehensive, AI-readable+`repo push` requires explicit, repeatable `--files`; there is no+"push everything changed" mode. -The wiki page's `content` field — the markdown body — must give a-downstream agent everything they'd need to continue work without-reading external docs. **The CLI does not write the body for you;-you produce it via `adom-wiki page edit --field content` (or as part-of `page publish`).** Required sections:+## Verify on a cold profile, from the wiki -| Section | What it captures |-|---|---|-| **Brief** (above the fold) | One-line elevator pitch. Same as the page brief. |-| **Live 3D viewer** | Pointer to the iframe, mention `?autoplay=off` opt-out. |-| **How it works** | The circuit story: what each block does, key constants, font/layout source. |-| **Hardware summary** table | Block / Part / JLCPCB / Notes for every refdes family. |-| **Mechanical** | Board dims, USB-C edge, workcell-pin info, silkscreen choices. |-| **Source layout** | The project's directory tree with one-line per file. |-| **Build commands** | The exact bash to clone → install → build → preview → publish. |-| **Color options / variants** (if applicable) | What's parameterised and how to retune. |-| **Known issues / lessons learned** | Things that bit during the build, in case they come up again. |-| **Build provenance** | Author, tooling versions, walkthrough authorship. |-| **Files attached** | Two sub-lists: **Source — recreate the molecule** (plan.md, source bundle) and **Build outputs** (GLB, SVGs, demo video). |--**Rule:** if a future agent has to ask the human user any factual-question about the project that they could have answered by reading-this page, the body is incomplete. Treat it as a writeup, not a-README stub.--## Hero image--`adom-wiki page publish` requires `--hero-image <path>` (the wiki-enforces it for non-app pages). The hero image is **the thumbnail**-that shows up on the molecule index page — heavy interactive viewers-can't be embedded in index lists, so a static iso render is the-right artifact for that role.--For an adom-tsci-published molecule:--- The **index/listing page** uses the `--hero-image` PNG as the- thumbnail.-- The **full molecule page** has the interactive `tsci-viewer`- iframe as its hero (rendered automatically by the wiki when a- `tsci_viewer` asset is present).--Take the hero image with `adom-cli hydrogen screenshot panel-hiding the components HUD. ~1500 px wide is plenty.--## Verifying the publish--After `export-wiki` returns `OK: published …`, open the molecule URL-in a browser:+Not your dev server, and not a browser that may have cached a working bundle. -```-https://wiki-ufypy5dpx93o.adom.cloud/molecules/<slug>+```bash+adom-bridge --ai-thread "<thread>" pup_open_window \+ '{"sessionId":"verify","profile":"verify","freshProfile":true,+ "url":"https://wiki.adom.inc/<owner>/<slug>/render/viewer/index.html"}' ``` -Confirm visually:+- [ ] `lights` is `["light","spotLight"]`, not `[]`, and not a fallback you added+- [ ] `env: true` — the IBL loaded, so it looks like the local webview+- [ ] `activeRenderLoops.length === 1` (2 means something raced the bundle)+- [ ] walkthrough camera radius CHANGES between steps+- [ ] PCB / Schematic / Parts tabs render+- [ ] the wiki's native 3D viewer shows the board flat and readable+- [ ] every `render/` asset returns 200 to an unauthenticated `curl`+- [ ] no `localhost` / `/proxy/` / `.adom.cloud` in README.html — a published+ page must outlive the container that built it++## Known limitations, do not chase these++- **`MP1`–`MP4` stack at the schematic origin and `lint` fails on it.**+ `<Molecule>` renders `jsx(MachinePin, {type, name, pcbX, pcbY})`, and+ `MachinePinOrContact` in `@tsci/adom-inc.library` destructures only+ `{portHints, pcbX, pcbY, name}`, dropping schematic coordinates. No caller+ can fix it, including a hand-rolled `<board>`.+- **`schX`/`schY` is all-or-nothing.** Placing *some* parts disables+ auto-layout for the rest and stacks them at the origin.+- **`GET viewer/runframe/` 404s** on every load — the "tsci live" tab only+ exists against a dev server.+- **`--texture-resolution N` silently falls back** to the 1024 GLB with a hint+ about `rebake-glb.mjs`. The 4096 rebakes are already in+ `~/.cache/adom-tsci/rebakes/`; the keys are content hashes, so match one to+ your board with `scripts/glb-inspect.mjs`.++## Helper scripts++These live in the adom-tsci page repo under `scripts/`. `adom-tsci install`+deploys `SKILL.md` and the guides but **not** these yet, so fetch them: -1. **Walkthrough auto-plays** within ~2 s of page load. Step text- appears at the bottom of the iframe with Back/Next controls.-2. **3D scene is rendered** — the board (not the loading screen) is- visible.-3. **Source bundle download works** — click the `*-source.tar.gz`- link in the body, untar, confirm `lib/index.tsx` and `plan.md`- are present.-4. **plan.md link works** — opens directly without untar.+```bash+for f in glb-datauri-textures glb-make-zup glb-inspect; do+ curl -fsSL "https://wiki.adom.inc/adom/adom-tsci/render/scripts/$f.mjs" -o "scripts/$f.mjs"+done+``` -If the walkthrough doesn't fire, check the iframe URL has no-`?autoplay=off`, and that `walkthrough.json` was non-empty in the-bundle (`tar -tzf <bundle>.tar.gz | grep walkthrough`). -## Troubleshooting+| script | what it does |+|---|---|+| `glb-datauri-textures.mjs` | embedded images → `data:` URIs, prunes vacated bufferViews, remaps accessors |+| `glb-make-zup.mjs` | wraps scene roots in a `ZUpRoot` (+90° about X), optionally composed with a Z spin |+| `glb-inspect.mjs` | node/LED counts, board extents, J1 placement — for matching a cache rebake to your board | -| Symptom | Cause | Fix |-|---|---|---|-| `dist/lib/index/circuit.json not found` | No build artifacts | Pass `--rebuild` or run `bunx tsci build` first |-| `--texture-resolution N` warns "no rebake-glb.mjs in cache" | First-time use without prior `adom-tsci start` | Run `adom-tsci start .` once to populate the cache, then re-export |-| `bundle is over 95 MB` warning | Big GLB (very high texture res) or many extra files | Drop `--texture-resolution` to 4096 or 2048 |-| `adom-wiki upload failed: page-type mismatch` | Slug exists at a different page-type | Either pass the matching `--page-type`, OR delete the existing page first (`adom-wiki page delete <type>/<slug>`) |-| Source-bundle upload fails but viewer publish succeeds | Transient wiki error | Re-run `adom-wiki asset upload <page>/<slug> --asset-type file --file /tmp/<slug>-source.tar.gz` manually — the CLI prints this hint |-| Walkthrough doesn't auto-play on the wiki page | walkthrough.json missing or empty | Run `adom-tsci walkthrough-gen` in the project, hand-edit if needed, re-export |--## See also--- `adom-tsci/guides/demo-recording.md` — making a 30-second narrated- demo video to attach to the page (separate workflow; the live- viewer is now the primary artifact, demo video is supplementary).-- `adom-tsci/guides/adom-usbc.md` — USB-C placement rules for the- molecule before you publish.-- `adom-wiki` skill — the underlying CLI for asset uploads and page- edits.+## Worked example++[`adom/evan-led-nameplate`](https://wiki.adom.inc/adom/evan-led-nameplate)+exercises every item on this page.
guides/export-wiki.md+211−202@@ -1,241 +1,250 @@-# adom-tsci/export-wiki — publishing a tscircuit molecule to the Adom Wiki+# adom-tsci/export-wiki — publishing a tscircuit board to the Adom Wiki **Read this before running `adom-tsci export-wiki` on any project.**-The CLI is deliberately opinionated: it ships the interactive 3D-viewer, the source bundle, the plan.md, AND a comprehensive body-markdown to the wiki page in one shot. Skipping any of those pieces-makes the page useless to a future viewer (human or AI) — the goal-is "another agent can pick up exactly where this one left off" with-nothing missing. -## What the CLI does, in order+> **Read `wiki-readme-html` from the [Adom Wiki Skill Pack](https://wiki.adom.inc/adom/adom-wiki-skillpack)+> first.** It owns the generic readme.html contract: the sandbox shims, the+> size budget, the `readme-height` protocol, the shadowing rule, theming. This+> guide covers only what is specific to shipping a **tscircuit board** through+> that contract, and defers to it everywhere else.++## Current state of the tooling (2026-08-20)++**`adom-tsci export-wiki` cannot upload.** It shells out to+`adom-wiki asset upload --asset-type tsci-viewer`, and `adom-wiki` has no+`asset` pillar any more (file-bearing verbs are now `repo push`,+`release upload`, `page attach`). Use `--no-upload` for the staging half —+which is still correct — and push the files yourself.++The older text of this guide described the wiki auto-rendering an iframe+section from a `tsci-viewer` asset. That is not what happens. Current pages+push `viewer/` as ordinary repo files and embed it from a hand-written+`README.html`, which the wiki renders in preference to `README.md`.++## What a board page ships ```-adom-tsci export-wiki [<project>] --slug <wiki-slug> \- --page-type molecules \- --label "Live 3D viewer" \- [--rebuild] [--texture-resolution N] [--no-upload]+README.html the page body; embeds the viewer (see wiki-readme-html)+README.md plain-text source of record+board.glb Z-UP, for the wiki's own native 3D viewer+pcb.svg schematic.svg picked up by the native Symbol & Footprint section+viewer/ the self-contained adom-tsci viewer bundle+plan.md the brief and every decision made against it+<slug>-source.tar.gz full project source+docs/hero.png 16:10, 1920x1200 ``` -1. **Confirms `dist/lib/index/circuit.json` exists.** Skip-rebuild is- the default — `bunx tsci build` can take 10 minutes on dense- boards. Pass `--rebuild` to force.-- **Fallback-dist search** (1.3.91+): if the in-place dist is missing,- the CLI looks for an existing dist at known parallel locations- before erroring out. Order: `~/project/adom-tsci-projects/<basename>/dist`,- `~/project/adom-tsci/examples/<basename>/dist`,- `~/project/tscircuit-projects/<basename>/dist`. Picks the freshest- by `circuit.json` mtime. Many canonical molecules live in two- places (the example-library copy and the local scratch-build- copy); only one has a fresh dist at any given moment, and there's- no reason to spend 10 minutes rebuilding when the other copy is- already there.-- **The reflex when a build seems missing:** `ls- ~/project/adom-tsci-projects/<name>/dist/lib/index/circuit.json`- FIRST. Only rebuild if neither copy has a fresh dist. The CLI does- this automatically now, but the same rule applies to any AI helper- debugging "why doesn't this project have a dist?" — search before- rebuilding.-2. **Resolves the GLB.** Default = `dist/lib/index/3d.glb` (1024-px- texture). Pass `--texture-resolution N` to rebake at higher res- (4096 typical for 100–200 mm boards; first bake ~75 s, cache hit- ~190 ms).-3. **Stages the viewer bundle** at `/tmp/adom-tsci-export-<slug>/`:- - `index.html` — `shell.html` rewritten for static hosting (fetch- monkeypatch, walkthrough autoplay, all `glb`-style URLs- remapped to relative paths).- - `js/adom-3d-viewer.min.js`, `js/tscircuit-alphabet.js`,- `js/environmentSpecular.env`, `adom.css`, `favicon.svg` —- embedded into the binary, copied out at staging time.- - `3d.glb`, `circuit.json`, `walkthrough.json`, `pcb.svg`,- `schematic.svg` — the project's build artifacts.-4. **Tarballs the viewer bundle** as- `<slug>-tsci-viewer.tar.gz`. Uploads via `adom-wiki asset upload- --asset-type tsci-viewer`. The wiki extracts to- `/static/<page-type-plural>/<slug>/tsci-viewer/<label-slug>/` and- auto-renders an iframe section on the page.-5. **Builds a separate source bundle** at- `/tmp/<slug>-source.tar.gz` containing every file an agent would- need to recreate the molecule:- - `lib/` (recursive)- - `package.json`- - `tscircuit.config.json`- - `tsconfig.json`- - `walkthrough.json`- - `.npmrc`- - **`plan.md`** (or `PLAN.md`) — the design brief. Required by- convention; see "plan.md" below.- - `README.md` (if present)- Excluded: `dist/` (build output) and `node_modules/` (deps).- Uploaded as a `file` asset.-6. **Uploads `plan.md` standalone** as a separate `file` asset so the- wiki can render a one-click link to it without untar.--Failures on steps 5 / 6 are non-fatal — the viewer publish in step 4-is the load-bearing one and lands first. If a transient wiki failure-blocks the source-bundle upload, the CLI emits a hint with the retry-command.--## Walkthrough autoplay--The static export of `shell.html` registers a small bootstrapper that-**fires `walkthroughStart()` ~2 s after the page loads**. This is on-by default for the wiki context — the walkthrough is the canonical-"tour the board" experience for an external viewer who isn't going-to know to click anything. It can be opted out with-`?autoplay=off` on the iframe URL if a future wiki template wants to-defer firing it.--The walkthrough is loaded from `walkthrough.json` in the bundle. If-the project has no `walkthrough.json`, the autoplay no-ops gracefully-(no walkthroughStart call until the array is populated). Generate-one with:+## The three tscircuit-specific traps++Everything else in the sandbox is `wiki-readme-html`'s territory.++### 1. `board.glb` must be Z-up; `viewer/3d.glb` must not++glTF is Y-up by spec and that is what tscircuit emits — `Box0` spans about+±0.7 in **Y**, which is the board thickness. Two consumers, two conventions:++| file | consumer | needs |+|---|---|---|+| `viewer/3d.glb` | the adom-tsci viewer | **Y-up** — it rotates at runtime (`zUp: true` + `applyGlbZUpTransform`) |+| `board.glb` | the wiki's native 3D Model viewer | **Z-up** — it consumes the raw file |++Publish an unrotated `board.glb` and the wiki stands your board on edge like a+wall, which reads as a modelling error rather than a convention mismatch.+Rotate both and the tsci viewer double-rotates. The wiki viewer also looks+from −Y, so a board whose connector edge is at +X faces away; composing 180°+about Z is usually wanted. ```bash-adom-tsci walkthrough-gen # auto-generate from circuit.json+node scripts/glb-make-zup.mjs <pristine.glb> board.glb 180 ``` -…or hand-edit `walkthrough.json` directly. The `_meta` block has a-`do_not_edit_by_hand` field — set it to a plausible-looking string-(e.g. "Hand-edited intentionally") to keep `walkthrough-gen` from-overwriting your edits.+Verify by rotating probe vectors, not by squinting: `+Y → +Z`, and the+bounding box should come out with its thin axis on Z. -## plan.md — the design brief+### 2. The viewer bundle is 13 MB, and `render/` 413s over ~4 MB -**Every molecule publish should include `plan.md` at the project-root.** plan.md is the original prompt the project was authored from,-plus the refinements that came out during build. It carries forward-to the wiki so a future agent skimming the page can answer:+`wiki-readme-html` gives you the document-level size budget. This is the+per-file one: any single file served through+`https://wiki.adom.inc/<owner>/<slug>/render/<path>` over roughly 4 MB returns+`{"error":"File too large to render"}`. A `<script src>` cannot surface that;+it just fails. -- What was the user actually asking for?-- What design decisions were made and why?-- What's intentionally out of scope?+Ship `adom-3d-viewer.min.js` as 3.5 MB parts and reassemble client-side: -If the project doesn't have a plan.md when you run `export-wiki`,-**create one before publishing**. Reconstruct it from the original-prompt + the design conversation; check it into the project root.-Skeleton:+```bash+split -b 3500000 -d js/adom-3d-viewer.min.js js/adom-3d-viewer.min.js.part+cat js/adom-3d-viewer.min.js.part* | cmp - js/adom-3d-viewer.min.js # always verify+``` -```markdown-# Plan — <Project Name>+Two rules in the loader: -## Original prompt+- **Reassemble as BYTES, never text.** A multi-byte character can straddle a+ split boundary; decoding per part corrupts it. Concatenate `Uint8Array`s,+ then `new TextDecoder('utf-8').decode(all)` once.+- **Inject with `script.textContent`, not a blob URL.** `script-src` allows+ `'unsafe-inline'` but not `blob:`. -> <copy the user's first ask verbatim>+### 3. GLB textures must be `data:` URIs, and externalising them does not work -## Refinements during the build+`wiki-readme-html` already says `blob:` images are blocked. The tscircuit-+specific sting: Babylon's glTF loader blobs every bufferView-backed image, and+this failure **throws** rather than degrading, killing the entire model load: -- <each meaningful refinement, one bullet per>+```+Unable to load from ./3d.glb: /textures/0: … blob:null/… - Fallback texture was used+``` -## Hardware decisions+The obvious fix — write the images out as sibling `.png` files and point the+GLB at them — **does not work either**, because Babylon still blobs a relative+URI in a null-origin document. `data:` URIs are the only accepted form. -- <each component choice with rationale>+```bash+node scripts/glb-datauri-textures.mjs <in.glb> viewer/3d.glb+```++Costs about 8% file size, and the script prunes the vacated bufferViews while+remapping every accessor.++## One more, if your page has both viewers++A hardware page renders the wiki's own native 3D viewer from `board.glb` above+your README. If your README's viewer iframe starts pulling 15 MB at the same+time, the native viewer's ~2.8 MB fetch is starved and it gives up with+*"Failed to load model — taking too long"*. The file is fine. Wait for `load`+plus ~2.5 s before arming the `IntersectionObserver` that loads your iframe. -## Out of scope (deliberate)+Prefer auto-load-on-scroll over a click-to-load poster: a poster cannot be+driven by a synthetic click from outside the sandboxed frame, so it is+untestable in a ralph loop, and a still with a button on it reads as broken to+anyone who does not realise it is a button. -- <what was explicitly NOT built and why>+## Diagnosing a blank 3D tab -## Build → publish workflow+If the viewer is blank, the storage shim from `wiki-readme-html` is missing or+ran late. Confirm that before chasing anything else: +```js+const s = viewer.getScene(), e = viewer.getEngine()+;({ lights: s.lights.map(l => l.name), env: !!s.environmentTexture,+ loops: e.activeRenderLoops.length, cam: String(viewer.getCamera()) })+// healthy: ["light","spotLight"], true, 1, "Name: adomCamera, type: ArcRotateCamera"+// broken: [], false, 0, "null" ``` -(See `adom-tsci-projects/Brianna-LED-Nameplate/plan.md` for a full-example.)+Two things about the broken state that waste hours if you do not know them:++- **`viewer.getCamera()` returning `null` silently kills the walkthrough.**+ `walkthroughFlyTo` opens with `if (!scene || !cam) return;`, so every camera+ fly bails on line 4 while the step counter and narration keep advancing. It+ presents as "the walkthrough animates nothing", which is a different bug+ than the one you actually have.+- **A `typeof window !== "undefined"` guard is not enough.** `window` exists in+ a sandboxed iframe; the *origin* is null, so the property read itself throws.+ The shipped bundle still has one unguarded read+ (`localStorage.getItem("adom_camera_mode")`) behind exactly that wrong guard.+ Tracked in [`adom/wiki#60`](https://wiki.adom.inc/adom/wiki/issues/60).++## Measurement traps++Both of these produce confident wrong conclusions about a viewer.++- **`engine.getFps()` lies.** It reports 60 while `scene.render()` has never+ been called once. Count real frames instead:+ ```js+ let n = 0; scene.onAfterRenderObservable.add(() => n++)+ await new Promise(r => setTimeout(r, 1200)) // n === 0 -> nothing is drawing+ ```+- **An occluded window has rAF at zero.** `setTimeout` keeps running, so a+ walkthrough advances its steps and narration while the camera sits perfectly+ still — indistinguishable from a broken tween. Check `document.hidden`+ before believing any animation measurement, and either foreground the window+ (`pup_raise_os_window`) or force frames with+ `for (let i = 0; i < 90; i++) scene.render()`.++## Publish sequence -The CLI uploads `plan.md` standalone (one-click link on the page)-AND inside the source bundle (preserved alongside the rest of the-project source).+```bash+bunx tsci build lib/index.tsx --glbs --svgs --3d-png --pcb-png+adom-tsci lint++adom-tsci export-wiki . --slug <slug> --page-type molecules --no-upload+mkdir -p wiki-page/viewer && cp -r /tmp/adom-tsci-export-<slug>/* wiki-page/viewer/++node scripts/glb-datauri-textures.mjs <rebake.glb> wiki-page/viewer/3d.glb+node scripts/glb-make-zup.mjs <rebake.glb> wiki-page/board.glb 180+split -b 3500000 -d wiki-page/viewer/js/adom-3d-viewer.min.js \+ wiki-page/viewer/js/adom-3d-viewer.min.js.part+# + the storage shim and the part-loader patch in viewer/index.html+# + README.html per wiki-readme-html++adom-wiki page create <slug> --type hardware --kind molecule --org adom \+ --title "..." --brief "..." --because "..." \+ --headline "..." --subhead "..." --screenshot docs/hero.png --no-chrome \+ --source tscircuit --version 1.0.0++cd wiki-page+adom-wiki repo push <owner>/<slug> --message "..." \+ $(find . -type f | sed 's|^\./||' | sed 's/^/--files /' | tr '\n' ' ')+``` -## The body markdown — comprehensive, AI-readable+`repo push` requires explicit, repeatable `--files`; there is no+"push everything changed" mode. -The wiki page's `content` field — the markdown body — must give a-downstream agent everything they'd need to continue work without-reading external docs. **The CLI does not write the body for you;-you produce it via `adom-wiki page edit --field content` (or as part-of `page publish`).** Required sections:+## Verify on a cold profile, from the wiki -| Section | What it captures |-|---|---|-| **Brief** (above the fold) | One-line elevator pitch. Same as the page brief. |-| **Live 3D viewer** | Pointer to the iframe, mention `?autoplay=off` opt-out. |-| **How it works** | The circuit story: what each block does, key constants, font/layout source. |-| **Hardware summary** table | Block / Part / JLCPCB / Notes for every refdes family. |-| **Mechanical** | Board dims, USB-C edge, workcell-pin info, silkscreen choices. |-| **Source layout** | The project's directory tree with one-line per file. |-| **Build commands** | The exact bash to clone → install → build → preview → publish. |-| **Color options / variants** (if applicable) | What's parameterised and how to retune. |-| **Known issues / lessons learned** | Things that bit during the build, in case they come up again. |-| **Build provenance** | Author, tooling versions, walkthrough authorship. |-| **Files attached** | Two sub-lists: **Source — recreate the molecule** (plan.md, source bundle) and **Build outputs** (GLB, SVGs, demo video). |--**Rule:** if a future agent has to ask the human user any factual-question about the project that they could have answered by reading-this page, the body is incomplete. Treat it as a writeup, not a-README stub.--## Hero image--`adom-wiki page publish` requires `--hero-image <path>` (the wiki-enforces it for non-app pages). The hero image is **the thumbnail**-that shows up on the molecule index page — heavy interactive viewers-can't be embedded in index lists, so a static iso render is the-right artifact for that role.--For an adom-tsci-published molecule:--- The **index/listing page** uses the `--hero-image` PNG as the- thumbnail.-- The **full molecule page** has the interactive `tsci-viewer`- iframe as its hero (rendered automatically by the wiki when a- `tsci_viewer` asset is present).--Take the hero image with `adom-cli hydrogen screenshot panel-hiding the components HUD. ~1500 px wide is plenty.--## Verifying the publish--After `export-wiki` returns `OK: published …`, open the molecule URL-in a browser:+Not your dev server, and not a browser that may have cached a working bundle. -```-https://wiki-ufypy5dpx93o.adom.cloud/molecules/<slug>+```bash+adom-bridge --ai-thread "<thread>" pup_open_window \+ '{"sessionId":"verify","profile":"verify","freshProfile":true,+ "url":"https://wiki.adom.inc/<owner>/<slug>/render/viewer/index.html"}' ``` -Confirm visually:+- [ ] `lights` is `["light","spotLight"]`, not `[]`, and not a fallback you added+- [ ] `env: true` — the IBL loaded, so it looks like the local webview+- [ ] `activeRenderLoops.length === 1` (2 means something raced the bundle)+- [ ] walkthrough camera radius CHANGES between steps+- [ ] PCB / Schematic / Parts tabs render+- [ ] the wiki's native 3D viewer shows the board flat and readable+- [ ] every `render/` asset returns 200 to an unauthenticated `curl`+- [ ] no `localhost` / `/proxy/` / `.adom.cloud` in README.html — a published+ page must outlive the container that built it++## Known limitations, do not chase these++- **`MP1`–`MP4` stack at the schematic origin and `lint` fails on it.**+ `<Molecule>` renders `jsx(MachinePin, {type, name, pcbX, pcbY})`, and+ `MachinePinOrContact` in `@tsci/adom-inc.library` destructures only+ `{portHints, pcbX, pcbY, name}`, dropping schematic coordinates. No caller+ can fix it, including a hand-rolled `<board>`.+- **`schX`/`schY` is all-or-nothing.** Placing *some* parts disables+ auto-layout for the rest and stacks them at the origin.+- **`GET viewer/runframe/` 404s** on every load — the "tsci live" tab only+ exists against a dev server.+- **`--texture-resolution N` silently falls back** to the 1024 GLB with a hint+ about `rebake-glb.mjs`. The 4096 rebakes are already in+ `~/.cache/adom-tsci/rebakes/`; the keys are content hashes, so match one to+ your board with `scripts/glb-inspect.mjs`.++## Helper scripts++These live in the adom-tsci page repo under `scripts/`. `adom-tsci install`+deploys `SKILL.md` and the guides but **not** these yet, so fetch them: -1. **Walkthrough auto-plays** within ~2 s of page load. Step text- appears at the bottom of the iframe with Back/Next controls.-2. **3D scene is rendered** — the board (not the loading screen) is- visible.-3. **Source bundle download works** — click the `*-source.tar.gz`- link in the body, untar, confirm `lib/index.tsx` and `plan.md`- are present.-4. **plan.md link works** — opens directly without untar.+```bash+for f in glb-datauri-textures glb-make-zup glb-inspect; do+ curl -fsSL "https://wiki.adom.inc/adom/adom-tsci/render/scripts/$f.mjs" -o "scripts/$f.mjs"+done+``` -If the walkthrough doesn't fire, check the iframe URL has no-`?autoplay=off`, and that `walkthrough.json` was non-empty in the-bundle (`tar -tzf <bundle>.tar.gz | grep walkthrough`). -## Troubleshooting+| script | what it does |+|---|---|+| `glb-datauri-textures.mjs` | embedded images → `data:` URIs, prunes vacated bufferViews, remaps accessors |+| `glb-make-zup.mjs` | wraps scene roots in a `ZUpRoot` (+90° about X), optionally composed with a Z spin |+| `glb-inspect.mjs` | node/LED counts, board extents, J1 placement — for matching a cache rebake to your board | -| Symptom | Cause | Fix |-|---|---|---|-| `dist/lib/index/circuit.json not found` | No build artifacts | Pass `--rebuild` or run `bunx tsci build` first |-| `--texture-resolution N` warns "no rebake-glb.mjs in cache" | First-time use without prior `adom-tsci start` | Run `adom-tsci start .` once to populate the cache, then re-export |-| `bundle is over 95 MB` warning | Big GLB (very high texture res) or many extra files | Drop `--texture-resolution` to 4096 or 2048 |-| `adom-wiki upload failed: page-type mismatch` | Slug exists at a different page-type | Either pass the matching `--page-type`, OR delete the existing page first (`adom-wiki page delete <type>/<slug>`) |-| Source-bundle upload fails but viewer publish succeeds | Transient wiki error | Re-run `adom-wiki asset upload <page>/<slug> --asset-type file --file /tmp/<slug>-source.tar.gz` manually — the CLI prints this hint |-| Walkthrough doesn't auto-play on the wiki page | walkthrough.json missing or empty | Run `adom-tsci walkthrough-gen` in the project, hand-edit if needed, re-export |--## See also--- `adom-tsci/guides/demo-recording.md` — making a 30-second narrated- demo video to attach to the page (separate workflow; the live- viewer is now the primary artifact, demo video is supplementary).-- `adom-tsci/guides/adom-usbc.md` — USB-C placement rules for the- molecule before you publish.-- `adom-wiki` skill — the underlying CLI for asset uploads and page- edits.+## Worked example++[`adom/evan-led-nameplate`](https://wiki.adom.inc/adom/evan-led-nameplate)+exercises every item on this page.
package.json+5−2@@ -1,6 +1,6 @@ { "slug": "adom-tsci",- "version": "1.4.24",+ "version": "1.4.25", "type": "app", "description": "Interactive tscircuit board viewer in a Hydrogen webview \u2014 first-class 3D / PCB / Schematic tabs, an Inspect tool, a Fusion-style Measure tool, net x-ray, guided Walkthrough demos, one-click autorouter re-run, and auto high-res board-surface texture. Fully AI-drivable (CLI + HTTP + JS eval). Also publishes molecules/boards to the Adom Wiki.", "dependencies": {},@@ -28,6 +28,9 @@ "VERSION", "guides/adom-usbc.md", "guides/demo-recording.md",- "guides/export-wiki.md"+ "guides/export-wiki.md",+ "scripts/glb-datauri-textures.mjs",+ "scripts/glb-make-zup.mjs",+ "scripts/glb-inspect.mjs" ] }
scripts/glb-datauri-textures.mjsadded+78@@ -0,0 +1,78 @@+/**+ * Rewrite a GLB's embedded images as `data:` URIs, and drop the bufferViews+ * they vacated.+ *+ * Why not external files: Babylon's glTF loader still routes a relative image+ * URI through XHR + createObjectURL in a null-origin (sandboxed) document, and+ * the wiki's CSP is `img-src data: https:` with no `blob:`. A data: URI is+ * used directly by the loader, so it is the only embedded-texture form the+ * sandbox accepts.+ *+ * Usage: node glb-datauri-textures.mjs <in.glb> <out.glb>+ */+import fs from "fs"++const [inPath, outPath] = process.argv.slice(2)+const buf = fs.readFileSync(inPath)+if (buf.readUInt32LE(0) !== 0x46546c67) throw new Error("not a GLB")++const jsonLen = buf.readUInt32LE(12)+const json = JSON.parse(buf.slice(20, 20 + jsonLen).toString("utf8"))+let p = 20 + jsonLen+let bin = Buffer.alloc(0)+while (p < buf.length) {+ const len = buf.readUInt32LE(p), type = buf.readUInt32LE(p + 4)+ if (type === 0x004e4942) bin = buf.slice(p + 8, p + 8 + len)+ p += 8 + len + ((4 - (len % 4)) % 4)+}++const drop = new Set()+let n = 0+for (const [i, img] of (json.images || []).entries()) {+ if (img.bufferView === undefined) continue+ const bv = json.bufferViews[img.bufferView]+ const bytes = bin.slice(bv.byteOffset || 0, (bv.byteOffset || 0) + bv.byteLength)+ img.uri = `data:${img.mimeType || "image/png"};base64,${bytes.toString("base64")}`+ drop.add(img.bufferView)+ delete img.bufferView+ delete img.mimeType+ console.log(` image ${i}: ${(bytes.length / 1e6).toFixed(2)} MB inlined as data: URI`)+ n+++}+if (!n) { console.log(" no embedded images"); process.exit(0) }++// Rebuild BIN without the vacated views, remapping every surviving index.+const keep = json.bufferViews.map((_, i) => i).filter(i => !drop.has(i))+const remap = new Map(keep.map((old, idx) => [old, idx]))+const parts = []+let off = 0+const newViews = keep.map(i => {+ const bv = json.bufferViews[i]+ const bytes = bin.slice(bv.byteOffset || 0, (bv.byteOffset || 0) + bv.byteLength)+ const pad = (4 - (off % 4)) % 4+ if (pad) { parts.push(Buffer.alloc(pad)); off += pad }+ const v = { ...bv, byteOffset: off }+ parts.push(bytes); off += bytes.length+ return v+})+json.bufferViews = newViews+for (const a of json.accessors || [])+ if (a.bufferView !== undefined) a.bufferView = remap.get(a.bufferView)+for (const m of json.meshes || [])+ for (const pr of m.primitives || [])+ if (pr.extensions?.KHR_draco_mesh_compression?.bufferView !== undefined)+ pr.extensions.KHR_draco_mesh_compression.bufferView =+ remap.get(pr.extensions.KHR_draco_mesh_compression.bufferView)+const newBin = Buffer.concat(parts)+json.buffers = [{ byteLength: newBin.length }]++const jsonBuf = Buffer.from(JSON.stringify(json), "utf8")+const jsonChunk = Buffer.concat([jsonBuf, Buffer.alloc((4 - (jsonBuf.length % 4)) % 4, 0x20)])+const binChunk = Buffer.concat([newBin, Buffer.alloc((4 - (newBin.length % 4)) % 4, 0)])+const head = Buffer.alloc(12)+head.writeUInt32LE(0x46546c67, 0); head.writeUInt32LE(2, 4)+head.writeUInt32LE(12 + 8 + jsonChunk.length + 8 + binChunk.length, 8)+const jh = Buffer.alloc(8); jh.writeUInt32LE(jsonChunk.length, 0); jh.writeUInt32LE(0x4e4f534a, 4)+const bh = Buffer.alloc(8); bh.writeUInt32LE(binChunk.length, 0); bh.writeUInt32LE(0x004e4942, 4)+fs.writeFileSync(outPath, Buffer.concat([head, jh, jsonChunk, bh, binChunk]))+console.log(` ${(buf.length / 1e6).toFixed(2)} MB -> ${(fs.statSync(outPath).size / 1e6).toFixed(2)} MB`)
scripts/glb-inspect.mjsadded+26@@ -0,0 +1,26 @@+import fs from "fs"+const f = process.argv[2]+const b = fs.readFileSync(f)+const g = JSON.parse(b.slice(20, 20 + b.readUInt32LE(12)).toString("utf8"))+const mat = n => { if (n.matrix) return n.matrix.slice()+ const t=n.translation||[0,0,0], r=n.rotation||[0,0,0,1], s=n.scale||[1,1,1], [x,y,z,w]=r+ return [(1-2*(y*y+z*z))*s[0],(2*(x*y+z*w))*s[0],(2*(x*z-y*w))*s[0],0,+ (2*(x*y-z*w))*s[1],(1-2*(x*x+z*z))*s[1],(2*(y*z+x*w))*s[1],0,+ (2*(x*z+y*w))*s[2],(2*(y*z-x*w))*s[2],(1-2*(x*x+y*y))*s[2],0,t[0],t[1],t[2],1] }+const mul=(a,b)=>{const o=new Array(16);for(let c=0;c<4;c++)for(let r=0;r<4;r++){let v=0;for(let k=0;k<4;k++)v+=a[k*4+r]*b[c*4+k];o[c*4+r]=v}return o}+const xf=(m,p)=>[m[0]*p[0]+m[4]*p[1]+m[8]*p[2]+m[12],m[1]*p[0]+m[5]*p[1]+m[9]*p[2]+m[13],m[2]*p[0]+m[6]*p[1]+m[10]*p[2]+m[14]]+const I=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]+function bbox(i,parent,acc){const n=g.nodes[i],m=mul(parent,mat(n))+ if(n.mesh!=null)for(const p of g.meshes[n.mesh].primitives){const a=g.accessors[p.attributes.POSITION];if(!a.min)continue+ for(let k2=0;k2<8;k2++){const c=[(k2&1)?a.max[0]:a.min[0],(k2&2)?a.max[1]:a.min[1],(k2&4)?a.max[2]:a.min[2]],w=xf(m,c)+ for(let k=0;k<3;k++){acc.min[k]=Math.min(acc.min[k],w[k]);acc.max[k]=Math.max(acc.max[k],w[k])}}}+ for(const c of n.children||[])bbox(c,m,acc)}+const get=nm=>{const i=g.nodes.findIndex(n=>n.name===nm);if(i<0)return null+ const acc={min:[1e9,1e9,1e9],max:[-1e9,-1e9,-1e9]};bbox(i,I,acc);return acc}+const j1=get("J1"), bd=get("Box0")+const leds=g.nodes.filter(n=>/^D\d+$/.test(n.name||"")).length+const tex=(g.images||[]).length+console.log(`${f.split("/").pop()}`)+console.log(` nodes ${g.nodes.length} | LED nodes ${leds} | images(textures) ${tex}`)+console.log(` board ${(bd.max[0]-bd.min[0]).toFixed(1)} x ${(bd.max[2]-bd.min[2]).toFixed(1)} mm`)+console.log(` J1 pcb x ${(-j1.max[0]).toFixed(2)} .. ${(-j1.min[0]).toFixed(2)} (east edge ${bd.max[0].toFixed(2)})`)
scripts/glb-make-zup.mjsadded+70@@ -0,0 +1,70 @@+/**+ * Bake a Y-up -> Z-up rotation into a GLB by re-parenting every scene root+ * under one wrapper node.+ *+ * Why: glTF is Y-up by spec, and that is what tscircuit emits — the board's+ * thickness axis is Y (Box0 spans about +/-0.7 in Y). adom-tsci's own viewer+ * compensates at runtime (`zUp: true` + applyGlbZUpTransform), so the copy it+ * loads must stay Y-up. But the Adom wiki's native 3D Model viewer is Z-up and+ * consumes the raw file, so an unrotated board is displayed standing on its+ * edge like a wall.+ *+ * Rotating +90 degrees about X maps (x, y, z) -> (x, -z, y): the Y thickness+ * becomes Z, and the board lies flat in XY. Apply this to the copy the wiki+ * renders (board.glb), never to viewer/3d.glb.+ *+ * An extra spin about Z is often wanted too: the wiki's viewer looks from -Y,+ * so a board whose USB-C edge is at +X ends up facing away. Pass the degrees as+ * a third argument; it is composed as z_spin * x_90 (x first, then z).+ *+ * Usage: node glb-make-zup.mjs <in.glb> <out.glb> [zDegrees]+ */+import fs from "fs"++const [inPath, outPath, zDegRaw] = process.argv.slice(2)+const zDeg = Number(zDegRaw || 0)++/** Hamilton product, q1 applied AFTER q2. Both are glTF [x, y, z, w]. */+const qmul = (q1, q2) => [+ q1[3] * q2[0] + q1[0] * q2[3] + q1[1] * q2[2] - q1[2] * q2[1],+ q1[3] * q2[1] - q1[0] * q2[2] + q1[1] * q2[3] + q1[2] * q2[0],+ q1[3] * q2[2] + q1[0] * q2[1] - q1[1] * q2[0] + q1[2] * q2[3],+ q1[3] * q2[3] - q1[0] * q2[0] - q1[1] * q2[1] - q1[2] * q2[2],+]+const buf = fs.readFileSync(inPath)+if (buf.readUInt32LE(0) !== 0x46546c67) throw new Error("not a GLB")++const jsonLen = buf.readUInt32LE(12)+const json = JSON.parse(buf.slice(20, 20 + jsonLen).toString("utf8"))+let p = 20 + jsonLen+let bin = Buffer.alloc(0)+while (p < buf.length) {+ const len = buf.readUInt32LE(p), type = buf.readUInt32LE(p + 4)+ if (type === 0x004e4942) bin = buf.slice(p + 8, p + 8 + len)+ p += 8 + len + ((4 - (len % 4)) % 4)+}++const scene = json.scenes[json.scene ?? 0]+const roots = scene.nodes.slice()+if (roots.length === 1 && json.nodes[roots[0]].name === "ZUpRoot") {+ console.log(" already Z-up; nothing to do"); process.exit(0)+}+const S = Math.SQRT1_2 // sin(45deg) == cos(45deg)+const qx90 = [S, 0, 0, S] // Y-up -> Z-up+const zr = (zDeg * Math.PI) / 180 / 2+const qz = [0, 0, Math.sin(zr), Math.cos(zr)]+const q = qmul(qz, qx90).map(v => +v.toFixed(12))+json.nodes.push({ name: "ZUpRoot", rotation: q, children: roots })+scene.nodes = [json.nodes.length - 1]+console.log(` wrapped ${roots.length} root node(s) under ZUpRoot (+90deg about X, then ${zDeg}deg about Z)`)++const jsonBuf = Buffer.from(JSON.stringify(json), "utf8")+const jsonChunk = Buffer.concat([jsonBuf, Buffer.alloc((4 - (jsonBuf.length % 4)) % 4, 0x20)])+const binChunk = Buffer.concat([bin, Buffer.alloc((4 - (bin.length % 4)) % 4, 0)])+const head = Buffer.alloc(12)+head.writeUInt32LE(0x46546c67, 0); head.writeUInt32LE(2, 4)+head.writeUInt32LE(12 + 8 + jsonChunk.length + 8 + binChunk.length, 8)+const jh = Buffer.alloc(8); jh.writeUInt32LE(jsonChunk.length, 0); jh.writeUInt32LE(0x4e4f534a, 4)+const bh = Buffer.alloc(8); bh.writeUInt32LE(binChunk.length, 0); bh.writeUInt32LE(0x004e4942, 4)+fs.writeFileSync(outPath, Buffer.concat([head, jh, jsonChunk, bh, binChunk]))+console.log(` wrote ${outPath} (${(fs.statSync(outPath).size / 1e6).toFixed(2)} MB)`)