Skip to content

Wall with Door and Window ​

Wall with Door and Window, rendered in the brepjs playground
BIM · 177 lines▶ Run it in the playground

The outer wall of a house as a BIM model: an IfcWall that hosts a door and a window in a project, site, building and storey structure. Each opening is a void that the model cuts into the wall solid, and the view shows the three layers of the cavity wall. The brick, the wall layers, the door leaf and the lintel bearing are published figures, and the kernel measures the wall volume against the box less the two voids. The openings, the window, the frames and the ground are a display model.

Code ​

This is the full program. The playground runs it in your browser without a change.

ts
import { BimModel, placedSolids, toIfc } from 'brepjs-bim';
import { box, clone, compound, cutAll, cylinder, extrude, fuseAll, getSolids, intersect, measureVolume, polygon, rotate, unwrap } from 'brepjs/quick';
import { color, present } from 'brepjs/playground';

// Outer wall of a house as a BIM model: an IfcWall that hosts a door and a window. Each opening is a void that
// the model cuts into the wall solid. The brick, the wall layers, the door leaf and the lintel bearing are
// published figures. The openings, the window, the frames and the ground are a display model.
// Units are millimetres. The wall runs along Y, its outer face is at x = 0 and the room is on the -X side.
interface WallParams {
  doorOpen?: number; // degrees that the door leaf swings into the room
  windowOpen?: number; // degrees that the casement swings out
  length?: number; // length of the wall
}

// ---- published figures
const BRICK = { length: 215, width: 102.5, height: 65, joint: 10 }; // with its joint a brick takes 225 x 75 of the face
// Cavity wall, from the outside: a brick leaf, a cavity with insulation, a block leaf.
const LAYERS = [{ name: 'Facing brick', thicknessMm: 102.5 }, { name: 'Cavity with insulation', thicknessMm: 100 }, { name: 'Concrete block', thicknessMm: 100 }];
const LEAF = { width: 926, height: 2040, thickness: 44 }; // a standard door leaf
const LINTEL = { bearing: 150, courses: 3 };

// ---- display model
const COURSE = BRICK.height + BRICK.joint, EACH_M2 = 1e6 / ((BRICK.length + BRICK.joint) * COURSE), T = LAYERS.reduce((sum, layer) => sum + layer.thicknessMm, 0);
const HEIGHT = 36 * COURSE; // 2700
const DOOR = { opening: [1010, 2110], leaf: [LEAF.width, LEAF.height], leafT: LEAF.thickness, handle: 1000 }; // width, height
const WINDOW = { opening: [1810, 1350], sill: 12 * COURSE, frame: 70, depth: 70, sash: 50, glass: 24 };
const FRAME = { depth: 95, back: 60 }; // door frame, and how far the frames are behind the outer face
const COLORS = { wall: '#c97f5f', insulation: '#e3c65a', block: '#b9b5aa', stone: '#d8d2c4', frame: '#f5f2ea', leaf: '#12b5b0', glass: '#9fc3d4', metal: '#d3a956', floor: '#a8a294', ground: '#7d786f' };
type Tone = keyof typeof COLORS;
type P3 = [number, number, number];
type Body = ReturnType<typeof box>;
type Id = Extract<ReturnType<BimModel['addWall']>, { ok: true }>['value']; // the id of an element in the model
const Y: P3 = [0, 1, 0], Z: P3 = [0, 0, 1];

