From 7db634d7d5269bfc490fe19a68bcf0f16d098c7b Mon Sep 17 00:00:00 2001 From: karim Date: Fri, 23 Oct 2026 11:49:04 +0200 Subject: [PATCH] 3D: Schraffur der Wand-Oberseite folgt wie im 2D der Wandachse (topAngle; Daemmung nicht mehr 90 Grad verdreht) --- src-tauri/render3d/src/lib.rs | 2 +- src-tauri/render3d/src/mesh.rs | 2 +- src-tauri/render3d/src/section_fill.rs | 11 ++++++----- src-tauri/render3d/src/types.rs | 5 +++++ src/plan/toWalls3d.test.ts | 21 +++++++++++++++++++++ src/plan/toWalls3d/bands.ts | 14 +++++++++++++- src/plan/toWalls3d/shared.ts | 23 ++++++++++++++++++++++- 7 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src-tauri/render3d/src/lib.rs b/src-tauri/render3d/src/lib.rs index 64170e2e..0820ca6e 100644 --- a/src-tauri/render3d/src/lib.rs +++ b/src-tauri/render3d/src/lib.rs @@ -168,7 +168,7 @@ mod tests { /// `wall_x` mit gesetzter Bauteil-Schraffur (Voraussetzung fuer die Kappen). fn wall_x_hatched(len: f32, thickness: f32, height: f32) -> WallInput { WallInput { - hatch: Some(Hatch { pattern: 3, angle: 45.0, scale: 1.0, line_weight: 0.13 }), + hatch: Some(Hatch { pattern: 3, angle: 45.0, scale: 1.0, line_weight: 0.13, top_angle: None }), ..wall_x(len, thickness, height) } } diff --git a/src-tauri/render3d/src/mesh.rs b/src-tauri/render3d/src/mesh.rs index e97f0601..ce8f8194 100644 --- a/src-tauri/render3d/src/mesh.rs +++ b/src-tauri/render3d/src/mesh.rs @@ -989,7 +989,7 @@ pub fn build_free_wall_end_caps(walls: &[WallInput]) -> Vec { let c = |p: Point2| -> [f32; 9] { [ p[0], y, p[1], p[0], p[1], - hatch.pattern as f32, hatch.angle.to_radians(), hatch.scale.max(0.05), + hatch.pattern as f32, hatch.top_angle.unwrap_or(hatch.angle).to_radians(), hatch.scale.max(0.05), hatch.line_weight.max(0.0), ] }; diff --git a/src-tauri/render3d/src/section_fill.rs b/src-tauri/render3d/src/section_fill.rs index 5e32aedd..f2f36796 100644 --- a/src-tauri/render3d/src/section_fill.rs +++ b/src-tauri/render3d/src/section_fill.rs @@ -304,6 +304,7 @@ mod tests { angle: 90.0, scale: 2.0, line_weight: 0.5, + top_angle: None, }), cut: None, }; @@ -377,7 +378,7 @@ mod tests { layers: None, holes: vec![], material_index: None, - hatch: Some(Hatch { pattern: 2, angle: 0.0, scale: 1.0, line_weight: 0.13 }), + hatch: Some(Hatch { pattern: 2, angle: 0.0, scale: 1.0, line_weight: 0.13, top_angle: None }), cut: Some(CutBandMeta { join_priority: Some(50), component_id: Some("brick".into()), @@ -393,7 +394,7 @@ mod tests { z_bottom: 2.0, z_top: 2.4, color: [0.8, 0.8, 0.8], - hatch: Some(Hatch { pattern: 1, angle: 0.0, scale: 1.0, line_weight: 0.13 }), + hatch: Some(Hatch { pattern: 1, angle: 0.0, scale: 1.0, line_weight: 0.13, top_angle: None }), cut: Some(CutBandMeta { join_priority: Some(100), component_id: Some("concrete".into()), @@ -451,7 +452,7 @@ mod tests { layers: None, holes: vec![], material_index: None, - hatch: Some(Hatch { pattern: 2, angle: 0.0, scale: 1.0, line_weight: 0.13 }), + hatch: Some(Hatch { pattern: 2, angle: 0.0, scale: 1.0, line_weight: 0.13, top_angle: None }), cut: Some(CutBandMeta { join_priority: Some(50), component_id: Some("brick".into()), @@ -467,7 +468,7 @@ mod tests { z_bottom: 1.0, z_top: 1.06, color: [0.8, 0.8, 0.8], - hatch: Some(Hatch { pattern: 3, angle: 0.0, scale: 1.0, line_weight: 0.13 }), + hatch: Some(Hatch { pattern: 3, angle: 0.0, scale: 1.0, line_weight: 0.13, top_angle: None }), cut: Some(CutBandMeta { join_priority: Some(30), component_id: Some("screed".into()), @@ -482,7 +483,7 @@ mod tests { z_bottom: 0.96, z_top: 1.0, color: [0.8, 0.8, 0.8], - hatch: Some(Hatch { pattern: 4, angle: 0.0, scale: 1.0, line_weight: 0.13 }), + hatch: Some(Hatch { pattern: 4, angle: 0.0, scale: 1.0, line_weight: 0.13, top_angle: None }), cut: Some(CutBandMeta { join_priority: Some(20), component_id: Some("insulation".into()), diff --git a/src-tauri/render3d/src/types.rs b/src-tauri/render3d/src/types.rs index ea812e5a..58701bb0 100644 --- a/src-tauri/render3d/src/types.rs +++ b/src-tauri/render3d/src/types.rs @@ -47,6 +47,11 @@ pub struct Hatch { /// `thin` 0.13 mm). Default 0.13 (Alt-Verhalten/Haarlinie). #[serde(default = "default_hatch_line_weight", rename = "lineWeight")] pub line_weight: f32, + /// Musterdrehung (Grad, Modell-Winkel gegen den Uhrzeigersinn) fuer die Wand-OBERSEITE + /// (Draufsicht, Weltkoordinaten x/z): wie im 2D-Grundriss relativ zur Wandachse. Fehlt + /// es, gilt `angle`. + #[serde(default, rename = "topAngle")] + pub top_angle: Option, } fn default_hatch_scale() -> f32 { diff --git a/src/plan/toWalls3d.test.ts b/src/plan/toWalls3d.test.ts index 82b0a4c3..60501813 100644 --- a/src/plan/toWalls3d.test.ts +++ b/src/plan/toWalls3d.test.ts @@ -2763,3 +2763,24 @@ describe("emitStairs — gerade Betontreppe im Schnitt: glatte Soffit-Untersicht } }); }); + +describe("Wand-Schraffur in der Draufsicht (topAngle)", () => { + it("relativeToWall-Muster folgt der Wandachse: Wand längs x → 0°, längs y → 90°", () => { + const p: Project = { + ...sampleProject, + hatches: sampleProject.hatches.map((h) => + h.id === "sia-insulation" ? { ...h, angle: 0, relativeToWall: true } : h, + ), + }; + const { walls } = projectToModel3d(p); + const ins = walls.filter((w) => w.hatch && w.hatch.pattern === 2 && w.hatch.relativeToWall && w.hatch.baseAngle === 0); + const along = (w: (typeof walls)[number], axis: 0 | 1) => + Math.abs(w.end[axis] - w.start[axis]) > Math.abs(w.end[1 - axis] - w.start[1 - axis]); + const alongX = ins.filter((w) => along(w, 0)); + const alongY = ins.filter((w) => along(w, 1)); + expect(alongX.length).toBeGreaterThan(0); + expect(alongY.length).toBeGreaterThan(0); + for (const w of alongX) expect(Math.abs(((w.hatch!.topAngle ?? 99) + 360) % 180)).toBeLessThan(1e-6); + for (const w of alongY) expect(Math.abs((((w.hatch!.topAngle ?? 0) % 180) + 180) % 180 - 90)).toBeLessThan(1e-6); + }); +}); diff --git a/src/plan/toWalls3d/bands.ts b/src/plan/toWalls3d/bands.ts index bcb4d48d..9740cd23 100644 --- a/src/plan/toWalls3d/bands.ts +++ b/src/plan/toWalls3d/bands.ts @@ -182,6 +182,18 @@ function resolveWallBands(project: Project, wall: Wall, layered = true): WallBan } } +/** + * Setzt `topAngle` (Draufsicht): wie der 2D-Grundriss — das Muster folgt der Wandachse + * (`relativeToWall`), `resolveHatch` zieht den Wandwinkel ab (SVG-Konvention, y nach unten); + * render3d rechnet in Modell-Winkeln (gegen den Uhrzeigersinn), daher das Vorzeichen. + */ +function withTopAngle(h: RHatch, dx: number, dy: number): RHatch { + if (h.baseAngle === undefined) return h; + const wallAngle = (Math.atan2(dy, dx) * 180) / Math.PI; + const svgAngle = h.relativeToWall ? h.baseAngle - wallAngle : h.baseAngle; + return { ...h, topAngle: -svgAngle }; +} + /** * Hängt eine Wand-Schicht-Box an: das Achsenstück [from..to] (Meter ab * Wand-Startpunkt) über den Höhenbereich [zBottom..zTop], quer um `normalOffset` @@ -245,7 +257,7 @@ function pushSegment( color, layers: [], wallId, - ...(hatch ? { hatch } : {}), + ...(hatch ? { hatch: withTopAngle(hatch, dx, dy) } : {}), ...(materialIndex != null ? { materialIndex } : {}), ...(holes && holes.length > 0 ? { holes } : {}), ...(cut ? { cut } : {}), diff --git a/src/plan/toWalls3d/shared.ts b/src/plan/toWalls3d/shared.ts index 74c6c365..97f8926f 100644 --- a/src/plan/toWalls3d/shared.ts +++ b/src/plan/toWalls3d/shared.ts @@ -47,6 +47,17 @@ export interface RHatch { * Schraffur einstellbar ist (z. B. SIA `hatch-hair` 0.02 mm vs. `thin` 0.13 mm). */ lineWeight?: number; + /** + * Nur TS-intern: Grundwinkel der Schraffur (SVG-Konvention, vor Wandbezug) und ob das Muster + * der Wandachse folgt (`relativeToWall`). `pushSegment` leitet daraus {@link topAngle} ab. + */ + baseAngle?: number; + relativeToWall?: boolean; + /** + * Musterdrehung (Grad, Modell-Winkel gegen den Uhrzeigersinn) für die Wand-OBERSEITE in der + * Draufsicht — wie im 2D-Grundriss relativ zur Wandachse (render3d::Hatch.topAngle). + */ + topAngle?: number; } /** Bildet ein 2D-{@link HatchPattern} auf die Muster-Id von {@link RHatch}/CAP_WGSL ab. */ @@ -89,7 +100,17 @@ export function resolveComponentHatch( // (`HatchRender.angle`, bereits relativeToWall-korrigiert) UND die Musterlinien- // Stärke (`lineWeight`, aus dem LineStyle) — nicht mehr den rohen Hatch-Winkel. const hr = resolveHatch(project, comp.hatchId, axisAngleDeg); - return { pattern: hatchPatternId(hr.pattern), angle: hr.angle, scale: hr.scale, lineWeight: hr.lineWeight }; + // Wandbezug für die Draufsicht: Grundwinkel + ob das Muster der Wandachse folgt. + const abs = resolveHatch(project, comp.hatchId, undefined); + const relativeToWall = resolveHatch(project, comp.hatchId, 90).angle !== abs.angle; + return { + pattern: hatchPatternId(hr.pattern), + angle: hr.angle, + scale: hr.scale, + lineWeight: hr.lineWeight, + baseAngle: abs.angle, + relativeToWall, + }; } catch { return undefined; }