Skip to content

Space Volume ​

Space Volume, rendered in the brepjs playground
BIM · 154 lines▶ Run it in the playground

An IfcSpace is the volume of a room, an element of its own that plain solid modelling does not have. Two rooms of an office floor, each with its space lifted out above it to show the volume as a solid: set lift to 0 to put it back. The kernel measures each volume, and the published rule of 11 cubic metres of room for each person gives the people that the room has volume for. The rooms and the furniture 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, cylinder, measureVolume, translate, unwrap } from 'brepjs/quick';
import { color, present } from 'brepjs/playground';

// Space volume: an IfcSpace is the volume of a room, an element of its own with no part to touch.
// Two rooms of an office floor, and above each room its space, lifted out to show it as a solid.
// The lesson is the SPACES table and the addSpace call. The rooms are a display model. Units are millimetres.
interface SpaceParams {
  lift?: number; // how far the view raises each space above its room. 0 puts it back
  height?: number; // clear height of the rooms, from the floor finish to the ceiling
  cutaway?: boolean; // leave the corridor partition off in the view. The model and the IFC file keep it
}

type P3 = [number, number, number];
type Made = ReturnType<BimModel['addSpace']>;
type Id = Extract<Made, { ok: true }>['value'];
type Body = ReturnType<typeof box>;
type Tone = 'space' | 'wall' | 'slab' | 'carpet' | 'rug' | 'glass' | 'wood' | 'seat' | 'dark';
const X: P3 = [1, 0, 0], Y: P3 = [0, 1, 0], Z: P3 = [0, 0, 1];

// ---- published figures
const ROOM_PER_PERSON = 11; // m3 of empty room for each person who works in it
const COUNTED_HEIGHT = 3000; // a room that is higher than this counts as 3.0 m high

// ---- display model
const FINISH = 10; // the floor finish on the slab
const WALL = { height: 3000, facade: 300, partition: 100 };
const DEPTH = 4500, LENGTH = 11500, SPLIT = 7200; // the plan: X is into the room, Y is along the facade
// One row for each room: the corner of its floor and its size in plan.
const SPACES = [
  { name: 'Office 1.01', longName: 'Open office', at: [0, 0], size: [DEPTH, SPLIT], seats: 6 },
  { name: 'Meeting 1.02', longName: 'Meeting room', at: [0, SPLIT + WALL.partition], size: [DEPTH, LENGTH - SPLIT - WALL.partition], seats: 4 },
] as const;