function wallModel({ doorOpen = 50, windowOpen = 25, length = 4500 }: WallParams = {}) {
  const model = new BimModel(), owned: { delete(): void }[] = [];
  const own = <T extends { delete(): void }>(s: T): T => { owned.push(s); return s; };
  try {
    model.init({ name: 'Wall example' });
    // The spatial structure makes this a BIM model: project, site, building, storey.
    const project = model.getProject();
    const site = unwrap(model.addSite({ name: 'Site' }));
    const building = unwrap(model.addBuilding({ name: 'House' }));
    const storey = unwrap(model.addStorey({ name: 'Ground floor', elevation: 0 }));
    if (project) model.aggregate(project.localId, site);
    model.aggregate(site, building);
    model.aggregate(building, storey);
    const tones = new Map<Id, Tone>();
    const put = (tone: Tone, made: ReturnType<BimModel['addWall']>): Id => {
      const id = unwrap(made);
      model.placeIn(id, storey);
      tones.set(id, tone);
      return id;
    };

    // The wall. Its thickness goes to the left of axisX, so a wall along +Y is thick toward -X.
    const wall = put('wall', model.addWall({ length, height: HEIGHT, thickness: T, origin: [0, 0, 0], axisX: Y, axisZ: Z, materialName: 'Brick', materialLayers: LAYERS, layerSetName: 'Cavity wall', isExternal: true, loadBearing: true }));
    // The door and the window name their host wall. The model cuts a void for each, and the IFC file relates
    // wall, void and filling. A door and a window have no solid of their own in this library.
    const doorAt = 550, windowAt = length - WINDOW.opening[0]! - 550;
    put('frame', model.addDoor({ wallLocalId: wall, width: DOOR.opening[0]!, height: DOOR.opening[1]!, offsetAlongWall: doorAt, offsetFromFloor: 0, materialName: 'Timber', isExternal: true }));
    put('frame', model.addWindow({ wallLocalId: wall, width: WINDOW.opening[0]!, height: WINDOW.opening[1]!, offsetAlongWall: windowAt, offsetFromFloor: WINDOW.sill, materialName: 'Timber', isExternal: true }));

    // A lintel over each opening carries the wall. It bears 150 mm on each side.
    const lintelDepth = LINTEL.courses * COURSE;
    const lintel = (at: number, width: number, z: number): Id => put('stone', model.addBeam({
      length: width + 2 * LINTEL.bearing, profile: { kind: 'RECTANGULAR', width: T, height: lintelDepth },
      origin: [-T / 2, at - LINTEL.bearing, z + lintelDepth / 2], axisX: Y, axisZ: Z, predefinedType: 'LINTEL', materialName: 'Precast concrete',
    }));
    const lintels = [lintel(doorAt, DOOR.opening[0]!, DOOR.opening[1]!), lintel(windowAt, WINDOW.opening[0]!, WINDOW.sill + WINDOW.opening[1]!)];
    // The floor of the room, and the ground outside: 150 mm lower.
    put('floor', model.addSlab({ length: T + 1500, width: length, thickness: 200, origin: [-T - 1500, 0, -200], axisX: [1, 0, 0], axisZ: Z, predefinedType: 'FLOOR', materialName: 'Concrete' }));
    put('ground', model.addSlab({ length: 900, width: length, thickness: 50, origin: [0, 0, -200], axisX: [1, 0, 0], axisZ: Z, predefinedType: 'BASESLAB', materialName: 'Paving' }));

    furnish(model, put, own, { doorAt, windowAt, doorOpen, windowOpen });

    // The view. placedSolids() gives each element in its place, as the IFC file has it. The wall comes with its
    // voids. The view cuts the seat of each lintel out of the wall, splits the wall into its three layers and
    // marks the bed joints of the brick leaf.
    const groups: Record<Tone, Body[]> = { wall: [], insulation: [], block: [], stone: [], frame: [], leaf: [], glass: [], metal: [], floor: [], ground: [] };
    const all = new Map(model.getAllElements().map((el) => [el.localId, el]));
    const seats = lintels.flatMap((id) => unwrap(placedSolids(all.get(id)!)).map((body) => own(body)));
    let net = 0;
    for (const [id, el] of all) {
      const tone = tones.get(id);
      if (!tone) continue;
      const placed = unwrap(placedSolids(el)).map((body) => own(body));
      if (id === wall) {
        net = unwrap(measureVolume(placed[0]!));
        const seated = own(unwrap(cutAll(placed[0]!, seats)));
        const leaf = (from: number, to: number) => own(unwrap(intersect(seated, own(box(to - from, length + 2, HEIGHT + 2, { at: [-(from + to) / 2, length / 2, HEIGHT / 2] })))));
        const [brick, cavity] = [LAYERS[0]!.thicknessMm, LAYERS[1]!.thicknessMm];
        const joints = Array.from({ length: HEIGHT / COURSE - 1 }, (_, i) => own(box(8, length + 2, BRICK.joint, { at: [0, length / 2, (i + 1) * COURSE - BRICK.joint / 2] })));
        groups.wall.push(own(unwrap(cutAll(leaf(0, brick), joints))));
        groups.insulation.push(leaf(brick, brick + cavity));
        groups.block.push(leaf(brick + cavity, T));
      } else groups[tone].push(...placed);
    }
    const shown = (Object.keys(COLORS) as Tone[]).filter((tone) => groups[tone].length > 0).map((tone) => color(compound(groups[tone]), COLORS[tone]));
    const voids = (DOOR.opening[0]! * DOOR.opening[1]! + WINDOW.opening[0]! * WINDOW.opening[1]!) * T;
    return { model, shown, net, byHand: length * HEIGHT * T - voids, bricks: Math.round(net / T / 1e6 * EACH_M2) };
  } catch (error) {
    model[Symbol.dispose]();
    throw error;
  } finally {
    owned.splice(0).forEach((body) => body.delete());
  }
}

