Brickheart

Brick Heart: handover, build page

: Written by a human with AI assistance.

1. State

Verified (you tested, on Cloudflare):

  • /en/build/?set=… works. Pack download prompt, then models load.
  • Palette list moves 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, SELECT all work.
  • DELETE puts part back in palette. Used-up rows leave list and wall.
  • History shows placed parts at final position plus rotation.
  • Export MPD works. One STEP per part.
  • Parts show the right way up.

Not tested or unknown:

  • Subjects 2 and 3 on build page. Cold install on clean origin.
  • Large sets (cap is under 999 parts). Whole scene re-renders on each action.
  • Rotation direction vs "rotated 90°" text vs exported matrix.
  • Colour 16 export for the 8 colours with no ldraw_code. Those place as grey.
  • Exported MPD in a real LDraw viewer. You said all works, but you did not name the viewer.
  • Service worker. True offline reload.
  • Blocked-network test and removeSubject dedup (still open from last session).

2. Decisions made

  • Palette is the left list. One row per part and colour. Row hides at zero left.
  • Ids. Every brick gets a 4-digit id up front. Id is (seed + n × 6181) mod 10000. Seed is a hash of the set number. Deterministic. Unique.
  • Label. #0412 red.4 plate 1x2. Family is colors.base_color. Colour id is colors.ldraw_code, falling back to the Rebrickable id. Name is the DB name lowercased with 1 x 2 squeezed to 1x2.
  • State. Op list (place, move, rot, del) is the truth. History, palette and scene are all derived. Undo and redo move a cursor.
  • Place. Drops at x=0, z=0, lowest point on the floor. Next free id of the row.
  • Move. Stud 20, plate 8, brick 24 LDU. Arrows are screen-relative. Rotate is a 90° turn about Y.
  • Export. One 0 FILE. 0 // #id label comment, then the type 1 line, then 0 STEP. Engine coordinates converted back: x, -y, -z.
  • Scene. 32×32 stud baseplate. Parts wall stands behind it at z=-340. Light values copied from the reference.
  • "Iso" camera is a fixed diagonal view, not orthographic.
  • Voxels parked. No collision. voxels.json is 264 MB, over the 25 MiB limit.

3. Files (all in app/)

  • src/build.ts. Whole page logic. Imports ./ldraw/ldraw-hook, ldraw-store, geometry, parts, mpd.
  • render-build.mjs. HTML and DEFAULTS for all build.* strings.
  • css/build.css.
  • build.mjs. renderBuild call must sit after fs.rmSync(dist). Two esbuild entries: js/app.js, js/build.js. WASM copy covers both bundles.
  • render.mjs. Build column header, BROWSE_DEFAULTS.
  • src/main.ts. renderRows has the Build link and colSpan 6.

Build order: npm run typecheck && npm run build && npm run preview.

4. Next session

  1. Add build.* and browse.* Build keys to ui.json. The key list is DEFAULTS in render-build.mjs. Then zh/build can be built.
  2. Link from zh browse to zh/build once it exists. It currently links to en/build.
  3. Test subjects 2 and 3 on the build page. Test a set with a colour that has no ldraw_code.
  4. Check rotation direction. Rotate, export, open in a viewer, compare.
  5. Cmarea buttons. 4 fixed cameras plus wall camera.
  6. Place position. All parts drop at 0,0 and stack. Consider a free spot or a cursor.
  7. Blocked-network test, removeSubject dedup, interrupted install.
  8. Service worker for real offline reload.
  9. Then, in order: connector snapping (connections.json, solveAttachmentSeated), command line, colour modes, collision.

5. Cautions

  • Don't guess. Ask for terminal output first.
  • Mark anything unverified. British spelling.
  • All visible text in the real app goes through site/ui.json with your approval. Current build.* text is English defaults only.
  • No inline styles. CSP is style-src 'self'. Set colours through CSSOM.
  • Cloudflare limits are 25 MiB per file and 20,000 files. Generated artefacts must be committed.
  • Whole files, not patches, when edits are not simple.
  • Unresolved from reference:
    • connections.json key mapping. The keys are not confirmed to be LDraw stems.
    • Reference collision code location. Not found.
    • metaOf and STUD_PITCH definitions. Seen only at call sites. The code uses 20.
  • Known gaps: bench flattenMpd reads the first 0 FILE as a submodel, so exported files load empty in the bench. Part names use the full DB name, so odd labels like weapon sword (uruk-hai) appear. The spec wants the generic noun.