Skip to content

COBie, IDS and BCF ​

COBie, IDS and BCF, rendered in the brepjs playground
BIM · 209 lines▶ Run it in the playground

The three formats that carry the work around a model, as one chain on a small office block. COBie 2.4 handover sheets come from the spatial structure. An IDS 1.0 requirement is checked against the exported file, and the front wall fails it. A BCF 3.0 issue is then filed on that wall by its GlobalId, with a camera on it, and the view paints the wall orange. Results print to the console, and the Files button saves the COBie sheets and the BCF markup and viewpoint. The block is a display model, shown with its roof off.

Code ​

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

ts
import { BimModel, SpfReader, checkIds, deriveCobieModel, parseIdsXml, placedSolids, serializeBcfFiles, serializeCobieToCsv, toIfc } from 'brepjs-bim';
import { box, compound, getBounds, translate, unwrap } from 'brepjs/quick';
import { color, present } from 'brepjs/playground';

// COBie, IDS and BCF: IFC carries the model, and three sibling formats carry the work around it.
// COBie is the handover sheet, IDS is a requirement that a machine can check, BCF is an issue on an element.
// Here they make one chain on a small office block: the IDS check finds a wall, and a BCF issue is filed on it
// by its GlobalId. The view paints that wall orange. The console has the results, and the Files button saves them.
interface BlockParams {
  offices?: number; // the number of offices along the block
  declared?: boolean; // true gives the front wall its IsExternal flag: the IDS passes and no issue is filed
  roof?: boolean; // show the roof slab. The model and the files have it in each case
}

type P3 = [number, number, number];
type Made = ReturnType<BimModel['addWall']>;
type Id = Extract<Made, { ok: true }>['value'];
type Body = ReturnType<typeof box>;
type Tone = 'wall' | 'flagged' | 'space' | 'slab' | 'glass' | 'door' | 'roof';
const X: P3 = [1, 0, 0], Y: P3 = [0, 1, 0], Z: P3 = [0, 0, 1];

// ---- display model: the plan of the block. X is the depth, Y is the length, and the front looks toward +X
const DEPTH = 7200, LOBBY = 2700, OFFICE = 4350, OUTER = 300, INNER = 100;
const HEIGHT = { wall: 3000, room: 2700 };
const COLORS: Record<Tone, string> = { wall: '#f5f2ea', flagged: '#ff5a1f', space: '#12b5b0', slab: '#c3c9d1', glass: '#9fc3d4', door: '#d3a956', roof: '#48515c' };

// ---- THE LESSON. Try riverside({ offices: 4 }), riverside({ declared: true }) or riverside({ roof: true }).
const block = riverside();
const bytes = unwrap(await toIfc(block.model, { applicationName: 'brepjs playground', applicationVersion: '1.0' }));

// COBie 2.4: the view for the facility manager. It comes from the spatial structure and the property sets,
// not from geometry. The spaces of the model make its Space sheet.
const cobie = deriveCobieModel(block.model, { contact: { email: 'fm@example.com', givenName: 'Facilities', familyName: 'Team' } });
const sheets = serializeCobieToCsv(cobie);
console.log('COBie sheets: ' + [...sheets.keys()].join(', '));
console.log('  ' + cobie.space.length + ' spaces, ' + cobie.floor.length + ' floors, ' + cobie.component.length + ' components');

