@nubisco/bim 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,686 @@
1
+ import {
2
+ DEFAULTS,
3
+ isGlazed
4
+ } from "./chunk-6Q4JIXFQ.js";
5
+
6
+ // src/ifc.ts
7
+ var Enum = class {
8
+ constructor(v) {
9
+ this.v = v;
10
+ }
11
+ v;
12
+ };
13
+ var Int = class {
14
+ constructor(v) {
15
+ this.v = v;
16
+ }
17
+ v;
18
+ };
19
+ var Typed = class {
20
+ constructor(t, v) {
21
+ this.t = t;
22
+ this.v = v;
23
+ }
24
+ t;
25
+ v;
26
+ };
27
+ var DERIVED = /* @__PURE__ */ Symbol("derived");
28
+ var E = (v) => new Enum(v);
29
+ var I = (v) => new Int(v);
30
+ var T = (t, v) => new Typed(t, v);
31
+ function stepString(s) {
32
+ let out = "";
33
+ for (const ch of s) {
34
+ const c = ch.codePointAt(0);
35
+ if (c === 39) out += "''";
36
+ else if (c === 92) out += "\\\\";
37
+ else if (c >= 32 && c < 127) out += ch;
38
+ else if (c <= 65535) out += `\\X2\\${c.toString(16).toUpperCase().padStart(4, "0")}\\X0\\`;
39
+ else out += `\\X4\\${c.toString(16).toUpperCase().padStart(8, "0")}\\X0\\`;
40
+ }
41
+ return `'${out}'`;
42
+ }
43
+ function stepReal(n) {
44
+ if (!Number.isFinite(n)) throw new Error(`Not a number: ${n}`);
45
+ let r = Math.round(n * 1e6) / 1e6;
46
+ if (Object.is(r, -0)) r = 0;
47
+ const s = String(r);
48
+ if (s.includes("e")) {
49
+ const [m2, e] = r.toExponential().split("e");
50
+ return `${m2.includes(".") ? m2 : m2 + "."}E${e}`;
51
+ }
52
+ return s.includes(".") ? s : `${s}.`;
53
+ }
54
+ function fmt(v) {
55
+ if (v === null) return "$";
56
+ if (v === DERIVED) return "*";
57
+ if (typeof v === "string") return stepString(v);
58
+ if (typeof v === "number") return stepReal(v);
59
+ if (typeof v === "boolean") return v ? ".T." : ".F.";
60
+ if (Array.isArray(v)) return `(${v.map(fmt).join(",")})`;
61
+ if (v instanceof Enum) return `.${v.v}.`;
62
+ if (v instanceof Int) return String(Math.round(v.v));
63
+ if (v instanceof Typed) return `${v.t}(${fmt(v.v)})`;
64
+ return `#${v.ref}`;
65
+ }
66
+ var Step = class {
67
+ lines = [];
68
+ add(type, ...args) {
69
+ const ref = this.lines.length + 1;
70
+ this.lines.push(`#${ref}=${type}(${args.map(fmt).join(",")});`);
71
+ return { ref };
72
+ }
73
+ get data() {
74
+ return this.lines.join("\n");
75
+ }
76
+ };
77
+ var B64 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$";
78
+ function hash128(s) {
79
+ let h1 = 1779033703;
80
+ let h2 = 3144134277;
81
+ let h3 = 1013904242;
82
+ let h4 = 2773480762;
83
+ for (let i = 0; i < s.length; i++) {
84
+ const k = s.charCodeAt(i);
85
+ h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
86
+ h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
87
+ h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
88
+ h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
89
+ }
90
+ h1 = Math.imul(h3 ^ h1 >>> 18, 597399067);
91
+ h2 = Math.imul(h4 ^ h2 >>> 22, 2869860233);
92
+ h3 = Math.imul(h1 ^ h3 >>> 17, 951274213);
93
+ h4 = Math.imul(h2 ^ h4 >>> 19, 2716044179);
94
+ h1 ^= h2 ^ h3 ^ h4;
95
+ h2 ^= h1;
96
+ h3 ^= h1;
97
+ h4 ^= h1;
98
+ return [h1 >>> 0, h2 >>> 0, h3 >>> 0, h4 >>> 0];
99
+ }
100
+ function globalId(key) {
101
+ let n = hash128(key).reduce((acc, x) => acc << 32n | BigInt(x), 0n);
102
+ let out = "";
103
+ for (let i = 0; i < 22; i++) {
104
+ out = B64[Number(n & 63n)] + out;
105
+ n >>= 6n;
106
+ }
107
+ return out;
108
+ }
109
+ var DEVICE_CLASSES = [
110
+ "IfcActuator",
111
+ "IfcAlarm",
112
+ "IfcAudioVisualAppliance",
113
+ "IfcBuildingElementProxy",
114
+ "IfcController",
115
+ "IfcElectricAppliance",
116
+ "IfcFlowMeter",
117
+ "IfcLightFixture",
118
+ "IfcOutlet",
119
+ "IfcSensor",
120
+ "IfcSwitchingDevice",
121
+ "IfcUnitaryEquipment"
122
+ ];
123
+ var FURNITURE_HEIGHT = {
124
+ table: 750,
125
+ cabinet: 900,
126
+ island: 900,
127
+ bed: 500,
128
+ sofa: 800,
129
+ shelves: 1800,
130
+ rug: 10,
131
+ bath: 550,
132
+ shower: 50,
133
+ toilet: 400,
134
+ basin: 850,
135
+ lounger: 350,
136
+ parasol: 2300,
137
+ planter: 600,
138
+ pergola: 2500
139
+ };
140
+ var FURNITURE_NAME = {
141
+ table: "Table",
142
+ cabinet: "Cabinet",
143
+ island: "Kitchen island",
144
+ bed: "Bed",
145
+ sofa: "Sofa",
146
+ shelves: "Shelves",
147
+ rug: "Rug",
148
+ bath: "Bath",
149
+ shower: "Shower",
150
+ toilet: "Toilet",
151
+ basin: "Washbasin",
152
+ lounger: "Sun lounger",
153
+ parasol: "Parasol",
154
+ planter: "Planter",
155
+ pergola: "Pergola"
156
+ };
157
+ var SANITARY = {
158
+ bath: "BATH",
159
+ shower: "SHOWER",
160
+ toilet: "TOILETPAN",
161
+ basin: "WASHHANDBASIN"
162
+ };
163
+ var FURNITURE_TYPE = {
164
+ table: "TABLE",
165
+ bed: "BED",
166
+ sofa: "SOFA",
167
+ shelves: "SHELF"
168
+ };
169
+ var COVERING_NAME = {
170
+ shutter: "Roller shutter",
171
+ "external-blind": "External blind",
172
+ awning: "Awning",
173
+ curtain: "Curtains",
174
+ blind: "Interior blind"
175
+ };
176
+ var COVERING_TYPE = {
177
+ shutter: "SHUTTER",
178
+ "external-blind": "JALOUSIE",
179
+ awning: "AWNING",
180
+ curtain: "USERDEFINED",
181
+ blind: "USERDEFINED"
182
+ };
183
+ function doorOperation(d) {
184
+ const side = d.hinge === "end" ? "RIGHT" : "LEFT";
185
+ switch (d.operation) {
186
+ case "swing":
187
+ return { type: `SINGLE_SWING_${side}`, user: null };
188
+ case "double-swing":
189
+ return { type: "DOUBLE_DOOR_SINGLE_SWING", user: null };
190
+ case "sliding":
191
+ return { type: "DOUBLE_DOOR_SLIDING", user: null };
192
+ case "folding":
193
+ return { type: `FOLDING_TO_${side}`, user: null };
194
+ case "lift-slide":
195
+ return { type: "USERDEFINED", user: "LIFT_AND_SLIDE" };
196
+ case "pocket":
197
+ return { type: "USERDEFINED", user: "POCKET" };
198
+ }
199
+ }
200
+ var SPACE_TYPE = {
201
+ room: { type: "INTERNAL", objectType: null },
202
+ outdoor: { type: "EXTERNAL", objectType: null },
203
+ paved: { type: "USERDEFINED", objectType: "Paving" },
204
+ pool: { type: "USERDEFINED", objectType: "Pool" }
205
+ };
206
+ var m = (mm) => mm / 1e3;
207
+ var P = (p) => [m(p[0]), -m(p[1])];
208
+ function insidePolygon(poly, x, y) {
209
+ let inside = false;
210
+ for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
211
+ const [xi, yi] = poly[i];
212
+ const [xj, yj] = poly[j];
213
+ if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) inside = !inside;
214
+ }
215
+ return inside;
216
+ }
217
+ function inSpace(s, x, y) {
218
+ return insidePolygon(s.outline, x, y) && !(s.holes ?? []).some((h) => insidePolygon(h, x, y));
219
+ }
220
+ function toIfc(plan, opts) {
221
+ const w = new Step();
222
+ const gid = (key) => globalId(`${opts.name}|${key}`);
223
+ const point3 = (x, y, z) => w.add("IFCCARTESIANPOINT", [x, y, z]);
224
+ const point2 = (x, y) => w.add("IFCCARTESIANPOINT", [x, y]);
225
+ const dir3 = (x, y, z) => w.add("IFCDIRECTION", [x, y, z]);
226
+ const zUp = dir3(0, 0, 1);
227
+ const origin = point3(0, 0, 0);
228
+ const wcs = w.add("IFCAXIS2PLACEMENT3D", origin, null, null);
229
+ const context = w.add("IFCGEOMETRICREPRESENTATIONCONTEXT", null, "Model", I(3), 1e-5, wcs, null);
230
+ const body = w.add(
231
+ "IFCGEOMETRICREPRESENTATIONSUBCONTEXT",
232
+ "Body",
233
+ "Model",
234
+ DERIVED,
235
+ DERIVED,
236
+ DERIVED,
237
+ DERIVED,
238
+ context,
239
+ null,
240
+ E("MODEL_VIEW"),
241
+ null
242
+ );
243
+ const units = w.add("IFCUNITASSIGNMENT", [
244
+ w.add("IFCSIUNIT", DERIVED, E("LENGTHUNIT"), null, E("METRE")),
245
+ w.add("IFCSIUNIT", DERIVED, E("AREAUNIT"), null, E("SQUARE_METRE")),
246
+ w.add("IFCSIUNIT", DERIVED, E("VOLUMEUNIT"), null, E("CUBIC_METRE")),
247
+ w.add("IFCSIUNIT", DERIVED, E("PLANEANGLEUNIT"), null, E("RADIAN"))
248
+ ]);
249
+ const place = (rel2, at, x) => {
250
+ const axes = x ? w.add("IFCAXIS2PLACEMENT3D", point3(...at), zUp, dir3(x[0], x[1], 0)) : w.add("IFCAXIS2PLACEMENT3D", point3(...at), null, null);
251
+ return w.add("IFCLOCALPLACEMENT", rel2, axes);
252
+ };
253
+ const solid = (profile, z0, depth) => w.add("IFCEXTRUDEDAREASOLID", profile, w.add("IFCAXIS2PLACEMENT3D", point3(0, 0, z0), null, null), zUp, depth);
254
+ const shape = (...solids) => w.add("IFCPRODUCTDEFINITIONSHAPE", null, null, [
255
+ w.add("IFCSHAPEREPRESENTATION", body, "Body", "SweptSolid", solids)
256
+ ]);
257
+ const box = (cx, cy, xd, yd, z0, depth) => solid(
258
+ w.add(
259
+ "IFCRECTANGLEPROFILEDEF",
260
+ E("AREA"),
261
+ null,
262
+ w.add("IFCAXIS2PLACEMENT2D", point2(cx, cy), null),
263
+ Math.max(xd, 1e-3),
264
+ Math.max(yd, 1e-3)
265
+ ),
266
+ z0,
267
+ Math.max(depth, 1e-3)
268
+ );
269
+ const loop = (pts) => {
270
+ const ps = pts.map((p) => point2(...P(p)));
271
+ return w.add("IFCPOLYLINE", [...ps, ps[0]]);
272
+ };
273
+ const area = (s, z0, depth) => solid(
274
+ s.holes?.length ? w.add("IFCARBITRARYPROFILEDEFWITHVOIDS", E("AREA"), null, loop(s.outline), s.holes.map(loop)) : w.add("IFCARBITRARYCLOSEDPROFILEDEF", E("AREA"), null, loop(s.outline)),
275
+ z0,
276
+ depth
277
+ );
278
+ const rel = (type, key, ...args) => w.add(type, gid(`rel|${key}`), null, null, null, ...args);
279
+ const psets = [];
280
+ const materials = /* @__PURE__ */ new Map();
281
+ const material = (name, on) => {
282
+ if (!materials.has(name)) materials.set(name, { material: w.add("IFCMATERIAL", name, null, null), on: [] });
283
+ materials.get(name).on.push(on);
284
+ };
285
+ const project = w.add("IFCPROJECT", gid("project"), null, opts.name, null, null, null, null, [context], units);
286
+ const sitePlace = place(null, [0, 0, 0]);
287
+ const site = w.add(
288
+ "IFCSITE",
289
+ gid("site"),
290
+ null,
291
+ "Plot",
292
+ null,
293
+ null,
294
+ sitePlace,
295
+ null,
296
+ null,
297
+ E("ELEMENT"),
298
+ null,
299
+ null,
300
+ null,
301
+ null,
302
+ null
303
+ );
304
+ const buildingPlace = place(sitePlace, [0, 0, 0]);
305
+ const building = w.add(
306
+ "IFCBUILDING",
307
+ gid("building"),
308
+ null,
309
+ opts.name,
310
+ null,
311
+ null,
312
+ buildingPlace,
313
+ null,
314
+ null,
315
+ E("ELEMENT"),
316
+ null,
317
+ null,
318
+ null
319
+ );
320
+ rel("IFCRELAGGREGATES", "project", project, [site]);
321
+ psets.push({
322
+ key: "site",
323
+ name: "House_Site",
324
+ on: site,
325
+ props: [
326
+ ["Width", T("IFCPOSITIVELENGTHMEASURE", m(plan.site.w))],
327
+ ["Depth", T("IFCPOSITIVELENGTHMEASURE", m(plan.site.h))],
328
+ ["Snap", T("IFCPOSITIVELENGTHMEASURE", m(plan.snap))]
329
+ ]
330
+ });
331
+ rel("IFCRELAGGREGATES", "site", site, [building]);
332
+ const layerSets = /* @__PURE__ */ new Map();
333
+ const storeys = [];
334
+ for (const st of plan.storeys) storeys.push(exportStorey(st));
335
+ rel("IFCRELAGGREGATES", "building", building, storeys);
336
+ for (const [t, { usage, walls }] of layerSets) rel("IFCRELASSOCIATESMATERIAL", `walls|${t}`, walls, usage);
337
+ for (const [name, { material: mat, on }] of materials) rel("IFCRELASSOCIATESMATERIAL", `material|${name}`, on, mat);
338
+ for (const p of psets) {
339
+ const props = p.props.filter((x) => x[1] !== null).map(([n, v]) => w.add("IFCPROPERTYSINGLEVALUE", n, null, v, null));
340
+ if (!props.length) continue;
341
+ const set = w.add("IFCPROPERTYSET", gid(`pset|${p.key}`), null, p.name, null, props);
342
+ rel("IFCRELDEFINESBYPROPERTIES", `pset|${p.key}`, [p.on], set);
343
+ }
344
+ function exportStorey(st) {
345
+ const k = (s) => `${st.id}|${s}`;
346
+ const placement = place(buildingPlace, [0, 0, m(st.elevation)]);
347
+ const storey = w.add(
348
+ "IFCBUILDINGSTOREY",
349
+ gid(k("storey")),
350
+ null,
351
+ st.name,
352
+ null,
353
+ null,
354
+ placement,
355
+ null,
356
+ null,
357
+ E("ELEMENT"),
358
+ m(st.elevation)
359
+ );
360
+ const contained = [];
361
+ const walled = st.spaces.filter((s) => s.kind === "room");
362
+ const roomAt = (x, y) => walled.some((s) => inSpace(s, x, y));
363
+ const spaces = [];
364
+ const wallTop = Math.max(DEFAULTS.wallHeight, ...st.walls.map((x) => x.height));
365
+ for (const s of st.spaces) {
366
+ if (s.outline.length < 3) continue;
367
+ const t = SPACE_TYPE[s.kind];
368
+ const [z0, depth] = s.kind === "room" ? [0, m(wallTop)] : s.kind === "pool" ? [-1.5, 1.5] : [0, 0.05];
369
+ spaces.push(
370
+ w.add(
371
+ "IFCSPACE",
372
+ gid(k(`space|${s.id}`)),
373
+ null,
374
+ s.name,
375
+ null,
376
+ t.objectType,
377
+ place(placement, [0, 0, 0]),
378
+ shape(area(s, z0, depth)),
379
+ null,
380
+ E("ELEMENT"),
381
+ E(t.type),
382
+ null
383
+ )
384
+ );
385
+ if (s.kind === "room")
386
+ contained.push(
387
+ w.add(
388
+ "IFCSLAB",
389
+ gid(k(`slab|${s.id}`)),
390
+ null,
391
+ `Floor, ${s.name}`,
392
+ null,
393
+ null,
394
+ place(placement, [0, 0, 0]),
395
+ shape(area(s, -0.2, 0.2)),
396
+ s.id,
397
+ E(st.level <= 0 ? "BASESLAB" : "FLOOR")
398
+ )
399
+ );
400
+ }
401
+ if (spaces.length) rel("IFCRELAGGREGATES", k("spaces"), storey, spaces);
402
+ const wallPlace = /* @__PURE__ */ new Map();
403
+ for (const wl of st.walls) {
404
+ const dx = wl.b[0] - wl.a[0];
405
+ const dy = wl.b[1] - wl.a[1];
406
+ const len = Math.hypot(dx, dy);
407
+ if (len < 1) continue;
408
+ const pl = place(placement, [...P(wl.a), 0], [dx / len, -dy / len]);
409
+ const ref = w.add(
410
+ "IFCWALL",
411
+ gid(k(`wall|${wl.id}`)),
412
+ null,
413
+ "Wall",
414
+ null,
415
+ null,
416
+ pl,
417
+ shape(box(m(len) / 2, 0, m(len), m(wl.thickness), 0, m(wl.height))),
418
+ wl.id,
419
+ E("STANDARD")
420
+ );
421
+ contained.push(ref);
422
+ if (!layerSets.has(wl.thickness)) {
423
+ const layer = w.add(
424
+ "IFCMATERIALLAYER",
425
+ w.add("IFCMATERIAL", "Wall", null, null),
426
+ m(wl.thickness),
427
+ null,
428
+ null,
429
+ null,
430
+ null,
431
+ null
432
+ );
433
+ const set = w.add("IFCMATERIALLAYERSET", [layer], `Wall ${wl.thickness} mm`, null);
434
+ layerSets.set(wl.thickness, {
435
+ usage: w.add("IFCMATERIALLAYERSETUSAGE", set, E("AXIS2"), E("POSITIVE"), -m(wl.thickness) / 2, null),
436
+ walls: []
437
+ });
438
+ }
439
+ layerSets.get(wl.thickness).walls.push(ref);
440
+ wallPlace.set(wl.id, { ref, placement: pl, wall: wl, len, left: [dy / len, -dx / len] });
441
+ }
442
+ const fills = /* @__PURE__ */ new Map();
443
+ const shading = /* @__PURE__ */ new Map();
444
+ for (const o of st.openings) {
445
+ const host = wallPlace.get(o.wall);
446
+ if (!host) continue;
447
+ const { wall } = host;
448
+ const glazed = o.kind !== "gap";
449
+ const sill = glazed ? Math.max(0, o.sill) : 0;
450
+ const head = glazed ? Math.min(wall.height, Math.max(o.head, sill + 1)) : wall.height;
451
+ const ok = k(`opening|${o.id}`);
452
+ const opPlace = place(host.placement, [m(o.at), 0, m(sill)]);
453
+ const opening = w.add(
454
+ "IFCOPENINGELEMENT",
455
+ gid(ok),
456
+ null,
457
+ o.kind === "gap" ? "Open wall" : "Opening",
458
+ null,
459
+ null,
460
+ opPlace,
461
+ shape(box(m(o.width) / 2, 0, m(o.width), m(wall.thickness) + 0.1, 0, m(head - sill))),
462
+ o.id,
463
+ E("OPENING")
464
+ );
465
+ rel("IFCRELVOIDSELEMENT", `${ok}|voids`, host.ref, opening);
466
+ if (o.kind === "gap") continue;
467
+ const fillPlace = place(opPlace, [0, 0, 0]);
468
+ const fillShape = shape(box(m(o.width) / 2, 0, m(o.width), o.kind === "door" ? 0.06 : 0.04, 0, m(head - sill)));
469
+ let fill;
470
+ if (o.kind === "door") {
471
+ const op = doorOperation(o);
472
+ fill = w.add(
473
+ "IFCDOOR",
474
+ gid(k(`door|${o.id}`)),
475
+ null,
476
+ "Door",
477
+ null,
478
+ null,
479
+ fillPlace,
480
+ fillShape,
481
+ o.id,
482
+ m(head - sill),
483
+ m(o.width),
484
+ E("DOOR"),
485
+ E(op.type),
486
+ op.user
487
+ );
488
+ } else {
489
+ fill = w.add(
490
+ "IFCWINDOW",
491
+ gid(k(`window|${o.id}`)),
492
+ null,
493
+ "Window",
494
+ null,
495
+ null,
496
+ fillPlace,
497
+ fillShape,
498
+ o.id,
499
+ m(head - sill),
500
+ m(o.width),
501
+ E("WINDOW"),
502
+ E(o.operation === "sliding" ? "DOUBLE_PANEL_VERTICAL" : "SINGLE_PANEL"),
503
+ null
504
+ );
505
+ }
506
+ contained.push(fill);
507
+ fills.set(o.id, fill);
508
+ rel("IFCRELFILLSELEMENT", `${ok}|fills`, opening, fill);
509
+ if (o.frame?.material) material(o.frame.material, fill);
510
+ psets.push({
511
+ key: k(`opening|${o.id}`),
512
+ name: "House_Opening",
513
+ on: fill,
514
+ props: [
515
+ ["Operation", T("IFCLABEL", o.operation)],
516
+ ["Leaf", o.kind === "door" ? T("IFCLABEL", o.leaf) : null],
517
+ ["FrameMaterial", o.frame?.material ? T("IFCLABEL", o.frame.material) : null],
518
+ ["FrameColour", o.frame?.colour ? T("IFCLABEL", o.frame.colour) : null],
519
+ ["Hinge", o.hinge ? T("IFCLABEL", o.hinge) : null],
520
+ ["Opens", o.opens ? T("IFCLABEL", o.opens) : null],
521
+ ["SillHeight", T("IFCLENGTHMEASURE", m(sill))],
522
+ ["HeadHeight", T("IFCLENGTHMEASURE", m(head))]
523
+ ]
524
+ });
525
+ if (!isGlazed(o)) continue;
526
+ const mid = [
527
+ wall.a[0] + (wall.b[0] - wall.a[0]) * (o.at + o.width / 2) / host.len,
528
+ wall.a[1] + (wall.b[1] - wall.a[1]) * (o.at + o.width / 2) / host.len
529
+ ];
530
+ const probe = wall.thickness / 2 + 200;
531
+ const leftRoom = roomAt(mid[0] + host.left[0] * probe, mid[1] + host.left[1] * probe);
532
+ const rightRoom = roomAt(mid[0] - host.left[0] * probe, mid[1] - host.left[1] * probe);
533
+ const insideIsLeft = !(rightRoom && !leftRoom);
534
+ const driven = new Set(st.placements.filter((p) => p.host?.opening === o.id).map((p) => p.host?.covering));
535
+ for (const c of o.coverings ?? []) {
536
+ const sign = c.side === "inside" === insideIsLeft ? 1 : -1;
537
+ const off = sign * (m(wall.thickness) / 2 + 0.05);
538
+ const W = m(o.width);
539
+ const Hh = m(head - sill);
540
+ const solids = c.kind === "curtain" ? [box(W * 0.075, off, W * 0.15, 0.04, 0, Hh), box(W * 0.925, off, W * 0.15, 0.04, 0, Hh)] : c.kind === "awning" ? [box(W / 2, off + sign * 0.1, W, 0.2, Hh, 0.12)] : [box(W / 2, off, W, 0.12, Math.max(0, Hh - 0.18), 0.18)];
541
+ const ref = w.add(
542
+ "IFCSHADINGDEVICE",
543
+ gid(k(`covering|${o.id}|${c.id}`)),
544
+ null,
545
+ COVERING_NAME[c.kind],
546
+ null,
547
+ COVERING_TYPE[c.kind] === "USERDEFINED" ? COVERING_NAME[c.kind] : null,
548
+ place(opPlace, [0, 0, 0]),
549
+ shape(...solids),
550
+ c.id,
551
+ E(COVERING_TYPE[c.kind])
552
+ );
553
+ contained.push(ref);
554
+ shading.set(`${o.id}|${c.id}`, ref);
555
+ rel("IFCRELCONNECTSELEMENTS", k(`covering|${o.id}|${c.id}|on`), null, fill, ref);
556
+ psets.push({
557
+ key: k(`covering|${o.id}|${c.id}`),
558
+ name: "House_Covering",
559
+ on: ref,
560
+ props: [
561
+ ["Kind", T("IFCLABEL", c.kind)],
562
+ ["Side", T("IFCLABEL", c.side)],
563
+ ["Motorised", T("IFCBOOLEAN", driven.has(c.id))]
564
+ ]
565
+ });
566
+ }
567
+ }
568
+ for (const r of st.radiators) {
569
+ const dx = r.b[0] - r.a[0];
570
+ const dy = r.b[1] - r.a[1];
571
+ const len = Math.hypot(dx, dy);
572
+ if (len < 1) continue;
573
+ const sign = r.side === "left" ? 1 : -1;
574
+ contained.push(
575
+ w.add(
576
+ "IFCSPACEHEATER",
577
+ gid(k(`radiator|${r.id}`)),
578
+ null,
579
+ "Radiator",
580
+ null,
581
+ null,
582
+ place(placement, [...P(r.a), 0], [dx / len, -dy / len]),
583
+ shape(box(m(len) / 2, sign * 0.06, m(len), 0.08, 0.15, 0.6)),
584
+ r.id,
585
+ E("RADIATOR")
586
+ )
587
+ );
588
+ }
589
+ for (const f of st.furniture) {
590
+ const sanitary = SANITARY[f.kind];
591
+ const type = sanitary ?? FURNITURE_TYPE[f.kind] ?? "USERDEFINED";
592
+ const [cx, cy] = P([f.x + f.w / 2, f.y + f.d / 2]);
593
+ contained.push(
594
+ w.add(
595
+ sanitary ? "IFCSANITARYTERMINAL" : "IFCFURNITURE",
596
+ gid(k(`furniture|${f.id}`)),
597
+ null,
598
+ FURNITURE_NAME[f.kind],
599
+ null,
600
+ type === "USERDEFINED" ? FURNITURE_NAME[f.kind] : null,
601
+ place(placement, [cx, cy, 0]),
602
+ shape(box(0, 0, m(f.w), m(f.d), 0, m(f.height ?? FURNITURE_HEIGHT[f.kind]))),
603
+ f.id,
604
+ E(type)
605
+ )
606
+ );
607
+ }
608
+ for (const p of st.placements) {
609
+ const d = opts.devices?.[p.ref];
610
+ if (!d || !DEVICE_CLASSES.includes(d.ifcClass)) continue;
611
+ const z = d.z ?? deviceHeight(p, st);
612
+ const ref = w.add(
613
+ d.ifcClass.toUpperCase(),
614
+ gid(k(`device|${p.ref}`)),
615
+ null,
616
+ d.name,
617
+ null,
618
+ d.predefined === "USERDEFINED" ? d.objectType ?? d.name : null,
619
+ place(placement, [...P([p.x, p.y]), m(z)]),
620
+ shape(box(0, 0, 0.2, 0.2, -0.1, 0.2)),
621
+ null,
622
+ E(d.predefined)
623
+ );
624
+ contained.push(ref);
625
+ psets.push({
626
+ key: k(`device|${p.ref}`),
627
+ name: "House_Device",
628
+ on: ref,
629
+ props: [["Reference", T("IFCIDENTIFIER", p.ref)]]
630
+ });
631
+ const drives = p.host?.covering ? shading.get(`${p.host.opening}|${p.host.covering}`) : void 0;
632
+ if (drives) rel("IFCRELCONNECTSELEMENTS", k(`device|${p.ref}|drives`), null, ref, drives);
633
+ }
634
+ if (contained.length) rel("IFCRELCONTAINEDINSPATIALSTRUCTURE", k("contains"), contained, storey);
635
+ return storey;
636
+ }
637
+ const header = [
638
+ "ISO-10303-21;",
639
+ "HEADER;",
640
+ `FILE_DESCRIPTION((${stepString("ViewDefinition [DesignTransferView]")}),'2;1');`,
641
+ `FILE_NAME(${[
642
+ stepString(opts.fileName ?? "house.ifc"),
643
+ stepString(opts.timestamp ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 19)),
644
+ `(${stepString("")})`,
645
+ `(${stepString("")})`,
646
+ stepString(opts.application ?? ""),
647
+ stepString(opts.application ?? ""),
648
+ stepString("")
649
+ ].join(",")});`,
650
+ "FILE_SCHEMA(('IFC4'));",
651
+ "ENDSEC;",
652
+ "DATA;"
653
+ ];
654
+ return `${header.join("\n")}
655
+ ${w.data}
656
+ ENDSEC;
657
+ END-ISO-10303-21;
658
+ `;
659
+ }
660
+ function deviceHeight(p, st) {
661
+ const top = Math.max(DEFAULTS.wallHeight, ...st.walls.map((x) => x.height));
662
+ switch (p.mount) {
663
+ case "ceiling":
664
+ return top - 100;
665
+ case "wall":
666
+ return 1800;
667
+ case "table":
668
+ return 850;
669
+ case "floor":
670
+ return 1400;
671
+ case "pool":
672
+ return -500;
673
+ default:
674
+ return p.host ? 2e3 : 1100;
675
+ }
676
+ }
677
+
678
+ export {
679
+ stepString,
680
+ stepReal,
681
+ globalId,
682
+ DEVICE_CLASSES,
683
+ FURNITURE_HEIGHT,
684
+ FURNITURE_NAME,
685
+ toIfc
686
+ };