Skip to content

Finishes and Access ​

Finishes and Access, rendered in the brepjs playground
BIM · 168 lines▶ Run it in the playground

The finishes of one corner of a building, cut back layer by layer: the floor, the walls, the ceiling and the roof are built up from separate IfcCovering elements, each with its own material and thickness on the slab or the wall that it covers. A 1:15 entrance ramp with a landing, two steps and a posted guardrail gives access. The ramp limits, the step rise, the conductivities and the U-value limits are published figures, and the kernel measures the area of each covering. The room and the build-ups 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, compound, intersect, measureVolume, unwrap } from 'brepjs/quick';
import { color, present } from 'brepjs/playground';

// The finishes of one corner of a building, peeled back layer by layer, and its entrance ramp.
// Each layer of the floor, the walls and the roof is an IfcCovering with its own material and thickness,
// on the slab or the wall that it covers. Units are millimetres. Z is up, and z = 0 is the finished floor.
interface FinishParams {
  peel?: number; // how far the view cuts each layer back from the layer under it. 0 shows the model whole
  rise?: number; // height of the floor above the ground: the ramp climbs it at 1:15
}

// ---- published figures
const RAMP = { gradient: 15, longest: 5000, width: 1500, landing: 1200 }; // a 1:15 ramp: 5 m long at most, 1.5 m wide, landings of 1.2 m or more
const STEP = { rise: 170 }; // largest rise of an outside step
const LIMIT = { wall: 0.26, roof: 0.16 }; // largest U-value of a new wall and roof, W/m2K
const LAMBDA = { mineralWool: 0.038, pir: 0.025, concrete: 2.3, block: 1.63, plaster: 0.46 }; // conductivity, W/mK
const SURFACE = { inside: 0.13, outside: 0.04, insideUp: 0.1 }; // surface resistance, m2K/W

// ---- display model
const ROOM = { x: 6000, y: 4500, clear: 2700, void: 285 };
// Each build-up from the structure outward: material, thickness, and the tint in the view.
const FLOOR = { slab: 250, layers: [['PIR insulation', 100, '#e9d98a'], ['Sand and cement screed', 65, '#c9c4b8'], ['Oak boards', 18, '#b98a5a']] as const };
const WALL = { block: 140, inside: [['Gypsum plaster', 13, '#f5f2ea']] as const, outside: [['Mineral wool slab', 150, '#d9b44a'], ['Timber batten', 38, '#8a6f52'], ['Fibre cement panel', 12, '#12b5b0']] as const };
const ROOF = { slab: 200, layers: [['PIR roof board', 160, '#e9d98a'], ['Bitumen membrane', 8, '#48515c']] as const, ceiling: ['Mineral fibre tile', 15, '#f5f2ea'] as const };
const CONCRETE = '#a8a294', BLOCK = '#bdb7aa';

type P3 = [number, number, number];
type Body = ReturnType<typeof box>;
type Id = Extract<ReturnType<BimModel['addSlab']>, { ok: true }>['value'];
type Kind = 'FLOORING' | 'CEILING' | 'CLADDING' | 'INSULATION' | 'ROOFING' | 'SKIRTINGBOARD';
type Keep = [number, number, number, number]; // the part of the plan that the view keeps: x0, y0, x1, y1
const X: P3 = [1, 0, 0], Y: P3 = [0, 1, 0], Z: P3 = [0, 0, 1], FAR = 20000;

