Make a fresh clone servable after `git lfs pull` alone, and rebuildable with `tools/build.py` without re-rendering unchanged PSDs: - Track build/ (rendered base PNGs, previews, world composites), web/tiles/, web/tiles-trimmed/, web/data/world.json and web/data/markers/. Large PNGs and the tile pyramids go through Git LFS (.gitattributes); JSON stays plain. - build.py: decide PSD re-export from build/<id>/base.stamp.json (PSD size, mtime, SHA-256 recorded at export time) instead of file mtimes, which are meaningless after an LFS checkout. Same size + new mtime hashes once and refreshes the stamp; --stamp-only writes stamps for existing base.pngs. - Ignore .DS_Store and .env files; track sources/**/*.jpg through LFS. Viewer: - Right-click (long-press) the map for a category menu that drops a draft marker under the pointer and enters marker edit mode for that map. - Marker editing moves out of the side panel into a box anchored next to the marker: Enter or a left click anywhere else saves, Esc cancels, Delete inside the box; drags save position plus the box contents. - Maps panel expands on hover, header click pins/unpins (status shown in the header), unpinned collapses 2 s after the pointer leaves; Overview is the first list entry instead of a separate button. Only the panel scrolls; the page never grows past the viewport. Hover tooltips render above markers. Also includes the pending source additions (overall square base, skirt textures, AI regeneration tooling and notes), service worker, Caddyfile and map config updates. Co-Authored-By: Claude Fable 5 <[email protected]>
9.6 KiB
TODO — Regenerate the world with Gemini image-to-image
Status: Implemented. The pipeline tools are complete:
tools/ai/gemini.py: Gemini client wrapper for image generation and image-to-image editing.tools/square_base.py: Generates the square base satellite map with corner outpainting.tools/composite.py: Creates multi-resolution world composites and transition masks.tools/regen_world.py: Serpentine sliding window AI patch loop with guardrails and resume support.tools/tile.py: Extended with"mode": "aligned"skirts and unified backdrop handling.
Two goals:
- Square base map — the overall satellite is rotated 45°, so the world is a diamond with four empty corner triangles. Fill them so the base is a full square.
- One seamless world at a stable resolution — detail maps (native z6–z9) sit on a base that is native z3; edges, palette and sharpness jump at every map boundary. Produce one coherent layer at a single, modest resolution for the whole world, and use it to blend every map into its surroundings.
Why Gemini: unlike MiniMax (image-01, text-to-image only — tested, no
inpainting/outpainting, subject_reference is portrait-only and degenerates on
terrain), Gemini image models accept input images in contents and return
an edited/extended image. That is what both goals need.
0. Ground truth you will be working with
| Fact | Value | Where |
|---|---|---|
| Base source | sources/overall/overall.jpeg, 1308 × 1296 RGB |
maps.json → world.image |
| Base rotation | 45° CCW, expand=True → 1841 × 1841 |
tile.py → load_source, common.rotated_size |
| World pixels | 1841 × overallScale 64 = 117 824 × 117 824 |
world.json → worldSize |
| Zoom depth | maxZoom 9, tile 256 px; world z n edge = 117 824 / 2^(9−n) px |
common.Config |
| Base native level | z3 (1841 px edge) — Leaflet upscales it beyond | world.json |
| Detail maps | 12, native z6–z9, placed by place in rotated overall-map px |
maps.json, §3 of DOCUMENTATION |
| Trim polygons | customs, customs-dorms, woods, reserve, shoreline, lighthouse, streets | maps.json → trim.points (normalised 0–1) |
| Viewer stacking | base bottom; finer map on top; focused family lifted | app.js → focus() |
| Attribution | re3mr.com · CC BY-NC-SA 4.0 — derived imagery inherits it | README |
World edge per level: z4 3 682 px · z5 7 364 px · z6 14 728 px · z7 29 456 px.
1. Square base map
Approach (recommended): outpaint the corners of the already rotated canvas
Keep every placement valid by never changing the rotated frame:
tools/square_base.py: loadoverall.jpeg, rotate exactly asload_sourcedoes (rotate(45, expand=True, BICUBIC)) → 1841² RGBA with transparent corners. Upscale ×2 first (3682², = world z4) so Gemini has pixels to work with.- For each corner triangle, cut overlapping 1024² windows that contain
(a) a generous band of real satellite content and (b) the empty wedge.
Send
[window image, mask image, prompt]to Gemini; prompt: "Extend the satellite photo into the transparent/masked region. Continue terrain, forest, coastline and road network plausibly; match colour, grain, season and lighting exactly; do not alter any existing pixel; output the full window." Low temperature; fixed seed if the model exposes one. - Stitch with feathered overlaps (cosine ramp, ≥128 px). Composite generated pixels only where the original alpha was 0 (hard guarantee that real imagery is untouched — verify with a pixel diff, fail the run if > 0).
- Save
sources/overall/overall-square.png(LFS). Inmaps.jsonsetworld.imageto it andworld.rotateto 0. Becauseplaceis already expressed in rotated-frame pixels and the new image has the exact rotated size (1841², or 3682² withoverallScalehalved to 32), no placement changes. Confirmcommon.rotated_size(...)of the new source equals the old rotated size;retilt.pybecomes a no-op at 0°. python tools/build.py --tiles-only overall→ base pyramid gets z0–z4 (was z0–z3) if you kept the ×2 upscale.
Alternative (rejected): generate a brand-new square satellite — loses real geography the placements were aligned to.
Acceptance: overview shows a square; corner content has no visible seam at z≤4;
git diff maps.json touches only world.image/world.rotate/overallScale.
2. Seamless world at a stable resolution
2.1 Pick the resolution
Target world z6 (14 728² px) — about 8 px per overall-map pixel, where the coarsest detail maps (Shoreline, Ground Zero, native z6) are at 1:1 and the sharpest (z9) are downscaled 8×. Enough to read roads and buildings at overview/mid zooms; the native high-res tiles keep serving deep zooms. z5 (7 364²) is a 4× cheaper first pass to validate the pipeline.
2.2 Build the input composite (no AI yet)
tools/composite.py --level 6:
- Reuse
common.Config.placement()/tile.pymaths to paint, onto a z6 canvas: the square base (upscaled), then every detail map's trimmed raster (build/<id>/trimmed.png, skirts off) scaled to its world rect, in the viewer's stacking order. Paint tile-wise or in strips — 14 728² RGBA is ~870 MB; PIL copes, but writebuild/world/composite-z6.pngin chunks. - Also write
build/world/mask-z6.png: 0 = real art inside a trim polygon (protect), 128 = transition band (art edge ± N px and every art-on-satellite overlap), 255 = satellite-only (free to re-render).
2.3 Patch loop with Gemini
tools/regen_world.py --level 6 --window 1024 --overlap 256:
- Serpentine order over the canvas so each window sees already-processed neighbours (left/top) in its overlap → long-range coherence.
- Per window send: current composite crop (with processed neighbours baked in), the mask crop, and the prompt: "Re-render this top-down map patch at one uniform resolution and style. Keep every road, building, shoreline, rail and clearing exactly where it is (white = free to re-render, grey = blend both sides seamlessly, black = copy unchanged). Match the style of the black regions. No text, no labels."
- Post-process: paste back only where mask > 0; cosine-feather the overlaps; for protected pixels, copy the original regardless of the output.
- Guardrails per patch: edge-map IoU between input and output inside the
grey band ≥ 0.6 (no invented geometry), mean colour shift < 12/255, no text
detected (run
mmx vision describeor Gemini itself as a cheap judge). Retry with a new seed up to 3×, then flag the window inbuild/world/report.json. - Resume support (skip windows already done), dry-run that writes the window grid as an overlay for inspection before spending money.
Cost ballpark: ~370 windows at z6 whole-world / ~150 for bands only; at ~$0.04 per 1K image that is $6–15 per full pass. z5 is 4× cheaper.
2.4 Use it in the viewer — two integration modes
- A. Unified backdrop (simple): tile
build/world/unified-z6.pngas a new base layerworld-unified(z0–z6) replacingoverallunder the detail maps. Detail maps still paint above it at their native resolution; since the unified layer was derived from the same art, the hand-off at their polygon is subtle. Keepoverallas a fallback layer behind a flag. - B. Aligned skirts (best seams): extend
skirtintile.pywith"mode": "aligned"— instead of tiling a texture, cut the ring around each map's rectangle out of the unified composite at world coordinates, scale to the map's raster and use it as the skirt. Pixel-exact continuity with both the art and the backdrop; all existing knobs (featherIn,fadeOut,soften) still apply; the stamp must include the unified image's hash. This is the mode that makes "seamless" true at every zoom.
2.5 Acceptance
- Pan Woods → Customs → Interchange at z4–z6: no frame edges, no resolution jumps, palette continuous; roads continue across polygons.
- Deep zooms unchanged (native tiles); editors unaffected (original pyramid).
- Bytes: report total tile MB before/after; keep the Detail-mode/
softenbudgets in mind (skirts doubled bytes until softened).
3. Plumbing / hygiene
- API key:
tools/gemini_image.pycurrently has a key pasted intoGOOGLE_API_KEY. Move it toGEMINI_API_KEYin the environment (the client reads it when the constant is empty) before committing — the file is tracked. Consider a.env+python-dotenvand add.envto.gitignore. - Refactor
tools/gemini_image.pyintotools/ai/gemini.pywithedit_image(images: list[PIL.Image], prompt, *, size, seed) -> PIL.Imageandgenerate(prompt, ...);skirt.pygets--backend minimax|gemini. - Check current Gemini image model names/limits (
gemini-3.1-flash-imagevsgemini-3-pro-image-preview), max input images, output sizes (1K/2K/4K), whetherseed/temperatureapply viaGenerateContentConfig, rate limits. - Put all generated sources under
sources/ai/(LFS,*.png|*.jpgalready matched) with a JSON sidecar per file: model, prompt, seed, windows, input hashes — so a pass is reproducible and attributable. - Licence: generated imagery derived from re3mr art stays CC BY-NC-SA; keep the attribution control and note AI-assisted regions in the README.
4. Order of work
square_base.py(small, self-contained, immediately visible win).composite.pyat z5 +regen_world.pydry-run grid → one real pass on the Woods/Customs/Reserve cluster only → evaluate.- Integration mode A (backdrop) → if seams still show at z5–z6, mode B.
- Full-world pass at z6; byte budget check; docs.