Brickheart

App (Page 2)

  • Changelog 09NOV2026 app

    Bench plan decisions from 9 Nov. Planning only, nothing was built that day. Items changed on 10 or 11 Nov are noted.

    • The Build page is now called the bench (app/src/bench.ts).
    • Several bench pages (touch, mouse, key, voice, button, API, CLI) will share one core. Every page shows the 3D stage, and a model saved on one page opens on any other.
    • The core is three layers: core with no DOM or THREE, session and view, and one adapter per page.
    • The ops log with a cursor is the truth, and everything shown is derived from it.
    • Commands return structured results. They have separate preview and commit steps.
    • Orientation is one command, with yaw, pitch and roll as variants.
    • Each bench page declares whether it is accessible. Click-and-drag modes are flagged as not accessible.
    • Camera: four presets at floor level on the box diagonals, recorded as plain CAMERA 1 to 4 comments. Changed on 10 Nov: camera presets are deferred. Changed on 11 Nov: the "wall view" preset is dropped.
    • MPD export keeps history in comments, with one STEP per part.
    • Palette wall: tiles share one look function, with seeded jitter of plus or minus 15 degrees, big parts tilted and small parts scaled down. Changed on 10 Nov: the wall has no wobble. Changed on 11 Nov: the fixed A to Z, 1 to 9 grid is dropped, and the wall is laid out from the tile count.
    • Where the first part goes is answered on 11 Nov: the front-centre floor anchor.
    • Taken connectors are derived from poses with connectionsFor and not tracked at attach time. Decided on 11 Nov.
    • Saving: one model per set, autosaved after every change, with a my-models page and bulk backup and restore. The ops log is the saved format. Single-file LDR/MPD import is parked.
    • Set image on the left wall of the box, from local copies only. Sets with no image get a no-image state.
    • OMR models are bundled as a pack per subject with a download button, matched to sets by set number.
    • Settings: a Settings link at the bottom right, holding smart assemble, canvas size, show/hide toggles, language and theme.
    • Written instructions are a by-product of use. The build history gives a draft that a person refines for a blind builder, following the Bricks for the Blind templates.
    • A monochrome mode will use patterns in place of the 12 colour families.
    • Voice is English only and is a constraint, not a deliverable. Tool lists stay at about 10 per mode, with a gate for noise.
    • API and CLI (proposed, not confirmed): window.brickheart as a typed command object, a CLI text bar calling it, and an LLM driving the page by browser automation. No server.
  • i18n migration and renames

    • The Build page is now the bench: bench.ts, render-bench.mjs and URLs at /<lang>/bench/.
    • Browse files are named for the page: browse.ts and render-browse.mjs.
    • App strings live in app/i18n/ui, with en.json, <lang>.json and todo.<lang>.json.
    • The build now fails when a file is over 25 MiB and warns within 5% of it.
    • The app build adds 'wasm-unsafe-eval' to the CSP.
  • Scene collision checks, packs and the attach picker

    Packs and storage

    • New pack.ts: one reader for the indexed packs, DAT and BIN. The DAT install was rewritten to use it.
    • New collide-store.ts: collision packs live in IndexedDB, keyed by stem. They have the same tap-to-install, persistence and cleanup as DAT.
    • The collision pack is optional. Parts place without it.
    • The LDraw and collision stores use separate IndexedDB databases, brickheart-ldraw and brickheart-collide, so they cannot clash.

    Collision check

    • The check runs off the main thread in collide.worker.ts, through collide-client.ts.
    • The scene is rebuilt from the part list, reusing cached hulls.
    • Time budget is 1.5 s per check. Over budget reports "incomplete", never a guessed hit.
    • Modes: off, on rest (400 ms after the last op) and manual (Check button). The mode is saved in localStorage.
    • Collision is a warning only. Nothing is blocked. A status line shows under #msg.

    Attach picker

    • Candidates are ranked: clear first, then unknown, then colliding. Colliding ones get a "(collides)" marker.
    • New wording for pin, pin hole, clip, bar, hollow stud, tyre and "axle through".
    • Pin roll angles are collapsed, so 4 duplicates instead of 16.
    • Axle and bush offer near and far end seats. The move buttons do the nudging.
    • Axle and tyre joints skip the relation filter, since they overlap by design.
    • No collision flag for a pin in a hole, a hollow stud or a tyre on a rim.
  • BrickNet port from Python to TypeScript

    • It lives in app/src/snap. After the port, 12 snapshot tests and tsc --noEmit pass.
    • Ported graph.py, core.py, data.py and tree.py: connector frames, the mate table, edge building, components and placement.
    • Ported edgeMatrix, graphEdgeRotation, decodeGraph, graphToLdr and the path-text codec (serializeTree, parseSample, id2i, i2id).
    • The axis check follows Python: normalise first, then compare with a signed dot of at least 0.95.
    • The kind check follows Python: stud against hole first, then the sub pair. Kind hole owns hole, tube and post. Kind stud owns stud and open. This was confirmed on four stems only.
    • ry4 is the standard Y rotation, and RX_PI is diag(1,-1,-1). Both were confirmed from tree.py.
    • Euler angles match scipy as_euler("xyz"). In gimbal lock scipy zeroes the third angle.
    • Edge order differs from Python, so tests compare edges as sets.
    • sampleTree takes an injected rand, so random walks do not match numpy. BFS is exact.
    • Parity tests on car.ldr: connector order and frames for the first 40 stems, aliases and orthonormalised poses, all 136 edges with family, flip, yaw, slide and rot to 1e-7, components, and placement (3001 on 3001 gives 8, 2, 1 and 2 edges, with yaw equal to turns x 90 degrees).
    • Decode tests: letter IDs round-trip, Python number formatting (round(v, 6) and .12g), decode_graph, graph_to_ldr text, a component tree round trip, and parse_sample errors.
    • Test data is written by tools/export_bricknet.py and tools/dump_decode.py in /home/chinapal/bricknet to app/test-data/bricknet. The export has 14,583 parts and 2,522 aliases.
    • Parts with no connectors raise a ParseError. Python raises KeyError.
  • Offline mode

    The app now works with no network.

    • New src/db.worker.ts, one module worker. It owns sql.js, the only copy of the database, and ldraw-store.ts.
    • Worker ops: init, query, isInstalled, listStems, install, closure, remove, cleanupInterrupted and cancel.
    • init gives the worker an absolute base URL, because relative paths inside a worker resolve against /js/, not the page.
    • The worker makes its own onProgress and AbortController, since functions cannot be posted.
    • Error names are passed through, so QuotaExceededError and AbortError survive. Only one install runs at a time.
    • New src/db-client.ts: startDb(root) starts the worker and must be awaited first. call(op, args, {onProgress, signal}) is the RPC, and run(Built) runs a query from query.ts. A worker crash rejects all pending calls.
    • main.ts dropped sql.js. All queries go through run. Render and setSubject are async, and a renderSeq counter drops stale results.
    • bench.ts dropped sql.js. query, isInstalled, install and closure go through call. The install URL is absolute.
    • installFileLoaderHook() and setOfflineFiles(files) stay on the main thread, because three's FileLoader lives there.
    • releaseGroups() runs after the wall loads. It clears groupCache and keeps geomCache.
    • New src/sw.js service worker: network-first with a cache fallback. Navigation uses ignoreSearch, so ?set=... hits the cached page. The cache is named app-<hash>, old caches are deleted on activate, and it uses skipWaiting and clients.claim. It is registered in main.ts and build.ts.
    • Results: JS heap was 42 MB for 172 distinct parts, all 3 packs install and load from IndexedDB, and the service worker serves pages and assets offline.
    • CSP unchanged. script-src 'self' 'wasm-unsafe-eval' covers the worker and the wasm, and worker-src falls back to script-src.
  • Changelog 26OCT2026 app

    Connector snapping, palette buckets and the accessibility contract, decided on 26 Oct. Items changed by later sessions are noted.

    Snapping

    • Source of connector data: BrickNet, MIT, 14,583 parts. The converted format stays source-neutral: kind, sub, pol, length, a 12-number frame and an address. Done on 31 Oct by the port.
    • Mate rules come from core.py: the stud table and the axle table. Hinge, ball and fixed pair when subtypes match and polarities are in and on.
    • Addresses are (type, index), counted within each group of the canonical order. This is what makes "stud 3" meaningful.
    • For stud-family joints: source pose = target pose, then target connector frame, then a Y turn, then the inverse of the source connector frame.
    • All snap maths is done in LDraw space. A part is converted at the boundary, and place.ts never mixes frames.
    • The picked palette part is the source and moves. The target defaults to the last placed part. Turn means quarter-turns about the vertical axis.
    • Only compatible connector types and connectors are listed. Typed commands and pickers build the same command object.
    • Preview before commit: the app announces the result, then confirms with Enter or a button.
    • Mating axis: -Y, settled by the 31 Oct port, which follows axes = -col1. Up and down wording is still to be decided from real part geometry.
    • Changed on 11 Nov: a snap op with the chosen relation is dropped. The history stores poses only, and connections are derived with connectionsFor.
    • Changed on 11 Nov: groups can be rotated by the ring's assembly scope as one rigid transform. The 26 Oct rule was translate only.
    • Single-part move never drags other parts. Group move is a separate op.
    • Warnings are written, never blocking, for the placed part only. Overlap uses bounds, occupied connector, and partial mate counted with _POS_THR = 3.0 and _AXIS_THR = 0.95.
    • Axle, pin, hinge, ball and fixed joints are later phases.

    Palette buckets

    • Each part is in exactly one bucket. Structural is the default.
    • Changed on 10 Nov: six buckets from the Rebrickable category name (structural, functional, interaction, decorative, wheels, minifig). This replaces the five-bucket hierarchy with connector-signature rules.
    • Changed on 11 Nov: wall order is bucket, then connector, then colour, then part number. This replaces the in-bucket ordering by quantity and footprint.
    • Each bucket is a labelled group with a heading and a count. Group order stays consistent. Announce the grouping once on load, and do not reorder silently.

    Input and accessibility

    • Every action is a DOM control. The canvas is output only, and nothing essential needs a pointer on it.
    • Keyboard operable, with a short focus order and a visible focus indicator that sticky UI does not hide.
    • No drag, hold, chord, hover-only or timed interactions. No built-in timers in v1.
    • Accessible names contain the visible label text, so voice control can say "click place".
    • Single-key shortcuts can be remapped or turned off.
    • Targets meet the WCAG 2.2 minimum, with larger sizes selectable.
    • Undo and redo are one action. Save and resume are automatic.
    • Primary input is enumerated placements: a numbered list of valid (target connector, source connector, turn) combinations with a canvas marker. The typed command is a secondary fast path and the text form of the history.
    • Connectors get a display index in reading order in the part's own frame, mapped to BrickNet's canonical index. BrickNet's raw order is never shown.
    • Settings come first and profiles last: target size, confirm before placing, placement entry, single-key shortcuts, list length, camera control, announcements and motion. Profiles: Mouse, Touch, Keyboard, Voice, Switch-friendly and Large-target.
    • Voice is left to the operating system. The app does not build in speech recognition, because browser recognition may send audio to a server and the app is offline first.
    • "Suggested next" moves nearer the core, as a default for the Switch-friendly and Voice profiles.
  • Build mode

    Tested and working

    • /en/build/?set=... works on Cloudflare: pack download prompt, then models load.
    • Palette list moves the camera. Search, colour and category filters work.
    • Browse has a Build link on each row.
    • Pick, place, move (buttons and arrow keys), rotate, undo, redo and select all work.
    • Delete puts the part back in the palette. Used-up rows leave the list and wall.
    • History shows placed parts at final position plus rotation.
    • Export MPD works, with one STEP per part. Parts show the right way up.

    Decisions

    • The palette is the left list, with one row per part and colour. A row hides at zero left.
    • Every brick gets a 4-digit id up front: (seed + n x 6181) mod 10000. The seed is a hash of the set number, so ids are deterministic and unique.
    • Label format is #0412 red.4 plate 1x2. Family is colors.base_color. Colour id is colors.ldraw_code, falling back to the Rebrickable id. The name is the database name lowercased, with 1 x 2 squeezed to 1x2.
    • The op list (place, move, rot, del) is the truth. History, palette and scene are derived, and undo and redo move a cursor.
    • Move steps are stud 20, plate 8 and brick 24 LDU. Arrows are screen-relative. Rotate is a 90 degree turn about Y. These are still the ring's standard steps.
    • Export writes one 0 FILE. Each part has a 0 // #id label comment, the type 1 line, then 0 STEP. Coordinates are converted back with x, -y, -z.
    • The "iso" camera is a fixed diagonal view, not orthographic.
    • Voxel collision is parked. voxels.json is 264 MB, over the 25 MiB limit.
  • Offline LDraw pack bench

    Verified on subject 1 (?step=9)

    • Install: 4021 of 4021 files in 1.5 s. Origin storage was 13.7 MiB, including the sql.js database.
    • Run: 196 of 1759 stems, closure 899 files, 0 missing, closure 114 ms, geometry 2522 ms, 18,092 triangles, 0 failures. JS heap 110.9 MiB.
    • Run with ?all=1: 2157 of 2157 files installed in 0.9 s, 18.1 MiB origin storage, 923 of 923 stems, 0 missing, closure 245 ms, geometry 10230 ms, 80,040 triangles, 0 failures. JS heap 301.9 MiB.
    • The r:1 root flag works: listStems returned 1759.
    • dist/data/ldraw is served, so the build.mjs copy block works.

    Decisions

    • No stripping. Packs hold the text as read.
    • files is keyed by normalised name and shared across subjects. A members store keyed [subject, name] has an index on name and an r root flag. Removal deletes a file only when no member row remains.
    • The packer checks that shared files are identical across subjects.
    • The tap handler calls requestPersistence() explicitly, before the install.
    • The bench takes its parts from the installed pack, with no excavator and no MPD.
  • Product spec and the target flow

    Product spec

    • Browser app, offline-capable after a first visit. No LLM and no mouse drag. Touch and audio friendly. Voice is wanted but optional (NeuDecide ONNX, about 43 MB).
    • Out of scope: minifigs, flexible parts, nested assemblies and editing assemblies after creation.
    • MVP: the viewer shows the set with LDrawLoader.js, then a basic UI places bricks from the palette on top of one in the scene.
    • Palette: a finite set inventory, or an unlimited era or designer palette (a stack of 3 per part).
    • Directions are screen-relative. UP and DOWN are world-vertical, and -Y is up.

    Target flow

    • Set number gives the inventory (non-spare rows with ldraw_stem, ldraw_code and quantity) and its pack through themes.subject_id.
    • Colour definitions need LDConfig.ldr, which ships in every pack.
    • The DB is read with sql.js in a worker, packs install per subject on demand with a service worker, and collision checks run in a worker with an optional pack, with no Pyodide.