// The model stays alive for the IFC file. Each temporary solid is freed, also when the build throws.
function finishes({ peel = 450, rise = 300 }: FinishParams = {}) {
  const model = new BimModel(), owned: Body[] = [];
  const own = <T extends Body>(s: T): T => { owned.push(s); return s; };
  try {
    model.init({ name: 'Finishes and access', projectId: 'finishes-demo' });
    const site = unwrap(model.addSite({ name: 'Site' }));
    const building = unwrap(model.addBuilding({ name: 'Block A' }));
    const storey = unwrap(model.addStorey({ name: 'Ground Floor', elevation: 0 }));
    const project = model.getProject();
    if (project) model.aggregate(project.localId, site);
    model.aggregate(site, building);
    model.aggregate(building, storey);
    const view = new Map<Id, { tint: string; keep?: Keep }>();
    const put = (made: ReturnType<BimModel['addSlab']>, tint: string, keep?: Keep): Id => {
      const id = unwrap(made);
      model.placeIn(id, storey);
      view.set(id, keep ? { tint, keep } : { tint });
      return id;
    };
    const { x: LX, y: LY } = ROOM, out = WALL.block + WALL.outside.reduce((sum, l) => sum + l[1], 0); // 340: the wall outside the room
    const floorTop = -FLOOR.layers.reduce((sum, l) => sum + l[1], 0), soffit = ROOM.clear + ROOF.ceiling[1] + ROOM.void;

    // ---- the lesson. A covering is a sheet: its length and width are in its local XY plane, and its
    // thickness is along its local Z. The host is the element that it covers.
    const flat = (host: Id, kind: Kind, [materialName, thickness, tint]: readonly [string, number, string], z: number, keep: Keep, x0 = 0, y1 = LY): Id =>
      put(model.addCovering({ length: LX - x0, width: y1, thickness, origin: [x0, 0, z], axisX: X, axisZ: Z, predefinedType: kind, materialName }, host), tint, keep);
    // A sheet on the north wall has its thickness along +Y. Its local Y is axisZ x axisX, so axisX is -X to keep it upright.
    const north = (host: Id, kind: Kind, [materialName, thickness, tint]: readonly [string, number, string], y: number, x0: number, x1: number, z0: number, z1: number, keep: Keep): Id =>
      put(model.addCovering({ length: x1 - x0, width: z1 - z0, thickness, origin: [x1, y, z0], axisX: [-1, 0, 0], axisZ: Y, predefinedType: kind, materialName }, host), tint, keep);
    // A sheet on the west wall has its thickness along +X, and runs along +Y.
    const west = (host: Id, kind: Kind, [materialName, thickness, tint]: readonly [string, number, string], x: number, y0: number, y1: number, z0: number, z1: number, keep: Keep): Id =>
      put(model.addCovering({ length: y1 - y0, width: z1 - z0, thickness, origin: [x, y0, z0], axisX: Y, axisZ: X, predefinedType: kind, materialName }, host), tint, keep);
    const upTo = (k: number): Keep => [-FAR, -FAR, LX - k * peel, FAR]; // cut back from the east end
    const from = (k: number): Keep => [-FAR, k * peel, FAR, FAR]; // cut back from the south end

    // The floor: insulation, screed and boards on the ground slab.
    const slab = put(model.addSlab({ length: LX + out, width: LY + out, thickness: FLOOR.slab, origin: [-out, 0, floorTop - FLOOR.slab], axisX: X, axisZ: Z, predefinedType: 'BASESLAB', materialName: 'Concrete' }), CONCRETE);
    let z = floorTop;
    FLOOR.layers.forEach((layer, i) => { flat(slab, i === 0 ? 'INSULATION' : 'FLOORING', layer, z, upTo(i + 1)); z += layer[1]; });

    // The walls: blockwork with plaster and a skirting inside, and insulation, battens and panels outside.
    const wall = { height: soffit - floorTop, thickness: WALL.block, axisZ: Z, materialName: 'Concrete block', isExternal: true };
    const outside = WALL.outside.length, plaster = WALL.inside[0], skirting = ['Painted softwood skirting', 15, '#e3dfd3'] as const;
    const northWall = put(model.addWall({ ...wall, length: LX + WALL.block, origin: [-WALL.block, LY, floorTop], axisX: X }), BLOCK, upTo(outside));
    const westWall = put(model.addWall({ ...wall, length: LY, origin: [0, 0, floorTop], axisX: Y }), BLOCK, from(outside));
    north(northWall, 'CLADDING', plaster, LY - plaster[1], 0, LX, 0, ROOM.clear, upTo(outside + 1));
    west(westWall, 'CLADDING', plaster, 0, 0, LY - plaster[1], 0, ROOM.clear, from(outside + 1));
    north(northWall, 'SKIRTINGBOARD', skirting, LY - plaster[1] - skirting[1], plaster[1], LX, 0, 95, upTo(outside + 1));
    west(westWall, 'SKIRTINGBOARD', skirting, plaster[1], 0, LY - plaster[1] - skirting[1], 0, 95, from(outside + 1));
    let d = WALL.block;
    WALL.outside.forEach((layer, i) => {
      const kind = i === 0 ? 'INSULATION' : 'CLADDING', k = outside - 1 - i, z1 = soffit + ROOF.slab;
      if (i === 1) {
        // The battens stand at 600 mm centres and leave an air gap behind the panels.
        for (let x = -d; x < LX - 50; x += 600) north(northWall, kind, layer, LY + d, x, x + 50, floorTop, z1, upTo(k));
        for (let y = 0; y < LY + d - 50; y += 600) west(westWall, kind, layer, -d - layer[1], y, y + 50, floorTop, z1, from(k));
      } else {
        north(northWall, kind, layer, LY + d, -d - layer[1], LX, floorTop, z1, upTo(k));
        west(westWall, kind, layer, -d - layer[1], 0, LY + d, floorTop, z1, from(k));
      }
      d += layer[1];
    });

    // The roof: a hung ceiling under the slab, and insulation and a membrane on it. The view keeps one corner.
    const corner = (k: number): Keep => (peel > 0 ? [-FAR, LY - 3000 + k * peel, 3300 - k * peel, FAR] : [-FAR, -FAR, FAR, FAR]);
    const roof = put(model.addSlab({ length: LX + WALL.block, width: LY + WALL.block, thickness: ROOF.slab, origin: [-WALL.block, 0, soffit], axisX: X, axisZ: Z, predefinedType: 'ROOF', materialName: 'Concrete' }), CONCRETE, corner(1));
    flat(roof, 'CEILING', ROOF.ceiling, ROOM.clear, corner(0), plaster[1], LY - plaster[1]);
    z = soffit + ROOF.slab;
    ROOF.layers.forEach((layer, i) => { flat(roof, i === 0 ? 'INSULATION' : 'ROOFING', layer, z, corner(i + 2), -WALL.block, LY + WALL.block); z += layer[1]; });

    // ---- access: a 1:15 ramp along the front to a landing, two steps, and a guard on the open edge of the landing.
    // The slope is rise / run, so the run follows from the rise. The width of a flight is on the left of its direction.
    const run = rise * RAMP.gradient, risers = Math.ceil(rise / STEP.rise), paving = '#6f6a60', stone = '#d8d4c8';
    const concrete = { materialName: 'Concrete' };
    put(model.addRamp({ name: 'Entrance ramp', predefinedType: 'STRAIGHT_RUN_RAMP', ...concrete, flights: [
      { width: RAMP.width, length: run, slope: 1 / RAMP.gradient, thickness: 150, origin: [RAMP.width + run, 0, -rise], axisX: [-1, 0, 0], axisZ: Z, predefinedType: 'STRAIGHT', ...concrete },
    ] }), stone);
    put(model.addSlab({ length: RAMP.width, width: RAMP.width, thickness: 150, origin: [0, -RAMP.width, -150], axisX: X, axisZ: Z, predefinedType: 'LANDING', ...concrete }), stone);
    put(model.addStair({ name: 'Entrance steps', predefinedType: 'STRAIGHT_RUN_STAIR', ...concrete, flights: [
      { width: RAMP.width, riserHeight: rise / risers, treadLength: 300, numberOfRisers: risers, origin: [RAMP.width, -RAMP.width - risers * 300, -rise], axisX: Y, axisZ: Z, ...concrete },
    ] }), stone);
    put(model.addRailing({ length: RAMP.width, height: 1100, thickness: 60, origin: [60, -RAMP.width, 0], axisX: Y, axisZ: Z, predefinedType: 'GUARDRAIL', infill: 'POSTED', materialName: 'Steel' }), '#c3c9d1');
    // The ground around the ramp, in three pieces.
    const ground = (x0: number, y0: number, x1: number, y1: number): Id =>
      put(model.addSlab({ length: x1 - x0, width: y1 - y0, thickness: 100, origin: [x0, y0, -rise - 100], axisX: X, axisZ: Z, predefinedType: 'BASESLAB', materialName: 'Concrete paving' }), paving);
    const east = Math.max(LX, RAMP.width + run) + 1200, front = -RAMP.width - risers * 300;
    ground(-out, front - 1200, east, front);
    ground(RAMP.width, front, east, -RAMP.width);
    ground(RAMP.width + run, -RAMP.width, east, 0);

    console.log('ramp: rise ' + rise + ' mm over ' + run + ' mm run (1:' + RAMP.gradient + '), landing ' + RAMP.width + ' mm deep (' + RAMP.landing + ' or more). ' + (run <= RAMP.longest ? 'ok' : 'TOO LONG') + ': a 1:' + RAMP.gradient + ' ramp can be ' + RAMP.longest + ' mm at most');

    // ---- the schedule and the view. The kernel measures each covering: volume / thickness = area.
    const groups = new Map<string, Body[]>(), rows = new Map<string, { type: string; material: string; thickness: number; m2: number }>();
    for (const el of model.getAllElements()) {
      const seen = view.get(el.localId);
      if (!seen) continue;
      for (const solid of unwrap(placedSolids(el))) {
        own(solid);
        if (el.category === 'COVERING') {
          const { predefinedType: type = 'COVERING', materialName: material, thickness } = el.spec;
          const row = rows.get(material) ?? { type, material, thickness, m2: 0 };
          row.m2 += unwrap(measureVolume(solid)) / thickness / 1e6;
          rows.set(material, row);
        }
        const k = seen.keep;
        const part = peel > 0 && k ? own(unwrap(intersect(solid, own(box(k[2] - k[0], k[3] - k[1], 2 * FAR, { at: [(k[0] + k[2]) / 2, (k[1] + k[3]) / 2, 0] }))))) : solid;
        groups.set(seen.tint, [...(groups.get(seen.tint) ?? []), part]);
      }
    }
    for (const r of rows.values()) console.log('  ' + r.type.padEnd(14) + r.material.padEnd(26) + String(r.thickness).padStart(4) + ' mm' + r.m2.toFixed(1).padStart(7) + ' m2');

    // The insulation is there for a reason. U = 1 / the sum of the resistance of each layer (thickness / conductivity).
    // The panels are in front of a vented gap, so they do not count and the gap side has the inside resistance.
    const mm = (t: number, lambda: number): number => t / 1000 / lambda;
    const wallU = 1 / (SURFACE.inside + mm(plaster[1], LAMBDA.plaster) + mm(WALL.block, LAMBDA.block) + mm(WALL.outside[0][1], LAMBDA.mineralWool) + SURFACE.inside);
    const roofU = 1 / (SURFACE.insideUp + mm(ROOF.slab, LAMBDA.concrete) + mm(ROOF.layers[0][1], LAMBDA.pir) + SURFACE.outside);
    console.log('U-value: wall ' + wallU.toFixed(2) + ' W/m2K (limit ' + LIMIT.wall + '), roof ' + roofU.toFixed(2) + ' W/m2K (limit ' + LIMIT.roof + ')');
    return { model, shown: [...groups].map(([tint, solids]) => color(compound(solids), tint)) };
  } catch (error) {
    model[Symbol.dispose]();
    throw error;
  } finally {
    owned.splice(0).forEach((s) => s.delete());
  }
}

// Show the layers cut back by 450 mm each. Try finishes({ peel: 0 }), or finishes({ rise: 150 }).
const job = finishes();
export default present(job.shown, {
  bimTree: job.model.toTreeSummary(),
  ifc: async () => unwrap(await toIfc(job.model, { applicationName: 'brepjs playground', applicationVersion: '1.0' })),
});

Functions used ​

placedSolids toIfc box compound intersect measureVolume unwrap color present

▶ Run Finishes and Access in the playground

Released under the Apache 2.0 License.