[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:
5 files changed
+190
-8
No files matched your search
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user