Brick Heart: handover for the next session
1. State at end of this session
Verified (by you, in Edge):
app/data/models/bulldozer.mpd(an excavator with 8 nested submodels, 45° tilts and flipped matrices) loads as individual bricks via the reference path.- The render path runs:
composeMatrix(h), the URL-modifier hook,getColorMaterial,getPartGeometry(merge, flip 180° about X, cache by part id) and thePartsRendererloop with its cancel token. Memory was about 57K. - Keyboard picking and moving worked. Export was written last, and confirmed in Stud.io.
Inferred, not read from the reference:
engineRotFromLdrawwas my derivation (F·R·F with F = diag(1,-1,-1)). It held on the excavator, but2fmu4y60objlb.jslines 160 to 190 have never been seen.- Record
yandzare stored negated (engine coordinates, y up). - I used three's stock
LDrawLoaderandLDrawConditionalLineMaterial, not the reference's classm(lines 434 to 857, 935 to 1224) orM(1224).
Not done, and the main gap: the bench is not offline. bench-build.mjs writes a flat file tree from the parts embedded in the MPD and serves it statically, so it only works for that one model. I called that "a stand-in for the offline store", and it was not one.
Build order is npm run build (it empties dist), then node bench-build.mjs bulldozer.mpd, then npm run preview.
2. Agreed design (offline part files)
Principle: LDrawLoader needs .dat text for a set's parts and nothing else. The browser database holds the data. Python is kept only because _resolve (library search order, p/8 preference) already exists there. You said it is not core.
- Build step,
ldraw_pack.py(Python).- Select sets through
sets.subject_id(agreed change, see section 4). - Strip each file to line types 1 to 5 and
0 BFClines. Round numbers if wanted. - Write each file's direct subfile list (
deps). - Output one gzipped JSON line per file,
{n, d, t}, instead of0 FILEandNOFILEblocks, so the browser can stream it. - Regenerate the manifest (names, sizes, SHA-256).
- Select sets through
- Install (once per subject, on "Make available offline").
- Stream the pack through
DecompressionStream('gzip')and split on newlines. - Write batches into an IndexedDB
filesstore keyed by the normalised name. - Normalisation is lowercase, backslash to slash, strip a leading
parts/orp/. It is applied on write and on lookup. - Call
navigator.storage.persist()and handle failure.
- Stream the pack through
- Open a set.
- Read the stems from the inventory.
- Walk
depsin IndexedDB for the closure, a few hundred rows. - Build an in-memory
Mapof name to text and answer the loader's requests from it. No pack is assembled and nothing extra is written.
- Inventory source. Stay on the existing sql.js database for now. Moving it to IndexedDB is the separate Phase 1 decision.
- Loader interception. Patch
FileLoader.prototype.load, scoped to/ldraw/URLs, to read from the Map. The reference's URL-modifier still runs first. The store interface stays the same if this later moves to a service worker.
Measured facts behind it (subject 1):
| Item | Value |
|---|---|
| Raw size | 32,892,877 bytes |
| Non-comment bytes | 30,861,570 |
| Gzip, current | 5,342,561 bytes (5.09 MiB) |
| Gzip, stripped (no rounding) | 4,879,989 bytes |
| Saving from stripping | about 9% |
Stripping is for parse speed and cleanliness, not download size. Baking geometry in Python would shrink it much more, but it abandons LDrawLoader. I deferred that.
3. Plan of action for the next session
- Packer. Edit
ldraw_pack.pyas above and regenerate. Report per-subject set, part and file counts, raw and gzip sizes, and duplicate-name checks across subjects. - IndexedDB layer (TypeScript).
normalise(name).installSubject(id, onProgress).getClosure(stems).isInstalled(id).removeSubject(id).- Handle failed and interrupted installs, and the temporary versus persistent distinction.
- Loader hook. Patch
FileLoader.load, then check thatLDConfig.ldrand every.datgo through it. - Bench v2. Take the excavator's part list from the real installed pack, with no embedded blocks and no
/bench/ldrawtree. Delete the static tree and themodel.mpdfetch for parts. - Offline test. Load online once, install, switch Edge to offline, reload, and confirm it renders. Report install time, extracted size, time to first render and memory against 57K.
- Resolve the inferred pieces. Paste
2fmu4y60objlb.jslines 160 to 190 and swap in the realengineRotFromLdraw. Confirm or correct the stock loader versus classm.
After that, in order:
- The
?set=build page from the database inventory, with the palette (this needs your approval of theui.jsonkeys). - Connector-based PLACE, which needs
2fmu4y60objlb.jslines 205 to 337 and theconnections.jsonformat. - The service worker, the colour modes, and splitting the Real World pack.
Questions:
- Stripping and printed parts: the excavator test only used plain parts. Do you want a printed part and a part with fixed-colour subparts added to the test list, to exercise colour inheritance after stripping?
- Persistence: should the install ask for
persist()when the user taps "Make available offline", or silently?
Carried-over cautions:
- Don't guess. Mark anything unverified. British spelling.
- All visible text in the real app goes through
site/ui.jsonwith your approval. The bench is English only and not shipped. - The sql.js CSP uses
'wasm-unsafe-eval', not'unsafe-eval'. - Cloudflare limits are 25 MiB per file and 20,000 files, and generated artefacts must be committed.