From f96470c911221068bc21b2ba9bdf1b7e5093ed5f Mon Sep 17 00:00:00 2001 From: karim Date: Fri, 23 Oct 2026 13:17:55 +0200 Subject: [PATCH] Extrusion: Eckenradius (B-Rep-Kreisboegen) + B-Rep-Grundkoerper-Feld, Panel-Feld, STEP-Export ueber gemeinsame Spezifikation --- src/export/exportStep.ts | 24 ++-------- src/i18n/de.ts | 2 + src/i18n/en.ts | 2 + src/model/types.ts | 14 ++++++ src/panels/ObjectInfoPanel.tsx | 28 +++++++++++ src/panels/host.ts | 2 + src/plan/extrudedSolidSpec.test.ts | 44 ++++++++++++++++++ src/plan/extrudedSolidSpec.ts | 74 ++++++++++++++++++++++++++++++ src/plan/toWalls3d/extrusions.ts | 20 +++++--- src/state/selectionInfo.ts | 6 +++ src/state/usePanelHostBase.ts | 11 +++++ 11 files changed, 199 insertions(+), 28 deletions(-) create mode 100644 src/plan/extrudedSolidSpec.test.ts create mode 100644 src/plan/extrudedSolidSpec.ts diff --git a/src/export/exportStep.ts b/src/export/exportStep.ts index f75bc968..adba003c 100644 --- a/src/export/exportStep.ts +++ b/src/export/exportStep.ts @@ -19,6 +19,7 @@ import { projectToModel3d } from "../plan/toWalls3d"; import type { RWall } from "../plan/toWalls3d"; import { roofBaseElevation, roofGeometry } from "../geometry/roof"; import { exportStepSolids } from "../engine/truckSolid"; +import { extrudedSolidSpec } from "../plan/extrudedSolidSpec"; import type { SolidSpec } from "../engine/truckSolid"; const EPS = 1e-6; @@ -147,7 +148,6 @@ export function projectSolidSpecs(project: Project): SolidSpec[] { } for (const solid of project.extrudedSolids ?? []) { - if (solid.points.length < 3 || solid.height <= 0) continue; let baseZ = 0; if (solid.levelId) { try { @@ -156,26 +156,8 @@ export function projectSolidSpecs(project: Project): SolidSpec[] { baseZ = 0; } } - const taper = Math.min(1, Math.max(0, solid.taper ?? 0)); - const flat = solid.points.flatMap((p) => [p.x, p.y]); - if (taper < 1e-6) { - out.push({ kind: "extrude", points: flat, height: solid.height, z0: baseZ }); - } else if (taper < 1 - 1e-6) { - // Verjüngung: oberer Ring linear zum Schwerpunkt skaliert (Loft Boden → Kopf). - const cx = solid.points.reduce((s, p) => s + p.x, 0) / solid.points.length; - const cy = solid.points.reduce((s, p) => s + p.y, 0) / solid.points.length; - const top = solid.points.flatMap((p) => [ - cx + (p.x - cx) * (1 - taper), - cy + (p.y - cy) * (1 - taper), - ]); - out.push({ - kind: "loft", - sections: [ - { z: baseZ, points: flat }, - { z: baseZ + solid.height, points: top }, - ], - }); - } + const spec = extrudedSolidSpec(solid, baseZ); + if (spec) out.push(spec); } return out; } diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 28872088..018920f4 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -709,6 +709,8 @@ export const de = { "objinfo.extrudedSolid.section": "Extrusion", "objinfo.extrudedSolid.height": "Höhe", "objinfo.extrudedSolid.taper": "Verjüngung", + "objinfo.extrudedSolid.cornerRadius": "Eckenradius", + "objinfo.extrudedSolid.brep": "B-Rep-Körper", "objinfo.extrudedSolid.area": "Grundfläche", "objinfo.extrudedSolid.floor": "Geschoss", "objinfo.rotate": "Drehen", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 4b4f9dc7..dbea96cf 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -705,6 +705,8 @@ export const en: Record = { "objinfo.extrudedSolid.section": "Extrusion", "objinfo.extrudedSolid.height": "Height", "objinfo.extrudedSolid.taper": "Taper", + "objinfo.extrudedSolid.cornerRadius": "Corner radius", + "objinfo.extrudedSolid.brep": "B-rep solid", "objinfo.extrudedSolid.area": "Footprint area", "objinfo.extrudedSolid.floor": "Floor", "objinfo.rotate": "Rotate", diff --git a/src/model/types.ts b/src/model/types.ts index 4131f68b..fd379404 100644 --- a/src/model/types.ts +++ b/src/model/types.ts @@ -2215,6 +2215,20 @@ export interface ExtrudedSolid { * Pyramide bei Polygon-Profil). Linear zum Profil-Schwerpunkt skaliert. */ taper?: number; + /** + * Eckenradius (Meter) der Aussenkontur: jede Ecke wird durch einen echten Kreisbogen + * verrundet (truck-B-Rep, auch im STEP-Export exakt). Fehlt/0 = scharfe Ecken. + */ + cornerRadius?: number; + /** + * B-Rep-Körper statt Profil-Extrusion (Grundkörper Kugel/Zylinder/Kegel/Torus/Quader … + * oder beliebige `trucksolid`-Spezifikation). `spec` ist eine `SolidSpec` + * (`engine/truckSolid.ts`) in LOKALEN Koordinaten (Z ab der Geschoss-UK); `origin` ist der + * Wert von `points[0]` bei der Erzeugung — die aktuelle Verschiebung ergibt sich aus + * `points[0] − origin`, sodass Verschieben/Kopieren das Profil mitnimmt. `points` bleibt die + * Grundriss-Fläche (Auswahl/2D-Umriss), `height` die Körperhöhe. + */ + brep?: { spec: Record; origin: Vec2; label?: string }; } // ── Stütze (Column, Tragwerk) ────────────────────────────────────────────── diff --git a/src/panels/ObjectInfoPanel.tsx b/src/panels/ObjectInfoPanel.tsx index 330830b0..0d3563ca 100644 --- a/src/panels/ObjectInfoPanel.tsx +++ b/src/panels/ObjectInfoPanel.tsx @@ -668,7 +668,34 @@ export function ExtrudedSolidSection({ /> + {solid.brepLabel && ( +
+ {t("objinfo.extrudedSolid.brep")} + {solid.brepLabel} +
+ )} + + {/* Eckenradius (editierbar, ≥ 0): echte Kreisbögen an den Ecken der Aussenkontur. */} + {!solid.brepLabel && ( +
+ {t("objinfo.extrudedSolid.cornerRadius")} + { + const v = Number(e.target.value); + if (Number.isFinite(v) && v >= 0) host.onSetExtrudedSolidCornerRadius(v); + }} + title={t("objinfo.extrudedSolid.cornerRadius")} + /> +
+ )} + {/* Verjüngung (editierbar, 0..1) — löst eine Re-Extrusion (truck-WASM) aus. */} + {!solid.brepLabel && (
{t("objinfo.extrudedSolid.taper")}
+ )} {/* Grundfläche (read-only, abgeleitet). */}
diff --git a/src/panels/host.ts b/src/panels/host.ts index 583b0b94..77236e6f 100644 --- a/src/panels/host.ts +++ b/src/panels/host.ts @@ -532,6 +532,8 @@ export interface PanelHostValue { onSetExtrudedSolidHeight: (height: number) => void; /** Setzt die Verjüngung (0..1) — löst eine Re-Extrusion aus. */ onSetExtrudedSolidTaper: (taper: number) => void; + /** Setzt den Eckenradius der Aussenkontur (Meter, ≥ 0) — echte Kreisbögen. */ + onSetExtrudedSolidCornerRadius: (radius: 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 new file mode 100644 index 00000000..259ad49b --- /dev/null +++ b/src/plan/extrudedSolidSpec.test.ts @@ -0,0 +1,44 @@ +import { describe, expect, it } from "vitest"; +import type { ExtrudedSolid } from "../model/types"; +import { extrudedSolidSpec, needsBrepPath } from "./extrudedSolidSpec"; + +const sq = [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 2 }, { x: 0, y: 2 }]; +const base: ExtrudedSolid = { id: "e1", type: "extrudedSolid", levelId: "eg", points: sq, height: 3 }; + +describe("extrudedSolidSpec", () => { + it("Prisma ohne Besonderheiten bleibt auf dem alten Pfad", () => { + expect(needsBrepPath(base)).toBe(false); + expect(extrudedSolidSpec(base, 1)).toMatchObject({ kind: "extrude", z0: 1, height: 3 }); + }); + + it("Eckenradius schaltet auf den B-Rep-Pfad und landet in der Spezifikation", () => { + const s = { ...base, cornerRadius: 0.3 }; + expect(needsBrepPath(s)).toBe(true); + expect(extrudedSolidSpec(s, 0)).toMatchObject({ kind: "extrude", cornerRadius: 0.3 }); + }); + + 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(); + }); + + it("Kreisprofil → Zylinder bzw. Kegel", () => { + const c = { ...base, circle: { center: { x: 1, y: 1 }, r: 1 } }; + expect(extrudedSolidSpec(c, 0)?.kind).toBe("cylinder"); + expect(extrudedSolidSpec({ ...c, taper: 1 }, 0)?.kind).toBe("cone"); + }); + + it("Grundkörper (brep): Verschiebung ergibt sich aus points[0] − origin, UK = baseZ", () => { + const moved: ExtrudedSolid = { + ...base, + points: sq.map((p) => ({ x: p.x + 5, y: p.y - 1 })), + brep: { spec: { kind: "sphere", center: [1, 1, 1], r: 1 }, origin: { x: 0, y: 0 } }, + }; + expect(needsBrepPath(moved)).toBe(true); + expect(extrudedSolidSpec(moved, 2.6)).toEqual({ + kind: "translate", + v: [5, -1, 2.6], + solid: { kind: "sphere", center: [1, 1, 1], r: 1 }, + }); + }); +}); diff --git a/src/plan/extrudedSolidSpec.ts b/src/plan/extrudedSolidSpec.ts new file mode 100644 index 00000000..80e1d535 --- /dev/null +++ b/src/plan/extrudedSolidSpec.ts @@ -0,0 +1,74 @@ +// Übersetzt einen `ExtrudedSolid` des Projekts in eine B-Rep-Spezifikation (`SolidSpec`, +// truck/trucksolid). Gemeinsame Quelle für den 3D-Viewer (Eckenradius, Grundkörper) und den +// STEP-Export — reiner Kern, kein WASM. + +import type { ExtrudedSolid } from "../model/types"; +import type { SolidSpec } from "../engine/truckSolid"; + +/** + * Ob der Körper über den B-Rep-Pfad (`buildSolidMesh`) gebaut werden muss: Grundkörper + * (`brep`) und Profile mit Eckenradius. Alles andere nutzt weiter die Prisma-Extrusion + * (`extrudePolygon`/`extrudeCircle`) — bitgleich zum bisherigen Verhalten. + */ +export function needsBrepPath(solid: ExtrudedSolid): boolean { + if (solid.brep) return true; + return (solid.cornerRadius ?? 0) > 1e-9 && !solid.circle && (solid.taper ?? 0) < 1e-6; +} + +/** + * B-Rep-Spezifikation des Körpers, UK auf `baseZ`. `null`, wenn truck dafür (noch) keine + * Beschreibung hat (Pyramide: Spitze als B-Rep entartet). + */ +export function extrudedSolidSpec(solid: ExtrudedSolid, baseZ: number): SolidSpec | null { + if (solid.brep) { + const p0 = solid.points[0]; + const dx = p0 ? p0.x - solid.brep.origin.x : 0; + const dy = p0 ? p0.y - solid.brep.origin.y : 0; + return { kind: "translate", v: [dx, dy, baseZ], solid: solid.brep.spec as unknown as SolidSpec }; + } + if (solid.points.length < 3 || solid.height <= 0) return null; + const taper = Math.min(1, Math.max(0, solid.taper ?? 0)); + if (solid.circle && taper < 1e-6) { + return { + kind: "cylinder", + cx: solid.circle.center.x, + cy: solid.circle.center.y, + z0: baseZ, + r: solid.circle.r, + height: solid.height, + }; + } + if (solid.circle && taper >= 1 - 1e-6) { + return { + kind: "cone", + cx: solid.circle.center.x, + cy: solid.circle.center.y, + z0: baseZ, + r: solid.circle.r, + height: solid.height, + }; + } + const flat = solid.points.flatMap((p) => [p.x, p.y]); + if (taper < 1e-6) { + return { + kind: "extrude", + points: flat, + height: solid.height, + z0: baseZ, + ...((solid.cornerRadius ?? 0) > 0 ? { cornerRadius: solid.cornerRadius } : {}), + }; + } + if (taper < 1 - 1e-6) { + const cx = solid.points.reduce((s, p) => s + p.x, 0) / solid.points.length; + const cy = solid.points.reduce((s, p) => s + p.y, 0) / solid.points.length; + const top = solid.points.flatMap((p) => [cx + (p.x - cx) * (1 - taper), cy + (p.y - cy) * (1 - taper)]); + return { + kind: "loft", + sections: [ + { z: baseZ, points: flat }, + { z: baseZ + solid.height, points: top }, + ], + }; + } + return null; +} diff --git a/src/plan/toWalls3d/extrusions.ts b/src/plan/toWalls3d/extrusions.ts index 19fdb62e..8ebc060b 100644 --- a/src/plan/toWalls3d/extrusions.ts +++ b/src/plan/toWalls3d/extrusions.ts @@ -4,7 +4,8 @@ import type { ExtrudedSolid, Project } from "../../model/types"; import { getFloor } from "../../model/types"; -import { extrudeCircle, extrudePolygon } from "../../engine/truckSolid"; +import { buildSolidMesh, extrudeCircle, extrudePolygon } from "../../engine/truckSolid"; +import { extrudedSolidSpec, needsBrepPath } from "../extrudedSolidSpec"; import type { RMesh, RRgb } from "./shared"; /** Warmes Orange für truck-Profil-Extrusionen (hebt sie klar von Wand/Decke/Kontext ab). */ @@ -34,7 +35,8 @@ interface TruckCacheEntry { const truckMeshCache = new Map(); function extrudedSolidSignature(solid: ExtrudedSolid): string { - return `${solid.height}|${solid.taper ?? 0}|${solid.points.map((p) => `${p.x},${p.y}`).join(";")}`; + 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(";")}`; } export function emitExtrudedSolids(project: Project): RMesh[] { @@ -68,14 +70,18 @@ export function emitExtrudedSolids(project: Project): RMesh[] { // Kreis-Profil: echte runde truck-Extrusion (extrudeCircle) statt der // 48-Eck-Tessellierung in `points` — glattes Zylinder-Mesh. const taper = solid.taper ?? 0; - const extrusion = solid.circle - ? extrudeCircle(solid.circle.center.x, solid.circle.center.y, solid.circle.r, solid.height, taper) - : extrudePolygon(solid.points.flatMap((p) => [p.x, p.y]), solid.height, taper); + // B-Rep-Pfad (Grundkörper, Eckenradius): die Spezifikation trägt die UK (baseZ) selbst. + const brepSpec = needsBrepPath(solid) ? extrudedSolidSpec(solid, baseZ) : null; + const extrusion = brepSpec + ? buildSolidMesh(brepSpec, 0.005) + : solid.circle + ? extrudeCircle(solid.circle.center.x, solid.circle.center.y, solid.circle.r, solid.height, taper) + : extrudePolygon(solid.points.flatMap((p) => [p.x, p.y]), solid.height, taper); extrusion .then((mesh) => { - // truck extrudiert immer ab z=0 — auf die Geschoss-UK anheben. + // Prisma-Pfad: truck extrudiert ab z=0 — auf die Geschoss-UK anheben. const positions = - baseZ === 0 + brepSpec || baseZ === 0 ? mesh.positions : mesh.positions.map((v, i) => (i % 3 === 2 ? v + baseZ : v)); const cur = truckMeshCache.get(solid.id); diff --git a/src/state/selectionInfo.ts b/src/state/selectionInfo.ts index ee304e13..52e52b39 100644 --- a/src/state/selectionInfo.ts +++ b/src/state/selectionInfo.ts @@ -313,6 +313,10 @@ export interface ExtrudedSolidInfo { height: number; /** Verjüngung 0 (Prisma) … 1 (Spitze), editierbar. */ taper: number; + /** Eckenradius der Aussenkontur (m), editierbar (0 = scharf). */ + cornerRadius: number; + /** B-Rep-Körper (Grundkörper): Ecken-/Verjüngungsfelder entfallen. */ + brepLabel?: string; /** Grundfläche des Profils (m²). */ area: number; /** Geschoss, dessen `baseElevation` die UK des Körpers bestimmt. */ @@ -1042,6 +1046,8 @@ function extrudedSolidSelection(project: Project, s: ExtrudedSolid): Selection { const info: ExtrudedSolidInfo = { height: s.height, taper: s.taper ?? 0, + cornerRadius: s.cornerRadius ?? 0, + ...(s.brep ? { brepLabel: s.brep.label ?? "B-Rep" } : {}), area: polygonArea(s.points), floorId: s.levelId, floorName: floor?.name ?? s.levelId, diff --git a/src/state/usePanelHostBase.ts b/src/state/usePanelHostBase.ts index 896aea24..c6861b93 100644 --- a/src/state/usePanelHostBase.ts +++ b/src/state/usePanelHostBase.ts @@ -1029,6 +1029,17 @@ export function usePanelHostBase(opts: { ), })); }, + onSetExtrudedSolidCornerRadius: (radius) => { + if (selection?.kind !== "extrudedSolid") return; + const r = Math.max(0, radius); + const id = selection.id; + setProject((p) => ({ + ...p, + extrudedSolids: (p.extrudedSolids ?? []).map((s) => + s.id === id ? { ...s, cornerRadius: r > 0 ? r : undefined } : s, + ), + })); + }, // ── Stützen-Attribute (Tragwerk; nur bei selektierter Stütze) ────────── onSetColumnProfileKind: (kind) => { if (selection?.kind !== "column") return;