Skip to content
 
 

Repository files navigation

Floorplan → 3D Model 🏗️

Turn a 2D floorplan image into a 3D model (.obj / .stl) you can open in any 3D viewer or slicer.

The working pipeline is built around a deep-learning floorplan parser (CubiCasa5K) that understands walls and rooms, plus a small set of scripts that extrude the detected geometry into clean 3D. A classical OpenCV route (FloorplanToBlender3d, via Docker) is kept as a fallback. Everything runs locally on CPU — no GPU required.

Results

Floorplan Detection overlay 3D model
Unit C1 c1 overlay c1 3d
2d-model 2d overlay 2d 3d

The overlay (detected walls/rooms drawn on the source) is the accuracy check; the 3D is the extruded model. Outputs live in Target/.obj, .stl, and preview PNGs.

Recommended pipeline (CubiCasa5K, accurate)

The CubiCasa model + weights + venv are heavy and git-ignored — set them up once via SETUP_CUBICASA.md. Then, for any floorplan image:

# 1) segment walls/rooms (neural net, CPU ~2 min) -> saves *_vectors.pkl + *_overlay.png
cd cubicasa/CubiCasa5k
../.venv/bin/python cubi_infer.py <image> out/<name> 1024
cd ../..

# 2) extrude the clean vector geometry into a connected 3D wall shell + room floors
cubicasa/.venv/bin/python poly_to_obj.py cubicasa/CubiCasa5k/out/<name>_vectors.pkl Target/<name>.obj

# 3) convert to STL (pure Python, no deps)
python3 obj_to_stl.py Target/<name>.obj Target/<name>.stl

Scripts

  • cubi_infer.py — CubiCasa inference on one image → room/wall segmentation, clean vector geometry (*_vectors.pkl), and a diagnostic overlay. (Run from inside the CubiCasa5k clone; see SETUP.)
  • poly_to_obj.py — extrudes the vector geometry: unions wall rectangles into one connected shell (seamless corners, capped top/bottom) and builds per-room floor slabs.
  • obj_to_stl.py — Wavefront OBJ → binary STL (triangulates faces).
  • render_obj.py — quick matplotlib preview of an OBJ.

Alternative: Docker (FloorplanToBlender3d, classical CV)

The original OpenCV route works via the upstream prebuilt image (its bundled Blender crashes under x86 emulation on Apple Silicon, so floorplan_to_obj.py exports geometry directly, skipping Blender):

docker build --platform linux/amd64 -f Dockerfile.patch -t ftb-patched .
docker run --rm --platform linux/amd64 \
  -v "$PWD/floorplan_to_obj.py":/home/floorplan_to_blender/floorplan_to_obj.py \
  -v "$PWD/your.jpg":/home/floorplan_to_blender/Images/your.jpg \
  -v "$PWD/Target":/home/floorplan_to_blender/Target \
  -w /home/floorplan_to_blender --entrypoint python3.8 ftb-patched \
  floorplan_to_obj.py --walls-only Images/your.jpg Target/your.obj

Results are far rougher than the CubiCasa pipeline — kept only for reference.

Known limitations

  • CPU inference takes a couple of minutes per image.
  • Scale is proportional, not metric (no automatic real-world dimensions yet).
  • Doorways aren't cut — CubiCasa reports 0 door/window openings on these arc-style plans, so walls stay continuous. poly_to_obj.py subtracts openings automatically whenever the model does detect them.
  • Detection quality depends on input resolution (~800–1024px works best) and a reasonably clean floorplan.

👤 Authors

Parth Bhandakkar – B.Tech ECE @ IIIT Naya Raipur — GitHub Srijan Ratrey – B.Tech AI/DS @ IIIT Naya Raipur — GitHub

📄 License

MIT License – see LICENSE file for details.

Credits

Model: CubiCasa5K (Kalervo et al., 2019). Classical route: FloorplanToBlender3d.

About

Built a prototype that generates simple 3D models (.obj/.stl) from reference images using open-source AI models. Combines deep learning with geometry processing for creative design workflows.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages