pixel-art-topdown-lessons
README.md
# 2D Pixel Art Asset & Animation RAG + MCP (`pixel-art-topdown-lessons`)
Offline-ready Hybrid RAG (**SQLite FTS5 BM25 + ChromaDB `ONNXMiniLM_L6_V2` + `cross-encoder/ms-marco-MiniLM-L-6-v2` Reranker + Reciprocal Rank Fusion**) and stdio JSON-RPC 2.0 MCP documentation server synthesizing **2D Top-Down & Front-View (`48–64px`) Pixel Art asset creation, anime/chibi eyes & hair coordinate recipes, copy-paste hex color ramps, code-drawn mask algebra, tilesets/autotiling (`Wang-16`, `Blob-47`, `Dual-Grid`), animation cycles, combat smears, pixel VFX, UI/icons, and Aseprite-to-engine export pipelines**.
## Repository Layout
- `docs/` — **14 curated practitioner guides** (`00_` through `13_`, including **48–64px Front-View Anime/Chibi & Equipment** in `11_`, **Copy-Paste Hex Palettes** in `12_`, **Code-Drawn Mask Algebra** in `13_`, **40-item Pitfall & QA Gate** in `09_`, and **Courses Compendium** in `10_`).
- `assets/references/` — **6 labeled visual pixel-art reference PNGs** generated by `generate_references.py` (`3x3`/`5x5` anime eyes, `64x64` chibi coordinates, hair & equipment, hex swatches, mask shading vs pillow shading, 3/4 top-down & Dual-Grid).
- `AGENTS.md` — System instruction rules directing AI agents to query `pixel-art-topdown-lessons` before creating or exporting 2D pixel art.
- `fetch_sources.py` — Reproducible downloader pulling YouTube transcripts/chapters (`yt-dlp`), free web guides (`Slynyrd`, `FinalBossBlues`, `Saint11`, `Wang/Blob`), and companion GitHub scripts into gitignored `raw_sources/`.
- `ingest.py` — Builds `data/lessons.sqlite3` (FTS5 + structured `pitfalls` + pre-extracted `summary`/`actionable_json` per meaning-chunk) and `data/chroma/` (`pixel_art_topdown_lessons`), and warms up the local cross-encoder cache.
- `pixel_rag.py` — Standalone CLI + bilingual (Vietnamese/English) Hybrid RAG + Cross-Encoder Reranker + Automated PNG QA + stdio JSON-RPC 2.0 MCP server (`5` read-only tools).
- `eval_queries.json` & `eval_rag.py` — Continuous **40-query** evaluation suite tracking `Recall@1`, `Recall@3`, `Recall@5`, and `MRR`.
- `smoke_test.py` — End-to-end verification suite (CLI stats, safe query expansion, empty-arg & error handling, PNG QA, and strict stdio MCP protocol validation).
## Curated Knowledge Base (`docs/`)
| File | `doc_id` | Coverage |
|---|---|---|
| `00_master_pixel_art_pipeline_and_resolution.md` | `master-pixel-art-pipeline-and-resolution` | 10-stage pipeline, integer resolutions (`320x180`, `384x216`, `480x270`, `640x360`), style tiers, anti-mixel law |
| `01_pixel_fundamentals_lines_clusters_and_aa.md` | `pixel-fundamentals-lines-clusters-and-aa` | Clean lines, jaggies/doubles removal, pixel clusters, banning pillow shading & banding, manual AA & sel-out |
| `02_color_theory_palettes_and_hue_shifting.md` | `color-theory-palettes-and-hue-shifting` | Hue-shifted ramps, grayscale value validation, ramp bridging, figure-ground contrast |
| `03_topdown_perspective_proportion_and_silhouettes.md` | `topdown-perspective-proportion-and-silhouettes` | 3/4 oblique projection, chibi proportions, silhouette clarity, 3/4/5/8-direction turnarounds, contact shadows & feet pivot |
| `04_topdown_tilesets_autotiling_and_environments.md` | `topdown-tilesets-autotiling-and-environments` | Seamless 3x3 tiling, Wang-16, Blob-47 bitmask folding, Dual-Grid 15-tile offset, cliff elevation & water shores |
| `05_props_foliage_materials_and_architecture.md` | `props-foliage-materials-and-architecture` | Modular leaf-cluster trees, wood/stone/metal/glass materials, top-down props, exteriors & interior room caps |
| `06_animation_principles_and_topdown_cycles.md` | `animation-principles-and-topdown-cycles` | 12 principles, sub-pixel animation, 4f idle, 4f/6f/8f walk/run (`down 1px, down 1px, up 2px`), non-uniform ms timing |
| `07_combat_actions_smears_and_pixel_vfx.md` | `combat-actions-smears-and-pixel-vfx` | 5-phase weapon attacks (`Anticipation -> 50ms Smear -> Follow-Through`), dash/hitstun/death, explosions, fire, dust, ripples |
| `08_pixel_ui_icons_aseprite_and_engine_pipeline.md` | `pixel-ui-icons-aseprite-and-engine-pipeline` | 9-slice UI, 16x16/24x24 icons, pixel fonts, Aseprite CLI/Lua automation, 1px tile extrusion, Unity/Godot/Phaser import |
| `09_ai_agent_pixel_art_pitfalls_and_qa_checklist.md` | `ai-agent-pixel-art-pitfalls-and-qa-checklist` | 40-item bug matrix (including AI code-gen/image-gen pitfalls) + 10-Point Pre-Delivery QA Gate |
| `10_courses_and_lessons_compendium.md` | `courses-and-lessons-compendium` | Complete indexed map of free YouTube playlists, flagship tutorials, web blogs & GitHub repos |
| `11_front_view_anime_chibi_48_64px_and_equipment.md` | `front-view-anime-chibi-48-64px-and-equipment` | 48–64px front-view anime/chibi Y-budgets, `3x3`/`5x5` eye coordinate grids, spiky hair, pauldrons, capes & swords |
| `12_ready_hex_palettes_and_color_ramps.md` | `ready-hex-palettes-and-color-ramps` | Copy-paste hex ramps (Skin, Hair, Steel, Gold, Leather, Capes, Ground) + Endesga 32, DawnBringer 32, PICO-8 |
| `13_code_drawn_pixel_art_masks_and_workflow.md` | `code-drawn-pixel-art-masks-and-workflow` | Layer masks, `dilate4` outlines, `mask & ~shift(mask)` directional shading, cleanup filters & preview-critique loop |
## Quick Setup & Verification
```bash
# 1. Install dependencies (Python >= 3.10)
pip install -r requirements.txt
# 2. (Optional) Generate reference PNG sheets & fetch upstream sources
python generate_references.py
python fetch_sources.py all
# 3. Build local SQLite FTS5 + Chroma vector index + cache Cross-Encoder
python ingest.py
# 4. Query via CLI (English or Vietnamese; defaults to curated tier)
python pixel_rag.py search "vẽ mắt anime ở 64px"
python pixel_rag.py pitfalls
python pixel_rag.py qa --asset-type character --image assets/references/ref_chibi_64px_proportions.png
python pixel_rag.py review-logs
# 5. Verify RAG + MCP protocol + Recall@5 benchmark
python smoke_test.py
python eval_rag.py
```
## Exposed MCP Tools (`pixel-art-topdown-lessons`)
- `search_pixel_lessons(query, topic=None, tier="curated", limit=6)` — Returns `summary`, `actionable` (`rules`, `numbers`, `hex_colors`, `code_or_coords`), `reference_images`, and `snippet`.
- `read_pixel_lesson(doc_id, section=None, offset=0, limit=16000)`
- `get_pixel_pitfalls(symptom_or_topic="", category=None, limit=8)` — Works with or without arguments.
- `get_qa_checklist(asset_type="all", image_path=None, max_colors=32)` — Executable QA checklist + automated Pillow/NumPy pixel check when `image_path` is provided.
- `list_pixel_topics_and_courses(tier="curated")`
## Security & Privacy
- Runs **100% offline** at query time (`HF_HUB_OFFLINE=1`, `?mode=ro` SQLite, telemetry disabled) — see [SECURITY.md](SECURITY.md).
- Query telemetry (`data/query_log.jsonl`) is strictly local, append-only, and inspectable via `python pixel_rag.py review-logs` (set `PIXEL_RAG_DISABLE_LOG=1` to disable).