Turning a 2D floor plan into a walkable 3D home
The model only reads the plan into JSON. Plain code turns that JSON into walls, areas and a 3D scene, so every derived number comes from code.
Naksha 3D takes a 2D floor plan, the kind you get from a builder’s brochure, and turns it into a furnished 3D home you can walk through in a browser tab.
The obvious way to build that is to ask an AI model for the 3D scene. I did the opposite. The model does one narrow job, reading the drawing, and everything derived from that reading is ordinary code.
The split: read, then derive
There are two steps, and they have very different jobs.
- Read. A vision model looks at the image and returns JSON. Rooms are axis-aligned rectangles in metres, measured wall-centre to wall-centre. Doors and windows are a centre point, a width and the direction of the wall they sit on.
- Derive. A deterministic function takes that JSON and computes the walls, their types, where each opening cuts a wall, and the floor areas. The 3D viewer builds the scene from that result.
The model’s job is reading: it copies the printed room sizes, converts them to metres, and lays the rooms out in one coordinate frame. It never outputs a wall, a wall type or an area. Those are derived.
What the model is asked for
The prompt asks for exactly one JSON shape. This is the studio sample, abridged:
{
"name": "Studio apartment",
"rooms": [
{"name": "Balcony", "kind": "balcony",
"rects": [{"x": 0, "y": 0, "w": 3.6, "h": 1.2}]},
{"name": "Kitchenette", "kind": "kitchen",
"rects": [{"x": 0, "y": 3.6, "w": 2.4, "h": 2.1}]},
{"name": "Bath", "kind": "bath",
"rects": [{"x": 4.8, "y": 3.6, "w": 1.8, "h": 2.1}]}
],
"openings": [
{"type": "main_door", "x": 5.4, "y": 0, "w": 1.05, "dir": "h"},
{"type": "window", "x": 0, "y": 2.4, "w": 1.5, "dir": "v"}
]
}
A few rules in the prompt do most of the work:
- Read the printed dimensions. Indian plans often print sizes in feet and inches, like
12'0" X 10'6". The model converts them (1 ft = 0.3048 m) so each room has its real size. - Shared edges. Adjacent rooms must share edges exactly, with no gaps or overlaps. An L-shaped room is two rectangles with the same name.
- A small vocabulary.
kindis one of eleven values (bedroom, living, kitchen, bath, balcony, pooja and so on), and labels like TOILET or SIT-OUT are mapped onto them. - A way to say no. If the image isn’t a floor plan, the model returns no rooms and a note, instead of inventing a house.
Cleaning the reading
Model output is treated as untrusted input. Before anything is drawn, a sanitize step:
- caps the counts (40 rooms, 6 rectangles per room, 80 openings) and drops rectangles under 30 cm;
- catches unit mistakes: if the plan spans more than 45 “metres”, the numbers were almost certainly feet, so it rescales by 0.3048; anything still over 60 m is rejected;
- snaps every edge to a 5 cm grid, so edges that are almost equal become exactly equal.
The snapping matters more than it sounds. A model that writes 3.6 for one edge and 3.62 for its neighbour means the same line, and after snapping it is the same line. A bigger disagreement doesn’t disappear: it shows up as a visible gap in the plan, which is exactly what you want to see and fix.
Deriving walls from rectangles
This is the core idea, and it’s simpler than it looks. The layout function paints every room onto a 5 cm grid, so each cell knows which room it belongs to, or that it’s outside.
Then it walks every grid line. Wherever the cells on the two sides of a line belong to different rooms, there’s a wall. The type comes from what’s on each side:
| Left / right of the line | Wall type | Thickness used |
|---|---|---|
| Room and outside | Exterior | 23 cm |
| Balcony and outside | Parapet | Low wall, 1.05 m high |
| Room and a different room | Interior | 12 cm |
| Same room on both sides | No wall | — |
Consecutive cells of the same type merge into one wall run. For the studio sample that gives 12 runs. Nobody drew them, and the model never mentioned them.
Openings work the same way. Each door or window snaps to the nearest wall line in its direction, within 45 cm. It’s trimmed so it stays 6 cm clear of the wall’s ends, and dropped if less than 30 cm is left. That stops a slightly misplaced window from floating in a room.
From walls to a 3D scene
The viewer turns each wall run into boxes: 2.9 m tall, with gaps cut where openings sit. Doors get a 2.1 m head height. Windows sit on a sill at about 0.9 m and get a frame and glass. Floors get a finish by room kind, so a bath and a bedroom don’t look the same.
Because the walls are data, the same model drives every view: a dollhouse cut at 1.2 m, a top-down plan, and a first-person walk with collisions against the walls.
Areas: the number buyers actually ask about
Once walls have thicknesses, the code can produce an approximate area statement. These are my approximations of the terms on a builder’s brochure, not a legal definition. Carpet area counts the rooms (not the balcony), minus the part of the exterior walls inside each room’s wall-centre rectangle. Built-up area adds the balcony and the exterior walls back.
These are estimates from a drawing, not a surveyed figure. But they’re computed, so they’re consistent: change one rectangle and every number moves with it.
Why this split works
- Mistakes are visible. If the model misreads a room, you see a wrong rectangle and fix that rectangle. You don’t have to debug a mesh.
- Same input, same house. The derive step has no randomness, so a fix stays fixed.
- One model call. Each plan costs a single model call. Everything after it is plain code, with no further AI cost.
- Testable. A script checks the sample plans without calling any model: overlaps, sliver gaps, openings that miss their wall, rooms you can’t reach from the main door, and bedrooms, living, dining or kitchen spaces without a window.
The general lesson: let the model read and let code compute. Models are good at turning a messy drawing into structure. Geometry and areas you can check are better done by code you can test.

