Extrusion: Fase an den Ecken (B-Rep), Panel-Feld

This commit is contained in:
karim committed 2026-10-23 13:24:27 +02:00
1 parent 3c7589269d
commit 9f30f8788b
12 files changed
+107 -9

No files matched your search

+56 -7
View File
@@ -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<f64>],
height: f64,
z0: f64,
corner_radius: f64,
chamfer: f64,
) -> Res<Solid> {
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<Solid> {
/// Baut den Volumenkörper aus der Spezifikation.
pub fn build_solid(spec: &SolidSpec) -> Res<Solid> {
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 }),
+2
View File
@@ -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";
+1
View File
@@ -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",
+1
View File
@@ -706,6 +706,7 @@ export const en: Record<TranslationKey, string> = {
"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",
+2
View File
@@ -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`
+19
View File
@@ -694,6 +694,25 @@ export function ExtrudedSolidSection({
</div>
)}
{/* Fase (editierbar, ≥ 0): gerade Abschrägung der Ecken der Aussenkontur. */}
{!solid.brepLabel && (
<div className="objinfo-field">
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.chamfer")}</span>
<input
type="number"
className="objinfo-text"
step={0.05}
min={0}
value={solid.chamfer}
onChange={(e) => {
const v = Number(e.target.value);
if (Number.isFinite(v) && v >= 0) host.onSetExtrudedSolidChamfer(v);
}}
title={t("objinfo.extrudedSolid.chamfer")}
/>
</div>
)}
{/* Verjüngung (editierbar, 0..1) — löst eine Re-Extrusion (truck-WASM) aus. */}
{!solid.brepLabel && (
<div className="objinfo-field">
+2
View File
@@ -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. */
+6
View File
@@ -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();
+3 -1
View File
@@ -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) {
+1 -1
View File
@@ -36,7 +36,7 @@ const truckMeshCache = new Map<string, TruckCacheEntry>();
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[] {
+3
View File
@@ -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,
+11
View File
@@ -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;