[K4][B5][C11] Merge: IFC- und Mesh-Export-Sammler im Kern (IFC grosses Projekt 82 s → 2.4 s), Dach-Innenhöfe bei Georeferenz
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
37 files changed
+3053
-2934
No files matched your search
@@ -8,7 +8,6 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf } from "./exportIfc";
|
||||
import { EBKPH_GROUPS, ebkphGroup, layerClassification } from "./ifcClassification";
|
||||
import { readIfcElements } from "../io/ifcElements";
|
||||
import { classificationSuffix, ifcToImportedMeshes, readIfc } from "../io/ifcImport";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
@@ -35,27 +34,7 @@ function houseWithRooms(): Project {
|
||||
};
|
||||
}
|
||||
|
||||
describe("eBKP-H-Standardzuordnung", () => {
|
||||
it("nur gesicherte Hauptgruppen, Tür und Raum bleiben unklassifiziert", () => {
|
||||
expect(Object.keys(EBKPH_GROUPS)).toEqual(["C", "E", "F"]);
|
||||
expect(ebkphGroup("wall")).toEqual({ code: "C", name: "Konstruktion Gebäude" });
|
||||
expect(ebkphGroup("slab")?.code).toBe("C");
|
||||
expect(ebkphGroup("column")?.code).toBe("C");
|
||||
expect(ebkphGroup("stair")?.code).toBe("C");
|
||||
expect(ebkphGroup("roof")).toEqual({ code: "F", name: "Bedachung Gebäude" });
|
||||
expect(ebkphGroup("window")).toEqual({ code: "E", name: "Äussere Wandbekleidung Gebäude" });
|
||||
expect(ebkphGroup("door")).toBeNull();
|
||||
expect(ebkphGroup("space")).toBeNull();
|
||||
});
|
||||
|
||||
it("Ebene: Name aus dem Ebenenbaum, unbekannter Code bleibt Code, ohne Code nichts", () => {
|
||||
expect(layerClassification(sampleProject, "20")?.code).toBe("20");
|
||||
expect(layerClassification(sampleProject, "25")?.name).toBe("Stützen"); // Unterkategorie
|
||||
expect(layerClassification(sampleProject, "777")).toEqual({ code: "777", name: "777" });
|
||||
expect(layerClassification(sampleProject, undefined)).toBeNull();
|
||||
expect(layerClassification(sampleProject, " ")).toBeNull();
|
||||
});
|
||||
});
|
||||
// Zuordnungstabelle eBKP-H und Ebenen-Auflösung: Rust-Tests in `src-tauri/core/src/ifc_data.rs`.
|
||||
|
||||
describe("IFC-Export: Zonen und Geschoss-Kennwerte (SIA 416)", () => {
|
||||
it("je Kategorie eine IfcZone mit ihren Räumen, Kategorie und Fläche als Eigenschaft", () => {
|
||||
|
||||
@@ -701,3 +701,17 @@ describe("[B5] Pset_*Common mit den Werten aus dem Modell", () => {
|
||||
expect(kueche).toContain(".INTERNAL.");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Sammler im Kern ([K4], 29.10.)", () => {
|
||||
it("Fehler des Kerns kommen mit dessen Meldung (unbekannter Wandtyp)", () => {
|
||||
const p = fixtureProject();
|
||||
const broken: Project = { ...p, walls: p.walls.map((w, i) => (i === 0 ? { ...w, wallTypeId: "fehlt" } : w)) };
|
||||
expect(() => exportIfcSpf(broken)).toThrow("Unbekannter Wandtyp: fehlt");
|
||||
});
|
||||
|
||||
it("zweimal exportieren gibt dieselbe Datei (bis auf den Zeitstempel)", () => {
|
||||
const strip = (s: string) => s.replace(/\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d/g, "T").replace(/IFCOWNERHISTORY\([^;]*;/g, "");
|
||||
const p = fixtureProject();
|
||||
expect(strip(exportIfcSpf(p, { ebkph: true, layerCodes: true }))).toBe(strip(exportIfcSpf(p, { ebkph: true, layerCodes: true })));
|
||||
});
|
||||
});
|
||||
+53
-1060
File diff suppressed because it is too large.
Load diff
@@ -9,8 +9,7 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf, ifcGuid } from "./exportIfc";
|
||||
import { pickGeometry } from "../plan/toWalls3d";
|
||||
import { wallCutMeshes } from "../plan/wallMeshCut";
|
||||
import { wallMeshVolumes } from "./meshScene.testutil";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Project } from "../model/types";
|
||||
|
||||
@@ -202,17 +201,8 @@ describe.skipIf(!hasIfcOpenShell)("IFC-Export gegen ifcopenshell", { timeout: 60
|
||||
});
|
||||
it("[B5] Demo-Haus: jede Wand hat nach ifcopenshell (Öffnungen abgezogen) das Volumen des 3D-Meshes", () => {
|
||||
const project = sampleProject;
|
||||
const bands = pickGeometry(project).walls;
|
||||
const meshVolume = new Map<string, number>();
|
||||
wallCutMeshes(bands).forEach((m, i) => {
|
||||
let v6 = 0;
|
||||
for (let k = 0; k < m.indices.length; k += 3) {
|
||||
const [a, b, c] = [m.indices[k], m.indices[k + 1], m.indices[k + 2]].map((j) => m.positions.slice(j * 3, j * 3 + 3));
|
||||
v6 += a[0] * (b[1] * c[2] - b[2] * c[1]) + a[1] * (b[2] * c[0] - b[0] * c[2]) + a[2] * (b[0] * c[1] - b[1] * c[0]);
|
||||
}
|
||||
const id = bands[i].wallId;
|
||||
meshVolume.set(id, (meshVolume.get(id) ?? 0) + Math.abs(v6) / 6);
|
||||
});
|
||||
// Vergleichswert: dieselben öffnungsgenauen Wand-Netze wie im 3D/OBJ (Kern, `mesh_data.rs`).
|
||||
const meshVolume = wallMeshVolumes(project);
|
||||
const walls = wallVolumes("demo-volumen", exportIfcSpf(project));
|
||||
let swept = 0;
|
||||
for (const wall of project.walls) {
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
// Mesh-Export vollständig ([C11], 28.10.): Dächer, Treppen, Stützen, Kontext-Meshes, ein Knoten je Öffnung,
|
||||
// rechtshändige Achsen in OBJ/STL/glTF, Dreieckszahl wie die 3D-Ableitung, Khronos-Validator.
|
||||
// rechtshändige Achsen in OBJ/STL/glTF, Dreieckszahl wie die 3D-Ableitung, Khronos-Validator. Die Wicklung
|
||||
// (`orient_outward`) prüfen die Rust-Tests in `export_flat.rs`, hier das Volumen je Bauteil in der Datei.
|
||||
import { describe, it, expect } from "vitest";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import validator from "gltf-validator";
|
||||
import { exportGlb, exportGltf, exportObj, exportStl } from "./exportMesh";
|
||||
import { orientOutward } from "./meshOrient";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Column, ImportedMesh, Project, TerrainMesh } from "../model/types";
|
||||
import { emitColumns, emitOpeningMeshes, emitRoofs, emitStairMeshes, emitStairRailings, emitStairs } from "./model3dParts";
|
||||
import { ProjectDocument, type QueryName } from "../core/document";
|
||||
|
||||
/** 3D-Ableitung des Kerns (`queries.rs`) auf einem eigenen Dokument — Vergleichswert für die Dreieckszahl. */
|
||||
function derive<T>(project: Project, name: QueryName, args: number[] = []): T {
|
||||
const doc = new ProjectDocument(project);
|
||||
try {
|
||||
return doc.query<T>(name, args);
|
||||
} finally {
|
||||
doc.close();
|
||||
}
|
||||
}
|
||||
|
||||
interface Gltf {
|
||||
nodes: { name: string; mesh?: number; children?: number[]; extras?: { type: string; id: string } }[];
|
||||
@@ -85,31 +95,6 @@ function objVolumes(obj: string): Map<string, number> {
|
||||
return out;
|
||||
}
|
||||
|
||||
describe("orientOutward", () => {
|
||||
it("dreht einen innen gewickelten Würfel nach aussen und gleicht gemischte Wicklung an", () => {
|
||||
const pos = CUBE_POS;
|
||||
const mixed = CUBE_IDX.slice();
|
||||
// ein Dreieck umdrehen ⇒ widersprüchliche Wicklung
|
||||
[mixed[1], mixed[2]] = [mixed[2], mixed[1]];
|
||||
const inward: number[] = [];
|
||||
for (let i = 0; i < CUBE_IDX.length; i += 3) inward.push(CUBE_IDX[i], CUBE_IDX[i + 2], CUBE_IDX[i + 1]);
|
||||
const vol = (idx: number[]) => {
|
||||
let v = 0;
|
||||
for (let i = 0; i < idx.length; i += 3) {
|
||||
const [a, b, c] = [idx[i] * 3, idx[i + 1] * 3, idx[i + 2] * 3];
|
||||
v +=
|
||||
pos[a] * (pos[b + 1] * pos[c + 2] - pos[b + 2] * pos[c + 1]) -
|
||||
pos[a + 1] * (pos[b] * pos[c + 2] - pos[b + 2] * pos[c]) +
|
||||
pos[a + 2] * (pos[b] * pos[c + 1] - pos[b + 1] * pos[c]);
|
||||
}
|
||||
return v / 6;
|
||||
};
|
||||
expect(vol(CUBE_IDX)).toBeCloseTo(8, 9);
|
||||
expect(vol(orientOutward(pos, inward))).toBeCloseTo(8, 9);
|
||||
expect(vol(orientOutward(pos, mixed))).toBeCloseTo(8, 9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Mesh-Export vollständig", () => {
|
||||
const project = withContext(sampleProject);
|
||||
|
||||
@@ -182,14 +167,15 @@ describe("Mesh-Export vollständig", () => {
|
||||
it("Dreieckszahl je Bauteilart = Summe der 3D-Ableitungen (Dach, Treppe, Stütze, Öffnungsteile)", () => {
|
||||
const g = glbJson(exportGlb(project));
|
||||
const tris = (type: string) => g.nodes.filter((n) => n.extras?.type === type).reduce((s, n) => s + nodeTris(g, n), 0);
|
||||
const meshTris = (ms: { indices: number[] }[]) => ms.reduce((s, m) => s + m.indices.length / 3, 0);
|
||||
expect(tris("roof")).toBe(meshTris(emitRoofs(project)));
|
||||
expect(tris("column")).toBe(meshTris(emitColumns(project)));
|
||||
expect(tris("window") + tris("door")).toBe(meshTris(emitOpeningMeshes(project, "mittel")));
|
||||
const stairMeshes = meshTris(emitStairMeshes(project)) + meshTris(emitStairRailings(project));
|
||||
const meshTris = (name: QueryName, args: number[] = []) => derive<{ indices: number[] }[]>(project, name, args).reduce((s, m) => s + m.indices.length / 3, 0);
|
||||
expect(tris("roof")).toBe(meshTris("roofMeshes"));
|
||||
expect(tris("column")).toBe(meshTris("columnMeshes"));
|
||||
expect(tris("window") + tris("door")).toBe(meshTris("openingMeshes", [1]));
|
||||
const stairMeshes = meshTris("stairMeshes") + meshTris("stairRailings");
|
||||
// Stufen-Prismen: jede Stufe wird zu einem Prisma (2 Kappen + Mantel) — mindestens die Mesh-Dreiecke.
|
||||
expect(emitStairs(project).length).toBeGreaterThan(0);
|
||||
expect(tris("stair")).toBeGreaterThanOrEqual(stairMeshes + emitStairs(project).length * 12);
|
||||
const steps = derive<unknown[]>(project, "stairSlabs", [0]).length;
|
||||
expect(steps).toBeGreaterThan(0);
|
||||
expect(tris("stair")).toBeGreaterThanOrEqual(stairMeshes + steps * 12);
|
||||
// OBJ und glTF enthalten dieselben Dreiecke
|
||||
const faces = exportObj(project).split("\n").filter((l) => l.startsWith("f ")).length;
|
||||
const all = g.nodes.reduce((s, n) => s + nodeTris(g, n), 0);
|
||||
@@ -209,4 +195,12 @@ describe("Mesh-Export vollständig", () => {
|
||||
const r2 = await validator.validateString(exportGltf(project), { maxIssues: 50 });
|
||||
expect(r2.issues.numErrors).toBe(0);
|
||||
});
|
||||
|
||||
it("leeres Projekt: gültige Szene ohne Knoten (kein leeres `nodes`, Validator EMPTY_ENTITY)", async () => {
|
||||
const empty: Project = { ...sampleProject, walls: [], openings: [], ceilings: [], roofs: [], stairs: [], rooms: [], columns: [], context: [] };
|
||||
const r1 = await validator.validateBytes(exportGlb(empty), { maxIssues: 50 });
|
||||
expect(r1.issues.messages.filter((m) => m.severity === 0)).toEqual([]);
|
||||
const r2 = await validator.validateString(exportGltf(empty), { maxIssues: 50 });
|
||||
expect(r2.issues.numErrors).toBe(0);
|
||||
});
|
||||
});
|
||||
+16
-477
@@ -1,317 +1,17 @@
|
||||
// OBJ-/STL-/glTF-Export des 3D-Gebäudemodells als Dreiecks-Mesh. Seit [C4] (28.10.) schreibt Rust die
|
||||
// Datei (`src-tauri/fileio/src/mesh_export.rs`, Format-Modul pkgFileIo, vorher `await loadFileio()`):
|
||||
// buildScene() liest das Projekt und sammelt Dreiecke, Materialien und Geschosse flach, exportObj()/
|
||||
// exportStl()/exportGlb()/exportGltf() rufen den Schreiber synchron auf. Kein Datei-IO hier.
|
||||
// OBJ-/STL-/glTF-Export des 3D-Gebäudemodells als Dreiecks-Mesh. Seit [K4]/[C11] (29.10.) rechnet alles
|
||||
// in Rust: der Kern sammelt aus dem Projekt-Dokument die Szene (`src-tauri/core/src/mesh_data.rs`,
|
||||
// Abfrage `meshExportData`: ein Knoten je Bauteil, Teil-Netze je Material, Materialtabelle,
|
||||
// Geschosse; Wicklung nach aussen), das Format-Modul schreibt daraus die Datei
|
||||
// (`src-tauri/fileio/src/mesh_export.rs`). TS gibt nur die Optionen weiter und reicht die Bytes vom
|
||||
// Kern an `fileio`. Verlangt das geladene Format-Modul (`await loadFileio()`). Kein Datei-IO hier.
|
||||
//
|
||||
// TRIANGEL-QUELLE (bewusste v1-Entscheidung, siehe PENDENZEN):
|
||||
// • Wände: pickGeometry() aus toWalls3d.ts liefert dieselben Schicht-Bänder,
|
||||
// die auch der 3D-Viewer zeichnet (EIN RWall je Materiallage/Achsen-
|
||||
// Teilstück, bereits mit End-Cuts/Gehrungen/Decken-Dominanz aufgelöst).
|
||||
// Bänder mit Öffnungs-`holes` werden über den gemeinsamen Loch-Ausschnitt-
|
||||
// Generator (`plan/wallMeshCut.ts` → Rust-Kern, Gitter-Zerlegung wie render3ds
|
||||
// `extrude_layer_segment_with_holes`) ÖFFNUNGSGENAU trianguliert — die
|
||||
// Fenster/Türen sind sichtbar ausgestanzt inkl. Laibungsflächen, genau wie
|
||||
// im 3D-Viewer. Lochlose Bänder bleiben die klassische geteilte 8-Ecken-Box.
|
||||
// • Decken: pickGeometry() liefert den Umriss + zBottom/zTop je Decke;
|
||||
// der Umriss wird mit dem vorhandenen Ear-Clipping-Triangulator
|
||||
// (`triangulate` aus plan/glPlan/glPlanCompile.ts, bereits getestet und
|
||||
// konkav-fähig) zu Boden-/Deckenkappen trianguliert, dazwischen ein
|
||||
// Seitenmantel — ein einfaches Umriss-Prisma.
|
||||
// • ExtrudedSolids (truck-Profile): `src/engine/truckSolid.ts` liefert zwar
|
||||
// "echte" truck-Dreiecke, ABER nur asynchron über WASM
|
||||
// (`extrudePolygon`/`extrudeCircle` geben Promises zurück). Das würde die
|
||||
// geforderte SYNCHRONE, WASM-freie Signatur `exportObj(project): string`
|
||||
// brechen. Deshalb nutzt dieser Export stattdessen DIESELBE Prisma-
|
||||
// Triangulierung wie die Decken (Umriss aus `solid.points` — bei
|
||||
// Kreisprofilen bereits eine 48-Eck-Tessellierung, siehe
|
||||
// `ExtrudedSolid.points`-Doc) inkl. `taper`-Verjüngung (linear zum
|
||||
// Schwerpunkt skaliert, wie die truck-Extrusion es tut). Das ist eine
|
||||
// bewusste Abweichung vom ursprünglichen Plan ("truckSolid-Dreiecke") zu-
|
||||
// gunsten der pure-Modul-Architektur — ehrlich dokumentiert, kein
|
||||
// Stillschweigen.
|
||||
//
|
||||
// ACHSEN-KONVENTION (intern, Weg zum Schreiber): Modell (x, y, z-hoch) → Welt (x, z, y) wie die
|
||||
// Pick-/Highlight-Geometrie in toWalls3d.ts (`selectionHighlightLines`). Das ist eine Spiegelung
|
||||
// des Modells; der Rust-Schreiber stellt für ALLE Formate (OBJ, STL, glTF) die Rechtshändigkeit
|
||||
// her: Gesamtabbildung Modell (x, y, z-hoch) → Datei (x, z, −y), Norden = −Z.
|
||||
//
|
||||
// WEITERE BAUTEILE ([C11], 28.10.): Dächer, Treppen (Tritte, Laufplatte, Handlauf), Stützen,
|
||||
// Öffnungsteile (je Öffnung ein Knoten), Gelände und importierte Kontext-Meshes. Quelle sind
|
||||
// dieselben `emit*`-Ableitungen wie im 3D-Viewer (`projectToModel3d`). Diese liefern keine
|
||||
// Bauteil-ids; deshalb wird jede Ableitung je Bauteil mit einem Projekt aufgerufen, das nur dieses
|
||||
// Bauteil enthält (reines Lesen, `src/plan` bleibt unverändert). Die Ableitungen schreiben keine
|
||||
// verlässliche Wicklung (render3d zeichnet doppelseitig): {@link orientOutward} richtet jedes
|
||||
// geschlossene Teil nach aussen aus.
|
||||
// Achsen: Datei rechtshändig, Y-up — Modell (x, y, z-hoch) → (x, z, −y), Norden = −Z, Meter.
|
||||
// Dreiecks-Quelle, Prisma-Näherung der Extrusionen und Grenzen: Kopf von `mesh_data.rs`, `TODO.md` [C11].
|
||||
|
||||
import type { Project, Vec2 } from "../model/types";
|
||||
import { getFloor } from "../model/types";
|
||||
import { pickGeometry } from "../plan/toWalls3d";
|
||||
import type { RWall } from "../plan/toWalls3d";
|
||||
import { wallCutMeshes, type CutMesh } from "../plan/wallMeshCut";
|
||||
import { triangulate } from "../plan/glPlan/glPlanCompile";
|
||||
import type { RMesh } from "../plan/toWalls3d/shared";
|
||||
import { IMPORTED_RGB, TERRAIN_RGB, hexToRgb } from "../plan/toWalls3d/shared";
|
||||
import type { Project } from "../model/types";
|
||||
import { fileio } from "../engine/fileioWasm";
|
||||
import { orientOutward } from "./meshOrient";
|
||||
import { emitColumns, emitOpeningMeshes, emitRoofs, emitStairMeshes, emitStairRailings, emitStairs } from "./model3dParts";
|
||||
|
||||
/**
|
||||
* Ein Teil-Mesh mit EINEM Material und LOKALEN (0-basierten) Vertex-/Dreiecks-Indizes. Der Rust-Schreiber
|
||||
* (`mesh_export.rs`) verschiebt die Indizes beim Serialisieren auf die globale OBJ-Nummerierung.
|
||||
*/
|
||||
interface MeshPrim {
|
||||
/** Index in die Materialtabelle (`SceneBuilder.materials`), −1 = keins. */
|
||||
material: number;
|
||||
/** Flaches Weltkoordinaten-Array (x,y,z, x,y,z, …), Meter, Y-up. */
|
||||
positions: number[];
|
||||
/** Dreiecks-Indizes (3 je Dreieck), 0-basiert relativ zu `positions`. */
|
||||
indices: number[];
|
||||
}
|
||||
|
||||
/** Eine Mesh-Gruppe = ein Bauteil-Vorkommen (Wand, Decke, Dach, Treppe, Öffnung …) mit ≥ 1 Teil-Mesh. */
|
||||
interface MeshGroup {
|
||||
name: string;
|
||||
/** Bauteilart für glTF-`extras` ("wall", "slab", "extrusion", "roof", "stair", "column", "window", "door", "terrain", "context"). */
|
||||
kind: string;
|
||||
/** Bauteil-id im Modell ("" bei Sammelgruppen). */
|
||||
id: string;
|
||||
/** Index in `levels` oder −1. */
|
||||
level: number;
|
||||
prims: MeshPrim[];
|
||||
}
|
||||
|
||||
function newGroup(name: string, kind: string, id: string, level: number): MeshGroup {
|
||||
return { name, kind, id, level, prims: [] };
|
||||
}
|
||||
|
||||
function newPrim(group: MeshGroup, material: number): MeshPrim {
|
||||
const prim: MeshPrim = { material, positions: [], indices: [] };
|
||||
group.prims.push(prim);
|
||||
return prim;
|
||||
}
|
||||
|
||||
/** OBJ-Gruppennamen dürfen keine Whitespaces/Sonderzeichen enthalten. */
|
||||
function sanitizeName(id: string): string {
|
||||
return id.replace(/[^A-Za-z0-9_-]/g, "_") || "x";
|
||||
}
|
||||
|
||||
/**
|
||||
* Die 6 Quader-Seiten als Eckpunkt-Quadrupel (Index-Bits: bit0=Achse −/+,
|
||||
* bit1=Höhe −/+, bit2=Dicke −/+ — dieselbe Konvention wie `emitOpeningMeshes`/
|
||||
* `selectionHighlightLines` in toWalls3d.ts), in nach AUSSEN gewundener
|
||||
* Reihenfolge (für ein rechtshändiges Dreibein Achse×Höhe=Dicke-Normale, wie
|
||||
* es die Wandbox-Konstruktion unten aufspannt). Jedes Quadrupel wird zu 2
|
||||
* Dreiecken (0,1,2)+(0,2,3).
|
||||
*/
|
||||
const BOX_QUADS: Array<[number, number, number, number]> = [
|
||||
[4, 6, 7, 5], // Dicke +
|
||||
[1, 3, 2, 0], // Dicke −
|
||||
[2, 3, 7, 6], // Höhe + (Wandkopf)
|
||||
[4, 5, 1, 0], // Höhe − (Wand-UK)
|
||||
[1, 5, 7, 3], // Achse + (Wandende)
|
||||
[2, 6, 4, 0], // Achse − (Wandanfang)
|
||||
];
|
||||
|
||||
/**
|
||||
* Hängt EIN Wand-Schicht-Band (`RWall`, siehe toWalls3d.ts) an eine Mesh-Gruppe
|
||||
* an: hat das Band echte Öffnungs-`holes`, wird das öffnungsgenaue Loch-Ausschnitt-
|
||||
* Mesh `cut` (vorab für alle Bänder über {@link wallCutMeshes}) verwendet — die
|
||||
* Fenster/Türen sind sichtbar ausgestanzt inkl. Laibungen, exakt wie im 3D-Viewer.
|
||||
* Ohne Löcher bleibt es die klassische, geteilte 8-Ecken-Box ({@link pushWallBox})
|
||||
* (Joins/Gehrungen stecken schon in `start`/`end`).
|
||||
*/
|
||||
function pushWall(group: MeshPrim, w: RWall, cut: CutMesh | undefined): void {
|
||||
if (cut) {
|
||||
const base = group.positions.length / 3;
|
||||
for (const p of cut.positions) group.positions.push(p);
|
||||
for (const idx of cut.indices) group.indices.push(base + idx);
|
||||
return;
|
||||
}
|
||||
pushWallBox(group, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hängt EINEN vollen Wand-Schicht-Quader (`RWall`) an eine Mesh-Gruppe an — Box
|
||||
* über Achse×Höhe×Dicke, OHNE Öffnungs-Ausschnitt (nur für lochlose Bänder, siehe
|
||||
* {@link pushWall}). Degenerierte Bänder (Länge/Höhe/Dicke ≤ 0) werden übersprungen.
|
||||
*/
|
||||
function pushWallBox(group: MeshPrim, w: RWall): void {
|
||||
const [sx, sy] = w.start;
|
||||
const [ex, ey] = w.end;
|
||||
const dx = ex - sx;
|
||||
const dz = ey - sy;
|
||||
const len = Math.hypot(dx, dz);
|
||||
if (len < 1e-9 || w.height <= 1e-9 || w.thickness <= 1e-9) return;
|
||||
const ax = dx / len;
|
||||
const az = dz / len;
|
||||
// Normale = Welt-Hoch × Achse (rechtshändig), dieselbe Konvention wie
|
||||
// `selectionHighlightLines`: normal = (az, 0, −ax).
|
||||
const nx = az;
|
||||
const nz = -ax;
|
||||
const halfLen = len / 2;
|
||||
const halfHeight = w.height / 2;
|
||||
const halfThick = w.thickness / 2;
|
||||
const cx = (sx + ex) / 2;
|
||||
const cz = (sy + ey) / 2;
|
||||
const cy = w.baseElevation + w.height / 2;
|
||||
const base = group.positions.length / 3;
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const sL = i & 1 ? 1 : -1;
|
||||
const sH = i & 2 ? 1 : -1;
|
||||
const sT = i & 4 ? 1 : -1;
|
||||
group.positions.push(
|
||||
cx + sL * halfLen * ax + sT * halfThick * nx,
|
||||
cy + sH * halfHeight,
|
||||
cz + sL * halfLen * az + sT * halfThick * nz,
|
||||
);
|
||||
}
|
||||
for (const [a, b, c, d] of BOX_QUADS) {
|
||||
group.indices.push(base + a, base + b, base + c, base + a, base + c, base + d);
|
||||
}
|
||||
}
|
||||
|
||||
/** Signierte Fläche eines Modell-XY-Umrisses (Shoelace); ≥0 = CCW. */
|
||||
function signedAreaXY(pts: Vec2[]): number {
|
||||
let a = 0;
|
||||
for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {
|
||||
a += pts[j].x * pts[i].y - pts[i].x * pts[j].y;
|
||||
}
|
||||
return a / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hängt ein extrudiertes Umriss-Prisma (Decke ODER truck-Profil-Extrusion,
|
||||
* siehe Moduldoc) an eine Mesh-Gruppe an: Boden-/Deckkappe (Ear-Clipping-
|
||||
* Triangulierung via `triangulate`) + Seitenmantel. `taper` (0..1) verjüngt
|
||||
* den OBEREN Ring linear zum Flächenschwerpunkt — dieselbe Semantik wie
|
||||
* `ExtrudedSolid.taper`/die truck-Extrusion (0 = Prisma, 1 = Spitze/Pyramide).
|
||||
* Der Umriss wird intern auf CCW (Modell-XY) normalisiert, damit die
|
||||
* Seitenmantel-Normalen unabhängig von der Eingabe-Wicklung nach außen zeigen.
|
||||
*/
|
||||
function pushPrism(
|
||||
group: MeshPrim,
|
||||
outline: Vec2[],
|
||||
zBottom: number,
|
||||
zTop: number,
|
||||
taper = 0,
|
||||
): void {
|
||||
if (outline.length < 3 || zTop - zBottom <= 1e-9) return;
|
||||
const ccw = signedAreaXY(outline) >= 0 ? outline : [...outline].reverse();
|
||||
const n = ccw.length;
|
||||
let cx = 0;
|
||||
let cyModel = 0;
|
||||
for (const p of ccw) {
|
||||
cx += p.x;
|
||||
cyModel += p.y;
|
||||
}
|
||||
cx /= n;
|
||||
cyModel /= n;
|
||||
const t = Math.min(1, Math.max(0, taper));
|
||||
const base = group.positions.length / 3;
|
||||
// Unterer Ring (base + 0..n-1), oberer Ring (base + n..2n-1).
|
||||
for (const p of ccw) group.positions.push(p.x, zBottom, p.y);
|
||||
for (const p of ccw) {
|
||||
const tx = cx + (p.x - cx) * (1 - t);
|
||||
const ty = cyModel + (p.y - cyModel) * (1 - t);
|
||||
group.positions.push(tx, zTop, ty);
|
||||
}
|
||||
// Kappen: `triangulate` liefert bei CCW-Eingabe stets CCW-in-Modell-XY-
|
||||
// Dreiecke — eingebettet in die Weltebene (x, const, y) entspricht das einer
|
||||
// nach UNTEN (−Y) zeigenden Flächennormale (Kreuzprodukt-Herleitung siehe
|
||||
// Moduldoc-Kommentar oben). Die Bodenkappe nutzt diese Wicklung direkt
|
||||
// (Normale zeigt nach unten = nach außen), die Deckkappe braucht die
|
||||
// umgekehrte Wicklung (Normale nach oben).
|
||||
const capTris = triangulate(ccw);
|
||||
for (let i = 0; i < capTris.length; i += 3) {
|
||||
const a = capTris[i];
|
||||
const b = capTris[i + 1];
|
||||
const c = capTris[i + 2];
|
||||
group.indices.push(base + a, base + b, base + c);
|
||||
group.indices.push(base + n + a, base + n + c, base + n + b);
|
||||
}
|
||||
// Seitenmantel: je Umrisskante ein Quad (2 Dreiecke), Wicklung so, dass die
|
||||
// Normale nach außen zeigt (siehe Moduldoc-Herleitung).
|
||||
for (let i = 0; i < n; i++) {
|
||||
const j = (i + 1) % n;
|
||||
const bi = base + i;
|
||||
const bj = base + j;
|
||||
const ti = base + n + i;
|
||||
const tj = base + n + j;
|
||||
group.indices.push(bi, ti, tj);
|
||||
group.indices.push(bi, tj, bj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hängt ein Modell-Mesh (x, y, z-hoch) an ein Teil-Mesh: Achsen nach Welt (x, z, y) und Wicklung
|
||||
* nach aussen. `closed`: geschlossener Körper ⇒ {@link orientOutward}; sonst (Gelände, offene
|
||||
* Importe) bleibt die Wicklung des Modells erhalten — die Achsenspiegelung kehrt sie um.
|
||||
*/
|
||||
function appendModelMesh(prim: MeshPrim, positions: readonly number[], indices: readonly number[], closed: boolean): void {
|
||||
const pos: number[] = [];
|
||||
for (let i = 0; i + 2 < positions.length; i += 3) pos.push(positions[i], positions[i + 2], positions[i + 1]);
|
||||
const nv = pos.length / 3;
|
||||
const tri: number[] = [];
|
||||
for (let i = 0; i + 2 < indices.length; i += 3) {
|
||||
const a = indices[i];
|
||||
const b = indices[i + 1];
|
||||
const c = indices[i + 2];
|
||||
// Indizes ausserhalb (kaputter Import) und entartete Dreiecke weglassen.
|
||||
if (!(a >= 0 && a < nv && b >= 0 && b < nv && c >= 0 && c < nv)) continue;
|
||||
tri.push(a, c, b);
|
||||
}
|
||||
const idx = closed ? orientOutward(pos, tri) : tri;
|
||||
const base = prim.positions.length / 3;
|
||||
for (const v of pos) prim.positions.push(v);
|
||||
for (const i of idx) prim.indices.push(base + i);
|
||||
}
|
||||
|
||||
type Rgb = [number, number, number];
|
||||
|
||||
/** Material der Szene: Farbe sRGB 0..1, `rgba[3]` < 1 = transparent (Glas). */
|
||||
interface SceneMaterial {
|
||||
name: string;
|
||||
rgba: [number, number, number, number];
|
||||
metallic: number;
|
||||
roughness: number;
|
||||
}
|
||||
|
||||
/** Materialtabelle: gleiche Farbe + Name = ein Material. */
|
||||
class Materials {
|
||||
readonly list: SceneMaterial[] = [];
|
||||
private readonly byKey = new Map<string, number>();
|
||||
|
||||
get(name: string, rgb: Rgb, alpha = 1, metallic = 0, roughness = 0.9): number {
|
||||
const key = `${name}|${rgb.join(",")}|${alpha}|${metallic}|${roughness}`;
|
||||
let i = this.byKey.get(key);
|
||||
if (i === undefined) {
|
||||
i = this.list.length;
|
||||
this.list.push({ name, rgba: [rgb[0], rgb[1], rgb[2], alpha], metallic, roughness });
|
||||
this.byKey.set(key, i);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
/** Die für den Rust-Schreiber gesammelte Szene. */
|
||||
interface MeshScene {
|
||||
groups: MeshGroup[];
|
||||
materials: SceneMaterial[];
|
||||
levels: { id: string; name: string }[];
|
||||
}
|
||||
|
||||
/** Standardfarbe der Extrusionen/Decken (wie `SLAB_RGB` in toWalls3d/shared.ts). */
|
||||
const SLAB_COLOR: Rgb = [0.86, 0.86, 0.88];
|
||||
/** Verglasung und Rahmenteile aus `emitOpeningMeshes` (Farben `PART_RGB` in toWalls3d/openings.ts). */
|
||||
const GLASS_COLOR: Rgb = [0.62, 0.76, 0.85];
|
||||
const OPENING_PART_NAMES: Array<[Rgb, string]> = [
|
||||
[[0.85, 0.85, 0.83], "Blendrahmen"],
|
||||
[[0.88, 0.88, 0.9], "Fluegelrahmen"],
|
||||
[[0.8, 0.8, 0.78], "Fensterbank/Zarge"],
|
||||
[[0.25, 0.27, 0.3], "Schwelle"],
|
||||
[[0.93, 0.9, 0.85], "Tuerblatt"],
|
||||
];
|
||||
const sameRgb = (a: readonly number[], b: readonly number[]) => a.length === 3 && b.length === 3 && a.every((v, i) => Math.abs(v - b[i]) < 1e-9);
|
||||
import { documentFor } from "../core/document";
|
||||
import { decodeExportFlat } from "./exportIfc";
|
||||
|
||||
/** Was in die Szene kommt. Alles standardmässig an (vollständiges 3D-Modell). */
|
||||
export interface MeshOptions {
|
||||
@@ -321,172 +21,11 @@ export interface MeshOptions {
|
||||
context?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut alle Mesh-Gruppen (Wände, Decken, Extrusionen, Dächer, Treppen, Stützen, Öffnungsteile,
|
||||
* Kontext-Meshes) und die Materialtabelle.
|
||||
*/
|
||||
function buildScene(project: Project, opts: MeshOptions = {}): MeshScene {
|
||||
const groups: MeshGroup[] = [];
|
||||
const mats = new Materials();
|
||||
const { walls, slabs } = pickGeometry(project);
|
||||
const levels = project.drawingLevels.filter((l) => l.kind === "floor").map((l) => ({ id: l.id, name: l.name }));
|
||||
const levelOf = (floorId: string | undefined): number => levels.findIndex((l) => l.id === floorId);
|
||||
const componentName = (id: string | undefined, fallback: string): string =>
|
||||
(id !== undefined && project.components.find((c) => c.id === id)?.name) || fallback;
|
||||
|
||||
// Wände: alle Schicht-Bänder DERSELBEN Wand-Id in EINE Gruppe (mehrere
|
||||
// Materiallagen ergeben mehrere Boxen im selben Bauteil-Vorkommen).
|
||||
const wallGroups = new Map<string, MeshGroup>();
|
||||
const wallFloor = new Map(project.walls.map((w) => [w.id, w.floorId]));
|
||||
// Loch-Ausschnitte aller gelochten Bänder in EINEM Kern-Aufruf.
|
||||
const holed = walls.filter((w) => w.holes && w.holes.length > 0);
|
||||
const cuts = new Map<RWall, CutMesh>();
|
||||
wallCutMeshes(holed).forEach((m, i) => cuts.set(holed[i], m));
|
||||
for (const w of walls) {
|
||||
let g = wallGroups.get(w.wallId);
|
||||
if (!g) {
|
||||
g = newGroup(`Wand_${sanitizeName(w.wallId)}`, "wall", w.wallId, levelOf(wallFloor.get(w.wallId)));
|
||||
wallGroups.set(w.wallId, g);
|
||||
groups.push(g);
|
||||
}
|
||||
const mat = mats.get(componentName(w.cut?.componentId, "Wand"), w.color);
|
||||
pushWall(newPrim(g, mat), w, cuts.get(w));
|
||||
}
|
||||
|
||||
// Decken: ein Prisma je Decke.
|
||||
const ceilingFloor = new Map((project.ceilings ?? []).map((c) => [c.id, c.floorId]));
|
||||
for (const s of slabs) {
|
||||
const g = newGroup(`Decke_${sanitizeName(s.ceilingId)}`, "slab", s.ceilingId, levelOf(ceilingFloor.get(s.ceilingId)));
|
||||
const outline: Vec2[] = s.outline.map(([x, y]) => ({ x, y }));
|
||||
pushPrism(newPrim(g, mats.get(componentName(s.cut?.componentId, "Decke"), s.color)), outline, s.zBottom, s.zTop);
|
||||
groups.push(g);
|
||||
}
|
||||
|
||||
// Extrudierte Profile (truck-Integration): eigenes Prisma je Körper (siehe
|
||||
// Moduldoc — bewusst NICHT die truck-WASM-Dreiecke, aus Sync-/Pure-Gründen).
|
||||
for (const solid of project.extrudedSolids ?? []) {
|
||||
if (solid.points.length < 3 || solid.height <= 0) continue;
|
||||
let baseZ = 0;
|
||||
try {
|
||||
baseZ = getFloor(project, solid.levelId).baseElevation ?? 0;
|
||||
} catch {
|
||||
// Geschoss nicht (mehr) auflösbar: bei UK 0 extrudieren (Fallback, wie toWalls3d).
|
||||
}
|
||||
const g = newGroup(`Extrusion_${sanitizeName(solid.id)}`, "extrusion", solid.id, levelOf(solid.levelId));
|
||||
pushPrism(newPrim(g, mats.get("Extrusion", SLAB_COLOR)), solid.points, baseZ, baseZ + solid.height, solid.taper ?? 0);
|
||||
groups.push(g);
|
||||
}
|
||||
|
||||
// Dächer, Stützen, Treppen: je Bauteil EIN Aufruf der 3D-Ableitung mit einem Projekt, das nur dieses
|
||||
// Bauteil enthält — so tragen die Meshes die Bauteil-id (die Ableitungen liefern keine).
|
||||
const addMeshes = (g: MeshGroup, meshes: RMesh[], name: string, closed = true) => {
|
||||
for (const m of meshes) {
|
||||
if (m.indices.length === 0) continue;
|
||||
appendModelMesh(newPrim(g, mats.get(name, m.color)), m.positions, m.indices, closed);
|
||||
}
|
||||
};
|
||||
for (const roof of project.roofs ?? []) {
|
||||
const g = newGroup(`Dach_${sanitizeName(roof.id)}`, "roof", roof.id, levelOf(roof.floorId));
|
||||
addMeshes(g, emitRoofs({ ...project, roofs: [roof] }), "Dach");
|
||||
groups.push(g);
|
||||
}
|
||||
for (const col of project.columns ?? []) {
|
||||
const g = newGroup(`Stuetze_${sanitizeName(col.id)}`, "column", col.id, levelOf(col.floorId));
|
||||
addMeshes(g, emitColumns({ ...project, columns: [col] }), componentName(col.componentId, "Stuetze"));
|
||||
groups.push(g);
|
||||
}
|
||||
for (const stair of project.stairs ?? []) {
|
||||
const one: Project = { ...project, stairs: [stair] };
|
||||
const g = newGroup(`Treppe_${sanitizeName(stair.id)}`, "stair", stair.id, levelOf(stair.floorId));
|
||||
for (const s of emitStairs(one)) {
|
||||
const outline: Vec2[] = s.outline.map(([x, y]) => ({ x, y }));
|
||||
pushPrism(newPrim(g, mats.get("Treppe", s.color)), outline, s.zBottom, s.zTop);
|
||||
}
|
||||
addMeshes(g, emitStairMeshes(one), "Treppe");
|
||||
addMeshes(g, emitStairRailings(one), "Handlauf");
|
||||
groups.push(g);
|
||||
}
|
||||
|
||||
// Öffnungsteile: je Öffnung ein Knoten (Name Fenster_<id>/Tuer_<id>) mit Glas und den Rahmenteilen als
|
||||
// Teil-Meshes je Material. Auch hier die Ableitung nur mit der Wirtswand und dieser Öffnung.
|
||||
if (opts.openingParts ?? true) {
|
||||
for (const op of project.openings ?? []) {
|
||||
const host = project.walls.find((w) => w.id === op.hostWallId);
|
||||
if (!host) continue;
|
||||
const parts = emitOpeningMeshes({ ...project, walls: [host], openings: [op] }, "mittel");
|
||||
if (parts.length === 0) continue;
|
||||
const g = newGroup(`${op.kind === "window" ? "Fenster" : "Tuer"}_${sanitizeName(op.id)}`, op.kind, op.id, levelOf(host.floorId));
|
||||
const prims = new Map<string, MeshPrim>();
|
||||
for (const m of parts) {
|
||||
const glass = sameRgb(m.color, GLASS_COLOR);
|
||||
const name = glass ? "Glas" : (OPENING_PART_NAMES.find(([c]) => sameRgb(c, m.color))?.[1] ?? "Oeffnungsteil");
|
||||
let prim = prims.get(name);
|
||||
if (!prim) {
|
||||
// Glas transparent und glatt (BLEND), Rahmen matt.
|
||||
const mat = glass ? mats.get(name, m.color, 0.35, 0, 0.05) : mats.get(name, m.color, 1, 0, 0.6);
|
||||
prim = newPrim(g, mat);
|
||||
prims.set(name, prim);
|
||||
}
|
||||
appendModelMesh(prim, m.positions, m.indices, true);
|
||||
}
|
||||
groups.push(g);
|
||||
}
|
||||
}
|
||||
|
||||
// Gelände und importierte Meshes (IFC/DXF): Farbe der Quelle, falls gesetzt.
|
||||
if (opts.context ?? true) {
|
||||
for (const obj of project.context ?? []) {
|
||||
if (obj.type !== "terrainMesh" && obj.type !== "importedMesh") continue;
|
||||
if (obj.positions.length < 9 || obj.indices.length < 3) continue;
|
||||
const terrain = obj.type === "terrainMesh";
|
||||
const rgb: Rgb = !terrain && obj.color ? hexToRgb(obj.color, IMPORTED_RGB) : terrain ? TERRAIN_RGB : IMPORTED_RGB;
|
||||
const g = newGroup(`${terrain ? "Gelaende" : "Kontext"}_${sanitizeName(obj.id)}`, terrain ? "terrain" : "context", obj.id, -1);
|
||||
const prim = newPrim(g, mats.get(terrain ? "Gelaende" : obj.name || "Kontext", rgb));
|
||||
appendModelMesh(prim, obj.positions, obj.indices, false);
|
||||
groups.push(g);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
groups: groups.filter((g) => g.prims.some((p) => p.indices.length > 0)),
|
||||
materials: mats.list,
|
||||
levels,
|
||||
};
|
||||
}
|
||||
|
||||
// ── Flacher Puffer (Gegenstück zu src-tauri/fileio/src/mesh_export.rs, dort die Kodierung) ─────
|
||||
|
||||
const FLAT_VERSION = 1;
|
||||
|
||||
/** Kodiert die Szene als `[Zahlenpuffer, Zeichenketten durch \0 getrennt]`. */
|
||||
function encodeScene(scene: MeshScene, byLevel: boolean): [Float64Array, string] {
|
||||
const nums: number[] = [FLAT_VERSION, byLevel ? 1 : 0];
|
||||
const strings: string[] = [];
|
||||
const str = (s: string): number => {
|
||||
strings.push(s.replace(/\0/g, ""));
|
||||
return strings.length - 1;
|
||||
};
|
||||
nums.push(scene.materials.length);
|
||||
for (const m of scene.materials) nums.push(str(m.name), m.rgba[0], m.rgba[1], m.rgba[2], m.rgba[3], m.metallic, m.roughness);
|
||||
nums.push(scene.levels.length);
|
||||
for (const l of scene.levels) nums.push(str(l.id), str(l.name));
|
||||
nums.push(scene.groups.length);
|
||||
for (const g of scene.groups) {
|
||||
nums.push(str(g.name), str(g.kind), str(g.id), g.level, g.prims.length);
|
||||
for (const p of g.prims) {
|
||||
nums.push(p.material, p.positions.length / 3);
|
||||
for (let i = 0; i < p.positions.length; i++) nums.push(p.positions[i]);
|
||||
nums.push(p.indices.length / 3);
|
||||
for (let i = 0; i < p.indices.length; i++) nums.push(p.indices[i]);
|
||||
}
|
||||
}
|
||||
return [new Float64Array(nums), strings.join("\0")];
|
||||
}
|
||||
|
||||
/** Ruft eine Rust-Bindung; leeres Ergebnis (kaputter Puffer) wird zum Fehler mit dem Grund. */
|
||||
function write<T extends string | Uint8Array>(project: Project, opts: MeshOptions, byLevel: boolean, run: (m: ReturnType<typeof fileio>, buf: Float64Array, strings: string) => T): T {
|
||||
const args = [(opts.openingParts ?? true) ? 1 : 0, (opts.context ?? true) ? 1 : 0, byLevel ? 1 : 0];
|
||||
const [buf, strings] = decodeExportFlat(documentFor(project).queryBin("meshExportData", args));
|
||||
const m = fileio();
|
||||
const [buf, strings] = encodeScene(buildScene(project, opts), byLevel);
|
||||
const out = run(m, buf, strings);
|
||||
if (out.length === 0) {
|
||||
const why = m.export_mesh_check_flat(buf, strings);
|
||||
@@ -497,9 +36,9 @@ function write<T extends string | Uint8Array>(project: Project, opts: MeshOption
|
||||
|
||||
/**
|
||||
* Baut einen vollständigen Wavefront-OBJ-String des 3D-Gebäudemodells (Meter, Y-up rechtshändig:
|
||||
* Modell (x, y, z-hoch) → (x, z, −y), siehe Moduldoc). Ein `o`-Objekt je Bauteil-Vorkommen (Wand, Decke,
|
||||
* Extrusion, Dach, Treppe, Stütze, Fenster/Tür, Kontext-Mesh). Leeres Projekt ⇒ gültige Datei nur mit
|
||||
* Kopf-Kommentaren. Verlangt das geladene Format-Modul (`await loadFileio()`).
|
||||
* Modell (x, y, z-hoch) → (x, z, −y)). Ein `o`-Objekt je Bauteil-Vorkommen (Wand, Decke, Extrusion, Dach,
|
||||
* Treppe, Stütze, Fenster/Tür, Kontext-Mesh). Leeres Projekt ⇒ gültige Datei nur mit Kopf-Kommentaren.
|
||||
* Verlangt das geladene Format-Modul (`await loadFileio()`).
|
||||
*/
|
||||
export function exportObj(project: Project, opts: MeshOptions = {}): string {
|
||||
return write(project, opts, false, (m, b, s) => m.export_mesh_obj_flat(b, s));
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
// Klassifikation im IFC-Export ([B5], 28.10.): welche Klassifikationssysteme das Modell hergibt und die
|
||||
// Standard-Zuordnung nach eBKP-H. Reine Tabellen/Funktionen, kein IFC-Schreiben (das macht Rust über
|
||||
// den Datensatz CLASSIFICATION, `ifc_export.rs`).
|
||||
//
|
||||
// Was das Modell führt: KEINEN eBKP-H-/BKP-Code. `categoryCode` an Bauteilen ist die Grafik-Ebene
|
||||
// („20" Wände, „30" Decken …, `LayerCategory`), kein Kostenschlüssel. Daher zwei getrennte Wege:
|
||||
// • `layerCodes` — die Ebene des Modells als eigenes System „Dossier-Ebenen" (Code = `categoryCode`,
|
||||
// Name = Ebenenname). Stammt aus dem Modell, behauptet keinen Standard.
|
||||
// • `ebkph` — Standardzuordnung je Bauteilart auf eBKP-H-HAUPTGRUPPEN (siehe `EBKPH_GROUPS`).
|
||||
//
|
||||
// Quelle eBKP-H: CRB, „eBKP-H Elementbasierter Baukostenplan Hochbau", SN 506 511 (Ausgabe 2020).
|
||||
// Gesichert sind nur die Hauptgruppen-Buchstaben und ihre Namen (A Grundstück, B Vorbereitung,
|
||||
// C Konstruktion Gebäude, D Technik Gebäude, E Äussere Wandbekleidung Gebäude, F Bedachung Gebäude,
|
||||
// G Ausbau Gebäude, H Nutzungsspezifische Anlagen Gebäude, I Umgebung Gebäude, J Ausstattung,
|
||||
// V Planungsleistungen, W Nebenkosten, Y Reserve, Z Mehrwertsteuer). Keine Untergruppen (C01 …):
|
||||
// die hängen von Konstruktionsart und Lage ab, die das Modell nicht trägt.
|
||||
//
|
||||
// Die Zuordnung ist deshalb bewusst grob und ein VORSCHLAG für die Kostenplanung, kein Ersatz für
|
||||
// die Einordnung durch die Kostenplanerin:
|
||||
// Wand → C (Wandkonstruktion; Aussen-/Innenbekleidung E/G und nichttragende Innenwände
|
||||
// unterscheidet das Modell nicht — dafür fehlt ein Feld am Wandtyp)
|
||||
// Decke → C (Deckenkonstruktion; Bodenbeläge/Unterdecken wären G)
|
||||
// Stütze → C
|
||||
// Treppe → C (Treppenkonstruktion; Belag/Geländer wären G)
|
||||
// Dach → F (Dachaufbau mit Eindeckung/Abdichtung; die reine Tragkonstruktion wäre C)
|
||||
// Fenster → E (Fenster der Gebäudehülle)
|
||||
// Tür → keine (Aussentür E, Innentür G — nicht unterscheidbar, daher nicht geraten)
|
||||
// Raum → keine (Räume sind Flächen, kein Bauteil; sie haben die SIA-416-Zonen)
|
||||
|
||||
import type { LayerCategory, Project } from "../model/types";
|
||||
|
||||
/** IFC-Schema der Ausgabe: IFC4 (Standard) oder IFC2x3 (Coordination View 2.0, TC1). */
|
||||
export type IfcSchema = "IFC4" | "IFC2X3";
|
||||
|
||||
/** Optionen des IFC-Exports: Schema und Klassifikation. */
|
||||
export interface IfcExportOptions {
|
||||
/** Schema der Datei; ohne Angabe IFC4. */
|
||||
schema?: IfcSchema;
|
||||
/** eBKP-H-Hauptgruppen je Bauteilart (Standardzuordnung, s. Dateikopf). */
|
||||
ebkph?: boolean;
|
||||
/** `categoryCode` (Ebene) des Modells als System „Dossier-Ebenen". */
|
||||
layerCodes?: boolean;
|
||||
}
|
||||
|
||||
/** Bauteilarten, die klassifiziert werden können. */
|
||||
export type ClassifiedKind = "wall" | "slab" | "roof" | "column" | "stair" | "window" | "door" | "space";
|
||||
|
||||
/** Ein Klassifikationssystem für IfcClassification. */
|
||||
export interface ClassificationSystem {
|
||||
name: string;
|
||||
source: string;
|
||||
/** Ausgabe; leer = keine Angabe. */
|
||||
edition: string;
|
||||
}
|
||||
|
||||
export const EBKPH_SYSTEM: ClassificationSystem = {
|
||||
name: "eBKP-H",
|
||||
source: "CRB Schweizerische Zentralstelle für Baurationalisierung",
|
||||
edition: "SN 506 511:2020",
|
||||
};
|
||||
|
||||
export const LAYER_SYSTEM: ClassificationSystem = {
|
||||
name: "Dossier-Ebenen",
|
||||
source: "Dossier",
|
||||
edition: "",
|
||||
};
|
||||
|
||||
/** Gesicherte eBKP-H-Hauptgruppen (nur die hier verwendeten). */
|
||||
export const EBKPH_GROUPS = {
|
||||
C: "Konstruktion Gebäude",
|
||||
E: "Äussere Wandbekleidung Gebäude",
|
||||
F: "Bedachung Gebäude",
|
||||
} as const;
|
||||
|
||||
const EBKPH_BY_KIND: Partial<Record<ClassifiedKind, keyof typeof EBKPH_GROUPS>> = {
|
||||
wall: "C",
|
||||
slab: "C",
|
||||
column: "C",
|
||||
stair: "C",
|
||||
roof: "F",
|
||||
window: "E",
|
||||
};
|
||||
|
||||
/** eBKP-H-Hauptgruppe zur Bauteilart, oder `null` (Tür, Raum: nicht eindeutig). */
|
||||
export function ebkphGroup(kind: ClassifiedKind): { code: string; name: string } | null {
|
||||
const code = EBKPH_BY_KIND[kind];
|
||||
return code ? { code, name: EBKPH_GROUPS[code] } : null;
|
||||
}
|
||||
|
||||
function findLayer(list: readonly LayerCategory[], code: string): LayerCategory | undefined {
|
||||
for (const c of list) {
|
||||
if (c.code === code) return c;
|
||||
const sub = c.children ? findLayer(c.children, code) : undefined;
|
||||
if (sub) return sub;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Ebene (Code + Name) eines Bauteils; ohne Code `null`, ohne bekannte Ebene der Code als Name. */
|
||||
export function layerClassification(project: Project, categoryCode: string | undefined): { code: string; name: string } | null {
|
||||
const code = categoryCode?.trim();
|
||||
if (!code) return null;
|
||||
return { code, name: findLayer(project.layers, code)?.name ?? code };
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
// Türen/Fenster im IFC-Export ([B5]): TS sammelt nur die Parameter aus Typ und Öffnung; die Geometrie
|
||||
// rechnet Rust (`src-tauri/fileio/src/ifc_openings.rs`, dort die Fälle Rahmen/Blatt/Glas/Ausführung).
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { fillParams } from "./ifcOpenings";
|
||||
import type { DoorType, Opening, Project, Wall, WindowType } from "../model/types";
|
||||
|
||||
const wall = { id: "W", start: { x: 0, y: 0 }, end: { x: 5, y: 0 } } as Wall;
|
||||
const host = { nLo: -0.2, nHi: 0.2 };
|
||||
const proj = (over: { doorTypes?: DoorType[]; windowTypes?: WindowType[] }) =>
|
||||
({ doorTypes: over.doorTypes ?? [], windowTypes: over.windowTypes ?? [] }) as unknown as Project;
|
||||
const door = (over: Partial<Opening> = {}) =>
|
||||
({ id: "D", type: "opening", hostWallId: "W", categoryCode: "21", kind: "door", position: 1, width: 1, height: 2.1, sillHeight: 0, ...over }) as Opening;
|
||||
const win = (over: Partial<Opening> = {}) =>
|
||||
({ id: "F", type: "opening", hostWallId: "W", categoryCode: "21", kind: "window", position: 1, width: 1.2, height: 1.2, sillHeight: 0.9, ...over }) as Opening;
|
||||
const cut = (o: Opening) => ({ from: o.position, to: o.position + o.width, zBottom: o.sillHeight, zTop: o.sillHeight + o.height });
|
||||
const wt = (over: Partial<WindowType> = {}): WindowType =>
|
||||
({ id: "wt", name: "Fenster", kind: "dreh", wingCount: 1, glazing: "dreifach", frameThickness: 0.08, defaultSillHeight: 0.9, defaultWidth: 1.2, defaultHeight: 1.2, ...over }) as WindowType;
|
||||
const dtp = (over: Partial<DoorType> = {}): DoorType =>
|
||||
({ id: "dt", name: "Tür", kind: "dreh", leafCount: 1, leafStyle: "glatt", frameThickness: 0.06, defaultWidth: 1, defaultHeight: 2.1, ...over }) as DoorType;
|
||||
|
||||
describe("fillParams", () => {
|
||||
it("Fenster: Typwerte, Flügeltabelle, Flügelzahl der Öffnung vor dem Typ", () => {
|
||||
const t = wt({
|
||||
frameWidth: 0.09,
|
||||
frameDepth: 0.1,
|
||||
insetFromFace: 0.05,
|
||||
insetFace: "innen",
|
||||
wingCount: 3,
|
||||
sashes: [{ kind: "fluegel", autoWidth: false, width: 0.5 }, { kind: "pfosten", postWidth: 0.1 }, { kind: "fluegel" }],
|
||||
});
|
||||
const o = win({ typeId: "wt", wingCount: 2 });
|
||||
expect(fillParams(proj({ windowTypes: [t] }), wall, o, cut(o), host)).toMatchObject({
|
||||
from: 1,
|
||||
to: 2.2,
|
||||
zBottom: 0.9,
|
||||
zTop: 2.1,
|
||||
nLo: -0.2,
|
||||
nHi: 0.2,
|
||||
frameDepth: 0.1,
|
||||
frameWidth: 0.09,
|
||||
inset: 0.05,
|
||||
insetOutside: false,
|
||||
wingCount: 2,
|
||||
panes: 3,
|
||||
sashes: [
|
||||
{ post: false, fixed: true, width: 0.5 },
|
||||
{ post: true, postWidth: 0.1, fixed: false },
|
||||
{ post: false, fixed: false },
|
||||
],
|
||||
});
|
||||
// Ohne Typ: nichts vom Typ, zwei Scheiben, eine Flügel.
|
||||
const p = fillParams(proj({}), wall, win(), cut(win()), host);
|
||||
expect(p).toMatchObject({ frameDepth: undefined, frameWidth: undefined, insetOutside: true, wingCount: 1, panes: 2, sashes: [] });
|
||||
});
|
||||
|
||||
it("Tür: Art, Blätter, Aufschlag, Scharnier, Oberlicht, Glas", () => {
|
||||
const o = door({ typeId: "dt", hinge: "end", swing: "right", openingDir: "out" });
|
||||
const t = dtp({ kind: "schiebe", leafCount: 2, transomHeight: 0.4, leafStyle: "glas", glazingRatio: 0.36 });
|
||||
expect(fillParams(proj({ doorTypes: [t] }), wall, o, cut(o), host)).toMatchObject({
|
||||
doorKind: 1,
|
||||
leafCount: 2,
|
||||
swingSign: -1,
|
||||
dirSign: -1,
|
||||
hingeAtStart: false,
|
||||
transomHeight: 0.4,
|
||||
glazed: true,
|
||||
glazingRatio: 0.36,
|
||||
});
|
||||
const plain = fillParams(proj({}), wall, door(), cut(door()), host);
|
||||
expect(plain).toMatchObject({ doorKind: 0, leafCount: 1, swingSign: 1, dirSign: 1, hingeAtStart: true, transomHeight: 0, glazed: false });
|
||||
expect(fillParams(proj({}), wall, door({ doorType: "wandoeffnung" }), cut(door()), host).doorKind).toBe(2);
|
||||
expect(fillParams(proj({ doorTypes: [dtp({ kind: "wandoeffnung" })] }), wall, door({ typeId: "dt" }), cut(door()), host).doorKind).toBe(2);
|
||||
});
|
||||
});
|
||||
@@ -1,91 +0,0 @@
|
||||
// Türen und Fenster im IFC-Export ([B5]): sammelt die Parameter einer Füllung aus dem Modell (Typ und
|
||||
// Öffnung) für den Rust-Schreiber. Körper (Rahmen/Zarge, Türblatt, Glas), Füllungs-Placement und
|
||||
// OperationType/PartitioningType rechnet `src-tauri/fileio/src/ifc_openings.rs` (Port der früheren
|
||||
// TS-Rechnung, 28.10.; Kodierung FILL im Kopf von `ifc_export.rs`). Fehlende Typwerte bleiben `undefined`,
|
||||
// die Standardmasse (Rahmen 6 × 7 cm, Blatt 4 cm, Glaspakete) kennt nur Rust.
|
||||
|
||||
import type { Opening, Project, Vec2, Wall } from "../model/types";
|
||||
import { getDoorType, getWindowType, glazingPanesOf } from "../model/types";
|
||||
|
||||
/** Ein Eintrag der Flügeltabelle, wie im Modell (`SashDef`). */
|
||||
export interface FillSash {
|
||||
post: boolean;
|
||||
postWidth?: number;
|
||||
fixed: boolean;
|
||||
width?: number;
|
||||
}
|
||||
|
||||
/** Parameter einer Füllung (Reihenfolge der Kodierung: `FlatIfc.opening` in `exportIfc.ts`). */
|
||||
export interface FillParams {
|
||||
wallStart: Vec2;
|
||||
wallEnd: Vec2;
|
||||
/** Achs-Intervall (Abstand ab `wall.start`) und absolute Höhen der Öffnung. */
|
||||
from: number;
|
||||
to: number;
|
||||
zBottom: number;
|
||||
zTop: number;
|
||||
/** Querausdehnung der ganzen Wand entlang der linken Normalen ab `wall.start` (`nLo` = Aussenseite). */
|
||||
nLo: number;
|
||||
nHi: number;
|
||||
frameDepth?: number;
|
||||
inset?: number;
|
||||
insetOutside: boolean;
|
||||
frameWidth?: number;
|
||||
/** Fenster: Flügelzahl, Scheiben (1–3), Flügeltabelle. */
|
||||
wingCount: number;
|
||||
panes: number;
|
||||
sashes: FillSash[];
|
||||
/** Tür: 0 Dreh, 1 Schiebe, 2 reine Wandöffnung. */
|
||||
doorKind: 0 | 1 | 2;
|
||||
leafCount: number;
|
||||
/** +1 Aufschlag links der Achse, −1 rechts; Richtung +1 innen, −1 aussen. */
|
||||
swingSign: 1 | -1;
|
||||
dirSign: 1 | -1;
|
||||
hingeAtStart: boolean;
|
||||
transomHeight: number;
|
||||
glazed: boolean;
|
||||
glazingRatio?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter der Füllung einer Öffnung. `c` = Achs-Intervall und absolute Höhen der Öffnung, `host` =
|
||||
* Querausdehnung der ganzen Wand (wie im 2D/3D).
|
||||
*/
|
||||
export function fillParams(
|
||||
project: Project,
|
||||
wall: Wall,
|
||||
opening: Opening,
|
||||
c: { from: number; to: number; zBottom: number; zTop: number },
|
||||
host: { nLo: number; nHi: number },
|
||||
): FillParams {
|
||||
const isDoor = opening.kind === "door";
|
||||
const dt = isDoor ? getDoorType(project, opening) : undefined;
|
||||
const wt = isDoor ? undefined : getWindowType(project, opening);
|
||||
const t = dt ?? wt;
|
||||
const kind = dt?.kind ?? (opening.doorType === "wandoeffnung" ? "wandoeffnung" : "dreh");
|
||||
return {
|
||||
wallStart: wall.start,
|
||||
wallEnd: wall.end,
|
||||
from: c.from,
|
||||
to: c.to,
|
||||
zBottom: c.zBottom,
|
||||
zTop: c.zTop,
|
||||
nLo: host.nLo,
|
||||
nHi: host.nHi,
|
||||
frameDepth: t?.frameDepth,
|
||||
inset: t?.insetFromFace,
|
||||
insetOutside: (t?.insetFace ?? "aussen") === "aussen",
|
||||
frameWidth: t?.frameWidth,
|
||||
wingCount: opening.wingCount ?? wt?.wingCount ?? 1,
|
||||
panes: wt ? glazingPanesOf(wt) : 2,
|
||||
sashes: (wt?.sashes ?? []).map((s) => ({ post: s.kind === "pfosten", postWidth: s.postWidth, fixed: s.autoWidth === false, width: s.width })),
|
||||
doorKind: kind === "schiebe" ? 1 : kind === "wandoeffnung" ? 2 : 0,
|
||||
leafCount: dt?.leafCount ?? 1,
|
||||
swingSign: (opening.swing ?? "left") === "left" ? 1 : -1,
|
||||
dirSign: (opening.openingDir ?? "in") === "in" ? 1 : -1,
|
||||
hingeAtStart: (opening.hinge ?? "start") === "start",
|
||||
transomHeight: dt?.transomHeight ?? 0,
|
||||
glazed: dt?.leafStyle === "glas",
|
||||
glazingRatio: dt?.glazingRatio,
|
||||
};
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
// Basismengen für den IFC-Export ([B5], 28.10.): reine Rechnung aus der Geometrie, Werte nachrechenbar.
|
||||
import { describe, it, expect } from "vitest";
|
||||
import type { RWall } from "../plan/toWalls3d";
|
||||
import {
|
||||
columnQuantities,
|
||||
flightQuantities,
|
||||
meshVolume,
|
||||
openingQuantities,
|
||||
railingQuantities,
|
||||
ringArea,
|
||||
ringPerimeter,
|
||||
roofQuantities,
|
||||
slabQuantities,
|
||||
wallQuantities,
|
||||
} from "./ifcQuantities";
|
||||
|
||||
const byName = (q: { name: string; value: number }[]) => Object.fromEntries(q.map((x) => [x.name, x.value]));
|
||||
|
||||
/** Wandband: Quader `len` lang entlang x ab `x0`, Dicke, Höhe ab `base`. */
|
||||
function band(x0: number, len: number, thickness: number, height: number, base = 0, topDrop?: [number, number]): RWall {
|
||||
return { start: [x0, 0], end: [x0 + len, 0], thickness, height, baseElevation: base, color: [1, 1, 1], layers: [], wallId: "W", ...(topDrop ? { topDrop } : {}) };
|
||||
}
|
||||
|
||||
describe("Hilfen", () => {
|
||||
it("Ringfläche (unabhängig vom Umlaufsinn) und Umfang", () => {
|
||||
const sq = [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 4, y: 3 }, { x: 0, y: 3 }];
|
||||
expect(ringArea(sq)).toBe(12);
|
||||
expect(ringArea([...sq].reverse())).toBe(12);
|
||||
expect(ringPerimeter(sq)).toBe(14);
|
||||
expect(ringArea([])).toBe(0);
|
||||
});
|
||||
|
||||
it("Mesh-Volumen eines Würfels, unabhängig von der Wicklung", () => {
|
||||
const pos = [0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 2, 0, 0, 0, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2];
|
||||
const idx = [0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 0, 4, 3, 4, 7];
|
||||
expect(meshVolume(pos, idx)).toBeCloseTo(8, 12);
|
||||
const rev: number[] = [];
|
||||
for (let i = 0; i < idx.length; i += 3) rev.push(idx[i], idx[i + 2], idx[i + 1]);
|
||||
expect(meshVolume(pos, rev)).toBeCloseTo(8, 12);
|
||||
expect(meshVolume([], [])).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Wand", () => {
|
||||
const wall = { start: { x: 0, y: 0 }, end: { x: 5, y: 0 } };
|
||||
|
||||
it("eine Schicht: Länge, Dicke, Höhe, Seitenfläche, Volumen; Öffnung wird netto abgezogen", () => {
|
||||
const q = byName(
|
||||
wallQuantities(wall, [band(0, 5, 0.3, 2.6)], [{ from: 1, to: 2, zBottom: 0.9, zTop: 2.1 }]),
|
||||
);
|
||||
expect(q.Length).toBe(5);
|
||||
expect(q.Width).toBeCloseTo(0.3, 12);
|
||||
expect(q.Height).toBeCloseTo(2.6, 12);
|
||||
expect(q.GrossSideArea).toBeCloseTo(13, 12);
|
||||
expect(q.NetSideArea).toBeCloseTo(13 - 1.2, 12);
|
||||
expect(q.GrossVolume).toBeCloseTo(13 * 0.3, 12);
|
||||
expect(q.NetVolume).toBeCloseTo((13 - 1.2) * 0.3, 12);
|
||||
});
|
||||
|
||||
it("mehrere Schichten: Dicke und Volumen summieren, Öffnung schneidet jede Schicht", () => {
|
||||
// Aussenschicht 0.2 (Achse −0.15 … ), Dämmung 0.1: Mittellinien bei y = −0.05 und +0.1
|
||||
const a = { ...band(0, 5, 0.2, 2.6), start: [0, -0.05], end: [5, -0.05] } as RWall;
|
||||
const b = { ...band(0, 5, 0.1, 2.6), start: [0, 0.1], end: [5, 0.1] } as RWall;
|
||||
const q = byName(wallQuantities(wall, [a, b], [{ from: 2, to: 3, zBottom: 0, zTop: 2.1 }]));
|
||||
expect(q.Width).toBeCloseTo(0.3, 12);
|
||||
expect(q.GrossVolume).toBeCloseTo(5 * 0.3 * 2.6, 12);
|
||||
expect(q.NetVolume).toBeCloseTo((5 * 2.6 - 1 * 2.1) * 0.3, 12);
|
||||
});
|
||||
|
||||
it("innere Schicht endet unter der Decke: Seitenfläche mit voller Wandhöhe, Volumen je Schicht", () => {
|
||||
const outer = band(0, 5, 0.2, 2.6);
|
||||
const inner = band(0.1, 4.8, 0.1, 2.3);
|
||||
const q = byName(wallQuantities(wall, [outer, inner], []));
|
||||
expect(q.Height).toBeCloseTo(2.6, 12);
|
||||
expect(q.GrossSideArea).toBeCloseTo(13, 12);
|
||||
expect(q.GrossVolume).toBeCloseTo(5 * 0.2 * 2.6 + 4.8 * 0.1 * 2.3, 12);
|
||||
});
|
||||
|
||||
it("Gehrung/Anschluss: kürzeres Band ändert Volumen, nicht die Wandlänge", () => {
|
||||
const q = byName(wallQuantities(wall, [band(0.1, 4.8, 0.3, 2.6)], []));
|
||||
expect(q.Length).toBe(5);
|
||||
expect(q.GrossVolume).toBeCloseTo(4.8 * 0.3 * 2.6, 12);
|
||||
expect(q.NetVolume).toBeCloseTo(q.GrossVolume, 12);
|
||||
});
|
||||
|
||||
it("schräge Oberkante: Höhe fehlt (nicht konstant), Fläche und Volumen mit mittlerer Höhe", () => {
|
||||
const q = byName(wallQuantities(wall, [band(0, 5, 0.3, 3, 0, [0, 1])], []));
|
||||
expect(q.Height).toBeUndefined();
|
||||
expect(q.GrossSideArea).toBeCloseTo(5 * 2.5, 12);
|
||||
expect(q.GrossVolume).toBeCloseTo(5 * 0.3 * 2.5, 12);
|
||||
});
|
||||
|
||||
it("Mesh-Wand: Netto-Volumen aus dem Netz, Brutto bleibt der Quader", () => {
|
||||
const q = byName(wallQuantities(wall, [band(0, 5, 0.3, 2.6)], [{ from: 1, to: 2, zBottom: 0.9, zTop: 2.1 }], 3.5));
|
||||
expect(q.NetVolume).toBe(3.5);
|
||||
expect(q.GrossVolume).toBeCloseTo(13 * 0.3, 12);
|
||||
});
|
||||
|
||||
it("Öffnung grösser als die Wand: Netto nie negativ; Öffnung ausserhalb zieht nichts ab", () => {
|
||||
const q = byName(wallQuantities(wall, [band(0, 5, 0.3, 2.6)], [{ from: -1, to: 6, zBottom: -1, zTop: 5 }, { from: 8, to: 9, zBottom: 0, zTop: 2 }]));
|
||||
expect(q.NetSideArea).toBe(0);
|
||||
expect(q.NetVolume).toBeCloseTo(0, 12);
|
||||
});
|
||||
|
||||
it("keine Bänder: keine Mengen", () => {
|
||||
expect(wallQuantities(wall, [], [])).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Decke, Dach, Stütze, Öffnung, Treppe", () => {
|
||||
it("Decke: Fläche, Umfang, Dicke; Aussparung nur netto", () => {
|
||||
const outline = [{ x: 0, y: 0 }, { x: 5, y: 0 }, { x: 5, y: 4 }, { x: 0, y: 4 }];
|
||||
const hole = [{ x: 1, y: 1 }, { x: 2, y: 1 }, { x: 2, y: 2 }, { x: 1, y: 2 }];
|
||||
const q = byName(slabQuantities(outline, [hole], 0.2));
|
||||
expect(q.Width).toBeCloseTo(0.2, 12);
|
||||
expect(q.Perimeter).toBe(18);
|
||||
expect(q.GrossArea).toBe(20);
|
||||
expect(q.NetArea).toBe(19);
|
||||
expect(q.GrossVolume).toBeCloseTo(4, 12);
|
||||
expect(q.NetVolume).toBeCloseTo(3.8, 12);
|
||||
});
|
||||
|
||||
it("Dach: geneigte Fläche > Grundrissfläche (Satteldach 30°)", () => {
|
||||
// Zwei Flächen 5 × 2 m Grundriss, 30° geneigt: je 5 × 2/cos(30°).
|
||||
const h = Math.tan(Math.PI / 6) * 2;
|
||||
const planes = [
|
||||
[[0, 0, 0], [5, 0, 0], [5, 2, h], [0, 2, h]],
|
||||
[[0, 4, 0], [0, 2, h], [5, 2, h], [5, 4, 0]],
|
||||
] as [number, number, number][][];
|
||||
const q = byName(roofQuantities(planes));
|
||||
expect(q.ProjectedArea).toBeCloseTo(20, 9);
|
||||
expect(q.GrossArea).toBeCloseTo(20 / Math.cos(Math.PI / 6), 9);
|
||||
expect(q.NetArea).toBe(q.GrossArea);
|
||||
});
|
||||
|
||||
it("Stütze 0.3 × 0.3 × 2.6", () => {
|
||||
const fp = [{ x: 0, y: 0 }, { x: 0.3, y: 0 }, { x: 0.3, y: 0.3 }, { x: 0, y: 0.3 }];
|
||||
const q = byName(columnQuantities(fp, 2.6));
|
||||
expect(q.Length).toBe(2.6);
|
||||
expect(q.CrossSectionArea).toBeCloseTo(0.09, 12);
|
||||
expect(q.OuterSurfaceArea).toBeCloseTo(1.2 * 2.6, 12);
|
||||
expect(q.NetSurfaceArea).toBeCloseTo(1.2 * 2.6 + 0.18, 12);
|
||||
expect(q.GrossVolume).toBeCloseTo(0.09 * 2.6, 12);
|
||||
expect(q.NetVolume).toBeCloseTo(q.GrossVolume, 12);
|
||||
});
|
||||
|
||||
it("Fenster/Tür: Breite, Höhe, Umfang, Fläche", () => {
|
||||
const q = byName(openingQuantities(1.2, 1.5));
|
||||
expect(q.Width).toBe(1.2);
|
||||
expect(q.Height).toBe(1.5);
|
||||
expect(q.Perimeter).toBeCloseTo(5.4, 12);
|
||||
expect(q.Area).toBeCloseTo(1.8, 12);
|
||||
});
|
||||
|
||||
it("Lauf und Geländer", () => {
|
||||
expect(byName(flightQuantities(3.4, 1.2))).toEqual({ Length: 3.4, GrossVolume: 1.2, NetVolume: 1.2 });
|
||||
expect(byName(railingQuantities(5))).toEqual({ Length: 5 });
|
||||
});
|
||||
|
||||
it("nie NaN/negativ: kaputte Eingaben ergeben 0", () => {
|
||||
const q = openingQuantities(Number.NaN, -1);
|
||||
for (const x of q) expect(Number.isFinite(x.value) && x.value >= 0).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,213 +0,0 @@
|
||||
// Basismengen (Qto_*BaseQuantities) für den IFC-Export ([B5], 28.10.): Längen, Flächen und Volumen
|
||||
// aus derselben Geometrie, die in die Datei geschrieben wird — für Kostenplanung (eBKP-H/BKP) und
|
||||
// Mengenermittlung. Reine Rechnung auf einfachen Eingaben (Bänder, Ringe, Netze), kein Zugriff auf
|
||||
// das Projekt; `exportIfc.ts` sammelt und ruft sie auf, Rust schreibt die IfcElementQuantity.
|
||||
//
|
||||
// Netto = abzüglich Öffnungen (Wand, Decke). Fehlt einer Menge die Grundlage (z. B. Höhe bei schräger
|
||||
// Wandoberkante: „nur angeben, wenn konstant“), lassen wir sie weg statt zu raten.
|
||||
|
||||
import type { Vec2 } from "../model/types";
|
||||
import type { RWall } from "../plan/toWalls3d";
|
||||
|
||||
/** Eine Menge: Name nach IFC4-Vorlage, Art (Länge/Fläche/Volumen) und Wert (immer endlich und ≥ 0). */
|
||||
export interface Qty {
|
||||
name: string;
|
||||
kind: "length" | "area" | "volume";
|
||||
value: number;
|
||||
}
|
||||
|
||||
/** Rundungsfehler und kaputte Eingaben (NaN) auf 0, nie negativ. */
|
||||
const clean = (v: number): number => (Number.isFinite(v) && v > 0 ? v : 0);
|
||||
const q = (name: string, kind: Qty["kind"], value: number): Qty => ({ name, kind, value: clean(value) });
|
||||
const len = (name: string, v: number) => q(name, "length", v);
|
||||
const area = (name: string, v: number) => q(name, "area", v);
|
||||
const vol = (name: string, v: number) => q(name, "volume", v);
|
||||
|
||||
/** Fläche eines Rings (Shoelace, unabhängig vom Umlaufsinn); offener Ring, die Schlusskante gilt als gegeben. */
|
||||
export function ringArea(pts: readonly Vec2[]): number {
|
||||
let a = 0;
|
||||
for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) a += pts[j].x * pts[i].y - pts[i].x * pts[j].y;
|
||||
return Math.abs(a) / 2;
|
||||
}
|
||||
|
||||
/** Umfang eines geschlossenen Rings. */
|
||||
export function ringPerimeter(pts: readonly Vec2[]): number {
|
||||
let p = 0;
|
||||
for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) p += Math.hypot(pts[i].x - pts[j].x, pts[i].y - pts[j].y);
|
||||
return p;
|
||||
}
|
||||
|
||||
/** Volumen eines geschlossenen Dreiecks-Netzes (Betrag der Summe der Tetraeder-Volumen zum Ursprung). */
|
||||
export function meshVolume(positions: readonly number[], indices: readonly number[]): number {
|
||||
let v = 0;
|
||||
for (let i = 0; i + 2 < indices.length; i += 3) {
|
||||
const a = indices[i] * 3;
|
||||
const b = indices[i + 1] * 3;
|
||||
const c = indices[i + 2] * 3;
|
||||
v +=
|
||||
positions[a] * (positions[b + 1] * positions[c + 2] - positions[b + 2] * positions[c + 1]) -
|
||||
positions[a + 1] * (positions[b] * positions[c + 2] - positions[b + 2] * positions[c]) +
|
||||
positions[a + 2] * (positions[b] * positions[c + 1] - positions[b + 1] * positions[c]);
|
||||
}
|
||||
return Math.abs(v) / 6;
|
||||
}
|
||||
|
||||
/** Öffnung einer Wand: Achs-Intervall (ab Wandanfang) und absolute Höhen. */
|
||||
export interface Cutout {
|
||||
from: number;
|
||||
to: number;
|
||||
zBottom: number;
|
||||
zTop: number;
|
||||
}
|
||||
|
||||
const overlap = (a0: number, a1: number, b0: number, b1: number): number => Math.max(0, Math.min(a1, b1) - Math.max(a0, b0));
|
||||
|
||||
/**
|
||||
* Wand-Basismengen aus den Schicht-Bändern (dieselben wie im 3D) und den Öffnungen.
|
||||
* • Length: Achslänge; Width: Gesamtdicke quer zur Achse; Height: nur bei konstanter Höhe.
|
||||
* • GrossSideArea: Achslänge × Wandhöhe (schräge Oberkante: höchste mittlere Bandhöhe);
|
||||
* NetSideArea: abzüglich der Öffnungsflächen.
|
||||
* • GrossVolume: Summe der Band-Quader (Gehrungen/Anschlüsse stecken in den Bandlängen);
|
||||
* NetVolume: abzüglich der Öffnungen je Band — oder `netVolume`, wenn die Wand als Netz mit schon
|
||||
* ausgestanzten Öffnungen (und Laibungen) geschrieben wird.
|
||||
*/
|
||||
export function wallQuantities(
|
||||
wall: { start: Vec2; end: Vec2 },
|
||||
bands: readonly RWall[],
|
||||
cutouts: readonly Cutout[],
|
||||
netVolume?: number,
|
||||
): Qty[] {
|
||||
if (bands.length === 0) return [];
|
||||
const axisLen = Math.hypot(wall.end.x - wall.start.x, wall.end.y - wall.start.y);
|
||||
const ux = axisLen > 0 ? (wall.end.x - wall.start.x) / axisLen : 1;
|
||||
const uy = axisLen > 0 ? (wall.end.y - wall.start.y) / axisLen : 0;
|
||||
// Quer zur Achse: Ausdehnung aller Bänder entlang der linken Normalen (−uy, ux).
|
||||
let nLo = Infinity;
|
||||
let nHi = -Infinity;
|
||||
let zMin = Infinity;
|
||||
let zMax = -Infinity;
|
||||
let sloped = false;
|
||||
let gross = 0;
|
||||
let tallest = 0;
|
||||
for (const b of bands) {
|
||||
const l = Math.hypot(b.end[0] - b.start[0], b.end[1] - b.start[1]);
|
||||
const off = -(b.start[0] - wall.start.x) * uy + (b.start[1] - wall.start.y) * ux;
|
||||
nLo = Math.min(nLo, off - b.thickness / 2);
|
||||
nHi = Math.max(nHi, off + b.thickness / 2);
|
||||
zMin = Math.min(zMin, b.baseElevation);
|
||||
zMax = Math.max(zMax, b.baseElevation + b.height);
|
||||
const drop = b.topDrop ? (b.topDrop[0] + b.topDrop[1]) / 2 : 0;
|
||||
if (b.topDrop && (Math.abs(b.topDrop[0]) > 1e-9 || Math.abs(b.topDrop[1]) > 1e-9)) sloped = true;
|
||||
gross += l * b.thickness * (b.height - drop);
|
||||
tallest = Math.max(tallest, b.height - drop);
|
||||
}
|
||||
// Seitenfläche der Wandebene: innere Schichten enden oft unter der Decke (niedrigere Bänder), die Wand
|
||||
// selbst reicht über die volle Höhe — bei konstanter Oberkante zählt die Gesamthöhe, bei schräger die
|
||||
// höchste mittlere Bandhöhe.
|
||||
const grossSide = axisLen * (sloped ? tallest : zMax - zMin);
|
||||
let cutSide = 0;
|
||||
let cutVolume = 0;
|
||||
for (const c of cutouts) {
|
||||
cutSide += (c.to - c.from) * overlap(c.zBottom, c.zTop, zMin, zMax);
|
||||
for (const b of bands) {
|
||||
const a0 = (b.start[0] - wall.start.x) * ux + (b.start[1] - wall.start.y) * uy;
|
||||
const a1 = (b.end[0] - wall.start.x) * ux + (b.end[1] - wall.start.y) * uy;
|
||||
const ox = overlap(Math.min(a0, a1), Math.max(a0, a1), c.from, c.to);
|
||||
cutVolume += ox * overlap(c.zBottom, c.zTop, b.baseElevation, b.baseElevation + b.height) * b.thickness;
|
||||
}
|
||||
}
|
||||
// Netto aus dem Netz kann den Band-Quader um Rundung/Gehrungsdetails überschreiten: Brutto nie unter Netto.
|
||||
const net = netVolume ?? Math.max(0, gross - cutVolume);
|
||||
gross = Math.max(gross, net);
|
||||
const out: Qty[] = [len("Length", axisLen), len("Width", nHi - nLo)];
|
||||
if (!sloped && zMax - zMin > 0) out.push(len("Height", zMax - zMin));
|
||||
out.push(
|
||||
area("GrossSideArea", grossSide),
|
||||
area("NetSideArea", Math.max(0, grossSide - cutSide)),
|
||||
vol("GrossVolume", gross),
|
||||
vol("NetVolume", net),
|
||||
);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Brutto-Volumen der Löcher in einem Band (für Netz-Wände ohne Netz-Volumen, s. `wallQuantities`). */
|
||||
export function holeVolume(bands: readonly RWall[]): number {
|
||||
let v = 0;
|
||||
for (const b of bands) for (const h of b.holes ?? []) v += (h.to - h.from) * overlap(h.zBottom, h.zTop, b.baseElevation, b.baseElevation + b.height) * b.thickness;
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Platten-Basismengen (Decke, Podest): Dicke, Umfang der Aussenkontur, Flächen und Volumen; Netto
|
||||
* zieht die Aussparungen ab.
|
||||
*/
|
||||
export function slabQuantities(outline: readonly Vec2[], openings: readonly (readonly Vec2[])[], thickness: number): Qty[] {
|
||||
const gross = ringArea(outline);
|
||||
const net = Math.max(0, gross - openings.reduce((s, r) => s + ringArea(r), 0));
|
||||
return [
|
||||
len("Width", thickness),
|
||||
len("Perimeter", ringPerimeter(outline)),
|
||||
area("GrossArea", gross),
|
||||
area("NetArea", net),
|
||||
vol("GrossVolume", gross * thickness),
|
||||
vol("NetVolume", net * thickness),
|
||||
];
|
||||
}
|
||||
|
||||
type Vec3 = readonly [number, number, number];
|
||||
|
||||
/**
|
||||
* Dach-Basismengen aus den geneigten Dachflächen (Aussenseite): geneigte Fläche (brutto = netto, das
|
||||
* Modell kennt keine Dachfenster/Aussparungen) und Grundrissprojektion.
|
||||
*/
|
||||
export function roofQuantities(planes: readonly (readonly Vec3[])[]): Qty[] {
|
||||
let sloped = 0;
|
||||
let projected = 0;
|
||||
for (const pts of planes) {
|
||||
// Newell: Vektorfläche des Polygons; Betrag = Fläche, z-Anteil = Projektion auf den Grundriss.
|
||||
let nx = 0;
|
||||
let ny = 0;
|
||||
let nz = 0;
|
||||
for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {
|
||||
const c = pts[j];
|
||||
const d = pts[i];
|
||||
nx += (c[1] - d[1]) * (c[2] + d[2]);
|
||||
ny += (c[2] - d[2]) * (c[0] + d[0]);
|
||||
nz += (c[0] - d[0]) * (c[1] + d[1]);
|
||||
}
|
||||
sloped += Math.hypot(nx, ny, nz) / 2;
|
||||
projected += Math.abs(nz) / 2;
|
||||
}
|
||||
return [area("GrossArea", sloped), area("NetArea", sloped), area("ProjectedArea", projected)];
|
||||
}
|
||||
|
||||
/** Stützen-Basismengen: Länge, Querschnitt, Mantel, Oberfläche und Volumen (keine Aussparungen). */
|
||||
export function columnQuantities(footprint: readonly Vec2[], length: number): Qty[] {
|
||||
const cross = ringArea(footprint);
|
||||
const outer = ringPerimeter(footprint) * length;
|
||||
return [
|
||||
len("Length", length),
|
||||
area("CrossSectionArea", cross),
|
||||
area("OuterSurfaceArea", outer),
|
||||
area("NetSurfaceArea", outer + 2 * cross),
|
||||
vol("GrossVolume", cross * length),
|
||||
vol("NetVolume", cross * length),
|
||||
];
|
||||
}
|
||||
|
||||
/** Tür-/Fenster-Basismengen (lichte Öffnung): Breite, Höhe, Umfang, Fläche. */
|
||||
export function openingQuantities(width: number, height: number): Qty[] {
|
||||
const w = clean(width);
|
||||
const h = clean(height);
|
||||
return [len("Width", w), len("Height", h), len("Perimeter", 2 * (w + h)), area("Area", w * h)];
|
||||
}
|
||||
|
||||
/** Treppenlauf: Lauflänge entlang der Lauflinie und Volumen (keine Aussparungen). */
|
||||
export function flightQuantities(length: number, volume: number): Qty[] {
|
||||
return [len("Length", length), vol("GrossVolume", volume), vol("NetVolume", volume)];
|
||||
}
|
||||
|
||||
/** Geländer: Länge. */
|
||||
export function railingQuantities(length: number): Qty[] {
|
||||
return [len("Length", length)];
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
// Treppen im IFC-Export ([B5], 28.10.): statt eines Fussabdruck-Quaders die Teile der Treppe wie im 3D —
|
||||
// Läufe (IfcStairFlight), Podest (IfcSlab LANDING) und Handlauf/Pfosten (IfcRailing), zusammengefasst
|
||||
// von der IfcStair (IfcRelAggregates). Quelle sind dieselben Ableitungen wie im 3D-Viewer
|
||||
// (`emitStairs` Tritt-Prismen und Podest, `emitStairMeshes` glatte Ortbeton-Laufplatte,
|
||||
// `emitStairRailings`), je Treppe mit einem Ein-Treppen-Projekt aufgerufen (die Ableitungen liefern keine
|
||||
// ids). Dieses Modul sammelt und rechnet die Basismengen; die Entitäten schreibt Rust (`ifc_export.rs`, STAIR).
|
||||
//
|
||||
// Zuordnung der Tritt-Prismen: bei "L" ist das Podest das Prisma mit dem Umriss des Podest-Polygons der
|
||||
// Treppengeometrie; Tritte bis zur Podest-Oberkante gehören zum ersten, die darüber zum zweiten Lauf.
|
||||
// Gerade und Wendeltreppen haben einen Lauf (die Wendel-Mitte bleibt Teil davon, wie im 3D).
|
||||
|
||||
import type { Project, Stair, Vec2 } from "../model/types";
|
||||
import { getStairType } from "../model/types";
|
||||
import { stairVerticalExtent } from "../model/wall";
|
||||
import { stairGeometry } from "../geometry/stair";
|
||||
import type { RSlab } from "../plan/toWalls3d";
|
||||
import { orientOutward } from "./meshOrient";
|
||||
import { flightQuantities, meshVolume, railingQuantities, ringArea, slabQuantities, type Qty } from "./ifcQuantities";
|
||||
import { emitStairMeshes, emitStairRailings, emitStairs } from "./model3dParts";
|
||||
|
||||
/** Ein Prisma (Profil in Welt-XY, Unterkante relativ zum Geschoss, Tiefe). */
|
||||
export interface StairSolid {
|
||||
pts: Vec2[];
|
||||
zRel: number;
|
||||
depth: number;
|
||||
}
|
||||
|
||||
export interface StairFlightParts {
|
||||
name: string;
|
||||
risers: number;
|
||||
treads: number;
|
||||
riserHeight: number;
|
||||
treadLength: number;
|
||||
/** IfcStairFlightTypeEnum. */
|
||||
predefined: "STRAIGHT" | "SPIRAL";
|
||||
quantities: Qty[];
|
||||
/** Entweder Prismen oder ein Dreiecks-Netz (IFC: x, y, z-hoch, Z relativ zum Geschoss). */
|
||||
solids?: StairSolid[];
|
||||
mesh?: { positions: number[]; indices: number[] };
|
||||
}
|
||||
|
||||
export interface StairParts {
|
||||
flights: StairFlightParts[];
|
||||
landing: { name: string; pts: Vec2[]; zRel: number; depth: number; quantities: Qty[] } | null;
|
||||
rail: { name: string; predefined: "HANDRAIL"; mesh: { positions: number[]; indices: number[] }; quantities: Qty[] } | null;
|
||||
}
|
||||
|
||||
const EPS = 1e-6;
|
||||
|
||||
/** Gleicher Umriss (gleiche Punktmenge, auch bei anderer Reihenfolge/Startpunkt). */
|
||||
function sameRing(a: readonly [number, number][], b: readonly Vec2[]): boolean {
|
||||
if (a.length !== b.length) return false;
|
||||
return a.every((p) => b.some((q) => Math.abs(p[0] - q.x) < EPS && Math.abs(p[1] - q.y) < EPS));
|
||||
}
|
||||
|
||||
const centroid = (pts: readonly Vec2[]): Vec2 => ({
|
||||
x: pts.reduce((s, p) => s + p.x, 0) / pts.length,
|
||||
y: pts.reduce((s, p) => s + p.y, 0) / pts.length,
|
||||
});
|
||||
|
||||
/** Netz (Modell x, y, z-hoch) nach IFC: Z relativ zum Geschoss, Wicklung nach aussen. */
|
||||
function ifcMesh(positions: readonly number[], indices: readonly number[], base: number): { positions: number[]; indices: number[] } {
|
||||
const pos = positions.slice();
|
||||
for (let i = 2; i < pos.length; i += 3) pos[i] -= base;
|
||||
return { positions: pos, indices: orientOutward(pos, indices) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Teile einer Treppe für den IFC-Export; `base` = Oberkante des Geschosses, dem die Treppe zugeordnet
|
||||
* ist (Z-Werte werden relativ dazu geschrieben). Leere Teile (keine Geometrie) ergeben `flights: []`,
|
||||
* `landing: null`, `rail: null` — der Aufrufer fällt dann auf den Fussabdruck zurück.
|
||||
*/
|
||||
export function stairParts(project: Project, stair: Stair, base: number): StairParts {
|
||||
const one: Project = { ...project, stairs: [stair] };
|
||||
const { zBottom, zTop } = stairVerticalExtent(project, stair);
|
||||
const rise = zTop - zBottom;
|
||||
const geo = stairGeometry(stair, rise);
|
||||
const slabs = emitStairs(one);
|
||||
const meshes = emitStairMeshes(one);
|
||||
const predefined = stair.shape === "spiral" ? "SPIRAL" : "STRAIGHT";
|
||||
|
||||
// Podest nur bei "L" (bei der Wendel ist das Polygon die Treppenmitte, Teil des Laufs).
|
||||
let landingSlab: RSlab | undefined;
|
||||
if (stair.shape === "L" && geo.landing) landingSlab = slabs.find((s) => sameRing(s.outline, geo.landing as Vec2[]));
|
||||
const treadSlabs = slabs.filter((s) => s !== landingSlab);
|
||||
|
||||
const solidOf = (s: RSlab): StairSolid => ({ pts: s.outline.map(([x, y]) => ({ x, y })), zRel: s.zBottom - base, depth: s.zTop - s.zBottom });
|
||||
const groups: RSlab[][] = [];
|
||||
if (landingSlab) {
|
||||
const top = landingSlab.zTop + EPS;
|
||||
const lower = treadSlabs.filter((s) => s.zTop <= top);
|
||||
const upper = treadSlabs.filter((s) => s.zTop > top);
|
||||
for (const g of [lower, upper]) if (g.length > 0) groups.push(g);
|
||||
} else if (treadSlabs.length > 0) {
|
||||
groups.push(treadSlabs);
|
||||
}
|
||||
|
||||
const flights: StairFlightParts[] = [];
|
||||
groups.forEach((g, k) => {
|
||||
// Tritte = verschiedene Oberkanten (Setzstufen-Platten und Nasen teilen die Höhe ihres Tritts).
|
||||
const tops = [...new Set(g.map((s) => Math.round(s.zTop / 1e-4)))];
|
||||
const treads = tops.length;
|
||||
// Lauflänge: Weg zwischen erstem und letztem Tritt (Schwerpunkte) plus eine Trittiefe, mit der Steigung.
|
||||
const lowest = g.reduce((m, s) => (s.zTop < m.zTop ? s : m), g[0]);
|
||||
const highest = g.reduce((m, s) => (s.zTop > m.zTop ? s : m), g[0]);
|
||||
const c0 = centroid(solidOf(lowest).pts);
|
||||
const c1 = centroid(solidOf(highest).pts);
|
||||
const run = Math.hypot(c1.x - c0.x, c1.y - c0.y) + geo.treadDepth;
|
||||
const lift = highest.zTop - lowest.zTop + geo.riserHeight;
|
||||
const solids = g.map(solidOf);
|
||||
const volume = g.reduce((s, x) => s + ringArea(x.outline.map(([px, py]) => ({ x: px, y: py }))) * (x.zTop - x.zBottom), 0);
|
||||
flights.push({
|
||||
name: groups.length > 1 ? `Lauf ${k + 1}` : "Lauf",
|
||||
risers: treads,
|
||||
treads,
|
||||
riserHeight: geo.riserHeight,
|
||||
treadLength: geo.treadDepth,
|
||||
predefined,
|
||||
quantities: flightQuantities(Math.hypot(run, lift), volume),
|
||||
solids,
|
||||
});
|
||||
});
|
||||
// Glatte Ortbeton-Laufplatte (gerade Betontreppe): ein Lauf als Netz.
|
||||
if (meshes.length > 0) {
|
||||
const positions: number[] = [];
|
||||
const indices: number[] = [];
|
||||
for (const m of meshes) {
|
||||
const at = positions.length / 3;
|
||||
for (const v of m.positions) positions.push(v);
|
||||
for (const i of m.indices) indices.push(at + i);
|
||||
}
|
||||
const mesh = ifcMesh(positions, indices, base);
|
||||
flights.push({
|
||||
name: flights.length > 0 ? `Lauf ${flights.length + 1}` : "Lauf",
|
||||
risers: geo.treads.length,
|
||||
treads: geo.treads.length,
|
||||
riserHeight: geo.riserHeight,
|
||||
treadLength: geo.treadDepth,
|
||||
predefined,
|
||||
quantities: flightQuantities(Math.hypot(stair.runLength, rise), meshVolume(mesh.positions, mesh.indices)),
|
||||
mesh,
|
||||
});
|
||||
}
|
||||
|
||||
let landing: StairParts["landing"] = null;
|
||||
if (landingSlab) {
|
||||
const s = solidOf(landingSlab);
|
||||
landing = { name: "Podest", pts: s.pts, zRel: s.zRel, depth: s.depth, quantities: slabQuantities(s.pts, [], s.depth) };
|
||||
}
|
||||
|
||||
let rail: StairParts["rail"] = null;
|
||||
const railMeshes = emitStairRailings(one);
|
||||
if (railMeshes.length > 0) {
|
||||
const positions: number[] = [];
|
||||
const indices: number[] = [];
|
||||
for (const m of railMeshes) {
|
||||
const at = positions.length / 3;
|
||||
for (const v of m.positions) positions.push(v);
|
||||
for (const i of m.indices) indices.push(at + i);
|
||||
}
|
||||
const sides = getStairType(project, stair)?.railing === "beide" ? 2 : 1;
|
||||
rail = {
|
||||
name: "Handlauf",
|
||||
predefined: "HANDRAIL",
|
||||
mesh: ifcMesh(positions, indices, base),
|
||||
quantities: railingQuantities(Math.hypot(stair.runLength, rise) * sides),
|
||||
};
|
||||
}
|
||||
return { flights, landing, rail };
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
// Wicklung von Dreiecks-Netzen nach aussen ausrichten — gemeinsam für Mesh-Export (OBJ/STL/glTF) und
|
||||
// IFC-Export. Die 3D-Ableitungen (`plan/toWalls3d/*`) liefern keine verlässliche Wicklung, weil render3d
|
||||
// doppelseitig zeichnet; Dateiformate verlangen sie.
|
||||
|
||||
/**
|
||||
* Richtet ein Dreiecks-Netz (Weltkoordinaten) so aus, dass die Flächennormalen nach AUSSEN zeigen:
|
||||
* Dreiecke werden über gemeinsame Kanten (Eckpunkte auf 0,01 mm verschweisst) zu Zusammenhangs-
|
||||
* Komponenten verbunden, jede Komponente zuerst in sich widerspruchsfrei gewickelt (Nachbarn
|
||||
* durchlaufen eine gemeinsame Kante gegenläufig) und dann nach dem Vorzeichen ihres Volumens
|
||||
* gedreht. Kanten mit mehr als zwei Dreiecken (Verschneidungen) verbinden nicht. Offene
|
||||
* Komponenten haben kein sinnvolles Volumen und bleiben, wie sie sind (nach dem Konsistenz-Schritt).
|
||||
*/
|
||||
export function orientOutward(pos: readonly number[], idx: readonly number[]): number[] {
|
||||
const nTri = Math.floor(idx.length / 3);
|
||||
const nVert = pos.length / 3;
|
||||
const weld = new Map<string, number>();
|
||||
const canon = new Array<number>(nVert);
|
||||
const q = (v: number) => Math.round(v * 1e5);
|
||||
for (let i = 0; i < nVert; i++) {
|
||||
const key = `${q(pos[3 * i])},${q(pos[3 * i + 1])},${q(pos[3 * i + 2])}`;
|
||||
let c = weld.get(key);
|
||||
if (c === undefined) {
|
||||
c = weld.size;
|
||||
weld.set(key, c);
|
||||
}
|
||||
canon[i] = c;
|
||||
}
|
||||
const N = weld.size + 1;
|
||||
// Kante (min,max) → [(Dreieck, vorwärts?)…]
|
||||
const edges = new Map<number, number[]>();
|
||||
const corner = (t: number, k: number) => canon[idx[3 * t + k]];
|
||||
for (let t = 0; t < nTri; t++) {
|
||||
for (let k = 0; k < 3; k++) {
|
||||
const a = corner(t, k);
|
||||
const b = corner(t, (k + 1) % 3);
|
||||
if (a === b) continue;
|
||||
const key = Math.min(a, b) * N + Math.max(a, b);
|
||||
const list = edges.get(key);
|
||||
const entry = t * 2 + (a < b ? 1 : 0);
|
||||
if (list) list.push(entry);
|
||||
else edges.set(key, [entry]);
|
||||
}
|
||||
}
|
||||
// Nachbarschaft über Kanten mit genau zwei Dreiecken: Wicklungs-Paritaet (0 = gleich, 1 = gegenläufig noetig).
|
||||
const adj: number[][] = Array.from({ length: nTri }, () => []);
|
||||
for (const list of edges.values()) {
|
||||
if (list.length !== 2) continue;
|
||||
const [e1, e2] = list;
|
||||
const t1 = e1 >> 1;
|
||||
const t2 = e2 >> 1;
|
||||
if (t1 === t2) continue;
|
||||
// Gleiche Durchlaufrichtung = Widerspruch ⇒ eines muss gedreht werden.
|
||||
const parity = (e1 & 1) === (e2 & 1) ? 1 : 0;
|
||||
adj[t1].push(t2 * 2 + parity);
|
||||
adj[t2].push(t1 * 2 + parity);
|
||||
}
|
||||
const flip = new Array<number>(nTri).fill(-1);
|
||||
const out = idx.slice();
|
||||
for (let s = 0; s < nTri; s++) {
|
||||
if (flip[s] >= 0) continue;
|
||||
const comp: number[] = [s];
|
||||
flip[s] = 0;
|
||||
for (let h = 0; h < comp.length; h++) {
|
||||
const t = comp[h];
|
||||
for (const e of adj[t]) {
|
||||
const u = e >> 1;
|
||||
if (flip[u] < 0) {
|
||||
flip[u] = flip[t] ^ (e & 1);
|
||||
comp.push(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Volumen der Komponente mit den bisherigen Drehungen; Offenheit: Kante mit nur einem Dreieck.
|
||||
let vol = 0;
|
||||
for (const t of comp) {
|
||||
const [a, b, c] = flip[t] ? [idx[3 * t], idx[3 * t + 2], idx[3 * t + 1]] : [idx[3 * t], idx[3 * t + 1], idx[3 * t + 2]];
|
||||
const A = a * 3;
|
||||
const B = b * 3;
|
||||
const C = c * 3;
|
||||
vol +=
|
||||
pos[A] * (pos[B + 1] * pos[C + 2] - pos[B + 2] * pos[C + 1]) -
|
||||
pos[A + 1] * (pos[B] * pos[C + 2] - pos[B + 2] * pos[C]) +
|
||||
pos[A + 2] * (pos[B] * pos[C + 1] - pos[B + 1] * pos[C]);
|
||||
}
|
||||
const turn = vol < 0 ? 1 : 0;
|
||||
for (const t of comp) {
|
||||
if (flip[t] ^ turn) {
|
||||
out[3 * t + 1] = idx[3 * t + 2];
|
||||
out[3 * t + 2] = idx[3 * t + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Testhilfe: liest die Mesh-Szene des Kerns (`meshExportData`, Kodierung `mesh_export.rs`) — z. B. das
|
||||
// öffnungsgenaue Wand-Volumen je Wand als Vergleichswert für IFC-Export und -Import.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
import { decodeExportFlat } from "./exportIfc";
|
||||
|
||||
export interface SceneGroup {
|
||||
name: string;
|
||||
kind: string;
|
||||
id: string;
|
||||
prims: { positions: Float64Array; indices: Float64Array }[];
|
||||
}
|
||||
|
||||
/** Knoten der Mesh-Szene (Welt x, Höhe, y; Wicklung nach aussen im Modell). */
|
||||
export function meshSceneGroups(project: Project): SceneGroup[] {
|
||||
const [b, text] = decodeExportFlat(documentFor(project).queryBin("meshExportData", [1, 1, 0]));
|
||||
const s = text.split("\0");
|
||||
let i = 2;
|
||||
i += 1 + b[i] * 7;
|
||||
i += 1 + b[i] * 2;
|
||||
const n = b[i++];
|
||||
const out: SceneGroup[] = [];
|
||||
for (let g = 0; g < n; g++) {
|
||||
const group: SceneGroup = { name: s[b[i]], kind: s[b[i + 1]], id: s[b[i + 2]], prims: [] };
|
||||
const np = b[i + 4];
|
||||
i += 5;
|
||||
for (let k = 0; k < np; k++) {
|
||||
const nv = b[i + 1];
|
||||
const positions = b.subarray(i + 2, i + 2 + nv * 3);
|
||||
i += 2 + nv * 3;
|
||||
const nt = b[i];
|
||||
const indices = b.subarray(i + 1, i + 1 + nt * 3);
|
||||
i += 1 + nt * 3;
|
||||
group.prims.push({ positions, indices });
|
||||
}
|
||||
out.push(group);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Volumen je Wand (Summe der Beträge je Schicht-Band, Öffnungen samt Laibungen ausgestanzt). */
|
||||
export function wallMeshVolumes(project: Project): Map<string, number> {
|
||||
const out = new Map<string, number>();
|
||||
for (const g of meshSceneGroups(project)) {
|
||||
if (g.kind !== "wall") continue;
|
||||
let sum = 0;
|
||||
for (const { positions: p, indices: x } of g.prims) {
|
||||
let v6 = 0;
|
||||
for (let t = 0; t + 2 < x.length; t += 3) {
|
||||
const [a, b, c] = [x[t] * 3, x[t + 1] * 3, x[t + 2] * 3];
|
||||
v6 += p[a] * (p[b + 1] * p[c + 2] - p[b + 2] * p[c + 1]) + p[a + 1] * (p[b + 2] * p[c] - p[b] * p[c + 2]) + p[a + 2] * (p[b] * p[c + 1] - p[b + 1] * p[c]);
|
||||
}
|
||||
sum += Math.abs(v6) / 6;
|
||||
}
|
||||
out.set(g.id, sum);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
// 3D-Teile einzelner Bauteile für die Exporte (OBJ/STL/glTF, IFC): dieselben Ableitungen wie das 3D,
|
||||
// gerechnet im Kern auf dem Projekt-Dokument (`queries.rs`, [K4]). Die Exporte rufen sie je Bauteil
|
||||
// mit einem Ein-Bauteil-Projekt auf (die Ableitungen liefern keine ids); damit das gemeinsame
|
||||
// Dokument der App nicht bei jedem Aufruf umgebaut wird, bekommt jeder Aufruf ein eigenes, kurzlebiges
|
||||
// Dokument.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import type { RMesh, RSlab } from "../plan/toWalls3d/shared";
|
||||
import { ProjectDocument, type QueryName } from "../core/document";
|
||||
|
||||
const DETAIL_CODE: Record<string, number> = { grob: 0, mittel: 1, fein: 2 };
|
||||
|
||||
function queryOnce<T>(project: Project, name: QueryName, args: number[] = [], text = ""): T {
|
||||
const doc = new ProjectDocument(project);
|
||||
try {
|
||||
return doc.query<T>(name, args, text);
|
||||
} finally {
|
||||
doc.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** Dach-Meshes (geschlossene Schicht-Körper je Dach). */
|
||||
export function emitRoofs(project: Project): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "roofMeshes");
|
||||
}
|
||||
|
||||
/** Stützen als Profil-Extrusionen. */
|
||||
export function emitColumns(project: Project): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "columnMeshes");
|
||||
}
|
||||
|
||||
/** Öffnungs-Einbauteile (Rahmen, Glas, Blatt) im Detailgrad `detail`. */
|
||||
export function emitOpeningMeshes(project: Project, detail: "grob" | "mittel" | "fein" = "fein"): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "openingMeshes", [DETAIL_CODE[detail] ?? 2]);
|
||||
}
|
||||
|
||||
/** Treppentritte (und Podeste) als extrudierte Platten; `forSection` wie im Schnitt. */
|
||||
export function emitStairs(project: Project, forSection = false): RSlab[] {
|
||||
return queryOnce<RSlab[]>(project, "stairSlabs", [forSection ? 1 : 0]);
|
||||
}
|
||||
|
||||
/** Glatte Ortbeton-Laufplatten. */
|
||||
export function emitStairMeshes(project: Project): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "stairMeshes");
|
||||
}
|
||||
|
||||
/** Handläufe und Pfosten. */
|
||||
export function emitStairRailings(project: Project): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "stairRailings");
|
||||
}
|
||||
Reference in new issue
Block a user