Build your own house: walls, windows, doors, floors, roof, stairs, furniture
Deploy web Studio / deploy (push) Successful in 3m27s

House parts (stdlib isokit/house): house_wall drawn along a line, with ends
that adapt at corners, T-junctions and straight runs so no two walls
overlap; window and door that sit on a wall and cut its opening (door
styles panel, glass, double, sliding, opening; swing and hinge by
rotation); floor (boards, tiles, carpet, stone); roof (hip, gable, flat,
optional solar); stairs.

Furniture (stdlib isokit/furniture): chair, sofa / armchair, table with
chairs, desk with monitor and chair, TV, bed, cupboard, bookshelf, kitchen
run, bathtub, shower, toilet, washbasin, plant, rug, floor lamp.

Cut-open levels: on gf / 1f the walls in front of a room are cut low
(rooms are found by their floors), the roof becomes an outline on the
floor, and storeys above are left out. A part's storey comes from z
(storey_h, default 3 m).

Scripting: objects_of, objects_at, objects_on, mount_of, mounted, frame,
to_world, to_local, local_of. Prefab meta: shape (line / rect), mount,
storey.

Studio: drag to draw lines and rectangles (walls, roads, fences, hedges,
floors, areas, buildings, roofs). The Room tool draws a floor plus walls,
without doubling walls that already stand on an edge. Windows and doors
snap onto walls with a hover preview, and they move, turn, copy and
delete with their wall in one undo step. New parts land on the storey
the view shows. Palette categories collapse, and the palette scrolls
apart from the object list.

The MCP instructions explain house building, and list_prefabs shows
sits_on. examples/house is a furnished bungalow; the web Studio gets a
House demo button. Tests: wall corners and junctions, zero depth-sort
cycles in every view, cut levels, and the house demo in every view;
check_studio covers the room / window / door / storey flow, check_web
the House demo.
This commit is contained in:
grabowski committed 2026-10-24 17:39:04 +07:00
1 parent 84309a7a08
commit 95ea4a8512
26 files changed
+2137 -64

No files matched your search