// IDS 1.0: a requirement in the form that a client issues. Applicability selects the entities to test, and
// requirements say what they must have. The lines are joined with a space: XML does not need the line breaks.
const IDS_XML = [
  '<?xml version="1.0" encoding="UTF-8"?>',
  '<ids xmlns="http://standards.buildingsmart.org/IDS">',
  '  <info><title>Walls declare IsExternal</title></info>',
  '  <specifications>',
  '    <specification name="Walls declare IsExternal" ifcVersion="IFC4">',
  '      <applicability minOccurs="1" maxOccurs="unbounded">',
  '        <entity><name><simpleValue>IFCWALL</simpleValue></name></entity>',
  '      </applicability>',
  '      <requirements>',
  '        <property>',
  '          <propertySet><simpleValue>Pset_WallCommon</simpleValue></propertySet>',
  '          <baseName><simpleValue>IsExternal</simpleValue></baseName>',
  '        </property>',
  '      </requirements>',
  '    </specification>',
  '  </specifications>',
  '</ids>',
].join(' ');
const idsReport = unwrap(await checkIds(bytes, unwrap(parseIdsXml(IDS_XML))));
console.log('IDS: ' + (idsReport.pass ? 'PASS' : 'FAIL'));
for (const r of idsReport.results) console.log('  ' + r.specificationName + ': ' + r.passedCount + '/' + r.applicableCount + ' applicable entities pass');

// The IDS report names an entity by its line in the file. The GlobalId of that line is the name that the
// model, the BCF issue and each other tool share.
const reader = unwrap(await SpfReader.create(bytes));
const failed = idsReport.results.flatMap((r) => r.issues).flatMap((i) => (typeof i.entity === 'number' ? [reader.guidFromExpressId(i.entity) ?? ''] : []));
reader.close();

// BCF 3.0: one issue for each wall that failed, on the element by its GlobalId, with a camera that looks at it.
// BCF is in metres and the model is in millimetres. A topic and a viewpoint have a UUID, not an IFC GlobalId.
// The container is not zipped here: it is a map from a file name to its contents.
const bcf = serializeBcfFiles({
  version: { versionId: '3.0' },
  project: { projectId: 'interop-demo', name: 'Riverside Block' },
  topics: block.model.getWalls().filter((wall) => failed.includes(wall.guid)).map((wall) => ({
    guid: crypto.randomUUID(),
    title: 'Wall does not declare IsExternal',
    topicType: 'Issue',
    topicStatus: 'Open',
    creationAuthor: 'fm@example.com',
    creationDate: '2026-01-05T09:00:00Z',
    description: 'Pset_WallCommon has no IsExternal. The IDS of the client requires it on each wall.',
    comments: [],
    viewpoints: [
      {
        guid: crypto.randomUUID(),
        viewpointFile: 'viewpoint.bcfv', // the markup names this file, so the saved copy keeps the name
        components: { selection: [{ ifcGuid: wall.guid }], coloring: [{ color: 'FFFF5A1F', components: [{ ifcGuid: wall.guid }] }] },
        camera: block.cameraOn(wall.localId),
      },
    ],
  })),
});
console.log('BCF container: ' + [...bcf.keys()].join(', '));
// The files of a topic are in a folder with the guid of the topic, so find them by the end of the name.
const markupKey = [...bcf.keys()].find((k) => k.endsWith('/markup.bcf')) ?? '';
const viewpointKey = [...bcf.keys()].find((k) => k.endsWith('.bcfv')) ?? '';

