Extrusion: Eckenradius (B-Rep-Kreisboegen) + B-Rep-Grundkoerper-Feld, Panel-Feld, STEP-Export ueber gemeinsame Spezifikation
This commit is contained in:
1 parent
79c1e74349
commit
f96470c911
11 files changed
+199
-28
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -705,6 +705,8 @@ export const en: Record<TranslationKey, string> = {
|
||||
"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",
|
||||
|
||||
@@ -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<string, unknown>; origin: Vec2; label?: string };
|
||||
}
|
||||
|
||||
// ── Stütze (Column, Tragwerk) ──────────────────────────────────────────────
|
||||
|
||||
@@ -668,7 +668,34 @@ export function ExtrudedSolidSection({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{solid.brepLabel && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.brep")}</span>
|
||||
<span className="objinfo-fval">{solid.brepLabel}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Eckenradius (editierbar, ≥ 0): echte Kreisbögen an den Ecken der Aussenkontur. */}
|
||||
{!solid.brepLabel && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.cornerRadius")}</span>
|
||||
<input
|
||||
type="number"
|
||||
className="objinfo-text"
|
||||
step={0.05}
|
||||
min={0}
|
||||
value={solid.cornerRadius}
|
||||
onChange={(e) => {
|
||||
const v = Number(e.target.value);
|
||||
if (Number.isFinite(v) && v >= 0) host.onSetExtrudedSolidCornerRadius(v);
|
||||
}}
|
||||
title={t("objinfo.extrudedSolid.cornerRadius")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Verjüngung (editierbar, 0..1) — löst eine Re-Extrusion (truck-WASM) aus. */}
|
||||
{!solid.brepLabel && (
|
||||
<div className="objinfo-field">
|
||||
<span className="objinfo-flabel">{t("objinfo.extrudedSolid.taper")}</span>
|
||||
<input
|
||||
@@ -685,6 +712,7 @@ export function ExtrudedSolidSection({
|
||||
title={t("objinfo.extrudedSolid.taper")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Grundfläche (read-only, abgeleitet). */}
|
||||
<div className="objinfo-field">
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<string, TruckCacheEntry>();
|
||||
|
||||
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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user