[B5] IFC: Daecher als IfcRoof (Schicht-Meshes wie im 3D, IfcRoofType mit Schichten), Stuetzen als IfcColumn mit Material; Dach-Meshes nach aussen gewunden

- toWalls3d/roofs.ts: Ober-/Unterseite und Stirnflaechen je Dachschicht konsistent nach aussen gewunden (render3d
  zeichnet Daecher doppelseitig, Bild unveraendert; IFC-Closed-Flag und STL/OBJ-Normalen profitieren)
- Bekannt offen: an Walm-/Zeltspitzen trifft die paarweise Gehrung der Unterseite nicht exakt (Restluecke < 0.01 m2),
  solche Daecher gehen als nicht geschlossenes Face-Set ins IFC
- Tests (Wicklung aller Dachformen, IfcRoof/IfcColumn), ifcopenshell gueltig

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-27 20:40:02 +00:00
1 parent af8091251d
commit 53e189a8e4
5 files changed
+190 -8

No files matched your search

+34
View File
@@ -449,3 +449,37 @@ describe("Materialschichten über Bauteiltypen", () => {
expect(lines(spf, "IFCMATERIAL")).toHaveLength(1);
});
});
describe("Dächer und Stützen", () => {
const withRoofAndColumn = (): Project => ({
...fixtureProject(),
roofTypes: [{ id: "rt", name: "Ziegeldach", layers: [{ componentId: "c", thickness: 0.05 }, { componentId: "c", thickness: 0.2 }] }],
roofs: [
{
id: "D1", type: "roof", floorId: "og", categoryCode: "35",
outline: [{ x: 0, y: 0 }, { x: 5, y: 0 }, { x: 5, y: 4 }, { x: 0, y: 4 }],
shape: "sattel", pitchDeg: 35, overhang: 0.3, ridgeAxis: "x", thickness: 0.25, roofTypeId: "rt",
},
],
columns: [
{
id: "S1", type: "column", floorId: "eg", categoryCode: "50",
position: { x: 2, y: 2 }, profile: { kind: "rect", width: 0.3, depth: 0.3 }, rotation: 0, height: 2.6, componentId: "c",
},
],
});
it("Dach → IfcRoof (Satteldach) mit geschlossenem Mesh und IfcRoofType", () => {
const spf = exportIfcSpf(withRoofAndColumn());
const roof = spf.split("\n").find((l) => l.includes("=IFCROOF("))!;
expect(roof).toContain(".GABLE_ROOF.");
expect(spf.split("\n").filter((l) => l.includes("=IFCTRIANGULATEDFACESET(") && l.includes(".T."))).not.toHaveLength(0);
expect(spf).toMatch(/=IFCROOFTYPE\(.*'Ziegeldach'.*\.GABLE_ROOF\.\);/);
});
it("Stütze → IfcColumn mit Material", () => {
const spf = exportIfcSpf(withRoofAndColumn());
const col = spf.split("\n").find((l) => l.includes("=IFCCOLUMN("))!;
expect(col).toContain(".COLUMN.");
const colId = col.slice(0, col.indexOf("="));
expect(spf.split("\n").some((l) => l.includes("=IFCRELASSOCIATESMATERIAL(") && l.includes(`(${colId})`))).toBe(true);
});
});
+74 -1
View File
@@ -30,6 +30,8 @@
// Tür/Fenster bleiben als eigenes Objekt IfcDoor/IfcWindow mit eigener Box-
// Geometrie erhalten (füllt das ausgeschnittene Loch, "sieht aus wie 3D").
// • Extrusion → IfcBuildingElementProxy aus points+height.
// • Dach → IfcRoof (Schicht-Meshes wie im 3D), Dachtyp → IfcRoofType mit Schichten.
// • Stütze → IfcColumn (Profil-Extrusion), Bauteil → IfcMaterial.
// • Raum → IfcSpace (im Geschoss aggregiert) mit Qto_SpaceBaseQuantities und SIA-416-Kategorie.
// • Treppe → IfcStair, GEOMETRISCH bewusst vereinfacht auf einen
// extrudierten Bounding-Footprint (Lauf-Rechteck bei "straight"; Achsen-
@@ -55,6 +57,7 @@ import type {
Wall,
} from "../model/types";
import {
columnLabel,
getCeilingType,
getWallType,
openingLabel,
@@ -63,6 +66,7 @@ import {
import { projectToWorldCoords } from "../model/geoRebase";
import {
ceilingVerticalExtent,
columnVerticalExtent,
stairVerticalExtent,
wallReferenceOffset,
wallVerticalExtent,
@@ -71,6 +75,8 @@ import { pickGeometry } from "../plan/toWalls3d";
import type { RWall } from "../plan/toWalls3d";
import { isWatertight, wallCutMesh } from "../plan/wallMeshCut";
import { evaluateRoom } from "../geometry/roomArea";
import { columnFootprint } from "../geometry/column";
import { emitRoofs } from "../plan/toWalls3d/roofs";
// ── IFC-GUID (Base64-Kompression, 22 Zeichen) ───────────────────────────────
// Standard-Kompressionsalgorithmus (IfcOpenShell guid.compress): das erste
@@ -559,7 +565,7 @@ export function exportIfcSpf(projectIn: Project): string {
}
const elementTypes = new Map<string, ElementTypeRef>();
const typeFor = (
ifcType: "IFCWALLTYPE" | "IFCSLABTYPE",
ifcType: "IFCWALLTYPE" | "IFCSLABTYPE" | "IFCROOFTYPE",
predefined: string,
t: { id: string; name: string; layers: { componentId: string; thickness: number }[] },
): ElementTypeRef => {
@@ -818,6 +824,73 @@ export function exportIfcSpf(projectIn: Project): string {
);
}
// ── Dächer → IfcRoof ───────────────────────────────────────────────────
// Dieselben geschlossenen Schicht-Meshes wie das 3D (`emitRoofs`: Dachflächen je Schicht,
// an First/Grat gehrt), zu EINEM Face-Set je Dach vereint. Modell-Koordinaten sind bereits
// Z-oben (kein Achsentausch wie bei den Wänden); die Wicklung wird so gewählt, dass das Volumen
// positiv ist — nur dann ist das Face-Set als geschlossen markiert.
const ROOF_PREDEFINED: Record<string, string> = {
flach: "FLAT_ROOF",
pult: "SHED_ROOF",
sattel: "GABLE_ROOF",
walm: "HIP_ROOF",
mansarde: "MANSARD_ROOF",
zelt: "HIPPED_GABLE_ROOF",
};
for (const roof of project.roofs ?? []) {
const structure = resolveStructure(roof.floorId);
const positions: number[] = [];
const indices: number[] = [];
for (const mesh of emitRoofs({ ...project, roofs: [roof] })) {
const base = positions.length / 3;
for (let i = 0; i < mesh.positions.length; i += 3) {
positions.push(mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2] - structure.baseElevation);
}
for (const ix of mesh.indices) indices.push(base + ix);
}
if (indices.length === 0) continue;
let closed = isWatertight({ positions, indices });
if (!closed) {
const flipped: number[] = [];
for (let i = 0; i < indices.length; i += 3) flipped.push(indices[i], indices[i + 2], indices[i + 1]);
if (isWatertight({ positions, indices: flipped })) {
indices.splice(0, indices.length, ...flipped);
closed = true;
}
}
const { placementId, shapeId } = emitTriangulatedProduct(positions, indices, structure.placementId, closed);
const predefined = ROOF_PREDEFINED[roof.shape] ?? "NOTDEFINED";
const roofType = roof.roofTypeId ? (project.roofTypes ?? []).find((t) => t.id === roof.roofTypeId) : undefined;
const entityId = emitBuildingElement("IFCROOF", ifcGuid(roof.id), roofType?.name ?? "Dach", placementId, shapeId, ENUM(predefined));
if (roofType) typeFor("IFCROOFTYPE", predefined, roofType).occurrences.push(entityId);
addToContainment(structure.entityId, entityId);
}
// ── Stützen → IfcColumn (Profil-Extrusion, Material = Bauteil) ──────────
const materialAssoc = new Map<number, number[]>();
for (const col of project.columns ?? []) {
const footprint = columnFootprint(col);
if (footprint.length < 3) continue;
const { zBottom, zTop } = columnVerticalExtent(project, col);
if (!(zTop > zBottom)) continue;
const structure = resolveStructure(col.floorId);
const { placementId, shapeId } = emitBoxProduct(footprint, zBottom - structure.baseElevation, zTop - zBottom, structure.placementId);
const entityId = emitBuildingElement("IFCCOLUMN", ifcGuid(col.id), columnLabel(col), placementId, shapeId, ENUM("COLUMN"));
addToContainment(structure.entityId, entityId);
if (col.componentId) {
const mat = materialOf(col.componentId);
const list = materialAssoc.get(mat);
if (list) list.push(entityId);
else materialAssoc.set(mat, [entityId]);
}
}
for (const [mat, ids] of materialAssoc) {
w.add(
"IFCRELASSOCIATESMATERIAL",
`${S(ifcGuid(`material:${mat}`))},#${ownerHistory},$,$,${LIST(ids.map((id) => `#${id}`))},#${mat}`,
);
}
// ── Typ-Zuordnung (je Bauteiltyp eine IfcRelDefinesByType) ─────────────
for (const [key, ref] of elementTypes) {
if (ref.occurrences.length === 0) continue;
+9
View File
@@ -32,4 +32,13 @@ describe.skipIf(!hasIfcOpenShell)("IFC-Export gegen ifcopenshell", () => {
expect(r.out).toContain("0 Befunde");
expect(r.status).toBe(0);
});
it("mit Stütze (Rechteck und rund)", () => {
const col = (id: string, profile: { kind: "rect"; width: number; depth: number } | { kind: "round"; radius: number }) => ({
id, type: "column" as const, floorId: "eg", categoryCode: "50", position: { x: 1, y: 1 }, profile, rotation: 0.3, height: 2.5,
});
const p = { ...sampleProject, columns: [col("S1", { kind: "rect", width: 0.3, depth: 0.2 }), col("S2", { kind: "round", radius: 0.15 })] };
const r = validate("stuetzen", exportIfcSpf(p));
expect(r.out).toContain("0 Befunde");
expect(r.status).toBe(0);
});
});
+51
View File
@@ -0,0 +1,51 @@
// Dach-Meshes (`emitRoofs`) sind je Schicht geschlossene, nach aussen gewundene Körper — Voraussetzung
// für Closed-Face-Sets im IFC und korrektes Rückseiten-Culling.
import { describe, expect, it } from "vitest";
import { emitRoofs } from "./roofs";
import { isWatertight } from "../wallMeshCut";
import { sampleProject } from "../../model/sampleProject";
import type { Project, Roof, RoofShape } from "../../model/types";
const roof = (shape: RoofShape, ridgeAxis: "x" | "y" = "x"): Roof => ({
id: "D", type: "roof", floorId: "eg", categoryCode: "35",
outline: [{ x: 0, y: 0 }, { x: 8, y: 0 }, { x: 8, y: 6 }, { x: 0, y: 6 }],
shape, pitchDeg: 35, overhang: 0.4, ridgeAxis, thickness: 0.3,
});
/** Restfläche ∮n dA (0 = dicht) und 6× Volumen (> 0 = nach aussen gewunden). */
function closure(m: { positions: number[]; indices: number[] }): { gap: number; vol6: number } {
const p = m.positions;
let ax = 0, ay = 0, az = 0, vol6 = 0;
for (let t = 0; t < m.indices.length; t += 3) {
const [i0, i1, i2] = [m.indices[t] * 3, m.indices[t + 1] * 3, m.indices[t + 2] * 3];
const e1 = [p[i1] - p[i0], p[i1 + 1] - p[i0 + 1], p[i1 + 2] - p[i0 + 2]];
const e2 = [p[i2] - p[i0], p[i2 + 1] - p[i0 + 1], p[i2 + 2] - p[i0 + 2]];
const c = [e1[1] * e2[2] - e1[2] * e2[1], e1[2] * e2[0] - e1[0] * e2[2], e1[0] * e2[1] - e1[1] * e2[0]];
ax += c[0]; ay += c[1]; az += c[2];
vol6 += p[i0] * c[0] + p[i0 + 1] * c[1] + p[i0 + 2] * c[2];
}
return { gap: Math.hypot(ax, ay, az) / 2, vol6 };
}
describe("Dach-Meshes geschlossen und nach aussen gewunden", () => {
// Wo drei oder mehr Flächen in einem Punkt zusammenkommen (Walm-/Zeltspitze), trifft die paarweise
// Gehrung der Unterseite nicht exakt: kleine Restlücke (bekannt, offen). Sattel/Pult/Flach/Mansarde
// sind dicht.
const exact: RoofShape[] = ["flach", "pult", "sattel", "mansarde"];
for (const shape of ["flach", "pult", "sattel", "walm", "mansarde", "zelt"] as RoofShape[]) {
for (const axis of ["x", "y"] as const) {
it(`${shape} (First ${axis})`, () => {
const p: Project = { ...sampleProject, roofs: [roof(shape, axis)] };
const meshes = emitRoofs(p);
expect(meshes.length).toBeGreaterThan(0);
for (const m of meshes) {
const c = closure(m);
expect(c.vol6).toBeGreaterThan(0);
if (exact.includes(shape)) expect(isWatertight(m, 1e-6)).toBe(true);
else expect(c.gap).toBeLessThan(0.01);
}
});
}
}
});
+22 -7
View File
@@ -28,11 +28,14 @@ const ROOF_RGB: RRgb = [0.72, 0.45, 0.36];
* Polygone (Dreieck/Quader bei den meisten Formen, ein Fünfeck-Giebel bei
* Mansarde) — ein Fächer trianguliert diese korrekt, ohne Ear-Clipping.
*/
function pushFanTriangles(positions: number[], indices: number[], pts: RoofVec3[]): void {
function pushFanTriangles(positions: number[], indices: number[], pts: RoofVec3[], flip = false): void {
if (pts.length < 3) return;
const base = positions.length / 3;
for (const p of pts) positions.push(p[0], p[1], p[2]);
for (let i = 1; i < pts.length - 1; i++) indices.push(base, base + i, base + i + 1);
for (let i = 1; i < pts.length - 1; i++) {
if (flip) indices.push(base, base + i + 1, base + i);
else indices.push(base, base + i, base + i + 1);
}
}
/**
@@ -162,17 +165,29 @@ function pushRoofSlabBetween(
bottom: RoofVec3[],
shared: boolean[],
): void {
pushFanTriangles(positions, indices, top);
pushFanTriangles(positions, indices, bottom);
// Wicklung nach aussen (geschlossener Körper, s. roofWinding.test.ts): Umlaufsinn der
// Oberseite von oben gesehen (Newell, Höhen-Komponente). Gegen den Uhrzeigersinn ⇒ Oberseite
// wie gegeben, Unterseite umgekehrt, Stirnfläche je Kante i→j als top[i], bottom[i], bottom[j],
// top[j] (Normale zeigt rechts der Kante = aussen); im Uhrzeigersinn alles gespiegelt.
let nz = 0;
for (let i = 0; i < top.length; i++) {
const a = top[i];
const b = top[(i + 1) % top.length];
nz += (a[0] - b[0]) * (a[1] + b[1]);
}
const ccw = nz > 0;
pushFanTriangles(positions, indices, top, !ccw);
pushFanTriangles(positions, indices, bottom, ccw);
for (let i = 0; i < top.length; i++) {
if (shared[i]) continue;
const j = (i + 1) % top.length;
const base = positions.length / 3;
positions.push(top[i][0], top[i][1], top[i][2]);
positions.push(top[j][0], top[j][1], top[j][2]);
positions.push(bottom[j][0], bottom[j][1], bottom[j][2]);
positions.push(bottom[i][0], bottom[i][1], bottom[i][2]);
indices.push(base, base + 1, base + 2, base, base + 2, base + 3);
positions.push(bottom[j][0], bottom[j][1], bottom[j][2]);
positions.push(top[j][0], top[j][1], top[j][2]);
if (ccw) indices.push(base, base + 1, base + 2, base, base + 2, base + 3);
else indices.push(base, base + 2, base + 1, base, base + 3, base + 2);
}
}