Update README with 3D reconstruction docs and Space link
Browse files12345624 unmodified lines3132333435363738394041424344453 unmodified lines4950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231245 unmodified lines130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186# ๐ Floor Plan ParserParse floor plan images into structured data โ walls with thickness, doors, windows, and automatically detected rooms.## Architecture24 unmodified linesโ (VLM or human) โ outputs field-level correctionsโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผ converged? โโnoโโโ back to step 1yesโผFinal structured schema (JSON)```## The SchemaWalls are first-class. Everything else references them.```json{3 unmodified lines"centerline": [{"x": 0, "y": 0}, {"x": 6, "y": 0}],"thickness": 0.24,"openings": [{"id": "win1","type": "window","start": 1.5,"length": 1.5}]}],"rooms": [{"id": "r1","label": "bedroom","boundary": [{"wall_id": "w1", "side": "right"},{"wall_id": "w2", "side": "left"}],"area": 16.0}]}```**Key design decisions:**- **Walls have thickness** โ exterior (0.20-0.30m) vs interior (0.10-0.15m)- **Openings live on walls** โ `start` + `length` along the centerline- **Rooms are topological** โ defined by ordered wall-face references (left/right side), not duplicate coordinates- **Curved walls** = polyline centerlines with many sample points- **Non-rectangular rooms** fully supported (any angles)## Modules| File | Purpose ||------|---------|| `floorplan/schema.py` | Pydantic data models โ `Wall`, `Opening`, `Room`, `FloorPlan`, `Correction` || `floorplan/geometry.py` | Computational geometry โ wall polygons, room detection, centerline ops || `floorplan/renderer.py` | SVG + PIL rendering for visual verification and overlay || `floorplan/parser.py` | VLM-based parsing with iterative correction loop |## Quick Start### Demo (no API key needed)```bashpip install pydantic shapely numpy pillowpython example.py --demo```Renders a 2-bedroom apartment with angled walls โ `output/demo_floorplan.png` + `.svg` + `.json`### Parse a real floor plan```bashpip install pydantic shapely numpy pillow openaipython example.py --image myfloorplan.png --api-key sk-...```Or with a local model (vLLM, Ollama, etc.):```bashpython example.py --image myfloorplan.png --base-url http://localhost:8000/v1 --model qwen2.5-vl-72b```### Python API```pythonfrom floorplan import FloorPlan, Wall, Opening, OpeningType, Point2Dfrom floorplan import build_rooms, render_to_image, render_floorplan_svg# Build a floor plan programmaticallywalls = [Wall(id="w1", centerline=[Point2D(x=0, y=0), Point2D(x=5, y=0)], thickness=0.24,openings=[Opening(id="d1", type=OpeningType.DOOR, start=1.0, length=0.9)]),5 unmodified linesrooms, room_polygons = build_rooms(walls)fp = FloorPlan(walls=walls, rooms=rooms)# Renderimg = render_to_image(fp, room_polygons=room_polygons)img.save("output.png")# Export SVGsvg = render_floorplan_svg(fp, room_polygons=room_polygons)# Serialize to JSONprint(fp.model_dump_json(indent=2))```### VLM parsing with correction loop```pythonfrom floorplan import parse_floorplanfp, room_polygons, overlays = parse_floorplan(image="floorplan.png",api_key="sk-...",model="gpt-4o",max_iterations=4,)# overlays contains the render-on-original images for each iterationfor i, overlay in enumerate(overlays):overlay.save(f"overlay_{i}.png")```## Features- โ **Wall thickness** โ not just centerlines- โ **Non-rectangular rooms** โ any angles- โ **Curved walls** โ polyline approximation- โ **Automatic room detection** โ from wall topology via Shapely- โ **Doors & windows** โ parametric on walls- โ **SVG + PNG rendering** โ dual output- โ **Overlay verification** โ rendered schema composited on original- โ **Iterative VLM correction** โ parse โ render โ compare โ correct โ repeat- โ **JSON serialization** โ full Pydantic roundtrip- โ **Field-level corrections** โ modify, add, delete walls/openings## Dependencies**Core** (always needed):- `pydantic` โ schema validation- `shapely` โ computational geometry- `numpy` โ array ops- `pillow` โ image rendering**VLM parsing** (optional):- `openai` โ for VLM API calls (works with any OpenAI-compatible endpoint)## License1234567824 unmodified lines333435363738394041424344454647484950515253545556575859603 unmodified lines646566676869707172737475767778798081828384858687888990915 unmodified lines979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155# ๐ Floor Plan Parser + 3D ReconstructionParse floor plan images into structured data โ walls with thickness, doors, windows, and automatically detected rooms. Then generate interactive 3D models.**๐ฎ Try it live:** [rikhoffbauer2/floorplan-3d](https://huggingface.co/spaces/rikhoffbauer2/floorplan-3d)## Architecture24 unmodified linesโ (VLM or human) โ outputs field-level correctionsโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผ converged? โโnoโโโ back to step 2yesโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 5. 3D RECONSTRUCTION โ Extrude walls, cut openings,โ (trimesh + manifold3d) โ add floors/ceilings โ GLBโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผInteractive 3D model (GLB/glTF)```## Modules| File | Purpose ||------|---------|| `floorplan/schema.py` | Pydantic data models โ `Wall`, `Opening`, `Room`, `FloorPlan`, `Correction` || `floorplan/geometry.py` | Computational geometry โ wall polygons, room detection, centerline ops || `floorplan/renderer.py` | SVG + PIL rendering for visual verification and overlay || `floorplan/parser.py` | VLM-based parsing with iterative correction loop || `floorplan/reconstruction.py` | **NEW** โ 3D mesh generation, boolean ops, GLB/OBJ export |## The Schema```json{3 unmodified lines"centerline": [{"x": 0, "y": 0}, {"x": 6, "y": 0}],"thickness": 0.24,"openings": [{"id": "win1", "type": "window", "start": 1.5, "length": 1.5}]}],"rooms": [{"id": "r1", "label": "bedroom","boundary": [{"wall_id": "w1", "side": "right"}, {"wall_id": "w2", "side": "left"}],"area": 16.0}]}```## Quick Start### Demo (no API key needed)```pythonfrom floorplan import *# Build a floor planwalls = [Wall(id="w1", centerline=[Point2D(x=0, y=0), Point2D(x=5, y=0)], thickness=0.24,openings=[Opening(id="d1", type=OpeningType.DOOR, start=1.0, length=0.9)]),5 unmodified linesrooms, room_polygons = build_rooms(walls)fp = FloorPlan(walls=walls, rooms=rooms)# 2D renderimg = render_to_image(fp, room_polygons=room_polygons)img.save("output.png")# 3D modelscene = generate_3d_model(fp, room_polygons=room_polygons)export_glb(scene, "model.glb") # Open in any 3D viewer or Three.js```### Parse a real floor plan with VLM```pythonfrom floorplan import parse_floorplan, generate_3d_model, export_glb# Parse image โ structured data (uses HF Inference API)fp, room_polygons, overlays = parse_floorplan(image="floorplan.png",api_key="hf_...",base_url="https://router.huggingface.co/v1",model="Qwen/Qwen2.5-VL-72B-Instruct",max_iterations=3,)# Generate 3Dscene = generate_3d_model(fp, room_polygons=room_polygons, pixels_per_meter=100)export_glb(scene, "model.glb")```## 3D OutputThe 3D reconstruction generates:- **Walls** โ extruded from 2D polygons, all walls boolean-unioned into a single watertight mesh- **Door openings** โ cut through walls via boolean subtraction + door frame meshes- **Window openings** โ cut at sill/head height + glass pane meshes- **Floor slabs** โ per room, with wood material- **Ceilings** โ per room, with white material- **PBR materials** โ walls (warm white), floors (light wood), ceilings (white), glass (translucent blue)Export formats: **GLB** (web/Three.js), **glTF**, **OBJ**## Dependencies**Core:**- `pydantic` โ schema validation- `shapely` โ computational geometry- `numpy` โ array ops- `pillow` โ image rendering**3D reconstruction:**- `trimesh[easy]` โ mesh generation, boolean ops, GLB export (includes manifold3d)**VLM parsing (optional):**- `openai` โ for VLM API calls## License
README.md+56-87