// The door set, the window, the sill and the step. Each part is a proxy in the storey.
function furnish(
  model: BimModel,
  put: (tone: Tone, made: ReturnType<BimModel['addWall']>) => Id,
  own: <T extends { delete(): void }>(s: T) => T,
  at: { doorAt: number; windowAt: number; doorOpen: number; windowOpen: number },
): void {
  // A boolean gives a compound, and a proxy takes a solid: one() copies the solid out.
  const one = (shape: Parameters<typeof getSolids>[0]): Body => unwrap(clone(getSolids(own(shape))[0]!)) as Body;
  const part = (tone: Tone, name: string, solid: Body, materialName: string): Id => put(tone, model.addProxy({ name, solid, materialName }));
  const block = (x0: number, x1: number, y0: number, y1: number, z0: number, z1: number): Body => box(x1 - x0, y1 - y0, z1 - z0, { at: [(x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2] });
  const ring = (x0: number, x1: number, y0: number, y1: number, z0: number, z1: number, rim: number): Body =>
    one(unwrap(cutAll(own(block(x0, x1, y0, y1, z0, z1)), [own(block(x0 - 1, x1 + 1, y0 + rim, y1 - rim, z0 + rim, z1 - rim))])));
  const swing = (body: Body, degrees: number, pivot: P3): Body => (degrees === 0 ? body : rotate(own(body), degrees, { at: pivot, axis: Z }));

  // The door set: a frame of two jambs and a head, a threshold, and a leaf on three hinges.
  const [ow, oh] = [DOOR.opening[0]!, DOOR.opening[1]!], [lw, lh] = [DOOR.leaf[0]!, DOOR.leaf[1]!];
  const y0 = at.doorAt, y1 = y0 + ow, jamb = (ow - lw) / 2 - 2, sillH = 15, head = oh - sillH - lh - 6;
  const xo = -FRAME.back, xi = xo - FRAME.depth;
  const frame = one(unwrap(fuseAll([own(block(xi, xo, y0, y0 + jamb, 0, oh)), own(block(xi, xo, y1 - jamb, y1, 0, oh)), own(block(xi, xo, y0 + jamb, y1 - jamb, oh - head, oh))])));
  part('frame', 'Door frame', frame, 'Timber');
  part('metal', 'Threshold', block(xi, xo + 20, y0 + jamb, y1 - jamb, 0, sillH), 'Aluminium');
  // The leaf is flush with the inner face of the frame. It turns on the hinge barrels, on the room side of the jamb.
  const hinge: P3 = [xi - 7, y1 - jamb - 2, 0], z0 = sillH + 3, edge = hinge[1] - lw;
  const panels = [0, 1].flatMap((j) => [0, 1].map((k) => own(block(xi + DOOR.leafT - 8, xi + DOOR.leafT + 1, edge + 110 + j * (lw - 110) / 2, edge + (j + 1) * (lw - 110) / 2, z0 + 180 + k * 760, z0 + 180 + k * 760 + (k === 0 ? 640 : 520)))));
  const lite = own(block(xi - 1, xi + DOOR.leafT + 1, edge + 190, edge + lw - 190, z0 + 1560, z0 + lh - 180));
  // A lever handle on each face, on one spindle through the leaf.
  const hy = edge + 65, hz = DOOR.handle;
  const spindle = own(cylinder(9, DOOR.leafT + 110, { at: [xi - 55, hy, hz], axis: [1, 0, 0] }));
  const leaf = one(unwrap(cutAll(own(block(xi, xi + DOOR.leafT, edge, edge + lw, z0, z0 + lh)), [...panels, lite, spindle])));
  const lever = one(unwrap(fuseAll([
    spindle,
    own(cylinder(26, 8, { at: [xi - 8, hy, hz], axis: [1, 0, 0] })), own(cylinder(26, 8, { at: [xi + DOOR.leafT, hy, hz], axis: [1, 0, 0] })),
    own(block(xi - 55, xi - 39, hy - 8, hy + 120, hz - 8, hz + 8)), own(block(xi + DOOR.leafT + 39, xi + DOOR.leafT + 55, hy - 8, hy + 120, hz - 8, hz + 8)),
  ])));
  part('leaf', 'Door leaf', swing(leaf, -at.doorOpen, hinge), 'Timber, painted');
  part('glass', 'Door glazing', swing(block(xi + 12, xi + DOOR.leafT - 12, edge + 190, edge + lw - 190, z0 + 1560, z0 + lh - 180), -at.doorOpen, hinge), 'Glass');
  part('metal', 'Lever handle', swing(lever, -at.doorOpen, hinge), 'Brass');
  for (const z of [z0 + 150, z0 + lh / 2, z0 + lh - 250]) part('metal', 'Hinge', cylinder(7, 100, { at: [hinge[0], hinge[1], z] }), 'Brass');

  // The window: a frame with a mullion, a fixed light and a casement that opens out. A stone sill is under it.
  const [ww, wh] = [WINDOW.opening[0]!, WINDOW.opening[1]!], w0 = at.windowAt, w1 = w0 + ww, s0 = WINDOW.sill, sillT = COURSE;
  const fo = -FRAME.back, fi = fo - WINDOW.depth, f = WINDOW.frame, mid = (w0 + w1) / 2;
  const sill = own(unwrap(polygon([[-T + 0, w0, s0], [fo + 135, w0, s0], [fo + 135, w0, s0 + 30], [fo, w0, s0 + sillT], [-T, w0, s0 + sillT]])));
  part('stone', 'Window sill', unwrap(extrude(sill, [0, ww, 0])) as Body, 'Cast stone');
  const outer = own(block(fi, fo, w0, w1, s0 + sillT, s0 + wh));
  const lights = [own(block(fi - 1, fo + 1, w0 + f, mid - f / 2, s0 + sillT + f, s0 + wh - f)), own(block(fi - 1, fo + 1, mid + f / 2, w1 - f, s0 + sillT + f, s0 + wh - f))];
  part('frame', 'Window frame', one(unwrap(cutAll(outer, lights))), 'Timber');
  const g0 = (fi + fo) / 2 - WINDOW.glass / 2, g1 = g0 + WINDOW.glass;
  part('glass', 'Fixed glazing', block(g0, g1, w0 + f, mid - f / 2, s0 + sillT + f, s0 + wh - f), 'Glass');
  // The casement fills the other light. It hangs on the jamb at w1 and swings out.
  const c0 = mid + f / 2 + 3, c1 = w1 - f - 3, cz0 = s0 + sillT + f + 3, cz1 = s0 + wh - f - 3, pivot: P3 = [fo, c1, 0];
  const sash = ring(fo - 56, fo, c0, c1, cz0, cz1, WINDOW.sash);
  part('frame', 'Casement', swing(sash, at.windowOpen, pivot), 'Timber');
  part('glass', 'Casement glazing', swing(block(fo - 40, fo - 40 + WINDOW.glass, c0 + WINDOW.sash, c1 - WINDOW.sash, cz0 + WINDOW.sash, cz1 - WINDOW.sash), at.windowOpen, pivot), 'Glass');
  part('metal', 'Casement stay', swing(block(fo - 70, fo - 56, c0 + 15, c0 + 35, (cz0 + cz1) / 2 - 60, (cz0 + cz1) / 2 + 60), at.windowOpen, pivot), 'Brass');
  // A step at the door, on the ground.
  part('stone', 'Door step', block(0, 450, y0 - 150, y1 + 150, -150, -10), 'Cast stone');
}

// Try wallModel({ doorOpen: 90 }), wallModel({ windowOpen: 0 }) or wallModel({ length: 6000 }).
const scene = wallModel();
console.log('Wall: the kernel measures ' + (scene.net / 1e9).toFixed(3) + ' m3. The box less the two voids is ' + (scene.byHand / 1e9).toFixed(3) + ' m3. At ' + EACH_M2.toFixed(1) + ' bricks for each m2 of face, the outer leaf takes about ' + scene.bricks + ' bricks.');
// The tree panel shows the IFC structure. The IFC button saves the model as a file.
export default present(scene.shown, {
  bimTree: scene.model.toTreeSummary(),
  ifc: async () => unwrap(await toIfc(scene.model, { applicationName: 'brepjs playground', applicationVersion: '1.0' })),
});

Functions used ​

placedSolids toIfc box clone compound cutAll cylinder extrude fuseAll getSolids intersect measureVolume polygon rotate unwrap color present

▶ Run Wall with Door and Window in the playground

Released under the Apache 2.0 License.