Profile Gallery

Eight structural sections as real IfcColumn stubs on bolted base plates: I, L, T, U, Z, C, rectangular hollow and circular hollow. Beams and columns share one profile vocabulary, and each named kind exports as its own parametric IFC profile def, so the section stays editable data downstream. The IPE 300, the angle, the UPE 200 and the two hollow sections have their published dimensions, and the kernel measures the mass of each metre to set against the steel table. The view shows each M20 holding-down bolt as a screw with a helical thread in its nut, and the IFC file keeps plain proxies. The tee, the zed, the lipped channel, the base plates and the trestles are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
import { BimModel, placedSolids, toIfc } from 'brepjs-bim';
import { box, compound, cutAll, cylinder, extrude, getBounds, line, loft, measureVolume, polygon, translate, unwrap, wire } from 'brepjs/quick';
import { color, present } from 'brepjs/playground';
// Profile gallery: eight structural sections of the steel tables, as column stubs on bolted base plates.
// The lesson is the CATALOGUE: beams and columns take the same profile, and each named kind exports as its own
// parametric IFC profile def (IfcIShapeProfileDef, IfcLShapeProfileDef and so on), not as a baked outline.
// The body in the view has the root radii of the I section only. The other radii are data in the profile def.
interface StockParams {
as?: 'columns' | 'beams'; // stubs on base plates (IfcColumn), or lengths that lie on two trestles (IfcBeam)
length?: number; // length of each member in millimetres
radii?: boolean; // false leaves the root and corner radii out of each profile def
}
type P3 = [number, number, number];
type Made = ReturnType<BimModel['addBeam']>;
type Id = Extract<Made, { ok: true }>['value'];
type Profile = Parameters<BimModel['addBeam']>[0]['profile'];
type Body = Extract<ReturnType<typeof placedSolids>, { ok: true }>['value'][number];
type Tone = 'rolled' | 'hollow' | 'formed' | 'primer' | 'bolt' | 'floor';
const X: P3 = [1, 0, 0], Y: P3 = [0, 1, 0], Z: P3 = [0, 0, 1];
// ---- published figures: section dimensions and mass for each metre, from the steel tables
const STEEL = 7850e-9; // kg in each mm3
const IPE300 = { h: 300, b: 150, tw: 7.1, tf: 10.7, r: 15, kg: 42.2 };
const L150 = { leg: 150, t: 12, r: 16, kg: 27.3 };
const UPE200 = { h: 200, b: 80, tw: 6, tf: 11, kg: 22.8 };
const RHS200 = { h: 200, b: 100, t: 8, outer: 12, inner: 8, kg: 35.1 };
const CHS168 = { d: 168.3, t: 8, kg: 31.6 };
const M20 = { d: 20, minor: 17.294, pitch: 2.5, flats: 30 }; // the holding-down bolts: metric coarse thread, right hand
// ---- display model: the tee, the zed and the lipped channel have typical sizes, with no table mass
// THE LESSON. One entry for each profile kind. roll turns a section about its length to lay it on a flat side.
const catalogue = (radii: boolean): { name: string; tone: Tone; kg?: number; roll: number; profile: Profile }[] => [
{ name: 'IPE 300', tone: 'rolled', kg: IPE300.kg, roll: 0, profile: { kind: 'I_BEAM', overallWidth: IPE300.b, overallDepth: IPE300.h, flangeThickness: IPE300.tf, webThickness: IPE300.tw, filletRadius: radii ? IPE300.r : undefined } },
{ name: 'L 150x150x12', tone: 'rolled', kg: L150.kg, roll: 0, profile: { kind: 'L_SHAPE', depth: L150.leg, width: L150.leg, legThickness: L150.t, filletRadius: radii ? L150.r : undefined } },
{ name: 'T 140x140x15', tone: 'rolled', roll: 0, profile: { kind: 'T_SHAPE', depth: 140, flangeWidth: 140, webThickness: 15, flangeThickness: 15, filletRadius: radii ? 15 : undefined } },
{ name: 'UPE 200', tone: 'rolled', kg: UPE200.kg, roll: 0, profile: { kind: 'U_SHAPE', depth: UPE200.h, flangeWidth: UPE200.b, webThickness: UPE200.tw, flangeThickness: UPE200.tf } },
{ name: 'Z 160x70', tone: 'rolled', roll: 0, profile: { kind: 'Z_SHAPE', depth: 160, flangeWidth: 70, webThickness: 8.5, flangeThickness: 11 } },
{ name: 'C 200x75x20x2.5', tone: 'formed', roll: 0, profile: { kind: 'C_SHAPE', depth: 200, width: 75, wallThickness: 2.5, girth: 20, internalFilletRadius: radii ? 2.5 : undefined } },
{ name: 'RHS 200x100x8', tone: 'hollow', kg: RHS200.kg, roll: 0, profile: { kind: 'RECTANGLE_HOLLOW', xDim: RHS200.b, yDim: RHS200.h, wallThickness: RHS200.t, outerFilletRadius: radii ? RHS200.outer : undefined, innerFilletRadius: radii ? RHS200.inner : undefined } },
{ name: 'CHS 168.3x8', tone: 'hollow', kg: CHS168.kg, roll: 0, profile: { kind: 'CIRCLE_HOLLOW', radius: CHS168.d / 2, wallThickness: CHS168.t } },
];
const GAP = 110; // between two members
const ROW = 800; // from one row of stubs to the next
const PLATE = { thick: 20, margin: 70, bolt: 10 }; // a base plate with four holding-down bolts
const ANCHOR = { embed: 120, hole: 22, play: 0.15 }; // a bolt in the footing, its hole in the plate, the play of its nut
const TRESTLE = { height: 400, bearer: 100, leg: 80, stop: 150 };
function stock({ as = 'columns', length = 320, radii = true }: StockParams = {}) {
const model = new BimModel();
model.init({ name: 'Profile gallery' });
const site = unwrap(model.addSite({ name: 'Site' }));
const building = unwrap(model.addBuilding({ name: 'Workshop' }));
const storey = unwrap(model.addStorey({ name: 'Shop 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 steel = { materialName: 'Steel S355' };
const lying = as === 'beams';
// THE CALL. A beam runs along its local X and a column goes up its local Z. The profile is the same for both.
const member = (into: BimModel, profile: Profile, origin: P3, roll: number): Made => {
const turn = (roll * Math.PI) / 180;
return lying
? into.addBeam({ length, profile, origin, axisX: X, axisZ: [0, -Math.sin(turn), Math.cos(turn)], ...steel })
: into.addColumn({ height: length, profile, origin, axisX: [Math.cos(turn), Math.sin(turn), 0], axisZ: Z, ...steel });
};
// The origin of a profile is not at a corner. A trial member in a scratch model gives the box of the section.
const boxOf = (profile: Profile, roll: number) => {
const scratch = new BimModel();
scratch.init({ name: 'Scratch' });
const solid = (unwrap(placedSolids(scratch.getElement(unwrap(member(scratch, profile, [0, 0, 0], roll))) as never)) as Body[])[0] as Body;
const box = getBounds(solid);
solid.delete();
scratch[Symbol.dispose]();
return box;
};
// Stand the members in two rows, each on its plate, or lay them side by side on the trestles.
let cursor = 0, deepest = 0, width = 0;
const members = catalogue(radii).map((entry, i) => {
const b = boxOf(entry.profile, entry.roll), m = lying ? 0 : PLATE.margin;
const half = (b.xMax - b.xMin) / 2 + m, wide = b.yMax - b.yMin + 2 * m;
if (!lying && i === 4) cursor = 0; // the stubs stand in two rows of four
const cx = lying ? 0 : i < 4 ? ROW / 2 : -ROW / 2;
const origin: P3 = lying ? [0, cursor - b.yMin, TRESTLE.height - b.zMin] : [cx - (b.xMin + b.xMax) / 2, cursor + m - b.yMin, PLATE.thick];
const plate = { x: cx - half, y: cursor, deep: 2 * half, wide };
cursor += wide + GAP;
width = Math.max(width, cursor - GAP);
deepest = Math.max(deepest, 2 * half);
return { ...entry, plate, id: put(entry.tone, member(model, entry.profile, origin, entry.roll)) };
});
// The scenery. For the columns: a base plate with four holding-down bolts under each stub, on a strip footing.
// The IFC file keeps each nut and bolt end as a plain proxy. The view shows the whole bolt as a real screw: a plain
// shank from the footing up through the plate, a core with one helical tooth, and a hex nut with the mating tooth.
const keep = (s: unknown): Body => { owned.push(s as Body); return s as Body; };
const tooth = (core: number, tip: number, from: number, to: number, ref: number): Body => {
const root = tip > core ? core / 0.998 : core * 0.998, half = 0.42 * M20.pitch; // a hair clear of the core or the bore
const start = from + half, span = to - from - 2 * half, pieces = Math.ceil(span / (4 * M20.pitch));
const n = Math.round(span / pieces / M20.pitch * 24); // 24 loft sections in each turn
const section = (z: number) => {
const a = 2 * Math.PI * (z - ref) / M20.pitch;
const pts = [[root, -half], [tip, 0], [root, half]].map(([r, dz]): P3 => [r! * Math.cos(a), r! * Math.sin(a), z + dz!]);
return keep(unwrap(wire(pts.map((q, i) => keep(line(q, pts[(i + 1) % 3]!)) as never))));
};
// A row of lofts of 4 turns or less, end to end on one helix: a long loft is slow to mesh.
const lofts = Array.from({ length: pieces }, (_, k) => keep(unwrap(loft(Array.from({ length: n + 1 }, (_, j) => section(start + span * (k + j / n) / pieces)) as never, { ruled: false }))));
return keep(compound(lofts));
};
const nutTop = PLATE.thick + 16, top = nutTop + 24, bore = M20.d / 2 + ANCHOR.play, hexR = M20.flats / Math.sqrt(3);
const hex = keep(unwrap(polygon(Array.from({ length: 6 }, (_, i): P3 => [hexR * Math.cos((i * Math.PI) / 3), hexR * Math.sin((i * Math.PI) / 3), PLATE.thick]))));
const screw = lying ? undefined : keep(compound([
keep(cylinder(M20.d / 2, ANCHOR.embed + PLATE.thick, { at: [0, 0, -ANCHOR.embed] })), keep(cylinder(M20.minor / 2, top - PLATE.thick, { at: [0, 0, PLATE.thick] })), tooth(M20.minor / 2, M20.d / 2, PLATE.thick, top, 0),
keep(unwrap(cutAll(keep(unwrap(extrude(hex as never, 16))), [keep(cylinder(bore, 18, { at: [0, 0, PLATE.thick - 1] }))]))), tooth(bore, M20.minor / 2 + ANCHOR.play, PLATE.thick, nutTop, M20.pitch / 2),
]));
const screws: P3[] = [], drills = new Map<Id, Body[]>(), inFooting: Body[][] = [[], []]; // the holes that the view drills
if (!lying) for (const { plate: p } of members) {
const unit = box(p.deep, p.wide, PLATE.thick);
owned.push(unit);
const spots = [p.x + 32, p.x + p.deep - 32].flatMap((x) => [p.y + 32, p.y + p.wide - 32].map((y): P3 => [x, y, 0]));
screws.push(...spots);
drills.set(put('primer', model.addProxy({ name: 'Base plate', solid: translate(unit, [p.x, p.y, 0]), ...steel })), spots.map(([x, y]) => keep(cylinder(ANCHOR.hole / 2, PLATE.thick + 2, { at: [x, y, -1] }))));
inFooting[p.x + p.deep / 2 > 0 ? 0 : 1]!.push(...spots.map(([x, y]) => keep(cylinder(M20.d / 2, ANCHOR.embed + 1, { at: [x, y, -ANCHOR.embed] }))));
for (const [x, y] of spots) {
put('bolt', model.addProxy({ name: 'Nut', solid: cylinder(1.7 * PLATE.bolt, 16, { at: [x, y, PLATE.thick] }), ...steel }));
put('bolt', model.addProxy({ name: 'Holding-down bolt', solid: cylinder(PLATE.bolt, 24, { at: [x, y, PLATE.thick + 16] }), ...steel }));
}
}
// For the beams: two trestles of square hollow section, with a stop at each end of a bearer, on a floor slab.
const shs = (size: number, wall: number): Profile => ({ kind: 'RECTANGLE_HOLLOW', xDim: size, yDim: size, wallThickness: wall });
const over = 160, t = TRESTLE;
if (lying) for (const x of [0.2 * length, 0.8 * length]) {
put('primer', model.addBeam({ length: width + 2 * over, profile: shs(t.bearer, 5), origin: [x, -over, t.height - t.bearer / 2], axisX: Y, axisZ: Z, ...steel }));
for (const y of [-over + t.leg / 2 + 60, width + over - t.leg / 2 - 60]) {
put('primer', model.addColumn({ height: t.height - t.bearer - 12, profile: shs(t.leg, 4), origin: [x, y, 12], axisX: X, axisZ: Z, ...steel }));
put('primer', model.addColumn({ height: 12, profile: { kind: 'RECTANGULAR', width: 320, height: 200 }, origin: [x, y, 0], axisX: X, axisZ: Z, ...steel }));
}
for (const y of [-over + 30, width + over - 30]) put('primer', model.addColumn({ height: t.stop, profile: shs(50, 4), origin: [x, y, t.height], axisX: X, axisZ: Z, ...steel }));
}
if (lying) put('floor', model.addSlab({ length: length + 500, width: width + 2 * over + 500, thickness: 150, origin: [-250, -over - 250, -150], axisX: X, axisZ: Z, predefinedType: 'BASESLAB', materialName: 'Concrete' }));
else [ROW / 2, -ROW / 2].forEach((cx, row) => drills.set(put('floor', model.addFooting({ length: width + 400, width: deepest + 200, thickness: 200, origin: [cx + deepest / 2 + 100, -200, -200], axisX: Y, axisZ: Z, predefinedType: 'STRIP_FOOTING', materialName: 'Concrete' })), inFooting[row]!));
// The kernel measures each member. Volume and density give the mass for each metre, to set against the table.
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;
};
const report = members.map((m) => {
const kg = (unwrap(measureVolume(solidsOf(m.id)[0] as Body)) * STEEL) / (length / 1000);
return m.name + ' ' + kg.toFixed(1) + (m.kg === undefined ? '' : ' (' + m.kg + ')');
});
const groups = new Map<Tone, Body[]>();
for (const p of placed) {
if (p.tone === 'bolt') continue; // the screws below go in the place of these proxies
const tools = drills.get(p.id), list = solidsOf(p.id);
groups.set(p.tone, [...(groups.get(p.tone) ?? []), ...(tools ? list.map((body) => keep(unwrap(cutAll(body, tools)))) : list)]);
}
if (screw) groups.set('bolt', screws.map((at) => keep(translate(screw, at))));
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> = { rolled: '#c3c9d1', hollow: '#12b5b0', formed: '#f5f2ea', primer: '#ff5a1f', bolt: '#d3a956', floor: '#48515c' };
// Try stock({ as: 'beams', length: 1500 }), stock({ radii: false }) or stock({ length: 900 }).
const rack = stock();
console.log('Mass in kg for each metre, from the kernel volume (and from the steel table): ' + rack.report.join(', '));
export default present(
rack.shown.map((g) => color(g.shape, COLORS[g.tone])),
{
bimTree: rack.model.toTreeSummary(),
ifc: async () => unwrap(await toIfc(rack.model, { applicationName: 'brepjs playground', applicationVersion: '1.0' })),
},
);Functions used
placedSolids toIfc box compound cutAll cylinder extrude getBounds line loft measureVolume polygon translate unwrap wire color present