// ---- THE SCENERY: a lobby and a row of offices in one storey, with a space in each room.
function riverside({ offices = 2, declared = false, roof = false }: BlockParams = {}) {
  const model = new BimModel();
  model.init({ name: 'Interop demo', projectId: 'interop-demo' });
  const site = unwrap(model.addSite({ name: 'Site' }));
  const building = unwrap(model.addBuilding({ name: 'Riverside Block' }));
  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 placed: { id: Id; tone: Tone }[] = [];
  const owned: Body[] = [];
  const put = (tone: Tone, made: Made): Id => {
    const id = unwrap(made);
    model.placeIn(id, storey);
    placed.push({ id, tone });
    return id;
  };
  const fill = (tone: Tone, name: string, lo: P3, hi: P3): Id => {
    const unit = box(hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]);
    owned.push(unit);
    return put(tone, model.addProxy({ name, solid: translate(unit, lo) }));
  };
  const LENGTH = OUTER + LOBBY + offices * (INNER + OFFICE) + OUTER, inside = DEPTH - 2 * OUTER;
  const outer = { height: HEIGHT.wall, thickness: OUTER, axisZ: Z, materialName: 'Concrete' };
  // The outer walls. A wall goes toward its local Y from its axis. The front wall is the one with the fault:
  // it is an external wall, but it does not say so.
  const front = put('wall', model.addWall({ ...outer, length: LENGTH, origin: [DEPTH, 0, 0], axisX: Y, ...(declared ? { isExternal: true } : {}) }));
  const back = put('wall', model.addWall({ ...outer, length: LENGTH, origin: [0, LENGTH, 0], axisX: [0, -1, 0], isExternal: true }));
  const south = put('wall', model.addWall({ ...outer, length: inside, origin: [OUTER, 0, 0], axisX: X, isExternal: true }));
  const north = put('wall', model.addWall({ ...outer, length: inside, origin: [DEPTH - OUTER, LENGTH, 0], axisX: [-1, 0, 0], isExternal: true }));
  put('slab', model.addSlab({ length: DEPTH, width: LENGTH, thickness: 250, origin: [0, 0, -250], axisX: X, axisZ: Z, predefinedType: 'FLOOR', materialName: 'Concrete' }));
  const top = put('roof', model.addSlab({ length: DEPTH + 600, width: LENGTH + 600, thickness: 200, origin: [-300, -300, HEIGHT.wall], axisX: X, axisZ: Z, predefinedType: 'ROOF', materialName: 'Concrete' }));

  // The rooms: a space for each one, which is the source of the COBie Space sheet.
  const room = (name: string, y: number, width: number): Id =>
    put('space', model.addSpace({ name, length: inside, width, height: HEIGHT.room, origin: [OUTER, y, 0], axisX: X, axisZ: Z, materialName: 'Air' }));
  const pane = { width: 1500, height: 1350, offsetFromFloor: 900, materialName: 'Aluminium' };
  const door = { width: 900, height: 2100, offsetFromFloor: 0, materialName: 'Timber' };
  // A window at y in the front wall and in the back wall, with its glass and its sill. The back wall runs toward
  // -Y. The IFC writer gives each door and window a panel in the inner 100 mm of its wall: the proxies stay out of it.
  const lights = (y: number): void => {
    put('glass', model.addWindow({ ...pane, wallLocalId: front, offsetAlongWall: y }));
    put('glass', model.addWindow({ ...pane, wallLocalId: back, offsetAlongWall: LENGTH - y - pane.width }));
    fill('glass', 'Glazing', [DEPTH - 165, y, 950], [DEPTH - 135, y + pane.width, 2250]);
    fill('glass', 'Glazing', [135, y, 950], [165, y + pane.width, 2250]);
    fill('slab', 'Sill', [DEPTH - OUTER + 100, y, 900], [DEPTH + 60, y + pane.width, 950]);
    fill('slab', 'Sill', [-60, y, 900], [OUTER - 100, y + pane.width, 950]);
  };
  room('Lobby', OUTER, LOBBY);
  put('door', model.addDoor({ ...door, width: 1000, wallLocalId: front, offsetAlongWall: OUTER + 850 }));
  fill('door', 'Door leaf', [DEPTH - 170, OUTER + 850, 0], [DEPTH - 120, OUTER + 1850, 2100]);
  fill('slab', 'Step', [DEPTH, OUTER + 650, -250], [DEPTH + 600, OUTER + 2050, -20]);
  put('roof', model.addSlab({ length: DEPTH + 2400, width: LENGTH + 2000, thickness: 150, origin: [-1000, -1000, -400], axisX: X, axisZ: Z, predefinedType: 'BASESLAB', materialName: 'Paving' }));
  for (let k = 0; k < offices; k++) {
    const y = OUTER + LOBBY + k * (INNER + OFFICE);
    const partition = put('wall', model.addWall({ length: inside, height: HEIGHT.wall, thickness: INNER, origin: [OUTER, y, 0], axisX: X, axisZ: Z, materialName: 'Plasterboard', isExternal: false }));
    put('door', model.addDoor({ ...door, wallLocalId: partition, offsetAlongWall: 4500 }));
    room('Office 0' + (k + 1), y + INNER, OFFICE);
    lights(y + INNER + 500);
    lights(y + INNER + 2350);
  }
  for (const [wall, y] of [[south, 135], [north, LENGTH - 165]] as const) {
    put('glass', model.addWindow({ ...pane, wallLocalId: wall, offsetAlongWall: (inside - pane.width) / 2 }));
    fill('glass', 'Glazing', [DEPTH / 2 - pane.width / 2, y, 950], [DEPTH / 2 + pane.width / 2, y + 30, 2250]);
    fill('slab', 'Sill', [DEPTH / 2 - pane.width / 2, y < OUTER ? -60 : LENGTH - OUTER + 100, 900], [DEPTH / 2 + pane.width / 2, y < OUTER ? OUTER - 100 : LENGTH + 60, 950]);
  }

  const elements = new Map(model.getAllElements().map((el) => [el.localId, el]));
  const solidsOf = (id: Id): Body[] => {
    const list = unwrap(placedSolids(elements.get(id) as never)) as Body[];
    owned.push(...list);
    return list;
  };
  // A BCF camera that looks at an element from the front and from above. Up is square to the view direction.
  const cameraOn = (id: Id) => {
    const b = getBounds(solidsOf(id)[0] as Body);
    const target = [(b.xMin + b.xMax) / 2000, (b.yMin + b.yMax) / 2000, (b.zMin + b.zMax) / 2000] as const;
    const eye = [target[0] + 12, target[1] - 12, target[2] + 9] as const;
    const dir = [target[0] - eye[0], target[1] - eye[1], target[2] - eye[2]] as const;
    const len = Math.hypot(...dir), d = [dir[0] / len, dir[1] / len, dir[2] / len] as const;
    const up = [-d[0] * d[2], -d[1] * d[2], d[0] * d[0] + d[1] * d[1]] as const, upLen = Math.hypot(...up);
    return { kind: 'PERSPECTIVE' as const, viewPoint: [eye[0], eye[1], eye[2]] as P3, direction: [d[0], d[1], d[2]] as P3, upVector: [up[0] / upLen, up[1] / upLen, up[2] / upLen] as P3, fieldOfView: 60, aspectRatio: 16 / 9 };
  };
  // The view: one compound for each tone. A wall with an issue gets the tone of an issue.
  const view = (guids: readonly string[]) => {
    const groups = new Map<Tone, Body[]>();
    for (const p of placed) {
      if (p.id === top && !roof) continue;
      const tone = guids.includes(elements.get(p.id)?.guid ?? '') ? 'flagged' : p.tone;
      groups.set(tone, [...(groups.get(tone) ?? []), ...solidsOf(p.id)]);
    }
    const shown = [...groups].map(([tone, list]) => color(compound(list), COLORS[tone]));
    owned.splice(0).forEach((s) => s.delete());
    return shown;
  };
  return { model, cameraOn, view };
}

export default present(block.view(failed), {
  bimTree: block.model.toTreeSummary(),
  ifc: () => bytes,
  // A few files, not all nine COBie sheets: the Files button saves one file for each entry.
  files: () => [
    { name: 'cobie-Facility.csv', data: sheets.get('Facility') ?? '', mime: 'text/csv' },
    { name: 'cobie-Space.csv', data: sheets.get('Space') ?? '', mime: 'text/csv' },
    { name: 'markup.bcf', data: bcf.get(markupKey) ?? '', mime: 'application/xml' },
    { name: 'viewpoint.bcfv', data: bcf.get(viewpointKey) ?? '', mime: 'application/xml' },
  ].filter((file) => file.data.length > 0),
});

Functions used ​

checkIds deriveCobieModel parseIdsXml placedSolids serializeBcfFiles serializeCobieToCsv toIfc box compound getBounds translate unwrap color present

▶ Run COBie, IDS and BCF in the playground

Released under the Apache 2.0 License.