From 9f30f8788b01ad489864e3457f525034dad521d4 Mon Sep 17 00:00:00 2001 From: karim Date: Fri, 23 Oct 2026 13:24:27 +0200 Subject: [PATCH] Extrusion: Fase an den Ecken (B-Rep), Panel-Feld --- src-tauri/trucksolid/src/brep.rs | 63 ++++++++++++++++++++++++++---- src/engine/truckSolid.ts | 2 + src/i18n/de.ts | 1 + src/i18n/en.ts | 1 + src/model/types.ts | 2 + src/panels/ObjectInfoPanel.tsx | 19 +++++++++ src/panels/host.ts | 2 + src/plan/extrudedSolidSpec.test.ts | 6 +++ src/plan/extrudedSolidSpec.ts | 4 +- src/plan/toWalls3d/extrusions.ts | 2 +- src/state/selectionInfo.ts | 3 ++ src/state/usePanelHostBase.ts | 11 ++++++ 12 files changed, 107 insertions(+), 9 deletions(-) diff --git a/src-tauri/trucksolid/src/brep.rs b/src-tauri/trucksolid/src/brep.rs index 1646f043..4c9743b5 100644 --- a/src-tauri/trucksolid/src/brep.rs +++ b/src-tauri/trucksolid/src/brep.rs @@ -61,6 +61,11 @@ pub enum SolidSpec { /// Kreisbogen (exakte Zylinderfläche, auch im STEP) verrundet. 0 = scharf. #[serde(default, rename = "cornerRadius")] corner_radius: f64, + /// Fase (Meter) an den Ecken der Aussenkontur: gerade Abschrägung im Abstand `chamfer` + /// von der Ecke. 0 = scharf. Vor dem Eckenradius angewandt (beides zugleich: Radius + /// auf der gefasten Kontur). + #[serde(default)] + chamfer: f64, }, /// Prisma in einer beliebigen Ebene: Ring/Löcher in (u,v)-Koordinaten, platziert über /// `origin` + `uAxis`/`vAxis` (3D-Richtungen), extrudiert um `depth` entlang u×v. @@ -205,12 +210,37 @@ fn rounded_ring_wire(ring: &[(f64, f64)], radius: f64, z: f64) -> Wire { wire } +/// Ecken der Kontur im Abstand `d` abschrägen (je Ecke auf die Hälfte der kürzeren Kante begrenzt). +fn chamfer_ring(ring: &[(f64, f64)], d: f64) -> Vec<(f64, f64)> { + let n = ring.len(); + let mut out = Vec::with_capacity(n * 2); + for i in 0..n { + let (p0, v, p1) = (ring[(i + n - 1) % n], ring[i], ring[(i + 1) % n]); + let (a, b) = ((p0.0 - v.0, p0.1 - v.1), (p1.0 - v.0, p1.1 - v.1)); + let (la, lb) = (a.0.hypot(a.1), b.0.hypot(b.1)); + if la < 1e-9 || lb < 1e-9 { + out.push(v); + continue; + } + let cos_t = (a.0 * b.0 + a.1 * b.1) / (la * lb); + if cos_t < -1.0 + 1e-6 { + out.push(v); // gestreckt: keine Ecke + continue; + } + let t = d.min(la / 2.0).min(lb / 2.0); + out.push((v.0 + a.0 / la * t, v.1 + a.1 / la * t)); + out.push((v.0 + b.0 / lb * t, v.1 + b.1 / lb * t)); + } + out +} + fn extrude( points: &[f64], holes: &[Vec], height: f64, z0: f64, corner_radius: f64, + chamfer: f64, ) -> Res { if height <= 0.0 { return Err("height muss > 0 sein".into()); @@ -219,6 +249,9 @@ fn extrude( if signed_area(&outer) < 0.0 { outer.reverse(); } + if chamfer > 1e-6 { + outer = chamfer_ring(&outer, chamfer); + } let mut wires = vec![if corner_radius > 1e-6 { rounded_ring_wire(&outer, corner_radius, z0) } else { @@ -443,8 +476,8 @@ pub fn bool_op(a: &Solid, b: &Solid, op: BoolKind) -> Res { /// Baut den Volumenkörper aus der Spezifikation. pub fn build_solid(spec: &SolidSpec) -> Res { match spec { - SolidSpec::Extrude { points, holes, height, z0, corner_radius } => { - extrude(points, holes, *height, *z0, *corner_radius) + SolidSpec::Extrude { points, holes, height, z0, corner_radius, chamfer } => { + extrude(points, holes, *height, *z0, *corner_radius, *chamfer) } SolidSpec::ExtrudePlane { points, holes, origin, u_axis, v_axis, depth } => { extrude_plane(points, holes, *origin, *u_axis, *v_axis, *depth) @@ -641,7 +674,7 @@ mod tests { holes: vec![ring(1.0, 1.0, 2.0, 2.0)], height: 2.0, z0: 0.0, - corner_radius: 0.0, + corner_radius: 0.0, chamfer: 0.0, }; let m = solid_mesh_core(&spec, 0.01).unwrap(); assert!((volume(&m) - (12.0 - 1.0) * 2.0).abs() < 1e-3, "{}", volume(&m)); @@ -656,12 +689,28 @@ mod tests { height: 2.0, z0: 0.0, corner_radius: r, + chamfer: 0.0, }; let m = solid_mesh_core(&spec, 0.001).unwrap(); let area = 12.0 - (4.0 - PI) * r * r; assert!((volume(&m) - area * 2.0).abs() / (area * 2.0) < 0.003, "{}", volume(&m)); } + #[test] + fn fase_schneidet_vier_dreiecke_ab() { + let spec = SolidSpec::Extrude { + points: ring(0.0, 0.0, 4.0, 3.0), + holes: vec![], + height: 2.0, + z0: 0.0, + corner_radius: 0.0, + chamfer: 0.5, + }; + let m = solid_mesh_core(&spec, 0.01).unwrap(); + let area = 12.0 - 4.0 * 0.5 * 0.5 * 0.5; // 4 Eckdreiecke à 0,125 + assert!((volume(&m) - area * 2.0).abs() < 1e-3, "{}", volume(&m)); + } + #[test] fn eckenradius_wird_auf_die_halbe_kante_begrenzt() { // Radius 10 an einem 1×1-Quadrat → Kreis mit Radius 0,5 (Stadium-Grenzfall), kein Fehler. @@ -670,7 +719,7 @@ mod tests { holes: vec![], height: 1.0, z0: 0.0, - corner_radius: 10.0, + corner_radius: 10.0, chamfer: 0.0, }; let m = solid_mesh_core(&spec, 0.001).unwrap(); let expect = PI * 0.25; @@ -684,7 +733,7 @@ mod tests { holes: vec![], height: 2.0, z0: 0.0, - corner_radius: 0.5, + corner_radius: 0.5, chamfer: 0.0, }; let step = export_step_core(&[spec], &StepHeader::default()).unwrap(); let back = import_step_core(&step, 0.001).unwrap(); @@ -820,8 +869,8 @@ mod dbg_step { let ring = |x0: f64, y0: f64, x1: f64, y1: f64| vec![x0, y0, x1, y0, x1, y1, x0, y1]; let cases: Vec<(&str, SolidSpec)> = vec![ ("cuboid", SolidSpec::Cuboid { min: [0.0; 3], max: [2.0, 1.0, 1.0] }), - ("extrude_hole", SolidSpec::Extrude { points: ring(0.0, 0.0, 4.0, 3.0), holes: vec![ring(1.0, 1.0, 2.0, 2.0)], height: 2.0, z0: 0.0, corner_radius: 0.0 }), - ("extrude_round", SolidSpec::Extrude { points: ring(0.0, 0.0, 4.0, 3.0), holes: vec![], height: 2.0, z0: 0.0, corner_radius: 0.5 }), + ("extrude_hole", SolidSpec::Extrude { points: ring(0.0, 0.0, 4.0, 3.0), holes: vec![ring(1.0, 1.0, 2.0, 2.0)], height: 2.0, z0: 0.0, corner_radius: 0.0, chamfer: 0.0 }), + ("extrude_round", SolidSpec::Extrude { points: ring(0.0, 0.0, 4.0, 3.0), holes: vec![], height: 2.0, z0: 0.0, corner_radius: 0.5, chamfer: 0.0 }), ("cylinder", SolidSpec::Cylinder { cx: 0.0, cy: 0.0, z0: 0.0, r: 1.0, height: 2.0 }), ("cone", SolidSpec::Cone { cx: 0.0, cy: 0.0, z0: 0.0, r: 1.0, height: 3.0 }), ("sphere", SolidSpec::Sphere { center: [0.0; 3], r: 1.0 }), diff --git a/src/engine/truckSolid.ts b/src/engine/truckSolid.ts index 412ef9c0..cd6fce9c 100644 --- a/src/engine/truckSolid.ts +++ b/src/engine/truckSolid.ts @@ -91,6 +91,8 @@ export type SolidSpec = z0?: number; /** Eckenradius (m) der Aussenkontur — echte Kreisbögen, auch im STEP. */ cornerRadius?: number; + /** Fase (m) an den Ecken der Aussenkontur (gerade Abschrägung). */ + chamfer?: number; } | { kind: "extrudePlane"; diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 681eab77..5be2f29c 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -710,6 +710,7 @@ export const de = { "objinfo.extrudedSolid.height": "Höhe", "objinfo.extrudedSolid.taper": "Verjüngung", "objinfo.extrudedSolid.cornerRadius": "Eckenradius", + "objinfo.extrudedSolid.chamfer": "Fase", "objinfo.extrudedSolid.brep": "B-Rep-Körper", "objinfo.extrudedSolid.area": "Grundfläche", "objinfo.extrudedSolid.floor": "Geschoss", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 5607b961..096dba0c 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -706,6 +706,7 @@ export const en: Record = { "objinfo.extrudedSolid.height": "Height", "objinfo.extrudedSolid.taper": "Taper", "objinfo.extrudedSolid.cornerRadius": "Corner radius", + "objinfo.extrudedSolid.chamfer": "Chamfer", "objinfo.extrudedSolid.brep": "B-rep solid", "objinfo.extrudedSolid.area": "Footprint area", "objinfo.extrudedSolid.floor": "Floor", diff --git a/src/model/types.ts b/src/model/types.ts index fd379404..bd6b5dc5 100644 --- a/src/model/types.ts +++ b/src/model/types.ts @@ -2220,6 +2220,8 @@ export interface ExtrudedSolid { * verrundet (truck-B-Rep, auch im STEP-Export exakt). Fehlt/0 = scharfe Ecken. */ cornerRadius?: number; + /** Fase (Meter) an den Ecken der Aussenkontur — gerade Abschrägung; fehlt/0 = scharf. */ + chamfer?: number; /** * B-Rep-Körper statt Profil-Extrusion (Grundkörper Kugel/Zylinder/Kegel/Torus/Quader … * oder beliebige `trucksolid`-Spezifikation). `spec` ist eine `SolidSpec` diff --git a/src/panels/ObjectInfoPanel.tsx b/src/panels/ObjectInfoPanel.tsx index 0d3563ca..3cbea4c1 100644 --- a/src/panels/ObjectInfoPanel.tsx +++ b/src/panels/ObjectInfoPanel.tsx @@ -694,6 +694,25 @@ export function ExtrudedSolidSection({ )} + {/* Fase (editierbar, ≥ 0): gerade Abschrägung der Ecken der Aussenkontur. */} + {!solid.brepLabel && ( +
+ {t("objinfo.extrudedSolid.chamfer")} + { + const v = Number(e.target.value); + if (Number.isFinite(v) && v >= 0) host.onSetExtrudedSolidChamfer(v); + }} + title={t("objinfo.extrudedSolid.chamfer")} + /> +
+ )} + {/* Verjüngung (editierbar, 0..1) — löst eine Re-Extrusion (truck-WASM) aus. */} {!solid.brepLabel && (
diff --git a/src/panels/host.ts b/src/panels/host.ts index 77236e6f..0ba1ecbe 100644 --- a/src/panels/host.ts +++ b/src/panels/host.ts @@ -534,6 +534,8 @@ export interface PanelHostValue { onSetExtrudedSolidTaper: (taper: number) => void; /** Setzt den Eckenradius der Aussenkontur (Meter, ≥ 0) — echte Kreisbögen. */ onSetExtrudedSolidCornerRadius: (radius: number) => void; + /** Setzt die Fase der Aussenkontur (Meter, ≥ 0). */ + onSetExtrudedSolidChamfer: (chamfer: number) => void; // ── Stützen-Attribute (Tragwerk; nur die selektierte Stütze) ──────────── /** Wechselt das Profil (Rechteck/Kreis); leitet ein sinnvolles Mass ab. */ diff --git a/src/plan/extrudedSolidSpec.test.ts b/src/plan/extrudedSolidSpec.test.ts index 259ad49b..274f10c2 100644 --- a/src/plan/extrudedSolidSpec.test.ts +++ b/src/plan/extrudedSolidSpec.test.ts @@ -17,6 +17,12 @@ describe("extrudedSolidSpec", () => { expect(extrudedSolidSpec(s, 0)).toMatchObject({ kind: "extrude", cornerRadius: 0.3 }); }); + it("Fase schaltet ebenfalls auf den B-Rep-Pfad und landet in der Spezifikation", () => { + const s = { ...base, chamfer: 0.2 }; + expect(needsBrepPath(s)).toBe(true); + expect(extrudedSolidSpec(s, 0)).toMatchObject({ kind: "extrude", chamfer: 0.2 }); + }); + it("Verjüngung → Loft, volle Verjüngung (Pyramide) → keine B-Rep-Beschreibung", () => { expect(extrudedSolidSpec({ ...base, taper: 0.5 }, 0)?.kind).toBe("loft"); expect(extrudedSolidSpec({ ...base, taper: 1 }, 0)).toBeNull(); diff --git a/src/plan/extrudedSolidSpec.ts b/src/plan/extrudedSolidSpec.ts index 80e1d535..ea3e9f1f 100644 --- a/src/plan/extrudedSolidSpec.ts +++ b/src/plan/extrudedSolidSpec.ts @@ -12,7 +12,8 @@ import type { SolidSpec } from "../engine/truckSolid"; */ export function needsBrepPath(solid: ExtrudedSolid): boolean { if (solid.brep) return true; - return (solid.cornerRadius ?? 0) > 1e-9 && !solid.circle && (solid.taper ?? 0) < 1e-6; + const rounded = (solid.cornerRadius ?? 0) > 1e-9 || (solid.chamfer ?? 0) > 1e-9; + return rounded && !solid.circle && (solid.taper ?? 0) < 1e-6; } /** @@ -56,6 +57,7 @@ export function extrudedSolidSpec(solid: ExtrudedSolid, baseZ: number): SolidSpe height: solid.height, z0: baseZ, ...((solid.cornerRadius ?? 0) > 0 ? { cornerRadius: solid.cornerRadius } : {}), + ...((solid.chamfer ?? 0) > 0 ? { chamfer: solid.chamfer } : {}), }; } if (taper < 1 - 1e-6) { diff --git a/src/plan/toWalls3d/extrusions.ts b/src/plan/toWalls3d/extrusions.ts index 8ebc060b..82c20208 100644 --- a/src/plan/toWalls3d/extrusions.ts +++ b/src/plan/toWalls3d/extrusions.ts @@ -36,7 +36,7 @@ const truckMeshCache = new Map(); function extrudedSolidSignature(solid: ExtrudedSolid): string { const brep = solid.brep ? `${JSON.stringify(solid.brep.spec)}@${solid.brep.origin.x},${solid.brep.origin.y}` : ""; - return `${solid.height}|${solid.taper ?? 0}|${solid.cornerRadius ?? 0}|${brep}|${solid.points.map((p) => `${p.x},${p.y}`).join(";")}`; + return `${solid.height}|${solid.taper ?? 0}|${solid.cornerRadius ?? 0}|${solid.chamfer ?? 0}|${brep}|${solid.points.map((p) => `${p.x},${p.y}`).join(";")}`; } export function emitExtrudedSolids(project: Project): RMesh[] { diff --git a/src/state/selectionInfo.ts b/src/state/selectionInfo.ts index 52e52b39..e9ed3110 100644 --- a/src/state/selectionInfo.ts +++ b/src/state/selectionInfo.ts @@ -315,6 +315,8 @@ export interface ExtrudedSolidInfo { taper: number; /** Eckenradius der Aussenkontur (m), editierbar (0 = scharf). */ cornerRadius: number; + /** Fase an den Ecken der Aussenkontur (m), editierbar (0 = scharf). */ + chamfer: number; /** B-Rep-Körper (Grundkörper): Ecken-/Verjüngungsfelder entfallen. */ brepLabel?: string; /** Grundfläche des Profils (m²). */ @@ -1047,6 +1049,7 @@ function extrudedSolidSelection(project: Project, s: ExtrudedSolid): Selection { height: s.height, taper: s.taper ?? 0, cornerRadius: s.cornerRadius ?? 0, + chamfer: s.chamfer ?? 0, ...(s.brep ? { brepLabel: s.brep.label ?? "B-Rep" } : {}), area: polygonArea(s.points), floorId: s.levelId, diff --git a/src/state/usePanelHostBase.ts b/src/state/usePanelHostBase.ts index c6861b93..1b1e3bdc 100644 --- a/src/state/usePanelHostBase.ts +++ b/src/state/usePanelHostBase.ts @@ -1040,6 +1040,17 @@ export function usePanelHostBase(opts: { ), })); }, + onSetExtrudedSolidChamfer: (chamfer) => { + if (selection?.kind !== "extrudedSolid") return; + const c = Math.max(0, chamfer); + const id = selection.id; + setProject((p) => ({ + ...p, + extrudedSolids: (p.extrudedSolids ?? []).map((s) => + s.id === id ? { ...s, chamfer: c > 0 ? c : undefined } : s, + ), + })); + }, // ── Stützen-Attribute (Tragwerk; nur bei selektierter Stütze) ────────── onSetColumnProfileKind: (kind) => { if (selection?.kind !== "column") return;