[B5] IFC-Export: Wandachse und IfcMaterialLayerSetUsage an Extrusions-Wänden

Extrusions-Wände bekommen ein Placement am Wandanfang (X = Achse, Y = linke
Normale), eine "Axis"-Darstellung (IfcPolyline) und eine IfcMaterialLayerSetUsage
(AXIS2, POSITIVE, Offset der Aussenschicht), damit Revit/ArchiCAD die Schichten
der Wandachse zuordnen. Öffnungen werden ins Wandsystem gerechnet. Test: Achse
und Schichtbereiche per ifcopenshell, auch für schräge, rückwärts gezeichnete Wände.

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-28 12:46:09 +00:00
1 parent d909acc875
commit 2fd3997def
5 files changed
+380 -20

No files matched your search

+37 -5
View File
@@ -43,8 +43,12 @@
// echte Stufengeometrie ist ausgelassen (siehe stairFootprint()).
//
// Material-Schichten: je Wand-/Deckentyp ein IfcWallType/IfcSlabType mit
// IfcMaterialLayerSet, die Exemplare erben ihn über IfcRelDefinesByType. (Noch) KEIN
// IfcMaterialLayerSetUsage am Exemplar: die Wand hat keine Achs-Darstellung.
// IfcMaterialLayerSet, die Exemplare erben ihn über IfcRelDefinesByType. Extrusions-Wände
// ([B5], 28.10.) tragen zusätzlich eine „Axis"-Darstellung (IfcPolyline entlang der Wandachse)
// und eine IfcMaterialLayerSetUsage (AXIS2, POSITIVE, Offset = Abstand der Aussenschicht von der
// Achse), damit Revit/ArchiCAD die Schichten der Achse zuordnen: das Wand-Placement sitzt am
// Wandanfang, X = Achse, Y = linke Normale (Rust rechnet die Welt-Profile ins Wandsystem). Mesh-
// Wände (schräge Oberkante, Laibungs-Rücksprung) haben weder Achse noch Usage.
//
// Eigenschaften ([B5]): Pset_WallCommon/SlabCommon/RoofCommon/ColumnCommon/DoorCommon/
// WindowCommon/SpaceCommon nur mit Werten, die das Modell hergibt (Reference = Typname,
@@ -187,10 +191,24 @@ class FlatIfc {
for (const s of m.storeys) this.nums.push(this.str(s.id), this.str(s.name), s.base);
}
wallSolids(structure: number, id: string, name: string, ty: TypeRefIn | null, psets: PsetIn[], solids: { pts: Vec2[]; zRel: number; depth: number }[]): void {
/**
* Extrusions-Wand. `frame`: Wandanfang, Achsrichtung (Einheitsvektor), Länge und — wenn die Schichten
* des Typs genau den Wandquerschnitt füllen — der Abstand `offset` der ersten Schicht von der
* Wandachse entlang der linken Normalen (→ IfcMaterialLayerSetUsage).
*/
wallSolids(
structure: number,
id: string,
name: string,
ty: TypeRefIn | null,
psets: PsetIn[],
frame: { origin: Vec2; u: Vec2; length: number; offset: number | null },
solids: { pts: Vec2[]; zRel: number; depth: number }[],
): void {
this.nums.push(REC_WALL_SOLIDS, structure, this.str(id), this.str(name));
this.typeRef(ty);
this.psets(psets);
this.nums.push(1, frame.origin.x, frame.origin.y, frame.u.x, frame.u.y, frame.length, frame.offset === null ? 0 : 1, frame.offset ?? 0);
this.nums.push(solids.length);
for (const s of solids) {
this.pts(s.pts);
@@ -583,8 +601,22 @@ export function exportIfcSpf(projectIn: Project): string {
return { pts: rect, zRel: b.baseElevation - baseOf(structure), depth: b.height };
});
const id = wallIdentity(wall);
flat.wallSolids(structure, wall.id, id.name, id.ty, id.psets, solids);
hostExtent.set(wall.id, crossExtent(wall, bands));
// Wandsystem: Placement am Wandanfang, X = Achse, Y = linke Normale; die Schichten des Typs
// stehen ab der Aussenfläche (negative Normale) nebeneinander — IfcMaterialLayerSetUsage nur,
// wenn ihre Summe dem Querschnitt der Bänder entspricht (sonst wäre der Offset gelogen).
const extent = crossExtent(wall, bands);
const layerSum = id.ty?.layers.reduce((a, l) => a + l.thickness, 0) ?? 0;
const usage = id.ty !== null && layerSum > 0 && Math.abs(extent.nHi - extent.nLo - layerSum) < 1e-3;
flat.wallSolids(
structure,
wall.id,
id.name,
id.ty,
id.psets,
{ origin: wall.start, u: normalize(sub(wall.end, wall.start)), length: Math.hypot(wall.end.x - wall.start.x, wall.end.y - wall.start.y), offset: usage ? extent.nLo : null },
solids,
);
hostExtent.set(wall.id, extent);
}
// Mesh-Weg: Loch-Ausschnitte aller betroffenen Bänder in EINEM Kern-Aufruf.
const meshBands = meshWalls.flatMap((m) => m.bands);
+104 -1
View File
@@ -39,7 +39,7 @@ for w in m.by_type("IfcWall"):
sh = ifcopenshell.geom.create_shape(s, w)
out[w.GlobalId] = {"volume": us.get_volume(sh.geometry), "openings": len(w.HasOpenings),
"fills": sum(len(r.RelatedOpeningElement.HasFillings) for r in w.HasOpenings),
"rep": w.Representation.Representations[0].RepresentationType}
"rep": [r for r in w.Representation.Representations if r.RepresentationIdentifier == "Body"][0].RepresentationType}
print(json.dumps(out))
`;
@@ -52,6 +52,48 @@ function wallVolumes(name: string, ifc: string): Record<string, WallVolume> {
return JSON.parse(r.stdout);
}
// Achse und IfcMaterialLayerSetUsage je IfcWall: Placement, Achs-Polylinie (lokal), Usage und je
// Körper (Extrusion) der Bereich quer zur Achse (lokal Y) — alles unabhängig vom Exporter gelesen.
const WALL_AXES = `
import json, sys
import ifcopenshell, ifcopenshell.util.placement as up
m = ifcopenshell.open(sys.argv[1])
out = {}
for w in m.by_type("IfcWall"):
reps = {r.RepresentationIdentifier: r for r in w.Representation.Representations}
mat = up.get_local_placement(w.ObjectPlacement)
item = {"identifiers": sorted(reps), "usage": None, "axis": None, "items": []}
if "Axis" in reps:
pts = [p.Coordinates for p in reps["Axis"].Items[0].Points]
a = mat @ [pts[0][0], pts[0][1], 0, 1]
b = mat @ [pts[1][0], pts[1][1], 0, 1]
item["axis"] = [[a[0], a[1]], [b[0], b[1]], reps["Axis"].RepresentationType, [list(p) for p in pts]]
for e in reps["Body"].Items:
if e.is_a("IfcExtrudedAreaSolid"):
ys = [p.Coordinates[1] for p in e.SweptArea.OuterCurve.Points]
item["items"].append([min(ys), max(ys)])
for rel in w.HasAssociations:
if rel.is_a("IfcRelAssociatesMaterial") and rel.RelatingMaterial.is_a("IfcMaterialLayerSetUsage"):
u = rel.RelatingMaterial
item["usage"] = {"dir": u.LayerSetDirection, "sense": u.DirectionSense, "offset": u.OffsetFromReferenceLine,
"layers": [l.LayerThickness for l in u.ForLayerSet.MaterialLayers]}
out[w.GlobalId] = item
print(json.dumps(out))
`;
interface WallAxis {
identifiers: string[];
usage: { dir: string; sense: string; offset: number; layers: number[] } | null;
axis: [number[], number[], string, number[][]] | null;
items: number[][];
}
function wallAxes(name: string, ifc: string): Record<string, WallAxis> {
const r = spawnSync("python3", ["-c", WALL_AXES, writeIfc(name, ifc)], { encoding: "utf8", timeout: 120_000 });
expect(r.status, r.stderr).toBe(0);
return JSON.parse(r.stdout);
}
/** Eine freistehende Wand 5 × 0.4 × 2.6 m mit einem Fenster 1.2 × 1.2 m (Brüstung 0.9 m). */
function singleWall(recess: boolean): Project {
return {
@@ -134,4 +176,65 @@ describe.skipIf(!hasIfcOpenShell)("IFC-Export gegen ifcopenshell", { timeout: 60
}
expect(swept).toBeGreaterThan(0);
});
it("[B5] Wandachse + LayerSetUsage: Achse = Wandachse, Schichten ab Aussenfläche in Normalenrichtung", () => {
// Zwei Schichten (0.1 aussen, 0.3 innen), Wand schräg gestellt und rückwärts gezeichnet.
const [c0, c1] = sampleProject.components;
const base = singleWall(false);
const rotated: Project = {
...base,
walls: [{ ...base.walls[0], start: { x: 12, y: 7 }, end: { x: 9, y: 3 } }],
wallTypes: [...base.wallTypes.filter((t) => t.id !== "solo"), { id: "solo", name: "Zweischicht", layers: [{ componentId: c0.id, thickness: 0.1 }, { componentId: c1.id, thickness: 0.3 }] }],
openings: [],
};
const ifc = exportIfcSpf(rotated);
expect(validate("achse", ifc).out).toContain("0 Befunde");
const [w] = Object.values(wallAxes("achse", ifc));
expect(w.identifiers).toEqual(["Axis", "Body"]);
expect(w.axis![2]).toBe("Curve2D");
expect(w.axis![0][0]).toBeCloseTo(12, 6);
expect(w.axis![0][1]).toBeCloseTo(7, 6);
expect(w.axis![1][0]).toBeCloseTo(9, 6);
expect(w.axis![1][1]).toBeCloseTo(3, 6);
expect(w.axis![3][1]).toEqual([5, 0]); // Länge √(9+16) = 5 entlang lokal X
expect(w.usage).toMatchObject({ dir: "AXIS2", sense: "POSITIVE", layers: [0.1, 0.3] });
// Referenzlinie in der Mitte (Standard) → Offset −total/2; Körper je Schicht in Reihenfolge.
const off = w.usage!.offset;
let y = off;
expect(w.items.length).toBe(2);
w.items.forEach(([lo, hi], i) => {
expect(lo).toBeCloseTo(y, 6);
y += w.usage!.layers[i];
expect(hi).toBeCloseTo(y, 6);
});
});
it("[B5] Demo-Haus: jede Extrusions-Wand hat Achse und Usage, Körper-Bänder = Schichten in Reihenfolge", () => {
const project = sampleProject;
const axes = wallAxes("demo-achsen", exportIfcSpf(project));
let withAxis = 0;
for (const wall of project.walls) {
const w = axes[ifcGuid(`${project.id}/wall/${wall.id}`)];
expect(w, wall.id).toBeDefined();
if (!w.axis) {
expect(w.usage, wall.id).toBeNull(); // Mesh-Wand
continue;
}
withAxis++;
expect(w.axis[0][0], wall.id).toBeCloseTo(wall.start.x, 6);
expect(w.axis[0][1], wall.id).toBeCloseTo(wall.start.y, 6);
expect(w.axis[1][0], wall.id).toBeCloseTo(wall.end.x, 6);
expect(w.axis[1][1], wall.id).toBeCloseTo(wall.end.y, 6);
if (!w.usage) continue; // Schichtsumme passt nicht zum Querschnitt
// Mehrere Bänder je Schicht möglich (Joins): die verschiedenen Querbereiche ergeben die Schichten.
const spans = [...new Map(w.items.map(([lo, hi]) => [`${lo.toFixed(6)}/${hi.toFixed(6)}`, [lo, hi]])).values()].sort((a, b) => a[0] - b[0]);
expect(spans.length, wall.id).toBe(w.usage.layers.length);
let y = w.usage.offset;
spans.forEach(([lo, hi], i) => {
expect(lo, `${wall.id} Schicht ${i}`).toBeCloseTo(y, 6);
y += w.usage!.layers[i];
expect(hi, `${wall.id} Schicht ${i}`).toBeCloseTo(y, 6);
});
}
expect(withAxis).toBeGreaterThan(0);
});
});