diff --git a/TODO.md b/TODO.md index 8f5a0517..ef1c5a1d 100644 --- a/TODO.md +++ b/TODO.md @@ -1183,6 +1183,32 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]). Treppenuntersicht, Abzugskörper beliebiger Form im Schnitt. · L - ◐ **[G2] Wand an Dach.** 27.10.: schräge Oberkante (`topDrop`) in render3d statt 15-cm-Treppung. Offen: Schnitt, exakte Lösung über [B6]. · M–L + - (30.10.) **Exakt je Schicht, analytisch** (ohne Booleans, `wall_bands.rs`): Dach-Unterkante als Facetten + (`RoofFacet`: Dachfläche um die Schichtdicke senkrecht gesenkt, Gaubeninneres mit der Gaubendach-Unterkante, + `DormerGeom::under_facets`); über einem Punkt gilt die obere Hülle (Kehlen verschnittener Dächer, Gaube). + Jedes Band wird an den Bereichsgrenzen geteilt — längs mit der exakten Grenzlinie als Schnittlinie (First, + Grat, Kehle, Höhenlinie Dach = Krone/Fuss), seitlich über die Dicke, wo eine Grenze längs durchläuft + (Traufwand, deren Krone die Dachfläche schneidet) — und bekommt eine **ebene Oberkante** (`Piece.top_plane`, + `RWall.topPlane` = `[z am Anfang, dz/dx, dz/dy]`): jede Ecke exakt auf der Unterkante, auch quer über die + Dicke. Öffnungen unter dem Dach: Pfeiler/Brüstung/Sturz je mit eigener ebener Oberkante statt Treppung; + innere Teilungen als Stossfugen (`joint`, keine Stirn in Ansicht/Schnitt-Projektion). **Option je Wand** + `Wall.roofAttach` („An Dach anschliessen", Objekt-Info): fehlt = automatisch (nur kürzen, wo die Krone über + der Unterkante liegt), `true` = bis unter das Dach verlängern, `false` = Dächer schneiden nicht. Verbraucher: + render3d (Mesh, Deckel-Schraffur, Schnitt-Prisma mit schräger Deckelkante), Kern-Schnitt und -Ansicht + (Schnitt-Eingabe jetzt mit den Dächern des Geschosses), OBJ/STL/glTF und IFC (Prisma bis zur Dachunterkante, + `model3d::wall_piece_mesh`), Mengen (Brutto-/Nettovolumen exakt über die Grundfläche, + `wall_piece_volume`). Ansicht: Wandflächen unter Dächern gegen die Dachscheiben (Oberfläche, Trauf-/Ortgang- + Stirn, Gaubenstirn/-wangen) verdeckt bzw. auf die Verdeckungsgrenze gekappt, Giebeldreiecke entfallen, wenn + Wände ans Dach reichen (dafür Stirnflächen der Dachscheibe). Bogenwände ([T2]) laufen über die Sehnen- + Teilwände mit. Geprüft: Rust-Tests (Giebel beidseitig je Schicht exakt, Traufwand schräg + seitlich geteilt, + Fenster unter der Schräge Volumen exakt, An-Dach-Option, Kehle = obere Hülle, Schnitt-Pfad, Körper dicht und + Volumen = Analytik, Schnitt nie über der Unterkante, Ansicht Traufe/Giebel), render3d-Test (Mesh-Ecken auf der + Ebene, Schnitt schräg), CLI-Schnitte/-Ansichten eines Testhauses (Satteldach mit Trauf-/Giebelwänden, + Fenster unter der Schräge, T-Dach mit Kehlen, Gaube, Bogenwand, Innenwand „bis unters Dach") als PNG + angesehen (Linux). Offen: Ansicht bleibt Painter + Verdeckungstest gegen Dächer (keine HLR, [G4]); Grenzen, + die fast parallel zur Achse schräg durchs Band laufen, nur genähert (seitliche Teilung an der Mitte); + Fenster, das ins Dach ragt, verliert seinen Sturz; Dachgeometrie im 3D-Live-Schnitt unverändert; nicht in + der Tauri-App/Metal geprüft. - ◐ **[G3] Öffnungen beliebiger Form** (29.10.) `Opening.shape` (rundbogen, segmentbogen, spitzbogen, rund/oval, schraeg, giebel) + `shapeRise` (Stich). Kern `opening_shape.rs`: konvexer Umriss im Öffnungsrechteck; die Wand behält das Rechteck-Loch, der Rest zwischen Rechteck und Umriss kommt als Füllkörper (senkrechte Streifen = @@ -1228,6 +1254,16 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]). statt `RWall` gehen), 3D-Live-Schnitt-Deckel verschnittener Dächer (zeigen noch die unverschnittenen Schichten), IFC-Mengen der Gaube, Kehlen symmetrisch je Schicht (heute „überlappt" das frühere Dach), Gauben über First/Grat hinaus nicht abgefangen, nicht in der Tauri-App/Metal geprüft. + - (30.10.) Restpunkte: **Gauben über den First** werden abgefangen (`dormer::geometry`): Stirnhöhe (bzw. Tiefe + der Schleppgaube) so gekappt, dass die Gaubendach-Oberkante spätestens am First auf die Hauptdach-Oberkante + trifft (`DormerGeom.clamped`), das Gaubendach endet am Rand seiner Dachfläche (vorher ragte es jenseits des + Firsts als Splitter heraus). **IFC-Mengen der Gaube**: `Qto_DossierDormerQuantities` am IfcRoof (Breiten, + Stirnhöhe, geneigter Ausschnitt, Wand- und Dachvolumen aus den Körpern), NetArea des Dachs ohne den + Ausschnitt. **Haarfugen** der Dachfläche in der Ansicht: Kontur in Füllfarbe 0.15 mm statt 0.05 mm. Wand ↔ + Dach: [G2]. Wand ↔ Decke: bestehende Schicht-Dominanz (3D je Band nach Rang, Schnitt + `subtract_dominant_bands`) im CLI-Schnitt des Beispielprojekts angesehen, nicht geändert. Offen: + 3D-Live-Schnitt-Deckel verschnittener Dächer, Kehlen symmetrisch je Schicht, Warnung bei gekappter Gaube in + der UI, Wand ↔ Decke für beliebige Polygone im Schnitt ([G6]). - (30.10.) Boolean-Werkzeug dafür: Manifold-Port `manifold-rust`, nicht truck — truck scheitert an Gaube und L-Ecke (bündige Unterseiten), `manifold-rust` rechnet beide exakt und dicht. Details und Plan: [107]. - ○ **[G6] Allgemeine Polygon-Dominanz im Schnitt** (nicht nur Rechtecke). · M diff --git a/src-tauri/core/src/dormer.rs b/src-tauri/core/src/dormer.rs index 0583a28b..73f0fb01 100644 --- a/src-tauri/core/src/dormer.rs +++ b/src-tauri/core/src/dormer.rs @@ -76,6 +76,8 @@ pub struct DormerGeom { pub main_thickness: f64, /// Ende der Gaubendach-Flächen hinten (lokal v). pub v_end: f64, + /// Über den First hinaus und darum gekappt ([G5]). + pub clamped: bool, } /// Fläche des Gaubendachs: Grundriss-Polygon (lokal, Gegenuhrzeigersinn) und Ebene `z = a + bu·u + bv·v` @@ -157,8 +159,62 @@ pub fn roof_layers(p: &Project, roof: &Roof, d: &Dormer) -> Vec { } /// Gaubengeometrie; `None` bei unsinnigen Parametern (zu schmal, zu niedrig, Gaubendach steiler als das -/// Hauptdach bei der Schleppgaube, Punkt nicht in einer geneigten Fläche). +/// Hauptdach bei der Schleppgaube, Punkt nicht in einer geneigten Fläche). Reicht die Gaube über den +/// First/Grat ihrer Dachfläche hinaus (zu hoch), wird sie abgefangen: Stirnhöhe (bzw. Tiefe der +/// Schleppgaube) so gekappt, dass die Gaubendach-Oberkante spätestens am First auf die Hauptdach-Oberkante +/// trifft (`clamped`); das Gaubendach endet am Rand der Dachfläche. pub fn geometry(p: &Project, roof: &Roof, d: &Dormer) -> Option { + let g = geometry_raw(p, roof, d)?; + let pts = crate::roof::roof_geometry(&roof.params(), p.roof_base_elevation(roof)).planes.into_iter().nth(g.frame.plane)?; + let f = g.frame.clone(); + let inside = |v: f64| point_in_xy(f.plan(0.0, v)[0], f.plan(0.0, v)[1], &pts); + // Tiefe bis zum Rand der Dachfläche (First/Grat) längs der Gaubenmitte. + let (mut lo, mut hi) = (0.0, 60.0); + if inside(hi) { + return Some(g); + } + let mut g = g; + for _ in 0..60 { + let m = (lo + hi) / 2.0; + if inside(m) { + lo = m; + } else { + hi = m; + } + } + let v_edge = lo; + // Wo die Gaubendach-OBERKANTE die Hauptdach-Oberkante trifft (hinter dem Lochrand). + let (tm, t, hw, rv) = (f.tan_main, g.tan_p, g.width / 2.0, g.roof_vertical()); + let meet = match g.kind { + DormerKind::Schlepp => (g.front_height + rv) / (tm - t), + DormerKind::Flach => (g.front_height + rv) / tm, + _ => (g.front_height + hw * t + rv) / tm, + }; + let v_r = v_edge - 1e-3; + // Gaubendach nicht über den Rand der Dachfläche hinaus verlängern (sonst ragt es jenseits des Firsts); + // 1 cm davor endet es unter der Hauptdach-Oberkante (nicht bündig mit dem First: keine Splitter). + let cap = |g: &mut DormerGeom, meet: f64| g.v_end = g.v_end.min((v_edge - 0.01).max(meet.min(v_edge))); + if meet <= v_r + 1e-9 { + cap(&mut g, meet); + return Some(g); + } + let mut d2 = d.clone(); + match g.kind { + DormerKind::Schlepp if d.depth.is_some_and(|x| x.is_finite() && x > 0.1) => d2.depth = Some(d2.depth.unwrap_or(0.0) - (meet - v_r)), + DormerKind::Schlepp => d2.front_height = v_r * (tm - t) - rv, + DormerKind::Flach => d2.front_height = v_r * tm - rv, + _ => d2.front_height = v_r * tm - hw * t - rv, + } + if !(d2.front_height >= 0.3) || d2.depth.is_some_and(|x| !(x > 0.1)) { + return None; + } + let mut g2 = geometry_raw(p, roof, &d2)?; + cap(&mut g2, v_r); + g2.clamped = true; + Some(g2) +} + +fn geometry_raw(p: &Project, roof: &Roof, d: &Dormer) -> Option { let frame = frame(p, roof, d)?; if !(finite_pos(d.width) && d.width >= 0.4 && d.width <= 30.0 && finite_pos(d.front_height) && d.front_height <= 10.0) { return None; @@ -186,7 +242,7 @@ pub fn geometry(p: &Project, roof: &Roof, d: &Dormer) -> Option { return None; } let z_e = frame.z_m0 + d.front_height; - let mut g = DormerGeom { frame, kind: d.kind, width: d.width, front_height: d.front_height, overhang, tan_p, z_e, roof_layers, wall_layers, roof_thickness, wall_thickness, main_thickness, v_end: 0.0 }; + let mut g = DormerGeom { frame, kind: d.kind, width: d.width, front_height: d.front_height, overhang, tan_p, z_e, roof_layers, wall_layers, roof_thickness, wall_thickness, main_thickness, v_end: 0.0, clamped: false }; // Hinten weit genug, dass die ganze Gaubendach-Unterkante unter der Hauptdach-Unterkante endet. let main_v = main_thickness * (1.0 + tm * tm).sqrt(); let top_extra = roof_thickness * (1.0 + tan_p * tan_p).sqrt(); @@ -214,6 +270,49 @@ impl DormerGeom { } } + /// Unterkante des Gaubeninneren als Facetten für Wände darunter ([G2]): Bereich zwischen Stirn und + /// Wangen bis zum Lochrand, je Gaubendach-Fläche eine Ebene (Welt). + pub fn under_facets(&self) -> Vec { + let (hw, tw, t, ze) = (self.width / 2.0, self.wall_thickness, self.tan_p, self.z_e); + let hi = hw - tw; + if !(hi > 1e-3) { + return Vec::new(); + } + let ring: Vec

= match self.kind { + DormerKind::Flach | DormerKind::Schlepp => vec![[-hi, tw], [hi, tw], [hi, self.hole_v(hi)], [-hi, self.hole_v(-hi)]], + _ => vec![[-hi, tw], [hi, tw], [hi, self.hole_v(hi)], [0.0, self.hole_v(0.0)], [-hi, self.hole_v(-hi)]], + }; + // (Ring lokal, z = a + bu·u + bv·v), Bereiche überdeckungsfrei. + let mut parts: Vec<(Vec

, f64, f64, f64)> = Vec::new(); + match self.kind { + DormerKind::Flach => parts.push((ring, ze, 0.0, 0.0)), + DormerKind::Schlepp => parts.push((ring, ze, 0.0, t)), + DormerKind::Sattel | DormerKind::Unknown => { + parts.push((clip_half(&ring, [-1.0, 0.0, 0.0]), ze + hw * t, t, 0.0)); + parts.push((clip_half(&ring, [1.0, 0.0, 0.0]), ze + hw * t, -t, 0.0)); + } + DormerKind::Walm => { + // Stirn-Walm: v ≤ hw − |u|; Seiten: darüber, links/rechts. + let front = clip_half(&clip_half(&ring, [-1.0, -1.0, hw]), [1.0, -1.0, hw]); + parts.push((front, ze, 0.0, t)); + parts.push((clip_half(&clip_half(&ring, [-1.0, 0.0, 0.0]), [-1.0, 1.0, -hw]), ze + hw * t, t, 0.0)); + parts.push((clip_half(&clip_half(&ring, [1.0, 0.0, 0.0]), [1.0, 1.0, -hw]), ze + hw * t, -t, 0.0)); + } + } + let f = &self.frame; + parts + .into_iter() + .filter(|(r, ..)| r.len() >= 3) + .filter_map(|(r, a, bu, bv)| { + // u = (q − p)·ew, v = −(q − p)·h. + let gx = bu * f.ew[0] - bv * f.h[0]; + let gy = bu * f.ew[1] - bv * f.h[1]; + let c = a - gx * f.p[0] - gy * f.p[1]; + crate::wall_bands::RoofFacet::new(r.iter().map(|q| f.plan(q[0], q[1])).collect(), [c, gx, gy]) + }) + .collect() + } + /// Lotrechter Abstand Oberkante − Unterkante (Gaubendach). pub fn roof_vertical(&self) -> f64 { self.roof_thickness * (1.0 + self.tan_p * self.tan_p).sqrt() @@ -319,6 +418,24 @@ impl DormerGeom { } } +/// Konvexer Ring, beschnitten auf die Halbebene `a·u + b·v + c ≥ 0` (Sutherland-Hodgman). +fn clip_half(ring: &[P], [a, b, c]: [f64; 3]) -> Vec

{ + let f = |q: P| a * q[0] + b * q[1] + c; + let mut out = Vec::new(); + for i in 0..ring.len() { + let (p, q) = (ring[i], ring[(i + 1) % ring.len()]); + let (fp, fq) = (f(p), f(q)); + if fp >= 0.0 { + out.push(p); + } + if (fp >= 0.0) != (fq >= 0.0) { + let t = fp / (fp - fq); + out.push([p[0] + t * (q[0] - p[0]), p[1] + t * (q[1] - p[1])]); + } + } + out +} + /// Gaube `dormer_id` im Dach `roof_id` (Index des Dachs, Gaube). pub fn find<'a>(p: &'a Project, roof_id: &str, dormer_id: &str) -> Option<(usize, &'a Roof, &'a Dormer)> { let (ri, roof) = p.roofs.as_deref()?.iter().enumerate().find(|(_, r)| r.id == roof_id)?; @@ -345,7 +462,7 @@ pub fn dormer_openings(p: &Project, roof_index: usize) -> Vec<(&Opening, &Dormer } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; pub(crate) fn gable_project() -> Project { @@ -362,6 +479,25 @@ mod tests { .unwrap() } + #[test] + fn zu_hohe_gaube_wird_vor_dem_first_gekappt() { + let mut p = gable_project(); + let roof = &mut p.roofs.as_mut().unwrap()[0]; + roof.dormers.as_mut().unwrap()[0].front_height = 6.0; + let roof = &p.roofs.as_ref().unwrap()[0]; + let g = geometry(&p, roof, &roof.dormers.as_ref().unwrap()[0]).expect("gekappt statt verworfen"); + assert!(g.clamped && g.front_height < 6.0); + // Gaubendach trifft die Hauptdach-Oberkante 1 mm vor dem First (y = 4; Stirn bei y = 1 ⇒ 3 m), + // nichts reicht über den First. + let reach = g.hole().iter().map(|q| q[1]).fold(0.0, f64::max); + let meet = (g.front_height + 1.2 * g.tan_p + g.roof_vertical()) / g.frame.tan_main; + assert!(reach < 2.999 && (meet - 2.999).abs() < 1e-6 && g.v_end <= 3.0 + 1e-9, "{reach} {meet} {}", g.v_end); + let q = gable_project(); + let r0 = &q.roofs.as_ref().unwrap()[0]; + let ok = geometry(&q, r0, &r0.dormers.as_ref().unwrap()[0]).unwrap(); + assert!(!ok.clamped); + } + #[test] fn frame_and_hole_on_gable_roof() { let p = gable_project(); diff --git a/src-tauri/core/src/ifc_data.rs b/src-tauri/core/src/ifc_data.rs index 6c5875a7..9493e86b 100644 --- a/src-tauri/core/src/ifc_data.rs +++ b/src-tauri/core/src/ifc_data.rs @@ -269,7 +269,7 @@ fn by_from(p: &[f64; 4], q: &[f64; 4]) -> std::cmp::Ordering { fn bands_match_openings(wall: &Wall, bands: &[&RWall], cutouts: &[Cutout]) -> bool { let u = normalize(sub(wall.end, wall.start)); for b in bands { - if b.top_drop.is_some_and(|d| d[0].abs() > 1e-9 || d[1].abs() > 1e-9) { + if b.top_plane.is_some() || b.top_drop.is_some_and(|d| d[0].abs() > 1e-9 || d[1].abs() > 1e-9) { return false; } let a = dot(Vec2 { x: b.start[0] - wall.start.x, y: b.start[1] - wall.start.y }, u); @@ -497,6 +497,33 @@ struct SolidOpening { /// Dreiecke eines 8-Ecken-Quaders wie `model3d::OPENING_BOX_TRIS`. const BOX_TRIS: [u32; 36] = [0, 1, 3, 0, 3, 2, 4, 5, 7, 4, 7, 6, 0, 1, 5, 0, 5, 4, 2, 3, 7, 2, 7, 6, 0, 2, 6, 0, 6, 4, 1, 3, 7, 1, 7, 5]; +/// Gauben eines Dachs (Index) für die Mengen ([G5]): je Gaube Breite, Stirnhöhe, geneigte Fläche des +/// Ausschnitts im Hauptdach, Volumen der Wände (Stirn/Wangen) und des Gaubendachs aus den Körpern. +fn dormer_parts(p: &Project, ri: usize, roof: &Roof) -> Vec { + let solids = crate::roof_assembly::roof_solids(p, ri); + let vol = |id: &str, role: crate::roof_assembly::Role| -> f64 { + solids.as_ref().map_or(0.0, |s| s.parts.iter().filter(|x| x.role == role && x.dormer.as_deref() == Some(id)).map(|x| x.mesh.volume().abs()).sum()) + }; + roof.dormers + .as_deref() + .unwrap_or(&[]) + .iter() + .filter_map(|d| { + let g = crate::dormer::geometry(p, roof, d)?; + let hole = g.hole(); + let n = hole.len(); + let proj = (0..n).map(|i| hole[i][0] * hole[(i + 1) % n][1] - hole[(i + 1) % n][0] * hole[i][1]).sum::().abs() / 2.0; + Some(qty::DormerIn { + width: d.width, + front_height: g.front_height, + opening_area: proj * (1.0 + g.frame.tan_main * g.frame.tan_main).sqrt(), + wall_volume: vol(&d.id, crate::roof_assembly::Role::DormerWall), + roof_volume: vol(&d.id, crate::roof_assembly::Role::DormerRoof), + }) + }) + .collect() +} + fn push_box(positions: &mut Vec, indices: &mut Vec, b: &[f64; 24], base: f64) { let at = (positions.len() / 3) as u32; for c in b.chunks_exact(3) { @@ -766,6 +793,17 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result let bands = bands_by_wall.get(wall.id.as_str()).unwrap_or(&no_bands); let (mut positions, mut indices) = (Vec::::new(), Vec::::new()); for b in bands { + // Ebene Oberkante unter einem Dach ([G2]): Prisma bis an die Dachunterkante. + if b.top_plane.is_some() && b.holes.as_ref().is_none_or(|h| h.is_empty()) { + if let Some(m) = model3d::wall_piece_mesh(b) { + let at = (positions.len() / 3) as u32; + for c in m.positions.chunks_exact(3) { + positions.extend_from_slice(&[c[0], c[1], c[2] - base]); + } + indices.extend(m.indices.iter().map(|i| at + i)); + } + continue; + } let cut = wall_cut_mesh_checked(&CutWall { start: b.start, end: b.end, @@ -1085,7 +1123,16 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result props.extend(crate::u_value::roof_u_value(&p, roof).and_then(|u| u.u).map(|u| Prop::Thermal("ThermalTransmittance", u))); let planes = crate::roof::roof_geometry(&roof.params(), p.roof_base_elevation(roof)).planes; let mut psets = vec![Pset { name: "Pset_RoofCommon", props }]; - psets.extend(qto("Qto_RoofBaseQuantities", qty::roof_quantities(&planes))); + let mut roof_q = qty::roof_quantities(&planes); + // Gauben ([G5]): Ausschnitt im Hauptdach (geneigt) von der Nettofläche ab, eigene Mengen der Gauben. + let dormer_q = p.roofs.as_deref().unwrap_or(&[]).iter().position(|r| r.id == roof.id).map_or_else(Vec::new, |ri| qty::dormer_quantities(&dormer_parts(&p, ri, roof))); + if let Some(cut) = dormer_q.iter().find(|q| q.name == "OpeningArea").map(|q| q.value) { + if let Some(net) = roof_q.iter_mut().find(|q| q.name == "NetArea") { + net.value = max(0.0, net.value - cut); + } + } + psets.extend(qto("Qto_RoofBaseQuantities", roof_q)); + psets.extend(qto("Qto_DossierDormerQuantities", dormer_q)); let ty = roof_type.map(|t| (t.id.clone(), t.name.clone(), t.layers.iter().map(|l| (l.component_id.clone(), component_name(&p, &l.component_id), l.thickness)).collect::>())); let (id, name, pre) = (f.str(&roof.id), f.str(roof_type.map_or("Dach", |t| t.name.as_str())), f.str(predefined)); f.nums(&[REC_ROOF, structure, id, name, pre]); @@ -1253,6 +1300,20 @@ mod tests { assert_eq!(f.nums.iter().filter(|v| **v == REC_OPENING_SOLID).count() >= 2, true); } + /// [G5] Gauben-Mengen: Ausschnitt geneigt, Wand- und Dachvolumen aus den Körpern. + #[test] + fn gauben_mengen() { + let p = crate::dormer::tests::gable_project(); + let roof = &p.roofs.as_ref().unwrap()[0]; + let d = dormer_parts(&p, 0, roof); + assert_eq!(d.len(), 1); + assert!(d[0].opening_area > 2.4 * 1.6 * 2f64.sqrt() && d[0].opening_area < 2.4 * 3.0 * 2f64.sqrt(), "{d:?}"); + assert!(d[0].wall_volume > 0.1 && d[0].roof_volume > 0.1, "{d:?}"); + let q = qty::dormer_quantities(&d); + assert_eq!(q.len(), 5); + assert!(qty::dormer_quantities(&[]).is_empty()); + } + /// [T2] Bogenwand: Datensatz WALL_ARC mit Kreisachse (Mitte, Radius, Startwinkel, Schwenk). #[test] fn bogenwand_als_netz_mit_kreisachse() { diff --git a/src-tauri/core/src/ifc_quantities.rs b/src-tauri/core/src/ifc_quantities.rs index 9aae0071..aabce04b 100644 --- a/src-tauri/core/src/ifc_quantities.rs +++ b/src-tauri/core/src/ifc_quantities.rs @@ -115,9 +115,15 @@ pub fn wall_quantities(start: Vec2, end: Vec2, bands: &[&RWall], cutouts: &[Cuto z_min = min(z_min, b.base_elevation); z_max = max(z_max, b.base_elevation + b.height); let drop = b.top_drop.map_or(0.0, |d| (d[0] + d[1]) / 2.0); - if sloped_band(b) { + if sloped_band(b) || b.top_plane.is_some() { sloped = true; } + if b.top_plane.is_some() { + // Ebene Oberkante unter einem Dach ([G2]): exakt über die Grundfläche. + gross += crate::model3d::wall_piece_volume(b); + tallest = max(tallest, b.height); + continue; + } gross += l * b.thickness * (b.height - drop); tallest = max(tallest, b.height - drop); } @@ -235,6 +241,33 @@ pub fn roof_quantities(planes: &[Vec<[f64; 3]>]) -> Vec { vec![area("GrossArea", sloped), area("NetArea", sloped), area("ProjectedArea", projected)] } +/// Eine Gaube für die Mengen ([G5]). +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct DormerIn { + pub width: f64, + pub front_height: f64, + /// Geneigte Fläche des Ausschnitts im Hauptdach. + pub opening_area: f64, + pub wall_volume: f64, + pub roof_volume: f64, +} + +/// Gauben eines Dachs, summiert: Anzahl als Länge der Breiten (`Width`), grösste Stirnhöhe, Ausschnitt +/// im Hauptdach, Volumen der Gaubenwände und -dächer. Leer ohne Gauben. +pub fn dormer_quantities(d: &[DormerIn]) -> Vec { + if d.is_empty() { + return Vec::new(); + } + let sum = |f: fn(&DormerIn) -> f64| d.iter().map(f).sum::(); + vec![ + len("Width", sum(|x| x.width)), + len("FrontHeight", d.iter().map(|x| x.front_height).fold(0.0, f64::max)), + area("OpeningArea", sum(|x| x.opening_area)), + vol("WallVolume", sum(|x| x.wall_volume)), + vol("RoofVolume", sum(|x| x.roof_volume)), + ] +} + /// Stützen-Basismengen: Länge, Querschnitt, Mantel, Oberfläche und Volumen. pub fn column_quantities(footprint: &[Vec2], length: f64) -> Vec { let cross = ring_area(footprint); @@ -283,6 +316,7 @@ mod tests { height, base_elevation: base, top_drop: None, + top_plane: None, color: [0.5, 0.5, 0.5], layers: vec![], wall_id: "w".into(), diff --git a/src-tauri/core/src/mesh_data.rs b/src-tauri/core/src/mesh_data.rs index cf26aef0..7a6182a5 100644 --- a/src-tauri/core/src/mesh_data.rs +++ b/src-tauri/core/src/mesh_data.rs @@ -127,6 +127,19 @@ const BOX_QUADS: [[usize; 4]; 6] = [[4, 6, 7, 5], [1, 3, 2, 0], [2, 3, 7, 6], [4 /// Voller Wand-Schicht-Quader ohne Öffnungen (lochlose Bänder); entartete Bänder fallen weg. fn push_wall_box(g: &mut Prim, w: &RWall) { + // Ebene Oberkante unter einem Dach ([G2]): Prisma, Modell (x, y, z) → Welt (x, Höhe, y), gespiegelt. + if w.top_plane.is_some() { + if let Some(m) = crate::model3d::wall_piece_mesh(w) { + let base = (g.positions.len() / 3) as f64; + for c in m.positions.chunks_exact(3) { + g.positions.extend_from_slice(&[c[0], c[2], c[1]]); + } + for t in m.indices.chunks_exact(3) { + g.indices.extend_from_slice(&[base + t[0] as f64, base + t[2] as f64, base + t[1] as f64]); + } + } + return; + } let [sx, sy] = w.start; let [ex, ey] = w.end; let dx = ex - sx; diff --git a/src-tauri/core/src/model/generated.rs b/src-tauri/core/src/model/generated.rs index e1d37df0..aa0d949f 100644 --- a/src-tauri/core/src/model/generated.rs +++ b/src-tauri/core/src/model/generated.rs @@ -2212,6 +2212,12 @@ pub struct Wall { #[serde(rename = "sliceTermination", default, skip_serializing_if = "Option::is_none")] #[ts(optional)] pub slice_termination: Option, + /// An Dach anschliessen ([G2]): `undefined` = automatisch (die Wand endet an der Dach-Unterkante, + /// wo ihre Krone darüber liegt — je Schicht, Giebel/Traufe/Grat/Kehle/Gaube), `true` = zusätzlich bis + /// unter das Dach verlängert, `false` = Dächer schneiden die Wand nicht. + #[serde(rename = "roofAttach", default, skip_serializing_if = "Option::is_none")] + #[ts(optional)] + pub roof_attach: Option, /// Ansichtsschraffur ([100]): Drehung (Grad) des Oberflächenmusters dieses Elements gegenüber der /// Ausrichtung am Element (Default 0). #[serde(rename = "surfacePatternAngle", default, skip_serializing_if = "Option::is_none")] diff --git a/src-tauri/core/src/model3d.rs b/src-tauri/core/src/model3d.rs index f94a9d28..fc2d4e92 100644 --- a/src-tauri/core/src/model3d.rs +++ b/src-tauri/core/src/model3d.rs @@ -255,6 +255,10 @@ pub struct RWall { pub base_elevation: f64, #[serde(skip_serializing_if = "Option::is_none")] pub top_drop: Option<[f64; 2]>, + /// Ebene Oberkante unter einer Dachfläche ([G2]): `[z am Anfang (Mittellinie), dz/dx, dz/dy]` + /// (Grundriss-Meter). Übersteuert `topDrop`; `height` ist dann der höchste Eckwert über der UK. + #[serde(skip_serializing_if = "Option::is_none")] + pub top_plane: Option<[f64; 3]>, pub color: Rgb, pub layers: Vec<()>, pub wall_id: String, @@ -525,13 +529,13 @@ fn compute_joins_by_floor(p: &Project) -> Result, Stri Ok(merged) } -fn floor_context(p: &Project, floor_id: &str) -> FloorContext { +fn floor_context(p: &Project, floor_id: &str, with_ceilings: bool) -> FloorContext { let ceilings: Vec = p .ceilings .as_deref() .unwrap_or(&[]) .iter() - .filter(|c| c.floor_id == floor_id && c.outline.len() >= 3) + .filter(|c| with_ceilings && c.floor_id == floor_id && c.outline.len() >= 3) .map(|c| { let (z_bottom, z_top) = p.ceiling_vertical_extent(c); CeilingIn { @@ -552,7 +556,14 @@ fn floor_context(p: &Project, floor_id: &str) -> FloorContext { let eaves_z = p.roof_base_elevation(r); let geo = crate::roof::roof_geometry(&r.params(), eaves_z); let total: f64 = p.roof_layers(r).iter().fold(0.0, |s, l| s + l.thickness.max(0.0)); - RoofIn { eaves_z, total_thickness: total, eaves: geo.eaves, planes: geo.planes } + let mut ri = RoofIn::new(eaves_z, total, geo.eaves, geo.planes); + // Gauben ([G2]): unter dem Gaubeninneren endet die Wand an der Gaubendach-Unterkante. + for d in r.dormers.as_deref().unwrap_or(&[]) { + if let Some(g) = crate::dormer::geometry(p, r, d) { + ri.facets.extend(g.under_facets()); + } + } + ri }) .collect(); FloorContext::new(ceilings, roofs) @@ -571,17 +582,13 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result, String> { let joins = if layered { Some(compute_joins_by_floor(p)?) } else { None }; let maps = wall_material_color_maps(p); let mut contexts: HashMap<&str, FloorContext> = HashMap::new(); - let empty = FloorContext::default(); let mut out = Vec::new(); let by_wall = p.openings_by_wall(); for wall in &p.walls { let (bands, stacked) = resolve_wall_bands(p, &maps, wall, layered); let (z_bottom, z_top) = p.wall_vertical_extent(wall); - let ctx = if layered { - contexts.entry(wall.floor_id.as_str()).or_insert_with(|| floor_context(p, &wall.floor_id)) - } else { - &empty - }; + // Schnitt-Eingabe: nur die Dächer ([G2]); Decken rechnet der Schnitt selbst (Dominanz). + let ctx = contexts.entry(wall.floor_id.as_str()).or_insert_with(|| floor_context(p, &wall.floor_id, layered)); let win = wall_bands::WallIn { start: kv(wall.start), end: kv(wall.end), @@ -599,6 +606,7 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result, String> { bands: bands.iter().map(|b| BandIn { thickness: b.thickness, priority: b.priority }).collect(), openings: wall_openings(p, wall, by_wall.get(wall.id.as_str()).map_or(&[][..], |v| v.as_slice()), true), cuts: if layered { joins.as_ref().and_then(|j| j.get(&wall.id)).cloned().unwrap_or_default() } else { WallCuts::default() }, + roof_attach: wall.roof_attach, reveals: if layered && stacked { wall_reveals(p, wall, by_wall.get(wall.id.as_str()).map_or(&[][..], |v| v.as_slice()), bands.len()) } else { Vec::new() }, }; // Bogenwand ([T2]): Sehnen-Teilwände mit radialen Gehrungen. @@ -618,8 +626,8 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result, String> { let Some(b) = bands.get(piece.band) else { continue }; // Schnitt-Eingabe der Bogen-Teilwände: radiale Gehrungen auch ohne Schichtband-Pfad. if arc.is_some() && !layered { - piece.start_cut = win.cuts.start_cut; - piece.end_cut = win.cuts.end_cut; + piece.start_cut = piece.start_cut.or(win.cuts.start_cut); + piece.end_cut = piece.end_cut.or(win.cuts.end_cut); } out.push(RWall { start: [piece.start.x, piece.start.y], @@ -628,6 +636,7 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result, String> { height: piece.z_top - piece.z_bottom, base_elevation: piece.z_bottom, top_drop: piece.top_drop, + top_plane: piece.top_plane.map(|c| [c[0] + c[1] * piece.start.x + c[2] * piece.start.y, c[1], c[2]]), color: b.color, layers: vec![], wall_id: wall.id.clone(), @@ -637,7 +646,10 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result, String> { cut: band_cut_meta(b), start_cut: piece.start_cut.map(|l| [l.point.x, l.point.y, l.dir.x, l.dir.y]), end_cut: piece.end_cut.map(|l| [l.point.x, l.point.y, l.dir.x, l.dir.y]), - joint: arc.map_or([false; 2], |a| [inner_joint(&a, wall, &keep, piece.start), inner_joint(&a, wall, &keep, piece.end)]), + joint: { + let j = arc.map_or([false; 2], |a| [inner_joint(&a, wall, &keep, piece.start), inner_joint(&a, wall, &keep, piece.end)]); + [j[0] || piece.joint[0], j[1] || piece.joint[1]] + }, }); } } @@ -646,6 +658,68 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result, String> { Ok(out) } +/// Grundriss-Ecken eines Wandkörpers an seinen Schnittlinien: Anfang +n, Ende +n, Ende −n, Anfang −n +/// (+n = linke Normale). `None` bei entarteter Achse. +pub(crate) fn wall_footprint(w: &RWall) -> Option<[[f64; 2]; 4]> { + let (dx, dy) = (w.end[0] - w.start[0], w.end[1] - w.start[1]); + let l = hypot2(dx, dy); + if !(l > 1e-9) || !(w.thickness > 0.0) { + return None; + } + let (ux, uy) = (dx / l, dy / l); + let (nx, ny) = (-uy, ux); + let h = w.thickness / 2.0; + let at = |p: [f64; 2], o: f64, cut: Option<[f64; 4]>| -> [f64; 2] { + let q = [p[0] + nx * o, p[1] + ny * o]; + let Some([cx, cy, ex, ey]) = cut else { return q }; + let den = ux * ey - uy * ex; + if den.abs() < 1e-12 { + return q; + } + let t = ((cx - q[0]) * ey - (cy - q[1]) * ex) / den; + if t.is_finite() && t.abs() < l { + [q[0] + ux * t, q[1] + uy * t] + } else { + q + } + }; + Some([at(w.start, h, w.start_cut), at(w.end, h, w.end_cut), at(w.end, -h, w.end_cut), at(w.start, -h, w.start_cut)]) +} + +/// Oberkante eines Wandkörpers an einem Grundriss-Punkt (ebene Oberkante unter einem Dach, [G2]). +pub(crate) fn wall_top_at(w: &RWall, q: [f64; 2]) -> f64 { + let zt = w.base_elevation + w.height; + match w.top_plane { + Some(c) => (c[0] + c[1] * (q[0] - w.start[0]) + c[2] * (q[1] - w.start[1])).clamp(w.base_elevation, zt), + None => zt, + } +} + +/// Wandkörper mit ebener Oberkante als geschlossenes Netz (Modell x, y, z), ohne Löcher. +pub(crate) fn wall_piece_mesh(w: &RWall) -> Option { + let fp = wall_footprint(w)?; + let zb = w.base_elevation; + let m = crate::solid_bool::Mesh::prism_between(&fp, &|_, _| zb, &|x, y| wall_top_at(w, [x, y])); + (!m.is_empty()).then_some(m) +} + +/// Volumen eines Wandkörpers ohne Löcher: Grundfläche × Höhe im Schwerpunkt (exakt bei ebener Oberkante). +pub(crate) fn wall_piece_volume(w: &RWall) -> f64 { + let Some(q) = wall_footprint(w) else { return 0.0 }; + let (mut a, mut cx, mut cy) = (0.0, 0.0, 0.0); + for i in 0..4 { + let (p0, p1) = (q[i], q[(i + 1) % 4]); + let c = p0[0] * p1[1] - p1[0] * p0[1]; + a += c; + cx += (p0[0] + p1[0]) * c; + cy += (p0[1] + p1[1]) * c; + } + if a.abs() < 1e-15 { + return 0.0; + } + (a / 2.0).abs() * (wall_top_at(w, [cx / (3.0 * a), cy / (3.0 * a)]) - w.base_elevation) +} + // ── Öffnungs-Einbauteile (Glas, Rahmen, Sprossen, Bank, Kasten) ───────────── /// Farbe je Bauteil-Klasse (Index = `Part` in `openings3d.rs`). diff --git a/src-tauri/core/src/plan/elevation.rs b/src-tauri/core/src/plan/elevation.rs index 2f05e2be..f71fde64 100644 --- a/src-tauri/core/src/plan/elevation.rs +++ b/src-tauri/core/src/plan/elevation.rs @@ -73,6 +73,229 @@ struct Face { normal: [f64; 3], } +/// Stirnflächen der Dachscheibe an den freien Rändern der Dachflächen (Traufe, Ortgang): je Rand ein +/// Viereck von der Oberkante senkrecht zur Fläche um die Dicke nach innen (wie die 3D-Schichten). +fn fascia_quads(planes: &[Vec<[f64; 3]>], total: f64) -> Vec<[[f64; 3]; 4]> { + let mut out = Vec::new(); + if !(total > 1e-6) { + return out; + } + let same = |a: [f64; 3], b: [f64; 3]| (a[0] - b[0]).abs() < 1e-6 && (a[1] - b[1]).abs() < 1e-6 && (a[2] - b[2]).abs() < 1e-6; + for (i, pl) in planes.iter().enumerate() { + if pl.len() < 3 { + continue; + } + let n = model3d::plane_normal_up(pl); + if !(n[2] > 1e-3) { + continue; + } + for k in 0..pl.len() { + let (a, b) = (pl[k], pl[(k + 1) % pl.len()]); + let shared = planes.iter().enumerate().any(|(j, o)| j != i && (0..o.len()).any(|m| { let (c, d) = (o[m], o[(m + 1) % o.len()]); (same(a, c) && same(b, d)) || (same(a, d) && same(b, c)) })); + if shared || same(a, b) { + continue; + } + let off = |q: [f64; 3]| [q[0] - n[0] * total, q[1] - n[1] * total, q[2] - n[2] * total]; + out.push([a, b, off(b), off(a)]); + } + } + out +} + +/// Dach-Scheiben für die Verdeckung der Wände darunter ([G2]): je Dachfläche Ober- und Unterkante, +/// dazu die Stirnflächen der Ränder. +struct RoofSheet { + top: Vec, + under: Vec, + fascia: Vec<[[f64; 3]; 4]>, + bounds: [f64; 4], +} + +/// Kreuzt die waagrechte Strecke `a → b` (Grundriss) auf Höhe `z` eine Stirnfläche (im Innern)? +fn crosses_fascia(q: &[[f64; 3]; 4], a: (f64, f64), b: (f64, f64), z: f64) -> bool { + let e1 = [q[1][0] - q[0][0], q[1][1] - q[0][1], q[1][2] - q[0][2]]; + let e2 = [q[3][0] - q[0][0], q[3][1] - q[0][1], q[3][2] - q[0][2]]; + let m = [e1[1] * e2[2] - e1[2] * e2[1], e1[2] * e2[0] - e1[0] * e2[2], e1[0] * e2[1] - e1[1] * e2[0]]; + let side = |x: f64, y: f64| m[0] * (x - q[0][0]) + m[1] * (y - q[0][1]) + m[2] * (z - q[0][2]); + let (s0, s1) = (side(a.0, a.1), side(b.0, b.1)); + if !(s0 * s1 < 0.0) { + return false; + } + let t = s0 / (s0 - s1); + let x = [a.0 + (b.0 - a.0) * t - q[0][0], a.1 + (b.1 - a.1) * t - q[0][1], z - q[0][2]]; + let dot = |u: [f64; 3], v: [f64; 3]| u[0] * v[0] + u[1] * v[1] + u[2] * v[2]; + let (l1, l2) = (dot(e1, e1), dot(e2, e2)); + if !(l1 > 1e-12 && l2 > 1e-12) { + return false; + } + let (al, be) = (dot(x, e1) / l1, dot(x, e2) / l2); + (0.0..=1.0).contains(&al) && be > 1e-6 && be < 1.0 - 1e-6 +} + +impl RoofSheet { + /// Oberkante minus `z` über dem Grundriss-Punkt (`None`: kein Dach), nur wo die Unterkante echt unter + /// `z` liegt oder die Oberkante darunter (Strahl über dem Dach). + fn above(&self, x: f64, y: f64, z: f64) -> Option { + let b = self.bounds; + if x < b[0] || x > b[2] || y < b[1] || y > b[3] { + return None; + } + self.top.iter().zip(&self.under).filter(|(t, _)| t.contains(x, y)).map(|(t, u)| if u.z(x, y) < z - 1e-4 { t.z(x, y) - z } else { -1.0 }).reduce(f64::max) + } +} + +/// Wandflächen unter Dächern ([G2]) gegen die Dachscheiben vor ihnen: Ecken, deren Sichtstrahl (zum +/// Betrachter) durch ein Dach läuft, sind verdeckt. Ganz verdeckte Flächen entfallen (Oberseiten, +/// Laibungen und Stirnen innen unter dem Dach); bei senkrechten Kanten wird die Fläche auf die Höhe +/// gekappt, ab der das Dach sie verdeckt (Traufe vor der Wand). Ersetzt keine HLR ([G4]). +fn cull_under_roofs(p: &Project, frame: &[f64; 9], walls: &[RWall], faces: &mut Vec) { + let affected: std::collections::HashSet<&str> = walls.iter().filter(|w| w.top_plane.is_some() || w.joint != [false; 2]).map(|w| w.wall_id.as_str()).collect(); + if affected.is_empty() { + return; + } + let sheets: Vec = p + .roofs + .as_deref() + .unwrap_or(&[]) + .iter() + .map(|r| { + let g = crate::roof::roof_geometry(&r.params(), p.roof_base_elevation(r)); + let total: f64 = p.roof_layers(r).iter().map(|l| l.thickness.max(0.0)).sum(); + let top = crate::wall_bands::plane_facets(&g.planes, 0.0); + let under = crate::wall_bands::plane_facets(&g.planes, total); + let mut b = [f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY]; + for q in g.planes.iter().flatten() { + b = [b[0].min(q[0]), b[1].min(q[1]), b[2].max(q[0]), b[3].max(q[1])]; + } + // Stirnflächen, die in einem anderen Dach stecken (Kehlen verschnittener Dächer), verdecken nicht. + let others: Vec> = p + .roofs + .as_deref() + .unwrap_or(&[]) + .iter() + .filter(|o| o.id != r.id && o.floor_id == r.floor_id) + .flat_map(|o| crate::roof::roof_geometry(&o.params(), p.roof_base_elevation(o)).planes) + .collect(); + let fascia = fascia_quads(&g.planes, total) + .into_iter() + .filter(|q| !others.iter().any(|o| crate::dormer::point_in_xy((q[0][0] + q[1][0]) / 2.0, (q[0][1] + q[1][1]) / 2.0, o))) + .collect(); + RoofSheet { top, under, fascia, bounds: b } + }) + .filter(|s| s.top.len() == s.under.len() && !s.top.is_empty()) + .collect(); + if sheets.is_empty() { + return; + } + let (o, n, u) = ([frame[0], frame[2]], [frame[3], frame[5]], [frame[6], frame[8]]); + let reach = sheets.iter().map(|s| (s.bounds[2] - s.bounds[0]).max(s.bounds[3] - s.bounds[1])).fold(0.0, f64::max) + 1.0; + // Gaubenstirnen und -wangen als senkrechte Verdecker (lokal u, v; z von der Hauptdach-Unterkante bis + // zum Gaubendach). + let dormers: Vec = p + .roofs + .as_deref() + .unwrap_or(&[]) + .iter() + .flat_map(|r| r.dormers.as_deref().unwrap_or(&[]).iter().filter_map(move |d| crate::dormer::geometry(p, r, d))) + .collect(); + let dormer_hit = |a: (f64, f64), b: (f64, f64), z: f64| -> bool { + dormers.iter().any(|g| { + let (la, lb) = (g.frame.local(a.0, a.1), g.frame.local(b.0, b.1)); + let hw = g.width / 2.0; + let z_ok = |u: f64, v: f64| z >= g.frame.main_top(v) - g.main_thickness * 2.0 && z <= g.under(u, v) + g.roof_vertical(); + // Stirn (v = 0) oder Wange (|u| = hw) gekreuzt. + let front = (la[1] > 0.0) != (lb[1] > 0.0) && la[0].abs() <= hw && z_ok(la[0], 0.0); + let cheek = (la[0].abs() < hw) != (lb[0].abs() < hw) && la[1] >= 0.0 && la[1] <= g.hole_v(la[0]) && z_ok(la[0].clamp(-hw, hw), la[1]); + front || cheek + }) + }; + // Verdeckt: der Strahl zum Betrachter (−n im Grundriss) kreuzt die Dachoberfläche von unten nach + // oben gesehen (erst darunter, näher zum Betrachter darüber) oder eine Gaubenwand. + let hidden = |x: f64, y: f64, z: f64| -> bool { + let steps = ((reach / 0.04).ceil() as usize).min(5000); + let mut under = false; + let mut prev = (x, y); + let at = |t: f64| sheets.iter().filter_map(|s| s.above(x - n[0] * t, y - n[1] * t, z)).reduce(f64::max); + for i in 1..=steps { + let t = i as f64 * 0.04; + let q = (x - n[0] * t, y - n[1] * t); + if dormer_hit(prev, q, z) || sheets.iter().any(|s| s.fascia.iter().any(|f| crosses_fascia(f, prev, q, z))) { + return true; + } + prev = q; + match at(t) { + Some(d) if d >= 0.0 => under = true, + Some(_) if under => return true, + None if under => { + // Aus der Scheibe heraus (Traufkante): Oberkante genau an der Kante unter z? + let (mut lo, mut hi) = (t - 0.04, t); + for _ in 0..30 { + let m = (lo + hi) / 2.0; + if at(m).is_some() { + lo = m; + } else { + hi = m; + } + } + if at(lo).is_some_and(|d| d < -1e-6) { + return true; + } + under = false; + } + _ => {} + } + } + false + }; + faces.retain_mut(|f| { + if f.role != Role::Wall || !affected.contains(f.id.as_str()) || f.pts.len() < 3 { + return true; + } + // Tiefe je Ecke aus der Flächenebene (Normale in Welt x, Höhe, Grundriss-y). + let k = f.normal[0] * n[0] + f.normal[2] * n[1]; + if k.abs() < 1e-9 { + return true; + } + let m = f.pts.len() as f64; + let (cu, cv) = (f.pts.iter().map(|q| q[0]).sum::() / m, f.pts.iter().map(|q| q[1]).sum::() / m); + let nu = f.normal[0] * u[0] + f.normal[2] * u[1]; + let world = |q: Pt| -> (f64, f64, f64) { + let d = f.depth + (nu * (cu - q[0]) + f.normal[1] * (cv - q[1])) / k; + (o[0] + u[0] * q[0] + n[0] * d, o[1] + u[1] * q[0] + n[1] * d, q[1]) + }; + let hid: Vec = f.pts.iter().map(|&q| { + let (x, y, z) = world(q); + hidden(x, y, z - 1e-6) + }).collect(); + if hid.iter().all(|h| *h) { + return false; + } + if !hid.iter().any(|h| *h) { + return true; + } + // Verdeckte Ecke mit sichtbarer Ecke senkrecht darunter: auf die Verdeckungsgrenze senken. + let pts = f.pts.clone(); + for i in 0..pts.len() { + if !hid[i] { + continue; + } + let Some(j) = (0..pts.len()).find(|&j| !hid[j] && (pts[j][0] - pts[i][0]).abs() < 1e-6 && pts[j][1] < pts[i][1]) else { continue }; + let (x, y, _) = world(pts[i]); + let (mut lo, mut hi) = (pts[j][1], pts[i][1]); + for _ in 0..40 { + let mid = (lo + hi) / 2.0; + if hidden(x, y, mid) { + hi = mid; + } else { + lo = mid; + } + } + f.pts[i][1] = lo; + } + true + }); +} + /// `elevationFrame` flach: `[P, N, U]`. fn frame_of(plane: &super::section::Plane) -> [f64; 9] { let [nx, ny, nz] = plane.normal; @@ -97,13 +320,21 @@ struct RoofIn { fn project_faces(frame: &[f64; 9], walls: &[RWall], slabs: &[RSlab], roofs: &[RoofIn]) -> Vec { let mut w = vec![walls.len() as f64]; // Mit Schnittlinien (Bogen-Teilkörper, [T2]): die Ecken liegen auf der Gehrung statt rechtwinklig. - let cut = walls.iter().any(|x| x.start_cut.is_some() || x.end_cut.is_some() || x.joint != [false; 2]); + let planes = walls.iter().any(|x| x.top_plane.is_some()); + let cut = planes || walls.iter().any(|x| x.start_cut.is_some() || x.end_cut.is_some() || x.joint != [false; 2]); for x in walls { w.extend([x.start[0], x.start[1], x.end[0], x.end[1], x.thickness, x.height, x.base_elevation]); if cut { w.extend(corner_shifts(x)); w.extend([if x.joint[0] { 1.0 } else { 0.0 }, if x.joint[1] { 1.0 } else { 0.0 }]); } + // Ebene Oberkante unter einem Dach ([G2]). + if planes { + match x.top_plane { + Some(c) => w.extend([1.0, c[0], c[1], c[2]]), + None => w.extend([0.0; 4]), + } + } } let mut sl = vec![slabs.len() as f64]; for x in slabs { @@ -175,7 +406,10 @@ pub(crate) fn corner_shifts(x: &RWall) -> [f64; 4] { } /// `collectRoofFaces`. -fn collect_roof_faces(p: &Project, frame: &[f64; 9]) -> Result, String> { +fn collect_roof_faces(p: &Project, frame: &[f64; 9], walls: &[RWall]) -> Result, String> { + // Giebeldreiecke nur ohne Wand darunter ([G2]): sonst zeigt die Ansicht die Giebelwand selbst. + let reached: std::collections::HashSet<&str> = walls.iter().filter(|w| w.top_plane.is_some()).map(|w| w.wall_id.as_str()).collect(); + let floors: std::collections::HashSet<&str> = p.walls.iter().filter(|w| reached.contains(w.id.as_str())).map(|w| w.floor_id.as_str()).collect(); let mut roofs = Vec::new(); for (ri, roof) in p.roofs.as_deref().unwrap_or(&[]).iter().enumerate() { let g = crate::roof::roof_geometry(&roof.params(), p.roof_base_elevation(roof)); @@ -209,7 +443,29 @@ fn collect_roof_faces(p: &Project, frame: &[f64; 9]) -> Result, String .collect() }; // Wie die übrigen Dächer: Oberfläche der Eindeckung (Dach + Gaubendächer), dazu die Gaubenwände. - roofs.push(RoofIn { id: roof.id.clone(), fill, planes: crate::roof_assembly::planar_faces(&solids.top, &front(&solids.top)), gables: g.gables.clone() }); + // Wände reichen ans Dach ([G2]): Stirnflächen der Ränder, die nicht in einem anderen Dach stecken. + let gables = if floors.contains(roof.floor_id.as_str()) { + let total: f64 = p.roof_layers(roof).iter().map(|l| l.thickness.max(0.0)).sum(); + let others: Vec> = p + .roofs + .as_deref() + .unwrap_or(&[]) + .iter() + .filter(|o| o.id != roof.id && o.floor_id == roof.floor_id) + .flat_map(|o| crate::roof::roof_geometry(&o.params(), p.roof_base_elevation(o)).planes) + .collect(); + fascia_quads(&g.planes, total) + .into_iter() + .filter(|q| { + let (mx, my) = ((q[0][0] + q[1][0]) / 2.0, (q[0][1] + q[1][1]) / 2.0); + !others.iter().any(|o| crate::dormer::point_in_xy(mx, my, o)) + }) + .map(|q| q.to_vec()) + .collect() + } else { + g.gables.clone() + }; + roofs.push(RoofIn { id: roof.id.clone(), fill, planes: crate::roof_assembly::planar_faces(&solids.top, &front(&solids.top)), gables }); let wall_comp = solids.parts.iter().find(|pt| pt.role == crate::roof_assembly::Role::DormerWall && pt.layer == 0).and_then(|pt| p.component(&pt.component_id)); let wf = wall_comp.map_or([0.85, 0.83, 0.8], |c| hex_to_rgb(&c.color, [0.85, 0.83, 0.8])); let wall_faces = crate::roof_assembly::planar_faces(&solids.walls, &front(&solids.walls)); @@ -218,7 +474,14 @@ fn collect_roof_faces(p: &Project, frame: &[f64; 9]) -> Result, String } continue; } - roofs.push(RoofIn { id: roof.id.clone(), fill, planes: g.planes.clone(), gables: g.gables.clone() }); + // Wände reichen ans Dach: statt der Giebeldreiecke die Stirnflächen der Dachscheibe (Traufe, Ortgang). + let gables = if floors.contains(roof.floor_id.as_str()) { + let total: f64 = p.roof_layers(roof).iter().map(|l| l.thickness.max(0.0)).sum(); + fascia_quads(&g.planes, total).into_iter().map(|q| q.to_vec()).collect() + } else { + g.gables.clone() + }; + roofs.push(RoofIn { id: roof.id.clone(), fill, planes: g.planes.clone(), gables }); } Ok(project_faces(frame, &[], &[], &roofs)) } @@ -263,6 +526,10 @@ fn extend_wall_corners(p: &Project, rwalls: &mut [RWall], u: (f64, f64)) { if let Some(&i) = pieces.iter().find(|&&i| close(rwalls[i].start, w.start)) { let s = rwalls[i].start; rwalls[i].start = [s[0] - ux * e_start, s[1] - uz * e_start]; + // Ebene Oberkante bezieht sich auf den Anfang ([G2]). + if let Some(c) = rwalls[i].top_plane.as_mut() { + c[0] -= (c[1] * ux + c[2] * uz) * e_start; + } } } if e_end > EPS { @@ -740,7 +1007,8 @@ pub fn elevation_primitives(p: &Project, level: &LevelSpec, shadows: bool, mono: slabs.extend(model3d::emit_stairs(p, false)); extend_wall_corners(p, &mut walls, (frame[6], frame[8])); let mut faces = project_faces(&frame, &walls, &slabs, &[]); - faces.extend(collect_roof_faces(p, &frame)?); + cull_under_roofs(p, &frame, &walls, &mut faces); + faces.extend(collect_roof_faces(p, &frame, &walls)?); // Kategorie einer Fläche (erstes Element mit der id, wie `find`). let mut wall_cat: HashMap<&str, &str> = HashMap::new(); @@ -915,7 +1183,7 @@ pub fn elevation_primitives(p: &Project, level: &LevelSpec, shadows: bool, mono: // die Haarfugen zwischen ihnen. let fill = fill_for(f.fill); let seam = is_roof && assembled.contains(f.id.as_str()); - let mut prim = if seam { polygon(pts, &fill, &fill, 0.05, no_hatch()) } else { polygon(pts, &fill, "none", 0.0, no_hatch()) }; + let mut prim = if seam { polygon(pts, &fill, &fill, 0.15, no_hatch()) } else { polygon(pts, &fill, "none", 0.0, no_hatch()) }; if let Primitive::Polygon { greyed: g, wall_id, ceiling_id, roof_id, .. } = &mut prim { *g = Some(greyed(f)); if !f.id.is_empty() { @@ -1336,6 +1604,55 @@ mod tests { serde_json::to_string(&prims).unwrap() } + /// [G2] Wände unter dem Dach: in der Traufansicht verdeckt das Dach Giebel- und Innenwände (keine + /// Wandfläche über der Traufkante), in der Giebelansicht steht die Giebelwand bis unter das Dach. + #[test] + fn waende_unter_dem_dach_in_der_ansicht() { + let p: Project = serde_json::from_value(serde_json::json!({ + "id": "p", "name": "t", "lineStyles": [], "hatches": [], "components": [], "wallTypes": [], "layers": [], "drawings2d": [], "openings": [], + "drawingLevels": [ + {"id": "F", "name": "EG", "kind": "floor", "visible": true, "locked": false, "floorHeight": 3.0, "baseElevation": 0}, + {"id": "s", "name": "S", "kind": "elevation", "visible": true, "locked": false, "linePoints": [{"x": -2, "y": -3}, {"x": 12, "y": -3}], "directionSign": 1}, + {"id": "w", "name": "W", "kind": "elevation", "visible": true, "locked": false, "linePoints": [{"x": -3, "y": 10}, {"x": -3, "y": -2}], "directionSign": 1} + ], + "walls": [ + {"id": "WS", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": 0, "y": 0}, "end": {"x": 10, "y": 0}, "height": 3.5}, + {"id": "WW", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": 0, "y": 8}, "end": {"x": 0, "y": 0}, "height": 9.0}, + {"id": "WI", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": 5, "y": 0}, "end": {"x": 5, "y": 8}, "height": 9.0} + ], + "roofs": [{"id": "R", "type": "roof", "floorId": "F", "categoryCode": "35", + "outline": [{"x": 0, "y": 0}, {"x": 10, "y": 0}, {"x": 10, "y": 8}, {"x": 0, "y": 8}], + "shape": "sattel", "pitchDeg": 45, "overhang": 0.5, "overhangGable": 0.3, "ridgeAxis": "x", "thickness": 0.3}] + })) + .unwrap(); + let view = |id: &str| { + let l = p.drawing_levels.iter().find(|l| l.id == id).unwrap(); + let level = LevelSpec::from_json(&serde_json::to_value(l).unwrap()); + elevation_primitives(&p, &level, false, false, &Visibility::default(), 100.0).unwrap().unwrap().0 + }; + let wall_top = |prims: &[Primitive], id: &str| -> f64 { + prims + .iter() + .filter_map(|q| match q { + Primitive::Polygon { pts, wall_id: Some(w), .. } if w == id => Some(pts.iter().map(|v| v.y).fold(f64::NEG_INFINITY, f64::max)), + _ => None, + }) + .fold(f64::NEG_INFINITY, f64::max) + }; + // Traufe: Oberkante der Dachfläche an der Vorderkante (tiefster Punkt der Dachflächen). + let r = &p.roofs.as_ref().unwrap()[0]; + let eave = crate::roof::roof_geometry(&r.params(), p.roof_base_elevation(r)).planes.iter().flatten().map(|q| q[2]).fold(f64::INFINITY, f64::min); + let s = view("s"); + // Sichtbar bis unter die Traufstirn (Dicke 0.3 senkrecht zur 45°-Fläche: 0.3·cos 45° tiefer). + let fascia = eave - 0.3 * 0.5f64.sqrt(); + assert!(wall_top(&s, "WW") <= fascia + 1e-3 && wall_top(&s, "WI") <= fascia + 1e-3, "{} {} {fascia}", wall_top(&s, "WW"), wall_top(&s, "WI")); + assert!((wall_top(&s, "WS") - fascia).abs() < 1e-3, "Traufwand bis zur Traufstirn sichtbar: {}", wall_top(&s, "WS")); + // Giebel: First-Unterkante = Traufkante 3.0 + 4.5 (bei 45°) − 0.3·√2. + let w = view("w"); + let ridge_under = 7.5 - 0.3 * 2f64.sqrt(); + assert!((wall_top(&w, "WW") - ridge_under).abs() < 1e-6, "{}", wall_top(&w, "WW")); + } + /// [T2] Bogenwand in der Ansicht: keine Facetten-Fugen der Sehnen-Teilkörper, Umriss bleibt. #[test] fn bogenwand_ohne_facettenfugen() { @@ -1400,7 +1717,14 @@ mod tests { assert!(o1.len() == 2 && o1.iter().all(|n| *n >= 40), "Rahmen + Glas als Ellipse: {o1:?}"); assert_eq!(polys("DF"), vec![4, 4], "Dachfenster: Rahmen + Glas"); let first_df = prims.iter().position(|pr| matches!(pr, Primitive::Polygon { opening_id: Some(o), .. } if o == "DF")).unwrap(); - let last_roof = prims.iter().rposition(|pr| matches!(pr, Primitive::Polygon { roof_id: Some(_), .. })).unwrap(); + // Dachflächen, die das Dachfenster überdecken (die Traufstirn [G2] liegt davor, berührt es nicht). + let bb = |pts: &[Vec2]| pts.iter().fold([f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY], |b, q| [b[0].min(q.x), b[1].min(q.y), b[2].max(q.x), b[3].max(q.y)]); + let Primitive::Polygon { pts: df_pts, .. } = &prims[first_df] else { unreachable!() }; + let d = bb(df_pts); + let last_roof = prims + .iter() + .rposition(|pr| matches!(pr, Primitive::Polygon { roof_id: Some(_), pts, .. } if { let r = bb(pts); r[0] < d[2] && r[2] > d[0] && r[1] < d[3] && r[3] > d[1] })) + .unwrap(); assert!(first_df > last_roof, "Dachfenster vor der Dachfläche gezeichnet"); } diff --git a/src-tauri/core/src/plan/section.rs b/src-tauri/core/src/plan/section.rs index fe9e096f..952b868e 100644 --- a/src-tauri/core/src/plan/section.rs +++ b/src-tauri/core/src/plan/section.rs @@ -324,6 +324,7 @@ fn wall_input(w: &RWall) -> render3d::WallInput { height: json_f32(w.height), base_elevation: json_f32(w.base_elevation), top_drop: w.top_drop.map_or([0.0, 0.0], f32s2), + top_plane: w.top_plane.map(f32s3), color: f32s3(w.color), openings: Vec::new(), layers: Some(Vec::new()), @@ -3010,3 +3011,84 @@ mod abzug_faelle { assert_eq!(out[0].nse.as_ref().map(|n| n.len()), Some(2), "Schlüsselloch-Stege ungestrichen"); } } + +/// [G2] Wand an Dach: Schnitt und 3D-Körper der Wände unter einem Satteldach. +#[cfg(test)] +mod wand_an_dach { + use super::*; + + fn haus() -> Project { + serde_json::from_value(serde_json::json!({ + "id": "p", "name": "t", "lineStyles": [], "hatches": [], "components": [], "wallTypes": [], "layers": [], "drawings2d": [], + "drawingLevels": [ + {"id": "F", "name": "EG", "kind": "floor", "visible": true, "locked": false, "floorHeight": 3.0, "baseElevation": 0}, + {"id": "q", "name": "Q", "kind": "section", "visible": true, "locked": false, "linePoints": [{"x": 2, "y": -2}, {"x": 2, "y": 10}], "directionSign": 1}, + {"id": "l", "name": "L", "kind": "section", "visible": true, "locked": false, "linePoints": [{"x": -2, "y": 4}, {"x": 12, "y": 4}], "directionSign": 1} + ], + "walls": [ + {"id": "WS", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": 0, "y": 0}, "end": {"x": 10, "y": 0}, "height": 3.5}, + {"id": "WW", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": 0, "y": 8}, "end": {"x": 0, "y": 0}, "height": 9.0}, + {"id": "WB", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": 6, "y": 1}, "end": {"x": 6, "y": 7}, "height": 9.0, "bulge": 0.4} + ], + "openings": [{"id": "F1", "type": "opening", "hostWallId": "WW", "categoryCode": "21", "kind": "window", "position": 3.5, "width": 1.0, "height": 1.2, "sillHeight": 3.6}], + "roofs": [{"id": "R", "type": "roof", "floorId": "F", "categoryCode": "35", + "outline": [{"x": 0, "y": 0}, {"x": 10, "y": 0}, {"x": 10, "y": 8}, {"x": 0, "y": 8}], + "shape": "sattel", "pitchDeg": 45, "overhang": 0.5, "ridgeAxis": "x", "thickness": 0.3}] + })) + .unwrap() + } + + /// Dach-Unterkante (Traufkante 3.0 bei y = −0.5, 45°, Dicke 0.3 senkrecht). + fn under(y: f64) -> f64 { + 3.0 + (4.5 - (y - 4.0).abs()) - 0.3 * 2f64.sqrt() + } + + #[test] + fn schnitt_endet_an_der_dachunterkante() { + let p = haus(); + for id in ["q", "l"] { + let l = p.drawing_levels.iter().find(|l| l.id == id).unwrap(); + let level = LevelSpec::from_json(&serde_json::to_value(l).unwrap()); + let out = compute_section(&p, &level, &[]).unwrap().unwrap(); + let walls: Vec<&Cut> = out.cuts.iter().filter(|c| c.kind == Kind::Wall).collect(); + assert!(!walls.is_empty()); + let top = walls.iter().flat_map(|c| c.pts.iter().map(|q| q[1])).fold(f64::NEG_INFINITY, f64::max); + // Nie über der First-Unterkante. + assert!(top <= under(4.0) + 1e-4, "{id}: {top}"); + } + // Querschnitt quer zum First: Traufwand mit schräger Krone. + let l = p.drawing_levels.iter().find(|l| l.id == "q").unwrap(); + let out = compute_section(&p, &LevelSpec::from_json(&serde_json::to_value(l).unwrap()), &[]).unwrap().unwrap(); + let sloped = out.cuts.iter().filter(|c| c.kind == Kind::Wall).any(|c| { + let ys: Vec = c.pts.iter().map(|q| q[1]).filter(|v| *v > 2.0).collect(); + ys.len() >= 2 && (ys.iter().copied().fold(f64::NEG_INFINITY, f64::max) - ys.iter().copied().fold(f64::INFINITY, f64::min)) > 0.1 + }); + assert!(sloped, "Traufwand im Querschnitt mit schräger Krone"); + } + + #[test] + fn koerper_dicht_und_volumen_exakt() { + let p = haus(); + let walls = model3d::emit_walls(&p, true).unwrap(); + let ww: Vec<&RWall> = walls.iter().filter(|w| w.wall_id == "WW").collect(); + let mut vol = 0.0; + for w in walls.iter().filter(|w| w.top_plane.is_some()) { + let m = model3d::wall_piece_mesh(w).unwrap(); + assert!(m.is_closed(), "{w:?}"); + assert!((m.volume().abs() - model3d::wall_piece_volume(w)).abs() < 1e-9); + } + for w in &ww { + assert!(w.holes.as_ref().is_none_or(|h| h.is_empty()), "Fenster unter dem Dach als Teilkörper: {w:?}"); + vol += model3d::wall_piece_volume(w); + } + // Giebelwand: Fünfeck unter der Unterkante × Dicke, minus Fenster. + let t = p.wall_thickness(&p.walls[1], 0.2); + let area = |y0: f64, y1: f64| (y1 - y0) * (under(y0) + under(y1)) / 2.0; + let expect = t * (area(0.0, 4.0) + area(4.0, 8.0) - 1.2); + // Gehrungen an den Ecken ändern das Volumen nur an den Enden. + assert!((vol - expect).abs() < t * t * 7.0, "{vol} vs {expect}"); + // Bogenwand ([T2]): Sehnen-Teilwände ebenfalls unter dem Dach. + let wb: Vec<&RWall> = walls.iter().filter(|w| w.wall_id == "WB").collect(); + assert!(wb.len() > 4 && wb.iter().all(|w| w.base_elevation + w.height <= under(4.0) + 1e-6), "{}", wb.len()); + } +} diff --git a/src-tauri/core/src/plan_elevation.rs b/src-tauri/core/src/plan_elevation.rs index 4a348f5e..20fc0535 100644 --- a/src-tauri/core/src/plan_elevation.rs +++ b/src-tauri/core/src/plan_elevation.rs @@ -544,8 +544,22 @@ fn wall_faces(f: &Frame, w: &[f64], src: usize, out: &mut Vec) { let ht = w[4] / 2.0; let zb = w[6]; let zt = w[6] + w[5]; + // Ebene Oberkante unter einem Dach ([G2]): Deckel-Ecken auf der Ebene. + let plane = (w.len() >= 17 && w[13] == 1.0).then(|| [w[14], w[15], w[16]]); let corner = |s_along: f64, t_off: f64, y: f64| -> V3 { - [sx + a_hat[0] * s_along + n_hat[0] * t_off, y, sz + a_hat[2] * s_along + n_hat[2] * t_off] + let (x, z) = (sx + a_hat[0] * s_along + n_hat[0] * t_off, sz + a_hat[2] * s_along + n_hat[2] * t_off); + let y = match plane { + Some(c) if y == zt => (c[0] + c[1] * (x - sx) + c[2] * (z - sz)).clamp(zb, zt), + _ => y, + }; + [x, y, z] + }; + let top_n: V3 = match plane { + Some(c) => { + let l = (c[1] * c[1] + 1.0 + c[2] * c[2]).sqrt(); + [-c[1] / l, 1.0 / l, -c[2] / l] + } + None => [0.0, 1.0, 0.0], }; // Schnitt-Verschiebungen der vier Ecken längs der Achse ([T2]: Gehrung der Bogen-Teilkörper): // Anfang +n, Anfang −n, Ende +n, Ende −n; ohne Angabe 0 (rechtwinklig wie bisher). @@ -574,7 +588,7 @@ fn wall_faces(f: &Frame, w: &[f64], src: usize, out: &mut Vec) { (neg(n_hat), [corner(s_m, -ht, zb), corner(s_m, -ht, zt), corner(e_m, -ht, zt), corner(e_m, -ht, zb)]), (start_n, [corner(s_m, -ht, zb), corner(s_p, ht, zb), corner(s_p, ht, zt), corner(s_m, -ht, zt)]), (end_n, [corner(e_m, -ht, zb), corner(e_m, -ht, zt), corner(e_p, ht, zt), corner(e_p, ht, zb)]), - ([0.0, 1.0, 0.0], [corner(s_m, -ht, zt), corner(s_p, ht, zt), corner(e_p, ht, zt), corner(e_m, -ht, zt)]), + (top_n, [corner(s_m, -ht, zt), corner(s_p, ht, zt), corner(e_p, ht, zt), corner(e_m, -ht, zt)]), ([0.0, -1.0, 0.0], [corner(s_m, -ht, zb), corner(e_m, -ht, zb), corner(e_p, ht, zb), corner(s_p, ht, zb)]), ]; for (i, (normal, poly)) in faces.into_iter().enumerate() { @@ -715,6 +729,9 @@ pub fn faces(frame: &[f64], walls: &[f64], slabs: &[f64], roofs: &[f64]) -> Vec< 7 } else if walls.len() == 1 + 13 * nw { 13 + } else if walls.len() == 1 + 17 * nw { + // + ebene Oberkante ([G2]): Kennung (1 = vorhanden), z am Anfang, dz/dx, dz/dy. + 17 } else { return Vec::new(); }; diff --git a/src-tauri/core/src/roof_assembly.rs b/src-tauri/core/src/roof_assembly.rs index d334784f..02308cea 100644 --- a/src-tauri/core/src/roof_assembly.rs +++ b/src-tauri/core/src/roof_assembly.rs @@ -826,7 +826,7 @@ mod tests { #[test] fn planar_faces_keep_area() { let mut r = sattel("R", [[0.0, 0.0], [10.0, 8.0]], "x"); - r["dormers"] = serde_json::json!([{"id": "D", "kind": "sattel", "position": {"x": 4.0, "y": 1.2}, "width": 2.4, "frontHeight": 1.3}]); + r["dormers"] = serde_json::json!([{"id": "D", "kind": "sattel", "position": {"x": 4.0, "y": 1.2}, "width": 2.4, "frontHeight": 1.0}]); let p = base_project(serde_json::json!([r])); let s = roof_solids(&p, 0).unwrap(); let all: Vec = (0..s.skin.indices.len() / 3).collect(); @@ -844,7 +844,8 @@ mod tests { let faces = planar_faces(&s.skin, &all); let face_area: f64 = faces.iter().map(|f| area3(f)).sum(); assert!((tri_area - face_area).abs() < 1e-6 * tri_area, "{tri_area} vs {face_area}"); - assert!(faces.len() * 2 < all.len(), "zusammengefasst: {} Flächen aus {} Dreiecken", faces.len(), all.len()); + // Gaubendach endet am First ([G5]): ein paar Dreiecke mehr im Hauptdach-Querschnitt. + assert!(faces.len() * 3 < all.len() * 2, "zusammengefasst: {} Flächen aus {} Dreiecken", faces.len(), all.len()); } #[test] diff --git a/src-tauri/core/src/selection_info.rs b/src-tauri/core/src/selection_info.rs index 08f2b703..bb9734f6 100644 --- a/src-tauri/core/src/selection_info.rs +++ b/src-tauri/core/src/selection_info.rs @@ -488,6 +488,8 @@ fn wall_selection(root: &Map, w: &Value) -> Result { .raw("referenceOffset", w, "referenceOffset") .v("layerBoundaries", J::arr(boundaries)) .v("sliceTermination", nn(field(w, "sliceTermination")).cloned().unwrap_or_else(|| "both".into())) + // An Dach anschliessen ([G2]): fehlt = automatisch. + .v("roofAttach", Value::String(match field(w, "roofAttach").and_then(|v| v.as_bool()) { Some(true) => "on", Some(false) => "off", None => "auto" }.into())) .raw("wallTypeId", w, "wallTypeId") .n("thickness", thickness) .v("singleLayer", Value::Bool(layers.len() <= 1)) diff --git a/src-tauri/core/src/wall_bands.rs b/src-tauri/core/src/wall_bands.rs index b83f01a8..198fdd6d 100644 --- a/src-tauri/core/src/wall_bands.rs +++ b/src-tauri/core/src/wall_bands.rs @@ -9,13 +9,13 @@ //! als Löcher) und Schnitt-Eingabe (Pfeiler/Brüstung/Sturz-Segmente ohne Löcher). use crate::joins::{js_hypot, reference_offset, Line, Reference, WallCuts}; -use crate::roof::roof_underside_at; use kernel2d::{add, dot, left_normal, line_intersect, point_in_outline, scale, sub, Vec2}; /// Toleranz der Wand-Ableitung (`EPS` in `toWalls3d/shared.ts`). pub const EPS: f64 = 1e-4; -/// Schrittweite (Meter) der Dach-Unterkanten-Abtastung. -const ROOF_CLIP_STEP: f64 = 0.15; +/// Schrittweite (Meter) der Dach-Unterkanten-Abtastung (Wechsel der Dachfläche suchen; die Grenzen +/// selbst sind exakt). +const ROOF_SAMPLE: f64 = 0.05; /// Ein Schicht-Band: Dicke und Verschneidungs-Rang (`None`: keine Decken-Subtraktion). #[derive(Clone, Copy, Debug, PartialEq)] @@ -65,13 +65,96 @@ pub struct CeilingIn { pub layers: Option)>>, } -/// Ein Dach desselben Geschosses: Traufhöhe, Summe der Schichtdicken, Traufe-Umriss, Flächen. +/// Ein Dach desselben Geschosses: Traufhöhe, Summe der Schichtdicken, Traufe-Umriss, Flächen und +/// die Unterkanten-Facetten ([G2]), an denen Wände enden. #[derive(Clone, Debug, PartialEq)] pub struct RoofIn { pub eaves_z: f64, pub total_thickness: f64, pub eaves: Vec<[f64; 2]>, pub planes: Vec>, + pub facets: Vec, +} + +impl RoofIn { + /// Facetten aus den Dachflächen (Schichten senkrecht zur Fläche, Summe `total`). + pub fn new(eaves_z: f64, total: f64, eaves: Vec<[f64; 2]>, planes: Vec>) -> Self { + let facets = plane_facets(&planes, total); + RoofIn { eaves_z, total_thickness: total, eaves, planes, facets } + } +} + +/// Ebene Unterkante eines Dachteils über dem Grundriss-Bereich `ring`: `z = c + gx·x + gy·y`. Wo sich +/// Facetten überdecken (Kehlen verschnittener Dächer, Gaube über dem Hauptdach), gilt die obere Hülle. +#[derive(Clone, Debug, PartialEq)] +pub struct RoofFacet { + pub ring: Vec<[f64; 2]>, + pub plane: [f64; 3], + bounds: [f64; 4], +} + +impl RoofFacet { + /// `None` bei weniger als drei Ecken oder nicht endlichen Werten. + pub fn new(ring: Vec<[f64; 2]>, plane: [f64; 3]) -> Option { + if ring.len() < 3 || !plane.iter().all(|v| v.is_finite()) || !ring.iter().all(|q| q[0].is_finite() && q[1].is_finite()) { + return None; + } + let b = outline_bounds(ring.iter().map(|q| (q[0], q[1]))); + Some(RoofFacet { ring, plane, bounds: [b.min_x, b.min_y, b.max_x, b.max_y] }) + } + pub(crate) fn z(&self, x: f64, y: f64) -> f64 { + self.plane[0] + self.plane[1] * x + self.plane[2] * y + } + pub(crate) fn contains(&self, x: f64, y: f64) -> bool { + let b = self.bounds; + if x < b[0] || x > b[2] || y < b[1] || y > b[3] { + return false; + } + let mut inside = false; + let n = self.ring.len(); + let mut j = n - 1; + for i in 0..n { + let (a, c) = (self.ring[i], self.ring[j]); + if (a[1] > y) != (c[1] > y) && x < (c[0] - a[0]) * (y - a[1]) / (c[1] - a[1]) + a[0] { + inside = !inside; + } + j = i; + } + inside + } + /// Höchster Wert über den Ecken. + fn z_max(&self) -> f64 { + self.ring.iter().map(|q| self.z(q[0], q[1])).fold(f64::NEG_INFINITY, f64::max) + } +} + +/// Unterkanten-Facetten der Dachflächen: Oberfläche um `total` senkrecht zur Fläche gesenkt (wie die +/// 3D-Schichten); senkrechte Flächen entfallen. +pub fn plane_facets(planes: &[Vec<[f64; 3]>], total: f64) -> Vec { + let t = if total.is_finite() { total.max(0.0) } else { 0.0 }; + let mut out = Vec::new(); + for pts in planes { + if pts.len() < 3 { + continue; + } + let (mut a, mut b, mut c) = (0.0, 0.0, 0.0); + for i in 0..pts.len() { + let (p, q) = (pts[i], pts[(i + 1) % pts.len()]); + a += (p[1] - q[1]) * (p[2] + q[2]); + b += (p[2] - q[2]) * (p[0] + q[0]); + c += (p[0] - q[0]) * (p[1] + q[1]); + } + let len = (a * a + b * b + c * c).sqrt(); + if !(len > 1e-12) || c.abs() < 1e-6 * len { + continue; // senkrecht oder entartet + } + let (gx, gy) = (-a / c, -b / c); + let c0 = pts[0][2] - gx * pts[0][0] - gy * pts[0][1] - t * len / c.abs(); + if let Some(f) = RoofFacet::new(pts.iter().map(|q| [q[0], q[1]]).collect(), [c0, gx, gy]) { + out.push(f); + } + } + out } /// Terminierung am Deckenanschluss (`Wall.sliceTermination`). @@ -102,6 +185,10 @@ pub struct WallIn { pub cuts: WallCuts, /// Schichteinzug ([106]); leer = alle Schichten bündig. pub reveals: Vec, + /// An Dach anschliessen ([G2], `Wall.roofAttach`): `None` = automatisch (Wand endet an der + /// Dach-Unterkante, wo ihre Krone darüber liegt), `Some(true)` = zusätzlich bis unter das Dach + /// verlängert, `Some(false)` = Dächer schneiden die Wand nicht. + pub roof_attach: Option, } /// Decken und Dächer eines Geschosses — einmal je Geschoss gelesen, für alle seine Wände; die @@ -125,7 +212,7 @@ impl FloorContext { roofs: roofs .into_iter() .map(|r| { - let b = outline_bounds(r.eaves.iter().map(|p| (p[0], p[1]))); + let b = outline_bounds(r.eaves.iter().map(|p| (p[0], p[1])).chain(r.facets.iter().flat_map(|f| f.ring.iter().map(|q| (q[0], q[1]))))); (r, b) }) .collect(), @@ -149,8 +236,15 @@ pub struct Piece { /// beginnt/endet dort, wo die Band-Mittellinie sie trifft. `None`: rechtwinklig. pub start_cut: Option, pub end_cut: Option, - /// Eigene Dicke (Schichteinzug-Stück, [106]); `None` = Banddicke. + /// Eigene Dicke (Schichteinzug-Stück, [106]; seitlich geteiltes Band unter einem Dach, [G2]); + /// `None` = Banddicke. pub thickness: Option, + /// Ebene Oberkante unter einer Dachfläche ([G2]): `z = c + gx·x + gy·y` (Welt); `None` = waagrecht + /// auf `z_top`. `z_top` ist dann der höchste Eckwert, `top_drop` die Absenkung auf der Mittellinie. + pub top_plane: Option<[f64; 3]>, + /// Anfang/Ende liegt an einer inneren Stossfuge (Teilung an Dachkanten oder Öffnungen unter einem + /// Dach): dort keine sichtbare Stirnfläche (Ansicht). + pub joint: [bool; 2], } #[derive(Clone, Copy, Debug)] @@ -475,94 +569,337 @@ impl Emitter<'_> { start_cut: None, end_cut: None, thickness: None, + top_plane: None, + joint: [false; 2], }); } } -/// Oberkante des Bands unter den Dächern: Dach-Unterkante entlang der Achse abtasten, zu geraden -/// Stücken (Toleranz 2 mm) zusammenfassen, Knicke exakt als Schnitt der Nachbargeraden; je Stück -/// ein Körper mit schräger Oberkante. Ohne Dach darüber: ein Körper, unverändert. -#[allow(clippy::too_many_arguments)] -fn clip_to_roofs(w: &WallIn, ctx: &FloorContext, u: Vec2, n: Vec2, offset: f64, a: f64, bb: f64, zb: f64, zt: f64, emit: &mut dyn FnMut(f64, f64, f64, f64, f64)) { - if zt - zb <= EPS || bb - a <= EPS { - return; - } - let wb = wall_bounds(w, offset.abs() + 0.01); - let roofs: Vec<&RoofIn> = ctx.roofs.iter().filter(|(r, rb)| r.eaves_z + 50.0 >= zb && bounds_overlap(wb, *rb)).map(|(r, _)| r).collect(); - if roofs.is_empty() { - emit(a, bb, zb, zt, zt); - return; - } - let span = bb - a; - let count = 1usize.max((span / ROOF_CLIP_STEP).ceil() as usize); - let top_at = |t: f64| { - let tt = (bb - 1e-3).min((a + 1e-3).max(t)); - let p = add(add(w.start, scale(u, tt)), scale(n, offset)); - let mut clip = zt; - for r in &roofs { - if let Some(under) = roof_underside_at(&r.planes, r.total_thickness, p.x, p.y) { - if under < clip { - clip = under; +// ── Wand an Dach ([G2]) ─────────────────────────────────────────────────────── +// +// Die Oberkante eines Bands ist `clamp(U, zb, zt)` mit U = obere Hülle der Dach-Unterkanten-Facetten +// über dem Punkt (stückweise eben). Das Band wird an den Grenzen der Bereiche geteilt — längs der +// Achse mit der exakten Grenzlinie als Schnittlinie (First, Grat, Kehle, Höhenlinie U = zt bzw. zb), +// quer über die Dicke (seitlich), wo eine Grenze längs durch das Band läuft (Traufwand, deren Krone die +// Dachfläche schneidet). Jedes Stück bekommt eine ebene Oberkante: exakt je Schicht, an jeder Ecke. + +/// Bereich der Oberkante an einem Punkt. +#[derive(Clone, Copy, Debug, PartialEq)] +enum Fac { + /// Kein Dach darüber: Wandkrone. + Free, + /// Unter dem Dach, Unterkante über der (verlängerten) Krone: waagrecht auf der Krone. + Cap, + /// Unterkante unter dem Fuss: kein Körper. + Floor, + /// Unterkante der Facette `k`. + Roof(usize), +} + +struct Tops<'a> { + facets: Vec<&'a RoofFacet>, + zb: f64, + zt_free: f64, + zt_cap: f64, +} + +impl Tops<'_> { + fn at(&self, p: Vec2) -> Fac { + let mut best: Option<(f64, usize)> = None; + for (k, f) in self.facets.iter().enumerate() { + if f.contains(p.x, p.y) { + let z = f.z(p.x, p.y); + if best.is_none_or(|b| z > b.0) { + best = Some((z, k)); } } } - zb.max(clip) - }; - let mut ts = Vec::with_capacity(count + 1); - let mut tops = Vec::with_capacity(count + 1); - for i in 0..=count { - ts.push(a + (span * i as f64) / count as f64); - tops.push(top_at(ts[i])); - } - const TOL: f64 = 0.002; - let mut runs: Vec<(usize, usize)> = Vec::new(); - let mut i0 = 0; - while i0 < count { - let mut i1 = i0 + 1; - while i1 < count { - let k = i1 + 1; - let slope = (tops[k] - tops[i0]) / (ts[k] - ts[i0]); - let ok = (i0 + 1..=k).all(|m| (tops[i0] + slope * (ts[m] - ts[i0]) - tops[m]).abs() <= TOL); - if !ok { - break; + match best { + None => Fac::Free, + Some((z, _)) if z >= self.zt_cap - 1e-9 => { + if self.zt_cap == self.zt_free { + Fac::Free + } else { + Fac::Cap + } } - i1 = k; + Some((z, _)) if z <= self.zb + 1e-9 => Fac::Floor, + Some((_, k)) => Fac::Roof(k), } - runs.push((i0, i1)); - i0 = i1; } - let line = |r: (usize, usize)| { - let m = (tops[r.1] - tops[r.0]) / (ts[r.1] - ts[r.0]); - (m, tops[r.0] - m * ts[r.0]) + fn coef(&self, f: Fac) -> [f64; 3] { + match f { + Fac::Free => [self.zt_free, 0.0, 0.0], + Fac::Cap => [self.zt_cap, 0.0, 0.0], + Fac::Floor => [self.zb, 0.0, 0.0], + Fac::Roof(k) => self.facets[k].plane, + } + } +} + +/// Ein Stück der Band-Oberkante: Achsmass `[a, b]` auf seiner Mittellinie (Versatz `off`, Dicke `th`), +/// Schnittlinien, Höhe (`top` = höchster Eckwert) und Ebene. +#[derive(Clone, Debug)] +struct TopPiece { + a: f64, + b: f64, + cut_a: Option, + cut_b: Option, + off: f64, + th: f64, + top: f64, + plane: Option<[f64; 3]>, + joint: [bool; 2], +} + +/// Dächer, die eine Wand im Höhenbereich `[zb, zt]` betreffen; `None` = keine (unverändert). +fn roof_tops_ctx<'a>(w: &WallIn, ctx: &'a FloorContext, zb: f64, zt: f64) -> Option> { + if w.roof_attach == Some(false) || ctx.roofs.is_empty() { + return None; + } + let wb = wall_bounds(w, w.thickness_safe.max(0.0) + 0.01); + let facets: Vec<&RoofFacet> = ctx + .roofs + .iter() + .filter(|(r, rb)| r.eaves_z + 50.0 >= zb && bounds_overlap(wb, *rb)) + .flat_map(|(r, _)| r.facets.iter()) + .filter(|f| bounds_overlap(wb, Bounds { min_x: f.bounds[0], min_y: f.bounds[1], max_x: f.bounds[2], max_y: f.bounds[3] })) + .collect(); + if facets.is_empty() { + return None; + } + // Verlängern nur, wo der Höhenbereich bis zur Wandkrone reicht (nicht unter einer Decke). + let zt_cap = if w.roof_attach == Some(true) && (zt - w.z_top).abs() < EPS { facets.iter().map(|f| f.z_max()).fold(zt, f64::max) } else { zt }; + Some(Tops { facets, zb, zt_free: zt, zt_cap }) +} + +/// Ecken der Grundfläche eines Bandstücks (aussen +n, innen −n) an den Schnittlinien. +#[allow(clippy::too_many_arguments)] +fn strip_corners(w: &WallIn, u: Vec2, n: Vec2, off: f64, th: f64, a: f64, b: f64, cut_a: Option, cut_b: Option) -> [Vec2; 4] { + let base = add(w.start, scale(n, off)); + let at = |s: f64, o: f64, cut: Option| { + let q = add(add(base, scale(u, s)), scale(n, o)); + cut.and_then(|c| line_intersect(q, u, c.point, c.dir)).filter(|r| r.x.is_finite() && r.y.is_finite()).unwrap_or(q) }; - let mut cuts = vec![a]; - for r in 0..runs.len().saturating_sub(1) { - let l1 = line(runs[r]); - let l2 = line(runs[r + 1]); - let lo = ts[runs[r].1 - 1]; - let hi = ts[count.min(runs[r].1 + 1)]; - let mut x = ts[runs[r].1]; - if (l1.0 - l2.0).abs() > 1e-9 { - let cx = (l2.1 - l1.1) / (l1.0 - l2.0); - if cx >= lo && cx <= hi { - x = cx; - } - } - cuts.push(x); + let h = th / 2.0; + [at(a, h, cut_a), at(b, h, cut_b), at(b, -h, cut_b), at(a, -h, cut_a)] +} + +/// Oberkante eines Bandstreifens `[a, b]` (Mittellinie `off`, Dicke `th`) unter den Dächern `t`. +#[allow(clippy::too_many_arguments)] +fn strip_tops(w: &WallIn, t: &Tops, u: Vec2, n: Vec2, off: f64, th: f64, a: f64, b: f64, cut_a: Option, cut_b: Option, joint: [bool; 2], depth: u32, out: &mut Vec) { + if !(b - a > EPS) || !(th > 0.0) { + return; } - cuts.push(bb); - for (k, &r) in runs.iter().enumerate() { - let (sa, sb) = (cuts[k], cuts[k + 1]); - if sb - sa <= EPS { + let base = add(w.start, scale(n, off)); + let pt = |s: f64| add(base, scale(u, s)); + let steps = 8usize.max(((b - a) / ROOF_SAMPLE).ceil() as usize).min(20_000); + let ts: Vec = (0..=steps).map(|i| if i == steps { b } else { a + (b - a) * i as f64 / steps as f64 }).collect(); + let inner = |s: f64| s.clamp(a + 1e-6, b - 1e-6); + let fac: Vec = ts.iter().map(|&s| t.at(pt(inner(s)))).collect(); + // Läufe gleicher Bereiche und die Grenzen dazwischen (Achsmass, Schnittlinie). + let mut runs: Vec<(Fac, f64, Option)> = vec![(fac[0], a, cut_a)]; + for i in 1..=steps { + let last = runs.last().map_or(fac[0], |r| r.0); + if fac[i] == last { continue; } - let value_at = |x: f64| { - let l = line(r); - zt.min(zb.max(l.0 * x + l.1)) + let (fa, fb) = (fac[i - 1], fac[i]); + // Wechselstelle auf der Mittellinie (Bisektion), dann die exakte Grenzlinie beider Ebenen. + let (mut lo, mut hi) = (ts[i - 1], ts[i]); + for _ in 0..50 { + let mid = (lo + hi) / 2.0; + if t.at(pt(inner(mid))) == fa { + lo = mid; + } else { + hi = mid; + } + } + let sm = (lo + hi) / 2.0; + let p = pt(sm); + let (ca, cb) = (t.coef(fa), t.coef(fb)); + let d = [ca[0] - cb[0], ca[1] - cb[1], ca[2] - cb[2]]; + let g = js_hypot(d[1], d[2]); + let mut line = None; + if g > 1e-9 { + let dist = (d[0] + d[1] * p.x + d[2] * p.y) / g; + let dir = Vec2::new(-d[2] / g, d[1] / g); + // Nur, wenn die Grenze wirklich hier liegt (sonst Sprung, z. B. Traufe) und quer genug steht. + if dist.abs() < 0.02 && (dir.x * u.y - dir.y * u.x).abs() > 0.17 { + line = Some(Line { point: Vec2::new(p.x - d[1] / g * dist, p.y - d[2] / g * dist), dir }); + } + } + let prev = runs.last().map_or(a, |r| r.1); + let s_cut = line.and_then(|l| band_cut_distance(w, u, n, off, &l)).filter(|x| x.is_finite()).unwrap_or(sm).clamp(prev, b); + runs.push((fb, s_cut, line)); + } + let k_last = runs.len() - 1; + for k in 0..runs.len() { + let (f, s0, c0) = runs[k]; + let (s1, c1) = if k < k_last { (runs[k + 1].1, runs[k + 1].2) } else { (b, cut_b) }; + if !(s1 - s0 > EPS) { + continue; + } + let jt = [if k == 0 { joint[0] } else { true }, if k == k_last { joint[1] } else { true }]; + // Seitlich: läuft eine Grenze längs durchs Band (Kanten sehen einen anderen Bereich)? + if depth < 3 && th > 0.004 { + let mut other = None; + 'edges: for side in [1.0, -1.0] { + let eo = side * (th / 2.0 - 1e-4); + let e_lo = c0.and_then(|l| band_cut_distance(w, u, n, off + eo, &l)).unwrap_or(s0); + let e_hi = c1.and_then(|l| band_cut_distance(w, u, n, off + eo, &l)).unwrap_or(s1); + if !(e_hi - e_lo > 4.0 * EPS) { + continue; + } + let m = 4usize.max(((e_hi - e_lo) / ROOF_SAMPLE).ceil() as usize).min(20_000); + for j in 0..m { + let s = e_lo + (e_hi - e_lo) * (j as f64 + 0.5) / m as f64; + let fe = t.at(add(pt(s), scale(n, eo))); + if fe != f { + other = Some(fe); + break 'edges; + } + } + } + if let Some(fo) = other { + let (ca, cb) = (t.coef(f), t.coef(fo)); + let d = [ca[0] - cb[0], ca[1] - cb[1], ca[2] - cb[2]]; + let mid = pt((s0 + s1) / 2.0); + let den = d[1] * n.x + d[2] * n.y; + if den.abs() > 1e-9 { + let o = -(d[0] + d[1] * mid.x + d[2] * mid.y) / den; + if o.abs() < th / 2.0 - 1e-3 { + for (lo_o, hi_o) in [(-th / 2.0, o), (o, th / 2.0)] { + let c = off + (lo_o + hi_o) / 2.0; + let sa = c0.and_then(|l| band_cut_distance(w, u, n, c, &l)).unwrap_or(s0); + let sb = c1.and_then(|l| band_cut_distance(w, u, n, c, &l)).unwrap_or(s1); + strip_tops(w, t, u, n, c, hi_o - lo_o, sa, sb, c0, c1, jt, depth + 1, out); + } + continue; + } + } + } + } + let (plane, top) = match f { + Fac::Floor => continue, + Fac::Free => (None, t.zt_free), + Fac::Cap => (None, t.zt_cap), + Fac::Roof(_) => { + let c = t.coef(f); + let zmax = strip_corners(w, u, n, off, th, s0, s1, c0, c1).iter().map(|q| c[0] + c[1] * q.x + c[2] * q.y).fold(f64::NEG_INFINITY, f64::max); + (Some(c), zmax.min(t.zt_cap).max(t.zb)) + } }; - let (z0, z1) = (value_at(sa), value_at(sb)); - if z0.max(z1) - zb > EPS { - emit(sa, sb, zb, z0, z1); + out.push(TopPiece { a: s0, b: s1, cut_a: c0, cut_b: c1, off, th, top, plane, joint: jt }); + } +} + +/// Oberkante eines Bandstücks unter den Dächern; `None`, wenn kein Dach die Wand betrifft (dann +/// unverändert ein Körper auf der Krone). +#[allow(clippy::too_many_arguments)] +fn roof_tops(w: &WallIn, ctx: &FloorContext, u: Vec2, n: Vec2, off: f64, th: f64, a: f64, b: f64, cut_a: Option, cut_b: Option, zb: f64, zt: f64) -> Option> { + if zt - zb <= EPS || b - a <= EPS { + return None; + } + let t = roof_tops_ctx(w, ctx, zb, zt)?; + let mut out = Vec::new(); + strip_tops(w, &t, u, n, off, th, a, b, cut_a, cut_b, [false; 2], 0, &mut out); + // Nichts geteilt, nichts geneigt: wie ohne Dach. + if out.len() == 1 && out[0].plane.is_none() && out[0].top == zt && out[0].th == th && out[0].a == a && out[0].b == b { + return None; + } + Some(out) +} + +/// Löcher eines Bandkörpers ab `a` (Achsmass) im Höhenbereich `[zb, zt]`, mit Schichteinzug. +#[allow(clippy::too_many_arguments)] +fn band_holes(w: &WallIn, li: usize, cutouts: &[OpeningIn], innermost: bool, recess: f64, a: f64, zb: f64, zt: f64) -> Vec<[f64; 4]> { + let reveals = &w.reveals; + cutouts + .iter() + .filter(|h| h.z_top > zb + EPS && h.z_bottom < zt - EPS) + .map(|h| { + if let Some(s) = reveals.iter().find(|r| r.of(h)).and_then(|r| r.shifts.get(li)) { + [h.from - a - s[0], h.to - a + s[1], h.z_bottom - s[3], h.z_top + s[2]] + } else if innermost && h.recess_inner_layer { + [h.from - a - recess, h.to - a + recess, h.z_bottom - recess, h.z_top + recess] + } else { + [h.from - a, h.to - a, h.z_bottom, h.z_top] + } + }) + .collect() +} + +/// Ein Körper aus einem Oberkanten-Stück: Achsmass `[x0, x1]` relativ zu `tp.a`, Höhe `[zb, top]`. +#[allow(clippy::too_many_arguments)] +fn push_top_piece(em: &mut Emitter, li: usize, band_th: f64, tp: &TopPiece, x0: f64, x1: f64, zb: f64, top: f64, plane: Option<[f64; 3]>, holes: Vec<[f64; 4]>) { + let len = tp.b - tp.a; + let first = x0 <= EPS; + let last = x1 >= len - EPS; + let before = em.out.len(); + em.push(li, tp.a + x0, tp.a + x1, zb, top, tp.off, holes, [0.0, 0.0]); + let Some(pc) = em.out.get_mut(before) else { return }; + pc.start_cut = if first { tp.cut_a } else { None }; + pc.end_cut = if last { tp.cut_b } else { None }; + pc.joint = [if first { tp.joint[0] } else { true }, if last { tp.joint[1] } else { true }]; + if (tp.th - band_th).abs() > 1e-12 { + pc.thickness = Some(tp.th); + } + if let Some(c) = plane { + pc.top_plane = Some(c); + let at = |q: Vec2| c[0] + c[1] * q.x + c[2] * q.y; + let d = [top - at(pc.start), top - at(pc.end)]; + pc.top_drop = (d[0] > EPS || d[1] > EPS).then_some(d); + } +} + +/// Körper eines Oberkanten-Stücks; unter einer Dachfläche ohne Löcher (Pfeiler, Brüstung, Sturz je mit +/// eigener ebener Oberkante statt Treppung). +#[allow(clippy::too_many_arguments)] +fn emit_top_piece(em: &mut Emitter, li: usize, band_th: f64, tp: &TopPiece, u: Vec2, n: Vec2, zb: f64, cutouts: &[OpeningIn], innermost: bool, recess: f64) { + let w = em.w; + let holes = if w.layered { band_holes(w, li, cutouts, innermost, recess, tp.a, zb, tp.top) } else { Vec::new() }; + let len = tp.b - tp.a; + let Some(c) = tp.plane else { + push_top_piece(em, li, band_th, tp, 0.0, len, zb, tp.top, None, holes); + return; + }; + if holes.is_empty() { + push_top_piece(em, li, band_th, tp, 0.0, len, zb, tp.top, Some(c), holes); + return; + } + let mut xs = vec![0.0, len]; + for h in &holes { + for x in [h[0], h[1]] { + if x > EPS && x < len - EPS { + xs.push(x); + } + } + } + xs.sort_by(|p, q| p.total_cmp(q)); + xs.dedup_by(|p, q| (*p - *q).abs() <= EPS); + for i in 0..xs.len() - 1 { + let (x0, x1) = (xs[i], xs[i + 1]); + if x1 - x0 <= EPS { + continue; + } + let mid = (x0 + x1) / 2.0; + let mut zs: Vec<[f64; 2]> = holes.iter().filter(|h| h[0] <= mid && h[1] >= mid).map(|h| [h[2], h[3]]).collect(); + zs.sort_by(|p, q| p[0].total_cmp(&q[0])); + let mut cur = zb; + for [h0, h1] in zs { + if h0 > cur + EPS { + push_top_piece(em, li, band_th, tp, x0, x1, cur, h0, None, Vec::new()); + } + cur = cur.max(h1); + } + let ca = if x0 <= EPS { tp.cut_a } else { None }; + let cb = if x1 >= len - EPS { tp.cut_b } else { None }; + let zc: Vec = strip_corners(w, u, n, tp.off, tp.th, tp.a + x0, tp.a + x1, ca, cb).iter().map(|q| c[0] + c[1] * q.x + c[2] * q.y).collect(); + let (zmin, zmax) = (zc.iter().copied().fold(f64::INFINITY, f64::min), zc.iter().copied().fold(f64::NEG_INFINITY, f64::max)); + // Sturz/Pfeiler bis unter die Dachfläche (Fenster, das ins Dach ragt: der Rest entfällt). + if zmin > cur + EPS { + push_top_piece(em, li, band_th, tp, x0, x1, cur, zmax.min(tp.top), Some(c), Vec::new()); } } } @@ -599,9 +936,20 @@ pub fn wall_bands(w: &WallIn, ctx: &FloorContext) -> Vec { if !w.layered { // Schnitt-Pfad: Pfeiler/Brüstung/Sturz, je Segment alle Bänder. + // Unter Dächern ([G2]) je Segment die exakte Oberkante. + let u = Vec2::new((w.end.x - w.start.x) / axis_len, (w.end.y - w.start.y) / axis_len); + let n = left_normal(u); let seg = |em: &mut Emitter, from: f64, to: f64, zb: f64, zt: f64| { for (i, &off) in offsets.iter().enumerate() { - em.push(i, from, to, zb, zt, off, vec![], [0.0, 0.0]); + let th = w.bands[i].thickness; + match roof_tops(w, ctx, u, n, off, th, from, to, None, None, zb, zt) { + None => em.push(i, from, to, zb, zt, off, vec![], [0.0, 0.0]), + Some(tops) => { + for tp in &tops { + emit_top_piece(em, i, th, tp, u, n, zb, &[], false, 0.0); + } + } + } } }; if cutouts.is_empty() { @@ -696,8 +1044,14 @@ pub fn wall_bands(w: &WallIn, ctx: &FloorContext) -> Vec { let recess = b.thickness; for ([a, bb], cut_a, cut_b) in axis_pieces { let n0 = em.out.len(); - let mut emit_piece = |a: f64, bb: f64, zb: f64, zt_start: f64, zt_end: f64| { - emit_band_piece(&mut em, li, off, &cutouts, innermost, recess, a, bb, zb, zt_start, zt_end); + let th = b.thickness; + let mut emit_piece = |a: f64, bb: f64, ca: Option, cb: Option, zb: f64, zt: f64| match roof_tops(w, ctx, u, n, off, th, a, bb, ca, cb, zb, zt) { + None => emit_band_piece(&mut em, li, off, &cutouts, innermost, recess, a, bb, zb, zt), + Some(tops) => { + for tp in &tops { + emit_top_piece(&mut em, li, th, tp, u, n, zb, &cutouts, innermost, recess); + } + } }; let local: Vec<[f64; 4]> = band_z_cuts .iter() @@ -705,7 +1059,7 @@ pub fn wall_bands(w: &WallIn, ctx: &FloorContext) -> Vec { .filter(|c| c[1] > c[0] + EPS) .collect(); if local.is_empty() { - clip_to_roofs(w, ctx, u, n, off, a, bb, z_bottom, z_top, &mut emit_piece); + emit_piece(a, bb, cut_a, cut_b, z_bottom, z_top); set_piece_cuts(&mut em.out[n0..], w, u, a, bb, cut_a, cut_b); continue; } @@ -724,7 +1078,7 @@ pub fn wall_bands(w: &WallIn, ctx: &FloorContext) -> Vec { let mid = (xa + xb) / 2.0; let z_cutters: Vec<[f64; 2]> = local.iter().filter(|c| c[0] <= mid && c[1] >= mid).map(|c| [c[2], c[3]]).collect(); for [zb, zt] in terminate_or_subtract(z_bottom, z_top, &z_cutters, w.termination) { - clip_to_roofs(w, ctx, u, n, off, xa, xb, zb, zt, &mut emit_piece); + emit_piece(xa, xb, if xa == a { cut_a } else { None }, if xb == bb { cut_b } else { None }, zb, zt); } } set_piece_cuts(&mut em.out[n0..], w, u, a, bb, cut_a, cut_b); @@ -781,35 +1135,11 @@ fn reveal_pieces(em: &mut Emitter, offsets: &[f64]) { /// Ein Körper eines Bands im layered-Pfad: Öffnungs-Löcher auf den Körper-Start umrechnen (an der /// innersten Schicht mit Laibungs-Rücksprung geweitet); schräge Oberkante mit Löchern geht in /// render3d nicht → gestuft annähern. +/// Körper eines Bandstücks ohne Dach darüber (waagrechte Krone, Öffnungen als Löcher). #[allow(clippy::too_many_arguments)] -fn emit_band_piece(em: &mut Emitter, li: usize, off: f64, cutouts: &[OpeningIn], innermost: bool, recess: f64, a: f64, bb: f64, zb: f64, zt_start: f64, zt_end: f64) { - let zt = zt_start.max(zt_end); - let reveals = &em.w.reveals; - let holes: Vec<[f64; 4]> = cutouts - .iter() - .filter(|h| h.z_top > zb + EPS && h.z_bottom < zt - EPS) - .map(|h| { - if let Some(s) = reveals.iter().find(|r| r.of(h)).and_then(|r| r.shifts.get(li)) { - // [106]: Schicht springt je Seite zurück. - [h.from - a - s[0], h.to - a + s[1], h.z_bottom - s[3], h.z_top + s[2]] - } else if innermost && h.recess_inner_layer { - [h.from - a - recess, h.to - a + recess, h.z_bottom - recess, h.z_top + recess] - } else { - [h.from - a, h.to - a, h.z_bottom, h.z_top] - } - }) - .collect(); - if !holes.is_empty() && (zt_start - zt_end).abs() > EPS { - let k = 1usize.max(((bb - a) / ROOF_CLIP_STEP).ceil() as usize); - for i in 0..k { - let sa = a + ((bb - a) * i as f64) / k as f64; - let sb = a + ((bb - a) * (i + 1) as f64) / k as f64; - let zm = zt_start + ((zt_end - zt_start) * (i as f64 + 0.5)) / k as f64; - emit_band_piece(em, li, off, cutouts, innermost, recess, sa, sb, zb, zm, zm); - } - return; - } - em.push(li, a, bb, zb, zt, off, holes, [zt - zt_start, zt - zt_end]); +fn emit_band_piece(em: &mut Emitter, li: usize, off: f64, cutouts: &[OpeningIn], innermost: bool, recess: f64, a: f64, bb: f64, zb: f64, zt: f64) { + let holes = band_holes(em.w, li, cutouts, innermost, recess, a, zb, zt); + em.push(li, a, bb, zb, zt, off, holes, [0.0, 0.0]); } #[cfg(test)] @@ -832,6 +1162,7 @@ mod tests { openings: vec![], cuts: WallCuts::default(), reveals: vec![], + roof_attach: None, } } fn band(t: f64, p: f64) -> BandIn { @@ -844,9 +1175,6 @@ mod tests { wall_bands(w, &FloorContext::default()) } /// Achsen-Länge eines Körpers. - fn plen(p: &Piece) -> f64 { - js_hypot(p.end.x - p.start.x, p.end.y - p.start.y) - } #[test] fn schichten_gestapelt_und_referenzversetzt() { @@ -1093,7 +1421,7 @@ mod tests { w.z_top = 5.0; // Ebene z = 2 + 0.5·x über [−1, 5]². let plane = vec![[-1.0, -1.0, 1.5], [5.0, -1.0, 4.5], [5.0, 5.0, 4.5], [-1.0, 5.0, 1.5]]; - let roof = RoofIn { eaves_z: 1.5, total_thickness: 0.0, eaves: plane.iter().map(|p| [p[0], p[1]]).collect(), planes: vec![plane] }; + let roof = RoofIn::new(1.5, 0.0, plane.iter().map(|p| [p[0], p[1]]).collect(), vec![plane]); let ctx = FloorContext::new(vec![], vec![roof]); let p = wall_bands(&w, &ctx); assert_eq!(p.len(), 1, "{p:?}"); @@ -1101,12 +1429,172 @@ mod tests { // Abtastung 1 mm innerhalb der Enden (wie TS) → Toleranz 1e-3. let near = |a: f64, b: f64| (a - b).abs() < 1e-3; assert!(near(p[0].z_top, 4.0) && near(d[0], 2.0) && d[1] == 0.0, "{p:?}"); - // Mit Öffnung: gestuft, ohne top_drop. + // Mit Öffnung ([G2]): Pfeiler und Sturz mit schräger Oberkante statt Treppung. w.openings.push(OpeningIn { from: 1.0, to: 2.0, z_bottom: 0.0, z_top: 2.0, recess_inner_layer: false }); let p = wall_bands(&w, &ctx); - assert!(p.len() > 10 && p.iter().all(|q| q.top_drop.is_none())); - let total: f64 = p.iter().map(plen).sum(); - assert!(close(total, 4.0)); + assert!(p.len() == 3 && p.iter().all(|q| q.holes.is_empty() && q.top_plane.is_some()), "{p:?}"); + let vol: f64 = p.iter().map(|q| volume(&w, q)).sum(); + assert!((vol - 2.0).abs() < 1e-9, "{vol}"); + } + + // ── [G2] Wand an Dach: exakte Oberkante je Schicht ────────────────────────── + + /// Satteldach über [-1, 9] × [-1, 7], First bei y = 3 (längs x), Traufe z = 3, Neigung 45°. + fn gable(total: f64) -> RoofIn { + let s = vec![[-1.0, -1.0, 3.0], [9.0, -1.0, 3.0], [9.0, 3.0, 7.0], [-1.0, 3.0, 7.0]]; + let n = vec![[-1.0, 3.0, 7.0], [9.0, 3.0, 7.0], [9.0, 7.0, 3.0], [-1.0, 7.0, 3.0]]; + RoofIn::new(3.0, total, vec![[-1.0, -1.0], [9.0, -1.0], [9.0, 7.0], [-1.0, 7.0]], vec![s, n]) + } + + /// Unterkante des Satteldachs (Dicke `t` senkrecht zur Fläche, 45° ⇒ lotrecht t·√2). + fn gable_under(t: f64, y: f64) -> f64 { + 7.0 - (y - 3.0).abs() - t * 2f64.sqrt() + } + + /// Ecken einer Band-Grundfläche (mit Schnittlinien, Eigendicke). + fn corners(w: &WallIn, p: &Piece) -> [Vec2; 4] { + let u = sub(w.end, w.start); + let u = scale(u, 1.0 / js_hypot(u.x, u.y)); + let n = left_normal(u); + let h = p.thickness.unwrap_or(w.bands[p.band].thickness) / 2.0; + let clip = |base: Vec2, c: Option| c.and_then(|c| line_intersect(base, u, c.point, c.dir)).unwrap_or(base); + [clip(add(p.start, scale(n, h)), p.start_cut), clip(add(p.end, scale(n, h)), p.end_cut), clip(add(p.end, scale(n, -h)), p.end_cut), clip(add(p.start, scale(n, -h)), p.start_cut)] + } + + fn top_at(p: &Piece, q: Vec2) -> f64 { + p.top_plane.map_or(p.z_top, |c| c[0] + c[1] * q.x + c[2] * q.y) + } + + /// Volumen eines Körpers: Grundfläche × Höhe im Schwerpunkt (exakt bei ebener Oberkante), ohne Löcher. + fn volume(w: &WallIn, p: &Piece) -> f64 { + let q = corners(w, p); + let mut a = 0.0; + let (mut cx, mut cy) = (0.0, 0.0); + for i in 0..4 { + let (p0, p1) = (q[i], q[(i + 1) % 4]); + let c = p0.x * p1.y - p1.x * p0.y; + a += c; + cx += (p0.x + p1.x) * c; + cy += (p0.y + p1.y) * c; + } + if a.abs() < 1e-15 { + return 0.0; + } + let c = Vec2::new(cx / (3.0 * a), cy / (3.0 * a)); + let holes: f64 = p.holes.iter().map(|h| (h[1] - h[0]) * (h[3] - h[2])).sum::() * p.thickness.unwrap_or(w.bands[p.band].thickness); + (a / 2.0).abs() * (top_at(p, c) - p.z_bottom) - holes + } + + #[test] + fn giebelwand_folgt_beiden_dachflaechen_je_schicht() { + // Giebelwand quer zum First (x = 0, y 0 → 6), zwei Schichten, Oberkante weit über dem Dach. + let mut w = base((0.0, 0.0), (0.0, 6.0), vec![band(0.1, 10.0), band(0.2, 50.0)]); + w.z_top = 9.0; + let ctx = FloorContext::new(vec![], vec![gable(0.2)]); + let p = wall_bands(&w, &ctx); + // Je Schicht zwei Körper (links/rechts vom First), beide mit ebener Oberkante. + assert_eq!(p.len(), 4, "{p:?}"); + for q in &p { + assert!(q.top_plane.is_some() && q.holes.is_empty(), "{q:?}"); + for c in corners(&w, q) { + assert!((top_at(q, c) - gable_under(0.2, c.y)).abs() < 1e-9, "Ecke {c:?} {q:?}"); + } + } + // Volumen = Fläche unter der Unterkante × Dicke (Fünfeck), exakt. + let vol: f64 = p.iter().map(|q| volume(&w, q)).sum(); + let h0 = gable_under(0.2, 0.0); + let h1 = gable_under(0.2, 3.0); + let expect = 0.3 * (6.0 * h0 + 3.0 * (h1 - h0)); + assert!((vol - expect).abs() < 1e-9, "{vol} vs {expect}"); + // Innere Stossfuge am First: keine sichtbare Stirn. + assert!(p.iter().filter(|q| q.joint[0] || q.joint[1]).count() == 4); + } + + #[test] + fn traufwand_schraeg_ueber_die_dicke_und_seitlich_geteilt() { + // Traufwand längs x bei y = 0.5 (Dicke 0.3: y 0.35 … 0.65), Dach steigt quer zur Wand. + let mut w = base((0.0, 0.5), (8.0, 0.5), vec![band(0.3, 50.0)]); + w.z_top = 9.0; + let ctx = FloorContext::new(vec![], vec![gable(0.0)]); + let p = wall_bands(&w, &ctx); + assert_eq!(p.len(), 1, "{p:?}"); + let c = p[0].top_plane.unwrap(); + assert!(c[1].abs() < 1e-12 && (c[2] - 1.0).abs() < 1e-12, "Oberkante steigt mit y: {c:?}"); + for k in corners(&w, &p[0]) { + assert!((top_at(&p[0], k) - gable_under(0.0, k.y)).abs() < 1e-9); + } + // Wandkrone 4.5 schneidet die Unterkante in der Dicke (y = 0.5): zwei Streifen nebeneinander. + w.z_top = 4.5; + let p = wall_bands(&w, &ctx); + assert_eq!(p.len(), 2, "{p:?}"); + let vol: f64 = p.iter().map(|q| volume(&w, q)).sum(); + // Aussen (y 0.35 … 0.5) schräg 4.35 … 4.5, innen flach 4.5. + let expect = 8.0 * (0.15 * (4.35 + 4.5) / 2.0 + 0.15 * 4.5); + assert!((vol - expect).abs() < 1e-9, "{vol} vs {expect}"); + assert!(p.iter().all(|q| q.thickness.is_some_and(|t| (t - 0.15).abs() < 1e-9))); + } + + #[test] + fn wand_mit_fenster_unter_dachschraege_ohne_treppung() { + let mut w = base((0.0, 0.0), (0.0, 6.0), vec![band(0.2, 50.0)]); + w.z_top = 9.0; + w.openings.push(OpeningIn { from: 1.0, to: 2.0, z_bottom: 1.0, z_top: 2.5, recess_inner_layer: false }); + let ctx = FloorContext::new(vec![], vec![gable(0.0)]); + let p = wall_bands(&w, &ctx); + // Pfeiler, Brüstung, Sturz, Pfeiler bis zum First, Pfeiler danach: keine Treppen, keine Löcher. + assert!(p.len() <= 6 && p.iter().all(|q| q.holes.is_empty()), "{p:?}"); + let vol: f64 = p.iter().map(|q| volume(&w, q)).sum(); + let gross = 0.2 * (6.0 * 4.0 + 3.0 * 3.0); + assert!((vol - (gross - 0.2 * 1.5)).abs() < 1e-9, "{vol}"); + for q in &p { + for c in corners(&w, q) { + assert!(top_at(q, c) <= gable_under(0.0, c.y) + 1e-9); + } + } + } + + #[test] + fn an_dach_anschliessen_verlaengert_oder_ignoriert() { + // Wandkrone 2.5 unter der Traufe: automatisch unverändert. + let mut w = base((0.0, 0.0), (0.0, 6.0), vec![band(0.2, 50.0)]); + w.z_top = 2.5; + let ctx = FloorContext::new(vec![], vec![gable(0.0)]); + let p = wall_bands(&w, &ctx); + assert!(p.len() == 1 && p[0].top_plane.is_none() && close(p[0].z_top, 2.5)); + // An Dach anschliessen: bis unter die Dachfläche verlängert. + w.roof_attach = Some(true); + let p = wall_bands(&w, &ctx); + let vol: f64 = p.iter().map(|q| volume(&w, q)).sum(); + assert!((vol - 0.2 * (6.0 * 4.0 + 9.0)).abs() < 1e-9, "{vol} {p:?}"); + // Nie: Wand bleibt durchgehend, auch wenn sie über das Dach ragt. + w.roof_attach = Some(false); + w.z_top = 9.0; + let p = wall_bands(&w, &ctx); + assert!(p.len() == 1 && close(p[0].z_top, 9.0)); + } + + #[test] + fn kehle_zweier_daecher_nimmt_die_obere_huelle() { + // Zwei Pultdächer überdecken sich: Unterkante = obere Hülle (Maximum) der beiden. + let a = RoofIn::new(0.0, 0.0, vec![], vec![vec![[0.0, -1.0, 2.0], [6.0, -1.0, 5.0], [6.0, 1.0, 5.0], [0.0, 1.0, 2.0]]]); + let b = RoofIn::new(0.0, 0.0, vec![], vec![vec![[0.0, -1.0, 5.0], [6.0, -1.0, 2.0], [6.0, 1.0, 2.0], [0.0, 1.0, 5.0]]]); + let mut w = base((0.0, 0.0), (6.0, 0.0), vec![band(0.2, 50.0)]); + w.z_top = 9.0; + let p = wall_bands(&w, &FloorContext::new(vec![], vec![a, b])); + assert_eq!(p.len(), 2, "{p:?}"); + let vol: f64 = p.iter().map(|q| volume(&w, q)).sum(); + assert!((vol - 0.2 * 25.5).abs() < 1e-9, "{vol}"); + } + + #[test] + fn schnitt_pfad_schneidet_ebenfalls_am_dach() { + let mut w = base((0.0, 0.0), (0.0, 6.0), vec![band(0.3, 50.0)]); + w.z_top = 9.0; + w.layered = false; + w.openings.push(OpeningIn { from: 1.0, to: 2.0, z_bottom: 1.0, z_top: 2.5, recess_inner_layer: false }); + let p = wall_bands(&w, &FloorContext::new(vec![], vec![gable(0.0)])); + let vol: f64 = p.iter().map(|q| volume(&w, q)).sum(); + assert!((vol - 0.3 * (6.0 * 4.0 + 9.0 - 1.5)).abs() < 1e-9, "{vol}"); } #[test] @@ -1122,7 +1610,7 @@ mod tests { w.bands.push(band(0.0, 1.0)); let ctx = FloorContext::new( vec![CeilingIn { z_bottom: 0.5, z_top: 0.5, outline: vec![Vec2::new(0.0, 0.0); 3], layers: Some(vec![]) }], - vec![RoofIn { eaves_z: 0.0, total_thickness: 0.0, eaves: vec![], planes: vec![vec![]] }], + vec![RoofIn::new(0.0, 0.0, vec![], vec![vec![]]), RoofIn::new(0.0, f64::NAN, vec![], vec![vec![[0.0, 0.0, f64::NAN], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]], vec![[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 2.0]]])], ); let _ = wall_bands(&w, &ctx); diff --git a/src-tauri/render3d/examples/section_svg.rs b/src-tauri/render3d/examples/section_svg.rs index 534e3e9c..63681d4a 100644 --- a/src-tauri/render3d/examples/section_svg.rs +++ b/src-tauri/render3d/examples/section_svg.rs @@ -20,6 +20,7 @@ fn l_wall_scene() -> (Vec, Vec) { // Bruestung 0.8 m, Fensterhoehe 1.0 m (Sturz ab Y-Hoehe 1.8). WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [0.0, 3.0], thickness: 0.2, @@ -42,6 +43,7 @@ fn l_wall_scene() -> (Vec, Vec) { }, WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 3.0], end: [3.0, 3.0], thickness: 0.2, @@ -64,6 +66,7 @@ fn l_wall_scene() -> (Vec, Vec) { // 0.8..1.8), verdeckt darueber/darunter. WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [1.5, 1.2], end: [1.5, 1.8], thickness: 0.2, diff --git a/src-tauri/render3d/src/lib.rs b/src-tauri/render3d/src/lib.rs index 8491823b..466f0f3f 100644 --- a/src-tauri/render3d/src/lib.rs +++ b/src-tauri/render3d/src/lib.rs @@ -73,6 +73,7 @@ mod tests { fn wall_x(len: f32, thickness: f32, height: f32) -> WallInput { WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [len, 0.0], thickness, @@ -219,6 +220,7 @@ mod tests { fn wall_x_hatched(len: f32, thickness: f32, height: f32) -> WallInput { WallInput { top_drop: [0.0, 0.0], + top_plane: None, hatch: Some(Hatch { pattern: 3, angle: 45.0, scale: 1.0, line_weight: 0.13, top_angle: None }), ..wall_x(len, thickness, height) } @@ -277,6 +279,7 @@ mod tests { let a = wall_x_hatched(3.0, 0.2, 2.5); // (0,0) frei .. (3,0) verbunden let b = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [3.0, 0.0], end: [3.0, 4.0], ..wall_x_hatched(4.0, 0.2, 2.5) // (3,0) verbunden .. (3,4) frei @@ -305,6 +308,7 @@ mod tests { wall_x(3.0, 0.2, 2.5), WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [3.0, 0.0], end: [3.0, 4.0], thickness: 0.2, @@ -390,6 +394,7 @@ mod tests { // Auch nicht-achsparallele Waende extrudieren korrekt (nur andere Ecken). let w = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [2.0, 2.0], thickness: 0.3, @@ -418,6 +423,7 @@ mod tests { // Start == Ende -> keine Richtung -> uebersprungen (kein Absturz). let w = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [1.0, 1.0], end: [1.0, 1.0], thickness: 0.2, @@ -638,6 +644,7 @@ mod tests { // weder darueber hinaus (Ueberstand) noch darunter (Spalt). let a = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [3.0, 0.0], thickness: 0.4, @@ -655,6 +662,7 @@ mod tests { }; let b = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [0.0, 3.0], thickness: 0.4, @@ -721,6 +729,7 @@ mod tests { // rechtwinklig. Regressions-Absicherung: keine Panik, stabile Zaehlung. let mk = |s: [f32; 2], e: [f32; 2]| WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: s, end: e, thickness: 0.2, @@ -756,6 +765,7 @@ mod tests { // Geschoss weiterhin auf der 45-Grad-Linie relativ zu SEINER Basis). let mk = |s: [f32; 2], e: [f32; 2], base: f32| WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: s, end: e, thickness: 0.4, @@ -851,6 +861,7 @@ mod tests { }; let a = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [3.0, 0.0], thickness: 0.3, diff --git a/src-tauri/render3d/src/mesh.rs b/src-tauri/render3d/src/mesh.rs index 38eb9d50..6e8478b5 100644 --- a/src-tauri/render3d/src/mesh.rs +++ b/src-tauri/render3d/src/mesh.rs @@ -159,8 +159,9 @@ fn extrude_wall_with_miters(mesh: &mut Mesh, wall: &WallInput, miters: WallMiter ); } else { let drop = if segments.len() == 1 { wall.top_drop } else { [0.0, 0.0] }; + let plane = if segments.len() == 1 { wall.top_plane } else { None }; extrude_layer_segment( - mesh, wall, n, length, a0, a1, y0, y1, drop, off_a, off_b, start_cut, end_cut, + mesh, wall, n, length, a0, a1, y0, y1, drop, plane, off_a, off_b, start_cut, end_cut, layer.color, ); } @@ -240,6 +241,7 @@ fn extrude_layer_segment( y0: f32, y1: f32, top_drop: [f32; 2], + top_plane: Option<[f32; 3]>, off_a: f32, off_b: f32, start_cut: Option, @@ -285,14 +287,21 @@ fn extrude_layer_segment( top_drop[0] + (top_drop[1] - top_drop[0]) * t }; let (ya, yb) = (y1 - drop_at(a0), y1 - drop_at(a1)); - let t0 = w(g0, ya); - let t1 = w(g1, yb); - let t2 = w(g2, yb); - let t3 = w(g3, ya); + // Ebene Oberkante ([G2]): jede Ecke auf der Dach-Unterkante (auch quer über die Dicke). + let top_y = |g: Point2, fallback: f32| -> f32 { + match top_plane { + Some(p) => p[0] + p[1] * (g[0] - wall.start[0]) + p[2] * (g[1] - wall.start[1]), + None => fallback, + } + }; + let t0 = w(g0, top_y(g0, ya)); + let t1 = w(g1, top_y(g1, yb)); + let t2 = w(g2, top_y(g2, yb)); + let t3 = w(g3, top_y(g3, ya)); // Sechs Seiten als Quads (Ecken CCW von aussen gesehen -> Normale zeigt raus). // Deckel oben (+Y): t0,t1,t2,t3 von oben CCW. - let top_normal = if ya == yb { [0.0, 1.0, 0.0] } else { quad_normal(t0, t1, t3) }; + let top_normal = if ya == yb && top_plane.is_none() { [0.0, 1.0, 0.0] } else { quad_normal(t0, t1, t3) }; push_quad(mesh, t0, t1, t2, t3, top_normal, color); // Boden unten (-Y): b0,b3,b2,b1 (von unten gesehen CCW). push_quad(mesh, b0, b3, b2, b1, [0.0, -1.0, 0.0], color); @@ -1021,6 +1030,9 @@ pub fn build_free_wall_end_caps(walls: &[WallInput]) -> Vec { let dz = wall.end[1] - wall.start[1]; let len2 = (dx * dx + dz * dz).max(1e-12); let y_at = |p: Point2| -> f32 { + if let Some(q) = wall.top_plane { + return q[0] + q[1] * (p[0] - wall.start[0]) + q[2] * (p[1] - wall.start[1]); + } let t = (((p[0] - wall.start[0]) * dx + (p[1] - wall.start[1]) * dz) / len2).clamp(0.0, 1.0); y_top - (wall.top_drop[0] + (wall.top_drop[1] - wall.top_drop[0]) * t) }; diff --git a/src-tauri/render3d/src/section.rs b/src-tauri/render3d/src/section.rs index 7f5e546a..27015898 100644 --- a/src-tauri/render3d/src/section.rs +++ b/src-tauri/render3d/src/section.rs @@ -342,6 +342,19 @@ struct Prism { cut: Option, /// Monolith-Gruppe (siehe `SlabInput::monolith`); Waende: immer `None`. monolith: Option, + /// Ebene Oberkante unter einer Dachfläche ([G2], `WallInput::top_plane`): Ursprung (Grundriss) + /// und `[z, dz/dx, dz/dy]`; `z1` ist dann der höchste Eckwert. + top: Option<(Point2, [f32; 3])>, +} + +impl Prism { + /// Oberkante an einem Grundriss-Punkt. + fn top_at(&self, p: Point2) -> f32 { + match self.top { + Some((o, c)) => (c[0] + c[1] * (p[0] - o[0]) + c[2] * (p[1] - o[1])).clamp(self.z0, self.z1), + None => self.z1, + } + } } /// Wandachse + Oeffnungen, wie sie fuer die Oeffnungs-Zuordnung bei Cut- @@ -433,6 +446,7 @@ fn wall_prism(index: usize, wall: &WallInput) -> Option { }), cut: wall.cut.clone(), monolith: None, + top: wall.top_plane.map(|c| (wall.start, c)), }) } @@ -457,6 +471,7 @@ fn slab_prism(index: usize, slab: &SlabInput) -> Option { wall_axis: None, cut: slab.cut.clone(), monolith: slab.monolith.clone(), + top: None, }) } @@ -884,7 +899,7 @@ fn prism_wireframe_edges(prism: &Prism) -> Vec<([f32; 3], [f32; 3], HeightBias)> for i in 0..n { edges.push(( to_world(prism.footprint[i], prism.z0), - to_world(prism.footprint[i], prism.z1), + to_world(prism.footprint[i], prism.top_at(prism.footprint[i])), HeightBias::Vertical, )); } @@ -892,7 +907,9 @@ fn prism_wireframe_edges(prism: &Prism) -> Vec<([f32; 3], [f32; 3], HeightBias)> let a = prism.footprint[i]; let b = prism.footprint[(i + 1) % n]; edges.push((to_world(a, prism.z0), to_world(b, prism.z0), HeightBias::BottomCap)); - edges.push((to_world(a, prism.z1), to_world(b, prism.z1), HeightBias::TopCap)); + // Schräge Deckelkante ([G2]): Höhe variiert, geschlossene Randbehandlung. + let bias = if prism.top.is_some() { HeightBias::Vertical } else { HeightBias::TopCap }; + edges.push((to_world(a, prism.top_at(a)), to_world(b, prism.top_at(b)), bias)); } edges } @@ -1176,6 +1193,16 @@ pub fn cut_section( for (u0, u1) in footprint_u_intervals(plane, &prism.cut_footprint) { let (lo, hi) = (u0.min(u1), u0.max(u1)); for (rlo, rhi, rz0, rz1) in wall_cut_rectangles(plane, prism, lo, hi) { + // Ebene Oberkante ([G2]): Deckelkante längs der Schnittlinie schräg. + let (za, zb) = if prism.top.is_some() && rz1 >= prism.z1 { + let at = |u: f32| { + let (p0, ua) = (plane.plan_point(), plane.plan_u_axis()); + prism.top_at([p0[0] + u * ua[0], p0[1] + u * ua[1]]) + }; + (at(rlo), at(rhi)) + } else { + (rz1, rz1) + }; cut_polygons.push(CutPolygon { component: ComponentRef { kind: prism.kind, @@ -1183,7 +1210,7 @@ pub fn cut_section( }, color: prism.color, hatch: prism.hatch, - pts: vec![[rlo, rz0], [rhi, rz0], [rhi, rz1], [rlo, rz1]], + pts: vec![[rlo, rz0], [rhi, rz0], [rhi, zb], [rlo, za]], cut: prism.cut.clone(), }); } @@ -1227,6 +1254,7 @@ mod tests { let walls = vec![ WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [0.0, 3.0], thickness: 0.2, @@ -1244,6 +1272,7 @@ mod tests { }, WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 3.0], end: [3.0, 3.0], thickness: 0.2, @@ -1322,6 +1351,7 @@ mod tests { fn wand_vor_der_ebene_verdeckt_nichts_dahinter() { let mk = |start: [f32; 2], end: [f32; 2]| WallInput { top_drop: [0.0, 0.0], + top_plane: None, start, end, thickness: 0.2, @@ -1543,6 +1573,7 @@ mod tests { fn wall_with_window() -> WallInput { WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [4.0, 0.0], thickness: 0.2, @@ -1565,6 +1596,25 @@ mod tests { } } + #[test] + fn ebene_oberkante_schraeg_im_schnitt_und_in_der_projektion() { + // Traufwand längs x (y −0.1 … 0.1), Oberkante steigt quer zur Wand: z = 2.5 + 1·y. + let mut w = wall_with_window(); + w.openings.clear(); + w.height = 2.6; + w.top_plane = Some([2.5, 0.0, 1.0]); + // Schnitt quer zur Wand (Ebene x = 2, Blick +x): u längs −y. + let out = cut_section(&SectionPlane::looking_plus_x(2.0), &[w.clone()], &[], &[]); + let c = &out.cut_polygons[0]; + let tops: Vec = c.pts.iter().map(|p| p[1]).filter(|v| *v > 1.0).collect(); + assert_eq!(tops.len(), 2); + assert!((tops[0] - tops[1]).abs() > 0.19 && tops.iter().all(|v| (*v - 2.5).abs() <= 0.1 + 1e-5), "{:?}", c.pts); + // Mesh: jede Deckel-Ecke auf der Ebene. + let m = crate::mesh::build_walls_mesh(&[w]); + let ys: Vec = m.verts.chunks(9).filter(|p| p[1] > 1.0).map(|p| p[1] - (2.5 + p[2])).collect(); + assert!(!ys.is_empty() && ys.iter().all(|d| d.abs() < 1e-5), "{ys:?}"); + } + #[test] fn schnitt_durch_fenster_liefert_bruestung_und_sturz() { // Schnittebene bei Grundriss-X = 2.0: liegt MITTEN im Fenster (1.5..2.5). @@ -1640,6 +1690,7 @@ mod tests { let w0 = wall_with_window(); let w1 = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [2.0, 1.0], end: [4.0, 1.0], thickness: 0.2, @@ -1761,6 +1812,7 @@ mod tests { fn cut_section_mit_wand_und_dach_liefert_beide_cut_polygone() { let wall = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [2.0, -1.0], end: [2.0, 1.0], thickness: 0.3, diff --git a/src-tauri/render3d/src/section_fill.rs b/src-tauri/render3d/src/section_fill.rs index 82f82de7..bb2a4124 100644 --- a/src-tauri/render3d/src/section_fill.rs +++ b/src-tauri/render3d/src/section_fill.rs @@ -341,6 +341,7 @@ mod tests { fn hatch_muster_id_landet_in_den_cap_vertices() { let wall = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [3.0, 0.0], thickness: 0.3, @@ -390,6 +391,7 @@ mod tests { fn generator_muster_kommt_als_ribbons() { let mk = |pattern: u32| WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [3.0, 0.0], thickness: 0.3, @@ -427,6 +429,7 @@ mod tests { fn ohne_hatch_fallback_auf_diagonale() { let wall = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [3.0, 0.0], thickness: 0.3, @@ -463,6 +466,7 @@ mod tests { // Wand entlang +X bei x in [0,3], Dicke 0.4, volle Hoehe [0,2.5]; Prio 50. let wall = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [3.0, 0.0], thickness: 0.4, @@ -540,6 +544,7 @@ mod tests { // volle Hoehe [0,2.5]; Prio 50, Muster 2 (diagonal). let wall = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [3.0, 0.0], thickness: 0.4, @@ -625,6 +630,7 @@ mod tests { let color = [0.2, 0.4, 0.9]; let wall = WallInput { top_drop: [0.0, 0.0], + top_plane: None, start: [0.0, 0.0], end: [3.0, 0.0], thickness: 0.4, diff --git a/src-tauri/render3d/src/types.rs b/src-tauri/render3d/src/types.rs index 94f8b7f0..31dd97c4 100644 --- a/src-tauri/render3d/src/types.rs +++ b/src-tauri/render3d/src/types.rs @@ -136,6 +136,10 @@ pub struct WallInput { /// gestuft. Nur für Wände ohne `openings`/`holes` wirksam; `[0,0]` (Default) = flach. #[serde(default, rename = "topDrop")] pub top_drop: [f32; 2], + /// Ebene Oberkante unter einer Dachfläche ([G2]): `[z an start, dz/dx, dz/dy]` (Grundriss-Meter). + /// Übersteuert `top_drop`; jede Ecke liegt exakt auf der Ebene (auch quer über die Dicke). + #[serde(default, rename = "topPlane", skip_serializing_if = "Option::is_none")] + pub top_plane: Option<[f32; 3]>, /// Albedo-Farbe der Wand (RGB 0..1). Default helles Grau wie die three.js-Sicht. /// Nur wirksam, wenn `layers` fehlt/leer ist (Vollkoerper-Fallback). #[serde(default = "default_wall_color")] diff --git a/src/cli/__golden__/ansicht.svg b/src/cli/__golden__/ansicht.svg index 07f3bff7..a55b3b32 100644 --- a/src/cli/__golden__/ansicht.svg +++ b/src/cli/__golden__/ansicht.svg @@ -13,34 +13,43 @@ + + + + + + + - + + + - - - - + + + + @@ -56,9 +65,14 @@ + + + + + diff --git a/src/i18n/de.ts b/src/i18n/de.ts index a14d9c05..a202b723 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -525,6 +525,11 @@ export const de = { "objinfo.wall.refLine.right": "Innen (rechts)", "objinfo.wall.refLine.joint": "Fuge", "objinfo.wall.sliceTermination": "An Decke enden", + "objinfo.wall.roofAttach": "An Dach anschliessen", + "objinfo.wall.roofAttach.auto": "Automatisch", + "objinfo.wall.roofAttach.on": "Ja, bis unters Dach", + "objinfo.wall.roofAttach.off": "Nein", + "objinfo.wall.roofAttach.tip": "Automatisch: Die Wand endet je Schicht an der Dach-Unterkante, wo ihre Krone darüber liegt. Ja: zusätzlich bis unter das Dach verlängert. Nein: Dächer schneiden die Wand nicht.", "objinfo.wall.sliceTermination.both": "Aus", "objinfo.wall.sliceTermination.below": "Unten", "objinfo.wall.sliceTermination.above": "Oben", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 069373cd..fae1f02e 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -523,6 +523,11 @@ export const en: Record = { "objinfo.wall.refLine.right": "Interior (right)", "objinfo.wall.refLine.joint": "Joint", "objinfo.wall.sliceTermination": "End at ceiling", + "objinfo.wall.roofAttach": "Attach to roof", + "objinfo.wall.roofAttach.auto": "Automatic", + "objinfo.wall.roofAttach.on": "Yes, up to the roof", + "objinfo.wall.roofAttach.off": "No", + "objinfo.wall.roofAttach.tip": "Automatic: each wall layer ends at the roof underside where its top lies above it. Yes: also extended up to the roof. No: roofs do not cut the wall.", "objinfo.wall.sliceTermination.both": "Off", "objinfo.wall.sliceTermination.below": "Below", "objinfo.wall.sliceTermination.above": "Above", diff --git a/src/model/types.generated.ts b/src/model/types.generated.ts index b0d14762..72fd1202 100644 --- a/src/model/types.generated.ts +++ b/src/model/types.generated.ts @@ -3265,6 +3265,12 @@ export type Wall = { * Additiv; Alt-Projekte laden unverändert (Default = "both"). */ sliceTermination?: SliceTermination; + /** + * An Dach anschliessen ([G2]): `undefined` = automatisch (die Wand endet an der Dach-Unterkante, + * wo ihre Krone darüber liegt — je Schicht, Giebel/Traufe/Grat/Kehle/Gaube), `true` = zusätzlich bis + * unter das Dach verlängert, `false` = Dächer schneiden die Wand nicht. + */ + roofAttach?: boolean; /** * Ansichtsschraffur ([100]): Drehung (Grad) des Oberflächenmusters dieses Elements gegenüber der * Ausrichtung am Element (Default 0). diff --git a/src/panels/ObjectInfoPanel.tsx b/src/panels/ObjectInfoPanel.tsx index 4b26d659..260f0e29 100644 --- a/src/panels/ObjectInfoPanel.tsx +++ b/src/panels/ObjectInfoPanel.tsx @@ -2055,6 +2055,23 @@ export function WallSection({ /> + {/* An Dach anschliessen ([G2]): automatisch endet die Wand an der Dach-Unterkante, "Ja" + verlängert sie bis unter das Dach, "Nein" lässt die Dächer die Wand nicht schneiden. */} +

+ {t("objinfo.wall.roofAttach")} + host.onSetWallRoofAttach(v as "auto" | "on" | "off")} + options={[ + { value: "auto", label: t("objinfo.wall.roofAttach.auto") }, + { value: "on", label: t("objinfo.wall.roofAttach.on") }, + { value: "off", label: t("objinfo.wall.roofAttach.off") }, + ]} + title={t("objinfo.wall.roofAttach.tip")} + width={120} + /> +
+ {/* Aufbau-Typ-Segment. */}
{t("objinfo.wall.buildup")} diff --git a/src/panels/host.ts b/src/panels/host.ts index ebe875cf..82e670e7 100644 --- a/src/panels/host.ts +++ b/src/panels/host.ts @@ -398,6 +398,8 @@ export interface PanelHostValue { * "both" = heutiges Verhalten, "below"/"above" = die Wand endet an der Decke. */ onSetWallSliceTermination: (termination: SliceTermination) => void; + /** An Dach anschliessen ([G2]): "auto" = Default (Wand endet an der Dach-Unterkante). */ + onSetWallRoofAttach: (attach: "auto" | "on" | "off") => void; /** Ansichtsschraffur ([100]) an der gewählten Wand bzw. am gewählten Dach drehen/versetzen. */ onSetSurfacePatternPlacement?: (patch: { surfacePatternAngle?: number; surfacePatternOffset?: { x: number; y: number } }) => void; /** Weist der Wand einen Wandtyp-Preset (mehrschichtiger Aufbau) zu. */ diff --git a/src/plan/toWalls3d/shared.ts b/src/plan/toWalls3d/shared.ts index 349701cd..413eaa7b 100644 --- a/src/plan/toWalls3d/shared.ts +++ b/src/plan/toWalls3d/shared.ts @@ -104,6 +104,11 @@ export interface RWall { * Nur für Boxen ohne Löcher/Öffnungen (render3d `WallInput::top_drop`). */ topDrop?: [number, number]; + /** + * Ebene Oberkante unter einer Dachfläche ([G2]): `[z am Anfang, dz/dx, dz/dy]` (Grundriss-Meter); + * übersteuert `topDrop` (render3d `WallInput::top_plane`). Fehlt = waagrecht. + */ + topPlane?: [number, number, number]; color: RRgb; /** * Immer leer: die Schichten werden TS-seitig in eigene Voll-Boxen zerlegt diff --git a/src/state/selectionInfo.ts b/src/state/selectionInfo.ts index dadb64b6..b56e45d7 100644 --- a/src/state/selectionInfo.ts +++ b/src/state/selectionInfo.ts @@ -124,6 +124,8 @@ export interface WallInfo { layerBoundaries: LayerBoundaryChoice[]; /** Terminierungs-Regel am Deckenanschluss (Default "both" = heutiges Verhalten). */ sliceTermination: SliceTermination; + /** An Dach anschliessen ([G2]): "auto" (Default), "on" (bis unter das Dach verlängern), "off". */ + roofAttach: "auto" | "on" | "off"; wallTypeId: string; /** Aktuelle Gesamtdicke (Meter). */ thickness: number; diff --git a/src/state/usePanelHostBase.ts b/src/state/usePanelHostBase.ts index 5584cced..a475ed89 100644 --- a/src/state/usePanelHostBase.ts +++ b/src/state/usePanelHostBase.ts @@ -802,6 +802,11 @@ export function usePanelHostBase(opts: { sliceTermination: termination === "both" ? undefined : termination, }); }, + onSetWallRoofAttach: (attach) => { + if (selection?.kind === "wall") + // "auto" ist der Default ⇒ als undefined speichern. + updateWall(selection.id, { roofAttach: attach === "auto" ? undefined : attach === "on" }); + }, onSetWallType: (wallTypeId) => { if (selection?.kind === "wall") updateWall(selection.id, { wallTypeId });