function floor({ lift = 4800, height = 2700, cutaway = true }: SpaceParams = {}) {
  const model = new BimModel();
  model.init({ name: 'Space volume' });
  const site = unwrap(model.addSite({ name: 'Site' }));
  const building = unwrap(model.addBuilding({ name: 'Office building' }));
  const storey = unwrap(model.addStorey({ name: 'First floor', elevation: 0 }));
  const project = model.getProject();
  if (project) model.aggregate(project.localId, site);
  model.aggregate(site, building);
  model.aggregate(building, storey);
  const placed: { id: Id; tone: Tone; hidden: boolean }[] = [];
  const put = (tone: Tone, made: Made, hidden = false): Id => {
    const id = unwrap(made);
    model.placeIn(id, storey);
    placed.push({ id, tone, hidden });
    return id;
  };

  // THE LESSON. A space is a box of air: a name, a plan, a clear height and a place. It fills its room from the
  // floor finish to the ceiling and from wall face to wall face. It is in the storey like each other element.
  const spaces = SPACES.map((s) =>
    put('space', model.addSpace({
      name: s.name, longName: s.longName, length: s.size[0], width: s.size[1], height,
      origin: [s.at[0], s.at[1], FINISH], axisX: X, axisZ: Z, predefinedType: 'INTERNAL', materialName: 'Air',
    })),
  );

  // The rooms. The facade is at x = 0. A wall goes toward its local Y from its axis: that is -X when it runs along +Y.
  const wall = { height: WALL.height, axisZ: Z, materialName: 'Plasterboard on studs' };
  const facade = put('wall', model.addWall({ ...wall, length: LENGTH, thickness: WALL.facade, origin: [0, 0, 0], axisX: Y, materialName: 'Rendered masonry', isExternal: true }));
  const cross = put('wall', model.addWall({ ...wall, length: DEPTH, thickness: WALL.partition, origin: [0, SPLIT, 0], axisX: X }));
  const aisle = put('wall', model.addWall({ ...wall, length: LENGTH, thickness: WALL.partition, origin: [DEPTH + WALL.partition, 0, 0], axisX: Y }), cutaway);
  // Each space knows the walls that bound it.
  for (const space of spaces) for (const bound of [facade, cross, aisle])
    model.addSpaceBoundary(space, bound, 'PHYSICAL');

  const slab = put('slab', model.addSlab({ length: DEPTH + WALL.partition + WALL.facade, width: LENGTH, thickness: 250, origin: [-WALL.facade, 0, -250], axisX: X, axisZ: Z, predefinedType: 'FLOOR', materialName: 'Concrete' }));
  SPACES.forEach((s, i) => {
    const made = model.addCovering({ length: s.size[0], width: s.size[1], thickness: FINISH, origin: [s.at[0], s.at[1], 0], axisX: X, axisZ: Z, predefinedType: 'FLOORING', materialName: 'Carpet' }, slab);
    put(i === 0 ? 'carpet' : 'rug', made);
  });
  const window = { width: 1800, height: 1500, offsetFromFloor: 900, wallLocalId: facade, materialName: 'Aluminium' };
  const door = { width: 900, height: 2100, offsetFromFloor: 0, materialName: 'Timber' };
  const lights = [600, 2700, 4800, 8500];
  for (const y of lights) put('glass', model.addWindow({ ...window, offsetAlongWall: y }));
  put('wood', model.addDoor({ ...door, wallLocalId: cross, offsetAlongWall: 3300 }));
  put('wood', model.addDoor({ ...door, wallLocalId: aisle, offsetAlongWall: 5900 }));
  put('wood', model.addDoor({ ...door, wallLocalId: aisle, offsetAlongWall: 7600 }));

  // Glass, window boards and the furniture are proxies: plain solids with a name. The IFC writer gives each
  // door and window a panel of its own, in the 100 mm of its wall that is farthest from the wall axis.
  const owned: Body[] = [];
  const own = <T extends Body>(s: T): T => {
    owned.push(s);
    return s;
  };
  const block = (tone: Tone, name: string, lo: P3, hi: P3, hidden = false): Id =>
    put(tone, model.addProxy({ name, solid: translate(own(box(hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2])), lo) }), hidden);
  const post = (tone: Tone, name: string, at: P3, radius: number, tall: number): Id => put(tone, model.addProxy({ name, solid: cylinder(radius, tall, { at }) }));
  for (const y of lights) {
    block('glass', 'Glazing', [-170, y, 950], [-140, y + window.width, 2400]);
    block('slab', 'Window board', [-200, y, 900], [0, y + window.width, 950]);
  }
  const F = FINISH;
  const table = (x: number, y: number, deep: number, long: number): void => {
    block('wood', 'Table top', [x, y, F + 715], [x + deep, y + long, F + 740]);
    for (const end of [y + 60, y + long - 85]) block('dark', 'Table leg', [x + 60, end, F], [x + deep - 60, end + 25, F + 715]);
  };
  const chair = (x: number, y: number, faces: number): void => {
    post('dark', 'Chair base', [x, y, F], 280, 40);
    post('dark', 'Chair column', [x, y, F + 40], 30, 380);
    block('seat', 'Chair seat', [x - 230, y - 230, F + 420], [x + 230, y + 230, F + 480]);
    const rear = faces > 0 ? x - 230 : x + 190;
    block('seat', 'Chair back', [rear, y - 220, F + 480], [rear + 40, y + 220, F + 930]);
  };
  // The office: a bench of six desks, each with a screen. The meeting room: a table for four.
  for (const y of [1200, 2800, 4400]) for (const side of [-1, 1]) {
    const x = side < 0 ? 1450 : 2250;
    table(x, y, 800, 1600);
    chair(side < 0 ? 1000 : 3500, y + 800, -side);
    const screen = side < 0 ? 2050 : 2430;
    block('dark', 'Screen stand', [screen - 40, y + 760, F + 740], [screen + 60, y + 840, F + 850]);
    block('dark', 'Screen', [screen, y + 520, F + 850], [screen + 20, y + 1080, F + 1190]);
  }
  block('slab', 'Cabinet', [300, SPLIT - 450, F], [2700, SPLIT, F + 1100]);
  block('dark', 'Wall screen', [1300, SPLIT + WALL.partition, 1100], [2700, SPLIT + WALL.partition + 40, 1900]);
  table(1750, 8500, 1000, 1800);
  for (const y of [8950, 9850]) for (const side of [-1, 1]) chair(2250 + side * 900, y, -side);

  // The kernel measures each space. The published rule gives the people that the room has volume for.
  const elements = new Map(model.getAllElements().map((el) => [el.localId, el]));
  const solidsOf = (id: Id): Body[] => (unwrap(placedSolids(elements.get(id) as never)) as Body[]).map(own);
  const report = SPACES.map((s, i) => {
    const m3 = unwrap(measureVolume(solidsOf(spaces[i] as Id)[0] as Body)) / 1e9;
    const counted = m3 * Math.min(1, COUNTED_HEIGHT / height);
    return s.name + ' ' + m3.toFixed(1) + ' m3' + ', volume for ' + Math.floor(counted / ROOM_PER_PERSON) + ' people, ' + s.seats + ' seats';
  });
  const groups = new Map<Tone, Body[]>();
  for (const p of placed) {
    if (p.hidden) continue;
    const list = solidsOf(p.id).map((s) => (p.tone === 'space' && lift > 0 ? own(translate(s, [0, 0, lift])) : s));
    groups.set(p.tone, [...(groups.get(p.tone) ?? []), ...list]);
  }
  const shown = [...groups].map(([tone, list]) => ({ tone, shape: compound(list) }));
  owned.splice(0).forEach((s) => s.delete());
  return { model, shown, report };
}
const COLORS: Record<Tone, string> = { space: '#12b5b0', wall: '#f5f2ea', slab: '#c3c9d1', carpet: '#48515c', rug: '#5d6672', glass: '#9fc3d4', wood: '#d3a956', seat: '#ff5a1f', dark: '#2b3038' };

// Try floor({ lift: 0 }), floor({ height: 3600 }) or floor({ cutaway: false }).
const level = floor();
console.log('Space volumes from the kernel: ' + level.report.join('; ') + '. The rule is ' + ROOM_PER_PERSON + ' m3 for each person.');

export default present(
  level.shown.map((g) => color(g.shape, COLORS[g.tone])),
  {
    bimTree: level.model.toTreeSummary(),
    ifc: async () => unwrap(await toIfc(level.model, { applicationName: 'brepjs playground', applicationVersion: '1.0' })),
  },
);

Functions used ​

placedSolids toIfc box compound cylinder measureVolume translate unwrap color present

▶ Run Space Volume in the playground

Released under the Apache 2.0 License.