+201
View File
@@ -290,3 +290,204 @@ fn cfg_reaches_the_script() {
let b = r.build("site", 0, &c, &Doc::default()).unwrap();
assert_eq!(b.scene.layers[2].sprites[0].world_box().unwrap()[5], 9.0);
}
/// A 4 x 3 m room: floor, four walls on its edges, a window and a door.
fn room_doc() -> Doc {
let mut doc = Doc::default();
doc.objects
.push(obj("floor", "floor", 0.0, 0.0, json!({"w": 4, "d": 3})));
for (id, x, y, rot, w) in [
("south", 0.0, -1.5, 0.0, 4.0),
("north", 0.0, 1.5, 0.0, 4.0),
("west", -2.0, 0.0, 90.0, 3.0),
("east", 2.0, 0.0, 90.0, 3.0),
] {
let mut o = obj(id, "house_wall", x, y, json!({ "w": w }));
o.rot = rot;
doc.objects.push(o);
}
// a little off the wall line: still on the south wall
doc.objects
.push(obj("win", "window", 0.5, -1.4, json!({"w": 1.2})));
let mut door = obj("door", "door", 2.05, 0.4, json!({"open": true}));
door.rot = 90.0;
doc.objects.push(door);
doc
}
fn sprites_of(b: &crate::Built, id: &str) -> usize {
b.scene
.layers
.iter()
.flat_map(|l| l.sprites.iter())
.filter(|s| s.obj.as_deref() == Some(id))
.count()
}
#[test]
fn windows_and_doors_sit_on_walls() {
let r = Runtime::new(&Bundle::default()).unwrap();
let doc = room_doc();
let b = r.build("site", 0, &cfg(), &doc).unwrap();
assert!(b.scene.warnings.is_empty(), "{:?}", b.scene.warnings);
// the window snaps onto the south wall's line and the wall leaves a gap
let w = b.boxes["win"];
assert!(
(w[1] + 1.575).abs() < 1e-6 && (w[4] + 1.425).abs() < 1e-6,
"{w:?}"
);
assert!(
(w[0] + 0.1).abs() < 1e-6 && (w[3] - 1.1).abs() < 1e-6,
"{w:?}"
);
assert_eq!(sprites_of(&b, "south"), 2, "wall split around the window");
assert_eq!(sprites_of(&b, "north"), 1);
assert_eq!(sprites_of(&b, "east"), 2, "wall split around the door");
// the open door swings into the room (rot 90 on a rot 90 wall: towards -x)
let d = b.boxes["door"];
assert!(d[0] < 1.5 && d[3] <= 2.08, "{d:?}");
let html = render(&b.scene, 0, &RenderOpts::default()).html;
assert!(html.contains("iso-glassp"));
// corners: the walls along x run through, the others stop at their faces
let (sw, ww) = (b.boxes["south"], b.boxes["west"]);
assert!(
(sw[0] + 2.075).abs() < 1e-6 && (sw[3] - 2.075).abs() < 1e-6,
"{sw:?}"
);
assert!(
(ww[1] + 1.425).abs() < 1e-6 && (ww[4] - 1.425).abs() < 1e-6,
"{ww:?}"
);
for rot in 0..4u8 {
for lv in ["site", "gf"] {
let b = r.build(lv, rot, &cfg(), &doc).unwrap();
let out = render(&b.scene, rot, &RenderOpts::default());
assert_eq!(out.cycles, 0, "{lv}/{rot}: depth-sort cycles");
}
}
// moved off every wall, the window stands alone as a wall piece
let mut alone = doc.clone();
alone.get_mut("win").unwrap().y = -5.0;
let b = r.build("site", 0, &cfg(), &alone).unwrap();
assert_eq!(sprites_of(&b, "south"), 1);
assert!((b.boxes["win"][5] - 2.8).abs() < 1e-6);
}
#[test]
fn walls_meeting_at_a_t_or_in_line_do_not_overlap() {
let r = Runtime::new(&Bundle::default()).unwrap();
let mut doc = room_doc();
let mut inner = obj("inner", "house_wall", 0.0, 0.0, json!({"w": 3.0, "t": 0.1}));
inner.rot = 90.0;
doc.objects.push(inner);
// the north wall in two pieces meeting at x = 1
doc.get_mut("north").unwrap().props = json!({"w": 3.0}).as_object().cloned().unwrap();
doc.get_mut("north").unwrap().x = -0.5;
doc.objects
.push(obj("north2", "house_wall", 1.5, 1.5, json!({"w": 1.0})));
let b = r.build("site", 1, &cfg(), &doc).unwrap();
let i = b.boxes["inner"];
assert!(
(i[1] + 1.425).abs() < 1e-6 && (i[4] - 1.425).abs() < 1e-6,
"{i:?}"
);
let (n1, n2) = (b.boxes["north"], b.boxes["north2"]);
assert!(
(n1[3] - 1.0).abs() < 1e-6 && (n2[0] - 1.0).abs() < 1e-6,
"{n1:?} {n2:?}"
);
assert!((n1[0] + 2.075).abs() < 1e-6 && (n2[3] - 2.075).abs() < 1e-6);
}
#[test]
fn cut_levels_lower_the_walls_in_front_of_rooms() {
let r = Runtime::new(&Bundle::default()).unwrap();
let mut doc = room_doc();
doc.objects
.push(obj("roof", "roof", 0.0, 0.0, json!({"w": 4.15, "d": 3.15})));
let mut up = obj("chair", "chair", 0.0, 0.0, json!({}));
up.z = 3.0;
doc.objects.push(up);
for rot in 0..4u8 {
let site = r.build("site", rot, &cfg(), &doc).unwrap();
let gf = r.build("gf", rot, &cfg(), &doc).unwrap();
let tops = |b: &crate::Built| -> Vec<f64> {
["south", "north", "west", "east"]
.iter()
.map(|id| b.boxes[*id][5])
.collect()
};
assert!(tops(&site).iter().all(|z| (z - 2.8).abs() < 1e-6));
// two walls face the viewer: cut low; the two behind the room stay full
let t = tops(&gf);
let low = t.iter().filter(|z| (*z - 1.0).abs() < 1e-6).count();
let full = t.iter().filter(|z| (*z - 2.8).abs() < 1e-6).count();
assert_eq!((low, full), (2, 2), "rotation {rot}: {t:?}");
// the roof is a full roof on the site level, an outline when cut open
assert!(site.boxes["roof"][5] > 4.0);
assert!(
(gf.boxes["roof"][5] - 0.02).abs() < 1e-6,
"outline on the floor"
);
// the chair on the first floor: left out on GF, there on 1F
assert!(!gf.boxes.contains_key("chair"));
let f1 = r.build("1f", rot, &cfg(), &doc).unwrap();
assert!(f1.boxes.contains_key("chair"));
assert!(f1.boxes["south"][5] > 2.7, "GF closed below the cut storey");
assert!(gf.scene.warnings.is_empty(), "{:?}", gf.scene.warnings);
}
}
#[test]
fn object_queries_and_frames() {
let r = rt(r#"
let s = objects_of("floor");
let a = objects_at(["floor"], 1.9, 1.4);
let b = objects_at(["floor"], 2.1, 0.0);
let w = objects_of("house_wall")[3];
frame(w);
let p = to_world(1.0, 0.5);
let q = to_local(p[0], p[1]);
let m = mount_of(objects_of("door")[0], ["house_wall"]);
let on = mounted(w, ["window", "door"], ["house_wall"]);
frame(0, 0, 0, 0);
sprite("probe").box(0, 0, s.len(), a.len() + b.len() * 10, 0, 1, "wall");
sprite("frame").box(p[0], p[1], p[0] + q[0], p[1] + q[1], 0, 1, "wall");
sprite("mount").box(0, 0, m.u + 10.0, on.len(), 0, m.v + 10.0, "wall");
"#);
let b = r.build("site", 0, &cfg(), &room_doc()).unwrap();
let probe = b.scene.layers[2]
.sprites
.iter()
.find(|s| s.id == "probe")
.unwrap()
.world_box()
.unwrap();
assert_eq!(
(probe[3], probe[4]),
(1.0, 1.0),
"one floor, holding one point"
);
let f = b.scene.layers[2]
.sprites
.iter()
.find(|s| s.id == "frame")
.unwrap()
.world_box()
.unwrap();
// east wall at (2, 0) turned 90: local (1, 0.5) is world (1.5, 1)
assert_eq!([f[0], f[1], f[3], f[4]], [1.5, 1.0, 2.5, 1.5]);
let m = b.scene.layers[2]
.sprites
.iter()
.find(|s| s.id == "mount")
.unwrap()
.world_box()
.unwrap();
// the door at (2.05, 0.4) is 0.4 along the east wall, 0.05 off it
assert!(
(m[3] - 10.4).abs() < 1e-9 && (m[5] - 9.95).abs() < 1e-9,
"{m:?}"
);
assert_eq!(m[4], 1.0, "one opening on the east wall");
}