Merge rust-core-k4 (Laptop): [K1][K3a][K3c][K3d][K4] Kern-Port; IFC-/Mesh-Export bleibt in fileio (Kern-Duplikate entfernt), Exporte holen 3D-Teile aus dem Dokument
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
111 files changed
+14145
-6506
No files matched your search
@@ -6,14 +6,14 @@
|
||||
// • Ausnützungs-/Überbauungsziffer nur mit `project.parcelArea` oder der Parzellengrenze (`siteRules`).
|
||||
// • Raumprogramm (`project.roomProgram`, Soll) gegen die gezeichneten Räume.
|
||||
// Exakt für Prismen/Kegelstümpfe/Kreise, Näherung sonst (Fasen/Rundungen). Raumflächen je
|
||||
// Geschoss und Kategorie, Volumen und Parzellenfläche rechnet der Rust-Kern
|
||||
// (`src-tauri/core/src/kennzahlen.rs`); die Zusammenfassung nach SIA 416 (NF/NGF/GF) bleibt bei
|
||||
// `geometry/roomArea.ts::balance`, die auch Raumstempel, Bilanz, Raumliste und IFC nutzen.
|
||||
// Geschoss und Kategorie, Volumen, Parzellenfläche und die SIA-416-Zusammenfassung rechnet der
|
||||
// Rust-Kern auf dem Projekt-Dokument (`src-tauri/core/src/kennzahlen.rs`).
|
||||
|
||||
import type { ExtrudedSolid, Project } from "../model/types";
|
||||
import { SIA_CATEGORIES, balance, polygonArea } from "../geometry/roomArea";
|
||||
import { polygonArea } from "../geometry/roomArea";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { FlatWriter } from "../geometry/coreFlat";
|
||||
import { documentFor } from "../core/document";
|
||||
|
||||
export interface LevelKennzahlen {
|
||||
levelId: string;
|
||||
@@ -46,56 +46,12 @@ export function solidVolume(s: ExtrudedSolid): number {
|
||||
|
||||
const finite = (n: number): number => (Number.isFinite(n) ? n : 0);
|
||||
|
||||
/** Körper flach (`web/kennzahlen.rs`). */
|
||||
function encodeSolids(solids: ExtrudedSolid[]): Float64Array {
|
||||
const w = new FlatWriter().num(solids.length);
|
||||
for (const s of solids) {
|
||||
w.num(s.operation === "subtract" ? 1 : 0, s.circle ? s.circle.r : Number.NaN, s.height, s.taper ?? 0).ring(s.circle ? [] : s.points);
|
||||
}
|
||||
return w.done();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flächen je Geschoss (SIA 416), Gebäudevolumen, Ausnützungs- und Überbauungsziffer. Rechnet der
|
||||
* Kern auf dem Projekt-Dokument (`kennzahlen.rs`, [K4] S2).
|
||||
*/
|
||||
export function computeKennzahlen(project: Project): Kennzahlen {
|
||||
const floors = project.drawingLevels
|
||||
.filter((l) => l.kind === "floor")
|
||||
.slice()
|
||||
.sort((a, b) => (a.baseElevation ?? 0) - (b.baseElevation ?? 0));
|
||||
const levelIndex = new Map<string, number>();
|
||||
floors.forEach((l, i) => levelIndex.has(l.id) || levelIndex.set(l.id, i));
|
||||
const rooms = (project.rooms ?? []).filter((r) => levelIndex.has(r.floorId));
|
||||
const rw = new FlatWriter().num(rooms.length);
|
||||
for (const r of rooms) {
|
||||
const k = SIA_CATEGORIES.indexOf(r.siaCategory);
|
||||
// Unbekannte Kategorie → Index ausserhalb, zählt im Kern nicht.
|
||||
rw.num(levelIndex.get(r.floorId)!, k < 0 ? SIA_CATEGORIES.length : k).ring(r.boundary);
|
||||
}
|
||||
const parcelRing = project.siteRules?.parcel ?? [];
|
||||
const sums = core().kz_area_sums(
|
||||
floors.length,
|
||||
rw.done(),
|
||||
encodeSolids(project.extrudedSolids ?? []),
|
||||
project.parcelArea ?? Number.NaN,
|
||||
new FlatWriter().pts(Array.isArray(parcelRing) ? parcelRing : []).done(),
|
||||
);
|
||||
const gv = sums[0];
|
||||
const parcel = Number.isNaN(sums[1]) ? null : sums[1];
|
||||
const levels: LevelKennzahlen[] = floors.map((l, i) => {
|
||||
// Kategorie-Summen als Einträge der SIA-416-Bilanz → GF und NGF.
|
||||
const b = balance(SIA_CATEGORIES.map((category, k) => ({ category, area: sums[2 + i * SIA_CATEGORIES.length + k] })));
|
||||
return { levelId: l.id, name: l.name, gf: b.byKey.GF, agf: b.byKey.NGF, rooms: rooms.filter((r) => r.floorId === l.id).length };
|
||||
});
|
||||
const gf = levels.reduce((s, l) => s + l.gf, 0);
|
||||
const agf = levels.reduce((s, l) => s + l.agf, 0);
|
||||
const footprint = levels.find((l) => l.gf > 0)?.gf ?? 0;
|
||||
return {
|
||||
levels,
|
||||
gf,
|
||||
agf,
|
||||
gv,
|
||||
footprint,
|
||||
az: parcel ? agf / parcel : null,
|
||||
uez: parcel ? footprint / parcel : null,
|
||||
};
|
||||
return documentFor(project).query<Kennzahlen>("kennzahlen");
|
||||
}
|
||||
|
||||
export type ProgramStatus = "ok" | "zu klein" | "zu gross" | "fehlt" | "zu wenige" | "zu viele";
|
||||
|
||||
@@ -6,15 +6,12 @@
|
||||
// • Baulinie: Halbebene auf der Seite des Parzellen-Schwerpunkts.
|
||||
// • Gebäude-Grundfläche: Wände aller Geschosse und freie Körper (ohne Abzugskörper). Vorsprünge
|
||||
// (Dachüberstand, Balkone) und ihre Sonderregeln zählen nicht.
|
||||
// Gerechnet wird im Rust-Kern (`src-tauri/core/src/site_rules.rs`); hier wird aus dem Projekt
|
||||
// gesammelt (Grundflächen-Teile, Modellhöhe) und die Datenform übersetzt.
|
||||
// Gerechnet wird im Rust-Kern (`src-tauri/core/src/site_rules.rs`), die Prüfung des Modells auf dem
|
||||
// Projekt-Dokument; die Flächen-Hilfen (`allowedArea`, `multiPolygonArea`) nehmen flache Daten.
|
||||
|
||||
import type { Project, SiteRules, Vec2 } from "../model/types";
|
||||
import { getFloor, getWallType, wallTypeThickness } from "../model/types";
|
||||
import { wallVerticalExtent } from "../model/wall";
|
||||
import { wallCorners } from "../model/geometry";
|
||||
import { roofBaseElevation, roofGeometry } from "../geometry/roof";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { documentFor } from "../core/document";
|
||||
import { FlatReader, FlatWriter } from "../geometry/coreFlat";
|
||||
|
||||
/** Polygone mit Ringen: `[polygon][ring]`, Ring 0 aussen, weitere Löcher; Ringe offen. */
|
||||
@@ -41,46 +38,14 @@ export function allowedArea(r: SiteRules): Area {
|
||||
return new FlatReader(core().site_allowed_area(encodeRules(r))).polygons();
|
||||
}
|
||||
|
||||
/** Teile der Gebäude-Grundfläche (Wände aller Geschosse, freie Körper ohne Abzugskörper). */
|
||||
function footprintParts(project: Project): Area {
|
||||
const parts: Area = [];
|
||||
for (const w of project.walls) {
|
||||
if (Math.hypot(w.end.x - w.start.x, w.end.y - w.start.y) < 1e-9) continue;
|
||||
parts.push([wallCorners(w.start, w.end, wallTypeThickness(getWallType(project, w)))]);
|
||||
}
|
||||
for (const s of project.extrudedSolids ?? []) {
|
||||
if (s.operation === "subtract" || s.points.length < 3) continue;
|
||||
parts.push([s.points]);
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
/** Grundfläche des Gebäudes (Wände aller Geschosse, freie Körper ohne Abzugskörper). */
|
||||
/** Grundfläche des Gebäudes (Wände aller Geschosse, freie Körper ohne Abzugskörper). Rechnet der Kern. */
|
||||
export function buildingFootprint(project: Project): Area {
|
||||
const parts = footprintParts(project);
|
||||
if (parts.length === 0) return [];
|
||||
return new FlatReader(core().poly_union(new FlatWriter().polygons(parts).done())).polygons();
|
||||
return documentFor(project).query<Area>("buildingFootprint");
|
||||
}
|
||||
|
||||
/** Höchster Punkt des Modells über ±0.00 (Wände, freie Körper, Dächer); `null` ohne Bauteile. */
|
||||
export function modelTop(project: Project): number | null {
|
||||
let top = -Infinity;
|
||||
for (const w of project.walls) top = Math.max(top, wallVerticalExtent(project, w).zTop);
|
||||
for (const s of project.extrudedSolids ?? []) {
|
||||
if (s.operation === "subtract") continue;
|
||||
let base = 0;
|
||||
try {
|
||||
base = getFloor(project, s.levelId).baseElevation ?? 0;
|
||||
} catch {
|
||||
/* Geschoss fehlt → 0 */
|
||||
}
|
||||
top = Math.max(top, base + (s.baseOffset ?? 0) + s.height);
|
||||
}
|
||||
for (const r of project.roofs ?? []) {
|
||||
const eavesZ = roofBaseElevation(project, r);
|
||||
top = Math.max(top, eavesZ + roofGeometry(r, eavesZ).ridgeHeight);
|
||||
}
|
||||
return Number.isFinite(top) ? top : null;
|
||||
return documentFor(project).query<number | null>("modelTop");
|
||||
}
|
||||
|
||||
export interface SiteCheck {
|
||||
@@ -96,22 +61,6 @@ export interface SiteCheck {
|
||||
|
||||
/** Prüft das Modell gegen `project.siteRules`; `null` ohne (gültiges) Baurecht. Rechnung im Rust-Kern (`site_rules.rs`). */
|
||||
export function checkSiteRules(project: Project): SiteCheck | null {
|
||||
const r = project.siteRules;
|
||||
if (!r) return null;
|
||||
const maxTop = modelTop(project);
|
||||
const out = core().site_check(
|
||||
encodeRules(r),
|
||||
new FlatWriter().polygons(footprintParts(project)).done(),
|
||||
r.maxHeight ?? Number.NaN,
|
||||
maxTop ?? Number.NaN,
|
||||
);
|
||||
const rd = new FlatReader(out);
|
||||
if (rd.num() !== 1) return null;
|
||||
const parcelArea = rd.num();
|
||||
const allowedA = rd.num();
|
||||
const violationArea = rd.num();
|
||||
const heightExceeded = rd.num() === 1;
|
||||
const allowed = rd.polygons();
|
||||
const violations = rd.polygons();
|
||||
return { parcelArea, allowed, allowedArea: allowedA, violations, violationArea, maxTop, heightExceeded };
|
||||
if (!project.siteRules) return null;
|
||||
return documentFor(project).query<SiteCheck | null>("siteCheck");
|
||||
}
|
||||
+5
-61
@@ -5,16 +5,13 @@
|
||||
// • `shadowOfPrism`/`shadowPolygons`: Boden-Schatten (z = 0) von Wänden, freien Körpern und
|
||||
// Dächern als Vereinigung konvexer Hüllen (Prisma ∪ verschobenes Prisma). Modell: x = Ost,
|
||||
// y = Nord, Höhen über dem Geländenullpunkt (Meter).
|
||||
// Gerechnet wird im Rust-Kern (`src-tauri/core/src/sun.rs`); hier wird nur aus dem Projekt
|
||||
// gesammelt und die Datenform übersetzt.
|
||||
// Gerechnet wird im Rust-Kern (`src-tauri/core/src/sun.rs`), die Schatten auf dem Projekt-Dokument.
|
||||
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { FlatReader, FlatWriter, pointsOf } from "../geometry/coreFlat";
|
||||
import type { Project, Vec2 } from "../model/types";
|
||||
import { wallVerticalExtent } from "../model/wall";
|
||||
import { roofBaseElevation, roofGeometry } from "../geometry/roof";
|
||||
import { lv95ToWgs84 } from "../io/lv95";
|
||||
import { getFloor, getWallType, wallTypeThickness } from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
|
||||
export interface SunPosition {
|
||||
/** Grad von Nord im Uhrzeigersinn (Ost = 90, Süd = 180). */
|
||||
@@ -47,64 +44,11 @@ export function shadowOfPrism(footprint: Vec2[], zBottom: number, zTop: number,
|
||||
export type ShadowPolygon = Vec2[][];
|
||||
|
||||
/**
|
||||
* Vereinigter Schatten aller Wände, Körper und Dächer (leer bei Nacht). Hier werden nur die
|
||||
* Körper gesammelt — Wände und freie Körper als Prismen, Dächer als Punktwolke (Traufe auf
|
||||
* Traufhöhe, Traufe/First/Grate auf Firsthöhe); Schatten und Vereinigung rechnet der Rust-Kern.
|
||||
* Vereinigter Schatten aller Wände, Körper und Dächer (leer bei Nacht). Rechnet der Kern auf dem
|
||||
* Projekt-Dokument (`sun.rs`): Wände und freie Körper als Prismen, Dächer als Punktwolke.
|
||||
*/
|
||||
export function shadowPolygons(project: Project, sun: SunPosition): ShadowPolygon[] {
|
||||
const prisms = new FlatWriter();
|
||||
const prismCount = prisms.slot();
|
||||
let nPrisms = 0;
|
||||
for (const w of project.walls) {
|
||||
const { zBottom, zTop } = wallVerticalExtent(project, w);
|
||||
const dx = w.end.x - w.start.x;
|
||||
const dy = w.end.y - w.start.y;
|
||||
const len = Math.hypot(dx, dy);
|
||||
if (len < 1e-9) continue;
|
||||
const t = wallTypeThickness(getWallType(project, w)) / 2;
|
||||
const nx = (-dy / len) * t;
|
||||
const ny = (dx / len) * t;
|
||||
prisms.num(zBottom, zTop).ring([
|
||||
{ x: w.start.x + nx, y: w.start.y + ny },
|
||||
{ x: w.end.x + nx, y: w.end.y + ny },
|
||||
{ x: w.end.x - nx, y: w.end.y - ny },
|
||||
{ x: w.start.x - nx, y: w.start.y - ny },
|
||||
]);
|
||||
nPrisms++;
|
||||
}
|
||||
for (const s of project.extrudedSolids ?? []) {
|
||||
if (s.operation === "subtract") continue;
|
||||
let base = 0;
|
||||
try {
|
||||
base = getFloor(project, s.levelId).baseElevation ?? 0;
|
||||
} catch {
|
||||
/* Geschoss fehlt → 0 */
|
||||
}
|
||||
const z0 = base + (s.baseOffset ?? 0);
|
||||
prisms.num(z0, z0 + s.height).ring(s.points);
|
||||
nPrisms++;
|
||||
}
|
||||
const clouds = new FlatWriter();
|
||||
const cloudCount = clouds.slot();
|
||||
let nClouds = 0;
|
||||
for (const r of project.roofs ?? []) {
|
||||
const eavesZ = roofBaseElevation(project, r);
|
||||
const geo = roofGeometry(r, eavesZ);
|
||||
const top = eavesZ + geo.ridgeHeight;
|
||||
const pts: number[] = [];
|
||||
for (const p of geo.eaves) pts.push(p.x, p.y, eavesZ, p.x, p.y, top);
|
||||
for (const [a, b] of geo.ridges) pts.push(a.x, a.y, top, b.x, b.y, top);
|
||||
for (const [, b] of geo.hips) pts.push(b.x, b.y, top);
|
||||
clouds.num(pts.length / 3, ...pts);
|
||||
nClouds++;
|
||||
}
|
||||
const out = core().sun_shadow_union(
|
||||
prisms.set(prismCount, nPrisms).done(),
|
||||
clouds.set(cloudCount, nClouds).done(),
|
||||
sun.azimuth,
|
||||
sun.elevation,
|
||||
);
|
||||
return new FlatReader(out).polygons();
|
||||
return documentFor(project).query<ShadowPolygon[]>("shadows", [sun.azimuth, sun.elevation]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ProjectDocument } from "./document";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Project } from "../model/types";
|
||||
|
||||
const plain = (p: Project): unknown => JSON.parse(JSON.stringify(p));
|
||||
|
||||
function mutate(p: Project, seed: number): Project {
|
||||
let x = seed;
|
||||
const rnd = () => ((x = (x * 1664525 + 1013904223) % 4294967296) / 4294967296);
|
||||
let out = { ...p };
|
||||
const walls = [...out.walls];
|
||||
if (rnd() < 0.5 && walls.length) walls.splice(Math.floor(rnd() * walls.length), 1);
|
||||
if (rnd() < 0.7 && walls.length) {
|
||||
const i = Math.floor(rnd() * walls.length);
|
||||
walls[i] = { ...walls[i], height: (walls[i].height ?? 2.6) + rnd() };
|
||||
}
|
||||
if (rnd() < 0.6) walls.splice(Math.floor(rnd() * (walls.length + 1)), 0, { ...p.walls[0], id: `new-${seed}-a` }, { ...p.walls[0], id: `new-${seed}-b` });
|
||||
if (rnd() < 0.4) walls.reverse();
|
||||
out = { ...out, walls };
|
||||
if (rnd() < 0.5) out = { ...out, name: `n${seed}` };
|
||||
if (rnd() < 0.3) out = { ...out, referenceElevationMasl: rnd() * 500 };
|
||||
if (rnd() < 0.3) out = { ...out, geoAnchor: undefined };
|
||||
if (rnd() < 0.5) out = { ...out, drawings2d: [] };
|
||||
return out;
|
||||
}
|
||||
|
||||
describe("ProjectDocument (Kern-Spiegel)", () => {
|
||||
it("öffnet das Projekt unverändert", () => {
|
||||
const d = new ProjectDocument(sampleProject);
|
||||
expect(JSON.parse(d.json())).toEqual(plain(sampleProject));
|
||||
d.close();
|
||||
});
|
||||
|
||||
it("folgt beliebigen Änderungen über Ops", () => {
|
||||
const d = new ProjectDocument(sampleProject);
|
||||
let cur = sampleProject;
|
||||
for (let seed = 1; seed <= 300; seed++) {
|
||||
cur = mutate(cur, seed);
|
||||
d.sync(cur);
|
||||
const got = JSON.parse(d.json()) as Record<string, unknown>;
|
||||
const want = plain(cur) as Record<string, unknown>;
|
||||
const bad = [...new Set([...Object.keys(got), ...Object.keys(want)])].filter((k) => JSON.stringify(got[k]) !== JSON.stringify(want[k]));
|
||||
expect(bad, `seed ${seed}`).toEqual([]);
|
||||
}
|
||||
d.close();
|
||||
});
|
||||
|
||||
it("heilt sich bei doppelten ids (Neuöffnen)", () => {
|
||||
const d = new ProjectDocument(sampleProject);
|
||||
const dup = { ...sampleProject, walls: [...sampleProject.walls, sampleProject.walls[0]] };
|
||||
d.sync(dup);
|
||||
expect(JSON.parse(d.json())).toEqual(plain(dup));
|
||||
d.close();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,119 @@
|
||||
// Projekt-Dokument im Rust-Kern ([K4], Stufe S1): spiegelt das TS-Projekt über Ops nach Rust
|
||||
// (`document.rs`). TS bleibt vorerst Quelle der Änderungen (`setProject` → `diffToOps`); Rust hält
|
||||
// den Stand, auf dem die Ableitungen später direkt rechnen, ohne dass TS das Projekt je Aufruf
|
||||
// flach neu sammeln muss. Bei jedem Widerspruch (abgelehnte Ops, Fehler) wird das Dokument aus dem
|
||||
// vollen Projekt neu geöffnet — der Spiegel heilt sich selbst.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { diffToOps } from "./ops";
|
||||
|
||||
/** Abfragen des Kerns (`queries.rs`). */
|
||||
export type QueryName =
|
||||
| "kennzahlen"
|
||||
| "siteCheck"
|
||||
| "buildingFootprint"
|
||||
| "modelTop"
|
||||
| "shadows"
|
||||
| "materialMaps"
|
||||
| "slabs"
|
||||
| "columnMeshes"
|
||||
| "walls"
|
||||
| "openingMeshes"
|
||||
| "stairSlabs"
|
||||
| "stairMeshes"
|
||||
| "stairRailings"
|
||||
| "roofMeshes"
|
||||
| "roofCutLayers"
|
||||
| "scheduleRows"
|
||||
| "scheduleCsv"
|
||||
| "pickGeometry"
|
||||
| "model3dParts";
|
||||
|
||||
export class ProjectDocument {
|
||||
private handle = 0;
|
||||
private mirror: Project;
|
||||
|
||||
constructor(project: Project) {
|
||||
this.mirror = project;
|
||||
this.reopen(project);
|
||||
}
|
||||
|
||||
/** Handle im Kern (0 = nicht offen). */
|
||||
get id(): number {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
private reopen(project: Project): void {
|
||||
if (this.handle) core().doc_close(this.handle);
|
||||
this.handle = core().doc_open(JSON.stringify(project));
|
||||
if (!this.handle) console.warn("Projekt-Dokument im Kern konnte nicht geöffnet werden.");
|
||||
}
|
||||
|
||||
/** Bringt das Dokument auf den Stand `next` (über die Differenz als Ops). */
|
||||
sync(next: Project): void {
|
||||
if (next === this.mirror) return;
|
||||
const ops = diffToOps(this.mirror, next);
|
||||
this.mirror = next;
|
||||
if (ops.length === 0) return;
|
||||
if (!this.handle) {
|
||||
this.reopen(next);
|
||||
return;
|
||||
}
|
||||
const problems = core().doc_apply(this.handle, JSON.stringify(ops));
|
||||
if (problems) {
|
||||
console.warn("Kern-Dokument weicht ab, wird neu geöffnet:", problems);
|
||||
this.reopen(next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abfrage auf dem typisierten Projekt im Kern (`queries.rs`); `args` Zahlen, `text` ein Text
|
||||
* (z. B. eine id). Das Ergebnis ist JSON; Fehler im Kern (Projekt passt nicht zum Modell,
|
||||
* Rechenfehler) werfen mit der Meldung des Kerns.
|
||||
*/
|
||||
query<T>(name: QueryName, args: number[] = [], text = ""): T {
|
||||
return JSON.parse(this.queryJson(name, args, text)) as T;
|
||||
}
|
||||
|
||||
/** Wie {@link query}, aber das JSON als Text (spart das Parsen, wenn es nur weitergereicht wird). */
|
||||
queryJson(name: QueryName, args: number[] = [], text = ""): string {
|
||||
if (!this.handle) throw new Error(`Kern-Abfrage „${name}": Dokument nicht offen`);
|
||||
const out = core().doc_query_args(this.handle, name, Float64Array.from(args), text);
|
||||
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Datei-Text des Projekts (Formatversion vorn, Einrückung 2). */
|
||||
serialize(): string {
|
||||
return this.handle ? core().doc_serialize(this.handle) : "";
|
||||
}
|
||||
|
||||
/** Boden-Spuren der 2D-Zeichnungen als LineList-Vertices `[px, py, pz, r, g, b]`. */
|
||||
drawingLineVerts(): Float32Array {
|
||||
return this.handle ? core().doc_drawing_line_verts(this.handle) : new Float32Array(0);
|
||||
}
|
||||
|
||||
/** Das Dokument als JSON-Text (Test, Export). */
|
||||
json(): string {
|
||||
return this.handle ? core().doc_json(this.handle) : "";
|
||||
}
|
||||
|
||||
close(): void {
|
||||
if (this.handle) core().doc_close(this.handle);
|
||||
this.handle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
let shared: ProjectDocument | null = null;
|
||||
|
||||
/**
|
||||
* Das gemeinsame Kern-Dokument, auf den Stand von `project` gebracht. Der Abgleich läuft über die
|
||||
* Differenz zum zuletzt gesehenen Projekt (Referenzvergleich, unveränderte Teile kosten nichts);
|
||||
* wechselt ein Aufrufer zwischen sehr verschiedenen Projekten, ist es nur langsamer, nie falsch.
|
||||
*/
|
||||
export function documentFor(project: Project): ProjectDocument {
|
||||
if (!shared) shared = new ProjectDocument(project);
|
||||
else shared.sync(project);
|
||||
return shared;
|
||||
}
|
||||
@@ -109,7 +109,6 @@ import { isWatertight, wallCutMeshes, type CutMesh } from "../plan/wallMeshCut";
|
||||
import { evaluateRoom } from "../geometry/roomArea";
|
||||
import { columnFootprint } from "../geometry/column";
|
||||
import { openingInterval, openingVerticalExtent } from "../geometry/opening";
|
||||
import { emitRoofs } from "../plan/toWalls3d/roofs";
|
||||
import { fileio } from "../engine/fileioWasm";
|
||||
import { lv95ToWgs84 } from "../io/lv95";
|
||||
import { fillParams, type FillParams } from "./ifcOpenings";
|
||||
@@ -126,6 +125,7 @@ import {
|
||||
} from "./ifcQuantities";
|
||||
import { roofBaseElevation, roofGeometry } from "../geometry/roof";
|
||||
import { SIA_CATEGORIES, balance, siaLabel, type SiaCategory } from "../geometry/roomArea";
|
||||
import { emitRoofs } from "./model3dParts";
|
||||
import {
|
||||
EBKPH_SYSTEM,
|
||||
LAYER_SYSTEM,
|
||||
|
||||
@@ -7,10 +7,7 @@ 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 { emitOpeningMeshes } from "../plan/toWalls3d/openings";
|
||||
import { emitRoofs } from "../plan/toWalls3d/roofs";
|
||||
import { emitColumns } from "../plan/toWalls3d/columns";
|
||||
import { emitStairMeshes, emitStairRailings, emitStairs } from "../plan/toWalls3d/stairs";
|
||||
import { emitColumns, emitOpeningMeshes, emitRoofs, emitStairMeshes, emitStairRailings, emitStairs } from "./model3dParts";
|
||||
|
||||
interface Gltf {
|
||||
nodes: { name: string; mesh?: number; children?: number[]; extras?: { type: string; id: string } }[];
|
||||
|
||||
@@ -49,14 +49,11 @@ 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 { emitOpeningMeshes } from "../plan/toWalls3d/openings";
|
||||
import { emitRoofs } from "../plan/toWalls3d/roofs";
|
||||
import { emitColumns } from "../plan/toWalls3d/columns";
|
||||
import { emitStairMeshes, emitStairRailings, emitStairs } from "../plan/toWalls3d/stairs";
|
||||
import type { RMesh } from "../plan/toWalls3d/shared";
|
||||
import { IMPORTED_RGB, TERRAIN_RGB, hexToRgb } from "../plan/toWalls3d/shared";
|
||||
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
|
||||
|
||||
+16
-311
@@ -1,60 +1,12 @@
|
||||
// Bauteil-Schedule (Bauteilliste) — CSV-Export einer Bauteilaufstellung des
|
||||
// Projekts (AUDIT A6, DOSSIER-Parität). Reiner Rechen-/Serialisierungskern:
|
||||
// keine UI, kein Datei-IO — nur Modell → CSV-String (unit-testbar). Der
|
||||
// Download (Blob + Anchor) passiert im App-Layer, analog zum Raum-CSV
|
||||
// (geometry/roomArea → roomsToCsv) und zum Projekt-JSON-Speichern.
|
||||
//
|
||||
// Granularität: EINE Zeile je Bauteil-VORKOMMEN (Wand, Decke, Tür, Fenster/
|
||||
// Öffnung, Treppe, Extrusion). Räume sind bewusst NICHT enthalten — die haben
|
||||
// ihren eigenen CSV-Export (geometry/roomArea → roomsToCsv), keine Duplikation.
|
||||
// Optional folgt darunter ein Aggregat-Block je Bauteil-Typ.
|
||||
// Bezeichner englisch, Labels/Kommentare deutsch (CONVENTIONS.md). Einheit: METER.
|
||||
// Bauteil-Schedule (Bauteilliste) — CSV-Export einer Bauteilaufstellung des Projekts
|
||||
// (AUDIT A6, DOSSIER-Parität). Gerechnet wird im Rust-Kern (`src-tauri/core/src/export_schedule.rs`,
|
||||
// [K4] S2) auf dem Projekt-Dokument: EINE Zeile je Bauteil-VORKOMMEN (Wand, Decke, Tür, Fenster,
|
||||
// Treppe, Extrusion, Dach, Stütze); Räume sind bewusst nicht enthalten (eigener CSV-Export in
|
||||
// `geometry/roomArea`). Optional folgt ein Aggregat-Block je Bauteil-Typ. Der Download
|
||||
// (Blob + Anchor) passiert im App-Layer. Einheit: METER.
|
||||
|
||||
import type {
|
||||
Project,
|
||||
Wall,
|
||||
Ceiling,
|
||||
Opening,
|
||||
Stair,
|
||||
ExtrudedSolid,
|
||||
Roof,
|
||||
Column,
|
||||
} from "../model/types";
|
||||
import {
|
||||
getWallType,
|
||||
getCeilingType,
|
||||
wallTypeThickness,
|
||||
ceilingThickness,
|
||||
} from "../model/types";
|
||||
import { polygonArea } from "../geometry/roomArea";
|
||||
|
||||
// ── CSV-Primitive (RFC 4180, gespiegelt vom Raum-CSV) ───────────────────────
|
||||
|
||||
/** Ein Feld CSV-sicher quoten: „..." bei , " \n \r ; → " wird verdoppelt. */
|
||||
function csvField(value: string): string {
|
||||
if (/[",\n\r;]/.test(value)) {
|
||||
return `"${value.replace(/"/g, '""')}"`;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/** Zahl auf 2 Nachkommastellen, Punkt als Dezimaltrenner. Leer bei null. */
|
||||
function fmtNum(value: number | null | undefined): string {
|
||||
if (value == null || !Number.isFinite(value)) return "";
|
||||
return (Math.round(value * 100) / 100).toFixed(2);
|
||||
}
|
||||
|
||||
// ── Kennwert-Ableitung (aus dem Modell, keine erfundenen Felder) ────────────
|
||||
|
||||
/** Achslänge einer Wand (Meter) = Abstand Start→End der Centerline. */
|
||||
function wallLength(wall: Wall): number {
|
||||
return Math.hypot(wall.end.x - wall.start.x, wall.end.y - wall.start.y);
|
||||
}
|
||||
|
||||
/** Anzeigename eines Geschosses (oder die roh-ID, wenn unbekannt). */
|
||||
function floorNameOf(project: Project, floorId: string): string {
|
||||
return project.drawingLevels.find((z) => z.id === floorId)?.name ?? floorId;
|
||||
}
|
||||
import type { Project } from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
|
||||
/** Bauteilklassen der Bauteilliste. */
|
||||
export type ScheduleKind =
|
||||
@@ -79,10 +31,8 @@ export interface ScheduleRow {
|
||||
/** Geschoss-Name. */
|
||||
floor: string;
|
||||
/**
|
||||
* Geschoss-ID (rohe DrawingLevel-Referenz, additiv für Konsumenten wie das
|
||||
* Elemente-Panel — NICHT Teil der CSV-Spalten, siehe exportScheduleCsv).
|
||||
* `undefined` bei verwaister/nicht auflösbarer Referenz (z. B. Tür/Öffnung
|
||||
* mit gelöschter Wirtswand).
|
||||
* Geschoss-ID (rohe DrawingLevel-Referenz, additiv für Konsumenten wie das Elemente-Panel — NICHT
|
||||
* Teil der CSV-Spalten). Fehlt bei verwaister Referenz (z. B. Öffnung mit gelöschter Wirtswand).
|
||||
*/
|
||||
floorId?: string;
|
||||
/** Achslänge bzw. lichte Breite in Metern (null wo nicht verlässlich ableitbar). */
|
||||
@@ -95,200 +45,14 @@ export interface ScheduleRow {
|
||||
area: number | null;
|
||||
}
|
||||
|
||||
/** Wertet eine Wand für die Bauteilliste aus (defensiv gegen fehlende Typen). */
|
||||
function evalWall(project: Project, wall: Wall): ScheduleRow {
|
||||
let typeName = wall.wallTypeId;
|
||||
let thickness = 0;
|
||||
try {
|
||||
const wt = getWallType(project, wall);
|
||||
typeName = wt.name;
|
||||
thickness = wallTypeThickness(wt);
|
||||
} catch {
|
||||
/* verwaister Wandtyp — Roh-ID + Dicke 0 */
|
||||
}
|
||||
const length = wallLength(wall);
|
||||
return {
|
||||
kind: "Wand",
|
||||
id: wall.id,
|
||||
typeName,
|
||||
floor: floorNameOf(project, wall.floorId),
|
||||
floorId: wall.floorId,
|
||||
length,
|
||||
heightM: wall.height,
|
||||
thickness,
|
||||
area: length * wall.height,
|
||||
};
|
||||
}
|
||||
|
||||
/** Wertet eine Decke für die Bauteilliste aus (defensiv gegen fehlende Typen). */
|
||||
function evalCeiling(project: Project, ceiling: Ceiling): ScheduleRow {
|
||||
let typeName = ceiling.ceilingTypeId ?? ceiling.wallTypeId;
|
||||
try {
|
||||
typeName = getCeilingType(project, ceiling).name;
|
||||
} catch {
|
||||
/* verwaister Deckentyp — Roh-ID */
|
||||
}
|
||||
return {
|
||||
kind: "Decke",
|
||||
id: ceiling.id,
|
||||
typeName,
|
||||
floor: floorNameOf(project, ceiling.floorId),
|
||||
floorId: ceiling.floorId,
|
||||
length: null,
|
||||
heightM: null,
|
||||
thickness: ceilingThickness(project, ceiling),
|
||||
area: polygonArea(ceiling.outline),
|
||||
};
|
||||
}
|
||||
|
||||
/** Geschoss eines wandgehosteten Elements (Tür/Öffnung) über die Wirtswand. */
|
||||
function floorOfHostWall(project: Project, hostWallId: string): string {
|
||||
const wall = project.walls.find((w) => w.id === hostWallId);
|
||||
if (!wall) return hostWallId; // verwaiste Wirtswand — Roh-ID, analog verwaister Typreferenzen
|
||||
return floorNameOf(project, wall.floorId);
|
||||
}
|
||||
|
||||
/** Rohe Geschoss-ID eines wandgehosteten Elements (Tür/Öffnung), oder `undefined` bei verwaister Wirtswand. */
|
||||
function floorIdOfHostWall(project: Project, hostWallId: string): string | undefined {
|
||||
return project.walls.find((w) => w.id === hostWallId)?.floorId;
|
||||
}
|
||||
|
||||
/** Wertet eine Öffnung (Fenster oder Tür-Öffnung) für die Bauteilliste aus. */
|
||||
function evalOpening(project: Project, opening: Opening): ScheduleRow {
|
||||
const kind = opening.kind === "window" ? "Fenster" : "Tür";
|
||||
return {
|
||||
kind,
|
||||
id: opening.id,
|
||||
typeName: kind,
|
||||
floor: floorOfHostWall(project, opening.hostWallId),
|
||||
floorId: floorIdOfHostWall(project, opening.hostWallId),
|
||||
length: opening.width,
|
||||
heightM: opening.height,
|
||||
thickness: null,
|
||||
area: opening.width * opening.height,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wertet eine Treppe für die Bauteilliste aus. Fläche bleibt bewusst leer —
|
||||
* eine echte Footprint-Fläche bräuchte stairGeometry() (geometry/stair.ts)
|
||||
* samt dessen Geschosshöhen-Fallback, den wir hier nicht koppeln wollen.
|
||||
*/
|
||||
function evalStair(project: Project, stair: Stair): ScheduleRow {
|
||||
return {
|
||||
kind: "Treppe",
|
||||
id: stair.id,
|
||||
typeName: "Treppe",
|
||||
floor: floorNameOf(project, stair.floorId),
|
||||
floorId: stair.floorId,
|
||||
length: stair.runLength + (stair.run2Length ?? 0),
|
||||
heightM: stair.totalRise ?? null,
|
||||
thickness: null,
|
||||
area: null,
|
||||
};
|
||||
}
|
||||
|
||||
/** Wertet einen extrudierten Körper für die Bauteilliste aus. */
|
||||
function evalExtrudedSolid(project: Project, solid: ExtrudedSolid): ScheduleRow {
|
||||
return {
|
||||
kind: "Extrusion",
|
||||
id: solid.id,
|
||||
typeName: "Extrusion",
|
||||
floor: floorNameOf(project, solid.levelId),
|
||||
floorId: solid.levelId,
|
||||
length: null,
|
||||
heightM: solid.height,
|
||||
thickness: null,
|
||||
area: polygonArea(solid.points),
|
||||
};
|
||||
}
|
||||
|
||||
/** Wertet ein Dach für die Bauteilliste aus (defensiv gegen fehlenden Dachtyp). */
|
||||
function evalRoof(project: Project, roof: Roof): ScheduleRow {
|
||||
let typeName = roof.roofTypeId ?? roof.shape;
|
||||
if (roof.roofTypeId) {
|
||||
const rt = (project.roofTypes ?? []).find((t) => t.id === roof.roofTypeId);
|
||||
if (rt) typeName = rt.name;
|
||||
}
|
||||
return {
|
||||
kind: "Dach",
|
||||
id: roof.id,
|
||||
typeName,
|
||||
floor: floorNameOf(project, roof.floorId),
|
||||
floorId: roof.floorId,
|
||||
length: null,
|
||||
heightM: null,
|
||||
thickness: roof.thickness,
|
||||
area: polygonArea(roof.outline),
|
||||
};
|
||||
}
|
||||
|
||||
/** Wertet eine Stütze für die Bauteilliste aus (Querschnitt als „Dicke", Rechteck-Breite als „Länge"). */
|
||||
function evalColumn(project: Project, column: Column): ScheduleRow {
|
||||
return {
|
||||
kind: "Stütze",
|
||||
id: column.id,
|
||||
typeName: column.profile.kind === "round" ? "Rund" : "Rechteck",
|
||||
floor: floorNameOf(project, column.floorId),
|
||||
floorId: column.floorId,
|
||||
length: column.profile.kind === "rect" ? column.profile.width : null,
|
||||
heightM: column.height,
|
||||
thickness:
|
||||
column.profile.kind === "rect" ? column.profile.depth : column.profile.radius * 2,
|
||||
area: null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wertet ALLE Bauteil-Vorkommen eines Projekts aus (Wände, Decken, Türen,
|
||||
* Fenster/Öffnungen, Treppen, Extrusionen, Dächer, Stützen — Räume bewusst
|
||||
* ausgenommen, siehe Dateikopf). Reine Ableitung aus dem Modell — nichts wird
|
||||
* gespeichert. Reihenfolge: Wände, Decken, Türen, Öffnungen, Treppen,
|
||||
* Wertet ALLE Bauteil-Vorkommen eines Projekts aus. Reihenfolge: Wände, Decken, Öffnungen, Treppen,
|
||||
* Extrusionen, Dächer, Stützen (je in Dokumentreihenfolge).
|
||||
*/
|
||||
export function scheduleRows(project: Project): ScheduleRow[] {
|
||||
const rows: ScheduleRow[] = [];
|
||||
for (const w of project.walls ?? []) rows.push(evalWall(project, w));
|
||||
for (const c of project.ceilings ?? []) rows.push(evalCeiling(project, c));
|
||||
for (const o of project.openings ?? []) rows.push(evalOpening(project, o));
|
||||
for (const s of project.stairs ?? []) rows.push(evalStair(project, s));
|
||||
for (const e of project.extrudedSolids ?? []) rows.push(evalExtrudedSolid(project, e));
|
||||
for (const r of project.roofs ?? []) rows.push(evalRoof(project, r));
|
||||
for (const c of project.columns ?? []) rows.push(evalColumn(project, c));
|
||||
return rows;
|
||||
return documentFor(project).query<ScheduleRow[]>("scheduleRows");
|
||||
}
|
||||
|
||||
// ── Aggregat je Bauteil-Typ ─────────────────────────────────────────────────
|
||||
|
||||
interface TypeAggregate {
|
||||
kind: ScheduleKind;
|
||||
typeName: string;
|
||||
count: number;
|
||||
/** Summe der Längen (Meter) — Bauteile ohne Länge tragen 0 bei. */
|
||||
totalLength: number;
|
||||
/** Summe der Flächen (m²) — Bauteile ohne Fläche tragen 0 bei. */
|
||||
totalArea: number;
|
||||
}
|
||||
|
||||
/** Rollt die Zeilen je (Klasse + Typname) zu Zwischensummen zusammen. */
|
||||
function aggregateByType(rows: ScheduleRow[]): TypeAggregate[] {
|
||||
const map = new Map<string, TypeAggregate>();
|
||||
for (const r of rows) {
|
||||
const key = `${r.kind} ${r.typeName}`;
|
||||
let agg = map.get(key);
|
||||
if (!agg) {
|
||||
agg = { kind: r.kind, typeName: r.typeName, count: 0, totalLength: 0, totalArea: 0 };
|
||||
map.set(key, agg);
|
||||
}
|
||||
agg.count += 1;
|
||||
agg.totalLength += r.length ?? 0;
|
||||
agg.totalArea += r.area ?? 0;
|
||||
}
|
||||
return [...map.values()];
|
||||
}
|
||||
|
||||
// ── CSV-Serialisierung ───────────────────────────────────────────────────────
|
||||
|
||||
export interface ScheduleCsvOptions {
|
||||
/** Feldtrenner. Default „;" (Excel-DE-freundlich, wie der Raum-CSV). */
|
||||
delimiter?: string;
|
||||
@@ -296,69 +60,10 @@ export interface ScheduleCsvOptions {
|
||||
includeSummary?: boolean;
|
||||
}
|
||||
|
||||
/** Spaltenüberschriften der Bauteilliste (fix Deutsch, wie der Raum-CSV). */
|
||||
const HEADER = [
|
||||
"Typ",
|
||||
"ID",
|
||||
"Bauteil",
|
||||
"Geschoss",
|
||||
"Länge [m]",
|
||||
"Höhe [m]",
|
||||
"Dicke [m]",
|
||||
"Fläche [m²]",
|
||||
];
|
||||
|
||||
/**
|
||||
* Baut die Bauteilliste des Projekts als CSV-String (kein Datei-IO). Eine Zeile
|
||||
* je Bauteil-Vorkommen mit den aus dem Modell verlässlich ableitbaren
|
||||
* Kennwerten; optional ein Aggregat-Block je Bauteil-Typ.
|
||||
*
|
||||
* Leeres Projekt ⇒ nur die Kopfzeile (kein Crash).
|
||||
* Baut die Bauteilliste des Projekts als CSV-String (kein Datei-IO). Leeres Projekt ⇒ nur die
|
||||
* Kopfzeile (kein Crash).
|
||||
*/
|
||||
export function exportScheduleCsv(
|
||||
project: Project,
|
||||
options: ScheduleCsvOptions = {},
|
||||
): string {
|
||||
const d = options.delimiter ?? ";";
|
||||
const includeSummary = options.includeSummary ?? true;
|
||||
const rows = scheduleRows(project);
|
||||
const lines: string[] = [];
|
||||
|
||||
lines.push(HEADER.map(csvField).join(d));
|
||||
|
||||
for (const r of rows) {
|
||||
lines.push(
|
||||
[
|
||||
csvField(r.kind),
|
||||
csvField(r.id),
|
||||
csvField(r.typeName),
|
||||
csvField(r.floor),
|
||||
fmtNum(r.length),
|
||||
fmtNum(r.heightM),
|
||||
fmtNum(r.thickness),
|
||||
fmtNum(r.area),
|
||||
].join(d),
|
||||
);
|
||||
}
|
||||
|
||||
if (includeSummary && rows.length > 0) {
|
||||
lines.push(""); // Leerzeile trennt Liste von Aggregat
|
||||
lines.push([csvField("Zusammenfassung (je Bauteil-Typ)"), "", "", "", "", "", "", ""].join(d));
|
||||
for (const agg of aggregateByType(rows)) {
|
||||
lines.push(
|
||||
[
|
||||
csvField(agg.kind),
|
||||
"",
|
||||
csvField(agg.typeName),
|
||||
csvField(`${agg.count} Stk`),
|
||||
agg.totalLength > 0 ? fmtNum(agg.totalLength) : "",
|
||||
"",
|
||||
"",
|
||||
agg.totalArea > 0 ? fmtNum(agg.totalArea) : "",
|
||||
].join(d),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return lines.join("\r\n");
|
||||
export function exportScheduleCsv(project: Project, options: ScheduleCsvOptions = {}): string {
|
||||
return documentFor(project).queryJson("scheduleCsv", [options.includeSummary ?? true ? 1 : 0], options.delimiter ?? ";");
|
||||
}
|
||||
@@ -13,10 +13,10 @@ import type { Project, Stair, Vec2 } from "../model/types";
|
||||
import { getStairType } from "../model/types";
|
||||
import { stairVerticalExtent } from "../model/wall";
|
||||
import { stairGeometry } from "../geometry/stair";
|
||||
import { emitStairMeshes, emitStairRailings, emitStairs } from "../plan/toWalls3d/stairs";
|
||||
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 {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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");
|
||||
}
|
||||
+24
-108
@@ -1,9 +1,26 @@
|
||||
// Geometrie-Helfer für Ellipse/Bezier/Spline — reine Sample-/Tessellierungs-
|
||||
// Funktionen, gemeinsam genutzt von den Zeichen-Werkzeugen (Vorschau), dem
|
||||
// Grundriss-Generator (finales Rendering als Linien-/Polygon-Primitive) und
|
||||
// dem Snapping (Kandidaten-Strecken).
|
||||
// dem Snapping (Kandidaten-Strecken). Fassade über den Rust-Kern
|
||||
// (`src-tauri/core/src/curves.rs`, Bindungen `web/curves.rs`): die Formeln stehen nur dort.
|
||||
|
||||
import type { Vec2 } from "../model/types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
|
||||
function toPoints(f: Float64Array): Vec2[] {
|
||||
const out: Vec2[] = new Array(f.length >> 1);
|
||||
for (let i = 0; i < out.length; i++) out[i] = { x: f[2 * i], y: f[2 * i + 1] };
|
||||
return out;
|
||||
}
|
||||
|
||||
function toFlat(pts: Vec2[]): Float64Array {
|
||||
const f = new Float64Array(pts.length * 2);
|
||||
for (let i = 0; i < pts.length; i++) {
|
||||
f[2 * i] = pts[i].x;
|
||||
f[2 * i + 1] = pts[i].y;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/** Punkte einer (ggf. gedrehten) Ellipse, N gleichverteilte Parameterschritte. */
|
||||
export function ellipsePts(
|
||||
@@ -13,29 +30,7 @@ export function ellipsePts(
|
||||
rotation: number,
|
||||
n = 64,
|
||||
): Vec2[] {
|
||||
const pts: Vec2[] = [];
|
||||
const cosR = Math.cos(rotation);
|
||||
const sinR = Math.sin(rotation);
|
||||
for (let i = 0; i < n; i++) {
|
||||
const t = (i / n) * Math.PI * 2;
|
||||
const lx = rx * Math.cos(t);
|
||||
const ly = ry * Math.sin(t);
|
||||
pts.push({ x: center.x + lx * cosR - ly * sinR, y: center.y + lx * sinR + ly * cosR });
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
/** Punkt auf einer kubischen Bezier-Kurve (De-Casteljau-Formel) bei Parameter `t` ∈ [0,1]. */
|
||||
function cubicPoint(p0: Vec2, p1: Vec2, p2: Vec2, p3: Vec2, t: number): Vec2 {
|
||||
const u = 1 - t;
|
||||
const a = u * u * u;
|
||||
const b = 3 * u * u * t;
|
||||
const c = 3 * u * t * t;
|
||||
const d = t * t * t;
|
||||
return {
|
||||
x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,
|
||||
y: a * p0.y + b * p1.y + c * p2.y + d * p3.y,
|
||||
};
|
||||
return toPoints(core().curves_ellipse_flat(center.x, center.y, rx, ry, rotation, n));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,21 +41,7 @@ function cubicPoint(p0: Vec2, p1: Vec2, p2: Vec2, p3: Vec2, t: number): Vec2 {
|
||||
*/
|
||||
export function sampleBezierChain(pts: Vec2[], segsPerCurve = 24): Vec2[] {
|
||||
if (pts.length < 4) return [...pts];
|
||||
const out: Vec2[] = [pts[0]];
|
||||
for (let i = 0; i + 3 < pts.length; i += 3) {
|
||||
const p0 = pts[i], p1 = pts[i + 1], p2 = pts[i + 2], p3 = pts[i + 3];
|
||||
for (let s = 1; s <= segsPerCurve; s++) out.push(cubicPoint(p0, p1, p2, p3, s / segsPerCurve));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Kontrollpunkt-Zugriff für Catmull-Rom mit Rand-Klemmung bzw. Ring-Umlauf. */
|
||||
function crPoint(pts: Vec2[], i: number, closed: boolean): Vec2 {
|
||||
const n = pts.length;
|
||||
if (closed) return pts[((i % n) + n) % n];
|
||||
if (i < 0) return pts[0];
|
||||
if (i >= n) return pts[n - 1];
|
||||
return pts[i];
|
||||
return toPoints(core().curves_bezier_chain_flat(toFlat(pts), segsPerCurve));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,48 +54,7 @@ function crPoint(pts: Vec2[], i: number, closed: boolean): Vec2 {
|
||||
*/
|
||||
export function sampleCatmullRom(pts: Vec2[], closed: boolean, segsPerSpan = 16): Vec2[] {
|
||||
if (pts.length < 3) return [...pts];
|
||||
const out: Vec2[] = [];
|
||||
const spans = closed ? pts.length : pts.length - 1;
|
||||
for (let i = 0; i < spans; i++) {
|
||||
const p0 = crPoint(pts, i - 1, closed);
|
||||
const p1 = crPoint(pts, i, closed);
|
||||
const p2 = crPoint(pts, i + 1, closed);
|
||||
const p3 = crPoint(pts, i + 2, closed);
|
||||
for (let s = 0; s < segsPerSpan; s++) {
|
||||
const t = s / segsPerSpan;
|
||||
const t2 = t * t;
|
||||
const t3 = t2 * t;
|
||||
const x =
|
||||
0.5 *
|
||||
(2 * p1.x +
|
||||
(-p0.x + p2.x) * t +
|
||||
(2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 +
|
||||
(-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t3);
|
||||
const y =
|
||||
0.5 *
|
||||
(2 * p1.y +
|
||||
(-p0.y + p2.y) * t +
|
||||
(2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 +
|
||||
(-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t3);
|
||||
out.push({ x, y });
|
||||
}
|
||||
}
|
||||
if (!closed) out.push(pts[pts.length - 1]);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Punkt auf einem uniformen kubischen B-Spline-Segment (Standard-Basis, 4 Kontrollpunkte). */
|
||||
function bsplineSegPoint(p0: Vec2, p1: Vec2, p2: Vec2, p3: Vec2, t: number): Vec2 {
|
||||
const t2 = t * t;
|
||||
const t3 = t2 * t;
|
||||
const b0 = (1 - t) ** 3 / 6;
|
||||
const b1 = (3 * t3 - 6 * t2 + 4) / 6;
|
||||
const b2 = (-3 * t3 + 3 * t2 + 3 * t + 1) / 6;
|
||||
const b3 = t3 / 6;
|
||||
return {
|
||||
x: p0.x * b0 + p1.x * b1 + p2.x * b2 + p3.x * b3,
|
||||
y: p0.y * b0 + p1.y * b1 + p2.y * b2 + p3.y * b3,
|
||||
};
|
||||
return toPoints(core().curves_catmull_rom_flat(toFlat(pts), closed, segsPerSpan));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,35 +62,11 @@ function bsplineSegPoint(p0: Vec2, p1: Vec2, p2: Vec2, p3: Vec2, t: number): Vec
|
||||
* `pts` — Gegenstück zu `sampleCatmullRom`: die Kurve verläuft NICHT durch
|
||||
* die inneren Punkte, sie wird nur von ihnen „gezogen" (Kontrollnetz statt
|
||||
* Durchgangspunkte, wie CV-Modus in AutoCAD/Rhino). Offen: GEKLEMMT — die
|
||||
* Kurve berührt exakt `pts[0]`/`pts[n-1]` (Rand-Kontrollpunkte werden intern
|
||||
* je 2× zusätzlich dupliziert, Multiplizität 3 an beiden Enden — der
|
||||
* Standard-Trick für kubische B-Splines, ohne eine generische
|
||||
* Knotenvektor-Auswertung/Cox-de-Boor-Rekursion zu brauchen). Geschlossen:
|
||||
* periodisch (Kontrollpunkte laufen zyklisch um), die Kurve berührt dann
|
||||
* KEINEN der Punkte. Mit weniger als 3 Punkten identisches
|
||||
* Kurve berührt exakt `pts[0]`/`pts[n-1]`. Geschlossen: periodisch, die Kurve
|
||||
* berührt dann KEINEN der Punkte. Mit weniger als 3 Punkten identisches
|
||||
* Fallback-Verhalten wie `sampleCatmullRom` (Rohpunkte, Gummiband-Vorschau).
|
||||
*/
|
||||
export function sampleUniformBSpline(pts: Vec2[], closed: boolean, segsPerSpan = 16): Vec2[] {
|
||||
if (pts.length < 3) return [...pts];
|
||||
const out: Vec2[] = [];
|
||||
if (closed) {
|
||||
const n = pts.length;
|
||||
const at = (i: number) => pts[((i % n) + n) % n];
|
||||
for (let i = 0; i < n; i++) {
|
||||
for (let s = 0; s < segsPerSpan; s++) {
|
||||
out.push(bsplineSegPoint(at(i - 1), at(i), at(i + 1), at(i + 2), s / segsPerSpan));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
const last = pts[pts.length - 1];
|
||||
const padded = [pts[0], pts[0], ...pts, last, last];
|
||||
const spans = padded.length - 3;
|
||||
for (let i = 0; i < spans; i++) {
|
||||
for (let s = 0; s < segsPerSpan; s++) {
|
||||
out.push(bsplineSegPoint(padded[i], padded[i + 1], padded[i + 2], padded[i + 3], s / segsPerSpan));
|
||||
}
|
||||
}
|
||||
out.push(last);
|
||||
return out;
|
||||
return toPoints(core().curves_uniform_bspline_flat(toFlat(pts), closed, segsPerSpan));
|
||||
}
|
||||
+41
-334
@@ -1,8 +1,7 @@
|
||||
// Geometrie-Helfer für Öffnungen (Fenster/Türen) — reine Funktionen, die eine
|
||||
// `Opening` relativ zu ihrer Wirts-Wand in konkrete Welt-Geometrie auflösen:
|
||||
// • die Öffnungs-Lücke entlang der Wandachse (from/to in Metern),
|
||||
// • das Türblatt (Scharnier → offenes/geschlossenes Ende) + Schwenkbogen,
|
||||
// • die Fenster-Rahmen-/Glaslinien quer über die Lücke,
|
||||
// • die Fenster-Rahmen-/Glaslinien quer über die Lücke (`windowSymbol`, Fassade über den Rust-Kern),
|
||||
// • die vertikale Lage (UK/OK der Öffnung, absolut in Metern).
|
||||
//
|
||||
// Da JEDE Größe aus der aktuellen Wandachse (`wall.start`/`wall.end`) abgeleitet
|
||||
@@ -12,12 +11,11 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Opening, Project, SashDef, Vec2, Wall } from "../model/types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { getWallType, wallTypeThickness } from "../model/types";
|
||||
import { add, along, leftNormal, normalize, scale, sub } from "../model/geometry";
|
||||
import { wallReferenceOffset, wallVerticalExtent } from "../model/wall";
|
||||
|
||||
const DEG = Math.PI / 180;
|
||||
|
||||
/** Achslänge einer Wand (Meter). */
|
||||
export function wallAxisLength(wall: Wall): number {
|
||||
return Math.hypot(wall.end.x - wall.start.x, wall.end.y - wall.start.y);
|
||||
@@ -104,121 +102,6 @@ export function openingCenter(wall: Wall, o: Opening): Vec2 | null {
|
||||
return along(wall.start, wall.end, (iv.from + iv.to) / 2);
|
||||
}
|
||||
|
||||
// ── Tür-Symbol (Plan) ────────────────────────────────────────────────────────
|
||||
|
||||
/** Aufgelöste Tür-Symbol-Geometrie im Grundriss (Weltkoordinaten). */
|
||||
export interface DoorSymbol {
|
||||
/** Scharnierpunkt (auf der Achse). */
|
||||
hinge: Vec2;
|
||||
/** Ende des Blatts in GEÖFFNETER Stellung. */
|
||||
openEnd: Vec2;
|
||||
/** Ende des Blatts in GESCHLOSSENER Stellung (Bogen-Startpunkt). */
|
||||
closedEnd: Vec2;
|
||||
/** Radius (= Türbreite) des Schwenkbogens. */
|
||||
radius: number;
|
||||
/** Beide Pfosten-Punkte (für Rahmen-/Anschlagstriche). */
|
||||
jambStart: Vec2;
|
||||
jambEnd: Vec2;
|
||||
/** Achs-Normale (für kurze Anschlagstriche quer zur Wand). */
|
||||
normal: Vec2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst die Tür-Symbolik auf. `swing` wählt die Aufschlagseite (linke/rechte
|
||||
* Achs-Normale), `openingDir` ("out") spiegelt sie auf die andere Seite,
|
||||
* `hinge` wählt den Scharnier-Pfosten, `swingAngle` (Grad, Default 90) bestimmt,
|
||||
* wie weit das Blatt in der offenen Stellung aufsteht.
|
||||
*/
|
||||
export function doorSymbol(wall: Wall, o: Opening): DoorSymbol | null {
|
||||
const jambs = openingJambs(wall, o);
|
||||
if (!jambs) return null;
|
||||
const { u, n } = wallAxisFrame(wall);
|
||||
const { jambStart, jambEnd } = jambs;
|
||||
const width = Math.hypot(jambEnd.x - jambStart.x, jambEnd.y - jambStart.y);
|
||||
|
||||
const swingSign = (o.swing ?? "left") === "left" ? 1 : -1;
|
||||
const dirSign = (o.openingDir ?? "in") === "in" ? 1 : -1;
|
||||
const swingDir = scale(n, swingSign * dirSign);
|
||||
|
||||
const hinge = (o.hinge ?? "start") === "start" ? jambStart : jambEnd;
|
||||
// Geschlossene Richtung zeigt vom Scharnier zum GEGENüberliegenden Pfosten.
|
||||
const closedDir = (o.hinge ?? "start") === "start" ? u : scale(u, -1);
|
||||
|
||||
const angle = (o.swingAngle ?? 90) * DEG;
|
||||
// Offenes Blatt-Ende: um `angle` von der geschlossenen Richtung zur
|
||||
// Schwenkrichtung gedreht (Interpolation über die Basis closedDir/swingDir).
|
||||
const openDir = {
|
||||
x: closedDir.x * Math.cos(angle) + swingDir.x * Math.sin(angle),
|
||||
y: closedDir.y * Math.cos(angle) + swingDir.y * Math.sin(angle),
|
||||
};
|
||||
return {
|
||||
hinge,
|
||||
openEnd: add(hinge, scale(openDir, width)),
|
||||
closedEnd: add(hinge, scale(closedDir, width)),
|
||||
radius: width,
|
||||
jambStart,
|
||||
jambEnd,
|
||||
normal: n,
|
||||
};
|
||||
}
|
||||
|
||||
/** Ein einzelnes Türblatt (Grundriss): Scharnier + geschlossenes/offenes Ende + Radius. */
|
||||
export interface DoorLeaf {
|
||||
hinge: Vec2;
|
||||
openEnd: Vec2;
|
||||
closedEnd: Vec2;
|
||||
radius: number;
|
||||
}
|
||||
|
||||
/** Blatt-Geometrie aus Scharnier, geschlossener Richtung, Schwenkrichtung, Winkel, Breite. */
|
||||
function computeLeaf(
|
||||
hinge: Vec2,
|
||||
closedDir: Vec2,
|
||||
swingDir: Vec2,
|
||||
angle: number,
|
||||
width: number,
|
||||
): DoorLeaf {
|
||||
const openDir = {
|
||||
x: closedDir.x * Math.cos(angle) + swingDir.x * Math.sin(angle),
|
||||
y: closedDir.y * Math.cos(angle) + swingDir.y * Math.sin(angle),
|
||||
};
|
||||
return {
|
||||
hinge,
|
||||
openEnd: add(hinge, scale(openDir, width)),
|
||||
closedEnd: add(hinge, scale(closedDir, width)),
|
||||
radius: width,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Türblätter im Grundriss (1 oder 2 Flügel). Einflüglig: ein Blatt über die
|
||||
* volle Breite (Scharnier je `o.hinge`). Zweiflüglig (`leafCount === 2`): zwei
|
||||
* halbbreite Blätter, an den GEGENüberliegenden Pfosten angeschlagen, beide zur
|
||||
* selben Seite schwenkend (symmetrische Doppeltür / Stulptür). `doorSymbol`
|
||||
* bleibt unverändert (einflügelig) für Bestandspfade/Parität; dies ist additiv.
|
||||
*/
|
||||
export function doorLeaves(wall: Wall, o: Opening, leafCount: number): DoorLeaf[] {
|
||||
const jambs = openingJambs(wall, o);
|
||||
if (!jambs) return [];
|
||||
const { u, n } = wallAxisFrame(wall);
|
||||
const { jambStart, jambEnd } = jambs;
|
||||
const width = Math.hypot(jambEnd.x - jambStart.x, jambEnd.y - jambStart.y);
|
||||
const swingSign = (o.swing ?? "left") === "left" ? 1 : -1;
|
||||
const dirSign = (o.openingDir ?? "in") === "in" ? 1 : -1;
|
||||
const swingDir = scale(n, swingSign * dirSign);
|
||||
const angle = (o.swingAngle ?? 90) * DEG;
|
||||
if (leafCount >= 2) {
|
||||
const hw = width / 2;
|
||||
return [
|
||||
computeLeaf(jambStart, u, swingDir, angle, hw),
|
||||
computeLeaf(jambEnd, scale(u, -1), swingDir, angle, hw),
|
||||
];
|
||||
}
|
||||
const hinge = (o.hinge ?? "start") === "start" ? jambStart : jambEnd;
|
||||
const closedDir = (o.hinge ?? "start") === "start" ? u : scale(u, -1);
|
||||
return [computeLeaf(hinge, closedDir, swingDir, angle, width)];
|
||||
}
|
||||
|
||||
// ── Fenster-Symbol (Plan) ────────────────────────────────────────────────────
|
||||
|
||||
/** Aufgelöste Fenster-Linien im Grundriss (Weltkoordinaten). */
|
||||
@@ -288,62 +171,6 @@ export interface WindowRenderSpec {
|
||||
insetFace?: "aussen" | "innen";
|
||||
}
|
||||
|
||||
/** Ein Segment (Flügel/Pfosten) der Flügeleinteilung, mit aufgelöster Breite. */
|
||||
interface SashSegment {
|
||||
sash: SashDef;
|
||||
/** Abstand vom Laibungsstart in Metern (0 = jambStart). */
|
||||
from: number;
|
||||
/** Abstand vom Laibungsstart in Metern. */
|
||||
to: number;
|
||||
}
|
||||
|
||||
/** Default-Pfostenbreite (Meter), wenn ein `kind:"pfosten"`-Eintrag keine `postWidth` angibt. */
|
||||
const DEFAULT_POST_WIDTH = 0.06;
|
||||
/**
|
||||
* Default-Rahmentiefe (Meter), wenn ein Fenster-/Türtyp keine explizite
|
||||
* `frameDepth` trägt: reale Fensterrahmen sind ~70–90 mm tief (Holz/PVC/Alu),
|
||||
* unabhängig von der Wanddicke — NICHT die volle Wanddicke (das liess Fenster
|
||||
* wie einen massiven Block in der Öffnung wirken statt eines schlanken Rahmens
|
||||
* mit sichtbarer Laibung/Leibung ringsum, s. Recherche zu VW/ArchiCAD-Fenster-
|
||||
* konstruktion). Deckt sich mit `toWalls3d.ts::DEFAULT_FRAME_DEPTH` (2D=3D).
|
||||
*/
|
||||
const DEFAULT_FRAME_DEPTH = 0.07;
|
||||
|
||||
/**
|
||||
* Löst eine Flügeleinteilung ({@link SashDef}-Liste) zu konkreten Segment-
|
||||
* Intervallen (Meter, gemessen ab Laibungsstart) über die gegebene
|
||||
* Gesamtbreite auf: `kind:"pfosten"` und Flügel mit `autoWidth === false`
|
||||
* erhalten ihre feste Breite (`postWidth` bzw. `width`), die restlichen
|
||||
* (`autoWidth`, Default) teilen sich die verbleibende Breite gleichmäßig.
|
||||
* Degeneriert bei GLEICHMÄSSIGEN Flügeln (alle `autoWidth`, keine Pfosten) zur
|
||||
* bisherigen `wingCount`-Gleichverteilung (Regressionssicherheit).
|
||||
*/
|
||||
function sashSegments(sashes: SashDef[], totalWidth: number): SashSegment[] {
|
||||
if (sashes.length === 0) return [];
|
||||
let fixedSum = 0;
|
||||
let autoCount = 0;
|
||||
for (const s of sashes) {
|
||||
if (s.kind === "pfosten") fixedSum += Math.max(0, s.postWidth ?? DEFAULT_POST_WIDTH);
|
||||
else if (s.autoWidth === false) fixedSum += Math.max(0, s.width ?? 0);
|
||||
else autoCount++;
|
||||
}
|
||||
const remaining = Math.max(0, totalWidth - fixedSum);
|
||||
const autoWidth = autoCount > 0 ? remaining / autoCount : 0;
|
||||
const segs: SashSegment[] = [];
|
||||
let cursor = 0;
|
||||
for (const s of sashes) {
|
||||
const w =
|
||||
s.kind === "pfosten"
|
||||
? Math.max(0, s.postWidth ?? DEFAULT_POST_WIDTH)
|
||||
: s.autoWidth === false
|
||||
? Math.max(0, s.width ?? 0)
|
||||
: autoWidth;
|
||||
segs.push({ sash: s, from: cursor, to: cursor + w });
|
||||
cursor += w;
|
||||
}
|
||||
return segs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst die Fenster-Symbolik auf: ein Rahmen-Rechteck über die Lücke (volle
|
||||
* Wanddicke) plus 1–3 Glaslinien (dünne parallele Linien in der Wandmitte,
|
||||
@@ -355,6 +182,9 @@ function sashSegments(sashes: SashDef[], totalWidth: number): SashSegment[] {
|
||||
* referenziert/auflösbar), bleibt die Mittelpfosten-Berechnung beim
|
||||
* BISHERIGEN Verhalten — `o.wingCount` gleichmäßig verteilt, KEINE
|
||||
* Öffnungsandeutungen — exakt wie vor dieser Erweiterung (Rückwärtskompatibilität).
|
||||
*
|
||||
* Die Berechnung läuft im Rust-Kern (`src-tauri/core/src/opening_geom.rs`, [K3a]); diese Funktion
|
||||
* ist die Fassade mit unveränderter Signatur.
|
||||
*/
|
||||
export function windowSymbol(
|
||||
project: Project,
|
||||
@@ -364,167 +194,44 @@ export function windowSymbol(
|
||||
spec?: WindowRenderSpec,
|
||||
detail: "grob" | "mittel" | "fein" = "fein",
|
||||
): WindowSymbol | null {
|
||||
const jambs = openingJambs(wall, o);
|
||||
if (!jambs) return null;
|
||||
const { n } = wallAxisFrame(wall);
|
||||
const total = wallTypeThickness(getWallType(project, wall));
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
const outer = refOff + total / 2;
|
||||
const inner = refOff - total / 2;
|
||||
const { jambStart, jambEnd } = jambs;
|
||||
|
||||
// ── Reicher Pfad (typisiertes Fenster mit Flügeltabelle), SIA-Darstellung ─
|
||||
// Detailstufe = SIA-Massstab (fig. 36/37/38):
|
||||
// • grob (1:100): NUR Blendrahmen-Band + eine Glaslinie über die ganze
|
||||
// Öffnung — schematisch (SIA fig. 36).
|
||||
// • mittel(1:50): Blendrahmen + Flügel-Trennlinien + je Flügel eine Glas-
|
||||
// linie + kleines Stulp-Quadrat je Stoss (SIA fig. 37). KEINE Flügelrahmen.
|
||||
// • fein (1:20): zusätzlich verschachtelte Flügelrahmen, Glas als Doppel-
|
||||
// linie (Isolierverglasung) und je Stoss ZWEI Stulp-Quadrate (SIA fig. 38).
|
||||
if (spec && spec.sashes.length > 0) {
|
||||
const fw = Math.max(0.01, spec.frameWidth);
|
||||
const depth = Math.min(total, spec.frameDepth && spec.frameDepth > 1e-9 ? spec.frameDepth : DEFAULT_FRAME_DEPTH);
|
||||
const inset = Math.max(0, spec.insetFromFace ?? 0);
|
||||
const halfT = total / 2;
|
||||
// "aussen" = die Wandfläche, an der die ERSTE Wandtyp-Schicht (Aussenputz
|
||||
// etc., "Schichten außen → innen") liegt — das ist die Seite mit dem
|
||||
// NEGATIVEN Achs-Offset (s. addWallPoche: `off` startet bei `refOff-total/2`
|
||||
// für die erste Schicht). Bug bis 2026-07-12: hier stand `+1` für "aussen"
|
||||
// (positiver, NICHT negativer Offset) — der Rahmen landete dadurch bündig
|
||||
// an der INNEREN statt der äusseren Wandfläche (Nutzer-Report: "im 2D innen
|
||||
// bündig und im 3D aussen bündig" — das 3D-Pendant nutzt kompensierend eine
|
||||
// gespiegelte Normale, s. resolveFrameNormalRange/openingAxisBox).
|
||||
const sign = (spec.insetFace ?? "aussen") === "aussen" ? -1 : 1;
|
||||
// Rahmen-Vorderkante bündig mit der Bezugsfläche, um `inset` zurück; der
|
||||
// Körper reicht `depth` zur Wandmitte. Auf die Wanddicke geklemmt (mirror
|
||||
// von resolveFrameNormalRange im 3D). Alles relativ zur Referenzlinie.
|
||||
let frontRel = sign * (halfT - inset);
|
||||
let backRel = frontRel - sign * depth;
|
||||
frontRel = Math.max(-halfT, Math.min(halfT, frontRel));
|
||||
backRel = Math.max(-halfT, Math.min(halfT, backRel));
|
||||
const frameOuterN = refOff + Math.max(frontRel, backRel);
|
||||
const frameInnerN = refOff + Math.min(frontRel, backRel);
|
||||
const bandDepth = frameOuterN - frameInnerN;
|
||||
const gMidBase = (frameOuterN + frameInnerN) / 2;
|
||||
|
||||
const frame = [
|
||||
add(jambStart, scale(n, frameOuterN)),
|
||||
add(jambEnd, scale(n, frameOuterN)),
|
||||
add(jambEnd, scale(n, frameInnerN)),
|
||||
add(jambStart, scale(n, frameInnerN)),
|
||||
];
|
||||
|
||||
const glassLines: [Vec2, Vec2][] = [];
|
||||
const mullionLines: [Vec2, Vec2][] = [];
|
||||
const sashFrames: Vec2[][] = [];
|
||||
const meetingMarks: Vec2[][] = [];
|
||||
const jambMarks: Vec2[][] = [];
|
||||
|
||||
// grob (1:100): nur der Rahmenkasten + EINE Glaslinie über die ganze Öffnung.
|
||||
if (detail === "grob") {
|
||||
glassLines.push([add(jambStart, scale(n, gMidBase)), add(jambEnd, scale(n, gMidBase))]);
|
||||
return { frame, glassLines, mullionLines, sashFrames, sashOpeningLines: [], meetingMarks, jambMarks };
|
||||
}
|
||||
|
||||
const fein = detail === "fein";
|
||||
const axisWidth = Math.hypot(jambEnd.x - jambStart.x, jambEnd.y - jambStart.y);
|
||||
const segs = sashSegments(spec.sashes, axisWidth);
|
||||
// Öffenbarer Flügel sitzt `reveal` tiefer im Blendrahmen (nur „fein").
|
||||
const reveal = fein ? Math.min(bandDepth * 0.3, fw * 0.7) : 0;
|
||||
// Profil-Block über die VOLLE Rahmentiefe (aussen bis innen), Breite `2·halfU`
|
||||
// entlang der Achse, zentriert bei `uCenter` (Achsabstand ab jambStart) — der
|
||||
// Rahmenquerschnitt, wie er im Grundriss-Schnitt sichtbar ist (Nutzer:
|
||||
// „Rahmen aussen als zwei Flächen gleichbreit wie das Fenster [tief]").
|
||||
const frameBlock = (uCenter: number, halfU: number): Vec2[] => {
|
||||
const a = along(jambStart, jambEnd, uCenter - halfU);
|
||||
const b = along(jambStart, jambEnd, uCenter + halfU);
|
||||
return [
|
||||
add(a, scale(n, frameOuterN)),
|
||||
add(b, scale(n, frameOuterN)),
|
||||
add(b, scale(n, frameInnerN)),
|
||||
add(a, scale(n, frameInnerN)),
|
||||
];
|
||||
};
|
||||
// Laibungs-Pfosten an beiden Enden (Blendrahmen-Querschnitt an der Wand-
|
||||
// öffnung) — EIN Block je Seite, unabhängig vom Detailgrad. Teil des
|
||||
// Blendrahmens (jambMarks), NICHT der Flügelstoss-Marken (meetingMarks) —
|
||||
// separat steuerbar (Nutzer-Feedback).
|
||||
jambMarks.push(frameBlock(fw / 2, fw / 2), frameBlock(axisWidth - fw / 2, fw / 2));
|
||||
|
||||
// Flügel-Trennlinien (Mittelpfosten) an den inneren Segmentgrenzen +
|
||||
// Stulp-Block: mittel 1, fein 2 (die beiden zusammenstossenden Profile) —
|
||||
// je über die volle Rahmentiefe. KEINE zusätzliche dünne Trennlinie mehr
|
||||
// daneben (Nutzer-Feedback: „keine vertikale Trennlinie, sondern ein
|
||||
// Rechteck") — der Block selbst markiert den Stoss.
|
||||
for (let i = 0; i < segs.length - 1; i++) {
|
||||
const uPos = segs[i].to;
|
||||
if (fein) {
|
||||
meetingMarks.push(frameBlock(uPos - fw / 2, fw / 2), frameBlock(uPos + fw / 2, fw / 2));
|
||||
} else {
|
||||
meetingMarks.push(frameBlock(uPos, fw / 2));
|
||||
}
|
||||
}
|
||||
|
||||
for (const seg of segs) {
|
||||
if (seg.sash.kind === "pfosten") continue;
|
||||
const clearFrom = seg.from + fw;
|
||||
const clearTo = seg.to - fw;
|
||||
if (clearTo - clearFrom <= 1e-6) continue;
|
||||
const operable = !!seg.sash.opening && seg.sash.opening !== "fest";
|
||||
// „mittel" (SIA fig. 37) zeigt NUR Blendrahmen + Pfosten/Stulp — noch KEINE
|
||||
// Glaslinie/Flügelrahmen (Nutzer-Vorgabe: „im 1:50 muss man die Fenster-
|
||||
// linie noch nicht sehen, nur die Vierecke aussen/innen"). Das kommt erst
|
||||
// bei „fein" (SIA fig. 38) dazu.
|
||||
if (!fein) continue;
|
||||
const gOuterN = frameOuterN - (operable ? reveal : 0);
|
||||
const gInnerN = frameInnerN + (operable ? reveal : 0);
|
||||
// Verschachtelter Flügelrahmen NUR bei „fein" (SIA fig. 38); „mittel" bleibt
|
||||
// beim reinen Blendrahmen-Band (SIA fig. 37).
|
||||
// Keine Glaslinie mehr im Feld (auch nicht bei „fein") — Nutzer-Feedback:
|
||||
// eine feine Haarlinie mittig im Glasfeld wird nicht gebraucht, unabhängig
|
||||
// von der Fensterposition. Der Flügelrahmen (nur bei öffenbaren Flügeln)
|
||||
// bleibt als einzige zusätzliche Kontur bei „fein" bestehen.
|
||||
if (operable) {
|
||||
const sFrom = along(jambStart, jambEnd, clearFrom);
|
||||
const sTo = along(jambStart, jambEnd, clearTo);
|
||||
sashFrames.push([
|
||||
add(sFrom, scale(n, gOuterN)),
|
||||
add(sTo, scale(n, gOuterN)),
|
||||
add(sTo, scale(n, gInnerN)),
|
||||
add(sFrom, scale(n, gInnerN)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
return { frame, glassLines, mullionLines, sashFrames, sashOpeningLines: [], meetingMarks, jambMarks };
|
||||
}
|
||||
|
||||
// ── Alt-Pfad (kein Typ auflösbar) ────────────────────────────────────────
|
||||
// UNVERÄNDERT (Rust-Parität kernel2d): Rahmen an voller Wanddicke, Glaslinien
|
||||
// mittig, (wingCount−1) gleichmäßige Mittelpfosten. Keine Flügelrahmen.
|
||||
const frame = [
|
||||
add(jambStart, scale(n, outer)),
|
||||
add(jambEnd, scale(n, outer)),
|
||||
add(jambEnd, scale(n, inner)),
|
||||
add(jambStart, scale(n, inner)),
|
||||
const b: number[] = [
|
||||
wall.start.x, wall.start.y, wall.end.x, wall.end.y, total, wallReferenceOffset(wall, total),
|
||||
o.position, o.width, glassCount, o.wingCount ?? Number.NaN,
|
||||
detail === "grob" ? 0 : detail === "mittel" ? 1 : 2,
|
||||
spec ? 1 : 0,
|
||||
spec?.frameWidth ?? 0, spec?.frameDepth ?? Number.NaN, spec?.insetFromFace ?? Number.NaN,
|
||||
spec?.insetFace === "innen" ? 1 : 0,
|
||||
spec?.sashes.length ?? 0,
|
||||
];
|
||||
const glassLines: [Vec2, Vec2][] = [];
|
||||
const count = Math.max(1, glassCount);
|
||||
for (let i = 0; i < count; i++) {
|
||||
const spread = total / 8;
|
||||
const off = refOff + (count === 1 ? 0 : (i - (count - 1) / 2) * spread * 2);
|
||||
glassLines.push([add(jambStart, scale(n, off)), add(jambEnd, scale(n, off))]);
|
||||
for (const s of spec?.sashes ?? []) {
|
||||
b.push(s.kind === "pfosten" ? 1 : 0, s.autoWidth === false ? 0 : 1, s.width ?? Number.NaN, s.postWidth ?? Number.NaN,
|
||||
s.opening && s.opening !== "fest" ? 1 : 0);
|
||||
}
|
||||
const mullionLines: [Vec2, Vec2][] = [];
|
||||
const wings = Math.max(1, Math.min(4, Math.round(o.wingCount ?? 1)));
|
||||
if (wings > 1) {
|
||||
const postDepth = total * 0.6;
|
||||
const pOuter = refOff + postDepth / 2;
|
||||
const pInner = refOff - postDepth / 2;
|
||||
for (let i = 1; i < wings; i++) {
|
||||
const t = i / wings;
|
||||
const onAxis = add(jambStart, scale(sub(jambEnd, jambStart), t));
|
||||
mullionLines.push([add(onAxis, scale(n, pOuter)), add(onAxis, scale(n, pInner))]);
|
||||
const f = core().window_symbol_flat(Float64Array.from(b));
|
||||
if (f.length === 0) return null;
|
||||
let i = 1;
|
||||
const pt = (): Vec2 => ({ x: f[i++], y: f[i++] });
|
||||
const frame = [pt(), pt(), pt(), pt()];
|
||||
const segs = (): [Vec2, Vec2][] => {
|
||||
const n = f[i++];
|
||||
const out: [Vec2, Vec2][] = [];
|
||||
for (let k = 0; k < n; k++) out.push([pt(), pt()]);
|
||||
return out;
|
||||
};
|
||||
const rings = (): Vec2[][] => {
|
||||
const n = f[i++];
|
||||
const out: Vec2[][] = [];
|
||||
for (let k = 0; k < n; k++) {
|
||||
const m = f[i++];
|
||||
out.push(Array.from({ length: m }, pt));
|
||||
}
|
||||
}
|
||||
return { frame, glassLines, mullionLines, sashFrames: [], sashOpeningLines: [], meetingMarks: [], jambMarks: [] };
|
||||
return out;
|
||||
};
|
||||
const glassLines = segs();
|
||||
const mullionLines = segs();
|
||||
const sashFrames = rings();
|
||||
const meetingMarks = rings();
|
||||
const jambMarks = rings();
|
||||
return { frame, glassLines, mullionLines, sashFrames, sashOpeningLines: [], meetingMarks, jambMarks };
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { allowHost } from "../net/net";
|
||||
import Delaunator from "delaunator";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import type { ContextObject, Contour, ImportedMesh } from "../model/types";
|
||||
import { GEO_CATEGORY_DEFS } from "../model/contextCategories";
|
||||
|
||||
@@ -228,12 +228,7 @@ function triangulateRing(ring: { x: number; y: number }[]): number[] {
|
||||
coords[i * 2] = ring[i].x;
|
||||
coords[i * 2 + 1] = ring[i].y;
|
||||
}
|
||||
let tri: Uint32Array;
|
||||
try {
|
||||
tri = new Delaunator(coords).triangles;
|
||||
} catch {
|
||||
return fanTriangulate(n);
|
||||
}
|
||||
const tri = core().delaunay_flat(coords);
|
||||
const out: number[] = [];
|
||||
for (let t = 0; t < tri.length; t += 3) {
|
||||
const a = tri[t], b = tri[t + 1], c = tri[t + 2];
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { parseProjectFile, PROJECT_FORMAT_VERSION, serializeProject } from "./projectFormat";
|
||||
|
||||
describe("Projektdatei-Format", () => {
|
||||
it("Formatversion in TS und Kern stimmt überein", () => {
|
||||
expect(core().project_format_version()).toBe(PROJECT_FORMAT_VERSION);
|
||||
});
|
||||
it("Speichern setzt die Formatversion, Laden liefert dasselbe Projekt zurueck", () => {
|
||||
const text = serializeProject(sampleProject);
|
||||
expect(JSON.parse(text).formatVersion).toBe(PROJECT_FORMAT_VERSION);
|
||||
|
||||
+12
-120
@@ -1,145 +1,37 @@
|
||||
// Projektdatei-Format (`.obp`/`.obpt`/Alt-`.json`): Versionierung, Migration und EIN
|
||||
// Parser für alle Ladestellen.
|
||||
// Projektdatei-Format (`.obp`/`.obpt`/Alt-`.json`): Versionierung, Migration und EIN Parser für alle
|
||||
// Ladestellen. Gerechnet wird im Rust-Kern (`src-tauri/core/src/project_format.rs`, [K4]).
|
||||
//
|
||||
// Regeln:
|
||||
// • Jede gespeicherte Datei trägt `formatVersion` (s. {@link PROJECT_FORMAT_VERSION}).
|
||||
// • Ältere Dateien (auch ohne `formatVersion` = Version 0) laufen durch die Migrationskette.
|
||||
// • Neuere Dateien werden mit klarer Meldung ABGELEHNT (ein altes Programm würde Felder, die
|
||||
// es nicht kennt, beim nächsten Speichern verlieren).
|
||||
// • Neuere Dateien werden mit klarer Meldung ABGELEHNT (ein altes Programm würde Felder, die es
|
||||
// nicht kennt, beim nächsten Speichern verlieren).
|
||||
// • Tolerant lesen: fehlende Listen werden leer ergänzt, unbekannte Felder bleiben erhalten und
|
||||
// werden gemeldet (nicht gelöscht — die Liste bekannter Felder kann hinter dem Typ
|
||||
// zurückliegen, Löschen wäre dann Datenverlust).
|
||||
// • Was kein Dossier-Projekt ist (kein JSON-Objekt, keine Wände/Ebenen/Geschossliste), ist ein
|
||||
// Fehler mit Meldung — nie ein stilles `console.warn`.
|
||||
// werden gemeldet (nicht gelöscht).
|
||||
// • Was kein Dossier-Projekt ist, ist ein Fehler mit Meldung — nie ein stilles `console.warn`.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { documentFor } from "../core/document";
|
||||
|
||||
/** Aktuelle Version des Dateiformats. Bei jeder Formatänderung erhöhen + Migration anhängen. */
|
||||
/** Aktuelle Version des Dateiformats (muss `PROJECT_FORMAT_VERSION` im Kern entsprechen — Test). */
|
||||
export const PROJECT_FORMAT_VERSION = 2;
|
||||
|
||||
/**
|
||||
* Migrationen: `MIGRATIONS[i]` hebt eine Datei von Version `i` auf `i + 1`. Arbeitet auf dem
|
||||
* rohen JSON-Objekt (kopiert, nie das Original verändern).
|
||||
*/
|
||||
const MIGRATIONS: Array<(raw: Record<string, unknown>) => Record<string, unknown>> = [
|
||||
// 0 → 1: Einführung von `formatVersion`; Inhalt unverändert.
|
||||
(raw) => raw,
|
||||
// 1 → 2: Legacy-Türen (`doors`) werden zu Öffnungen (`openings`, kind "door"). Es gibt nur noch
|
||||
// EINEN Datensatz-Typ für Türen und Fenster.
|
||||
(raw) => {
|
||||
const doors = Array.isArray(raw.doors) ? (raw.doors as Array<Record<string, unknown>>) : [];
|
||||
const { doors: _drop, ...rest } = raw;
|
||||
if (doors.length === 0) return rest;
|
||||
const openings = Array.isArray(rest.openings) ? [...(rest.openings as Array<Record<string, unknown>>)] : [];
|
||||
const taken = new Set(openings.map((o) => String(o.id)));
|
||||
const doorTypes = Array.isArray(rest.doorTypes) ? (rest.doorTypes as Array<{ id?: string }>) : [];
|
||||
for (const d of doors) {
|
||||
let id = String(d.id);
|
||||
while (taken.has(id)) id = `${id}-t`;
|
||||
taken.add(id);
|
||||
openings.push({
|
||||
id,
|
||||
type: "opening",
|
||||
hostWallId: d.hostWallId,
|
||||
categoryCode: d.categoryCode,
|
||||
kind: "door",
|
||||
position: d.position,
|
||||
width: d.width,
|
||||
height: d.height,
|
||||
sillHeight: 0,
|
||||
swing: d.swing,
|
||||
hinge: d.hinge,
|
||||
...(doorTypes[0]?.id ? { typeId: doorTypes[0].id } : {}),
|
||||
});
|
||||
}
|
||||
return { ...rest, openings };
|
||||
},
|
||||
];
|
||||
|
||||
/** Pflichtlisten: fehlen sie, ist es kein Dossier-Projekt. */
|
||||
const REQUIRED_ARRAYS = ["walls", "layers", "drawingLevels"] as const;
|
||||
/** Listen, die bei Fehlen leer ergänzt werden. */
|
||||
const DEFAULT_ARRAYS = ["lineStyles", "hatches", "components", "wallTypes", "drawings2d"] as const;
|
||||
|
||||
/** Bekannte Felder von `Project` (für die Meldung unbekannter Felder). */
|
||||
const KNOWN_KEYS = new Set<string>([
|
||||
"formatVersion", "id", "name", "lineStyles", "textStyles", "hatches", "components", "wallTypes",
|
||||
"ceilingTypes", "roofTypes", "blockDefs", "doorTypes", "windowTypes", "stairTypes", "pens",
|
||||
"penSets", "activePenSetId", "customPalettes", "builtinPaletteBanks", "drawingLevels", "layers",
|
||||
"walls", "ceilings", "roofs", "openings", "stairs", "rooms", "drawings2d", "context",
|
||||
"extrudedSolids", "columns", "groups", "parametricWalls", "overrideRules", "viewSnapshots",
|
||||
"viewSnapshotFolders", "layouts", "masterLayouts", "layoutFolders", "referenceElevationMasl",
|
||||
"geoAnchor", "roomProgram", "parcelArea", "sunStudy", "siteRules", "scaleLineWeights",
|
||||
]);
|
||||
|
||||
export type ParseProjectResult =
|
||||
| { ok: true; project: Project; warnings: string[]; migratedFrom: number | null }
|
||||
| { ok: false; error: string };
|
||||
|
||||
/** Liest eine Projektdatei (Text) tolerant ein, migriert und prüft sie. */
|
||||
export function parseProjectFile(text: string): ParseProjectResult {
|
||||
let raw: unknown;
|
||||
try {
|
||||
raw = JSON.parse(text);
|
||||
} catch (e) {
|
||||
return { ok: false, error: `Die Datei ist kein gültiges JSON (${e instanceof Error ? e.message : String(e)}).` };
|
||||
}
|
||||
return parseProjectObject(raw);
|
||||
return JSON.parse(core().project_parse(text, Date.now())) as ParseProjectResult;
|
||||
}
|
||||
|
||||
/** Wie {@link parseProjectFile}, für ein bereits geparstes Objekt. */
|
||||
export function parseProjectObject(raw: unknown): ParseProjectResult {
|
||||
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
||||
return { ok: false, error: "Die Datei enthält kein Dossier-Projekt." };
|
||||
}
|
||||
let obj = { ...(raw as Record<string, unknown>) };
|
||||
const warnings: string[] = [];
|
||||
|
||||
const v = obj.formatVersion;
|
||||
let version = 0;
|
||||
if (v !== undefined) {
|
||||
if (typeof v !== "number" || !Number.isInteger(v) || v < 0) {
|
||||
return { ok: false, error: `Ungültige Formatversion „${String(v)}".` };
|
||||
}
|
||||
version = v;
|
||||
}
|
||||
if (version > PROJECT_FORMAT_VERSION) {
|
||||
return {
|
||||
ok: false,
|
||||
error:
|
||||
`Die Datei wurde mit einer neueren Dossier-Version gespeichert (Format ${version}, ` +
|
||||
`dieses Programm kennt bis ${PROJECT_FORMAT_VERSION}). Bitte Dossier aktualisieren.`,
|
||||
};
|
||||
}
|
||||
|
||||
for (const key of REQUIRED_ARRAYS) {
|
||||
if (!Array.isArray(obj[key])) {
|
||||
return { ok: false, error: `Die Datei enthält kein Dossier-Projekt (Liste „${key}" fehlt).` };
|
||||
}
|
||||
}
|
||||
|
||||
const migratedFrom = version < PROJECT_FORMAT_VERSION ? version : null;
|
||||
for (let i = version; i < PROJECT_FORMAT_VERSION; i++) obj = MIGRATIONS[i]({ ...obj });
|
||||
obj.formatVersion = PROJECT_FORMAT_VERSION;
|
||||
|
||||
for (const key of DEFAULT_ARRAYS) {
|
||||
if (obj[key] === undefined) obj[key] = [];
|
||||
else if (!Array.isArray(obj[key])) {
|
||||
warnings.push(`Feld „${key}" ist keine Liste und wurde geleert.`);
|
||||
obj[key] = [];
|
||||
}
|
||||
}
|
||||
if (typeof obj.id !== "string" || !obj.id) obj.id = `project-${Date.now().toString(36)}`;
|
||||
if (typeof obj.name !== "string") obj.name = "";
|
||||
|
||||
const unknown = Object.keys(obj).filter((k) => !KNOWN_KEYS.has(k));
|
||||
if (unknown.length) warnings.push(`Unbekannte Felder behalten: ${unknown.join(", ")}.`);
|
||||
|
||||
return { ok: true, project: obj as unknown as Project, warnings, migratedFrom };
|
||||
return parseProjectFile(JSON.stringify(raw ?? null));
|
||||
}
|
||||
|
||||
/** Serialisiert ein Projekt für die Datei (mit aktueller Formatversion vorne). */
|
||||
export function serializeProject(project: Project): string {
|
||||
const { formatVersion: _old, ...rest } = project as Project & { formatVersion?: number };
|
||||
return JSON.stringify({ formatVersion: PROJECT_FORMAT_VERSION, ...rest }, null, 2);
|
||||
return documentFor(project).serialize();
|
||||
}
|
||||
+6
-11
@@ -8,7 +8,7 @@
|
||||
//
|
||||
// Gelände ist NICHT semantisch — es ist Kontext-Geometrie (Project.context).
|
||||
|
||||
import Delaunator from "delaunator";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import type { Contour, TerrainMesh } from "./types";
|
||||
import { TERRAIN_CATEGORY } from "./contextCategories";
|
||||
|
||||
@@ -25,7 +25,7 @@ export const TERRAIN_LAYER = "Terrain";
|
||||
* z = Kontur-Höhe. Es wird KEIN zusätzliches Resampling betrieben — die
|
||||
* Kontur-Vertices selbst sind die Breaklines.
|
||||
* 2. Delaunay: 2D-Triangulation über die (x,y)-Projektion aller Vertices
|
||||
* (Delaunator). Die Z-Höhe je Vertex bleibt erhalten → echtes Gelände-TIN.
|
||||
* (Rust-Kern, `delaunay.rs`). Die Z-Höhe je Vertex bleibt erhalten → echtes Gelände-TIN.
|
||||
* 3. Degenerate-Filter: Dreiecke mit (nahezu) null Fläche in der (x,y)-Ebene
|
||||
* bzw. mit nicht-endlichen Koordinaten werden verworfen.
|
||||
*
|
||||
@@ -59,21 +59,16 @@ export function generateTerrainFromContours(contours: Contour[]): TerrainMesh {
|
||||
return { id, type: "terrainMesh", name, categoryCode: TERRAIN_CATEGORY.code, positions: [], indices: [] };
|
||||
}
|
||||
|
||||
// 2. Delaunay über die (x,y)-Projektion. Delaunator erwartet ein flaches
|
||||
// 2. Delaunay über die (x,y)-Projektion. der Kern erwartet ein flaches
|
||||
// [x0,y0, x1,y1, …]-Koordinatenarray.
|
||||
const coords2d = new Float64Array(xs.length * 2);
|
||||
for (let i = 0; i < xs.length; i++) {
|
||||
coords2d[i * 2] = xs[i];
|
||||
coords2d[i * 2 + 1] = ys[i];
|
||||
}
|
||||
// Bei kollinearen Punkten liefert Delaunator eine leere Triangulation — das ist
|
||||
// korrekt (kein Crash). Trotzdem schützen wir gegen einen möglichen Wurf.
|
||||
let triangles: Uint32Array;
|
||||
try {
|
||||
triangles = new Delaunator(coords2d).triangles;
|
||||
} catch {
|
||||
return { id, type: "terrainMesh", name, categoryCode: TERRAIN_CATEGORY.code, positions: [], indices: [] };
|
||||
}
|
||||
// Der Kern (`delaunay.rs`, Port von delaunator) liefert bei kollinearen Punkten eine leere
|
||||
// Triangulation — das ist korrekt.
|
||||
const triangles = core().delaunay_flat(coords2d);
|
||||
|
||||
// 3. positions (x,y,z) aufbauen; Z aus zs je Vertex.
|
||||
const positions: number[] = new Array(xs.length * 3);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import type { Ceiling, LayerCategory, Project } from "../../model/types";
|
||||
import { getCeilingType, getComponent } from "../../model/types";
|
||||
import { mergeHoles } from "../../geometry/polygonHoles";
|
||||
import { add, scale, sub } from "../../model/geometry";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import {
|
||||
NO_HATCH,
|
||||
OVERHEAD_DASH,
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
type DetailLevel,
|
||||
type Primitive,
|
||||
} from "./shared";
|
||||
import { segmentInsideWallBand, subtractIntervals, type WallFootprint } from "./walls";
|
||||
import type { WallFootprint } from "./walls";
|
||||
|
||||
/**
|
||||
* Decken-Poché im Grundriss: die Decke liegt als Slab ÜBER der Schnittebene und
|
||||
@@ -116,32 +116,25 @@ export function addCeilingPoche(
|
||||
// der Umriss ganz; nur Überstände (Vordach/Balkon jenseits der Wand)
|
||||
// bleiben sichtbar. Brückenkanten (künstliche Verbindung Aussenring↔Loch)
|
||||
// werden NICHT gestrichen.
|
||||
const n = ring.length;
|
||||
const bridgeSet = new Set(bridgeEdges);
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (bridgeSet.has(i)) continue;
|
||||
const a = ring[i];
|
||||
const b = ring[(i + 1) % n];
|
||||
const holes: Array<[number, number]> = [];
|
||||
for (const fp of wallFootprints) {
|
||||
const iv = segmentInsideWallBand(a, b, fp);
|
||||
if (iv) holes.push(iv);
|
||||
}
|
||||
const d = sub(b, a);
|
||||
for (const [t0, t1] of subtractIntervals(0, 1, holes)) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: add(a, scale(d, t0)),
|
||||
b: add(a, scale(d, t1)),
|
||||
cls: "ceiling-outline",
|
||||
// Überkopf-Ansichtslinie (Decke liegt als Slab über der Schnittebene) →
|
||||
// gestrichelt statt durchgezogen (BIM-Konvention) — die DICKE folgt
|
||||
// aber ceiling.strokeWeight/-Source wie bei der Wand (s. Aufrufer).
|
||||
weightMm: lwMm * LAYER_DETAIL_FACTOR[detail],
|
||||
dash: OVERHEAD_DASH,
|
||||
color: stroke,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
// Die freien Teilstücke berechnet der Kern (`plan_walls.rs`, [K3a]).
|
||||
const buf: number[] = [ring.length];
|
||||
for (const p of ring) buf.push(p.x, p.y);
|
||||
buf.push(bridgeEdges.length, ...bridgeEdges, wallFootprints.length);
|
||||
for (const fp of wallFootprints) buf.push(fp.a.x, fp.a.y, fp.u.x, fp.u.y, fp.m.x, fp.m.y, fp.len, fp.half, fp.refOff);
|
||||
const f = core().plan_ceiling_outline_flat(Float64Array.from(buf));
|
||||
for (let i = 0; i < f[0]; i++) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: { x: f[1 + 4 * i], y: f[2 + 4 * i] },
|
||||
b: { x: f[3 + 4 * i], y: f[4 + 4 * i] },
|
||||
cls: "ceiling-outline",
|
||||
// Überkopf-Ansichtslinie (Decke liegt als Slab über der Schnittebene) →
|
||||
// gestrichelt statt durchgezogen (BIM-Konvention) — die DICKE folgt
|
||||
// aber ceiling.strokeWeight/-Source wie bei der Wand (s. Aufrufer).
|
||||
weightMm: lwMm * LAYER_DETAIL_FACTOR[detail],
|
||||
dash: OVERHEAD_DASH,
|
||||
color: stroke,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
// Kontext-Domäne des Grundriss-Generators: zeichnet `project.context`
|
||||
// (Höhenlinien, importierte Gebäude/Terrain-Meshes) als dezente Referenz-
|
||||
// Konturen — für Meshes der Grundriss-Fussabdruck nahe der Objekt-Unterkante,
|
||||
// nicht das volle Drahtgitter.
|
||||
// nicht das volle Drahtgitter. Fussabdruck (Sockelkanten, entdoppelt) und Rahmen berechnet der
|
||||
// Rust-Kern (`src-tauri/core/src/plan_misc.rs`, [K3a]).
|
||||
|
||||
import type { Project } from "../../model/types";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import { NO_HATCH, SHOW_ALL, type CategoryDisplayResolver, type Primitive } from "./shared";
|
||||
|
||||
/** Dezente Plan-Farbe der Kontext-Konturen (gedämpftes Grau). */
|
||||
@@ -11,11 +13,6 @@ const CONTEXT_LINE_COLOR = "#9aa3ad";
|
||||
/** Strichstärke der Kontext-Konturen (mm Papier, dünn). */
|
||||
const CONTEXT_LINE_MM = 0.1;
|
||||
|
||||
/** Höhen-Toleranz (Meter): Dreieckskanten, deren beide Endpunkte höchstens so
|
||||
* weit über der Objekt-Unterkante (minZ) liegen, gelten als „Sockelkante" und
|
||||
* bilden den Grundriss-Fussabdruck eines importierten Gebäudes. */
|
||||
const FOOTPRINT_Z_TOL = 0.6;
|
||||
|
||||
/**
|
||||
* Zeichnet die Kontext-Schicht `project.context` in den Grundriss:
|
||||
* • ContourSet (Höhenlinien) → dünne Referenz-Linien (Z ignoriert).
|
||||
@@ -77,68 +74,41 @@ export function addContextContours(
|
||||
|
||||
/**
|
||||
* Zeichnet den Grundriss-Fussabdruck eines Meshes: Dreieckskanten nahe der
|
||||
* Unterkante (minZ + {@link FOOTPRINT_Z_TOL}), auf XY projiziert, über
|
||||
* quantisierte Endpunkt-Schlüssel entdoppelt. `positions` = flaches [x,y,z…]-
|
||||
* Array (Modell-Meter, z = Höhe), `indices` = Dreiecks-Indizes.
|
||||
* Unterkante (minZ + 0.6 m), auf XY projiziert, über 1-cm-quantisierte Endpunkte
|
||||
* entdoppelt. `positions` = flaches [x,y,z…]-Array (Modell-Meter, z = Höhe),
|
||||
* `indices` = Dreiecks-Indizes.
|
||||
*/
|
||||
function addMeshFootprint(out: Primitive[], positions: number[], indices: number[]): void {
|
||||
const vcount = Math.floor(positions.length / 3);
|
||||
if (vcount < 3 || indices.length < 3) return;
|
||||
let minZ = Infinity;
|
||||
for (let i = 2; i < positions.length; i += 3) if (positions[i] < minZ) minZ = positions[i];
|
||||
if (!Number.isFinite(minZ)) return;
|
||||
const zLimit = minZ + FOOTPRINT_Z_TOL;
|
||||
const q = (v: number) => Math.round(v * 100); // 1-cm-Quantisierung (Entdopplung)
|
||||
const seen = new Set<string>();
|
||||
const edge = (ia: number, ib: number) => {
|
||||
if (ia >= vcount || ib >= vcount) return;
|
||||
const za = positions[ia * 3 + 2];
|
||||
const zb = positions[ib * 3 + 2];
|
||||
if (za > zLimit || zb > zLimit) return; // nur Sockelkanten
|
||||
const ax = positions[ia * 3], ay = positions[ia * 3 + 1];
|
||||
const bx = positions[ib * 3], by = positions[ib * 3 + 1];
|
||||
// Kanten-Schlüssel richtungsunabhängig (kleinerer Endpunkt zuerst).
|
||||
const ka = `${q(ax)},${q(ay)}`;
|
||||
const kb = `${q(bx)},${q(by)}`;
|
||||
if (ka === kb) return;
|
||||
const key = ka < kb ? `${ka}|${kb}` : `${kb}|${ka}`;
|
||||
if (seen.has(key)) return;
|
||||
seen.add(key);
|
||||
const f = core().context_footprint_flat(Float64Array.from(positions), Float64Array.from(indices));
|
||||
for (let i = 0; i < f[0]; i++) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: { x: ax, y: ay },
|
||||
b: { x: bx, y: by },
|
||||
a: { x: f[1 + 4 * i], y: f[2 + 4 * i] },
|
||||
b: { x: f[3 + 4 * i], y: f[4 + 4 * i] },
|
||||
cls: "context-line",
|
||||
weightMm: CONTEXT_LINE_MM,
|
||||
color: CONTEXT_LINE_COLOR,
|
||||
});
|
||||
};
|
||||
for (let i = 0; i + 2 < indices.length; i += 3) {
|
||||
const a = indices[i], b = indices[i + 1], c = indices[i + 2];
|
||||
edge(a, b);
|
||||
edge(b, c);
|
||||
edge(c, a);
|
||||
}
|
||||
}
|
||||
|
||||
/** Grundriss-Rahmen eines Meshes (nur x/y) als vier Eckpunkte, oder `null` ohne Punkte. */
|
||||
function meshBboxCorners(positions: number[]): { x: number; y: number }[] | null {
|
||||
const b = core().context_bbox_flat(Float64Array.from(positions));
|
||||
if (b.length === 0) return null;
|
||||
return [
|
||||
{ x: b[0], y: b[1] },
|
||||
{ x: b[2], y: b[1] },
|
||||
{ x: b[2], y: b[3] },
|
||||
{ x: b[0], y: b[3] },
|
||||
];
|
||||
}
|
||||
|
||||
/** Zeichnet nur den achsenparallelen 2D-Umriss (Bounding-Box) eines Meshes —
|
||||
* für Terrain, dessen volles TIN-Gitter im Plan zu dicht wäre. */
|
||||
function addMeshBboxOutline(out: Primitive[], positions: number[]): void {
|
||||
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
||||
for (let i = 0; i + 2 < positions.length; i += 3) {
|
||||
const x = positions[i], y = positions[i + 1];
|
||||
if (x < minX) minX = x;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (y > maxY) maxY = y;
|
||||
}
|
||||
if (!Number.isFinite(minX)) return;
|
||||
const corners = [
|
||||
{ x: minX, y: minY },
|
||||
{ x: maxX, y: minY },
|
||||
{ x: maxX, y: maxY },
|
||||
{ x: minX, y: maxY },
|
||||
];
|
||||
const corners = meshBboxCorners(positions);
|
||||
if (!corners) return;
|
||||
for (let i = 0; i < 4; i++) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
@@ -157,28 +127,14 @@ function addMeshBboxOutline(out: Primitive[], positions: number[]): void {
|
||||
* trägt die `ContextObject.id` (analog `sectionLineId`, s. dort). Macht das
|
||||
* Objekt IRGENDWO innerhalb seiner Grundfläche anklickbar (nicht nur exakt auf
|
||||
* der dünnen Umriss-/Fussabdrucklinie) — wie bei Wänden, deren Poché-Fläche
|
||||
* ebenfalls als Ganzes klickbar ist (Nutzer-Wunsch: „eigene Elemente wie Wände").
|
||||
* `positions` = flaches [x,y,z…]-Array (Modell-Meter); die Bbox nutzt NUR x/y,
|
||||
* unabhängig von der Höhe.
|
||||
* ebenfalls als Ganzes klickbar ist.
|
||||
*/
|
||||
function addContextPickRegion(out: Primitive[], positions: number[], id: string): void {
|
||||
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
||||
for (let i = 0; i + 2 < positions.length; i += 3) {
|
||||
const x = positions[i], y = positions[i + 1];
|
||||
if (x < minX) minX = x;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (y > maxY) maxY = y;
|
||||
}
|
||||
if (!Number.isFinite(minX)) return;
|
||||
const pts = meshBboxCorners(positions);
|
||||
if (!pts) return;
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [
|
||||
{ x: minX, y: minY },
|
||||
{ x: maxX, y: minY },
|
||||
{ x: maxX, y: maxY },
|
||||
{ x: minX, y: maxY },
|
||||
],
|
||||
pts,
|
||||
fill: "none",
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
|
||||
@@ -9,18 +9,18 @@
|
||||
// Die Grösse kommt in PAPIER-MILLIMETERN herein und wird mit dem Massstab des
|
||||
// Plans in Modellmass umgerechnet (gleiche Linie wie die Bemassung, s.
|
||||
// `model/dimension.ts`): eine 3-mm-Pfeilspitze soll auf dem Papier 3 mm sein,
|
||||
// egal ob der Plan 1:50 oder 1:200 steht.
|
||||
// egal ob der Plan 1:50 oder 1:200 steht. Die Geometrie berechnet der Rust-Kern (`plan_misc.rs`, [K3a]).
|
||||
|
||||
import type { EndMark, Vec2 } from "../../model/types";
|
||||
import { mmToModel } from "../../model/dimension";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import type { Primitive } from "./shared";
|
||||
import { NO_HATCH } from "./shared";
|
||||
|
||||
/** Default-Grösse der Linienenden in Papier-Millimetern. */
|
||||
export const END_MARK_DEFAULT_SIZE_MM = 3;
|
||||
|
||||
/** Öffnungsverhältnis der Pfeilspitze (halbe Breite ÷ Länge) — schlanke Spitze. */
|
||||
const ARROW_ASPECT = 0.32;
|
||||
/** Kodierung der Linienenden im Kern (`plan_misc.rs`). */
|
||||
const MARK_CODE: Record<Exclude<EndMark, "none">, number> = { arrow: 1, arrowOpen: 2, dot: 3, tick: 4, square: 5 };
|
||||
|
||||
export interface EndMarkStyle {
|
||||
weightMm: number;
|
||||
@@ -49,82 +49,35 @@ export function addEndMark(
|
||||
style: EndMarkStyle,
|
||||
): number {
|
||||
if (!mark || mark === "none") return 0;
|
||||
const len = Math.hypot(dir.x, dir.y);
|
||||
if (len < 1e-9) return 0;
|
||||
const size = mmToModel(sizeMm, scaleDenominator);
|
||||
const ux = dir.x / len;
|
||||
const uy = dir.y / len;
|
||||
const nx = -uy;
|
||||
const ny = ux;
|
||||
const f = core().end_mark_flat(at.x, at.y, dir.x, dir.y, MARK_CODE[mark], sizeMm, scaleDenominator);
|
||||
if (f.length === 0) return 0;
|
||||
const { weightMm, color, greyed, drawingId } = style;
|
||||
|
||||
/** Fusspunkt der Spitze (size zurück entlang der Linie). */
|
||||
const base: Vec2 = { x: at.x - ux * size, y: at.y - uy * size };
|
||||
const half = size * ARROW_ASPECT;
|
||||
const wingA: Vec2 = { x: base.x + nx * half, y: base.y + ny * half };
|
||||
const wingB: Vec2 = { x: base.x - nx * half, y: base.y - ny * half };
|
||||
const line = (a: Vec2, b: Vec2) =>
|
||||
out.push({ kind: "line", a, b, cls: "draw2d", weightMm, dash: null, color, greyed, drawingId });
|
||||
|
||||
switch (mark) {
|
||||
case "arrow":
|
||||
let i = 2;
|
||||
for (let k = 0; k < f[1]; k++) {
|
||||
if (f[i] === 1) {
|
||||
const count = f[i + 1];
|
||||
const pts = Array.from({ length: count }, (_, j) => ({ x: f[i + 2 + 2 * j], y: f[i + 3 + 2 * j] }));
|
||||
out.push({ kind: "polygon", pts, fill: color, stroke: color, strokeWidthMm: weightMm, hatch: NO_HATCH, greyed, drawingId });
|
||||
i += 2 + 2 * count;
|
||||
} else if (f[i] === 2) {
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [at, wingA, wingB],
|
||||
fill: color,
|
||||
stroke: color,
|
||||
strokeWidthMm: weightMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
drawingId,
|
||||
});
|
||||
// Die gefüllte Spitze überdeckt die Linie — dort darf sie enden.
|
||||
return size;
|
||||
case "arrowOpen":
|
||||
line(wingA, at);
|
||||
line(wingB, at);
|
||||
// Offene Spitze: die Linie läuft bis zum Punkt durch (sie ist Teil des Bildes).
|
||||
return 0;
|
||||
case "dot":
|
||||
out.push({
|
||||
kind: "drawingCircle",
|
||||
center: at,
|
||||
r: size * 0.25,
|
||||
fill: color,
|
||||
stroke: color,
|
||||
kind: "line",
|
||||
a: { x: f[i + 1], y: f[i + 2] },
|
||||
b: { x: f[i + 3], y: f[i + 4] },
|
||||
cls: "draw2d",
|
||||
weightMm,
|
||||
dash: null,
|
||||
color,
|
||||
greyed,
|
||||
drawingId,
|
||||
});
|
||||
return 0;
|
||||
case "tick": {
|
||||
// 45°-Schrägstrich, mittig auf dem Endpunkt (SIA-Massstrich-Anmutung).
|
||||
const tx = (ux + nx) / Math.SQRT2;
|
||||
const ty = (uy + ny) / Math.SQRT2;
|
||||
const h = size / 2;
|
||||
line({ x: at.x - tx * h, y: at.y - ty * h }, { x: at.x + tx * h, y: at.y + ty * h });
|
||||
return 0;
|
||||
}
|
||||
case "square": {
|
||||
const h = size * 0.3;
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [
|
||||
{ x: at.x + (ux + nx) * h, y: at.y + (uy + ny) * h },
|
||||
{ x: at.x + (ux - nx) * h, y: at.y + (uy - ny) * h },
|
||||
{ x: at.x + (-ux - nx) * h, y: at.y + (-uy - ny) * h },
|
||||
{ x: at.x + (-ux + nx) * h, y: at.y + (-uy + ny) * h },
|
||||
],
|
||||
fill: color,
|
||||
stroke: color,
|
||||
strokeWidthMm: weightMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
drawingId,
|
||||
});
|
||||
return 0;
|
||||
i += 5;
|
||||
} else {
|
||||
out.push({ kind: "drawingCircle", center: { x: f[i + 1], y: f[i + 2] }, r: f[i + 3], fill: color, stroke: color, weightMm, greyed, drawingId });
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
return f[0];
|
||||
}
|
||||
|
||||
/** Punkt `p` um `d` in Richtung `dir` (normiert) zurückgezogen — für die Linienverkürzung. */
|
||||
|
||||
+124
-499
@@ -1,9 +1,12 @@
|
||||
// Öffnungs-Domäne des Grundriss-Generators: Tür-/Fenstersymbole je Detailgrad
|
||||
// (Blatt/Schwenkbogen/Anschlag bzw. Rahmen/Sprossen/Glas), das optionale
|
||||
// Rahmenband (Zarge/Blockrahmen) samt Schichteinzug aus der Typ-Bibliothek,
|
||||
// sowie das Legacy-Türsymbol (`Door`, vor der Öffnungs-Typ-Bibliothek).
|
||||
// Rahmenband (Zarge/Blockrahmen) samt Schichteinzug aus der Typ-Bibliothek.
|
||||
//
|
||||
// Die Geometrie entsteht im Rust-Kern (`src-tauri/core/src/plan_openings.rs`, [K3a]); hier bleibt
|
||||
// die Auflösung aus dem Modell (Typ-Bibliothek, Linien-Overrides) und die Übersetzung in
|
||||
// `Primitive`-Objekte mit Farbe, Strichstärke und `openingId`. Fällt mit [K3d] weg.
|
||||
|
||||
import type { Opening, Project, Vec2, Wall } from "../../model/types";
|
||||
import type { Opening, Project, Wall } from "../../model/types";
|
||||
import {
|
||||
getDoorType,
|
||||
getWindowType,
|
||||
@@ -11,16 +14,8 @@ import {
|
||||
sashesOfWindowType,
|
||||
wallTypeThickness,
|
||||
} from "../../model/types";
|
||||
import {
|
||||
doorLeaves,
|
||||
doorSymbol,
|
||||
openingGapQuad,
|
||||
openingJambs,
|
||||
wallAxisFrame,
|
||||
windowSymbol,
|
||||
} from "../../geometry/opening";
|
||||
import { wallReferenceOffset } from "../../model/wall";
|
||||
import { add, along, dot, scale, sub } from "../../model/geometry";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import {
|
||||
NO_HATCH,
|
||||
OVERHEAD_DASH,
|
||||
@@ -30,6 +25,17 @@ import {
|
||||
type Primitive,
|
||||
} from "./shared";
|
||||
|
||||
/** Linienklassen in der Reihenfolge der Kern-Kodierung (`plan_openings.rs`). */
|
||||
const LINE_CLS = [
|
||||
"door-leaf", "door-frame", "door-lintel", "opening-frame", "window-glass", "window-mullion",
|
||||
"window-sash", "window-stulp", "window-sill", "window-frame", "window-shading",
|
||||
] as const;
|
||||
/** Strichmuster (Kern-Kodierung): 1 Sturz, 2 Überkopf, 3 gepunktet. */
|
||||
const DASHES: (number[] | undefined)[] = [undefined, [0.18, 0.09], OVERHEAD_DASH, [0.04, 0.08]];
|
||||
const DETAIL_CODE: Record<DetailLevel, number> = { grob: 0, mittel: 1, fein: 2 };
|
||||
const LINTEL_CODE = { keine: 0, aussen: 1, innen: 2, beide: 3 } as const;
|
||||
const SILL_CODE = { aussen: 1, innen: 2, beide: 3 } as const;
|
||||
|
||||
/**
|
||||
* Aufgelöste Rahmen-Parameter (Typ-Bibliothek) einer Tür-/Fenster-Öffnung —
|
||||
* nur vorhanden, wenn die Öffnung einen Bauteil-Typ referenziert (`typeId`).
|
||||
@@ -74,133 +80,8 @@ function resolveOpeningFrameSpec(project: Project, o: Opening): OpeningFrameSpec
|
||||
}
|
||||
|
||||
/**
|
||||
* Rahmenband + Oberlicht-Andeutung einer Tür-/Fenstertyp-Öffnung im
|
||||
* Grundriss-Schnitt. Nur aufgerufen, wenn `resolveOpeningFrameSpec` einen Typ
|
||||
* liefert — sonst bleibt die Darstellung exakt wie zuvor (kein neues Primitiv).
|
||||
*
|
||||
* • Zarge — schmales Umlauf-Rahmenband, ringsum um `frameWidth`
|
||||
* von der vollen Öffnung (Pfosten × Wanddicke) nach innen eingezogen.
|
||||
* • Blockrahmen (Tür) — kräftiges Rechteckprofil, sitzt PROUD an der
|
||||
* gewählten Fläche (kein Einzug an den Pfosten, nur eine Tiefenscheibe von
|
||||
* `frameWidth` ab der Nah-Fläche), kräftigere Linie.
|
||||
* • Schichteinzug — verschiebt die Nah-Fläche des Rahmens um
|
||||
* `insetFromFace` von der gewählten Wandfläche nach innen; die Gegenfläche
|
||||
* bleibt unverändert (der Rahmen reicht weiterhin bis dorthin).
|
||||
* • Oberlicht — Überkopf-Andeutung (gestrichelte Linie quer über die
|
||||
* Öffnung), nur wenn `transomHeight > 0`.
|
||||
*/
|
||||
function addOpeningFrameBand(
|
||||
out: Primitive[],
|
||||
project: Project,
|
||||
wall: Wall,
|
||||
o: Opening,
|
||||
spec: OpeningFrameSpec,
|
||||
greyed: boolean,
|
||||
): void {
|
||||
const jambs = openingJambs(wall, o);
|
||||
if (!jambs) return;
|
||||
const { n } = wallAxisFrame(wall);
|
||||
const total = wallTypeThickness(getWallType(project, wall));
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
// "aussen" = die Fläche der ERSTEN Wandtyp-Schicht (kleinster Achs-Offset,
|
||||
// s. addWallPoche/`off` startet bei `refOff-total/2`) — mit `n = leftNormal(u)`
|
||||
// ist das die NEGATIVE Seite. Bug bis 2026-07-12: hier stand `+total/2` für
|
||||
// "aussen" (positive Seite, tatsächlich "innen") — Türrahmenbänder mit
|
||||
// insetFace:"aussen" landeten dadurch an der falschen Wandfläche.
|
||||
const outerFace = refOff - total / 2; // "aussen"-Fläche (−n, erste Schicht)
|
||||
const innerFace = refOff + total / 2; // "innen"-Fläche (+n, letzte Schicht)
|
||||
|
||||
// Schichteinzug: die GEWÄHLTE Fläche rückt um `insetFromFace` nach innen; die
|
||||
// gegenüberliegende Fläche bleibt unverändert (der Rahmen reicht weiterhin
|
||||
// bis dorthin) — vgl. DoorType.insetFromFace/WindowType.insetFromFace.
|
||||
const clampedInset = Math.max(0, Math.min(spec.insetFromFace, total));
|
||||
const nearIsAussen = spec.insetFace !== "innen";
|
||||
// "Nach innen" heisst: von der gewählten Fläche RICHTUNG WANDMITTE (refOff) —
|
||||
// von aussen (negative Seite) aus AUFWÄRTS (+clampedInset), von innen
|
||||
// (positive Seite) aus ABWÄRTS (−clampedInset).
|
||||
const faceNear = nearIsAussen ? outerFace + clampedInset : innerFace - clampedInset;
|
||||
const faceFar = nearIsAussen ? innerFace : outerFace;
|
||||
const lo = Math.min(faceNear, faceFar);
|
||||
const hi = Math.max(faceNear, faceFar);
|
||||
|
||||
const { jambStart, jambEnd } = jambs;
|
||||
const color = o.color ?? POCHE_STROKE;
|
||||
|
||||
// Rahmen-Rechteck NUR bei Türen zeichnen. Beim Fenster stellt bereits
|
||||
// `windowSymbol` den Rahmen dar (voller Öffnungsumriss + Glaslinien); ein
|
||||
// zusätzliches Band ergäbe ein doppeltes, verschachteltes Rechteck — genau
|
||||
// das wirkte im 2D „nicht korrekt". Die Tür hat dort nur Blatt+Bogen, daher
|
||||
// ist ihr Rahmenband die einzige Rahmenkontur und bleibt.
|
||||
if (o.kind === "door") {
|
||||
const frameWidth = Math.max(0, spec.frameWidth);
|
||||
const isBlock = spec.frameKind === "blockrahmen";
|
||||
let bandLo: number;
|
||||
let bandHi: number;
|
||||
let jStart: Vec2;
|
||||
let jEnd: Vec2;
|
||||
let weightMm: number;
|
||||
if (isBlock) {
|
||||
// Blockrahmen: volle Öffnungsbreite (kein Pfosten-Einzug), nur eine
|
||||
// Tiefenscheibe von frameWidth ab der Nah-Fläche — sitzt proud VOR/auf der
|
||||
// Laibung, statt schmal darin zu verschwinden (Zargen-Optik). "aussen"
|
||||
// liegt bei `lo` (s. Kommentar zu outerFace/innerFace oben), die Scheibe
|
||||
// beginnt dort und wächst RICHTUNG WANDMITTE (Richtung `hi`).
|
||||
const depth = Math.min(frameWidth, hi - lo);
|
||||
bandLo = nearIsAussen ? lo : hi - depth;
|
||||
bandHi = nearIsAussen ? lo + depth : hi;
|
||||
jStart = jambStart;
|
||||
jEnd = jambEnd;
|
||||
weightMm = SYMBOL_HAIRLINE_MM * 2.2;
|
||||
} else {
|
||||
// Zarge: ringsum um frameWidth von der vollen Öffnung eingezogenes,
|
||||
// schmales Rahmenband (Laibungs-Anschlaglinie).
|
||||
const jambSpan = Math.hypot(jambEnd.x - jambStart.x, jambEnd.y - jambStart.y);
|
||||
const jambInset = Math.min(frameWidth, jambSpan / 2);
|
||||
jStart = along(jambStart, jambEnd, jambInset);
|
||||
jEnd = along(jambEnd, jambStart, jambInset);
|
||||
const depthInset = Math.min(frameWidth, (hi - lo) / 2);
|
||||
bandLo = lo + depthInset;
|
||||
bandHi = hi - depthInset;
|
||||
weightMm = SYMBOL_HAIRLINE_MM;
|
||||
}
|
||||
|
||||
// Geschlossenes Rechteck aus 4 Kanten (Primitive "line", nicht "polygon" —
|
||||
// so bleibt das Band per `cls` selektierbar/testbar wie die übrigen Symbole).
|
||||
const p1 = add(jStart, scale(n, bandLo));
|
||||
const p2 = add(jEnd, scale(n, bandLo));
|
||||
const p3 = add(jEnd, scale(n, bandHi));
|
||||
const p4 = add(jStart, scale(n, bandHi));
|
||||
const edges: [Vec2, Vec2][] = [
|
||||
[p1, p2],
|
||||
[p2, p3],
|
||||
[p3, p4],
|
||||
[p4, p1],
|
||||
];
|
||||
for (const [a, b] of edges) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a,
|
||||
b,
|
||||
cls: "opening-frame",
|
||||
weightMm,
|
||||
color,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Die frühere Oberlicht-Andeutung (gestrichelte Linie quer über die ganze
|
||||
// Öffnung bei transomHeight>0) ist entfernt (Nutzer-Report: erscheint immer
|
||||
// auf der Wandachse, unabhängig davon, ob die Schnittebene den Kämpfer
|
||||
// überhaupt trifft — im horizontalen Grundriss-Schnitt architektonisch nicht
|
||||
// aussagekräftig, ein Kämpfer ist ein Höhen-, kein Grundriss-Merkmal).
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffnungs-Symbol (Fenster/Tür) je Detailgrad. Anders als das Legacy-`addDoorSymbol`
|
||||
* arbeitet diese Funktion über die reinen Geometrie-Helfer (opening.ts) und taggt
|
||||
* ihre Primitive mit `openingId`, sodass die Öffnung im Plan selektierbar ist.
|
||||
* Öffnungs-Symbol (Fenster/Tür) je Detailgrad. Arbeitet über den Kern (`plan_openings.rs`) und
|
||||
* taggt ihre Primitive mit `openingId`, sodass die Öffnung im Plan selektierbar ist.
|
||||
*
|
||||
* Tür:
|
||||
* • grob — gerade Türblatt-Linie (die Lücke kommt aus der ausgesparten Poché).
|
||||
@@ -208,8 +89,8 @@ function addOpeningFrameBand(
|
||||
* • fein — + Anschlag-Striche an beiden Pfosten.
|
||||
* Fenster:
|
||||
* • grob — eine einzelne Glaslinie über die Lücke.
|
||||
* • mittel — Rahmen-Rechteck (Umriss) + eine Glaslinie.
|
||||
* • fein — Rahmen + zwei Glaslinien (Doppelverglasung angedeutet).
|
||||
* • mittel — Rahmen-Rechteck (Umriss) + Pfosten/Stulp.
|
||||
* • fein — + Flügelrahmen, Fensterbank, Anschlagkerben.
|
||||
*/
|
||||
export function addOpeningSymbol(
|
||||
out: Primitive[],
|
||||
@@ -220,374 +101,118 @@ export function addOpeningSymbol(
|
||||
detail: DetailLevel,
|
||||
lwMm: number,
|
||||
): void {
|
||||
if (o.kind === "door") {
|
||||
const sym = doorSymbol(wall, o);
|
||||
if (!sym) return;
|
||||
// Unsichtbares Pick-Polygon über der Öffnungslücke (Laibung × Wanddicke) —
|
||||
// damit die Tür wie ein Fenster per Punkt-in-Polygon über die ganze
|
||||
// Öffnungsfläche selektierbar ist (Türsymbol besteht sonst nur aus dünnem
|
||||
// Blatt + Bogen, die man exakt treffen müsste). fill/stroke "none" ⇒ zeichnet
|
||||
// nichts; `pickOpening` (PlanView) testet nur die `pts`.
|
||||
const gap = openingGapQuad(project, wall, o);
|
||||
if (gap) {
|
||||
const total = wallTypeThickness(getWallType(project, wall));
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
const door = o.kind === "door";
|
||||
const wt = door ? undefined : getWindowType(project, o);
|
||||
const frameSpec = door ? resolveOpeningFrameSpec(project, o) : undefined;
|
||||
const sashes = wt ? sashesOfWindowType(wt) : [];
|
||||
const strokeColor = o.color ?? POCHE_STROKE;
|
||||
// Linien-Kategorien einzeln übersteuerbar: Rahmen-Schnitt, Rahmen-Aufsicht, Fenster
|
||||
// (Flügelrahmen/Sprossen), Sims. `undefined` ⇒ Strichfarbe/Haarlinie.
|
||||
const frameColor = o.frameLine?.color ?? strokeColor;
|
||||
const frameWeight = o.frameLine?.weight ?? lwMm;
|
||||
const frameViewWeight = o.frameViewLine?.weight ?? frameWeight;
|
||||
const colors = [
|
||||
"",
|
||||
strokeColor,
|
||||
frameColor,
|
||||
o.frameViewLine?.color ?? frameColor,
|
||||
o.sashLine?.color ?? strokeColor,
|
||||
o.sillLineStyle?.color ?? strokeColor,
|
||||
];
|
||||
const b: number[] = [
|
||||
wall.start.x, wall.start.y, wall.end.x, wall.end.y, total, refOff,
|
||||
o.position, o.width, door ? 1 : 0, DETAIL_CODE[detail],
|
||||
// Tür
|
||||
(o.swing ?? "left") !== "left" ? 1 : 0,
|
||||
(o.openingDir ?? "in") !== "in" ? 1 : 0,
|
||||
(o.hinge ?? "start") !== "start" ? 1 : 0,
|
||||
o.swingAngle ?? Number.NaN,
|
||||
(o.doorType ?? "normal") === "wandoeffnung" ? 1 : 0,
|
||||
door ? Math.max(1, Math.round(getDoorType(project, o)?.leafCount ?? 1)) : 1,
|
||||
LINTEL_CODE[o.lintelLines ?? "beide"],
|
||||
// Rahmenband
|
||||
frameSpec ? 1 : 0,
|
||||
frameSpec?.frameWidth ?? 0,
|
||||
frameSpec?.frameKind === "blockrahmen" ? 1 : 0,
|
||||
frameSpec?.insetFromFace ?? 0,
|
||||
frameSpec?.insetFace === "innen" ? 1 : 0,
|
||||
// Fenster
|
||||
wt ? 1 : 0,
|
||||
wt ? wt.frameWidth ?? 0.06 : 0,
|
||||
wt?.frameDepth ?? Number.NaN,
|
||||
wt?.insetFromFace ?? Number.NaN,
|
||||
wt?.insetFace === "innen" ? 1 : 0,
|
||||
o.wingCount ?? Number.NaN,
|
||||
detail === "fein" ? 2 : 1,
|
||||
wt?.sillLine ? SILL_CODE[wt.sillLine.faces] : 0,
|
||||
wt?.sillLine?.view === "unter" ? 1 : 0,
|
||||
wt?.shading?.create ? 1 : 0,
|
||||
wt?.shading?.box.width ?? 0,
|
||||
wt?.shading?.box.height ?? 0,
|
||||
// Strichstärken
|
||||
SYMBOL_HAIRLINE_MM,
|
||||
o.frameLine?.weight ?? SYMBOL_HAIRLINE_MM,
|
||||
frameViewWeight,
|
||||
o.sashLine?.weight ?? SYMBOL_HAIRLINE_MM,
|
||||
o.sillLineStyle?.weight ?? SYMBOL_HAIRLINE_MM,
|
||||
sashes.length,
|
||||
];
|
||||
for (const s of sashes) {
|
||||
b.push(s.kind === "pfosten" ? 1 : 0, s.autoWidth === false ? 0 : 1, s.width ?? Number.NaN, s.postWidth ?? Number.NaN,
|
||||
s.opening && s.opening !== "fest" ? 1 : 0);
|
||||
}
|
||||
const f = core().plan_opening_flat(Float64Array.from(b));
|
||||
if (f.length === 0) return;
|
||||
const openingId = o.id;
|
||||
const n = f[0];
|
||||
let i = 1;
|
||||
for (let k = 0; k < n; k++) {
|
||||
if (f[i] === 1) {
|
||||
const count = f[i + 4];
|
||||
const pts = new Array<{ x: number; y: number }>(count);
|
||||
for (let j = 0; j < count; j++) pts[j] = { x: f[i + 5 + 2 * j], y: f[i + 6 + 2 * j] };
|
||||
const frame = f[i + 1] === 1;
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: gap,
|
||||
pts,
|
||||
fill: "none",
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
stroke: frame ? colors[f[i + 3]] : "none",
|
||||
strokeWidthMm: f[i + 2],
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
openingId,
|
||||
});
|
||||
}
|
||||
// Tür-Typ „wandoeffnung": reiner Wanddurchbruch — KEIN Türblatt, KEIN
|
||||
// Schwenkbogen. Nur die Öffnung/Laibung bleibt (die Wandlücke kommt aus der
|
||||
// ausgesparten Poché; Sturz-/Anschlaglinien werden weiter unten gezeichnet).
|
||||
// Entspricht `oeff_tuer_typ == "wandoeffnung"` im Rhino-Plugin.
|
||||
const isWandoeffnung = (o.doorType ?? "normal") === "wandoeffnung";
|
||||
if (!isWandoeffnung) {
|
||||
// Türblätter (1 oder 2 Flügel, je DoorType.leafCount). Zweiflüglig ⇒ zwei
|
||||
// halbbreite Blätter an gegenüberliegenden Pfosten (symmetrische Doppeltür).
|
||||
const leafCount = Math.max(1, Math.round(getDoorType(project, o)?.leafCount ?? 1));
|
||||
for (const leaf of doorLeaves(wall, o, leafCount)) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: leaf.hinge,
|
||||
b: leaf.openEnd,
|
||||
cls: "door-leaf",
|
||||
weightMm: SYMBOL_HAIRLINE_MM,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
});
|
||||
// mittel + fein: Schwenkbogen von geschlossen → offen je Blatt.
|
||||
if (detail !== "grob") {
|
||||
out.push({
|
||||
kind: "arc",
|
||||
center: leaf.hinge,
|
||||
from: leaf.closedEnd,
|
||||
to: leaf.openEnd,
|
||||
r: leaf.radius,
|
||||
cls: "door-swing",
|
||||
weightMm: SYMBOL_HAIRLINE_MM,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// fein: Anschlag-Striche an beiden Pfosten (quer zur Wand).
|
||||
if (detail === "fein") {
|
||||
const reveal = 0.06;
|
||||
for (const jamb of [sym.jambStart, sym.jambEnd]) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: add(jamb, scale(sym.normal, reveal)),
|
||||
b: add(jamb, scale(sym.normal, -reveal)),
|
||||
cls: "door-frame",
|
||||
weightMm: SYMBOL_HAIRLINE_MM,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
// Rahmenband (Zarge/Blockrahmen) + Oberlicht-Andeutung — nur wenn die
|
||||
// Öffnung einen Türtyp referenziert (siehe `resolveOpeningFrameSpec`).
|
||||
const doorFrameSpec = resolveOpeningFrameSpec(project, o);
|
||||
if (doorFrameSpec) addOpeningFrameBand(out, project, wall, o, doorFrameSpec, greyed);
|
||||
// Sturzlinien (SIA, gestrichelt) — Überkopf-Projektion des Sturzes quer über
|
||||
// die Öffnung an der Wand-Innen-/Aussenkante. Entspricht `_make_tuer_sturz_curves`
|
||||
// im Rhino-Plugin. Default „beide" wenn nicht explizit gesetzt.
|
||||
const lintelMode = o.lintelLines ?? "beide";
|
||||
if (lintelMode !== "keine") {
|
||||
const jambs = openingJambs(wall, o);
|
||||
if (jambs) {
|
||||
const { n } = wallAxisFrame(wall);
|
||||
const total = wallTypeThickness(getWallType(project, wall));
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
const halfD = total / 2;
|
||||
// "aussen" = negative Seite (erste Wandtyp-Schicht), s. Kommentar in
|
||||
// addOpeningFrameBand — Bug bis 2026-07-12: stand hier vertauscht.
|
||||
const outerOff = refOff - halfD;
|
||||
const innerOff = refOff + halfD;
|
||||
// Strichmuster: gestrichelt (Überkopf-Projektion, SIA-Konvention).
|
||||
const dash: number[] = [0.18, 0.09];
|
||||
const strokeColor = o.color ?? POCHE_STROKE;
|
||||
/** Linie quer über die Öffnung am gegebenen Perp-Offset. */
|
||||
const lintelLine = (perpOff: number) => ({
|
||||
a: add(jambs.jambStart, scale(n, perpOff)),
|
||||
b: add(jambs.jambEnd, scale(n, perpOff)),
|
||||
});
|
||||
if (lintelMode === "aussen" || lintelMode === "beide") {
|
||||
const seg = lintelLine(outerOff);
|
||||
out.push({
|
||||
kind: "line" as const,
|
||||
a: seg.a,
|
||||
b: seg.b,
|
||||
cls: "door-lintel",
|
||||
weightMm: SYMBOL_HAIRLINE_MM,
|
||||
dash,
|
||||
color: strokeColor,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
});
|
||||
}
|
||||
if (lintelMode === "innen" || lintelMode === "beide") {
|
||||
const seg = lintelLine(innerOff);
|
||||
out.push({
|
||||
kind: "line" as const,
|
||||
a: seg.a,
|
||||
b: seg.b,
|
||||
cls: "door-lintel",
|
||||
weightMm: SYMBOL_HAIRLINE_MM,
|
||||
dash,
|
||||
color: strokeColor,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Fenster: Rahmen (mittel/fein) + Glaslinie(n) je Detailgrad + Fenstertyp.
|
||||
const wt = getWindowType(project, o);
|
||||
// Flügeltabelle NUR übergeben, wenn ein Fenstertyp auflösbar ist — fehlt er
|
||||
// (kein `typeId`/unbekannt), bleibt `windowSymbol` beim reinen
|
||||
// `o.wingCount`-Alt-Verhalten (siehe dortiger Kommentar, Regressionssicherheit).
|
||||
const spec = wt
|
||||
? {
|
||||
sashes: sashesOfWindowType(wt),
|
||||
frameWidth: wt.frameWidth ?? 0.06,
|
||||
frameDepth: wt.frameDepth,
|
||||
insetFromFace: wt.insetFromFace,
|
||||
insetFace: wt.insetFace,
|
||||
}
|
||||
: undefined;
|
||||
// Glaslinienzahl NUR für den Alt-Pfad (kein `spec`) relevant — der typisierte
|
||||
// Pfad entscheidet die Anzahl selbst nach SIA-Detailgrad (s. windowSymbol).
|
||||
const glassCount = detail === "fein" ? 2 : 1;
|
||||
const sym = windowSymbol(project, wall, o, glassCount, spec, detail);
|
||||
if (!sym) return;
|
||||
// Unsichtbares Pick-Polygon über der Öffnungslücke — macht das Fenster über
|
||||
// die ganze Fläche selektierbar, auch bei „grob" (nur eine Glaslinie, sonst
|
||||
// schwer zu treffen). Siehe Tür-Zweig oben.
|
||||
const wgap = openingGapQuad(project, wall, o);
|
||||
if (wgap) {
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: wgap,
|
||||
fill: "none",
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
});
|
||||
}
|
||||
// ── SIA-Fensterdarstellung, nach Detailgrad gestaffelt ────────────────────
|
||||
// grob (1:100): weisse Öffnung + EINE dünne Glaslinie, sonst nichts.
|
||||
// mittel (1:50): Blendrahmen-Rechteck + Pfosten-Trennlinien + Stulp-Mittel-
|
||||
// quadrat je Flügel-Junction + Glaslinie(n).
|
||||
// fein (1:20): zusätzlich Flügelrahmen, Stulp als ZWEI Rechtecke, Fensterbank
|
||||
// (aussen) und Anschlag-/Laibungskerben — deutlich reicher als mittel.
|
||||
const strokeColor = o.color ?? POCHE_STROKE;
|
||||
const { n: wn } = wallAxisFrame(wall);
|
||||
|
||||
if (detail === "grob") {
|
||||
// SIA 1:100 — nur eine dünne Glaslinie mittig über die weisse Öffnung.
|
||||
// Zählt zur "Fenster"-Kategorie (sashLine) — dieselbe Glaslinie, die bei
|
||||
// mittel/fein früher sichtbar war (jetzt dort entfernt, s. Fenster-Session).
|
||||
const g = sym.glassLines[Math.floor(sym.glassLines.length / 2)] ?? sym.glassLines[0];
|
||||
if (g) {
|
||||
i += 5 + 2 * count;
|
||||
} else if (f[i] === 2) {
|
||||
const slot = f[i + 3];
|
||||
const dash = DASHES[f[i + 4]];
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: g[0],
|
||||
b: g[1],
|
||||
cls: "window-glass",
|
||||
weightMm: o.sashLine?.weight ?? SYMBOL_HAIRLINE_MM,
|
||||
color: o.sashLine?.color ?? strokeColor,
|
||||
a: { x: f[i + 5], y: f[i + 6] },
|
||||
b: { x: f[i + 7], y: f[i + 8] },
|
||||
cls: LINE_CLS[f[i + 1]],
|
||||
weightMm: f[i + 2],
|
||||
...(dash ? { dash } : {}),
|
||||
...(slot ? { color: colors[slot] } : {}),
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
openingId,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Linien-Kategorien einzeln übersteuerbar (Nutzer-Wunsch): Rahmen-Schnitt
|
||||
// (Laibungs-/Stulp-Blöcke, geschnittenes Profil), Rahmen-Aufsicht (die
|
||||
// durchlaufende Kontur DAZWISCHEN, projiziert statt geschnitten), Fenster
|
||||
// (Flügelrahmen/Sprossen), Sims (Auf-/Untersicht-Andeutung, s. u.).
|
||||
// `undefined` ⇒ bisheriges Verhalten (strokeColor/SYMBOL_HAIRLINE_MM);
|
||||
// `frameViewLine` fällt zusätzlich auf `frameLine` zurück (eine Farbe für
|
||||
// Schnitt+Aufsicht, bis der Nutzer sie explizit trennt).
|
||||
const frameColor = o.frameLine?.color ?? strokeColor;
|
||||
const frameWeight = o.frameLine?.weight ?? lwMm;
|
||||
const frameHairline = o.frameLine?.weight ?? SYMBOL_HAIRLINE_MM;
|
||||
const frameViewColor = o.frameViewLine?.color ?? frameColor;
|
||||
const frameViewWeight = o.frameViewLine?.weight ?? frameWeight;
|
||||
const sashColor = o.sashLine?.color ?? strokeColor;
|
||||
const sashWeight = o.sashLine?.weight ?? SYMBOL_HAIRLINE_MM;
|
||||
|
||||
// Blendrahmen-Rechteck in Aufsicht (mittel + fein) — die durchlaufende
|
||||
// Kontur zwischen den geschnittenen Laibungs-/Stulp-Blöcken.
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: sym.frame,
|
||||
fill: "none",
|
||||
stroke: frameViewColor,
|
||||
strokeWidthMm: frameViewWeight,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
});
|
||||
// Pfosten-/Flügel-Trennlinien (Alt-Pfad ohne Typ — zählt als "Fenster").
|
||||
for (const [a, b] of sym.mullionLines) {
|
||||
out.push({ kind: "line", a, b, cls: "window-mullion", weightMm: sashWeight, color: sashColor, greyed, openingId: o.id });
|
||||
}
|
||||
// fein: Flügelrahmen (Flügelkontur) je öffenbarem Flügel — Schachtelung
|
||||
// Blendrahmen → Flügelrahmen → Glas (Feindetail, hebt fein klar von mittel ab).
|
||||
if (detail === "fein") {
|
||||
for (const pts of sym.sashFrames) {
|
||||
for (let i = 0; i < pts.length; i++) {
|
||||
out.push({ kind: "line", a: pts[i], b: pts[(i + 1) % pts.length], cls: "window-sash", weightMm: sashWeight, color: sashColor, greyed, openingId: o.id });
|
||||
}
|
||||
}
|
||||
}
|
||||
// Laibungs-Blöcke an den Öffnungsenden (Blendrahmen-Querschnitt) — Teil des
|
||||
// Blendrahmens, zählt zu "Rahmen".
|
||||
for (const mark of sym.jambMarks) {
|
||||
for (let i = 0; i < mark.length; i++) {
|
||||
out.push({ kind: "line", a: mark[i], b: mark[(i + 1) % mark.length], cls: "window-stulp", weightMm: frameHairline, color: frameColor, greyed, openingId: o.id });
|
||||
}
|
||||
}
|
||||
// Stulp-Mittelquadrat je Flügel-Junction (SIA-Signatur): mittel = EIN Quadrat,
|
||||
// fein = ZWEI anliegende Rechtecke (die beiden Stulp-Stäbe der Flügel) —
|
||||
// bereits tiefenkorrekt (inset-/insetFace-bewusst) in windowSymbol berechnet.
|
||||
// Sitzt zwischen den Flügeln, zählt zu "Fenster" (separat vom Blendrahmen
|
||||
// steuerbar — Nutzer-Feedback).
|
||||
for (const mark of sym.meetingMarks) {
|
||||
for (let i = 0; i < mark.length; i++) {
|
||||
out.push({ kind: "line", a: mark[i], b: mark[(i + 1) % mark.length], cls: "window-stulp", weightMm: sashWeight, color: sashColor, greyed, openingId: o.id });
|
||||
}
|
||||
}
|
||||
// Glaslinien (Anzahl je Detailgrad/Verglasung, s. glassCount).
|
||||
for (const [a, b] of sym.glassLines) {
|
||||
out.push({ kind: "line", a, b, cls: "window-glass", weightMm: SYMBOL_HAIRLINE_MM, greyed, openingId: o.id });
|
||||
}
|
||||
// Oberlicht-Andeutung (transom, gestrichelt) — mittel/fein.
|
||||
const windowFrameSpec = resolveOpeningFrameSpec(project, o);
|
||||
if (windowFrameSpec) addOpeningFrameBand(out, project, wall, o, windowFrameSpec, greyed);
|
||||
// fein: Fensterbank (aussen) + Anschlag-/Laibungskerben.
|
||||
if (detail === "fein") {
|
||||
const jb = openingJambs(wall, o);
|
||||
if (jb) {
|
||||
const { jambStart, jambEnd } = jb;
|
||||
// Tatsächliche Rahmen-Aussenkante (NICHT pauschal die volle Wandfläche —
|
||||
// ein eingezogener Rahmen, s. {@link WindowType.insetFromFace}, hat seine
|
||||
// Aussenkante weiter innen). "Aussen" ist der ALGEBRAISCH KLEINERE der
|
||||
// beiden Tiefen-Werte in sym.frame (s. windowSymbol: frontRel für
|
||||
// insetFace:"aussen" ist negativ) — welcher der beiden Eckpunkt-Paare das
|
||||
// ist, hängt von insetFace ab, daher robust über Math.min bestimmt statt
|
||||
// fest über sym.frame[0].
|
||||
const outerN = Math.min(
|
||||
dot(sub(sym.frame[0], jambStart), wn),
|
||||
dot(sub(sym.frame[2], jambStart), wn),
|
||||
);
|
||||
// Fensterbank: schmales Rechteck vor der Aussenfläche, seitlich ~3 cm
|
||||
// überstehend, ~4 cm auskragend (SIA-Sims-Andeutung im Grundriss).
|
||||
// Auskragung geht IMMER weiter nach aussen (algebraisch kleiner, s. o.).
|
||||
const ov = 0.03;
|
||||
const proj = 0.04;
|
||||
const s0 = along(jambStart, jambEnd, -ov);
|
||||
const s1 = along(jambEnd, jambStart, -ov);
|
||||
const b0 = add(s0, scale(wn, outerN));
|
||||
const b1 = add(s1, scale(wn, outerN));
|
||||
const b2 = add(s1, scale(wn, outerN - proj));
|
||||
const b3 = add(s0, scale(wn, outerN - proj));
|
||||
for (const [a, b] of [[b0, b1], [b1, b2], [b2, b3], [b3, b0]] as [Vec2, Vec2][]) {
|
||||
out.push({ kind: "line", a, b, cls: "window-sill", weightMm: SYMBOL_HAIRLINE_MM, color: strokeColor, greyed, openingId: o.id });
|
||||
}
|
||||
// Anschlag-Kerben an beiden Pfosten (kurz quer zur Wand).
|
||||
const reveal = 0.06;
|
||||
for (const jamb of [jambStart, jambEnd]) {
|
||||
out.push({ kind: "line", a: add(jamb, scale(wn, reveal)), b: add(jamb, scale(wn, -reveal)), cls: "window-frame", weightMm: SYMBOL_HAIRLINE_MM, color: strokeColor, greyed, openingId: o.id });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Auf-/Untersicht-Andeutung ({@link WindowType.sillLine}): eine Referenzlinie
|
||||
// an der Rahmen-Aussen-/Innenkante (NICHT der Wandachse — ersetzt die frühere,
|
||||
// falsch positionierte Brüstungslinie), nur wenn der Typ es explizit wählt.
|
||||
// "auf" (Aufsicht von oben, dünn gepunktet) vs. "unter" (Untersicht von unten,
|
||||
// gestrichelt wie die übrigen Überkopf-Projektionen).
|
||||
if (detail !== "grob" && wt?.sillLine) {
|
||||
const { faces, view } = wt.sillLine;
|
||||
const dash = view === "unter" ? OVERHEAD_DASH : [0.04, 0.08];
|
||||
const sillColor = o.sillLineStyle?.color ?? strokeColor;
|
||||
const sillWeight = o.sillLineStyle?.weight ?? SYMBOL_HAIRLINE_MM;
|
||||
// Welches der beiden sym.frame-Eckpunkt-Paare physisch "aussen" ist, hängt
|
||||
// von insetFace ab (s. windowSymbol) — robust über den Tiefen-Vergleich
|
||||
// entlang wn bestimmt statt fest über den Index.
|
||||
const pair01IsOuter = dot(sym.frame[0], wn) <= dot(sym.frame[3], wn);
|
||||
const outerPair: [Vec2, Vec2] = pair01IsOuter ? [sym.frame[0], sym.frame[1]] : [sym.frame[3], sym.frame[2]];
|
||||
const innerPair: [Vec2, Vec2] = pair01IsOuter ? [sym.frame[3], sym.frame[2]] : [sym.frame[0], sym.frame[1]];
|
||||
if (faces === "aussen" || faces === "beide") {
|
||||
out.push({ kind: "line", a: outerPair[0], b: outerPair[1], cls: "window-sill", weightMm: sillWeight, dash, color: sillColor, greyed, openingId: o.id });
|
||||
}
|
||||
if (faces === "innen" || faces === "beide") {
|
||||
out.push({ kind: "line", a: innerPair[0], b: innerPair[1], cls: "window-sill", weightMm: sillWeight, dash, color: sillColor, greyed, openingId: o.id });
|
||||
}
|
||||
}
|
||||
// Rollladen-/Sonnenschutzkasten (P0-Minimalfassung, reine 2D-Kontur): ein
|
||||
// gestricheltes Rechteck ÜBER der Öffnung, ausserhalb der Wand-Aussenfläche —
|
||||
// Breite = `shading.box.width` (0/fehlt ⇒ Öffnungsbreite), die zweite
|
||||
// Rechteckseite = `shading.box.height`. Die 3D-Tiefe (`box.depth`) bleibt für
|
||||
// eine spätere 3D-Box reserviert (Fokus hier bewusst 2D, s. Aufgabenstellung).
|
||||
// Gestrichelt wie die übrigen Überkopf-Projektionen (Sturz/Oberlicht) — der
|
||||
// Kasten liegt oberhalb der Schnittebene und wird nur angedeutet.
|
||||
if (wt?.shading?.create) {
|
||||
const jambs = openingJambs(wall, o);
|
||||
if (jambs) {
|
||||
const { u, n: nrm } = wallAxisFrame(wall);
|
||||
const total = wallTypeThickness(getWallType(project, wall));
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
// "aussen" = negative Seite (erste Wandtyp-Schicht), s. Kommentar in
|
||||
// addOpeningFrameBand — Bug bis 2026-07-12: stand hier vertauscht (der
|
||||
// Rollladenkasten landete an der Innenfläche statt aussen am Sturz).
|
||||
const outerFace = refOff - total / 2;
|
||||
const axisWidth = Math.hypot(
|
||||
jambs.jambEnd.x - jambs.jambStart.x,
|
||||
jambs.jambEnd.y - jambs.jambStart.y,
|
||||
);
|
||||
const boxWidth = wt.shading.box.width > 0 ? wt.shading.box.width : axisWidth;
|
||||
const boxHeight = Math.max(0, wt.shading.box.height);
|
||||
const center = add(jambs.jambStart, scale(u, axisWidth / 2));
|
||||
const half = boxWidth / 2;
|
||||
const c1 = add(center, scale(u, -half));
|
||||
const c2 = add(center, scale(u, half));
|
||||
const p1 = add(c1, scale(nrm, outerFace));
|
||||
const p2 = add(c2, scale(nrm, outerFace));
|
||||
const p3 = add(c2, scale(nrm, outerFace + boxHeight));
|
||||
const p4 = add(c1, scale(nrm, outerFace + boxHeight));
|
||||
const edges: [Vec2, Vec2][] = [
|
||||
[p1, p2],
|
||||
[p2, p3],
|
||||
[p3, p4],
|
||||
[p4, p1],
|
||||
];
|
||||
for (const [a, b] of edges) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a,
|
||||
b,
|
||||
cls: "window-shading",
|
||||
weightMm: SYMBOL_HAIRLINE_MM,
|
||||
dash: OVERHEAD_DASH,
|
||||
color: o.color ?? POCHE_STROKE,
|
||||
greyed,
|
||||
openingId: o.id,
|
||||
});
|
||||
}
|
||||
i += 9;
|
||||
} else {
|
||||
out.push({
|
||||
kind: "arc",
|
||||
center: { x: f[i + 2], y: f[i + 3] },
|
||||
from: { x: f[i + 4], y: f[i + 5] },
|
||||
to: { x: f[i + 6], y: f[i + 7] },
|
||||
r: f[i + 8],
|
||||
cls: "door-swing",
|
||||
weightMm: f[i + 1],
|
||||
greyed,
|
||||
openingId,
|
||||
});
|
||||
i += 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
// Strichpunkt-Schnittlinie mit Endmarken + Label) — NICHT zu verwechseln mit
|
||||
// `generateSectionPlan()` (der Schnitt-ALS-Plan-Übersetzung, bleibt Orchestrator
|
||||
// in `../generatePlan.ts`): diese Domäne zeichnet nur das Führungssymbol EINER
|
||||
// Schnitt-/Ansichtsebene IM Grundriss.
|
||||
// Schnitt-/Ansichtsebene IM Grundriss. Die Geometrie berechnet der Rust-Kern (`plan_misc.rs`, [K3a]).
|
||||
|
||||
import { leftNormal, normalize, sub } from "../../model/geometry";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import type { Project } from "../../model/types";
|
||||
import { NO_HATCH, SHOW_ALL, type CategoryDisplayResolver, type Primitive } from "./shared";
|
||||
|
||||
@@ -26,10 +26,6 @@ const SECTION_LINE_MM = 0.18;
|
||||
const SECTION_LINE_MARK_MM = 0.5;
|
||||
/** Strichpunkt-Muster der Schnittlinie (lange Striche + Punkt, mm Papier). */
|
||||
const SECTION_LINE_DASH: number[] = [6, 1.5, 0.4, 1.5];
|
||||
/** Länge der Endmarken (Querstrich/Pfeil) in Modell-Metern. */
|
||||
const SECTION_MARK_LEN = 0.6;
|
||||
/** Halbe Breite des unsichtbaren Pick-Bands über der Linie (Modell-Meter). */
|
||||
const SECTION_PICK_HALF = 0.3;
|
||||
/** Schrifthöhe des Schnitt-Labels (Modell-Meter). */
|
||||
const SECTION_LABEL_H = 0.5;
|
||||
|
||||
@@ -72,100 +68,48 @@ export function addSectionLines(
|
||||
const line = level.linePoints;
|
||||
if (!line) continue;
|
||||
const [p0, p1] = line;
|
||||
const axis = sub(p1, p0);
|
||||
const len = Math.hypot(axis.x, axis.y);
|
||||
if (len < 1e-6) continue;
|
||||
const u = normalize(axis);
|
||||
const n = leftNormal(u); // (-uy, ux)
|
||||
const sign = level.directionSign ?? 1;
|
||||
const bn = { x: n.x * sign, y: n.y * sign }; // Blicknormale
|
||||
|
||||
// Hauptlinie (Strichpunkt-Haarlinie).
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: p0,
|
||||
b: p1,
|
||||
cls: "section-line",
|
||||
weightMm: SECTION_LINE_MM,
|
||||
dash: SECTION_LINE_DASH,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
|
||||
// Endmarken (Querstrich + Richtungspfeil + Label) an beiden Enden.
|
||||
const half = SECTION_MARK_LEN / 2;
|
||||
for (const end of [p0, p1]) {
|
||||
// Querstrich senkrecht zur Linie, mittig am Endpunkt.
|
||||
const t0 = { x: end.x - n.x * half, y: end.y - n.y * half };
|
||||
const t1 = { x: end.x + n.x * half, y: end.y + n.y * half };
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: t0,
|
||||
b: t1,
|
||||
cls: "section-line",
|
||||
weightMm: SECTION_LINE_MARK_MM,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
// Richtungspfeil: vom Querstrich-Ende auf der Blickseite entlang bn.
|
||||
const base = { x: end.x + bn.x * half, y: end.y + bn.y * half };
|
||||
const tip = { x: base.x + bn.x * SECTION_MARK_LEN, y: base.y + bn.y * SECTION_MARK_LEN };
|
||||
const wingBack = {
|
||||
x: tip.x - bn.x * SECTION_MARK_LEN * 0.4,
|
||||
y: tip.y - bn.y * SECTION_MARK_LEN * 0.4,
|
||||
};
|
||||
const w = SECTION_MARK_LEN * 0.25;
|
||||
out.push({ kind: "line", a: base, b: tip, cls: "section-line", weightMm: SECTION_LINE_MARK_MM, color: SECTION_LINE_INK, greyed });
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: tip,
|
||||
b: { x: wingBack.x + u.x * w, y: wingBack.y + u.y * w },
|
||||
cls: "section-line",
|
||||
weightMm: SECTION_LINE_MARK_MM,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: tip,
|
||||
b: { x: wingBack.x - u.x * w, y: wingBack.y - u.y * w },
|
||||
cls: "section-line",
|
||||
weightMm: SECTION_LINE_MARK_MM,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
// Label (Kurz-Tag) etwas hinter dem Pfeil, horizontal.
|
||||
const labelAt = {
|
||||
x: tip.x + bn.x * SECTION_MARK_LEN * 0.4 - SECTION_LABEL_H * 0.3,
|
||||
y: tip.y + bn.y * SECTION_MARK_LEN * 0.4 + SECTION_LABEL_H * 0.5,
|
||||
};
|
||||
out.push({
|
||||
kind: "drawingText",
|
||||
at: labelAt,
|
||||
text: sectionLabelTag(level.name),
|
||||
heightM: SECTION_LABEL_H,
|
||||
angle: 0,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
const f = core().section_line_flat(p0.x, p0.y, p1.x, p1.y, level.directionSign ?? 1);
|
||||
if (f.length === 0) continue;
|
||||
let i = 1;
|
||||
for (let k = 0; k < f[0]; k++) {
|
||||
if (f[i] === 2) {
|
||||
const main = f[i + 1] === 0;
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: { x: f[i + 2], y: f[i + 3] },
|
||||
b: { x: f[i + 4], y: f[i + 5] },
|
||||
cls: "section-line",
|
||||
weightMm: main ? SECTION_LINE_MM : SECTION_LINE_MARK_MM,
|
||||
...(main ? { dash: SECTION_LINE_DASH } : {}),
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
i += 6;
|
||||
} else if (f[i] === 5) {
|
||||
out.push({
|
||||
kind: "drawingText",
|
||||
at: { x: f[i + 1], y: f[i + 2] },
|
||||
text: sectionLabelTag(level.name),
|
||||
heightM: SECTION_LABEL_H,
|
||||
angle: 0,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
i += 3;
|
||||
} else {
|
||||
// Unsichtbares Pick-Band (Rechteck entlang der Linie) — klickbar per Punkt-in-Polygon in
|
||||
// PlanView, trägt die DrawingLevel-Id.
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [0, 1, 2, 3].map((j) => ({ x: f[i + 1 + 2 * j], y: f[i + 2 + 2 * j] })),
|
||||
fill: "none",
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
hatch: NO_HATCH,
|
||||
sectionLineId: level.id,
|
||||
});
|
||||
i += 9;
|
||||
}
|
||||
}
|
||||
|
||||
// Unsichtbares Pick-Band (Rechteck entlang der Linie) — klickbar per
|
||||
// Punkt-in-Polygon in PlanView, trägt die DrawingLevel-Id.
|
||||
const off = { x: n.x * SECTION_PICK_HALF, y: n.y * SECTION_PICK_HALF };
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [
|
||||
{ x: p0.x + off.x, y: p0.y + off.y },
|
||||
{ x: p1.x + off.x, y: p1.y + off.y },
|
||||
{ x: p1.x - off.x, y: p1.y - off.y },
|
||||
{ x: p0.x - off.x, y: p0.y - off.y },
|
||||
],
|
||||
fill: "none",
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
hatch: NO_HATCH,
|
||||
sectionLineId: level.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
+67
-152
@@ -2,46 +2,21 @@
|
||||
// Auf-/Abpfeil, Zwischenpodest und Aussenlinie — mit dem Grundriss-Schnitt
|
||||
// (Tritte unter der Schnitthöhe durchgezogen, darüber gestrichelt/verdeckt +
|
||||
// SIA-Bruchlinie).
|
||||
//
|
||||
// Die Primitive entstehen im Rust-Kern (`src-tauri/core/src/plan_stairs.rs`, [K3a]); hier nur die
|
||||
// Übersetzung der flachen Liste in `Primitive`-Objekte (Farbe, Graustufen, `stairId`).
|
||||
// Fällt mit [K3d] weg, wenn der Plan-Puffer direkt aus Rust kommt.
|
||||
|
||||
import type { Project, Stair, Vec2 } from "../../model/types";
|
||||
import type { Project, Stair } from "../../model/types";
|
||||
import { stairVerticalExtent } from "../../model/wall";
|
||||
import { stairCut, stairGeometry, stairOutline } from "../../geometry/stair";
|
||||
import type { SpiralOutlineSegments } from "../../geometry/stair";
|
||||
import { encodeStair } from "../../geometry/stair";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import { NO_HATCH, POCHE_STROKE, type Primitive } from "./shared";
|
||||
|
||||
/**
|
||||
* Zeichnet die Wendel-Aussenlinie: Innen-/Aussenbogen als Arc-Primitive plus zwei
|
||||
* radiale Schliesslinien. Wird von `addStairSymbol` aufgerufen wenn `shape === "spiral"`.
|
||||
*/
|
||||
function _addSpiralOutline(
|
||||
out: Primitive[],
|
||||
seg: SpiralOutlineSegments,
|
||||
stroke: string,
|
||||
lwMm: number,
|
||||
greyed: boolean,
|
||||
stairId: string,
|
||||
): void {
|
||||
// Radiale Schliesslinien (Startwinkel + Endwinkel).
|
||||
for (const [a, b] of seg.lines) {
|
||||
out.push({ kind: "line", a, b, cls: "stair-outline", weightMm: lwMm, color: stroke, greyed, stairId });
|
||||
}
|
||||
// Innen- und Aussenbogen.
|
||||
for (const arc of seg.arcs) {
|
||||
const from: Vec2 = { x: arc.cx + arc.r * Math.cos(arc.a0), y: arc.cy + arc.r * Math.sin(arc.a0) };
|
||||
const to: Vec2 = { x: arc.cx + arc.r * Math.cos(arc.a1), y: arc.cy + arc.r * Math.sin(arc.a1) };
|
||||
out.push({
|
||||
kind: "arc",
|
||||
center: { x: arc.cx, y: arc.cy },
|
||||
from,
|
||||
to,
|
||||
r: arc.r,
|
||||
cls: "stair-outline",
|
||||
weightMm: lwMm,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
}
|
||||
}
|
||||
/** Linienklassen in der Reihenfolge der Kern-Kodierung (`plan_stairs.rs`). */
|
||||
const LINE_CLS = ["stair-outline", "stair-tread", "stair-break", "stair-run", "stair-arrow"] as const;
|
||||
/** Strichmuster der verdeckten Tritte (Meter). */
|
||||
const TREAD_DASH = [0.12, 0.08];
|
||||
|
||||
/**
|
||||
* Treppen-Symbol im Grundriss (DOSSIER/SIA):
|
||||
@@ -62,124 +37,64 @@ export function addStairSymbol(
|
||||
cutHeight: number,
|
||||
): void {
|
||||
const { zBottom, zTop } = stairVerticalExtent(project, stair);
|
||||
const totalRise = zTop - zBottom;
|
||||
const geo = stairGeometry(stair, totalRise);
|
||||
const cut = stairCut(geo, cutHeight);
|
||||
const below = new Set(cut.belowIndices);
|
||||
const f = core().plan_stair_flat(
|
||||
encodeStair(stair),
|
||||
zTop - zBottom,
|
||||
cutHeight,
|
||||
lwMm,
|
||||
stair.arrowStyle === "filled" ? 1 : 0,
|
||||
);
|
||||
if (f.length === 0) return;
|
||||
const stroke = stair.color ?? POCHE_STROKE;
|
||||
const stairId = stair.id;
|
||||
|
||||
// Umriss + Tritt-Trennlinien je Stufe. Der letzte Punkt jedes Tritt-Rechtecks
|
||||
// liefert die vordere Kante (Auftritt); wir zeichnen jede Tritt-Kante.
|
||||
for (const tr of geo.treads) {
|
||||
const isBelow = below.has(tr.index);
|
||||
// Tritt-Rechteck als reine Umrisslinie (keine Füllung), durchgezogen wenn
|
||||
// unter der Schnittebene, sonst gestrichelt (verdeckt).
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: tr.pts,
|
||||
fill: "none",
|
||||
stroke,
|
||||
strokeWidthMm: lwMm * 0.7,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
// Zusätzliche Auftrittskante (vordere Kante der Stufe) etwas kräftiger.
|
||||
const front: [Vec2, Vec2] = [tr.pts[1], tr.pts[2]];
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: front[0],
|
||||
b: front[1],
|
||||
cls: "stair-tread",
|
||||
weightMm: lwMm * (isBelow ? 1.0 : 0.6),
|
||||
dash: isBelow ? null : [0.12, 0.08],
|
||||
color: stroke,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
}
|
||||
|
||||
// Zwischenpodest (L/Wendel-Auge): Umriss-Polygon.
|
||||
if (geo.landing && geo.landing.length >= 3) {
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: geo.landing,
|
||||
fill: "none",
|
||||
stroke,
|
||||
strokeWidthMm: lwMm * 0.7,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
}
|
||||
|
||||
// SIA-Bruchlinie (Doppelstrich diagonal über den Schnitt-Tritt).
|
||||
if (cut.breakLine) {
|
||||
for (const [a, b] of cut.breakLine) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a,
|
||||
b,
|
||||
cls: "stair-break",
|
||||
weightMm: lwMm,
|
||||
color: stroke,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
const n = f[0];
|
||||
let i = 1;
|
||||
for (let k = 0; k < n; k++) {
|
||||
switch (f[i]) {
|
||||
case 1: {
|
||||
const count = f[i + 3];
|
||||
const pts = new Array<{ x: number; y: number }>(count);
|
||||
for (let j = 0; j < count; j++) pts[j] = { x: f[i + 4 + 2 * j], y: f[i + 5 + 2 * j] };
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts,
|
||||
fill: f[i + 2] ? stroke : "none",
|
||||
stroke,
|
||||
strokeWidthMm: f[i + 1],
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
i += 4 + 2 * count;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: { x: f[i + 4], y: f[i + 5] },
|
||||
b: { x: f[i + 6], y: f[i + 7] },
|
||||
cls: LINE_CLS[f[i + 1]],
|
||||
weightMm: f[i + 2],
|
||||
...(LINE_CLS[f[i + 1]] === "stair-tread" ? { dash: f[i + 3] ? TREAD_DASH : null } : {}),
|
||||
color: stroke,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
i += 8;
|
||||
break;
|
||||
default:
|
||||
out.push({
|
||||
kind: "arc",
|
||||
center: { x: f[i + 2], y: f[i + 3] },
|
||||
from: { x: f[i + 4], y: f[i + 5] },
|
||||
to: { x: f[i + 6], y: f[i + 7] },
|
||||
r: f[i + 8],
|
||||
cls: "stair-outline",
|
||||
weightMm: f[i + 1],
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
i += 9;
|
||||
}
|
||||
}
|
||||
|
||||
// Lauflinie (Lauflinie) — kräftig, durchgezogen.
|
||||
for (let i = 0; i < geo.runLine.length - 1; i++) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: geo.runLine[i],
|
||||
b: geo.runLine[i + 1],
|
||||
cls: "stair-run",
|
||||
weightMm: lwMm,
|
||||
color: stroke,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
}
|
||||
// Auf-/Abpfeil an der Spitze der Lauflinie. "filled" = gefülltes Dreieck
|
||||
// (SIA-Vollpfeil), sonst der offene Winkelpfeil (zwei Linien, Default).
|
||||
const [h1, tip, h2] = geo.arrow.head;
|
||||
if (stair.arrowStyle === "filled") {
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [h1, tip, h2],
|
||||
fill: stroke,
|
||||
stroke,
|
||||
strokeWidthMm: lwMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
} else {
|
||||
out.push({ kind: "line", a: h1, b: tip, cls: "stair-arrow", weightMm: lwMm, color: stroke, greyed, stairId });
|
||||
out.push({ kind: "line", a: h2, b: tip, cls: "stair-arrow", weightMm: lwMm, color: stroke, greyed, stairId });
|
||||
}
|
||||
|
||||
// Aussenlinie (Outline) der Treppe — schliessendes Umriss-Polygon (gerade/L)
|
||||
// bzw. Innen-/Aussenbogen + radiale Schliesslinien (Wendel).
|
||||
// Entspricht `_aussen_gerade` / `_aussen_l_polygon` / `_aussen_wendel` im
|
||||
// Rhino-Plugin. Stets durchgezogen, volle Strichstärke.
|
||||
const outline = stairOutline(stair, totalRise);
|
||||
if (outline.polygon && outline.polygon.length >= 3) {
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: outline.polygon,
|
||||
fill: "none",
|
||||
stroke,
|
||||
strokeWidthMm: lwMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
stairId,
|
||||
});
|
||||
}
|
||||
if (outline.spiral) {
|
||||
_addSpiralOutline(out, outline.spiral, stroke, lwMm, greyed, stairId);
|
||||
}
|
||||
}
|
||||
+118
-360
@@ -2,24 +2,19 @@
|
||||
// die Wand-Footprints (für das Verdecken darunterliegender Decken-Umrisse, s.
|
||||
// {@link ../ceilings}) und die eigentliche Wand-Poché (Schichten + Umriss +
|
||||
// Öffnungsaussparungen + T-Stoss-/Gehrungs-Behandlung).
|
||||
//
|
||||
// Die Geometrie der Poché entsteht im Rust-Kern (`src-tauri/core/src/plan_walls.rs`, [K3a]); hier
|
||||
// bleibt die Stilauflösung aus dem Modell (Bauteil, Schraffur, Farbe, Fugen-Linienstil) und die
|
||||
// Übersetzung in `Primitive`-Objekte. Fällt mit [K3d] weg.
|
||||
|
||||
import type { LayerCategory, Opening, Project, Vec2, Wall } from "../../model/types";
|
||||
import { getComponent, getWallType, wallTypeThickness } from "../../model/types";
|
||||
import { wallReferenceOffset } from "../../model/wall";
|
||||
import { openingInterval } from "../../geometry/opening";
|
||||
import {
|
||||
add,
|
||||
along,
|
||||
clippedBand,
|
||||
dot,
|
||||
leftNormal,
|
||||
lineIntersect,
|
||||
normalize,
|
||||
scale,
|
||||
sub,
|
||||
} from "../../model/geometry";
|
||||
import { leftNormal, normalize, sub } from "../../model/geometry";
|
||||
import type { Line } from "../../model/geometry";
|
||||
import type { WallCuts } from "../../model/joins";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import {
|
||||
HATCH_INK,
|
||||
HATCH_PAPER,
|
||||
@@ -33,6 +28,7 @@ import {
|
||||
resolveHatch,
|
||||
resolveHatchId,
|
||||
type DetailLevel,
|
||||
type HatchRender,
|
||||
type Primitive,
|
||||
} from "./shared";
|
||||
|
||||
@@ -61,38 +57,6 @@ export function wallGaps(
|
||||
return gaps.sort((a, b) => a.from - b.from);
|
||||
}
|
||||
|
||||
/** Toleranz für die Achsen-Intervall-Arithmetik der Durchgangswand-Aussparungen. */
|
||||
export const CUTOUT_EPS = 1e-9;
|
||||
|
||||
/**
|
||||
* Zieht die Loch-Intervalle `holes` vom Segment `[s,e]` ab und liefert die
|
||||
* verbleibenden (gezeichneten) Teil-Intervalle in Achsen-Metern. Löcher werden
|
||||
* auf `[s,e]` geklemmt, sortiert und vereinigt; leeres Ergebnis heisst „ganz
|
||||
* ausgespart". Ist `holes` leer, kommt exakt `[[s,e]]` zurück (unverändertes
|
||||
* Verhalten für Wände ohne Aussparung).
|
||||
*/
|
||||
export function subtractIntervals(
|
||||
s: number,
|
||||
e: number,
|
||||
holes: Array<[number, number]>,
|
||||
): Array<[number, number]> {
|
||||
const clipped = holes
|
||||
.map(([a, b]): [number, number] => [
|
||||
Math.max(s, Math.min(a, b)),
|
||||
Math.min(e, Math.max(a, b)),
|
||||
])
|
||||
.filter(([a, b]) => b > a + CUTOUT_EPS)
|
||||
.sort((p, q) => p[0] - q[0]);
|
||||
const parts: Array<[number, number]> = [];
|
||||
let cursor = s;
|
||||
for (const [a, b] of clipped) {
|
||||
if (a > cursor + CUTOUT_EPS) parts.push([cursor, a]);
|
||||
if (b > cursor) cursor = b;
|
||||
}
|
||||
if (cursor < e - CUTOUT_EPS) parts.push([cursor, e]);
|
||||
return parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wand-Footprint als orientiertes Rechteck (OBB) für das Verdecken der
|
||||
* darunterliegenden Decke im Grundriss: Achs-Startpunkt + Einheits-Richtung `u`
|
||||
@@ -133,49 +97,37 @@ export function buildWallFootprints(project: Project, walls: Wall[]): WallFootpr
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parametrisches Intervall [t0,t1] ⊆ [0,1], über das die Strecke `pa→pb`
|
||||
* INNERHALB des Wand-Footprints liegt (also von der Wand verdeckt). `null`, wenn
|
||||
* die Strecke den Footprint nicht schneidet. OBB-Test über zwei Slabs: Projektion
|
||||
* auf die Achse `u` (Bereich [−half, len+half]) und auf die Normale `m` (Bereich
|
||||
* [refOff−half, refOff+half]); das Schnitt-Intervall beider Slabs ∩ [0,1] ist die
|
||||
* verdeckte Strecke.
|
||||
*/
|
||||
export function segmentInsideWallBand(
|
||||
pa: Vec2,
|
||||
pb: Vec2,
|
||||
fp: WallFootprint,
|
||||
): [number, number] | null {
|
||||
const d = sub(pb, pa);
|
||||
const rel = sub(pa, fp.a);
|
||||
const clipSlab = (
|
||||
f0: number,
|
||||
fd: number,
|
||||
lo: number,
|
||||
hi: number,
|
||||
): [number, number] | null => {
|
||||
if (Math.abs(fd) < 1e-12)
|
||||
return f0 >= lo - CUTOUT_EPS && f0 <= hi + CUTOUT_EPS ? [0, 1] : null;
|
||||
let ta = (lo - f0) / fd;
|
||||
let tb = (hi - f0) / fd;
|
||||
if (ta > tb) [ta, tb] = [tb, ta];
|
||||
return [ta, tb];
|
||||
};
|
||||
const su = clipSlab(dot(rel, fp.u), dot(d, fp.u), -fp.half, fp.len + fp.half);
|
||||
if (!su) return null;
|
||||
const sm = clipSlab(
|
||||
dot(rel, fp.m),
|
||||
dot(d, fp.m),
|
||||
fp.refOff - fp.half,
|
||||
fp.refOff + fp.half,
|
||||
);
|
||||
if (!sm) return null;
|
||||
const t0 = Math.max(0, su[0], sm[0]);
|
||||
const t1 = Math.min(1, su[1], sm[1]);
|
||||
return t1 > t0 + CUTOUT_EPS ? [t0, t1] : null;
|
||||
}
|
||||
const lineBuf = (l: Line | null | undefined): number[] =>
|
||||
l ? [1, l.point.x, l.point.y, l.dir.x, l.dir.y] : [0, 0, 0, 0, 0];
|
||||
|
||||
const length = (w: Wall): number => Math.hypot(w.end.x - w.start.x, w.end.y - w.start.y);
|
||||
/** Eingabe der Kern-Funktion `plan_wall_poche_flat` (Aufbau: `plan_walls.rs`). */
|
||||
function encodeWallPoche(
|
||||
wall: Wall,
|
||||
layerThickness: number[],
|
||||
total: number,
|
||||
refOff: number,
|
||||
gaps: WallGap[],
|
||||
cuts: WallCuts,
|
||||
grob: boolean,
|
||||
viewOnly: boolean,
|
||||
): Float64Array {
|
||||
const b: number[] = [wall.start.x, wall.start.y, wall.end.x, wall.end.y, total, refOff, grob ? 1 : 0, viewOnly ? 1 : 0];
|
||||
b.push(layerThickness.length, ...layerThickness);
|
||||
b.push(...lineBuf(cuts.startCut), ...lineBuf(cuts.endCut));
|
||||
const lc = cuts.layerCuts;
|
||||
b.push(lc ? 1 : 0);
|
||||
if (lc) {
|
||||
for (let i = 0; i < layerThickness.length; i++) {
|
||||
b.push(...lineBuf(lc.start[i]), ...lineBuf(lc.end[i]), ...lineBuf(lc.startSide[i]), ...lineBuf(lc.endSide[i]));
|
||||
}
|
||||
}
|
||||
const sc = cuts.spanCutouts ?? [];
|
||||
b.push(sc.length);
|
||||
for (const c of sc) b.push(c.from, c.to, c.offA, c.offB);
|
||||
b.push(gaps.length);
|
||||
for (const g of gaps) b.push(g.from, g.to);
|
||||
return Float64Array.from(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wand als gefüllte Schnittfläche (Poché), um Öffnungen ausgespart.
|
||||
@@ -188,6 +140,9 @@ const length = (w: Wall): number => Math.hypot(w.end.x - w.start.x, w.end.y - w.
|
||||
* volle Wanddicke (Füllung = Farbe des „Backbone"-Bauteils mit höchster
|
||||
* joinPriority) mit dicker Umrisslinie. Bewusst vereinfacht (≙ DOSSIER
|
||||
* „Einfach").
|
||||
*
|
||||
* Segmente, Gehrungsbänder, Schichtfugen und Durchgangswand-Aussparungen berechnet der Kern;
|
||||
* hier kommen nur Stil und Pick-ID (`wallId`) dazu.
|
||||
*/
|
||||
export function addWallPoche(
|
||||
out: Primitive[],
|
||||
@@ -206,311 +161,114 @@ export function addWallPoche(
|
||||
): void {
|
||||
const wt = getWallType(project, wall);
|
||||
const total = wallTypeThickness(wt);
|
||||
// Versatz der Schichtstapelung über die Dicke gemäß Referenzlinie (center=0,
|
||||
// left=+T/2, right=−T/2). Alle Band-Offsets unten werden hierum verschoben,
|
||||
// sodass die Achse bei „außen"/„innen" auf der jeweiligen Wandfläche liegt.
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
// Jede Schicht-/Umrissfläche trägt die Wand-ID, damit ein Links-Klick die
|
||||
// GANZE Wand (alle Bänder) markiert und die PlanView die wallId nach oben
|
||||
// melden kann.
|
||||
const wallId = wall.id;
|
||||
// Achswinkel der Wand (Modell, Grad) — treibt wandbezogene Schraffuren
|
||||
// ({@link resolveHatch}), damit z. B. eine Diagonale oder die Dämmungsstriche
|
||||
// mit der Wandorientierung mitdrehen.
|
||||
// Achswinkel der Wand (Modell, Grad) — treibt wandbezogene Schraffuren ({@link resolveHatch}).
|
||||
const wallAngleDeg =
|
||||
(Math.atan2(wall.end.y - wall.start.y, wall.end.x - wall.start.x) * 180) / Math.PI;
|
||||
// Strich-/Umrandungsfarbe der Wand: optionale Übersteuerung (wall.color),
|
||||
// sonst der Default-Poché-Strich. Betrifft NUR die Linienfarbe (Umriss +
|
||||
// Schichtfugen), nicht die Schicht-Füllfarben/Schraffuren.
|
||||
// Strich-/Umrandungsfarbe der Wand: optionale Übersteuerung (wall.color), sonst der
|
||||
// Default-Poché-Strich. Betrifft NUR die Linienfarbe, nicht die Schicht-Füllfarben/Schraffuren.
|
||||
const stroke = wall.color ?? POCHE_STROKE;
|
||||
|
||||
// Öffnungs-Intervalle entlang der Wandachse, sortiert (bereits vereint).
|
||||
const openings = gaps;
|
||||
|
||||
// Wand in Segmente zwischen den Öffnungen zerlegen.
|
||||
let cursor = 0;
|
||||
const segments: Array<[number, number]> = [];
|
||||
for (const op of openings) {
|
||||
if (op.from > cursor) segments.push([cursor, op.from]);
|
||||
cursor = Math.max(cursor, op.to);
|
||||
}
|
||||
const axisLen = length(wall);
|
||||
if (cursor < axisLen) segments.push([cursor, axisLen]);
|
||||
|
||||
const outlineMm = wallLwMm * OUTLINE_DETAIL_FACTOR[detail];
|
||||
const layerLineMm = LAYER_LINE_MM * LAYER_DETAIL_FACTOR[detail];
|
||||
// Vereinfachte Füllung (grob): immer schwarze Vollfüllung, keine Schraffur
|
||||
|
||||
// Durchgangswand-Aussparungen (Phase 1c): über diese Achsen-Intervalle × Quer-
|
||||
// Offsetbereiche wird die Nah-Putz-Zone der Durchgangswand echt ausgeschnitten
|
||||
// (der Abzweig-Kern sticht durch). `offA` ist stets die Nahfläche, `offB` die
|
||||
// Rückgrat-Nahfläche (siehe SpanCutout in model/joins.ts). Leer ⇒ heutiges
|
||||
// Verhalten (Wand ohne T-Durchstoss).
|
||||
const spanCutouts = cuts.spanCutouts ?? [];
|
||||
const f = core().plan_wall_poche_flat(
|
||||
encodeWallPoche(wall, wt.layers.map((l) => l.thickness), total, refOff, gaps, cuts, detail === "grob", viewOnly),
|
||||
);
|
||||
if (f.length === 0) return;
|
||||
|
||||
// Kanten-Indizes der inneren Gehrungs-Stirnflächen (die Diagonalen am Knoten).
|
||||
// clippedBand liefert [A.start, A.end, B.end, B.start] → Kante 1 (A.end→B.end)
|
||||
// ist die endCut-Stirnfläche, Kante 3 (B.start→A.start) die startCut-Stirnfläche.
|
||||
// Diese werden NICHT umrissen: sonst 45°-Naht zwischen gleichfarbigen Schichten
|
||||
// + überschießende Gehrungs-Barbe am Eck-Apex. Freie Enden (kein Cut) bleiben
|
||||
// rechtwinklig gestrichen. Die Längskanten (Schichtfugen) bleiben stets sichtbar.
|
||||
const joinEdges = (startCut: Line | null, endCut: Line | null): number[] => {
|
||||
const e: number[] = [];
|
||||
if (endCut) e.push(1);
|
||||
if (startCut) e.push(3);
|
||||
return e;
|
||||
};
|
||||
|
||||
for (const [s, e] of segments) {
|
||||
const p1 = along(wall.start, wall.end, s);
|
||||
const p2 = along(wall.start, wall.end, e);
|
||||
// Nur die echten Wandenden bekommen die Gehrung. Türnahe Segmentenden
|
||||
// bleiben rechtwinklig (kein Schnitt).
|
||||
const startCut = s <= 1e-6 ? cuts.startCut : null;
|
||||
const endCut = e >= axisLen - 1e-6 ? cuts.endCut : null;
|
||||
|
||||
if (viewOnly) {
|
||||
// Ansichts-Wand (unter der Schnittebene): ein Umriss über die volle Dicke
|
||||
// als Haarlinie, ohne Füllung/Schraffur. Segment-/Gehrungs-/Öffnungs-Logik
|
||||
// bleibt dieselbe wie im Schnittfall (nur eben ohne Poché).
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: clippedBand(p1, p2, refOff - total / 2, refOff + total / 2, startCut, endCut),
|
||||
fill: "none",
|
||||
stroke,
|
||||
strokeWidthMm: layerLineMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
noStrokeEdges: joinEdges(startCut, endCut),
|
||||
wallId,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
if (detail === "grob") {
|
||||
// Eine Sammelfläche über die volle Dicke, ohne Schraffur, dicker Umriss.
|
||||
// Bei grob: immer Vollschwarz-Füllung gemäß SIA 400 Anhang B.9, Figur 36
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: clippedBand(p1, p2, refOff - total / 2, refOff + total / 2, startCut, endCut),
|
||||
fill: HATCH_INK,
|
||||
stroke,
|
||||
strokeWidthMm: outlineMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
noStrokeEdges: joinEdges(startCut, endCut),
|
||||
wallId,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// mittel/fein: Schichten von außen (-T/2) nach innen (+T/2) stapeln. Jede
|
||||
// Schicht löst Bauteil (Füllfarbe) + Schraffur (Muster/Maßstab/Winkel/Farbe)
|
||||
// auf. Die Bänder tragen NUR Füllung + Schraffur (kein eigener Umriss); jede
|
||||
// innere Schichtfuge wird als EIGENSTÄNDIGE, stilisierbare Linie gezeichnet.
|
||||
const bandJoinEdges = joinEdges(startCut, endCut);
|
||||
// Nur die Aussparungen, die dieses Segment [s,e] entlang der Achse berühren.
|
||||
const segCutouts = spanCutouts.filter(
|
||||
(c) =>
|
||||
Math.min(c.from, c.to) < e - CUTOUT_EPS &&
|
||||
Math.max(c.from, c.to) > s + CUTOUT_EPS,
|
||||
);
|
||||
// Punkt entlang der Wandachse bei Achsen-Meter `d` (p1/p2 an den Rändern).
|
||||
const axisPt = (d: number): Vec2 =>
|
||||
d === s ? p1 : d === e ? p2 : along(wall.start, wall.end, d);
|
||||
// Materialbewusster T-Stoss (siehe resolveJoinPriority in model/joins.ts):
|
||||
// liegt eine Pro-Schicht-Cut-Überschreibung vor, ersetzt sie PRO SCHICHT den
|
||||
// einheitlichen startCut/endCut — nur an den echten Wandenden (dieselbe
|
||||
// Maskierung wie oben für startCut/endCut, s <= 1e-6 / e >= axisLen-1e-6).
|
||||
// Fehlt sie, bleibt alles wie zuvor (startCut/endCut für jede Schicht).
|
||||
const layerCuts = cuts.layerCuts;
|
||||
let off = refOff - total / 2;
|
||||
for (let li = 0; li < wt.layers.length; li++) {
|
||||
const layer = wt.layers[li];
|
||||
const comp = getComponent(project, layer.componentId);
|
||||
// Stil je Schicht erst beim ersten Band lösen (wie zuvor: nur wenn die Wand Segmente hat).
|
||||
const layerStyle = new Map<number, { hatch: HatchRender; fill: string }>();
|
||||
const styleOf = (li: number) => {
|
||||
let st = layerStyle.get(li);
|
||||
if (!st) {
|
||||
const comp = getComponent(project, wt.layers[li].componentId);
|
||||
const layerHatchId =
|
||||
resolveHatchId(wall.hatchId, wall.hatchSource, category, comp.hatchId) ?? comp.hatchId;
|
||||
const layerHatch = resolveHatch(
|
||||
const hatch = resolveHatch(
|
||||
project,
|
||||
layerHatchId,
|
||||
wallAngleDeg,
|
||||
resolveForeground(comp, wall.foreground, category, wall.foregroundSource),
|
||||
);
|
||||
// SIA-Poché: neutraler Hintergrund (Papier) statt Bauteil-Albedo, die
|
||||
// Schichtschraffur (fest in HATCH_INK, siehe resolveHatch) liegt darüber;
|
||||
// Vollmuster ("solid") = Tinten-Poché.
|
||||
const layerSolid = layerHatch.pattern === "solid";
|
||||
// SIA-Poché: neutraler Hintergrund (Papier) statt Bauteil-Albedo, die Schichtschraffur
|
||||
// (fest in HATCH_INK, siehe resolveHatch) liegt darüber; Vollmuster ("solid") = Tinten-Poché.
|
||||
const bgOverride = resolveBackground(comp, wall.background, category, wall.backgroundSource);
|
||||
const layerStartCut = s <= 1e-6 ? (layerCuts ? layerCuts.start[li] : startCut) : null;
|
||||
const layerEndCut = e >= axisLen - 1e-6 ? (layerCuts ? layerCuts.end[li] : endCut) : null;
|
||||
// Durchgangswand-Aussparung: liegt der Quer-Offsetbereich dieses Bandes
|
||||
// [off, off+thickness] im Nah-Putz-Bereich einer Aussparung, wird das Band
|
||||
// entlang der Achse in Teil-Bänder VOR/NACH dem Intervall zerlegt (das
|
||||
// Durchstoss-Stück entfällt). Ohne Überlappung bleibt genau ein Band
|
||||
// [s,e] (unverändertes Verhalten).
|
||||
const bandLo = off;
|
||||
const bandHi = off + layer.thickness;
|
||||
const bandHoles: Array<[number, number]> = [];
|
||||
for (const c of segCutouts) {
|
||||
const cLo = Math.min(c.offA, c.offB);
|
||||
const cHi = Math.max(c.offA, c.offB);
|
||||
if (bandLo < cHi - CUTOUT_EPS && bandHi > cLo + CUTOUT_EPS)
|
||||
bandHoles.push([c.from, c.to]);
|
||||
}
|
||||
for (const [a, b] of subtractIntervals(s, e, bandHoles)) {
|
||||
const sc = a <= s + CUTOUT_EPS ? layerStartCut : null;
|
||||
const ec = b >= e - CUTOUT_EPS ? layerEndCut : null;
|
||||
st = { hatch, fill: bgOverride ?? (hatch.pattern === "solid" ? HATCH_INK : HATCH_PAPER) };
|
||||
layerStyle.set(li, st);
|
||||
}
|
||||
return st;
|
||||
};
|
||||
|
||||
const n = f[0];
|
||||
let i = 1;
|
||||
for (let k = 0; k < n; k++) {
|
||||
if (f[i] === 1) {
|
||||
const art = f[i + 1];
|
||||
const li = f[i + 2];
|
||||
const nNo = f[i + 3];
|
||||
const noStrokeEdges = Array.from(f.subarray(i + 4, i + 4 + nNo));
|
||||
const q = i + 4 + nNo;
|
||||
const pts = [0, 1, 2, 3].map((j) => ({ x: f[q + 2 * j], y: f[q + 2 * j + 1] }));
|
||||
i = q + 8;
|
||||
if (art === 2) {
|
||||
const st = styleOf(li);
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: clippedBand(axisPt(a), axisPt(b), off, off + layer.thickness, sc, ec),
|
||||
fill: bgOverride ?? (layerSolid ? HATCH_INK : HATCH_PAPER),
|
||||
// Band ohne Umriss: keine Schichtfuge über die Bandkante, keine 45°-Naht
|
||||
// am Knoten. Die Fugen kommen als separate `line`-Primitive (siehe unten).
|
||||
pts,
|
||||
fill: st.fill,
|
||||
// Band ohne Umriss: keine Schichtfuge über die Bandkante, keine 45°-Naht am Knoten.
|
||||
// Die Fugen kommen als separate `line`-Primitive.
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
hatch: layerHatch,
|
||||
hatch: st.hatch,
|
||||
greyed,
|
||||
// Für die Ecktests/Konsistenz beibehalten (bei stroke:"none" wirkungslos).
|
||||
noStrokeEdges: bandJoinEdges,
|
||||
noStrokeEdges,
|
||||
wallId,
|
||||
});
|
||||
} else {
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts,
|
||||
// Grob: immer Vollschwarz-Füllung gemäss SIA 400 Anhang B.9, Figur 36.
|
||||
fill: art === 1 ? HATCH_INK : "none",
|
||||
stroke,
|
||||
strokeWidthMm: art === 0 ? layerLineMm : outlineMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
noStrokeEdges,
|
||||
wallId,
|
||||
});
|
||||
}
|
||||
// L-Anschluss: eine getrimmte Schicht (z. B. Putz), die an eine
|
||||
// verschmelzende Nachbarschicht (durchlaufender Kern) grenzt, bekommt
|
||||
// zusätzlich eine seitliche Cut-Linie entlang der Durchgangsachse — sie
|
||||
// begrenzt die Schichtbreite dort, wo der Kern sie unterbricht (L-Form).
|
||||
const sideStart = s <= 1e-6 ? layerCuts?.startSide[li] : null;
|
||||
const sideEnd = e >= axisLen - 1e-6 ? layerCuts?.endSide[li] : null;
|
||||
if (sideStart || sideEnd) {
|
||||
const uSeg = normalize(sub(p2, p1));
|
||||
const nSeg = leftNormal(uSeg);
|
||||
const sidePoint = (base: Vec2, layerOff: number, cut: Line): Vec2 => {
|
||||
const pt = add(base, scale(nSeg, layerOff));
|
||||
return lineIntersect(pt, uSeg, cut.point, cut.dir) ?? pt;
|
||||
};
|
||||
if (sideStart) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: sidePoint(p1, off, sideStart),
|
||||
b: sidePoint(p1, off + layer.thickness, sideStart),
|
||||
cls: "layer-joint-l",
|
||||
weightMm: layerLineMm,
|
||||
color: stroke,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
if (sideEnd) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: sidePoint(p2, off, sideEnd),
|
||||
b: sidePoint(p2, off + layer.thickness, sideEnd),
|
||||
cls: "layer-joint-l",
|
||||
weightMm: layerLineMm,
|
||||
color: stroke,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
}
|
||||
off += layer.thickness;
|
||||
// Innere Schichtfuge (zwischen dieser und der nächst-inneren Schicht) als
|
||||
// eigene Linie am kumulierten Offset `off`, mit dem Cut der Bänder geclippt.
|
||||
// Stil aus layer.jointLineStyleId (Gewicht/Farbe/Strich); Rückfall = Haar-
|
||||
// linie (LAYER_LINE_MM) in Wandfarbe. Das Gewicht folgt demselben Detail-
|
||||
// Faktor wie die frühere Schichtfuge (`layerLineMm`), damit die Detailgrade
|
||||
// sich unverändert verhalten. Die innerste Schicht hat keine innere Fuge.
|
||||
// Nutzt bewusst weiterhin den einheitlichen startCut/endCut (nicht die
|
||||
// Pro-Schicht-Cuts): die Fuge markiert den Materialwechsel INNERHALB
|
||||
// dieser Wand und bleibt daher an der bisherigen Nahfläche.
|
||||
if (li < wt.layers.length - 1) {
|
||||
const jls = layer.jointLineStyleId
|
||||
? project.lineStyles.find((l) => l.id === layer.jointLineStyleId)
|
||||
: undefined;
|
||||
// Durchgangswand-Aussparung: liegt die Fuge im (geschlossenen) Nah-Putz-
|
||||
// Bereich einer Aussparung — inkl. der Rückgrat-Nahfläche (Merge-Kontakt)
|
||||
// —, wird sie über das Durchstoss-Intervall unterbrochen. So bleibt an der
|
||||
// Verschmelzungsfläche keine Trennlinie stehen.
|
||||
const fugeHoles: Array<[number, number]> = [];
|
||||
for (const c of segCutouts) {
|
||||
const cLo = Math.min(c.offA, c.offB);
|
||||
const cHi = Math.max(c.offA, c.offB);
|
||||
if (off >= cLo - CUTOUT_EPS && off <= cHi + CUTOUT_EPS)
|
||||
fugeHoles.push([c.from, c.to]);
|
||||
}
|
||||
for (const [a, b] of subtractIntervals(s, e, fugeHoles)) {
|
||||
const sc = a <= s + CUTOUT_EPS ? startCut : null;
|
||||
const ec = b >= e - CUTOUT_EPS ? endCut : null;
|
||||
// clippedBand(pa, pb, off, off, …) liefert [edgeStart, edgeEnd, edgeEnd,
|
||||
// edgeStart] → die zwei distinkten Endpunkte sind Index 0 (Start) und 1
|
||||
// (Ende), beide am Cut abgeschnitten wie die Bandlängskante.
|
||||
const jq = clippedBand(axisPt(a), axisPt(b), off, off, sc, ec);
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: jq[0],
|
||||
b: jq[1],
|
||||
cls: "layer-joint",
|
||||
weightMm: jls ? jls.weight * LAYER_DETAIL_FACTOR[detail] : layerLineMm,
|
||||
color: jls ? jls.color : stroke,
|
||||
dash: jls ? jls.dash : null,
|
||||
// Zickzack-Fuge (LineStyle kind==="zigzag") ebenfalls durchreichen.
|
||||
zigzag: jls?.kind === "zigzag" ? jls.zigzag : undefined,
|
||||
// Custom-Motiv-Fuge (LineStyle kind==="custom") ebenfalls durchreichen.
|
||||
motif: jls?.kind === "custom" ? jls.motif : undefined,
|
||||
greyed,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// Kräftige Wand-Umrisslinie über die volle Dicke (nur Kontur, keine Füllung),
|
||||
// damit die Wand sich klar von den dünnen Schichtfugen abhebt. Die Gehrungs-
|
||||
// Stirnkanten am Knoten entfallen → sauberer Eck-Apex ohne überschießende Barbe.
|
||||
// Bei einer Durchgangswand-Aussparung wird zusätzlich die NAHFLÄCHEN-Kante
|
||||
// (die Längskante auf der Durchstoss-Seite) über [from,to] strokelos gemacht
|
||||
// und als separate Segmente vor/nach dem Durchstoss gezeichnet — sonst liefe
|
||||
// die Umrisslinie über die Durchstoss-Breite.
|
||||
const offLo = refOff - total / 2;
|
||||
const offHi = refOff + total / 2;
|
||||
const holesHi: Array<[number, number]> = [];
|
||||
const holesLo: Array<[number, number]> = [];
|
||||
for (const c of segCutouts) {
|
||||
// `offA` ist stets die Nahfläche (Wandoberfläche); ordne die Aussparung der
|
||||
// passenden Längskante (offHi bzw. offLo) zu.
|
||||
if (Math.abs(c.offA - offHi) < 1e-6) holesHi.push([c.from, c.to]);
|
||||
else if (Math.abs(c.offA - offLo) < 1e-6) holesLo.push([c.from, c.to]);
|
||||
}
|
||||
const outlineNoStroke = [...bandJoinEdges];
|
||||
// clippedBand-Kantenreihenfolge [A.start(offLo), A.end(offLo), B.end(offHi),
|
||||
// B.start(offHi)]: Kante 0 ist die offLo-Längskante, Kante 2 die offHi-Längskante.
|
||||
if (holesHi.length) outlineNoStroke.push(2);
|
||||
if (holesLo.length) outlineNoStroke.push(0);
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: clippedBand(p1, p2, offLo, offHi, startCut, endCut),
|
||||
fill: "none",
|
||||
stroke,
|
||||
strokeWidthMm: outlineMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
noStrokeEdges: outlineNoStroke,
|
||||
wallId,
|
||||
});
|
||||
const drawNearEdge = (edgeOff: number, holes: Array<[number, number]>): void => {
|
||||
for (const [a, b] of subtractIntervals(s, e, holes)) {
|
||||
const sc = a <= s + CUTOUT_EPS ? startCut : null;
|
||||
const ec = b >= e - CUTOUT_EPS ? endCut : null;
|
||||
const jq = clippedBand(axisPt(a), axisPt(b), edgeOff, edgeOff, sc, ec);
|
||||
} else {
|
||||
const art = f[i + 1];
|
||||
const li = f[i + 2];
|
||||
const a = { x: f[i + 3], y: f[i + 4] };
|
||||
const b = { x: f[i + 5], y: f[i + 6] };
|
||||
i += 7;
|
||||
if (art === 0) {
|
||||
out.push({ kind: "line", a, b, cls: "layer-joint-l", weightMm: layerLineMm, color: stroke, greyed });
|
||||
} else if (art === 1) {
|
||||
// Innere Schichtfuge: Stil aus layer.jointLineStyleId (Gewicht/Farbe/Strich), Rückfall =
|
||||
// Haarlinie in Wandfarbe.
|
||||
const id = wt.layers[li].jointLineStyleId;
|
||||
const jls = id ? project.lineStyles.find((l) => l.id === id) : undefined;
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: jq[0],
|
||||
b: jq[1],
|
||||
cls: "wall-outline",
|
||||
weightMm: outlineMm,
|
||||
color: stroke,
|
||||
a,
|
||||
b,
|
||||
cls: "layer-joint",
|
||||
weightMm: jls ? jls.weight * LAYER_DETAIL_FACTOR[detail] : layerLineMm,
|
||||
color: jls ? jls.color : stroke,
|
||||
dash: jls ? jls.dash : null,
|
||||
zigzag: jls?.kind === "zigzag" ? jls.zigzag : undefined,
|
||||
motif: jls?.kind === "custom" ? jls.motif : undefined,
|
||||
greyed,
|
||||
});
|
||||
} else {
|
||||
out.push({ kind: "line", a, b, cls: "wall-outline", weightMm: outlineMm, color: stroke, greyed });
|
||||
}
|
||||
};
|
||||
if (holesHi.length) drawNearEdge(offHi, holesHi);
|
||||
if (holesLo.length) drawNearEdge(offLo, holesLo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { cutMeshWithPlane, ringArea, ringsToPolygons } from "./meshSection";
|
||||
import { cutMeshWithPlane, ringsToPolygons, type Pt2 } from "./meshSection";
|
||||
|
||||
const ringArea = (r: Pt2[]): number => {
|
||||
let a = 0;
|
||||
for (let i = 0; i < r.length; i++) {
|
||||
const p = r[i];
|
||||
const q = r[(i + 1) % r.length];
|
||||
a += p[0] * q[1] - q[0] * p[1];
|
||||
}
|
||||
return a / 2;
|
||||
};
|
||||
|
||||
/** Quader als geschlossenes Netz (12 Dreiecke, aussen orientiert). `inward` kehrt um (Hohlraum). */
|
||||
function box(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number, inward = false) {
|
||||
|
||||
+41
-168
@@ -8,9 +8,10 @@
|
||||
// Geschlossene Netze (Körper) ergeben geschlossene Ringe → Polygone mit Löchern; offene Netze
|
||||
// (Gelände) ergeben offene Linienzüge (Geländelinie im Schnitt).
|
||||
//
|
||||
// Robustheit: Ecken exakt AUF der Ebene werden einheitlich der „hinteren" Seite zugeschlagen
|
||||
// (symbolische Störung, `d > 0` ⇒ vorn) — so schliessen sich die Segmente auch bei Netzen, deren
|
||||
// Ecken genau auf der Schnittlinie liegen (Achsen im Raster!).
|
||||
// Die Rechnung liegt im Rust-Kern (`src-tauri/core/src/mesh_section.rs`, [K3c]); hier nur die
|
||||
// Fassade mit unveränderter Signatur.
|
||||
|
||||
import { core } from "../engine/coreWasm";
|
||||
|
||||
export type Pt2 = [number, number];
|
||||
|
||||
@@ -34,153 +35,35 @@ export interface HorizontalPlane {
|
||||
}
|
||||
export type CutPlane = VerticalPlane | HorizontalPlane;
|
||||
|
||||
const QUANT = 1e6;
|
||||
const key = (p: Pt2): string => `${Math.round(p[0] * QUANT)},${Math.round(p[1] * QUANT)}`;
|
||||
/** Liest `[n, (k, u, v …) × n]` ab `i` (Index wandert mit). */
|
||||
function readRings(f: Float64Array, at: { i: number }): Pt2[][] {
|
||||
const out: Pt2[][] = [];
|
||||
for (let k = 0, n = f[at.i++]; k < n; k++) {
|
||||
const count = f[at.i++];
|
||||
const ring = new Array<Pt2>(count);
|
||||
for (let j = 0; j < count; j++, at.i += 2) ring[j] = [f[at.i], f[at.i + 1]];
|
||||
out.push(ring);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schneidet das Netz mit `plane`. `positions` flach [x,y,z,…], `indices` je 3 ein Dreieck.
|
||||
* Entartete Segmente (Länge ~0) werden verworfen.
|
||||
*/
|
||||
export function cutMeshWithPlane(positions: ArrayLike<number>, indices: ArrayLike<number>, plane: CutPlane): CutResult {
|
||||
const nv = Math.floor(positions.length / 3);
|
||||
// Signierter Abstand + 2D-Koordinate je Vertex.
|
||||
const dist = new Float64Array(nv);
|
||||
const c0 = new Float64Array(nv);
|
||||
const c1 = new Float64Array(nv);
|
||||
for (let i = 0; i < nv; i++) {
|
||||
const x = positions[i * 3];
|
||||
const y = positions[i * 3 + 1];
|
||||
const z = positions[i * 3 + 2];
|
||||
if (plane.kind === "vertical") {
|
||||
// Normale der Ebene (im Grundriss): n = (dir.y, −dir.x); u = Position entlang dir.
|
||||
dist[i] = (x - plane.point.x) * plane.dir.y - (y - plane.point.y) * plane.dir.x;
|
||||
c0[i] = (x - plane.point.x) * plane.dir.x + (y - plane.point.y) * plane.dir.y;
|
||||
c1[i] = z;
|
||||
} else {
|
||||
dist[i] = z - plane.z;
|
||||
c0[i] = x;
|
||||
c1[i] = y;
|
||||
}
|
||||
}
|
||||
|
||||
// Kanten-Schnittpunkte cachen (jede Kante gehört zu bis zu 2 Dreiecken → gleicher Punkt).
|
||||
const edgePt = new Map<number, Pt2>();
|
||||
const edgeKey = (a: number, b: number): number => (a < b ? a * nv + b : b * nv + a);
|
||||
const crossing = (a: number, b: number): Pt2 => {
|
||||
const k = edgeKey(a, b);
|
||||
let p = edgePt.get(k);
|
||||
if (!p) {
|
||||
const t = dist[a] / (dist[a] - dist[b]);
|
||||
p = [c0[a] + (c0[b] - c0[a]) * t, c1[a] + (c1[b] - c1[a]) * t];
|
||||
edgePt.set(k, p);
|
||||
}
|
||||
return p;
|
||||
};
|
||||
|
||||
const segs: Array<[Pt2, Pt2]> = [];
|
||||
for (let t = 0; t + 2 < indices.length; t += 3) {
|
||||
const a = indices[t];
|
||||
const b = indices[t + 1];
|
||||
const c = indices[t + 2];
|
||||
const sa = dist[a] > 0;
|
||||
const sb = dist[b] > 0;
|
||||
const sc = dist[c] > 0;
|
||||
if (sa === sb && sb === sc) continue;
|
||||
// Genau eine Ecke steht allein auf ihrer Seite: die beiden Kanten dort bilden das Segment.
|
||||
const odd = sa !== sb && sa !== sc ? a : sb !== sa && sb !== sc ? b : c;
|
||||
const o1 = odd === a ? b : odd === b ? c : a;
|
||||
const o2 = odd === a ? c : odd === b ? a : b;
|
||||
const p = crossing(odd, o1);
|
||||
const q = crossing(odd, o2);
|
||||
if (Math.abs(p[0] - q[0]) < 1e-9 && Math.abs(p[1] - q[1]) < 1e-9) continue;
|
||||
// Einheitlicher Umlaufsinn je Seite der Einzelecke → Segmente benachbarter Dreiecke fügen
|
||||
// sich bei gleichsinnig orientiertem Netz zu gleichsinnigen Ketten.
|
||||
segs.push(dist[odd] > 0 ? [q, p] : [p, q]);
|
||||
}
|
||||
return chain(segs);
|
||||
}
|
||||
|
||||
/** Verkettet Segmente zu Ringen und Linienzügen. */
|
||||
function chain(segs: Array<[Pt2, Pt2]>): CutResult {
|
||||
// Start-/Endpunkt-Index.
|
||||
const byStart = new Map<string, number[]>();
|
||||
const byEnd = new Map<string, number[]>();
|
||||
segs.forEach((s, i) => {
|
||||
const ks = key(s[0]);
|
||||
const ke = key(s[1]);
|
||||
(byStart.get(ks) ?? byStart.set(ks, []).get(ks)!).push(i);
|
||||
(byEnd.get(ke) ?? byEnd.set(ke, []).get(ke)!).push(i);
|
||||
});
|
||||
const used = new Array<boolean>(segs.length).fill(false);
|
||||
const take = (m: Map<string, number[]>, k: string): number => {
|
||||
const l = m.get(k);
|
||||
if (!l) return -1;
|
||||
while (l.length) {
|
||||
const i = l.pop()!;
|
||||
if (!used[i]) return i;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
const rings: Pt2[][] = [];
|
||||
const lines: Pt2[][] = [];
|
||||
for (let i = 0; i < segs.length; i++) {
|
||||
if (used[i]) continue;
|
||||
used[i] = true;
|
||||
const pts: Pt2[] = [segs[i][0], segs[i][1]];
|
||||
const startKey = key(pts[0]);
|
||||
// vorwärts
|
||||
for (;;) {
|
||||
const k = key(pts[pts.length - 1]);
|
||||
if (k === startKey && pts.length > 2) break;
|
||||
const n = take(byStart, k);
|
||||
if (n < 0) break;
|
||||
used[n] = true;
|
||||
pts.push(segs[n][1]);
|
||||
}
|
||||
if (key(pts[pts.length - 1]) === startKey && pts.length > 3) {
|
||||
pts.pop();
|
||||
rings.push(pts);
|
||||
continue;
|
||||
}
|
||||
// rückwärts verlängern (offener Zug)
|
||||
for (;;) {
|
||||
const k = key(pts[0]);
|
||||
const n = take(byEnd, k);
|
||||
if (n < 0) break;
|
||||
used[n] = true;
|
||||
pts.unshift(segs[n][0]);
|
||||
if (key(pts[0]) === key(pts[pts.length - 1])) {
|
||||
pts.shift();
|
||||
rings.push(pts);
|
||||
pts.length = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pts.length >= 2) lines.push(pts);
|
||||
}
|
||||
const pl =
|
||||
plane.kind === "vertical"
|
||||
? [0, plane.point.x, plane.point.y, plane.dir.x, plane.dir.y]
|
||||
: [1, plane.z];
|
||||
const f = core().mesh_section_cut_flat(Float64Array.from(positions), Float64Array.from(indices), Float64Array.from(pl));
|
||||
if (f.length === 0) return { rings: [], lines: [] };
|
||||
const at = { i: 0 };
|
||||
const rings = readRings(f, at);
|
||||
const lines = readRings(f, at);
|
||||
return { rings, lines };
|
||||
}
|
||||
|
||||
export const ringArea = (r: Pt2[]): number => {
|
||||
let a = 0;
|
||||
for (let i = 0; i < r.length; i++) {
|
||||
const p = r[i];
|
||||
const q = r[(i + 1) % r.length];
|
||||
a += p[0] * q[1] - q[0] * p[1];
|
||||
}
|
||||
return a / 2;
|
||||
};
|
||||
|
||||
function pointInRing(p: Pt2, r: Pt2[]): boolean {
|
||||
let inside = false;
|
||||
for (let i = 0, j = r.length - 1; i < r.length; j = i++) {
|
||||
const [xi, yi] = r[i];
|
||||
const [xj, yj] = r[j];
|
||||
if (yi > p[1] !== yj > p[1] && p[0] < ((xj - xi) * (p[1] - yi)) / (yj - yi) + xi) inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
/** Ring mit Löchern (Aussenring zuerst, dann Löcher). */
|
||||
export type RingSet = Pt2[][];
|
||||
|
||||
@@ -189,35 +72,25 @@ export type RingSet = Pt2[][];
|
||||
* Loch). Unabhängig vom Umlaufsinn. Aussenringe zuerst-gross; Löcher folgen ihrem Aussenring.
|
||||
*/
|
||||
export function ringsToPolygons(rings: Pt2[][]): RingSet[] {
|
||||
const items = rings
|
||||
.filter((r) => r.length >= 3 && Math.abs(ringArea(r)) > 1e-12)
|
||||
.map((r) => ({ r, area: Math.abs(ringArea(r)) }))
|
||||
.sort((a, b) => b.area - a.area);
|
||||
const depth: number[] = items.map(() => 0);
|
||||
const parent: number[] = items.map(() => -1);
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
for (let j = i - 1; j >= 0; j--) {
|
||||
// Kandidat j (grösser) enthält i? Test mit einem Punkt von i (nicht auf dem Rand von j).
|
||||
if (pointInRing(items[i].r[0], items[j].r)) {
|
||||
parent[i] = j;
|
||||
depth[i] = depth[j] + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const b: number[] = [rings.length];
|
||||
for (const r of rings) {
|
||||
b.push(r.length);
|
||||
for (const p of r) b.push(p[0], p[1]);
|
||||
}
|
||||
const f = core().mesh_section_polygons_flat(Float64Array.from(b));
|
||||
if (f.length === 0) return [];
|
||||
const at = { i: 1 };
|
||||
const out: RingSet[] = [];
|
||||
const idx = new Map<number, number>();
|
||||
items.forEach((it, i) => {
|
||||
if (depth[i] % 2 === 0) {
|
||||
idx.set(i, out.length);
|
||||
out.push([it.r]);
|
||||
for (let k = 0; k < f[0]; k++) {
|
||||
const nr = f[at.i++];
|
||||
const set: RingSet = [];
|
||||
for (let r = 0; r < nr; r++) {
|
||||
const count = f[at.i++];
|
||||
const ring = new Array<Pt2>(count);
|
||||
for (let j = 0; j < count; j++, at.i += 2) ring[j] = [f[at.i], f[at.i + 1]];
|
||||
set.push(ring);
|
||||
}
|
||||
});
|
||||
items.forEach((it, i) => {
|
||||
if (depth[i] % 2 === 1) {
|
||||
const owner = idx.get(parent[i]);
|
||||
if (owner !== undefined) out[owner].push(it.r);
|
||||
}
|
||||
});
|
||||
out.push(set);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -16,9 +16,6 @@ import {
|
||||
collectElevationFaces,
|
||||
elevationFrame,
|
||||
generateElevationPlan,
|
||||
projectFace,
|
||||
projectPoint,
|
||||
wallWorldFaces,
|
||||
} from "./toElevation";
|
||||
|
||||
// Betrachter im Süden (world z = −2), Blick nach +Z (in die Szene). Damit liegt
|
||||
@@ -41,44 +38,29 @@ function wall(over: Partial<RWall> = {}): RWall {
|
||||
}
|
||||
|
||||
describe("toElevation — Projektion + Culling", () => {
|
||||
it("projiziert einen Weltpunkt auf (u, v, depth)", () => {
|
||||
const frame = elevationFrame(PLANE_SOUTH);
|
||||
// Punkt auf der Süd-Fassade (z ≈ −0.1), x = 4, Höhe 3.
|
||||
const p = projectPoint(frame, [4, 3, -0.1]);
|
||||
expect(p.v).toBeCloseTo(3, 6); // v = absolute Höhe
|
||||
expect(p.depth).toBeCloseTo(1.9, 6); // −0.1 − (−2) = 1.9 hinter der Ebene
|
||||
// u = dot(rel, U); U (entspiegelt, Blick +z ⇒ rechts = +x) = [1, 0, 0],
|
||||
// P.x = −1 → u = 4 − (−1) = 5.
|
||||
expect(p.u).toBeCloseTo(5, 6);
|
||||
});
|
||||
|
||||
it("Süd-Langseite einer Wand: erwartetes (u, v)-Rechteck + Tiefe, Rückseite gecullt", () => {
|
||||
const frame = elevationFrame(PLANE_SOUTH);
|
||||
const faces = wallWorldFaces(wall());
|
||||
const projected = faces.map((f) => projectFace(frame, f));
|
||||
const model: RModel3d = { walls: [wall()], slabs: [], meshes: [], roofLayers: [] };
|
||||
const visible = collectElevationFaces(model, frame);
|
||||
// Genau EINE sichtbare Fläche (die Süd-Langseite); alle anderen sind
|
||||
// Rückseiten oder streifend (Deckel/Boden/Stirnkappen).
|
||||
const visible = projected.filter((p) => p !== null);
|
||||
expect(visible.length).toBe(1);
|
||||
const face = visible[0]!;
|
||||
const face = visible[0];
|
||||
expect(face.wallId).toBe("W");
|
||||
const us = face.pts.map((p) => p[0]);
|
||||
const vs = face.pts.map((p) => p[1]);
|
||||
expect(Math.min(...us)).toBeCloseTo(1, 6); // x=0 → u=1 (P.x=−1)
|
||||
// U (entspiegelt, Blick +z ⇒ rechts = +x) = [1, 0, 0], P.x = −1.
|
||||
expect(Math.min(...us)).toBeCloseTo(1, 6); // x=0 → u=1
|
||||
expect(Math.max(...us)).toBeCloseTo(5, 6); // x=4 → u=5
|
||||
expect(Math.min(...vs)).toBeCloseTo(0, 6);
|
||||
expect(Math.max(...vs)).toBeCloseTo(3, 6);
|
||||
expect(face.depth).toBeCloseTo(1.9, 6);
|
||||
expect(face.depth).toBeCloseTo(1.9, 6); // z ≈ −0.1 − (−2)
|
||||
});
|
||||
|
||||
it("Rückseiten-Culling: eine Fläche mit Normale VON der Ebene weg erscheint nicht", () => {
|
||||
it("Rückseiten-Culling: eine Wand hinter dem Betrachter erscheint nicht", () => {
|
||||
const frame = elevationFrame(PLANE_SOUTH);
|
||||
const faces = wallWorldFaces(wall());
|
||||
// Die +Quer-Fläche (Nord-Langseite, Normale [0,0,−1]·N = −1 … eigentlich die
|
||||
// Süd-Seite ist sichtbar) — hier prüfen wir explizit die Rückseite:
|
||||
const north = faces.find((f) => f.normal[2] > 0.5); // Normale zeigt +Z (= mit N)
|
||||
expect(north).toBeDefined();
|
||||
expect(projectFace(frame, north!)).toBeNull();
|
||||
const model: RModel3d = { walls: [wall({ start: [0, -5], end: [4, -5] })], slabs: [], meshes: [], roofLayers: [] };
|
||||
expect(collectElevationFaces(model, frame)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+294
-922
File diff suppressed because it is too large.
Load diff
@@ -4,16 +4,14 @@
|
||||
* die schwächere per achsparalleler Rechteck-Subtraktion weg. Gleiche Priorität
|
||||
* koexistiert (kein Schnitt).
|
||||
*
|
||||
* Getestet ohne WASM:
|
||||
* 1. `subtractRect` direkt (Ecken-/Kanten-/Enthalten-/Kein-Overlap-Fälle).
|
||||
* 2. `subtractDominantBands` gegen den Nutzer-Testfall — ELEMENTÜBERGREIFEND:
|
||||
* Getestet über den Rust-Kern (`plan_section.rs`):
|
||||
* `subtractDominantBands` gegen den Nutzer-Testfall — ELEMENTÜBERGREIFEND:
|
||||
* ein Decken-Beton-Band (100) schneidet ein überlappendes Wand-Putz-Band
|
||||
* (10) weg; Beton bleibt voll; gleiche Priorität koexistiert.
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
subtractRect,
|
||||
subtractDominantBands,
|
||||
type Rect,
|
||||
type SectionCutPolygon,
|
||||
@@ -24,14 +22,6 @@ function r(uMin: number, uMax: number, vMin: number, vMax: number): Rect {
|
||||
return { uMin, uMax, vMin, vMax };
|
||||
}
|
||||
|
||||
/** Rechteck einer Rest-Menge normalisieren (auf 1e-9 gerundet, sortiert) für stabile Vergleiche. */
|
||||
function norm(rects: Rect[]): Rect[] {
|
||||
const round = (x: number) => Math.round(x * 1e9) / 1e9;
|
||||
return rects
|
||||
.map((x) => ({ uMin: round(x.uMin), uMax: round(x.uMax), vMin: round(x.vMin), vMax: round(x.vMax) }))
|
||||
.sort((a, b) => a.uMin - b.uMin || a.vMin - b.vMin);
|
||||
}
|
||||
|
||||
/** Ein achsparalleles Cut-Band mit joinPriority. */
|
||||
function band(
|
||||
uMin: number,
|
||||
@@ -83,50 +73,6 @@ function area(items: Array<Rect | SectionCutPolygon>): number {
|
||||
}, 0);
|
||||
}
|
||||
|
||||
describe("subtractRect: achsparallele Rechteck-Subtraktion", () => {
|
||||
it("kein Overlap → base unverändert", () => {
|
||||
expect(norm(subtractRect(r(0, 1, 0, 1), r(2, 3, 2, 3)))).toEqual(norm([r(0, 1, 0, 1)]));
|
||||
});
|
||||
|
||||
it("nur Kantenberührung (Fläche 0) → base unverändert", () => {
|
||||
// cutter grenzt bei u=1 an, überlappt aber nicht.
|
||||
expect(norm(subtractRect(r(0, 1, 0, 1), r(1, 2, 0, 1)))).toEqual(norm([r(0, 1, 0, 1)]));
|
||||
});
|
||||
|
||||
it("cutter enthält base vollständig → leere Restmenge", () => {
|
||||
expect(subtractRect(r(1, 2, 1, 2), r(0, 3, 0, 3))).toEqual([]);
|
||||
});
|
||||
|
||||
it("cutter mittig in base → 4 Rest-Rechtecke, Flächenbilanz stimmt", () => {
|
||||
const rest = subtractRect(r(0, 3, 0, 3), r(1, 2, 1, 2));
|
||||
expect(rest).toHaveLength(4);
|
||||
// 9 (base) − 1 (overlap) = 8.
|
||||
expect(area(rest)).toBeCloseTo(8, 9);
|
||||
// Rechtecke sind disjunkt: Summe der Einzelflächen = Gesamtfläche.
|
||||
const sum = rest.reduce((s, x) => s + (x.uMax - x.uMin) * (x.vMax - x.vMin), 0);
|
||||
expect(sum).toBeCloseTo(8, 9);
|
||||
});
|
||||
|
||||
it("Ecküberlappung → 2 Rest-Rechtecke (L-Form)", () => {
|
||||
// cutter überdeckt die obere-rechte Ecke von base.
|
||||
const rest = subtractRect(r(0, 2, 0, 2), r(1, 3, 1, 3));
|
||||
// overlap = [1,2]×[1,2] (Fläche 1). Rest = 4 − 1 = 3.
|
||||
expect(area(rest)).toBeCloseTo(3, 9);
|
||||
expect(norm(rest)).toEqual(
|
||||
norm([
|
||||
r(0, 1, 0, 2), // links, volle Höhe
|
||||
r(1, 2, 0, 1), // mittlerer Streifen unten
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("Kantenüberlappung (cutter deckt einen Randstreifen) → 1 Rest-Rechteck", () => {
|
||||
// cutter deckt den oberen Rand v∈[1,2] über die volle Breite.
|
||||
const rest = subtractRect(r(0, 2, 0, 2), r(-1, 3, 1, 3));
|
||||
expect(norm(rest)).toEqual(norm([r(0, 2, 0, 1)]));
|
||||
});
|
||||
});
|
||||
|
||||
describe("subtractDominantBands: stärkere Schicht schneidet schwächere", () => {
|
||||
it("Nutzer-Testfall ELEMENTÜBERGREIFEND: Decken-Beton(100) schneidet Wand-Putz(10) weg", () => {
|
||||
// Wand-Putz-Band (Element B): schwach, joinPriority 10, u∈[0,2], v∈[0,3].
|
||||
|
||||
+57
-315
@@ -27,6 +27,7 @@ import { projectToModel3d } from "./toWalls3d";
|
||||
import { subtractVoidsInSection } from "./voids";
|
||||
import { appendBodySections, appendTerrainProfiles } from "./sectionExtras";
|
||||
import { loadEngine3d } from "../engine/engine3d";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import {
|
||||
HATCH_INK,
|
||||
HATCH_PAPER,
|
||||
@@ -582,8 +583,6 @@ function ceilingRepresentativePriority(project: Project, ceiling: Ceiling): numb
|
||||
// ── Schnitt-Boolean-Dominanz (achsparallele Rechteck-Subtraktion) ───────────
|
||||
// Kleine Toleranz für Überlappungs-/Rest-Rechtecke: Null-/Negativflächen und
|
||||
// Rest-Streifen dünner als EPS werden verworfen (Float-Rauschen der u-/v-Meter).
|
||||
const RECT_EPS = 1e-6;
|
||||
|
||||
/** Achsparalleles Rechteck in (u, v)-Metern. */
|
||||
export interface Rect {
|
||||
uMin: number;
|
||||
@@ -605,177 +604,52 @@ function rectOfBand(band: SectionCutPolygon): Rect | null {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Rechteck-minus-Rechteck (beide achsparallel): `base` ohne die Überlappung mit
|
||||
* `cutter`, zerlegt in 0–4 disjunkte Rest-Rechtecke (links/rechts über die volle
|
||||
* Höhe, dann oben/unten im mittleren u-Streifen — überlappungsfrei). Kein echter
|
||||
* Überlapp (Fläche ≤ EPS in u oder v) ⇒ `base` bleibt ganz. Vollständige
|
||||
* Überdeckung ⇒ leere Liste. Rest-Streifen dünner als EPS werden verworfen.
|
||||
*/
|
||||
export function subtractRect(base: Rect, cutter: Rect): Rect[] {
|
||||
const oMinU = Math.max(base.uMin, cutter.uMin);
|
||||
const oMaxU = Math.min(base.uMax, cutter.uMax);
|
||||
const oMinV = Math.max(base.vMin, cutter.vMin);
|
||||
const oMaxV = Math.min(base.vMax, cutter.vMax);
|
||||
// Kein (nennenswerter) Überlapp — `base` unverändert.
|
||||
if (oMaxU - oMinU <= RECT_EPS || oMaxV - oMinV <= RECT_EPS) return [base];
|
||||
|
||||
const out: Rect[] = [];
|
||||
const push = (r: Rect) => {
|
||||
if (r.uMax - r.uMin > RECT_EPS && r.vMax - r.vMin > RECT_EPS) out.push(r);
|
||||
};
|
||||
// Links / rechts der Überlappung, jeweils über die volle Basis-Höhe.
|
||||
push({ uMin: base.uMin, uMax: oMinU, vMin: base.vMin, vMax: base.vMax });
|
||||
push({ uMin: oMaxU, uMax: base.uMax, vMin: base.vMin, vMax: base.vMax });
|
||||
// Unten / oben im mittleren u-Streifen (nur der von der Überlappung befreite Rest).
|
||||
push({ uMin: oMinU, uMax: oMaxU, vMin: base.vMin, vMax: oMinV });
|
||||
push({ uMin: oMinU, uMax: oMaxU, vMin: oMaxV, vMax: base.vMax });
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Globale Schnitt-Dominanz: für jedes Band wird die Rechteck-Überlappung ALLER
|
||||
* Bänder mit STRIKT höherer `joinPriority` subtrahiert (elementübergreifend —
|
||||
* z. B. schneidet ein Decken-Beton-Band 100 ein überlappendes Wand-Putz-Band 10
|
||||
* weg). Gleiche Priorität schneidet NICHT (koexistiert → durchgehende Fläche).
|
||||
* Bänder ohne `joinPriority` (unauflösbares Bauteil) nehmen weder als Basis noch
|
||||
* als Cutter teil und bleiben unverändert erhalten.
|
||||
*
|
||||
* Kanten: jedes emittierte Rest-Rechteck erhält in `generateSectionPlan` seine
|
||||
* eigene Schnitt-Umrisslinie (unverändert). An der Schnittkante fällt die
|
||||
* Rest-Rechteck-Kante mit der Kante des stärkeren Bands zusammen — das ist die
|
||||
* gewünschte Material-/Fugenlinie zwischen den Schichten; im Inneren einer
|
||||
* Schicht entstehen durch die überlappungsfreie Zerlegung keine falschen Kanten.
|
||||
* weg). Gleiche Priorität schneidet NICHT. Bänder ohne `joinPriority` nehmen
|
||||
* weder als Basis noch als Cutter teil. Danach verschmelzen angrenzende Bänder
|
||||
* gleicher `componentId` + Priorität zu einem Körper (keine innere Trennlinie).
|
||||
* Die Rechenarbeit liegt im Rust-Kern (`plan_section.rs`, [K3c]); hier nur
|
||||
* Ein-/Ausgabe der Bänder samt Stil.
|
||||
*/
|
||||
export function subtractDominantBands(bands: SectionCutPolygon[]): SectionCutPolygon[] {
|
||||
const rects = bands.map(rectOfBand);
|
||||
const ids = new Map<string, number>();
|
||||
const b: number[] = [bands.length];
|
||||
for (const band of bands) {
|
||||
const r = rectOfBand(band);
|
||||
let comp = -1;
|
||||
if (band.componentId !== undefined) {
|
||||
comp = ids.get(band.componentId) ?? ids.size;
|
||||
ids.set(band.componentId, comp);
|
||||
}
|
||||
b.push(r ? 1 : 0, r?.uMin ?? 0, r?.uMax ?? 0, r?.vMin ?? 0, r?.vMax ?? 0,
|
||||
band.joinPriority ?? Number.NaN, comp);
|
||||
}
|
||||
const f = core().section_dominant_bands_flat(Float64Array.from(b));
|
||||
const out: SectionCutPolygon[] = [];
|
||||
for (let i = 0; i < bands.length; i++) {
|
||||
const band = bands[i];
|
||||
const base = rects[i];
|
||||
const prio = band.joinPriority;
|
||||
// Nicht-rechteckig oder ohne Priorität: unverändert durchreichen.
|
||||
if (base === null || prio === undefined) {
|
||||
out.push(band);
|
||||
continue;
|
||||
}
|
||||
let pieces: Rect[] = [base];
|
||||
for (let j = 0; j < bands.length && pieces.length > 0; j++) {
|
||||
if (j === i) continue;
|
||||
const otherPrio = bands[j].joinPriority;
|
||||
const cutter = rects[j];
|
||||
if (cutter === null || otherPrio === undefined || otherPrio <= prio) continue;
|
||||
const next: Rect[] = [];
|
||||
for (const p of pieces) next.push(...subtractRect(p, cutter));
|
||||
pieces = next;
|
||||
}
|
||||
for (const p of pieces) out.push(bandFromRect(band, p));
|
||||
}
|
||||
// MERGE-Regel: nach der Dominanz-Subtraktion angrenzende/überlappende Bänder
|
||||
// gleicher Komponente + Priorität zu einem Körper verschmelzen (keine innere
|
||||
// Trennlinie durch gleichartiges Material). Die Subtraktion oben bleibt davon
|
||||
// unberührt (bit-identisch) — hier werden nur gleichartige Reste vereinigt.
|
||||
return mergeSameComponentBands(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Union zweier achsparalleler Rechtecke, ABER NUR wenn das Ergebnis EXAKT wieder
|
||||
* ein Rechteck ist — sonst `null`. Zwei Fälle liefern eine rechteckige Union
|
||||
* (jeweils mit `RECT_EPS`-Toleranz):
|
||||
* • Enthaltensein: eines liegt vollständig im anderen ⇒ das umschließende.
|
||||
* • Achs-Deckung + Berührung: in einer Achse deckungsgleich (gleiche min/max)
|
||||
* UND in der anderen berührend/überlappend (kein Spalt) ⇒ Bounding-Box.
|
||||
* Teil-/Eck-Überlappungen (Union wäre L-förmig) und Bänder mit Spalt liefern
|
||||
* `null` — sie dürfen NICHT verschmolzen werden (die Bounding-Box deckte sonst
|
||||
* leere Fläche ab). Genau die im Schnitt vorkommenden bündigen Rechtecke.
|
||||
*/
|
||||
function rectUnionIfRect(a: Rect, b: Rect): Rect | null {
|
||||
const E = RECT_EPS;
|
||||
// Enthaltensein (inkl. Deckungsgleichheit): Union = umschließendes Rechteck.
|
||||
const aInB =
|
||||
b.uMin - a.uMin <= E && a.uMax - b.uMax <= E && b.vMin - a.vMin <= E && a.vMax - b.vMax <= E;
|
||||
if (aInB) return { uMin: b.uMin, uMax: b.uMax, vMin: b.vMin, vMax: b.vMax };
|
||||
const bInA =
|
||||
a.uMin - b.uMin <= E && b.uMax - a.uMax <= E && a.vMin - b.vMin <= E && b.vMax - a.vMax <= E;
|
||||
if (bInA) return { uMin: a.uMin, uMax: a.uMax, vMin: a.vMin, vMax: a.vMax };
|
||||
|
||||
const uAligned = Math.abs(a.uMin - b.uMin) <= E && Math.abs(a.uMax - b.uMax) <= E;
|
||||
const vAligned = Math.abs(a.vMin - b.vMin) <= E && Math.abs(a.vMax - b.vMax) <= E;
|
||||
// Berührung/Überlappung in der jeweils ANDEREN Achse (kein Spalt größer EPS).
|
||||
const vTouch = a.vMax >= b.vMin - E && b.vMax >= a.vMin - E;
|
||||
const uTouch = a.uMax >= b.uMin - E && b.uMax >= a.uMin - E;
|
||||
if ((uAligned && vTouch) || (vAligned && uTouch)) {
|
||||
return {
|
||||
uMin: Math.min(a.uMin, b.uMin),
|
||||
uMax: Math.max(a.uMax, b.uMax),
|
||||
vMin: Math.min(a.vMin, b.vMin),
|
||||
vMax: Math.max(a.vMax, b.vMax),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* MERGE-Phase der Schnitt-Dominanz (vgl. `resolveJoinPriority` "merge",
|
||||
* src/model/joins.ts): Bänder mit GLEICHER `componentId` UND gleicher
|
||||
* `joinPriority`, deren achsparallele Rechtecke sich berühren/überlappen und
|
||||
* eine rechteckige Union bilden (`rectUnionIfRect`), werden zu EINEM Band
|
||||
* zusammengefasst — so entsteht an der Berührkante keine innere Trennlinie durch
|
||||
* gleichartiges Material (z. B. zwei Backstein-Kerne, Beton-Decke an Beton-Wand).
|
||||
*
|
||||
* Bänder VERSCHIEDENER Komponenten (auch bei gleicher Priorität) bleiben
|
||||
* getrennt (coexist). Bänder ohne `componentId`/`joinPriority` oder ohne
|
||||
* Rechteck-Form nehmen nicht teil und werden unverändert durchgereicht — daher
|
||||
* ist die Phase für die bestehenden Dominanz-Tests (keine `componentId`) ein
|
||||
* No-op. Iterativ bis zum Fixpunkt (Ketten aus ≥3 Rechtecken verschmelzen
|
||||
* schrittweise); die Reihenfolge bleibt erhalten (das verschmolzene Rechteck
|
||||
* ersetzt das erste Band an seiner Position).
|
||||
*/
|
||||
function mergeSameComponentBands(bands: SectionCutPolygon[]): SectionCutPolygon[] {
|
||||
const out = bands.slice();
|
||||
for (let merged = true; merged; ) {
|
||||
merged = false;
|
||||
for (let i = 0; i < out.length && !merged; i++) {
|
||||
const bi = out[i];
|
||||
if (bi.componentId === undefined || bi.joinPriority === undefined) continue;
|
||||
const ri = rectOfBand(bi);
|
||||
if (!ri) continue;
|
||||
for (let j = i + 1; j < out.length; j++) {
|
||||
const bj = out[j];
|
||||
if (bj.componentId !== bi.componentId || bj.joinPriority !== bi.joinPriority) continue;
|
||||
const rj = rectOfBand(bj);
|
||||
if (!rj) continue;
|
||||
const u = rectUnionIfRect(ri, rj);
|
||||
if (!u) continue;
|
||||
out[i] = bandFromRect(bi, u);
|
||||
out.splice(j, 1);
|
||||
merged = true; // Fixpunkt-Neustart: neu entstandene Nachbarschaften erfassen
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (let k = 0, i = 1; k < f[0]; k++, i += 6) {
|
||||
const src = bands[f[i]];
|
||||
out.push(f[i + 1] === 0 ? src : {
|
||||
component: src.component,
|
||||
color: src.color,
|
||||
pts: [
|
||||
[f[i + 2], f[i + 5]],
|
||||
[f[i + 3], f[i + 5]],
|
||||
[f[i + 3], f[i + 4]],
|
||||
[f[i + 2], f[i + 4]],
|
||||
],
|
||||
fill: src.fill,
|
||||
hatch: src.hatch,
|
||||
joinPriority: src.joinPriority,
|
||||
componentId: src.componentId,
|
||||
sourceId: src.sourceId,
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Erzeugt aus einem Rest-`Rect` ein Cut-Band, das Stil/Referenz von `src` erbt. */
|
||||
function bandFromRect(src: SectionCutPolygon, r: Rect): SectionCutPolygon {
|
||||
return {
|
||||
component: src.component,
|
||||
color: src.color,
|
||||
pts: [
|
||||
[r.uMin, r.vMax],
|
||||
[r.uMax, r.vMax],
|
||||
[r.uMax, r.vMin],
|
||||
[r.uMin, r.vMin],
|
||||
],
|
||||
fill: src.fill,
|
||||
hatch: src.hatch,
|
||||
joinPriority: src.joinPriority,
|
||||
componentId: src.componentId,
|
||||
sourceId: src.sourceId,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Zerlegt das EINE geschnittene Deckenrechteck (`cp`, vier Ecken in u/v-Metern)
|
||||
* in liegende Teil-Rechtecke je Schicht des Deckentyps `wt` — das Schnitt-
|
||||
@@ -1001,7 +875,6 @@ export function appendRoofSections(
|
||||
// plane.point[0]=x, plane.point[2]=y; u-Achse = (−nz, nx) (s. section.rs).
|
||||
const base: Vec2 = { x: plane.point[0], y: plane.point[2] };
|
||||
const uDir = sectionUAxisModel(plane);
|
||||
const EPS_U = 1e-6;
|
||||
|
||||
roofs.forEach((roof, index) => {
|
||||
const eavesZ = roofBaseElevation(project, roof);
|
||||
@@ -1010,100 +883,19 @@ export function appendRoofSections(
|
||||
const totalT = layers.reduce((s, l) => s + Math.max(0, l.thickness), 0);
|
||||
if (totalT <= 1e-9) return;
|
||||
|
||||
const segs: Array<{ tLo: number; tHi: number; zTop0: number; zTop1: number; cosTheta: number }> = [];
|
||||
for (const pl of geo.planes) {
|
||||
const pts = pl.pts;
|
||||
if (pts.length < 3) continue;
|
||||
// Ebenengleichung z = z0 − (A(x−x0)+B(y−y0))/C über die Newell-Normale.
|
||||
let A = 0;
|
||||
let B = 0;
|
||||
let C = 0;
|
||||
for (let i = 0; i < pts.length; i++) {
|
||||
const c = pts[i];
|
||||
const d = pts[(i + 1) % pts.length];
|
||||
A += (c[1] - d[1]) * (c[2] + d[2]);
|
||||
B += (c[2] - d[2]) * (c[0] + d[0]);
|
||||
C += (c[0] - d[0]) * (c[1] + d[1]);
|
||||
}
|
||||
if (Math.abs(C) < 1e-9) continue; // (nahezu) vertikale Fläche — kein Flächenschnitt
|
||||
const nLen = Math.hypot(A, B, C);
|
||||
const cosTheta = Math.abs(C) / (nLen || 1);
|
||||
const zAt = (x: number, y: number): number =>
|
||||
pts[0][2] - (A * (x - pts[0][0]) + B * (y - pts[0][1])) / C;
|
||||
|
||||
// Cyrus–Beck: Gerade base + t·uDir gegen das konvexe Aufsichts-Polygon.
|
||||
// Orientierungsunabhängig: Innenseite je Kante über den Polygon-Schwerpunkt.
|
||||
let cx = 0;
|
||||
let cy = 0;
|
||||
for (const p of pts) {
|
||||
cx += p[0];
|
||||
cy += p[1];
|
||||
}
|
||||
cx /= pts.length;
|
||||
cy /= pts.length;
|
||||
let tLo = -Infinity;
|
||||
let tHi = Infinity;
|
||||
let outside = false;
|
||||
for (let i = 0; i < pts.length && !outside; i++) {
|
||||
const a = pts[i];
|
||||
const b = pts[(i + 1) % pts.length];
|
||||
// Kanten-Normale, zum Schwerpunkt orientiert (Innenseite).
|
||||
let ex = -(b[1] - a[1]);
|
||||
let ey = b[0] - a[0];
|
||||
if (ex * (cx - a[0]) + ey * (cy - a[1]) < 0) {
|
||||
ex = -ex;
|
||||
ey = -ey;
|
||||
}
|
||||
const denom = ex * uDir.x + ey * uDir.y;
|
||||
const dist = ex * (base.x - a[0]) + ey * (base.y - a[1]);
|
||||
if (Math.abs(denom) < 1e-12) {
|
||||
if (dist < -1e-9) outside = true; // parallel ausserhalb
|
||||
continue;
|
||||
}
|
||||
const t = -dist / denom;
|
||||
if (denom > 0) tLo = Math.max(tLo, t);
|
||||
else tHi = Math.min(tHi, t);
|
||||
}
|
||||
if (outside || tHi - tLo <= EPS_U) continue;
|
||||
|
||||
const q = (t: number): Vec2 => ({ x: base.x + t * uDir.x, y: base.y + t * uDir.y });
|
||||
const p0 = q(tLo);
|
||||
const p1 = q(tHi);
|
||||
const zTop0 = zAt(p0.x, p0.y);
|
||||
const zTop1 = zAt(p1.x, p1.y);
|
||||
|
||||
segs.push({
|
||||
tLo,
|
||||
tHi,
|
||||
zTop0,
|
||||
zTop1,
|
||||
cosTheta,
|
||||
});
|
||||
// Spur der Schnittebene auf den Dachflächen (Cyrus–Beck gegen die konvexen Aufsichten, lineare
|
||||
// Oberkante), gleich geneigte anstossende Teile zu EINEM Band vereint — sonst stünde an der
|
||||
// Naht eine senkrechte Linie. Rechnet der Kern (`plan_section.rs`).
|
||||
const pl: number[] = [geo.planes.length];
|
||||
for (const plane of geo.planes) {
|
||||
pl.push(plane.pts.length);
|
||||
for (const p of plane.pts) pl.push(p[0], p[1], p[2]);
|
||||
}
|
||||
|
||||
// Aneinanderstossende/überlappende Bänder, deren Oberkante in einer Geraden weiterläuft und die gleiche
|
||||
// Dicke haben (z. B. Teilflächen EINER Ebene aus der konvexen Zerlegung, oder zwei
|
||||
// Flächen, die genau an der Schnittspur anstossen), zu EINEM Band vereinen — sonst
|
||||
// steht an der Naht eine senkrechte Linie.
|
||||
segs.sort((p, q) => p.tLo - q.tLo);
|
||||
const merged: typeof segs = [];
|
||||
for (const sg of segs) {
|
||||
const last = merged[merged.length - 1];
|
||||
const slope = (x: typeof sg) => (x.zTop1 - x.zTop0) / Math.max(x.tHi - x.tLo, 1e-12);
|
||||
const lineZ = (x: typeof sg, t: number) => x.zTop0 + slope(x) * (t - x.tLo);
|
||||
if (
|
||||
last &&
|
||||
sg.tLo <= last.tHi + 1e-6 && // anstossend ODER überlappend
|
||||
Math.abs(lineZ(last, sg.tLo) - sg.zTop0) < 1e-6 &&
|
||||
Math.abs(slope(sg) - slope(last)) < 1e-6 &&
|
||||
Math.abs(sg.cosTheta - last.cosTheta) < 1e-6
|
||||
) {
|
||||
const hi = Math.max(last.tHi, sg.tHi);
|
||||
last.zTop1 = lineZ(last, hi);
|
||||
last.tHi = hi;
|
||||
} else {
|
||||
merged.push({ ...sg });
|
||||
}
|
||||
const sg = core().section_roof_segments_flat(base.x, base.y, uDir.x, uDir.y, Float64Array.from(pl));
|
||||
const merged: Array<{ tLo: number; tHi: number; zTop0: number; zTop1: number; cosTheta: number }> = [];
|
||||
for (let k = 0; k < (sg[0] ?? 0); k++) {
|
||||
const o = 1 + 5 * k;
|
||||
merged.push({ tLo: sg[o], tHi: sg[o + 1], zTop0: sg[o + 2], zTop1: sg[o + 3], cosTheta: sg[o + 4] });
|
||||
}
|
||||
|
||||
for (const { tLo, tHi, zTop0, zTop1, cosTheta } of merged) {
|
||||
@@ -1384,69 +1176,19 @@ export function mergeMonolithCuts(
|
||||
/**
|
||||
* Äussere Umrisse der Vereinigung achsparalleler Rechtecke (Raster über alle
|
||||
* Kanten-Koordinaten, Randkanten verketten). Liefert je zusammenhängender
|
||||
* Fläche den Aussenring (CCW); Innenringe (Löcher) entfallen.
|
||||
* Fläche den Aussenring (CCW); Innenringe (Löcher) entfallen. Rechnet der Kern.
|
||||
*/
|
||||
export function unionRectOutlines(rects: Rect[]): Array<Array<[number, number]>> {
|
||||
const xs = [...new Set(rects.flatMap((r) => [r.uMin, r.uMax]))].sort((a, b) => a - b);
|
||||
const ys = [...new Set(rects.flatMap((r) => [r.vMin, r.vMax]))].sort((a, b) => a - b);
|
||||
const nx = xs.length - 1;
|
||||
const ny = ys.length - 1;
|
||||
if (nx < 1 || ny < 1) return [];
|
||||
const filled = (i: number, j: number): boolean => {
|
||||
if (i < 0 || j < 0 || i >= nx || j >= ny) return false;
|
||||
const cx = (xs[i] + xs[i + 1]) / 2;
|
||||
const cy = (ys[j] + ys[j + 1]) / 2;
|
||||
return rects.some((r) => cx > r.uMin && cx < r.uMax && cy > r.vMin && cy < r.vMax);
|
||||
};
|
||||
const cell: boolean[][] = [];
|
||||
for (let i = 0; i < nx; i++) {
|
||||
cell.push([]);
|
||||
for (let j = 0; j < ny; j++) cell[i].push(filled(i, j));
|
||||
}
|
||||
const at = (i: number, j: number) => i >= 0 && j >= 0 && i < nx && j < ny && cell[i][j];
|
||||
// Gerichtete Randkanten (Fläche links → CCW), als Gitterpunkt-Paare.
|
||||
const next = new Map<string, [number, number]>();
|
||||
const key = (i: number, j: number) => `${i},${j}`;
|
||||
for (let i = 0; i < nx; i++) {
|
||||
for (let j = 0; j < ny; j++) {
|
||||
if (!cell[i][j]) continue;
|
||||
if (!at(i, j - 1)) next.set(key(i, j), [i + 1, j]); // unten, nach rechts
|
||||
if (!at(i + 1, j)) next.set(key(i + 1, j), [i + 1, j + 1]); // rechts, nach oben
|
||||
if (!at(i, j + 1)) next.set(key(i + 1, j + 1), [i, j + 1]); // oben, nach links
|
||||
if (!at(i - 1, j)) next.set(key(i, j + 1), [i, j]); // links, nach unten
|
||||
}
|
||||
}
|
||||
const b: number[] = [rects.length];
|
||||
for (const r of rects) b.push(r.uMin, r.uMax, r.vMin, r.vMax);
|
||||
const f = core().section_union_outlines_flat(Float64Array.from(b));
|
||||
const rings: Array<Array<[number, number]>> = [];
|
||||
const used = new Set<string>();
|
||||
for (const start of next.keys()) {
|
||||
if (used.has(start)) continue;
|
||||
let i = 1;
|
||||
for (let k = 0; k < (f[0] ?? 0); k++) {
|
||||
const count = f[i++];
|
||||
const ring: Array<[number, number]> = [];
|
||||
let k = start;
|
||||
while (!used.has(k)) {
|
||||
used.add(k);
|
||||
const [i, j] = k.split(",").map(Number);
|
||||
ring.push([xs[i], ys[j]]);
|
||||
const n = next.get(k);
|
||||
if (!n) break;
|
||||
k = key(n[0], n[1]);
|
||||
}
|
||||
// Kollineare Zwischenpunkte entfernen.
|
||||
const simple = ring.filter((p, idx) => {
|
||||
const a = ring[(idx + ring.length - 1) % ring.length];
|
||||
const b = ring[(idx + 1) % ring.length];
|
||||
return !((a[0] === p[0] && p[0] === b[0]) || (a[1] === p[1] && p[1] === b[1]));
|
||||
});
|
||||
if (simple.length >= 4 && signedArea(simple) > 0) rings.push(simple);
|
||||
for (let j = 0; j < count; j++, i += 2) ring.push([f[i], f[i + 1]]);
|
||||
rings.push(ring);
|
||||
}
|
||||
return rings;
|
||||
}
|
||||
|
||||
function signedArea(ring: Array<[number, number]>): number {
|
||||
let a = 0;
|
||||
for (let i = 0; i < ring.length; i++) {
|
||||
const [x0, y0] = ring[i];
|
||||
const [x1, y1] = ring[(i + 1) % ring.length];
|
||||
a += x0 * y1 - x1 * y0;
|
||||
}
|
||||
return a / 2;
|
||||
}
|
||||
+68
-208
@@ -40,22 +40,13 @@
|
||||
// truck-Extrusionen, freie 2D-Geometrie) hat ihre eigene Datei unter
|
||||
// `toWalls3d/` — siehe dort für die konkrete Emissions-Logik je Bauteil.
|
||||
|
||||
import type { Project, Vec2, Wall } from "../model/types";
|
||||
import { getWallType, wallTypeThickness } from "../model/types";
|
||||
import { stairVerticalExtent } from "../model/wall";
|
||||
import { openingJambs, openingVerticalExtent } from "../geometry/opening";
|
||||
import type { Project, Vec2 } from "../model/types";
|
||||
import type { DetailLevel } from "../model/viewTypes";
|
||||
import { stairBBox, stairGeometry } from "../geometry/stair";
|
||||
import { roofBaseElevation, roofGeometry } from "../geometry/roof";
|
||||
import type { Vec3 as RoofVec3 } from "../geometry/roof";
|
||||
import { computeJoins } from "../model/joins";
|
||||
import type { WallCuts } from "../model/joins";
|
||||
import { documentFor } from "../core/document";
|
||||
import type { PickOpening, PickRoof, PickStair, PickContextMesh, PickDrawingSeg } from "./pickTypes";
|
||||
import {
|
||||
EPS,
|
||||
IMPORTED_RGB,
|
||||
TERRAIN_RGB,
|
||||
wallMaterialColorMaps,
|
||||
type RMesh,
|
||||
type RModel3d,
|
||||
type RRgb,
|
||||
@@ -63,114 +54,57 @@ import {
|
||||
type RVec2,
|
||||
type RWall,
|
||||
} from "./toWalls3d/shared";
|
||||
import { emitWalls } from "./toWalls3d/bands";
|
||||
import { emitSlabs } from "./toWalls3d/ceilings";
|
||||
import { emitStairMeshes, emitStairRailings, emitStairs } from "./toWalls3d/stairs";
|
||||
import { emitExtrudedSolids, TRUCK_MESH_READY_EVENT } from "./toWalls3d/extrusions";
|
||||
import { applyVoids3d } from "./toWalls3d/voids3d";
|
||||
import { emitDrawingLineVerts, pickDrawingSegs } from "./toWalls3d/drawing2d";
|
||||
import { emitColumns } from "./toWalls3d/columns";
|
||||
import { emitRoofCutLayers, emitRoofs } from "./toWalls3d/roofs";
|
||||
import { emitOpeningMeshes } from "./toWalls3d/openings";
|
||||
|
||||
// Re-Export des gemeinsamen Vokabulars — externe Konsumenten (viewport/,
|
||||
// export/, toSection.ts, nativeSync.ts, …) importieren weiterhin
|
||||
// ausschliesslich von hier, unverändert zur Zeit vor dem Domänen-Split.
|
||||
export { wallMaterialColorMaps, TRUCK_MESH_READY_EVENT };
|
||||
// 2D-Boden-Spuren gehen NICHT über `RModel3d`, sondern als LineList über den
|
||||
// binären `set_drawing_lines`-Kanal (s. dortige Funktionsdoc) — der Viewport
|
||||
// holt sie direkt hier ab.
|
||||
export { emitDrawingLineVerts };
|
||||
export { TRUCK_MESH_READY_EVENT };
|
||||
export type { RVec2, RRgb, RWall, RSlab, RModel3d };
|
||||
|
||||
/** World-Punkt [x, Höhe, y] für den Dach-Pick (Vec3-Konvention von raycast3d). */
|
||||
type RoofPickVec3 = [number, number, number];
|
||||
/**
|
||||
* Boden-Spuren aller 2D-Zeichnungen (Linie, Polylinie, Rechteck) als LineList-Vertices
|
||||
* `[px, py, pz, r, g, b]` in Welt-Metern für render3d (`set_drawing_lines`, Binärkanal — ein
|
||||
* Kataster-DXF kann Millionen Segmente liefern, als JSON-Mesh sprengte das Speicher und
|
||||
* String-Länge). Rechnet der Kern (`model3d.rs`, Chargen).
|
||||
*/
|
||||
export function emitDrawingLineVerts(project: Project): Float32Array {
|
||||
return documentFor(project).drawingLineVerts();
|
||||
}
|
||||
|
||||
/** Weltpunkt (x, elevation, y) — nur intern für Highlight-Kantengeometrie. */
|
||||
type RVec3 = [number, number, number];
|
||||
|
||||
/**
|
||||
* Emittiert die rohen Kontext-Meshes eines Projekts: Gelände-TINs (`terrainMesh`)
|
||||
* und importierte Volumen (`importedMesh`) aus `project.context`, plus alle
|
||||
* übrigen Kontext-Mesh-Domänen (truck-Extrusionen, Stützen, 2D-Boden-Spuren).
|
||||
* `contourSet` bleibt außen vor — das sind nur 2D-Linien (Höhenlinien/
|
||||
* Footprints), keine Dreiecksmeshes. Die `positions`/`indices` der Geo-Meshes
|
||||
* werden 1:1 durchgereicht (Modell-Koordinaten, x,y,z=Höhe); render3d bildet
|
||||
* sie selbst nach world ab.
|
||||
*/
|
||||
function emitMeshes(project: Project): RMesh[] {
|
||||
const out: RMesh[] = [];
|
||||
for (const obj of project.context ?? []) {
|
||||
if (obj.type === "terrainMesh" || obj.type === "importedMesh") {
|
||||
// Leere/entartete Meshes überspringen (render3d würde sie ohnehin verwerfen).
|
||||
if (obj.positions.length < 9 || obj.indices.length < 3) continue;
|
||||
out.push({
|
||||
positions: obj.positions,
|
||||
indices: obj.indices,
|
||||
kind: obj.type === "terrainMesh" ? "terrain" : "imported",
|
||||
color: obj.type === "terrainMesh" ? TERRAIN_RGB : IMPORTED_RGB,
|
||||
// Luftbild-Drape: das Gelände-TIN kann Pro-Vertex-Farben tragen (beim
|
||||
// Import aus dem Luftbild gesampelt) — dann zeigt render3d das Ortho
|
||||
// statt der Flächen-Grundfarbe.
|
||||
vertexColors:
|
||||
obj.type === "terrainMesh" && obj.vertexColors?.length
|
||||
? obj.vertexColors
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
// 2D-Zeichnungen sind hier bewusst NICHT dabei: sie gehen als LineList über
|
||||
// den binären `set_drawing_lines`-Kanal (s. `emitDrawingLineVerts`), weil ein
|
||||
// Kataster-Import als Meshes im JSON-Modell weder serialisierbar noch
|
||||
// speicherbar wäre (s. dortige Funktionsdoc).
|
||||
//
|
||||
// KEIN `out.push(...emitX(project))`: der Spread-Operator sprengt bei grossen
|
||||
// Arrays die Argumentzahl-Grenze von `push` (RangeError "Maximum call stack
|
||||
// size exceeded") — dieselbe, bereits dokumentierte Falle wie in
|
||||
// `swissBuildings3d.ts::concatMeshes`/`dwgParser.ts`.
|
||||
for (const m of emitExtrudedSolids(project)) out.push(m);
|
||||
for (const m of emitColumns(project)) out.push(m);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nur die Wände (Rückwärts-Kompatibilität / bestehende Aufrufer). Zerlegt Wände
|
||||
* mit Öffnungen in Teilquader.
|
||||
* Nur die Wände (Rückwärts-Kompatibilität / bestehende Aufrufer). Zerlegt Wände mit Öffnungen in
|
||||
* Teilquader bzw. (layered) in Schicht-Bänder. Rechnet der Kern auf dem Projekt-Dokument
|
||||
* (`model3d.rs`: Verschneidung je Geschoss, Bänder, Öffnungen, Decken-/Dach-Dominanz).
|
||||
*/
|
||||
export function projectToWalls3d(project: Project, layered = true): RWall[] {
|
||||
const out: RWall[] = [];
|
||||
// Verschneidungs-Schnittlinien PRO GESCHOSS berechnen (wie generatePlan.ts sie
|
||||
// je Grundriss auf der gefilterten Wandmenge bildet) — nur für den layered-3D-
|
||||
// Pfad. Nach Geschoss gruppieren, damit deckungsgleiche Wände verschiedener
|
||||
// Geschosse (z. B. EG/OG an identischen XY-Knoten) NICHT fälschlich verschneiden.
|
||||
// Der Schnitt-Pfad (layered=false) bekommt KEINE Cuts (unverändert, seine
|
||||
// Dominanz macht toSection.ts). Anders als im 2D wird hier NICHT nach
|
||||
// Sichtbarkeit gefiltert — 3D zeigt alle Wände, alle nehmen an den Joins teil.
|
||||
const joins = layered ? computeJoinsByFloor(project) : undefined;
|
||||
emitWalls(out, project, project.walls, layered, joins);
|
||||
return out;
|
||||
return documentFor(project).query<RWall[]>("walls", [layered ? 1 : 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet `computeJoins` getrennt je Geschoss (`wall.floorId`) und führt
|
||||
* die Ergebnis-Maps zu einer flachen `wallId → WallCuts` zusammen. So bilden nur
|
||||
* Wände desselben Geschosses gemeinsame Ecken/T-Stösse (identisch zur 2D-Semantik,
|
||||
* wo `generatePlan` je Grundriss aufruft).
|
||||
* Textur-Karten-URLs der Bauteile in der Reihenfolge des ersten Auftretens (Wandtypen, Decken,
|
||||
* Dächer): die Position + 1 ist die Textur-Ebene (`materialIndex`). Memoisiert je Projekt-Referenz.
|
||||
*/
|
||||
function computeJoinsByFloor(project: Project): Map<string, WallCuts> {
|
||||
const byFloor = new Map<string, Wall[]>();
|
||||
for (const w of project.walls) {
|
||||
const key = w.floorId ?? "";
|
||||
const list = byFloor.get(key);
|
||||
if (list) list.push(w);
|
||||
else byFloor.set(key, [w]);
|
||||
const materialMapCache = new WeakMap<Project, string[]>();
|
||||
export function wallMaterialColorMaps(project: Project): string[] {
|
||||
let maps = materialMapCache.get(project);
|
||||
if (!maps) {
|
||||
maps = documentFor(project).query<string[]>("materialMaps");
|
||||
materialMapCache.set(project, maps);
|
||||
}
|
||||
const merged = new Map<string, WallCuts>();
|
||||
for (const walls of byFloor.values()) {
|
||||
const cuts = computeJoins(project, walls);
|
||||
for (const [id, wc] of cuts) merged.set(id, wc);
|
||||
}
|
||||
return merged;
|
||||
return maps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dach-Meshes (geschlossene, geschichtete Körper je Dachschicht); `onlyRoofId` beschränkt auf ein
|
||||
* Dach (IFC-Export). Rechnet der Kern.
|
||||
*/
|
||||
export function roofMeshes(project: Project, onlyRoofId?: string): RMesh[] {
|
||||
return documentFor(project).query<RMesh[]>("roofMeshes", [], onlyRoofId ?? "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,33 +144,46 @@ export interface Model3dOptions {
|
||||
export function projectToModel3d(project: Project, opts: Model3dOptions = {}): RModel3d {
|
||||
const layered = opts.layeredWalls ?? true;
|
||||
const detail = opts.detail ?? "fein";
|
||||
const parts = documentFor(project).query<Model3dParts>(
|
||||
"model3dParts",
|
||||
[layered ? 1 : 0, DETAIL_CODE[detail] ?? 3, opts.forSection ? 1 : 0],
|
||||
);
|
||||
// Die truck-Körper (asynchron, mit Cache) kommen zwischen Kontext-Meshes und Stützen.
|
||||
const meshes: RMesh[] = [...parts.contextMeshes];
|
||||
for (const m of emitExtrudedSolids(project)) meshes.push(m);
|
||||
for (const m of parts.columnMeshes) meshes.push(m);
|
||||
for (const m of parts.openingMeshes) meshes.push(m);
|
||||
for (const m of parts.stairMeshes) meshes.push(m);
|
||||
for (const m of parts.stairRailings) meshes.push(m);
|
||||
for (const m of parts.roofMeshes) meshes.push(m);
|
||||
const model: RModel3d = {
|
||||
walls: projectToWalls3d(project, layered),
|
||||
// Decken + Treppen (Treppentritte als extrudierte Slabs) — so wird die Treppe
|
||||
// auch im WASM/wgpu-Renderer sichtbar (der three.js-Pfad rendert sie separat).
|
||||
slabs: [...emitSlabs(project), ...emitStairs(project, { forSection: opts.forSection })],
|
||||
// Kontext-Meshes (Terrain/Import) + Fenster-/Tür-Glasscheiben (eigenes Mesh
|
||||
// je Scheibe) + Rahmen-/Sprossen-Riegel typisierter Öffnungen (Zarge/
|
||||
// Blendrahmen/Kämpfer/Mittelpfosten, s. emitOpeningMeshes) + glatte Beton-
|
||||
// Laufplatten (gerade Betontreppen als Mesh) + Dachflächen/-giebel
|
||||
// (s. emitRoofs) — pickGeometry/Highlight nutzen `meshes` bewusst NICHT (man
|
||||
// wählt Wand/Öffnung/Treppe; Treppen-Pick läuft über die pickGeometry-Boxen).
|
||||
meshes: [
|
||||
...emitMeshes(project),
|
||||
...emitOpeningMeshes(project, detail),
|
||||
...emitStairMeshes(project),
|
||||
...emitStairRailings(project),
|
||||
...emitRoofs(project),
|
||||
],
|
||||
// Dach-Schicht-Eingabe für den 3D-Live-Schnitt (render3d::roof_cut) — s.
|
||||
// Kopfkommentar bei `RRoofLayer`/`emitRoofCutLayers`: getrennt von `meshes`,
|
||||
// weil `section.rs` beliebige Dreiecksnetze nicht schneiden kann.
|
||||
roofLayers: emitRoofCutLayers(project),
|
||||
walls: parts.walls,
|
||||
// Decken + Treppen (Treppentritte als extrudierte Slabs), Kontext-Meshes, Öffnungs-Einbauteile,
|
||||
// Betonlaufplatten, Handläufe und Dachflächen: alles aus dem Kern; Dach-Schichten für den
|
||||
// 3D-Live-Schnitt getrennt (`roofLayers`).
|
||||
slabs: parts.slabs,
|
||||
meshes,
|
||||
roofLayers: parts.roofLayers,
|
||||
};
|
||||
if (opts.voids) applyVoids3d(model, project);
|
||||
return model;
|
||||
}
|
||||
|
||||
/** Teile des 3D-Modells aus dem Kern (`model3d::Parts`). */
|
||||
interface Model3dParts {
|
||||
walls: RWall[];
|
||||
slabs: RSlab[];
|
||||
contextMeshes: RMesh[];
|
||||
columnMeshes: RMesh[];
|
||||
openingMeshes: RMesh[];
|
||||
stairMeshes: RMesh[];
|
||||
stairRailings: RMesh[];
|
||||
roofMeshes: RMesh[];
|
||||
roofLayers: RModel3d["roofLayers"];
|
||||
}
|
||||
|
||||
const DETAIL_CODE: Record<string, number> = { grob: 0, mittel: 1, fein: 2 };
|
||||
|
||||
/**
|
||||
* Pick-Geometrie für den TS-seitigen 3D-Raycast (siehe viewport/raycast3d): die
|
||||
* Wand-Teilquader (mit `wallId`) und Decken-Prismen (mit `ceilingId`) desselben
|
||||
@@ -259,94 +206,7 @@ export function pickGeometry(
|
||||
contextMeshes: PickContextMesh[];
|
||||
drawings: PickDrawingSeg[];
|
||||
} {
|
||||
// Dächer: Dachflächen + Giebel als WORLD-Dreiecke (fan-trianguliert wie
|
||||
// emitRoofs; model [x,y,z=Höhe] → world [x, z, y]) — präzise geneigte
|
||||
// Flächen für den Ray-Dreieck-Pick (raycast3d.rayRoofTris).
|
||||
const roofs: PickRoof[] = [];
|
||||
for (const roof of project.roofs ?? []) {
|
||||
const eavesZ = roofBaseElevation(project, roof);
|
||||
const g = roofGeometry(roof, eavesZ);
|
||||
const tris: [RoofPickVec3, RoofPickVec3, RoofPickVec3][] = [];
|
||||
const toWorld = (p: RoofVec3): RoofPickVec3 => [p[0], p[2], p[1]];
|
||||
for (const poly of [...g.planes.map((pl) => pl.pts), ...g.gables]) {
|
||||
for (let i = 1; i + 1 < poly.length; i++) {
|
||||
tris.push([toWorld(poly[0]), toWorld(poly[i]), toWorld(poly[i + 1])]);
|
||||
}
|
||||
}
|
||||
if (tris.length > 0) roofs.push({ tris, roofId: roof.id });
|
||||
}
|
||||
const openings: PickOpening[] = [];
|
||||
for (const o of project.openings ?? []) {
|
||||
const wall = project.walls.find((w) => w.id === o.hostWallId);
|
||||
if (!wall) continue;
|
||||
const jambs = openingJambs(wall, o);
|
||||
if (!jambs) continue;
|
||||
const thickness = wallTypeThickness(getWallType(project, wall));
|
||||
const { zBottom, zTop } = openingVerticalExtent(project, wall, o);
|
||||
if (zTop - zBottom <= 0) continue;
|
||||
openings.push({
|
||||
start: [jambs.jambStart.x, jambs.jambStart.y],
|
||||
end: [jambs.jambEnd.x, jambs.jambEnd.y],
|
||||
thickness,
|
||||
height: zTop - zBottom,
|
||||
baseElevation: zBottom,
|
||||
openingId: o.id,
|
||||
});
|
||||
}
|
||||
const stairs: PickStair[] = [];
|
||||
for (const st of project.stairs ?? []) {
|
||||
const { zBottom, zTop } = stairVerticalExtent(project, st);
|
||||
const totalRise = zTop - zBottom;
|
||||
if (totalRise <= 0) continue;
|
||||
const bbox = stairBBox(stairGeometry(st, totalRise));
|
||||
stairs.push({
|
||||
outline: [
|
||||
[bbox.minX, bbox.minY],
|
||||
[bbox.maxX, bbox.minY],
|
||||
[bbox.maxX, bbox.maxY],
|
||||
[bbox.minX, bbox.maxY],
|
||||
],
|
||||
zBottom,
|
||||
zTop,
|
||||
stairId: st.id,
|
||||
});
|
||||
}
|
||||
// Kontext-Meshes (importierte Gebäude/Terrain, s. ContextObject): rohe
|
||||
// WORLD-Dreiecke, direkt aus dem Indexpuffer (kein Fan nötig — ImportedMesh/
|
||||
// TerrainMesh liefern bereits ein echtes Dreiecksnetz). Kaputte Indizes
|
||||
// robust überspringen statt abzustürzen (importierte Daten).
|
||||
// Modell (x,y,z) → world (x, z, −y) — Nord-Achse NEGIERT, damit der Pick
|
||||
// dieselbe (gespiegelte→korrigierte) Lage trifft wie die sichtbare Geometrie
|
||||
// in `viewport3d/meshBuilders.ts::buildContextMesh` (dort ausführlich
|
||||
// begründet: reines Achsen-Vertauschen ohne Vorzeichenwechsel ist für einen
|
||||
// allgemeinen xyz-Punktsatz eine Spiegelung, anders als bei Wand/Dach, die
|
||||
// über eine orientierungserhaltende Rotation/Fächer-Triangulation entstehen).
|
||||
const contextMeshes: PickContextMesh[] = [];
|
||||
for (const obj of project.context ?? []) {
|
||||
if (obj.type === "contourSet" || obj.type === "image") continue;
|
||||
const pos = obj.positions;
|
||||
const vcount = pos.length / 3;
|
||||
const tris: [RoofPickVec3, RoofPickVec3, RoofPickVec3][] = [];
|
||||
for (let i = 0; i + 2 < obj.indices.length; i += 3) {
|
||||
const ia = obj.indices[i];
|
||||
const ib = obj.indices[i + 1];
|
||||
const ic = obj.indices[i + 2];
|
||||
if (ia >= vcount || ib >= vcount || ic >= vcount) continue;
|
||||
const at = (idx: number): RoofPickVec3 => [pos[idx * 3], pos[idx * 3 + 2], -pos[idx * 3 + 1]];
|
||||
tris.push([at(ia), at(ib), at(ic)]);
|
||||
}
|
||||
if (tris.length > 0) contextMeshes.push({ tris, contextObjectId: obj.id });
|
||||
}
|
||||
const drawings = pickDrawingSegs(project);
|
||||
return {
|
||||
walls: projectToWalls3d(project),
|
||||
slabs: emitSlabs(project),
|
||||
openings,
|
||||
stairs,
|
||||
roofs,
|
||||
contextMeshes,
|
||||
drawings,
|
||||
};
|
||||
return documentFor(project).query("pickGeometry");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,346 +0,0 @@
|
||||
// Wand-Domäne der 3D-Ableitung (SCHICHTEN → Bänder → Boxen, siehe Moduldoc in
|
||||
// `../../toWalls3d.ts`): löst den Schichtaufbau EINER Wand in quer zur Dicke
|
||||
// gestapelte Materialbänder auf und emittiert daraus Wandkörper — inklusive
|
||||
// aller materialbewussten Verschneidungen (Gehrungs-/Anschluss-Cuts an L-/
|
||||
// T-Stössen, Durchgangswand-Span-Cutouts, Decken-Dominanz pro Schicht, Dach-
|
||||
// Unterkanten-Kappung mit schräger Oberkante). Das 3D-Pendant zu
|
||||
// `generatePlan/walls.ts::addWallPoche`.
|
||||
//
|
||||
// Gerechnet wird im Rust-Kern (`src-tauri/core/src/wall_bands.rs`); hier bleiben
|
||||
// das Sammeln aus dem `Project` (Wandtyp, Öffnungen, Decken- und Dachaufbau,
|
||||
// Höhen), die flache Übergabe und die Darstellungs-Metadaten je Band (Farbe,
|
||||
// Schraffur, Material, Schnitt-Stil).
|
||||
|
||||
import type { Project, Wall } from "../../model/types";
|
||||
import {
|
||||
getCeilingType,
|
||||
getComponent,
|
||||
getWallType,
|
||||
getWindowType,
|
||||
openingsOfWall,
|
||||
roofLayers,
|
||||
wallTypeThickness,
|
||||
} from "../../model/types";
|
||||
import { ceilingVerticalExtent, wallVerticalExtent } from "../../model/wall";
|
||||
import { openingInterval, openingVerticalExtent } from "../../geometry/opening";
|
||||
import { roofBaseElevation, roofGeometry, roofPlanesFlat } from "../../geometry/roof";
|
||||
import { writeWallCuts, type WallCuts } from "../../model/joins";
|
||||
import { FlatReader, FlatWriter } from "../../geometry/coreFlat";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import {
|
||||
WALL_RGB,
|
||||
dominantLayerColor,
|
||||
dominantLayerHatch,
|
||||
hexToRgb,
|
||||
resolveComponentHatch,
|
||||
resolveComponentMaterialLayer,
|
||||
resolveCutLineStyle,
|
||||
type RCutMeta,
|
||||
type RHatch,
|
||||
type RHole,
|
||||
type RRgb,
|
||||
type RWall,
|
||||
} from "./shared";
|
||||
|
||||
/**
|
||||
* Achswinkel einer GESCHNITTENEN Wand im Schnitt-Koordinatensystem (Modell-
|
||||
* Konvention, identisch zu `SECTION_WALL_AXIS_ANGLE_DEG` in toSection.ts): das
|
||||
* Wand-Band steht vertikal (Achse entlang v, atan2(1,0) = 90°). Damit drehen
|
||||
* `relativeToWall`-Muster (Dämmung, Backstein) im 3D-Schnitt genauso mit der Wand
|
||||
* wie im 2D-Schnitt (`splitWallLayers` → `resolveHatch(…, 90, …)`). Für DECKEN gibt
|
||||
* es keinen Wandachsen-Bezug — dort bleibt der Winkel absolut (`emitSlabs` ruft
|
||||
* `resolveComponentHatch` ohne Achswinkel, wie `splitSlabLayers` → `resolveHatch(…,
|
||||
* undefined, …)`), sodass die liegende Boden-Dämmung vertikal statt horizontal läuft.
|
||||
*/
|
||||
const SECTION_WALL_AXIS_ANGLE_DEG = 90;
|
||||
|
||||
/**
|
||||
* Eine quer zur Wanddicke gestapelte Materiallage als 3D-Band: eigene Dicke und
|
||||
* Materialfarbe. Den Mitten-Versatz (Stapel um die Achse, Referenzlinie) rechnet
|
||||
* der Kern (`wall_bands.rs`); jede Lage wird dort pro Achsen-Teilstück zu einer
|
||||
* eigenen Voll-Box.
|
||||
*/
|
||||
interface WallBand {
|
||||
thickness: number;
|
||||
color: RRgb;
|
||||
/** Schnitt-Schraffur des Band-Bauteils (siehe {@link RHatch}). */
|
||||
hatch?: RHatch;
|
||||
/** Material-Textur-Ebene des Band-Bauteils (1-basiert, siehe `wallMaterialColorMaps`). */
|
||||
materialIndex?: number;
|
||||
/**
|
||||
* Verschneidungs-Rang dieser Materiallage (`Component.joinPriority`) — treibt
|
||||
* die per-Schicht-Dominanz gegen Decken im layered-3D-Pfad (s. `wall_bands.rs`):
|
||||
* eine Decke mit STRIKT höherer
|
||||
* `joinPriority` schneidet nur die Bänder mit niedrigerem Rang aus ihrem
|
||||
* z-Intervall (der Kern höherer Priorität läuft durch). `undefined` (kein
|
||||
* auflösbarer WallType / synthetisches Fallback-Band) ⇒ keine Decken-
|
||||
* Subtraktion (konservativ, wie das frühere Trim-Verhalten bei unbekanntem Typ).
|
||||
*/
|
||||
priority?: number;
|
||||
/**
|
||||
* Bauteil-Identität dieser Materiallage (`Component.id`) — treibt die MERGE-Regel
|
||||
* der Schnitt-Boolean-Dominanz (gleiche Komponente + Priorität verschmelzen, keine
|
||||
* innere Trennlinie). Reist als `RCutMeta.componentId` mit.
|
||||
*/
|
||||
componentId?: string;
|
||||
/** Farbe der Schnitt-Umrisslinie dieser Schicht (aus `jointLineStyleId`, sonst Default). */
|
||||
cutLineColor?: RRgb;
|
||||
/** Strichstärke der Schnitt-Umrisslinie in mm-Papier (aus `jointLineStyleId`, sonst Default). */
|
||||
cutLineWeight?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut die {@link RCutMeta}-Nutzlast eines Wand-Bandes (Priorität/Identität/
|
||||
* Schnittkanten-Stil), oder `undefined`, wenn das Band keinerlei Schnitt-Metadaten
|
||||
* trägt (z. B. das Fallback-Vollkörper-Band ohne auflösbaren WallType). Nur gesetzte
|
||||
* Felder werden übernommen, damit `#[serde(default)]` auf der Rust-Seite greift.
|
||||
*/
|
||||
function bandCutMeta(b: WallBand): RCutMeta | undefined {
|
||||
const meta: RCutMeta = {};
|
||||
if (b.priority !== undefined) meta.joinPriority = b.priority;
|
||||
if (b.componentId !== undefined) meta.componentId = b.componentId;
|
||||
if (b.cutLineColor !== undefined) meta.lineColor = b.cutLineColor;
|
||||
if (b.cutLineWeight !== undefined) meta.lineWeight = b.cutLineWeight;
|
||||
return Object.keys(meta).length > 0 ? meta : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst den Schichtstapel EINER Wand auf: je Materiallage ein {@link WallBand}
|
||||
* mit ihrer Dicke und Component-Farbe (`stacked: true`). Der Kern stapelt die
|
||||
* Lagen um die Wandachse und verschiebt den Stapel um den Referenzversatz
|
||||
* (`Wall.referenceLine`/`referenceOffset`), wie der 2D-Plan und die Gehrungs-
|
||||
* Cuts. Gesamtdicke = SUMME der Lagen-Dicken (lückenlos). Kein auflösbarer
|
||||
* WallType / keine Lagen ⇒ EIN Vollkörper-Band über die volle Dicke im neutralen
|
||||
* Grundton (`stacked: false`, ebenfalls Referenz-versetzt).
|
||||
*/
|
||||
function resolveWallBands(project: Project, wall: Wall, layered = true): { bands: WallBand[]; stacked: boolean } {
|
||||
try {
|
||||
const wt = getWallType(project, wall);
|
||||
if (wt.layers.length > 0) {
|
||||
// Gesamtdicke = Summe der Lagen (konsistent mit den Offsets); wenn diese
|
||||
// von wallTypeThickness abwiche, gewinnt die Lagen-Summe (keine Lücken).
|
||||
const total = wt.layers.reduce((s, l) => s + l.thickness, 0);
|
||||
// Schnitt-Eingabe (layered=false): EINE Voll-Box über die ganze Dicke statt
|
||||
// je Lage eine Box. So bleibt die Emission 1:1 Wand→Rechteck — passend zu
|
||||
// `wallSegmentOwners`/`splitWallLayers` in toSection.ts, die die Schicht-
|
||||
// Zerlegung TS-seitig aus diesem einen Rechteck machen. (Der 3D-Viewer ruft
|
||||
// mit Default layered=true auf und bekommt unverändert die Schicht-Bänder.)
|
||||
if (!layered) {
|
||||
const dominant = wt.layers.reduce((best, l) => (l.thickness > best.thickness ? l : best));
|
||||
const band: WallBand = {
|
||||
thickness: total,
|
||||
color: dominantLayerColor(wt.layers, project, WALL_RGB),
|
||||
hatch: dominantLayerHatch(wt.layers, project, SECTION_WALL_AXIS_ANGLE_DEG),
|
||||
materialIndex: resolveComponentMaterialLayer(project, dominant.componentId),
|
||||
};
|
||||
return { bands: [band], stacked: false };
|
||||
}
|
||||
const bands: WallBand[] = [];
|
||||
for (const l of wt.layers) {
|
||||
const comp = getComponent(project, l.componentId);
|
||||
const color = hexToRgb(comp.color);
|
||||
const lineStyle = resolveCutLineStyle(project, l.jointLineStyleId);
|
||||
bands.push({
|
||||
thickness: l.thickness,
|
||||
color,
|
||||
priority: comp.joinPriority,
|
||||
componentId: comp.id,
|
||||
cutLineColor: lineStyle?.color,
|
||||
cutLineWeight: lineStyle?.weight,
|
||||
hatch: resolveComponentHatch(project, l.componentId, SECTION_WALL_AXIS_ANGLE_DEG),
|
||||
materialIndex: resolveComponentMaterialLayer(project, l.componentId),
|
||||
});
|
||||
}
|
||||
return { bands, stacked: true };
|
||||
}
|
||||
// WallType ohne Schichten: EIN Vollkörper über die Typ-Gesamtdicke.
|
||||
return { bands: [{ thickness: wallTypeThickness(wt), color: WALL_RGB }], stacked: false };
|
||||
} catch {
|
||||
// Kein auflösbarer WallType: EIN Vollkörper mit Default-Dicke/Grundton.
|
||||
return { bands: [{ thickness: 0.2, color: WALL_RGB }], stacked: false };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt `topAngle` (Draufsicht): wie der 2D-Grundriss — das Muster folgt der Wandachse
|
||||
* (`relativeToWall`), `resolveHatch` zieht den Wandwinkel ab (SVG-Konvention, y nach unten);
|
||||
* render3d rechnet in Modell-Winkeln (gegen den Uhrzeigersinn), daher das Vorzeichen.
|
||||
*/
|
||||
function withTopAngle(h: RHatch, dx: number, dy: number): RHatch {
|
||||
if (h.baseAngle === undefined) return h;
|
||||
const wallAngle = (Math.atan2(dy, dx) * 180) / Math.PI;
|
||||
const svgAngle = h.relativeToWall ? h.baseAngle - wallAngle : h.baseAngle;
|
||||
// Parallel-/Kreuzschar (diagonal=2, crosshatch=3): die 2D-Kachel trägt bei Winkel 0 eine
|
||||
// SENKRECHTE Musterlinie (glPlanHatch: Basisrichtung (0,−1)), der 3D-Shader bei Winkel 0
|
||||
// eine HORIZONTALE → um 90° versetzen. Die Dämmungs-Welle (4) läuft in beiden entlang u.
|
||||
const quarter = h.pattern === 2 || h.pattern === 3 ? 90 : 0;
|
||||
return { ...h, topAngle: -svgAngle + quarter };
|
||||
}
|
||||
|
||||
/**
|
||||
* Dicke einer Wand für die grobe Grundriss-Hülle (Decken-Vorfilter im Kern):
|
||||
* Summe der WallType-Schichtdicken, sonst der Fallback-Grundton-Dicke aus
|
||||
* {@link resolveWallBands} (0.2 m), falls kein WallType auflösbar ist. Auch von
|
||||
* `openings.ts::emitOpeningMeshes` genutzt (Rahmen-Tiefe auf die Wanddicke
|
||||
* klemmen).
|
||||
*/
|
||||
export function wallThicknessSafe(project: Project, wall: Wall): number {
|
||||
try {
|
||||
return wallTypeThickness(getWallType(project, wall));
|
||||
} catch {
|
||||
return 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
/** `Wall.sliceTermination` → Kodierung im Kern (0 = beide/Standard). */
|
||||
const TERMINATION = { below: 1, above: 2 } as const;
|
||||
|
||||
/**
|
||||
* Schreibt Decken und Dächer EINES Geschosses (Kodierung `wall_bands.rs`): Decken
|
||||
* mit z-Ausdehnung, Umriss und Schichten samt Rang (NaN = Bauteil unbekannt,
|
||||
* Typ-Flag 0 = Deckentyp unbekannt); Dächer mit Traufhöhe, Schichtdicke, Traufe
|
||||
* und Flächen. Ob und wo eine Decke ein Band schneidet bzw. ein Dach die Oberkante
|
||||
* kappt, entscheidet der Kern.
|
||||
*/
|
||||
function writeFloor(w: FlatWriter, project: Project, floorId: string | undefined): void {
|
||||
const ceilings = (project.ceilings ?? []).filter((c) => c.floorId === floorId && c.outline && c.outline.length >= 3);
|
||||
w.num(ceilings.length);
|
||||
for (const c of ceilings) {
|
||||
const ext = ceilingVerticalExtent(project, c);
|
||||
w.num(ext.zBottom, ext.zTop).ring(c.outline);
|
||||
let layers;
|
||||
try {
|
||||
layers = getCeilingType(project, c).layers;
|
||||
} catch {
|
||||
w.num(0, 0);
|
||||
continue;
|
||||
}
|
||||
w.num(1, layers.length);
|
||||
for (const l of layers) {
|
||||
let prio = Number.NaN;
|
||||
try {
|
||||
prio = getComponent(project, l.componentId).joinPriority;
|
||||
} catch {
|
||||
// Unbekanntes Bauteil: diese Deckenschicht schneidet nicht.
|
||||
}
|
||||
w.num(l.thickness, prio);
|
||||
}
|
||||
}
|
||||
const roofs = (project.roofs ?? []).filter((r) => r.floorId === floorId);
|
||||
w.num(roofs.length);
|
||||
for (const r of roofs) {
|
||||
const eavesZ = roofBaseElevation(project, r);
|
||||
const geo = roofGeometry(r, eavesZ);
|
||||
const total = roofLayers(project, r).reduce((s, l) => s + Math.max(0, l.thickness), 0);
|
||||
w.num(eavesZ, total).ring(geo.eaves);
|
||||
const planes = roofPlanesFlat(geo);
|
||||
for (let i = 0; i < planes.length; i++) w.num(planes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emittiert die Wandkörper der Wände `walls` in EINEM Kern-Aufruf (Decken/Dächer je
|
||||
* Geschoss nur einmal übergeben). Reihenfolge der Körper wie Wand für Wand.
|
||||
*
|
||||
* ZWEI PFADE je `layered`:
|
||||
* • layered=true (3D-Viewer, Default): EIN Körper pro Schicht-Band über die
|
||||
* VOLLE Achse mit allen Öffnungen als echte `holes` (render3d stanzt sie in
|
||||
* die Langseiten), dazu die materialbewussten Verschneidungen (End-Cuts/Merge
|
||||
* an L-/T-Stössen aus `joins`, Durchgangswand-Span-Cutouts, Decken-Dominanz
|
||||
* pro Schicht, schräge Oberkante unter Dächern als `topDrop`).
|
||||
* • layered=false (Schnitt-Pfad, `computeSection`): Pfeiler/Brüstung/Sturz-
|
||||
* Segmentierung (EIN Voll-Band je Segment), passend zu
|
||||
* `toSection.ts::wallSegmentOwners`. Keine Löcher, keine Cuts.
|
||||
*/
|
||||
export function emitWalls(
|
||||
out: RWall[],
|
||||
project: Project,
|
||||
walls: readonly Wall[],
|
||||
layered = true,
|
||||
joins?: Map<string, WallCuts>,
|
||||
): void {
|
||||
const w = new FlatWriter().num(walls.length);
|
||||
const floors = new FlatWriter();
|
||||
const floorIndex = new Map<string | undefined, number>();
|
||||
const bandsOf: WallBand[][] = [];
|
||||
|
||||
for (const wall of walls) {
|
||||
const { bands, stacked } = resolveWallBands(project, wall, layered);
|
||||
bandsOf.push(bands);
|
||||
const { zBottom, zTop } = wallVerticalExtent(project, wall);
|
||||
let floor = -1;
|
||||
if (layered) {
|
||||
floor = floorIndex.get(wall.floorId) ?? -1;
|
||||
if (floor < 0) {
|
||||
floor = floorIndex.size;
|
||||
floorIndex.set(wall.floorId, floor);
|
||||
writeFloor(floors, project, wall.floorId);
|
||||
}
|
||||
}
|
||||
w.num(floor, wall.start.x, wall.start.y, wall.end.x, wall.end.y, zBottom, zTop, layered ? 1 : 0, stacked ? 1 : 0);
|
||||
if (wall.referenceOffset != null) w.num(3, wall.referenceOffset);
|
||||
else w.num(wall.referenceLine === "left" ? 1 : wall.referenceLine === "right" ? 2 : 0, 0);
|
||||
const term = wall.sliceTermination === "below" || wall.sliceTermination === "above" ? TERMINATION[wall.sliceTermination] : 0;
|
||||
w.num(wallThicknessSafe(project, wall), term, bands.length);
|
||||
for (const b of bands) w.num(b.thickness, b.priority ?? Number.NaN);
|
||||
|
||||
// Öffnungen (Fenster und Türen): Achsen-Intervall + vertikale Ausdehnung.
|
||||
const slot = w.slot();
|
||||
let nOpenings = 0;
|
||||
for (const op of openingsOfWall(project, wall.id)) {
|
||||
const iv = openingInterval(wall, op);
|
||||
if (!iv) continue;
|
||||
const v = openingVerticalExtent(project, wall, op);
|
||||
const recess = op.kind === "window" && getWindowType(project, op)?.innerLayerRecess === true;
|
||||
w.num(iv.from, iv.to, v.zBottom, v.zTop, recess ? 1 : 0);
|
||||
nOpenings++;
|
||||
}
|
||||
w.set(slot, nOpenings);
|
||||
writeWallCuts(w, layered ? joins?.get(wall.id) : undefined);
|
||||
}
|
||||
|
||||
const floorBuf = new FlatWriter().num(floorIndex.size).done();
|
||||
const r = new FlatReader(core().wall_bands_flat(w.done(), concat(floorBuf, floors.done())));
|
||||
const nWalls = Math.min(r.count(), walls.length);
|
||||
for (let i = 0; i < nWalls; i++) {
|
||||
const wall = walls[i];
|
||||
const bands = bandsOf[i];
|
||||
const dx = wall.end.x - wall.start.x;
|
||||
const dy = wall.end.y - wall.start.y;
|
||||
for (let n = r.count(); n > 0; n--) {
|
||||
const b = bands[r.num()];
|
||||
const start: [number, number] = [r.num(), r.num()];
|
||||
const end: [number, number] = [r.num(), r.num()];
|
||||
const zb = r.num();
|
||||
const zt = r.num();
|
||||
const sloped = r.num() === 1;
|
||||
const topDrop: [number, number] = [r.num(), r.num()];
|
||||
const holes: RHole[] = [];
|
||||
for (let k = r.count(); k > 0; k--) holes.push({ from: r.num(), to: r.num(), zBottom: r.num(), zTop: r.num() });
|
||||
if (!b) continue;
|
||||
const cut = bandCutMeta(b);
|
||||
out.push({
|
||||
start,
|
||||
end,
|
||||
thickness: b.thickness,
|
||||
height: zt - zb,
|
||||
baseElevation: zb,
|
||||
...(sloped ? { topDrop } : {}),
|
||||
color: b.color,
|
||||
layers: [],
|
||||
wallId: wall.id,
|
||||
...(b.hatch ? { hatch: withTopAngle(b.hatch, dx, dy) } : {}),
|
||||
...(b.materialIndex != null ? { materialIndex: b.materialIndex } : {}),
|
||||
...(holes.length > 0 ? { holes } : {}),
|
||||
...(cut ? { cut } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function concat(a: Float64Array, b: Float64Array): Float64Array {
|
||||
const out = new Float64Array(a.length + b.length);
|
||||
out.set(a);
|
||||
out.set(b, a.length);
|
||||
return out;
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
// Decken-Domäne der 3D-Ableitung: extrudiert `project.ceilings` zu geschichteten
|
||||
// Deckenplatten (eine RSlab je Materiallage, oben→unten gestapelt) — das 3D-
|
||||
// Pendant zu `generatePlan/ceilings.ts::addCeilingPoche`.
|
||||
//
|
||||
// Die Rechnung (Aussparungen über den Brücken-Trick in EINEN einfachen Umriss, derselbe Ring für
|
||||
// ALLE Schichten; z-Spanne proportional auf die Schichten verteilt) steht in Rust
|
||||
// (`src-tauri/core/src/ceilings3d.rs`). Hier nur: aus dem `Project` sammeln und je Schicht
|
||||
// Farbe, Schraffur und Schnitt-Metadaten zuordnen.
|
||||
|
||||
import type { Ceiling, Layer, Project } from "../../model/types";
|
||||
import { getCeilingType, getComponent } from "../../model/types";
|
||||
import { ceilingVerticalExtent } from "../../model/wall";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import { FlatWriter } from "../../geometry/coreFlat";
|
||||
import {
|
||||
SLAB_RGB,
|
||||
hexToRgb,
|
||||
resolveComponentHatch,
|
||||
resolveCutLineStyle,
|
||||
type RCutMeta,
|
||||
type RRgb,
|
||||
type RSlab,
|
||||
type RVec2,
|
||||
} from "./shared";
|
||||
|
||||
/** Emittiert die Deckenplatten eines Projekts (falls vorhanden). */
|
||||
export function emitSlabs(project: Project): RSlab[] {
|
||||
const ceilings: Ceiling[] = [];
|
||||
const layersOf: (Layer[] | undefined)[] = [];
|
||||
const w = new FlatWriter();
|
||||
const count = w.slot();
|
||||
for (const c of project.ceilings ?? []) {
|
||||
if (!c.outline || c.outline.length < 3) continue;
|
||||
// zBottom/zTop (und damit die Deckendicke) berechnet ceilingVerticalExtent
|
||||
// bereits über ceilingThickness (respektiert Typ-Dicke + Übersteuerung).
|
||||
const { zBottom, zTop } = ceilingVerticalExtent(project, c);
|
||||
// Kein auflösbarer Deckentyp ⇒ keine Lagen ⇒ EIN Vollkörper-Slab in SLAB_RGB.
|
||||
let layers: Layer[] | undefined;
|
||||
try {
|
||||
layers = getCeilingType(project, c).layers;
|
||||
} catch {
|
||||
layers = undefined;
|
||||
}
|
||||
w.ring(c.outline);
|
||||
const openings = c.openings ?? [];
|
||||
w.num(openings.length);
|
||||
for (const o of openings) w.ring(o);
|
||||
w.num(zBottom, zTop, layers?.length ?? 0);
|
||||
for (const l of layers ?? []) w.num(l.thickness);
|
||||
ceilings.push(c);
|
||||
layersOf.push(layers);
|
||||
}
|
||||
if (ceilings.length === 0) return [];
|
||||
w.set(count, ceilings.length);
|
||||
const f = core().ceilings3d_flat(w.done());
|
||||
|
||||
const out: RSlab[] = [];
|
||||
let i = 1;
|
||||
for (let n = f.length ? f[0] : 0; n > 0; n--) {
|
||||
const ci = f[i++];
|
||||
const c = ceilings[ci];
|
||||
const layers = layersOf[ci];
|
||||
const nPts = f[i++];
|
||||
const outline: RVec2[] = new Array(nPts);
|
||||
for (let k = 0; k < nPts; k++, i += 2) outline[k] = [f[i], f[i + 1]];
|
||||
for (let s = f[i++]; s > 0; s--, i += 3) {
|
||||
const layerIdx = f[i];
|
||||
const zBottom = f[i + 1];
|
||||
const zTop = f[i + 2];
|
||||
if (layerIdx < 0 || !layers) {
|
||||
out.push({ outline, zBottom, zTop, color: SLAB_RGB, ceilingId: c.id });
|
||||
continue;
|
||||
}
|
||||
const l = layers[layerIdx];
|
||||
let color: RRgb = SLAB_RGB;
|
||||
let cut: RCutMeta | undefined;
|
||||
try {
|
||||
const comp = getComponent(project, l.componentId);
|
||||
color = hexToRgb(comp.color);
|
||||
// Schnitt-Metadaten der Schicht: joinPriority + Identität (für die
|
||||
// Boolean-Dominanz/MERGE) + Schnittkanten-Stil aus jointLineStyleId.
|
||||
const lineStyle = resolveCutLineStyle(project, l.jointLineStyleId);
|
||||
cut = {
|
||||
joinPriority: comp.joinPriority,
|
||||
componentId: comp.id,
|
||||
...(lineStyle?.color ? { lineColor: lineStyle.color } : {}),
|
||||
...(lineStyle?.weight != null ? { lineWeight: lineStyle.weight } : {}),
|
||||
};
|
||||
} catch {
|
||||
color = SLAB_RGB;
|
||||
cut = undefined;
|
||||
}
|
||||
const hatch = resolveComponentHatch(project, l.componentId);
|
||||
out.push({
|
||||
outline,
|
||||
zBottom,
|
||||
zTop,
|
||||
color,
|
||||
ceilingId: c.id,
|
||||
...(hatch ? { hatch } : {}),
|
||||
...(cut ? { cut } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
// Stützen-Domäne der 3D-Ableitung (Tragwerk): extrudiert `project.columns` zu
|
||||
// parametrischen Prisma-Meshes (Rechteck-Box bzw. tesselliertes Kreis-Prisma).
|
||||
//
|
||||
// Das Prisma (Mantel-Quads, Deckel als Dreiecksfächer) rechnet Rust
|
||||
// (`src-tauri/core/src/columns3d.rs`); hier nur Querschnitt und Höhen sammeln und einfärben.
|
||||
|
||||
import type { Column, Project, Vec2 } from "../../model/types";
|
||||
import { getComponent } from "../../model/types";
|
||||
import { columnFootprint } from "../../geometry/column";
|
||||
import { columnVerticalExtent } from "../../model/wall";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import { hexToRgb, type RMesh, type RRgb } from "./shared";
|
||||
|
||||
/** Neutraler Beton-/Tragwerks-Grauton für Stützen (Fallback ohne Bauteil-Farbe). */
|
||||
const COLUMN_RGB: RRgb = [0.7, 0.7, 0.72];
|
||||
|
||||
/**
|
||||
* 3D-Farbe einer Stütze: die Bauteil-Albedo (`Component.color`), falls ein
|
||||
* `componentId` auflösbar ist, sonst der neutrale Tragwerks-Grauton {@link
|
||||
* COLUMN_RGB}. Eine explizite `column.color` (Grundriss-Umrissfarbe) wirkt
|
||||
* bewusst NICHT auf die 3D-Fläche (nur der 2D-Umriss), damit die 3D-Darstellung
|
||||
* material-/neutral bleibt — analog Wand (Umrissfarbe ≠ 3D-Albedo).
|
||||
*/
|
||||
function columnColor3d(project: Project, col: Column): RRgb {
|
||||
if (col.componentId) {
|
||||
try {
|
||||
return hexToRgb(getComponent(project, col.componentId).color, COLUMN_RGB);
|
||||
} catch {
|
||||
return COLUMN_RGB;
|
||||
}
|
||||
}
|
||||
return COLUMN_RGB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extrudiert `project.columns` (Tragwerk) zu parametrischen Prisma-Meshes —
|
||||
* Rechteck-Box bzw. tesselliertes Kreis-Prisma, je Profil. SYNCHRON (anders als
|
||||
* die truck-Extrusion der `ExtrudedSolid`s, s. `../extrusions.ts`): die
|
||||
* Kontur kommt aus `columnFootprint`, die vertikale Lage aus
|
||||
* `columnVerticalExtent` (UK/OK-Anker bzw. Geschoss-UK + Höhe). `positions` in MODELL-Metern
|
||||
* (x, y, z=Höhe); render3d rendert Kontext-Meshes doppelseitig, die Winding-Reihenfolge ist
|
||||
* unerheblich. Rust/render3d bleibt unverändert (Kontext-Mesh-Pfad).
|
||||
*/
|
||||
export function emitColumns(project: Project): RMesh[] {
|
||||
const cols: Column[] = [];
|
||||
const feet: Vec2[][] = [];
|
||||
const zs: number[] = [];
|
||||
let doubles = 1;
|
||||
for (const col of project.columns ?? []) {
|
||||
if (col.height <= 0) continue;
|
||||
const { zBottom, zTop } = columnVerticalExtent(project, col);
|
||||
const foot = columnFootprint(col);
|
||||
cols.push(col);
|
||||
feet.push(foot);
|
||||
zs.push(zBottom, zTop);
|
||||
doubles += 3 + 2 * foot.length;
|
||||
}
|
||||
if (cols.length === 0) return [];
|
||||
const buf = new Float64Array(doubles);
|
||||
buf[0] = cols.length;
|
||||
let w = 1;
|
||||
for (let k = 0; k < cols.length; k++) {
|
||||
const foot = feet[k];
|
||||
buf[w++] = zs[2 * k];
|
||||
buf[w++] = zs[2 * k + 1];
|
||||
buf[w++] = foot.length;
|
||||
for (const p of foot) {
|
||||
buf[w++] = p.x;
|
||||
buf[w++] = p.y;
|
||||
}
|
||||
}
|
||||
const f = core().columns3d_flat(buf);
|
||||
|
||||
const out: RMesh[] = [];
|
||||
let i = 1;
|
||||
for (let n = f.length ? f[0] : 0; n > 0; n--) {
|
||||
const col = cols[f[i]];
|
||||
const nPos = f[i + 1];
|
||||
const nIdx = f[i + 2];
|
||||
i += 3;
|
||||
const positions: number[] = [];
|
||||
for (let k = 0; k < nPos; k++) positions.push(f[i + k]);
|
||||
i += nPos;
|
||||
const indices: number[] = [];
|
||||
for (let k = 0; k < nIdx; k++) indices.push(f[i + k]);
|
||||
i += nIdx;
|
||||
out.push({ positions, indices, kind: "extrusion", color: columnColor3d(project, col) });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Project } from "../../model/types";
|
||||
import { sampleProject } from "../../model/sampleProject";
|
||||
import { emitDrawingLineVerts, pickDrawingSegs } from "./drawing2d";
|
||||
import { emitDrawingLineVerts, pickGeometry } from "../toWalls3d";
|
||||
|
||||
const pickDrawingSegs = (p: Project) => pickGeometry(p).drawings;
|
||||
|
||||
// `emitDrawingLineVerts` liefert die 2D-Boden-Spuren als LineList-Vertices für
|
||||
// render3ds `set_drawing_lines` (binärer Float32Array-Kanal) — interleaved
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
// Freie-2D-Geometrie-Domäne der 3D-Ableitung: zeigt jede 2D-Zeichnung
|
||||
// (line/polyline/rect) als Boden-Spur knapp über ihrer Geschossebene — die
|
||||
// "2D-Referenz im 3D", die der drei.js-Fallback (`addDrawing2DLines` in
|
||||
// Viewport3D.tsx) zeigt.
|
||||
//
|
||||
// Die Spuren gehen als LineList-Vertices (`emitDrawingLineVerts`) über einen
|
||||
// eigenen BINÄREN Kanal an render3d (`set_drawing_lines`), NICHT als Meshes
|
||||
// über `RModel3d.meshes`/`set_model`. Grund: ein Kataster-DXF kann Millionen
|
||||
// Segmente liefern — als Ribbon-Meshes im JSON-Modell sprengt das sowohl die
|
||||
// JS-String-Längengrenze als auch den Vertexspeicher (s. Funktionsdoc unten).
|
||||
|
||||
import type { Drawing2D, Project } from "../../model/types";
|
||||
import { flattenCategories, getFloor } from "../../model/types";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import { DRAWING_LINE_FALLBACK_RGB, hexToRgb, type RRgb } from "./shared";
|
||||
import { DRAWING_PICK_TOLERANCE, type PickDrawingSeg } from "../pickTypes";
|
||||
|
||||
/** Höhen-Offset über der Geschossebene gegen Z-Fighting (wie addDrawing2DLines in Viewport3D.tsx). */
|
||||
const DRAWING_LINE_ELEVATION_EPS = 0.01;
|
||||
|
||||
/**
|
||||
* Farb-Nachschlagetabellen für {@link drawingColor3d} — EINMAL je Emitter-Lauf
|
||||
* gebaut statt je Element. Vorher rief `drawingColor3d` pro Zeichnung
|
||||
* `flattenCategories(project.layers).find(...)` auf und baute damit den
|
||||
* GESAMTEN Kategorie-Baum je Element neu als Array auf (O(n·L) plus
|
||||
* entsprechender GC-Druck). Bei einem Kataster-Import mit >100'000 Elementen
|
||||
* war das zweistellige Millionen Allokationen pro Renderdurchlauf. Muster wie
|
||||
* `generatePlan.ts::categoryColorMap`.
|
||||
*/
|
||||
interface DrawingColorMaps {
|
||||
byCategory: Map<string, string>;
|
||||
byLineStyle: Map<string, string>;
|
||||
}
|
||||
|
||||
function buildDrawingColorMaps(project: Project): DrawingColorMaps {
|
||||
const byCategory = new Map<string, string>();
|
||||
for (const c of flattenCategories(project.layers)) {
|
||||
if (c.color) byCategory.set(c.code, c.color);
|
||||
}
|
||||
const byLineStyle = new Map<string, string>();
|
||||
for (const l of project.lineStyles) {
|
||||
if (l.color) byLineStyle.set(l.id, l.color);
|
||||
}
|
||||
return { byCategory, byLineStyle };
|
||||
}
|
||||
|
||||
/** Modellfarbe einer 2D-Zeichnung (color → LineStyle → Kategorie), analog `drawing2DColor`. */
|
||||
function drawingColor3d(maps: DrawingColorMaps, d: Drawing2D): RRgb {
|
||||
if (d.color) return hexToRgb(d.color, DRAWING_LINE_FALLBACK_RGB);
|
||||
const ls = d.lineStyleId ? maps.byLineStyle.get(d.lineStyleId) : undefined;
|
||||
if (ls) return hexToRgb(ls, DRAWING_LINE_FALLBACK_RGB);
|
||||
const cat = maps.byCategory.get(d.categoryCode);
|
||||
return cat ? hexToRgb(cat, DRAWING_LINE_FALLBACK_RGB) : DRAWING_LINE_FALLBACK_RGB;
|
||||
}
|
||||
|
||||
/** Boden-Spur-Höhe (world-Y) einer 2D-Zeichnung: Geschoss-UK + Epsilon gegen
|
||||
* Z-Fighting, oder 0 als Fallback (Geschoss nicht mehr auflösbar). Gemeinsam
|
||||
* für `emitDrawingLineVerts` (Sichtbarkeit) UND `pickDrawingSegs` (Klickbarkeit) —
|
||||
* beide MÜSSEN dieselbe Höhe verwenden, sonst klickt man daneben. */
|
||||
function drawingElevation(project: Project, d: Drawing2D): number {
|
||||
let baseZ = 0;
|
||||
try {
|
||||
baseZ = getFloor(project, d.levelId).baseElevation ?? 0;
|
||||
} catch {
|
||||
// Geschoss nicht (mehr) auflösbar: bei UK 0 zeichnen (Fallback).
|
||||
}
|
||||
return baseZ + DRAWING_LINE_ELEVATION_EPS;
|
||||
}
|
||||
|
||||
/** Doppelte je Charge an den Rust-Kern (Eingabe: `drawing2d_3d.rs`) — begrenzt den Speicher. */
|
||||
const CHUNK_DOUBLES = 1 << 18;
|
||||
let scratch: Float64Array | null = null;
|
||||
/** Art-Kennzahl der Zeichnung im Rust-Puffer; Kreis/Bogen/Text zeigt das 3D nicht. */
|
||||
const SHAPE_KIND = { line: 1, polyline: 2, rect: 3 } as const;
|
||||
|
||||
/**
|
||||
* Packt die darstellbaren Zeichnungen (line/polyline/rect — Parität mit `drawing2DSegments`
|
||||
* im drei.js-Fallback `Viewport3D.tsx`) in Chargen und ruft `fn(puffer, zeichnungen)` je Charge
|
||||
* auf. `color` liefert die Linienfarbe (`null`: ohne, für den Pick).
|
||||
*/
|
||||
function forEachChunk(
|
||||
project: Project,
|
||||
color: ((d: Drawing2D) => RRgb) | null,
|
||||
fn: (buf: Float64Array, drawings: Drawing2D[]) => void,
|
||||
): void {
|
||||
if (project.drawings2d.length === 0) return;
|
||||
// Der Zwischenpuffer lebt zwischen den Aufrufen weiter (Neuanlage von 2 MB kostet mehr als die
|
||||
// Rechnung bei kleinen Projekten); der Kern kopiert den Inhalt je Aufruf.
|
||||
scratch ??= new Float64Array(CHUNK_DOUBLES);
|
||||
let buf = scratch;
|
||||
let ids: Drawing2D[] = [];
|
||||
let w = 1; // [0] = Anzahl
|
||||
const flush = () => {
|
||||
if (ids.length === 0) return;
|
||||
buf[0] = ids.length;
|
||||
fn(buf.subarray(0, w), ids);
|
||||
ids = [];
|
||||
w = 1;
|
||||
};
|
||||
// Geschoss-UK je Ebene nur einmal auflösen (bei Kataster-Importen hängen Tausende Zeichnungen an einer).
|
||||
const elevations = new Map<string, number>();
|
||||
for (const d of project.drawings2d) {
|
||||
const g = d.geom;
|
||||
if (g.shape !== "line" && g.shape !== "rect" && g.shape !== "polyline") continue;
|
||||
const kind = SHAPE_KIND[g.shape];
|
||||
const nPts = g.shape === "polyline" ? g.pts.length : 2;
|
||||
const need = 7 + 2 * nPts;
|
||||
if (w + need > buf.length) {
|
||||
flush();
|
||||
if (1 + need > buf.length) buf = new Float64Array(1 + need);
|
||||
}
|
||||
let elev = elevations.get(d.levelId);
|
||||
if (elev === undefined) {
|
||||
elev = drawingElevation(project, d);
|
||||
elevations.set(d.levelId, elev);
|
||||
}
|
||||
const [r, gr, b] = color ? color(d) : [0, 0, 0];
|
||||
buf[w++] = kind;
|
||||
buf[w++] = elev;
|
||||
buf[w++] = r;
|
||||
buf[w++] = gr;
|
||||
buf[w++] = b;
|
||||
buf[w++] = g.shape === "polyline" && g.closed ? 1 : 0;
|
||||
buf[w++] = nPts;
|
||||
if (g.shape === "line") {
|
||||
buf[w++] = g.a.x; buf[w++] = g.a.y; buf[w++] = g.b.x; buf[w++] = g.b.y;
|
||||
} else if (g.shape === "rect") {
|
||||
buf[w++] = g.min.x; buf[w++] = g.min.y; buf[w++] = g.max.x; buf[w++] = g.max.y;
|
||||
} else {
|
||||
for (const p of g.pts) {
|
||||
buf[w++] = p.x;
|
||||
buf[w++] = p.y;
|
||||
}
|
||||
}
|
||||
ids.push(d);
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Boden-Spuren aller 2D-Zeichnungen als LineList-Vertices für render3d —
|
||||
* die "2D-Referenz im 3D" (z. B. ein Kataster-Plan oder Boden-Raster), die
|
||||
* auch der drei.js-Fallback (`addDrawing2DLines`) zeigt.
|
||||
*
|
||||
* Liefert interleaved `[px, py, pz, r, g, b, ...]` in WORLD-Metern, je zwei
|
||||
* Vertices ein Segment — direkt für `WebModelRenderer::set_drawing_lines`
|
||||
* (Binärtransfer als `Float32Array`, kein JSON). Entartete Segmente entfallen.
|
||||
*
|
||||
* WARUM LINIEN STATT MESHES (Nutzer-Report 2026-10-08, Kataster-DXF „Amtliche
|
||||
* Vermessung Luzern", 439 MB → 3,6 Mio. Segmente): als Ribbon-MESH im JSON-Modell sprengte das
|
||||
* die JS-String-Längengrenze, und `append_context_mesh` hätte ~1,55 GB Vertexdaten erzeugt.
|
||||
* Als LineList sind es 2 Vertices je Segment (~173 MB) ohne jede Textkodierung.
|
||||
*
|
||||
* WORLD-TRANSFORM: Modell `(x, y, z=Höhe)` → world `(x, Höhe, y)` — exakt die
|
||||
* `MeshKind::Extrusion`-Konvention (KEINE Nord-Negation; die gilt nur für `Terrain`/`Imported`,
|
||||
* s. `mesh.rs`). Die Segmente erzeugt der Rust-Kern (`drawing2d_3d.rs`) in Chargen; die
|
||||
* Teilergebnisse werden am Ende in EINEN Puffer kopiert.
|
||||
*/
|
||||
export function emitDrawingLineVerts(project: Project): Float32Array {
|
||||
if (project.drawings2d.length === 0) return new Float32Array(0);
|
||||
const maps = buildDrawingColorMaps(project);
|
||||
const parts: Float32Array[] = [];
|
||||
let total = 0;
|
||||
forEachChunk(project, (d) => drawingColor3d(maps, d), (buf) => {
|
||||
const v = core().drawing3d_line_verts(buf);
|
||||
if (v.length) {
|
||||
parts.push(v);
|
||||
total += v.length;
|
||||
}
|
||||
});
|
||||
if (parts.length === 0) return new Float32Array(0);
|
||||
if (parts.length === 1) return parts[0];
|
||||
const out = new Float32Array(total);
|
||||
let w = 0;
|
||||
for (const p of parts) {
|
||||
out.set(p, w);
|
||||
w += p.length;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick-Kandidaten (Raycast-Boxen, s. `viewport/raycast3d.ts::PickDrawingSeg`)
|
||||
* für alle 2D-Zeichnungen — dieselben Segmente/Höhen wie `emitDrawingLineVerts`
|
||||
* (Klick trifft, was sichtbar ist), nur mit grosszügiger Toleranz statt der
|
||||
* sichtbaren 0.008m Linienbreite.
|
||||
*/
|
||||
export function pickDrawingSegs(project: Project): PickDrawingSeg[] {
|
||||
const out: PickDrawingSeg[] = [];
|
||||
forEachChunk(project, null, (buf, drawings) => {
|
||||
const f = core().drawing3d_pick_segs(buf, DRAWING_PICK_TOLERANCE);
|
||||
for (let i = 0; i + 5 < f.length; i += 6) {
|
||||
out.push({
|
||||
start: [f[i], f[i + 1]],
|
||||
end: [f[i + 2], f[i + 3]],
|
||||
baseElevation: f[i + 4],
|
||||
drawingId: drawings[f[i + 5]].id,
|
||||
});
|
||||
}
|
||||
});
|
||||
return out;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { FrameCornerJoin } from "../../model/types";
|
||||
import { frameRingQuads } from "./openings";
|
||||
|
||||
type Q = ReturnType<typeof frameRingQuads>[number];
|
||||
// Eckenfolge (from,UK),(to,UK),(from,OK),(to,OK) → als Ring 0,1,3,2.
|
||||
const ring = (q: Q) => [q[0], q[1], q[3], q[2]];
|
||||
const area = (q: Q) => {
|
||||
const r = ring(q);
|
||||
let a = 0;
|
||||
for (let i = 0; i < 4; i++) a += r[i][0] * r[(i + 1) % 4][1] - r[(i + 1) % 4][0] * r[i][1];
|
||||
return Math.abs(a) / 2;
|
||||
};
|
||||
|
||||
describe("frameRingQuads", () => {
|
||||
const modes: FrameCornerJoin[] = ["vertikal", "horizontal", "gehrung"];
|
||||
for (const mode of modes) {
|
||||
it(`${mode}: Profile decken genau den Ring ab (keine Überlappung)`, () => {
|
||||
const qs = frameRingQuads(0, 1.2, 0.9, 2.1, 0.06, mode, true);
|
||||
expect(qs.length).toBe(4);
|
||||
const total = qs.reduce((a, q) => a + area(q), 0);
|
||||
const ringArea = 1.2 * 1.2 - (1.2 - 0.12) * (1.2 - 0.12);
|
||||
expect(total).toBeCloseTo(ringArea, 9);
|
||||
});
|
||||
it(`${mode}: ohne Schwelle (Tür) drei Profile`, () => {
|
||||
const qs = frameRingQuads(0, 1.0, 0, 2.1, 0.06, mode, false);
|
||||
expect(qs.length).toBe(3);
|
||||
const total = qs.reduce((a, q) => a + area(q), 0);
|
||||
expect(total).toBeCloseTo(1.0 * 2.1 - (1.0 - 0.12) * (2.1 - 0.06), 9);
|
||||
});
|
||||
}
|
||||
it("vertikal: Pfosten laufen durch, Riegel dazwischen", () => {
|
||||
const [left] = frameRingQuads(0, 1, 0, 1, 0.1, "vertikal", true);
|
||||
expect(left[0]).toEqual([0, 0]);
|
||||
expect(left[3]).toEqual([0.1, 1]);
|
||||
});
|
||||
});
|
||||
@@ -1,201 +0,0 @@
|
||||
// Öffnungs-Domäne der 3D-Ableitung: Glasscheibe(n)/Türblatt, Rahmen-/Sprossen-
|
||||
// Riegel (Zarge/Blendrahmen/Kämpfer/Mittelpfosten/Flügelrahmen + SIA-Symbole),
|
||||
// Fensterbänke, Zargen-Umgriff, Schwellenprofil und der Rollladen-/Sonnenschutz-
|
||||
// kasten typisierter Tür-/Fensteröffnungen — das 3D-Pendant zu
|
||||
// `generatePlan/openings.ts`.
|
||||
//
|
||||
// Gerechnet wird im Rust-Kern (`src-tauri/core/src/openings3d.rs`, Kodierung
|
||||
// dort); hier bleiben das Sammeln aus dem `Project` (Tür-/Fenstertyp, Flügel-
|
||||
// tabelle, Öffnungs-Intervall und -Höhe, Wanddicke), die flache Übergabe aller
|
||||
// Wände in EINEM Kern-Aufruf und die Farbe je Bauteil-Klasse.
|
||||
//
|
||||
// Die Quader liegen in MODELL-Metern (x, y, z = Höhe); render3d bildet sie nach
|
||||
// world ab und rendert sie doppelseitig (Winding egal). `kind: "extrusion"`
|
||||
// (NICHT "imported"): die Nord-Achsen-Negation in `append_context_mesh` gilt nur
|
||||
// für echte Import-Rohdaten, Öffnungs-Quader entstehen orientierungserhaltend aus
|
||||
// der Wandachse (Fund 2026-09-27).
|
||||
|
||||
import type { DoorType, FrameCornerJoin, Opening, Project, WindowType } from "../../model/types";
|
||||
import { getDoorType, getWindowType, glazingPanesOf } from "../../model/types";
|
||||
import { openingInterval, openingVerticalExtent } from "../../geometry/opening";
|
||||
import type { DetailLevel } from "../../model/viewTypes";
|
||||
import { FlatReader, FlatWriter } from "../../geometry/coreFlat";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import type { RMesh, RRgb } from "./shared";
|
||||
import { wallThicknessSafe } from "./bands";
|
||||
|
||||
/**
|
||||
* Farbe je Bauteil-Klasse (Index = `Part` in `openings3d.rs`): Glas (hell,
|
||||
* bläulich), Rahmen (helles, warmes Grau), Rollladenkasten, Fensterbank/
|
||||
* Schwelle (Stein-Grau), SIA-Symbole (dunkle Linien auf dem Glas), Türblatt
|
||||
* (warm, hell).
|
||||
*/
|
||||
const PART_RGB: readonly RRgb[] = [
|
||||
[0.62, 0.76, 0.85],
|
||||
[0.85, 0.85, 0.83],
|
||||
[0.88, 0.88, 0.9],
|
||||
[0.8, 0.8, 0.78],
|
||||
[0.25, 0.27, 0.3],
|
||||
[0.93, 0.9, 0.85],
|
||||
];
|
||||
|
||||
/** Dreiecke eines Öffnungs-Quaders (Ecken-Bits: bit0 = Achse, bit1 = Höhe, bit2 = quer). */
|
||||
const OPENING_BOX_TRIS: readonly number[] = [
|
||||
0, 1, 3, 0, 3, 2, // quer nMin
|
||||
4, 5, 7, 4, 7, 6, // quer nMax
|
||||
0, 1, 5, 0, 5, 4, // UK
|
||||
2, 3, 7, 2, 7, 6, // OK
|
||||
0, 2, 6, 0, 6, 4, // from
|
||||
1, 3, 7, 1, 7, 5, // to
|
||||
];
|
||||
|
||||
const DETAIL_CODE: Record<string, number> = { grob: 0, mittel: 1, fein: 2 };
|
||||
const JOIN_CODE: Record<string, number> = { horizontal: 1, gehrung: 2 };
|
||||
const OPENING_KIND_CODE: Record<string, number> = { dreh: 1, kipp: 2, drehkipp: 3, fest: 4, schiebe: 5 };
|
||||
const SILL_BOARD_CODE: Record<string, number> = { keine: 1, innen: 2, beide: 3 };
|
||||
|
||||
/** Fehlender Wert → NaN (der Kern setzt dort den Default). */
|
||||
const opt = (v: number | null | undefined): number => v ?? Number.NaN;
|
||||
const flag = (b: boolean): number => (b ? 1 : 0);
|
||||
const openingKindCode = (k: string | undefined): number => (k ? OPENING_KIND_CODE[k] ?? 6 : 0);
|
||||
|
||||
/** Gemeinsame Typwerte (Kodierung `openings3d.rs`). */
|
||||
function writeCommon(w: FlatWriter, t: DoorType | WindowType): void {
|
||||
w.num(
|
||||
opt(t.frameDepth),
|
||||
opt(t.insetFromFace),
|
||||
flag((t.insetFace ?? "aussen") === "innen"),
|
||||
JOIN_CODE[t.frameCornerJoin ?? ""] ?? 0,
|
||||
opt(t.frameWidth),
|
||||
opt(t.transomHeight),
|
||||
);
|
||||
}
|
||||
|
||||
function writeOpening(w: FlatWriter, project: Project, op: Opening): void {
|
||||
if (op.kind === "window") {
|
||||
const wt = getWindowType(project, op);
|
||||
if (!wt) {
|
||||
w.num(0);
|
||||
return;
|
||||
}
|
||||
w.num(1);
|
||||
writeCommon(w, wt);
|
||||
const shading = wt.shading?.create ? wt.shading.box : undefined;
|
||||
w.num(
|
||||
glazingPanesOf(wt),
|
||||
opt(wt.mullionRows),
|
||||
opt(wt.mullionCols),
|
||||
SILL_BOARD_CODE[wt.sillBoard ?? ""] ?? 0,
|
||||
flag(!!shading),
|
||||
shading?.width ?? 0,
|
||||
shading?.height ?? 0,
|
||||
shading?.depth ?? 0,
|
||||
op.wingCount ?? wt.wingCount ?? 1,
|
||||
openingKindCode(wt.kind),
|
||||
);
|
||||
const sashes = wt.sashes ?? [];
|
||||
w.num(sashes.length);
|
||||
for (const s of sashes) {
|
||||
w.num(
|
||||
s.kind === "fluegel" ? 0 : s.kind === "pfosten" ? 1 : 2,
|
||||
flag(s.autoWidth === false),
|
||||
opt(s.width),
|
||||
opt(s.postWidth),
|
||||
openingKindCode(s.opening),
|
||||
flag((s.hingeSide ?? "left") === "left"),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const dt = getDoorType(project, op);
|
||||
if (!dt) {
|
||||
w.num(0);
|
||||
return;
|
||||
}
|
||||
w.num(1);
|
||||
writeCommon(w, dt);
|
||||
w.num(
|
||||
flag(dt.threshold === true),
|
||||
opt(dt.leafCount),
|
||||
dt.leafStyle === "glas" ? 1 : dt.leafStyle === "kassette" ? 2 : 0,
|
||||
opt(dt.glazingRatio),
|
||||
flag((dt.frameKind ?? "zarge") === "zarge"),
|
||||
opt(dt.panelCols),
|
||||
opt(dt.panelRows),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle Öffnungs-Einbauteile eines Projekts als rohe Quader-Meshes, in EINEM
|
||||
* Kern-Aufruf. Reihenfolge wie früher: erst Glas/Türblätter aller Wände, dann
|
||||
* Rahmen/Sprossen/Bänke/Zargen (nicht bei „grob"), dann Rollladenkästen (nicht
|
||||
* bei „grob").
|
||||
*
|
||||
* • Ohne auflösbaren Typ: Fenster = EINE Vollscheibe mittig in der Wand, Tür =
|
||||
* offenes Loch, kein Rahmen (Rückwärtskompatibilität).
|
||||
* • „mittel": Blendrahmen + Oberlicht-Kämpfer + Flügelrahmen + Fensterbank/
|
||||
* Zargen-Umgriff/Schwellenprofil, keine Sprossen, keine SIA-Symbole.
|
||||
* • „fein": zusätzlich Flügel-Mittelpfosten, Kämpfer-Zeilen und SIA-Symbole.
|
||||
*/
|
||||
export function emitOpeningMeshes(project: Project, detail: DetailLevel = "fein"): RMesh[] {
|
||||
const byWall = new Map<string, Opening[]>();
|
||||
for (const op of project.openings ?? []) {
|
||||
const list = byWall.get(op.hostWallId);
|
||||
if (list) list.push(op);
|
||||
else byWall.set(op.hostWallId, [op]);
|
||||
}
|
||||
const w = new FlatWriter().num(DETAIL_CODE[detail] ?? 3, project.walls.length);
|
||||
for (const wall of project.walls) {
|
||||
w.num(wall.start.x, wall.start.y, wall.end.x, wall.end.y);
|
||||
const slot = w.slot();
|
||||
let count = 0;
|
||||
let thickness: number | undefined;
|
||||
for (const op of byWall.get(wall.id) ?? []) {
|
||||
const iv = openingInterval(wall, op);
|
||||
if (!iv) continue;
|
||||
const vert = openingVerticalExtent(project, wall, op);
|
||||
thickness ??= wallThicknessSafe(project, wall);
|
||||
w.num(iv.from, iv.to, vert.zBottom, vert.zTop, flag(op.kind !== "window"), thickness);
|
||||
writeOpening(w, project, op);
|
||||
count++;
|
||||
}
|
||||
w.set(slot, count);
|
||||
}
|
||||
const buf = core().opening_meshes_flat(w.done());
|
||||
const out: RMesh[] = [];
|
||||
const n = new FlatReader(buf).count();
|
||||
for (let k = 0, i = 1; k < n && i + 25 <= buf.length; k++, i += 25) {
|
||||
const positions = new Array<number>(24);
|
||||
for (let j = 0; j < 24; j++) positions[j] = buf[i + 1 + j];
|
||||
out.push({ positions, indices: [...OPENING_BOX_TRIS], kind: "extrusion", color: PART_RGB[buf[i]] ?? PART_RGB[1] });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rahmen-Ring (Pfosten links/rechts, Riegel oben, Riegel unten nur bei
|
||||
* `bottom`) über das Feld `[from,to]×[zB,zT]` mit Profilbreite `w`, ohne
|
||||
* überlappende Profile; `join` bestimmt die durchlaufenden Glieder. Glieder als
|
||||
* (u,h)-Vierecke: (from,UK), (to,UK), (from,OK), (to,OK). Rechnet im Kern.
|
||||
*/
|
||||
export function frameRingQuads(
|
||||
from: number,
|
||||
to: number,
|
||||
zB: number,
|
||||
zT: number,
|
||||
w: number,
|
||||
join: FrameCornerJoin,
|
||||
bottom: boolean,
|
||||
): Array<[[number, number], [number, number], [number, number], [number, number]]> {
|
||||
const r = new FlatReader(core().frame_ring_quads_flat(from, to, zB, zT, w, JOIN_CODE[join] ?? 0, bottom));
|
||||
const out: Array<[[number, number], [number, number], [number, number], [number, number]]> = [];
|
||||
for (let n = r.count(); n > 0; n--) {
|
||||
out.push([
|
||||
[r.num(), r.num()],
|
||||
[r.num(), r.num()],
|
||||
[r.num(), r.num()],
|
||||
[r.num(), r.num()],
|
||||
]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Vec3 } from "../../geometry/roof";
|
||||
import { mitredRoofOffsets } from "./roofs";
|
||||
|
||||
// Walmdach 12×7 m: zwei Trapeze + zwei Walm-Dreiecke, First (3,3)-(8,3).
|
||||
const planes: Vec3[][] = [
|
||||
[[-0.5, -0.5, 5.2], [11.5, -0.5, 5.2], [8, 3, 7.061], [3, 3, 7.061]],
|
||||
[[-0.5, 6.5, 5.2], [11.5, 6.5, 5.2], [8, 3, 7.061], [3, 3, 7.061]],
|
||||
[[-0.5, -0.5, 5.2], [-0.5, 6.5, 5.2], [3, 3, 7.061]],
|
||||
[[11.5, -0.5, 5.2], [11.5, 6.5, 5.2], [8, 3, 7.061]],
|
||||
];
|
||||
|
||||
const near = (a: Vec3, b: Vec3) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) < 1e-6;
|
||||
|
||||
describe("mitredRoofOffsets", () => {
|
||||
const m = mitredRoofOffsets(planes);
|
||||
it("erkennt First und Grate als geteilte Kanten, Traufen als frei", () => {
|
||||
expect(m.shared[0]).toEqual([false, true, true, true]); // Traufe, Grat, First, Grat
|
||||
expect(m.shared[2]).toEqual([false, true, true]);
|
||||
});
|
||||
it("Unterseiten treffen sich am First-Apex in EINEM Punkt (Gehrung statt Durchdringung)", () => {
|
||||
const d = 0.27;
|
||||
const apexA = m.at(0, d)[3]; // (3,3) der Trapezfläche
|
||||
const apexB = m.at(1, d)[3];
|
||||
const apexC = m.at(2, d)[2]; // Walm-Spitze
|
||||
expect(near(apexA, apexB)).toBe(true);
|
||||
expect(near(apexA, apexC)).toBe(true);
|
||||
expect(apexA[2]).toBeLessThan(7.061);
|
||||
});
|
||||
it("Versatz 0 = Originalfläche, freie Traufecke bleibt senkrecht versetzt", () => {
|
||||
expect(m.at(0, 0)).toEqual(planes[0]);
|
||||
const eaves = m.at(0, 0.2)[0];
|
||||
// Traufecke (−0.5,−0.5) teilt den Grat mit dem Walm → gehrt, aber Höhe unter der Traufe.
|
||||
expect(eaves[2]).toBeLessThan(5.2);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
// Dach-Meshes (`emitRoofs`) sind je Schicht geschlossene, nach aussen gewundene Körper — Voraussetzung
|
||||
// Dach-Meshes (`roofMeshes`) 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 { roofMeshes } from "../toWalls3d";
|
||||
import { isWatertight } from "../wallMeshCut";
|
||||
import { sampleProject } from "../../model/sampleProject";
|
||||
import type { Project, Roof, RoofShape } from "../../model/types";
|
||||
@@ -37,7 +37,7 @@ describe("Dach-Meshes geschlossen und nach aussen gewunden", () => {
|
||||
for (const axis of ["x", "y"] as const) {
|
||||
it(`${shape} (First ${axis})`, () => {
|
||||
const p: Project = { ...sampleProject, roofs: [roof(shape, axis)] };
|
||||
const meshes = emitRoofs(p);
|
||||
const meshes = roofMeshes(p);
|
||||
expect(meshes.length).toBeGreaterThan(0);
|
||||
for (const m of meshes) {
|
||||
const c = closure(m);
|
||||
|
||||
@@ -1,298 +0,0 @@
|
||||
// Dach-Domäne der 3D-Ableitung: emittiert Dächer (`project.roofs`) als
|
||||
// geschlossene, geschichtete Dreiecks-Meshes (Eindeckung → innen) aus den
|
||||
// geneigten Dachflächen (`RoofGeometry.planes`) — jede Schicht ein eigener
|
||||
// solider Slab mit ihrer Bauteilfarbe/-textur.
|
||||
|
||||
import type { Project } from "../../model/types";
|
||||
import { getComponent, roofLayers } from "../../model/types";
|
||||
import { roofBaseElevation, roofGeometry } from "../../geometry/roof";
|
||||
import type { Vec3 as RoofVec3 } from "../../geometry/roof";
|
||||
import {
|
||||
EPS,
|
||||
hexToRgb,
|
||||
resolveComponentMaterialLayer,
|
||||
resolveCutLineStyle,
|
||||
type RCutMeta,
|
||||
type RMesh,
|
||||
type RRgb,
|
||||
type RRoofLayer,
|
||||
} from "./shared";
|
||||
|
||||
/** Warmer Terrakotta-Grauton für Dachflächen/-giebel — hebt das Dach klar von Wand/Decke/Kontext ab. */
|
||||
const ROOF_RGB: RRgb = [0.72, 0.45, 0.36];
|
||||
|
||||
/**
|
||||
* Trianguliert ein KONVEXES 3D-Polygon per Dreiecks-Fächer ab Vertex 0 und hängt
|
||||
* die Dreiecke an `positions`/`indices` an. `roofGeometry` (Vertrag in
|
||||
* `geometry/roof.ts`) liefert für `planes`/`gables` ausschliesslich konvexe
|
||||
* 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[], 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++) {
|
||||
if (flip) indices.push(base, base + i + 1, base + i);
|
||||
else indices.push(base, base + i, base + i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Robuste Flächennormale (Newell) einer Polygon-Ebene in MODELL-Koordinaten
|
||||
* ([x, y, z=Höhe]), nach OBEN orientiert (positive Höhen-Komponente) — für die
|
||||
* Dach-Dickenversetzung (Unterseite = Oberseite − Normale·Dicke).
|
||||
*/
|
||||
function planeNormalUp(pts: RoofVec3[]): [number, number, number] {
|
||||
let nx = 0;
|
||||
let ny = 0;
|
||||
let nz = 0;
|
||||
for (let i = 0; i < pts.length; i++) {
|
||||
const c = pts[i];
|
||||
const d = pts[(i + 1) % pts.length];
|
||||
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]);
|
||||
}
|
||||
const len = Math.hypot(nx, ny, nz) || 1;
|
||||
const u: [number, number, number] = [nx / len, ny / len, nz / len];
|
||||
return u[2] < 0 ? [-u[0], -u[1], -u[2]] : u;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gehrte Versatz-Ecken für ALLE Dachflächen eines Daches: liefert je Fläche die
|
||||
* um `d` (Meter, entlang der Flächennormalen nach innen) versetzten Ecken —
|
||||
* aber an Kanten, die sich zwei Flächen teilen (First/Grat/Knick), NICHT
|
||||
* stur entlang der EIGENEN Normalen, sondern auf der Gehrung: die Ecke liegt im
|
||||
* Schnitt der versetzten Ebenen beider Flächen. Vorher durchdrangen sich die
|
||||
* Slabs benachbarter Flächen am First, ihre Stirnflächen lagen deckungsgleich
|
||||
* auf der Nachbar-Oberseite (Störtriangle am First-Apex im „Schattiert mit
|
||||
* Kanten"-Modus). Freie Kanten (Traufe/Ortgang) behalten die senkrechte
|
||||
* Stirnfläche. `shared[i][k]` = Kante k→k+1 von Fläche i ist geteilt.
|
||||
*/
|
||||
export function mitredRoofOffsets(planes: RoofVec3[][]): {
|
||||
at: (i: number, d: number) => RoofVec3[];
|
||||
shared: boolean[][];
|
||||
} {
|
||||
const r = (v: number) => Math.round(v * 1e5);
|
||||
const pk = (p: RoofVec3) => `${r(p[0])},${r(p[1])},${r(p[2])}`;
|
||||
const ek = (a: RoofVec3, b: RoofVec3) => {
|
||||
const ka = pk(a);
|
||||
const kb = pk(b);
|
||||
return ka < kb ? `${ka}|${kb}` : `${kb}|${ka}`;
|
||||
};
|
||||
const edgeOwners = new Map<string, number[]>();
|
||||
planes.forEach((pts, i) => {
|
||||
for (let k = 0; k < pts.length; k++) {
|
||||
const key = ek(pts[k], pts[(k + 1) % pts.length]);
|
||||
const list = edgeOwners.get(key);
|
||||
if (list) list.push(i);
|
||||
else edgeOwners.set(key, [i]);
|
||||
}
|
||||
});
|
||||
const normals = planes.map((pts) => planeNormalUp(pts));
|
||||
const neighbor = planes.map((pts, i) =>
|
||||
pts.map((p, k) => {
|
||||
const owners = edgeOwners.get(ek(p, pts[(k + 1) % pts.length])) ?? [];
|
||||
const j = owners.find((o) => o !== i);
|
||||
return j === undefined ? -1 : j;
|
||||
}),
|
||||
);
|
||||
const shared = neighbor.map((row) => row.map((j) => j >= 0));
|
||||
const dot = (a: RoofVec3, b: RoofVec3) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
||||
const cross = (a: RoofVec3, b: RoofVec3): RoofVec3 => [
|
||||
a[1] * b[2] - a[2] * b[1],
|
||||
a[2] * b[0] - a[0] * b[2],
|
||||
a[0] * b[1] - a[1] * b[0],
|
||||
];
|
||||
// Ebene (Normale m, Abstand c: m·x = c) der Kante k→k+1 von Fläche i beim Versatz d:
|
||||
// geteilt → versetzte Nachbarebene (Gehrung), frei → senkrechte Stirnebene.
|
||||
const edgePlane = (i: number, k: number, d: number): [RoofVec3, number] => {
|
||||
const pts = planes[i];
|
||||
const a = pts[k];
|
||||
const b = pts[(k + 1) % pts.length];
|
||||
const j = neighbor[i][k];
|
||||
if (j >= 0) return [normals[j], dot(normals[j], planes[j][0]) - d];
|
||||
const dir: RoofVec3 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
||||
const m = cross(dir, normals[i]);
|
||||
return [m, dot(m, a)];
|
||||
};
|
||||
// Schnittpunkt dreier Ebenen (Cramer über Kreuzprodukte), null wenn entartet.
|
||||
const solve = (rows: Array<[RoofVec3, number]>): RoofVec3 | null => {
|
||||
const [[a, ca], [b, cb], [c, cc]] = rows;
|
||||
const bc = cross(b, c);
|
||||
const det = dot(a, bc);
|
||||
if (Math.abs(det) < 1e-9) return null;
|
||||
const cxa = cross(c, a);
|
||||
const axb = cross(a, b);
|
||||
return [
|
||||
(ca * bc[0] + cb * cxa[0] + cc * axb[0]) / det,
|
||||
(ca * bc[1] + cb * cxa[1] + cc * axb[1]) / det,
|
||||
(ca * bc[2] + cb * cxa[2] + cc * axb[2]) / det,
|
||||
];
|
||||
};
|
||||
const at = (i: number, d: number): RoofVec3[] => {
|
||||
const pts = planes[i];
|
||||
const n = normals[i];
|
||||
if (d <= EPS) return pts.map((p) => [p[0], p[1], p[2]]);
|
||||
const own: [RoofVec3, number] = [n, dot(n, pts[0]) - d];
|
||||
return pts.map((p, k) => {
|
||||
const prev = (k + pts.length - 1) % pts.length;
|
||||
const fallback: RoofVec3 = [p[0] - n[0] * d, p[1] - n[1] * d, p[2] - n[2] * d];
|
||||
if (!shared[i][prev] && !shared[i][k]) return fallback;
|
||||
const q = solve([own, edgePlane(i, prev, d), edgePlane(i, k, d)]);
|
||||
// Ausreisser (fast parallele Ebenen) abfangen: nicht weiter als ein paar
|
||||
// Dicken von der senkrechten Lösung entfernt.
|
||||
if (!q || Math.hypot(q[0] - fallback[0], q[1] - fallback[1], q[2] - fallback[2]) > 4 * d + 0.5) {
|
||||
return fallback;
|
||||
}
|
||||
return q;
|
||||
});
|
||||
};
|
||||
return { at, shared };
|
||||
}
|
||||
|
||||
/**
|
||||
* Slab einer Dachfläche zwischen fertigen Ober-/Unterseiten-Ecken (gleiche
|
||||
* Reihenfolge). Stirnflächen nur an FREIEN Kanten (`shared[k]` = false) — an
|
||||
* geteilten Kanten stossen die Nachbarflächen auf Gehrung, eine Stirnfläche
|
||||
* läge dort im Inneren des Dachs.
|
||||
*/
|
||||
function pushRoofSlabBetween(
|
||||
positions: number[],
|
||||
indices: number[],
|
||||
top: RoofVec3[],
|
||||
bottom: RoofVec3[],
|
||||
shared: boolean[],
|
||||
): void {
|
||||
// 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(bottom[i][0], bottom[i][1], bottom[i][2]);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emittiert Dächer (`project.roofs`) als geschlossene Dreiecks-Meshes: sowohl die
|
||||
* geneigten Dachflächen (`RoofGeometry.planes`) als auch die Giebelflächen
|
||||
* (`RoofGeometry.gables`) — erst zusammen bilden sie einen von aussen
|
||||
* geschlossenen Körper (die Giebel schliessen die offenen Enden bei Sattel/
|
||||
* Mansarde, die First-/Grat-/Knicklinien sind reine Grundriss-Hilfslinien und
|
||||
* werden hier nicht gebraucht). Traufhöhe über `roofBaseElevation`
|
||||
* (Override oder Geschoss-Oberkante), Flächen über `roofGeometry`. Farbe:
|
||||
* `roof.color` (falls gültiges Hex), sonst {@link ROOF_RGB}. `positions` in
|
||||
* MODELL-Metern (x, y, z=Höhe); render3d rendert Kontext-Meshes doppelseitig,
|
||||
* die Winding-Reihenfolge ist also unerheblich.
|
||||
*/
|
||||
export function emitRoofs(project: Project): RMesh[] {
|
||||
const out: RMesh[] = [];
|
||||
for (const roof of project.roofs ?? []) {
|
||||
const eavesZ = roofBaseElevation(project, roof);
|
||||
const g = roofGeometry(roof, eavesZ);
|
||||
const overrideColor = roof.color ? hexToRgb(roof.color, ROOF_RGB) : null;
|
||||
// Schichtaufbau (aussen/Eindeckung → innen). Jede Schicht wird zu einem
|
||||
// eigenen RMesh mit ihrer Bauteilfarbe, entlang der Flächennormalen unter die
|
||||
// vorige gestapelt. Leere componentId (einschichtige thickness-Fallback) ⇒
|
||||
// Default-Dachfarbe. Eine Roof.color-Übersteuerung gilt für alle Schichten.
|
||||
const layers = roofLayers(project, roof);
|
||||
const mitre = mitredRoofOffsets(g.planes.map((pl) => pl.pts));
|
||||
layers.reduce((offsetAbove, layer) => {
|
||||
const t = Math.max(0, layer.thickness);
|
||||
if (t <= EPS) return offsetAbove;
|
||||
const color =
|
||||
overrideColor ??
|
||||
(layer.componentId ? hexToRgb(getComponent(project, layer.componentId).color, ROOF_RGB) : ROOF_RGB);
|
||||
// Material-Textur-Ebene fürs Textured-Rendering (z. B. echte Dachziegel-
|
||||
// Textur der Eindeckung) — nur wenn KEIN Farb-Override greift (Override
|
||||
// = bewusst eine einheitliche Farbe für alle Schichten, kein Bauteil-Bezug).
|
||||
const materialIndex =
|
||||
!overrideColor && layer.componentId
|
||||
? resolveComponentMaterialLayer(project, layer.componentId)
|
||||
: undefined;
|
||||
const positions: number[] = [];
|
||||
const indices: number[] = [];
|
||||
g.planes.forEach((plane, i) => {
|
||||
// Oberseite dieser Schicht = Dachfläche um `offsetAbove` nach innen
|
||||
// versetzt, Unterseite um `offsetAbove + t` — an First/Grat gehrt.
|
||||
if (plane.pts.length < 3) return;
|
||||
const top = mitre.at(i, offsetAbove);
|
||||
const bottom = mitre.at(i, offsetAbove + t);
|
||||
pushRoofSlabBetween(positions, indices, top, bottom, mitre.shared[i]);
|
||||
});
|
||||
if (indices.length > 0) out.push({ positions, indices, kind: "extrusion", color, materialIndex });
|
||||
return offsetAbove + t;
|
||||
}, 0);
|
||||
// Giebel-ENDFÜLLUNG bewusst NICHT mehr emittieren: die dreieckige Giebelfläche
|
||||
// wurde früher als papierdünne Einzelfläche gebaut ("komischer Abschluss" an
|
||||
// den Sattel-/Mansard-Enden) und lag zudem deckungsgleich vor der Giebelwand,
|
||||
// die ohnehin bis an die Dach-Unterkante hochgeklemmt wird (s.
|
||||
// `../bands.ts::clipPieceToRoofs`) — also doppelt und optisch als dünne
|
||||
// 2D-Schicht sichtbar. Es wird nur noch das Dach SELBST (die geneigten
|
||||
// Slab-Flächen) konstruiert; der Giebel entsteht aus der Wand darunter.
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut die Dach-Schicht-Eingabe für den 3D-Live-Schnitt (`RRoofLayer[]`,
|
||||
* `render3d::roof_cut::cut_roof_layer`) — GETRENNT von {@link emitRoofs} (dem
|
||||
* Render-Mesh), weil `section.rs` beliebige Dreiecksnetze nicht schneiden
|
||||
* kann (nur Wand-Boxen/Decken-Polygone; eine Dachfläche ist kein vertikales
|
||||
* Prisma, s. `RRoofLayer`-Doc in `shared.ts`). EIN Eintrag je (Dach, Schicht,
|
||||
* geneigte Fläche) — ein mehrflächiges Dach (Sattel/Walm/Mansarde) hat
|
||||
* mehrere `g.planes`, jede mit ihrer eigenen Normalen, anders als beim
|
||||
* gemeinsam tessellierten Render-Mesh also KEIN zusammengefasster Eintrag.
|
||||
* Punkte/Normalen bleiben in MODELL-Metern (wie `emitRoofs`) — render3d macht
|
||||
* den Modell->Welt-Wechsel selbst (dieselbe Konvention wie `RMesh`).
|
||||
*/
|
||||
export function emitRoofCutLayers(project: Project): RRoofLayer[] {
|
||||
const out: RRoofLayer[] = [];
|
||||
for (const roof of project.roofs ?? []) {
|
||||
const eavesZ = roofBaseElevation(project, roof);
|
||||
const g = roofGeometry(roof, eavesZ);
|
||||
const overrideColor = roof.color ? hexToRgb(roof.color, ROOF_RGB) : null;
|
||||
const layers = roofLayers(project, roof);
|
||||
layers.reduce((offsetAbove, layer) => {
|
||||
const t = Math.max(0, layer.thickness);
|
||||
if (t <= EPS) return offsetAbove;
|
||||
const color =
|
||||
overrideColor ??
|
||||
(layer.componentId ? hexToRgb(getComponent(project, layer.componentId).color, ROOF_RGB) : ROOF_RGB);
|
||||
const lineStyle = resolveCutLineStyle(project, layer.jointLineStyleId);
|
||||
const cut: RCutMeta | undefined =
|
||||
lineStyle && (lineStyle.color !== undefined || lineStyle.weight !== undefined)
|
||||
? { lineColor: lineStyle.color, lineWeight: lineStyle.weight }
|
||||
: undefined;
|
||||
for (const plane of g.planes) {
|
||||
const nrm = planeNormalUp(plane.pts);
|
||||
const top: RoofVec3[] = plane.pts.map((p) => [
|
||||
p[0] - nrm[0] * offsetAbove,
|
||||
p[1] - nrm[1] * offsetAbove,
|
||||
p[2] - nrm[2] * offsetAbove,
|
||||
]);
|
||||
out.push({ polygon: top, normal: nrm, thickness: t, color, cut });
|
||||
}
|
||||
return offsetAbove + t;
|
||||
}, 0);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
// Gemeinsame Grundlage der 3D-Ableitung: das Serde-Vokabular (`RWall`/`RSlab`/
|
||||
// `RMesh`/…, matcht 1:1 render3d::types) sowie die Farb-/Schraffur-/Material-
|
||||
// Auflösung, die über mehrere Bauteil-Domänen hinweg identisch gelten muss
|
||||
// (Hex→RGB, dominante Schicht, Schnitt-Schraffur, Material-Textur-Ebene).
|
||||
// (Hex→RGB). Die Ableitung selbst rechnet der Rust-Kern (`src-tauri/core/src/model3d.rs`).
|
||||
//
|
||||
// Jede Datei unter `toWalls3d/` importiert von hier, NIE von `../toWalls3d`
|
||||
// selbst — das hielte die Orchestrator-Datei (`toWalls3d.ts`) andernfalls in
|
||||
// einem Zirkelimport mit jeder einzelnen Domäne.
|
||||
|
||||
import type { HatchPattern, Layer, Project } from "../../model/types";
|
||||
import { getCeilingType, getComponent, getWallType, roofLayers } from "../../model/types";
|
||||
import { resolveHatch } from "../generatePlan";
|
||||
import type { Vec3 as RoofVec3 } from "../../geometry/roof";
|
||||
|
||||
export type RVec2 = [number, number];
|
||||
@@ -60,144 +57,6 @@ export interface RHatch {
|
||||
topAngle?: number;
|
||||
}
|
||||
|
||||
/** Bildet ein 2D-{@link HatchPattern} auf die Muster-Id von {@link RHatch}/CAP_WGSL ab. */
|
||||
function hatchPatternId(p: HatchPattern): number {
|
||||
switch (p) {
|
||||
case "solid":
|
||||
return 1;
|
||||
case "diagonal":
|
||||
return 2;
|
||||
case "crosshatch":
|
||||
return 3;
|
||||
case "insulation":
|
||||
return 4;
|
||||
case "none":
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst die Schnitt-Schraffur eines Bauteils (per `Component.hatchId`) zu einem
|
||||
* {@link RHatch} auf — dasselbe Muster/Winkel/Skalierung wie der 2D-Schnitt
|
||||
* (`generatePlan.ts::resolveHatch`, hier bewusst NICHT aufgerufen: nur die drei
|
||||
* render3d-relevanten Felder werden direkt aus dem `HatchStyle` gezogen, die
|
||||
* Farbe bleibt monochrom im Shader). `undefined`, wenn das Bauteil/die Schraffur
|
||||
* nicht auflösbar ist (der Cap-Shader fällt dann auf sein Diagonalmuster zurück).
|
||||
*/
|
||||
export function resolveComponentHatch(
|
||||
project: Project,
|
||||
componentId: string,
|
||||
axisAngleDeg?: number,
|
||||
): RHatch | undefined {
|
||||
try {
|
||||
const comp = getComponent(project, componentId);
|
||||
if (!comp.hatchId) return undefined;
|
||||
// GENAU der 2D-Schnitt-Pfad (`splitWallLayers`/`splitSlabLayers` →
|
||||
// `resolveHatch`): `axisAngleDeg` = 90 für WAND-Bänder (die geschnittene Wand
|
||||
// steht vertikal, `relativeToWall`-Muster drehen mit), `undefined` für DECKEN
|
||||
// (kein Wandachsen-Bezug → absoluter Winkel). Wir übernehmen den ENDWINKEL
|
||||
// (`HatchRender.angle`, bereits relativeToWall-korrigiert) UND die Musterlinien-
|
||||
// Stärke (`lineWeight`, aus dem LineStyle) — nicht mehr den rohen Hatch-Winkel.
|
||||
const hr = resolveHatch(project, comp.hatchId, axisAngleDeg);
|
||||
// Wandbezug für die Draufsicht: Grundwinkel + ob das Muster der Wandachse folgt.
|
||||
const abs = resolveHatch(project, comp.hatchId, undefined);
|
||||
const relativeToWall = resolveHatch(project, comp.hatchId, 90).angle !== abs.angle;
|
||||
return {
|
||||
pattern: hatchPatternId(hr.pattern),
|
||||
angle: hr.angle,
|
||||
scale: hr.scale,
|
||||
lineWeight: hr.lineWeight,
|
||||
baseAngle: abs.angle,
|
||||
relativeToWall,
|
||||
};
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schnitt-Schraffur der dicksten (dominanten) Schicht eines Schichtstapels.
|
||||
* `axisAngleDeg` wie {@link resolveComponentHatch} (90 für Wand, undefined für Decke).
|
||||
*/
|
||||
export function dominantLayerHatch(
|
||||
layers: Layer[],
|
||||
project: Project,
|
||||
axisAngleDeg?: number,
|
||||
): RHatch | undefined {
|
||||
if (layers.length === 0) return undefined;
|
||||
const dominant = layers.reduce((best, l) => (l.thickness > best.thickness ? l : best));
|
||||
return resolveComponentHatch(project, dominant.componentId, axisAngleDeg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Geordnete Liste der EINDEUTIGEN Material-Farbkarten-URLs (`Component.material.
|
||||
* color`), die von Wand-/Decken-Bauteilen des Projekts benutzt werden — in
|
||||
* deterministischer First-Seen-Reihenfolge über `project.walls` (Wandtyp-Schichten)
|
||||
* dann `project.ceilings`. Die POSITION in dieser Liste (+1) ist der Textur-Array-
|
||||
* Index (`WallInput.materialIndex`, 1-basiert; Ebene 0 = Fallback-Schachbrett), den
|
||||
* sowohl {@link resolveComponentMaterialLayer} (Zuweisung je Band) als auch der
|
||||
* JS-Decoder (`viewport/materialTextures`) verwenden — so stimmen Band-Index und
|
||||
* hochgeladene Textur-Ebene ohne separaten Map-Transport überein. Memoisiert je
|
||||
* Projekt-REFERENZ (der Store ist immutabel — jede Änderung liefert ein neues
|
||||
* Objekt, also kein Stale-Risiko), damit die per-Band-Auflösung nicht quadratisch wird.
|
||||
*/
|
||||
const materialMapCache = new WeakMap<Project, string[]>();
|
||||
export function wallMaterialColorMaps(project: Project): string[] {
|
||||
const cached = materialMapCache.get(project);
|
||||
if (cached) return cached;
|
||||
const seen = new Set<string>();
|
||||
const list: string[] = [];
|
||||
const consider = (componentId: string): void => {
|
||||
try {
|
||||
const url = getComponent(project, componentId).material?.color;
|
||||
if (url && !seen.has(url)) {
|
||||
seen.add(url);
|
||||
list.push(url);
|
||||
}
|
||||
} catch {
|
||||
// Unauflösbares Bauteil überspringen.
|
||||
}
|
||||
};
|
||||
for (const w of project.walls) {
|
||||
try {
|
||||
for (const l of getWallType(project, w).layers) consider(l.componentId);
|
||||
} catch {
|
||||
// Kein auflösbarer Wandtyp.
|
||||
}
|
||||
}
|
||||
for (const c of project.ceilings ?? []) {
|
||||
try {
|
||||
for (const l of getCeilingType(project, c).layers) consider(l.componentId);
|
||||
} catch {
|
||||
// Kein auflösbarer Deckentyp.
|
||||
}
|
||||
}
|
||||
for (const r of project.roofs ?? []) {
|
||||
for (const l of roofLayers(project, r)) {
|
||||
if (l.componentId) consider(l.componentId);
|
||||
}
|
||||
}
|
||||
materialMapCache.set(project, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Textur-Array-Ebene (1-basiert) der Material-Farbkarte eines Bauteils, oder
|
||||
* `undefined`, wenn das Bauteil kein Material mit Farbkarte trägt. Ebene 0 ist das
|
||||
* Fallback-Schachbrett — deshalb `indexOf + 1`. Siehe {@link wallMaterialColorMaps}.
|
||||
*/
|
||||
export function resolveComponentMaterialLayer(project: Project, componentId: string): number | undefined {
|
||||
try {
|
||||
const url = getComponent(project, componentId).material?.color;
|
||||
if (!url) return undefined;
|
||||
const idx = wallMaterialColorMaps(project).indexOf(url);
|
||||
return idx >= 0 ? idx + 1 : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein rechteckiges LOCH (Fenster/Tür) in EINEM Wandkörper — matcht 1:1
|
||||
* render3d::types::Hole. KONVENTION: `from`/`to` sind Achsen-Meter ab
|
||||
@@ -407,41 +266,3 @@ export function hexToRgb(hex: string, fallback: RRgb = WALL_RGB): RRgb {
|
||||
const v = parseInt(m[1], 16);
|
||||
return [((v >> 16) & 0xff) / 255, ((v >> 8) & 0xff) / 255, (v & 0xff) / 255];
|
||||
}
|
||||
|
||||
/**
|
||||
* Repräsentative Bauteilfarbe eines Schichtaufbaus: die Farbe der DICKSTEN
|
||||
* Schicht (i. d. R. die tragende/dominante Schicht, z. B. Mauerwerk/Beton) —
|
||||
* einfache Näherung, solange Wände/Decken als EIN Vollkörper emittiert werden
|
||||
* (kein Schicht-Rendering in 3D). Fällt auf `fallback` zurück, wenn keine
|
||||
* Schicht vorhanden ist oder deren Component nicht auflösbar ist.
|
||||
*/
|
||||
export function dominantLayerColor(layers: Layer[], project: Project, fallback: RRgb): RRgb {
|
||||
if (layers.length === 0) return fallback;
|
||||
const dominant = layers.reduce((best, l) => (l.thickness > best.thickness ? l : best));
|
||||
try {
|
||||
return hexToRgb(getComponent(project, dominant.componentId).color, fallback);
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst den Schnitt-UMRISSLINIEN-Stil einer Schicht aus ihrem
|
||||
* `Layer.jointLineStyleId` (LineStyle) auf: Farbe (hex→RGB 0..1) + Strichstärke
|
||||
* (mm-Papier) — dieselbe Quelle wie die 2D-Schichtfuge (`generatePlan/walls.ts`).
|
||||
* Fehlt der Verweis/LineStyle, `undefined` (der 3D-Cut fällt dann auf seinen
|
||||
* Default-Schnittkanten-Stil zurück, siehe `section_fill::build_cut_cap_lines`).
|
||||
* Bewusst tolerant (`find` statt `getLineStyle`), wie im 2D — ein verwaister
|
||||
* Verweis darf den 3D-Push nicht werfen. Von {@link ../bands.resolveWallBands}
|
||||
* UND `../ceilings.emitSlabs` genutzt (Wand- wie Deckenschicht teilen dieselbe
|
||||
* Fugen-Auflösung).
|
||||
*/
|
||||
export function resolveCutLineStyle(
|
||||
project: Project,
|
||||
jointLineStyleId: string | undefined,
|
||||
): { color?: RRgb; weight?: number } | undefined {
|
||||
if (!jointLineStyleId) return undefined;
|
||||
const ls = project.lineStyles.find((l) => l.id === jointLineStyleId);
|
||||
if (!ls) return undefined;
|
||||
return { color: hexToRgb(ls.color, DRAWING_LINE_FALLBACK_RGB), weight: ls.weight };
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
// Treppen-Domäne der 3D-Ableitung: emittiert Treppen als extrudierte RSlabs
|
||||
// (Tritte + Podest, tragart-abhängige Untersicht) — der WASM/wgpu-Renderer
|
||||
// kennt sonst KEINE Treppen (nur Wände/Decken/Meshes). Für Ortbeton-Läufe
|
||||
// zusätzlich ein glattes Dreiecks-Mesh der schrägen Laufplatten-Untersicht, und für gerade
|
||||
// Läufe Handlauf + Pfosten (`StairType.railing`).
|
||||
//
|
||||
// Die ganze Rechnung (Tritt-Prismen je Tragart, Nasen-Verlängerung `StairType.nosing`, dünne
|
||||
// Setzstufen-Platten `closedRisers`, Podest, Soffit-Scheiben im Schnitt, Laufplatten-Mesh,
|
||||
// Handlauf/Pfosten-Quader) steht in Rust (`src-tauri/core/src/stairs3d.rs`, Treppengeometrie aus
|
||||
// `kernel2d`). Hier nur: aus dem `Project` sammeln und die Ergebnisse einfärben.
|
||||
// `ceilingId` trägt bei den Slabs die Treppen-Id (nur TS-seitiges Tagging; render3d ignoriert
|
||||
// das Feld, und der Pick läuft separat über `pickGeometry`).
|
||||
|
||||
import type { Project, Stair, StairType } from "../../model/types";
|
||||
import { getStairType } from "../../model/types";
|
||||
import { stairVerticalExtent } from "../../model/wall";
|
||||
import { encodeStair } from "../../geometry/stair";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import { SLAB_RGB, hexToRgb, type RMesh, type RRgb, type RSlab, type RVec2 } from "./shared";
|
||||
|
||||
/** Neutraler Beton-Grauton für Treppen (wie der Three.js-Pfad `addStairMeshes`). */
|
||||
const STAIR_RGB: RRgb = hexToRgb("#9aa0a6", SLAB_RGB);
|
||||
/** Neutrales Metallgrau für Handlauf + Pfosten. */
|
||||
const RAIL_RGB: RRgb = hexToRgb("#74797f", SLAB_RGB);
|
||||
|
||||
const STRUCTURE = { massiv: 0, beton: 1, wange: 2, aufgesattelt: 2, spindel: 2 } as const;
|
||||
const RAILING = { keine: 0, links: 1, rechts: 2, beide: 3 } as const;
|
||||
|
||||
/**
|
||||
* Flache Rust-Eingabe der Treppen (Aufbau: `stairs3d.rs`); `null` ohne Treppen. `wanted` wählt
|
||||
* nur vor, welche Treppen sich lohnen (spart den WASM-Aufruf); die Regeln selbst prüft Rust.
|
||||
*/
|
||||
function stairInput(
|
||||
project: Project,
|
||||
wanted: (stair: Stair, st: StairType | undefined) => boolean = () => true,
|
||||
): { stairs: Stair[]; buf: Float64Array } | null {
|
||||
const stairs: Stair[] = [];
|
||||
const types: (StairType | undefined)[] = [];
|
||||
for (const stair of project.stairs ?? []) {
|
||||
const st = getStairType(project, stair);
|
||||
if (!wanted(stair, st)) continue;
|
||||
stairs.push(stair);
|
||||
types.push(st);
|
||||
}
|
||||
if (stairs.length === 0) return null;
|
||||
const buf = new Float64Array(1 + 23 * stairs.length);
|
||||
buf[0] = stairs.length;
|
||||
stairs.forEach((stair, k) => {
|
||||
const { zBottom, zTop } = stairVerticalExtent(project, stair);
|
||||
const st = types[k];
|
||||
const o = 1 + 23 * k;
|
||||
buf.set(encodeStair(stair), o);
|
||||
buf[o + 16] = zBottom;
|
||||
buf[o + 17] = zTop;
|
||||
buf[o + 18] = STRUCTURE[st?.structure ?? "massiv"] ?? 2;
|
||||
buf[o + 19] = st?.treadThickness ?? 0.04;
|
||||
buf[o + 20] = st?.nosing ?? 0;
|
||||
buf[o + 21] = st?.closedRisers ? 1 : 0;
|
||||
buf[o + 22] = RAILING[st?.railing ?? "keine"] ?? 0;
|
||||
});
|
||||
return { stairs, buf };
|
||||
}
|
||||
|
||||
/** Rust-Meshes `[n, (treppe, nPos, nIdx, positionen…, indizes…)…]` → `RMesh[]`. */
|
||||
function meshesOf(f: Float64Array, color: RRgb): RMesh[] {
|
||||
const out: RMesh[] = [];
|
||||
let i = 1;
|
||||
for (let n = f.length ? f[0] : 0; n > 0; n--) {
|
||||
const nPos = f[i + 1];
|
||||
const nIdx = f[i + 2];
|
||||
i += 3;
|
||||
const positions: number[] = [];
|
||||
for (let k = 0; k < nPos; k++) positions.push(f[i + k]);
|
||||
i += nPos;
|
||||
const indices: number[] = [];
|
||||
for (let k = 0; k < nIdx; k++) indices.push(f[i + k]);
|
||||
i += nIdx;
|
||||
out.push({ positions, indices, kind: "extrusion", color });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emittiert Treppen als RSlabs (extrudierte Grundriss-Polygone) — der WASM/wgpu-
|
||||
* Renderer kennt sonst KEINE Treppen (nur Wände/Decken/Meshes), sodass Treppen im
|
||||
* Standard-3D unsichtbar blieben. Jeder Tritt ist ein extrudiertes Polygon; das
|
||||
* ist exakt eine RSlab. Tragart über `getStairType`:
|
||||
* • "massiv" / kein Typ — Vollblock je Tritt von der Treppen-UK bis zur Tritt-OK
|
||||
* (gestuftes Massiv, Treppe auf Erdreich/Sockel).
|
||||
* • "beton" — Ortbeton-Laufplatte: je Tritt ein Block von der SCHRÄGEN Untersicht
|
||||
* (eine Stufe + Laufplattendicke unter der Tritt-OK, an der Treppen-UK gekappt)
|
||||
* bis zur Tritt-OK. Die stufig gestapelten Blöcke bilden die schräge, UNTEN
|
||||
* OFFENE Untersicht der klassischen Betontreppe.
|
||||
* • "wange"/"aufgesattelt"/"spindel" — nur eine dünne Tritt-Platte der Dicke
|
||||
* `treadThickness` an der Tritt-OK, darunter offen.
|
||||
* Podest (L/Wendel) als Vollblock bis zur halben Steighöhe. Bei OFFENEN
|
||||
* Tragarten wird die Vorderkante jedes Tritts zusätzlich um `StairType.nosing`
|
||||
* (Trittkanten-Überstand) verlängert und — bei `StairType.closedRisers` — eine dünne
|
||||
* Setzstufen-Platte an der Rückkante ergänzt. Massiv/Beton bilden EIN Körper
|
||||
* (`monolith`, s. render3d `SlabInput::monolith`).
|
||||
*/
|
||||
export function emitStairs(
|
||||
project: Project,
|
||||
/**
|
||||
* `forSection`: auch gerade Betontreppen als Tritt-Prismen liefern (deren
|
||||
* glatte Laufplatte ist im 3D ein Mesh, das der Schnitt-Extraktor nicht
|
||||
* schneiden kann — ohne diese Näherung fehlte die Treppe im Schnitt ganz).
|
||||
*/
|
||||
opts: { forSection?: boolean } = {},
|
||||
): RSlab[] {
|
||||
const input = stairInput(project);
|
||||
if (!input) return [];
|
||||
const f = core().stairs3d_slabs_flat(input.buf, !!opts.forSection);
|
||||
const out: RSlab[] = [];
|
||||
let i = 1;
|
||||
for (let n = f.length ? f[0] : 0; n > 0; n--) {
|
||||
const stair = input.stairs[f[i]];
|
||||
const monolith = f[i + 1] !== 0;
|
||||
const zBottom = f[i + 2];
|
||||
const zTop = f[i + 3];
|
||||
const nPts = f[i + 4];
|
||||
i += 5;
|
||||
const outline: RVec2[] = new Array(nPts);
|
||||
for (let k = 0; k < nPts; k++, i += 2) outline[k] = [f[i], f[i + 1]];
|
||||
out.push({
|
||||
outline,
|
||||
zBottom,
|
||||
zTop,
|
||||
color: STAIR_RGB,
|
||||
ceilingId: stair.id,
|
||||
...(monolith ? { monolith: stair.id } : {}),
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Glatte Ortbeton-Laufplatte (Tragart "beton") als echtes Dreiecks-Mesh — nur für
|
||||
* GERADE Läufe. Anders als die stufige Slab-Näherung ({@link emitStairs}) entsteht
|
||||
* eine SPIEGELGLATTE schräge Untersicht: je Tritt ein konvexes Prisma mit
|
||||
* HORIZONTALER Oberkante (= Trittfläche) und SCHRÄGER Unterkante auf EINER
|
||||
* gemeinsamen Soffit-Geraden. Positions in MODELL-Metern (x, y, z=Höhe); render3d bildet
|
||||
* nach world (x, z, y) ab.
|
||||
*/
|
||||
export function emitStairMeshes(project: Project): RMesh[] {
|
||||
// Nur gerade Betontreppen haben eine glatte Laufplatte.
|
||||
const input = stairInput(project, (s, st) => st?.structure === "beton" && s.shape === "straight");
|
||||
return input ? meshesOf(core().stairs3d_meshes_flat(input.buf), STAIR_RGB) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handlauf + Pfosten (`StairType.railing`: "keine"|"links"|"rechts"|"beide"). Nur für GERADE
|
||||
* Läufe: dort liegt die Vorderkante jedes Tritts exakt auf der linearen Rampen-Geraden, ein
|
||||
* gerades, schräges Segment je Seite + ein Pfosten je Trittvorderkante genügen. L-Läufe und
|
||||
* Wendeltreppen bleiben bewusst aussen vor (eigener Folgeschritt).
|
||||
*/
|
||||
export function emitStairRailings(project: Project): RMesh[] {
|
||||
const input = stairInput(project, (s, st) => s.shape === "straight" && (st?.railing ?? "keine") !== "keine");
|
||||
return input ? meshesOf(core().stairs3d_railings_flat(input.buf), RAIL_RGB) : [];
|
||||
}
|
||||
@@ -29,6 +29,11 @@ describe("Abzugskoerper — Polygon-Kern", () => {
|
||||
it("ohne Ueberschneidung: null (Original bleibt)", () => {
|
||||
expect(subtractRings(sq(0, 0, 1, 1), [sq(5, 5, 6, 6)])).toBeNull();
|
||||
});
|
||||
it("zwei getrennte Aussparungen wirken beide (drei Restteile)", () => {
|
||||
// Früher: der Überschneidungstest schnitt mit ALLEN Schneidern zugleich → keine Subtraktion.
|
||||
const r = subtractRings(sq(0, 0, 10, 2), [sq(1, -1, 2, 3), sq(6, -1, 7, 3)])!;
|
||||
expect(r).toHaveLength(3);
|
||||
});
|
||||
it("ungestrichene Originalkanten bleiben ungestrichen", () => {
|
||||
// Kante 1 (rechts, x=4) ungestrichen; der Schnitt links lässt sie unberührt.
|
||||
const r = subtractRings(sq(0, 0, 4, 2), [sq(-1, -1, 1, 3)], [1])!;
|
||||
|
||||
+42
-163
@@ -15,8 +15,8 @@
|
||||
// Polygone mit Loch (Körper ganz im Bauteil) werden über einen Steg an den Aussenring
|
||||
// gehängt (Schlüsselloch); die beiden Stegkanten sind nicht gestrichen (`noStrokeEdges`).
|
||||
|
||||
import * as polygonClipping from "../geometry/polygonBool";
|
||||
import type { Pair, Polygon as PcPolygon, MultiPolygon } from "../geometry/polygonBool";
|
||||
import type { Pair } from "../geometry/polygonBool";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import type { ExtrudedSolid, Project, Vec2 } from "../model/types";
|
||||
import { getFloor } from "../model/types";
|
||||
import { ceilingVerticalExtent, columnVerticalExtent } from "../model/wall";
|
||||
@@ -60,29 +60,18 @@ export function voidPrisms(project: Project): VoidPrism[] {
|
||||
return out;
|
||||
}
|
||||
|
||||
// ── Polygon-Booleans ─────────────────────────────────────────────────────────
|
||||
// ── Polygon-Booleans (Rust-Kern, `voids.rs`) ─────────────────────────────────
|
||||
|
||||
const ring = (pts: Vec2[]): Pair[] => pts.map((p) => [p.x, p.y] as Pair);
|
||||
|
||||
/** Fläche (vorzeichenbehaftet) eines Rings. */
|
||||
function signedArea(r: Pair[]): number {
|
||||
let a = 0;
|
||||
for (let i = 0; i < r.length; i++) {
|
||||
const p = r[i];
|
||||
const q = r[(i + 1) % r.length];
|
||||
a += p[0] * q[1] - q[0] * p[1];
|
||||
/** Ringliste flach für den Kern (`[n, (k, x, y …) × n]`). */
|
||||
function encodeRings(rings: Pair[][]): Float64Array {
|
||||
const b: number[] = [rings.length];
|
||||
for (const r of rings) {
|
||||
b.push(r.length);
|
||||
for (const p of r) b.push(p[0], p[1]);
|
||||
}
|
||||
return a / 2;
|
||||
}
|
||||
|
||||
/** Ring ohne doppelten Schlusspunkt (der Polygon-Kern liefert geschlossene Ringe). */
|
||||
function openRing(r: Pair[]): Pair[] {
|
||||
if (r.length > 1) {
|
||||
const a = r[0];
|
||||
const b = r[r.length - 1];
|
||||
if (Math.abs(a[0] - b[0]) < EPS && Math.abs(a[1] - b[1]) < EPS) return r.slice(0, -1);
|
||||
}
|
||||
return r;
|
||||
return Float64Array.from(b);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,45 +79,14 @@ function openRing(r: Pair[]): Pair[] {
|
||||
* Indizes der Stegkanten (Kante i = pts[i] → pts[i+1]).
|
||||
*/
|
||||
export function keyhole(poly: Pair[][]): { pts: Pair[]; bridges: number[] } {
|
||||
let outer = openRing(poly[0]);
|
||||
const bridges: number[] = [];
|
||||
const holes = poly.slice(1).map(openRing).filter((h) => h.length >= 3);
|
||||
// Löcher von rechts nach links einhängen (Stege kreuzen sich so nicht).
|
||||
holes.sort((a, b) => Math.max(...b.map((p) => p[0])) - Math.max(...a.map((p) => p[0])));
|
||||
for (const hole of holes) {
|
||||
// Lochpunkt mit grösstem x, nächster Aussenring-Punkt dazu.
|
||||
let hi = 0;
|
||||
for (let i = 1; i < hole.length; i++) if (hole[i][0] > hole[hi][0]) hi = i;
|
||||
const h = hole[hi];
|
||||
let oi = 0;
|
||||
let best = Infinity;
|
||||
for (let i = 0; i < outer.length; i++) {
|
||||
const d = Math.hypot(outer[i][0] - h[0], outer[i][1] - h[1]);
|
||||
if (d < best) {
|
||||
best = d;
|
||||
oi = i;
|
||||
}
|
||||
}
|
||||
const holeSeq = [...hole.slice(hi), ...hole.slice(0, hi), h];
|
||||
const next: Pair[] = [...outer.slice(0, oi + 1), ...holeSeq, outer[oi], ...outer.slice(oi + 1)];
|
||||
// Indizes der beiden Stegkanten (alte Stegindizes hinter oi verschieben sich).
|
||||
const shift = holeSeq.length + 1;
|
||||
for (let k = 0; k < bridges.length; k++) if (bridges[k] > oi) bridges[k] += shift;
|
||||
bridges.push(oi, oi + holeSeq.length);
|
||||
outer = next;
|
||||
}
|
||||
return { pts: outer, bridges };
|
||||
}
|
||||
|
||||
/** Liegt Segment a→b auf Segment p→q (kollinear, innerhalb)? */
|
||||
function onSegment(a: Pair, b: Pair, p: Pair, q: Pair, tol = 1e-6): boolean {
|
||||
const dx = q[0] - p[0];
|
||||
const dy = q[1] - p[1];
|
||||
const len = Math.hypot(dx, dy);
|
||||
if (len < EPS) return false;
|
||||
const dist = (r: Pair) => Math.abs((r[0] - p[0]) * dy - (r[1] - p[1]) * dx) / len;
|
||||
const t = (r: Pair) => ((r[0] - p[0]) * dx + (r[1] - p[1]) * dy) / (len * len);
|
||||
return dist(a) < tol && dist(b) < tol && t(a) > -tol && t(a) < 1 + tol && t(b) > -tol && t(b) < 1 + tol;
|
||||
const f = core().voids_keyhole_flat(encodeRings(poly));
|
||||
const n = f[0];
|
||||
const pts = new Array<Pair>(n);
|
||||
for (let i = 0; i < n; i++) pts[i] = [f[1 + 2 * i], f[2 + 2 * i]];
|
||||
const nb = f[1 + 2 * n];
|
||||
const bridges = new Array<number>(nb);
|
||||
for (let i = 0; i < nb; i++) bridges[i] = f[2 + 2 * n + i];
|
||||
return { pts, bridges };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,99 +101,33 @@ export function subtractRings(
|
||||
noStroke: number[] = [],
|
||||
): Array<{ pts: Pair[]; noStrokeEdges: number[] }> | null {
|
||||
if (pts.length < 3 || cutters.length === 0) return null;
|
||||
const subject: PcPolygon = [pts];
|
||||
const clips: MultiPolygon = cutters.filter((c) => c.length >= 3).map((c) => [c] as PcPolygon);
|
||||
if (clips.length === 0) return null;
|
||||
// Schnell-Test: überlappen die Hüllen überhaupt?
|
||||
let hit = false;
|
||||
try {
|
||||
hit = polygonClipping.intersection(subject, ...clips).length > 0;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (!hit) return null;
|
||||
let diff: MultiPolygon;
|
||||
try {
|
||||
diff = polygonClipping.difference(subject, ...clips);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
const area0 = Math.abs(signedArea(pts));
|
||||
const f = core().voids_subtract_rings_flat(
|
||||
encodeRings([pts]).subarray(1),
|
||||
encodeRings(cutters),
|
||||
Float64Array.from([noStroke.length, ...noStroke]),
|
||||
);
|
||||
if (f.length === 0 || f[0] < 0) return null;
|
||||
const out: Array<{ pts: Pair[]; noStrokeEdges: number[] }> = [];
|
||||
for (const poly of diff) {
|
||||
const { pts: kp, bridges } = keyhole(poly);
|
||||
if (kp.length < 3 || Math.abs(signedArea(openRing(poly[0]))) < area0 * 1e-9) continue;
|
||||
// Orientierung des Originals beibehalten (Schraffur-/Strich-Logik ist orientierungsfrei,
|
||||
// aber Tests und Nachbearbeitungen erwarten den Umlaufsinn).
|
||||
const sameDir = Math.sign(signedArea(kp)) === Math.sign(signedArea(pts)) || signedArea(pts) === 0;
|
||||
const ringPts = sameDir ? kp : [...kp].reverse();
|
||||
const n = ringPts.length;
|
||||
const bridgeSet = new Set(sameDir ? bridges : bridges.map((i) => (n - 2 - i + n) % n));
|
||||
const ns: number[] = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
const a = ringPts[i];
|
||||
const b = ringPts[(i + 1) % n];
|
||||
if (bridgeSet.has(i)) {
|
||||
ns.push(i);
|
||||
continue;
|
||||
}
|
||||
for (const e of noStroke) {
|
||||
const p = pts[e];
|
||||
const q = pts[(e + 1) % pts.length];
|
||||
if (p && q && onSegment(a, b, p, q)) {
|
||||
ns.push(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
out.push({ pts: ringPts, noStrokeEdges: ns });
|
||||
let i = 1;
|
||||
for (let k = 0; k < f[0]; k++) {
|
||||
const n = f[i++];
|
||||
const rp = new Array<Pair>(n);
|
||||
for (let j = 0; j < n; j++, i += 2) rp[j] = [f[i], f[i + 1]];
|
||||
const m = f[i++];
|
||||
const ns = new Array<number>(m);
|
||||
for (let j = 0; j < m; j++) ns[j] = f[i++];
|
||||
out.push({ pts: rp, noStrokeEdges: ns });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// ── Grundriss ────────────────────────────────────────────────────────────────
|
||||
|
||||
function pointInRing(x: number, y: number, r: Pair[]): boolean {
|
||||
let inside = false;
|
||||
for (let i = 0, j = r.length - 1; i < r.length; j = i++) {
|
||||
const [xi, yi] = r[i];
|
||||
const [xj, yj] = r[j];
|
||||
if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
/** Teile der Strecke a→b ausserhalb aller Ringe, als Parameter-Intervalle [t0, t1]. */
|
||||
export function segmentOutside(a: Vec2, b: Vec2, cutters: Pair[][]): Array<[number, number]> {
|
||||
const ts = [0, 1];
|
||||
const dx = b.x - a.x;
|
||||
const dy = b.y - a.y;
|
||||
for (const r of cutters) {
|
||||
for (let i = 0; i < r.length; i++) {
|
||||
const p = r[i];
|
||||
const q = r[(i + 1) % r.length];
|
||||
const ex = q[0] - p[0];
|
||||
const ey = q[1] - p[1];
|
||||
const den = dx * ey - dy * ex;
|
||||
if (Math.abs(den) < 1e-14) continue;
|
||||
const t = ((p[0] - a.x) * ey - (p[1] - a.y) * ex) / den;
|
||||
const u = ((p[0] - a.x) * dy - (p[1] - a.y) * dx) / den;
|
||||
if (t > 0 && t < 1 && u >= -1e-9 && u <= 1 + 1e-9) ts.push(t);
|
||||
}
|
||||
}
|
||||
ts.sort((x, y) => x - y);
|
||||
const f = core().voids_segment_outside_flat(Float64Array.from([a.x, a.y, b.x, b.y]), encodeRings(cutters));
|
||||
const out: Array<[number, number]> = [];
|
||||
for (let i = 0; i + 1 < ts.length; i++) {
|
||||
const [t0, t1] = [ts[i], ts[i + 1]];
|
||||
if (t1 - t0 < 1e-9) continue;
|
||||
const tm = (t0 + t1) / 2;
|
||||
const mx = a.x + dx * tm;
|
||||
const my = a.y + dy * tm;
|
||||
if (cutters.some((r) => pointInRing(mx, my, r))) continue;
|
||||
const last = out[out.length - 1];
|
||||
if (last && Math.abs(last[1] - t0) < 1e-9) last[1] = t1;
|
||||
else out.push([t0, t1]);
|
||||
}
|
||||
for (let k = 0; k < (f[0] ?? 0); k++) out.push([f[1 + 2 * k], f[2 + 2 * k]]);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -315,27 +207,14 @@ export function subtractVoidsInPlan(prims: Primitive[], project: Project, cutZ:
|
||||
* Richtung `uDir` (Einheitsvektor; u = Abstand entlang uDir ab `base`).
|
||||
*/
|
||||
export function voidSectionRects(v: VoidPrism, base: Vec2, uDir: Vec2): Pair[][] {
|
||||
const ts: number[] = [];
|
||||
const n = v.pts.length;
|
||||
// Normale der Schnittspur: Punkt-Seite über das Kreuzprodukt.
|
||||
const side = (p: Vec2) => (p.x - base.x) * uDir.y - (p.y - base.y) * uDir.x;
|
||||
for (let i = 0; i < n; i++) {
|
||||
const a = v.pts[i];
|
||||
const b = v.pts[(i + 1) % n];
|
||||
const sa = side(a);
|
||||
const sb = side(b);
|
||||
// Halboffene Regel (eine Ecke auf der Spur zählt nur einmal).
|
||||
if ((sa > 0) === (sb > 0)) continue;
|
||||
const t = sa / (sa - sb);
|
||||
const px = a.x + (b.x - a.x) * t;
|
||||
const py = a.y + (b.y - a.y) * t;
|
||||
ts.push((px - base.x) * uDir.x + (py - base.y) * uDir.y);
|
||||
}
|
||||
ts.sort((a, b) => a - b);
|
||||
const f = core().voids_section_rects_flat(
|
||||
Float64Array.from([v.pts.length, ...v.pts.flatMap((p) => [p.x, p.y])]),
|
||||
Float64Array.from([base.x, base.y, uDir.x, uDir.y]),
|
||||
);
|
||||
const rects: Pair[][] = [];
|
||||
for (let i = 0; i + 1 < ts.length; i += 2) {
|
||||
const [u0, u1] = [ts[i], ts[i + 1]];
|
||||
if (u1 - u0 < 1e-6) continue;
|
||||
for (let k = 0; k < (f[0] ?? 0); k++) {
|
||||
const u0 = f[1 + 2 * k];
|
||||
const u1 = f[2 + 2 * k];
|
||||
rects.push([
|
||||
[u0, v.z0],
|
||||
[u1, v.z0],
|
||||
|
||||
@@ -63,3 +63,4 @@ const store = createStore<RootState>((api) => ({
|
||||
export const useStore = store.useStore;
|
||||
export const getState = store.getState;
|
||||
export const setState = store.setState;
|
||||
|
||||
Reference in new issue
Block a user