From 72610645ae91cf9f271009e0e0c4ea26a1461c3f Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 16:19:15 +0000 Subject: [PATCH] =?UTF-8?q?[137]=203D-Pick:=20freie=20K=C3=B6rper=20(truck?= =?UTF-8?q?-Netz),=20Dachfenster/Gauben,=20Hervorhebung=20St=C3=BCtze/K?= =?UTF-8?q?=C3=B6rper;=20Gel=C3=A4nde=20einzeln=20sichtbar,=20Raster-Gel?= =?UTF-8?q?=C3=A4nde=20nachgl=C3=A4tten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/core/src/explode3d.rs | 6 ++ src-tauri/core/src/highlight3d.rs | 31 ++++++++++ src-tauri/core/src/model3d.rs | 62 +++++++++++++++++++- src/core/index.ts | 2 + src/i18n/de.ts | 7 +++ src/i18n/en.ts | 7 +++ src/model/terrain.ts | 10 ++++ src/panels/ContextObjectProps.tsx | 45 +++++++++++++- src/plan/pickTypes.ts | 19 +++++- src/plan/toWalls3d.pickSolids.test.ts | 81 ++++++++++++++++++++++++++ src/plan/toWalls3d.test.ts | 5 +- src/plan/toWalls3d.ts | 22 +++++-- src/plan/toWalls3d/extrusions.ts | 25 ++++++++ src/state/siteSelection.test.ts | 30 ++++++++++ src/state/siteSlice.ts | 17 +++++- src/state/useMouseSelectionHandlers.ts | 5 ++ src/ui/ContextImportDialog.tsx | 3 +- src/viewport/Wasm3DViewport.tsx | 6 +- src/viewport/raycast3d.ts | 18 +++++- src/views/viewportContent.tsx | 10 ++-- 20 files changed, 390 insertions(+), 21 deletions(-) create mode 100644 src/plan/toWalls3d.pickSolids.test.ts diff --git a/src-tauri/core/src/explode3d.rs b/src-tauri/core/src/explode3d.rs index 16b15e28..0e02cb64 100644 --- a/src-tauri/core/src/explode3d.rs +++ b/src-tauri/core/src/explode3d.rs @@ -217,6 +217,12 @@ pub fn pick_geometry(p: &Project, gap: f64) -> Result { v[1] += dz; } } + for o in &mut g.opening_meshes { + let dz = ex.of(&o.opening_id); + for v in o.tris.iter_mut().flatten() { + v[1] += dz; + } + } for s in &mut g.solids { let dz = ex.of(&s.solid_id); for v in s.tris.iter_mut().flatten() { diff --git a/src-tauri/core/src/highlight3d.rs b/src-tauri/core/src/highlight3d.rs index 6aa4219f..416b99d0 100644 --- a/src-tauri/core/src/highlight3d.rs +++ b/src-tauri/core/src/highlight3d.rs @@ -77,6 +77,27 @@ impl Out { } } + /// Achsparalleler Hüllquader um Welt-Punkte (nichts bei leerer Menge). + fn aabb_edges<'a>(&mut self, pts: impl Iterator) { + let (mut lo, mut hi) = ([f64::INFINITY; 3], [f64::NEG_INFINITY; 3]); + for q in pts { + for k in 0..3 { + lo[k] = lo[k].min(q[k]); + hi[k] = hi[k].max(q[k]); + } + } + if !lo[0].is_finite() { + return; + } + let mut c = [[0.0; 3]; 8]; + for (i, v) in c.iter_mut().enumerate() { + *v = [if i & 1 != 0 { hi[0] } else { lo[0] }, if i & 2 != 0 { hi[1] } else { lo[1] }, if i & 4 != 0 { hi[2] } else { lo[2] }]; + } + for (i, j) in BOX_EDGES { + self.edge(c[i], c[j]); + } + } + /// Prisma über dem Grundriss `outline` von `z_bottom` bis `z_top`. fn prism_edges(&mut self, outline: &[[f64; 2]], z_bottom: f64, z_top: f64) { let n = outline.len(); @@ -133,6 +154,16 @@ pub fn selection_highlight_lines(p: &Project, a: &Args) -> Result, Stri } } } + // [137] Öffnungen in Dach/Decke/Gaube: Hüllquader ihrer Teile. + if !openings.is_empty() { + for m in crate::model3d::pick_hosted_openings(p) { + if openings.contains(m.opening_id.as_str()) { + let n = out.v.len(); + out.aabb_edges(m.tris.iter().flatten()); + lift(&mut out, n, &m.opening_id); + } + } + } if !ceilings.is_empty() { for s in emit_slabs(p) { if ceilings.contains(s.ceiling_id.as_str()) { diff --git a/src-tauri/core/src/model3d.rs b/src-tauri/core/src/model3d.rs index 52497b88..23fdae0b 100644 --- a/src-tauri/core/src/model3d.rs +++ b/src-tauri/core/src/model3d.rs @@ -2341,6 +2341,14 @@ pub struct PickColumn { pub column_id: String, } +/// [137] Öffnung ohne Wand (Dach, Decke, Gaube) für den 3D-Pick: Welt-Dreiecke ihrer Teile. +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PickOpeningMesh { + pub tris: Vec, + pub opening_id: String, +} + /// [137] Freier Körper für den 3D-Pick: Welt-Dreiecke. #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] @@ -2362,6 +2370,9 @@ pub struct PickGeometry { pub columns: Vec, /// [137] Freie Körper (Prisma-Näherung; TS ersetzt sie durch das truck-Netz). pub solids: Vec, + /// [137] Öffnungen in Dach/Decke/Gaube als Netz. + #[serde(rename = "openingMeshes")] + pub opening_meshes: Vec, pub drawings: Vec, } @@ -2421,8 +2432,10 @@ pub fn pick_geometry(p: &Project) -> Result { for roof in p.roofs.as_deref().unwrap_or(&[]) { let g = crate::roof::roof_geometry(&roof.params(), p.roof_base_elevation(roof)); let to_world = |q: &V3| -> V3 { [q[0], q[2], q[1]] }; - let mut tris: Vec = Vec::new(); - for poly in g.planes.iter().chain(g.gables.iter()) { + // [137] Dachkörper wie gezeichnet (Gauben, Verschneidungen, Löcher der Dachfenster); ohne Körper die Flächen. + let mut tris: Vec = emit_roofs(p, Some(&roof.id)).unwrap_or_default().iter().flat_map(|m| extrusion_tris(&m.positions, &m.indices)).collect(); + let planes: &[Vec] = if tris.is_empty() { &g.planes } else { &[] }; + for poly in planes.iter().chain(g.gables.iter()) { for i in 1..poly.len().saturating_sub(1) { tris.push([to_world(&poly[0]), to_world(&poly[i]), to_world(&poly[i + 1])]); } @@ -2510,10 +2523,32 @@ pub fn pick_geometry(p: &Project) -> Result { context_meshes, columns: pick_columns(p), solids: pick_solids(p), + opening_meshes: pick_hosted_openings(p), drawings: pick_drawing_segs(p, &HashMap::new()), }) } +/// [137] Öffnungen in Dach, Decke oder Gaube (Dachfenster, Deckenöffnung, Gaubenfenster): ihre 3D-Teile +/// (Rahmen, Glas, Eindeckrahmen) als Welt-Dreiecke — sie haben keine Wand-Box wie [`pick_openings`]. +pub fn pick_hosted_openings(p: &Project) -> Vec { + let hosted: Vec<&Opening> = p.openings.as_deref().unwrap_or(&[]).iter().filter(|o| o.host_roof_id.is_some() || o.host_ceiling_id.is_some() || o.host_dormer_id.is_some()).collect(); + if hosted.is_empty() { + return Vec::new(); + } + let mut q = p.clone(); + q.context = None; + q.drawings2d.clear(); + let mut out = Vec::new(); + for o in hosted { + q.openings = Some(vec![o.clone()]); + let tris: Vec = emit_opening_meshes(&q, 1.0).iter().flat_map(|m| extrusion_tris(&m.positions, &m.indices)).collect(); + if !tris.is_empty() { + out.push(PickOpeningMesh { tris, opening_id: o.id.clone() }); + } + } + out +} + /// [137] Freie Körper (`extrudedSolids`, ohne Abzugskörper) als Prisma über dem Grundriss-Umriss: UK = /// Geschoss-UK + `baseOffset`, OK = UK + `height`. Näherung für Loft/Rotation/Abzug/Verjüngung — die Hülle /// (`pickGeometry` in `plan/toWalls3d.ts`) ersetzt die Dreiecke durch das truck-Netz, sobald es geladen ist. @@ -2696,6 +2731,29 @@ mod tests { assert!((top - 7.0).abs() < 1e-9, "{top}"); } + /// [137] Dachfenster sind im 3D anwählbar (Netz mit Id); das Dach hat dort ein Loch statt der vollen Fläche. + #[test] + fn pick_dachfenster_im_3d() { + let mut p = sample(); + p.openings.as_mut().unwrap().push(Opening { + id: "DF".into(), + kind: ElementKind::Window, + width: 0.78, + height: 1.18, + host_roof_id: Some("RF1".into()), + host_point: Some(Vec2 { x: 2.5, y: 1.0 }), + ..Default::default() + }); + let g = pick_geometry(&p).unwrap(); + let df = g.opening_meshes.iter().find(|m| m.opening_id == "DF").expect("Dachfenster in der Pick-Geometrie"); + assert!(df.tris.len() > 12); + // Welt (x, Höhe, y): um den Wirtpunkt (2.5, 1.0). + let (cx, cz) = df.tris.iter().flatten().fold((0.0, 0.0), |a, q| (a.0 + q[0], a.1 + q[2])); + let n = (df.tris.len() * 3) as f64; + assert!((cx / n - 2.5).abs() < 1.0 && (cz / n - 1.0).abs() < 1.5, "{} {}", cx / n, cz / n); + assert!(g.roofs.iter().any(|r| r.roof_id == "RF1" && !r.tris.is_empty())); + } + /// [137] Einzeln ausgeblendetes Gelände (`hidden`) und Gelände einer ausgeblendeten Kategorie fehlen im 3D /// und in der Pick-Geometrie; ein zweites Netz bleibt. #[test] diff --git a/src/core/index.ts b/src/core/index.ts index c55fba58..48569e3f 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -162,6 +162,8 @@ export { DRAWING_PICK_TOLERANCE, type PickContextMesh, type PickColumnMesh, + type PickSolidMesh, + type PickOpeningMesh, type PickDrawingSeg, type PickOpening, type PickRoof, diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 2c115e2a..4a7ce582 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -2099,6 +2099,13 @@ export const de = { "site.terrain.smooth.hint": "Gelände aus den Höhenlinien neu erzeugen (Bruchkanten bleiben, ein Undo-Schritt)", "site.terrain.smooth.raw": "roh (ohne Glättung)", "site.terrain.smooth.level": "Stufe {n}", + "site.terrain.meshVisible": "Dieses Gelände sichtbar", + "site.terrain.meshVisible.hint": "Blendet nur dieses Geländenetz aus (Grundriss, Schnitt, Ansicht, 3D); die Kategorie bleibt eingeschaltet", + "site.terrain.resmooth.hint": "Raster-Gelände (swissALTI3D) zusätzlich glätten — wirkt auf die Höhen des Rasters, ein Undo-Schritt", + "site.terrain.resmooth.unavailable": "Nicht verfügbar: weder Höhenlinien-Satz noch Höhenraster als Quelle (z. B. importiertes TIN)", + "site.terrain.resmooth.current": "{n} Durchgänge", + "site.terrain.resmooth.none": "ungeglättet", + "site.terrain.resmooth.more": "+{n} Durchgänge glätten", "site.type.image": "Luftbild", "site.group.image": "Luftbild", "site.dwgHint": "DWG? Zuerst mit dem gratis ODA File Converter in DXF umwandeln.", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index ab633a60..851a5927 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -2085,6 +2085,13 @@ export const en: Record = { "site.terrain.smooth.hint": "Regenerate the terrain from its contour lines (breaklines kept, one undo step)", "site.terrain.smooth.raw": "raw (no smoothing)", "site.terrain.smooth.level": "Level {n}", + "site.terrain.meshVisible": "This terrain visible", + "site.terrain.meshVisible.hint": "Hides only this terrain mesh (plan, section, elevation, 3D); the category stays on", + "site.terrain.resmooth.hint": "Smooth grid terrain (swissALTI3D) further — acts on the grid heights, one undo step", + "site.terrain.resmooth.unavailable": "Not available: neither a contour set nor a height grid as source (e.g. imported TIN)", + "site.terrain.resmooth.current": "{n} passes", + "site.terrain.resmooth.none": "unsmoothed", + "site.terrain.resmooth.more": "Smooth +{n} passes", "site.excavation.qty": "Cut {cut} m³ · Fill {fill} m³ · Backfill {backfill} m³", "site.excavation.noTerrain": "No terrain below the excavation", "site.type.image": "Aerial", diff --git a/src/model/terrain.ts b/src/model/terrain.ts index 9d5d580c..44c1cf89 100644 --- a/src/model/terrain.ts +++ b/src/model/terrain.ts @@ -75,6 +75,16 @@ export function smoothTerrainGrid(grid: TerrainGrid, passes: number): TerrainGri return { ...grid, z }; } +/** + * [137] Raster-Gelände (swissALTI3D, ein Vertex je Rasterpunkt) um `passes` weitere Durchgänge glätten + * (Rust `terrain.rs::resmooth_grid_mesh`): neue `positions` (nur z geändert), `null`, wenn das Netz kein + * Raster ist (TIN aus Höhenlinien). `passes` 0 prüft nur. + */ +export function resmoothGridTerrain(positions: readonly number[], passes: number): number[] | null { + const out = core().terrain_resmooth_grid(Float64Array.from(positions), passes); + return out.length === positions.length && out.length > 0 ? Array.from(out) : null; +} + /** * Baut ein Terrain-Mesh aus einem regulären Höhenraster (Quad-Gitter → zwei * Dreiecke je Zelle). Fehlende Zellen (`null`) werden ausgelassen; eine Zelle diff --git a/src/panels/ContextObjectProps.tsx b/src/panels/ContextObjectProps.tsx index bc164c0d..f87b1efd 100644 --- a/src/panels/ContextObjectProps.tsx +++ b/src/panels/ContextObjectProps.tsx @@ -1,7 +1,8 @@ // Einstellungen eines Kontext-Objekts (importiertes Mesh, Gelände, Baugrube) — gemeinsam für die Liste im // Panel „Gelände & Kontext" und die Objekt-Info ([137]: ein angeklicktes Gelände bzw. eine Baugrube zeigt // dort dieselben Felder). Gelände zusätzlich: Sichtbarkeit seiner Kategorie und Glättung (aus den -// Höhenlinien neu erzeugt, ein Undo-Schritt). +// Höhenlinien neu erzeugt, ein Undo-Schritt). [137] Dazu: dieses Netz einzeln ausblenden (`hidden`) und +// Raster-Gelände (swissALTI3D, ohne Höhenlinien) additiv nachglätten. // // Bezeichner englisch, UI-Text/Kommentare deutsch. Alle sichtbaren Texte über t(...). @@ -10,6 +11,8 @@ import { usePanelHost } from "./host"; import { useStore } from "../state/appStore"; import type { ContextObject } from "../model/types"; import { flattenCategories } from "../model/types"; +import { resmoothGridTerrain } from "../model/terrain"; +import { useMemo } from "react"; import type { ExcavationQuantity } from "../core"; /** Zahl-Eingabe für ein Feld eines Kontext-Objekts (leer = Standard, ungültig = keine Änderung). */ @@ -54,12 +57,18 @@ function ExcavationQty({ q }: { q: ExcavationQuantity | undefined }) { /** Glättungsstufen der Gelände-Erzeugung (`terrain.rs`, 0 = roh). */ const SMOOTH_LEVELS = [0, 1, 2, 3] as const; +/** [137] Zusätzliche Glättungs-Durchgänge für Raster-Gelände. */ +const RESMOOTH_PASSES = [1, 2, 4] as const; /** Felder eines Kontext-Objekts; `null` für Arten ohne eigene Einstellungen (Höhenlinien, Luftbild). */ export function ContextObjectProps({ obj, quantities }: { obj: ContextObject; quantities: readonly ExcavationQuantity[] }) { const host = usePanelHost(); const notify = useStore((s) => s.notify); const regenerateTerrain = useStore((s) => s.regenerateTerrain); + const resmoothTerrain = useStore((s) => s.resmoothTerrain); + // [137] Raster-Gelände (swissALTI3D) lässt sich ohne Höhenlinien nachglätten; Prüfung nur bei Netz-Wechsel. + const terrainPositions = obj.type === "terrainMesh" ? obj.positions : null; + const isGrid = useMemo(() => (terrainPositions ? resmoothGridTerrain(terrainPositions, 0) !== null : false), [terrainPositions]); const patch = (field: string) => (v: number | undefined) => host.onPatchContextObject(obj.id, { [field]: v }, `site-${obj.id}-${field}`); if (obj.type === "importedMesh") { @@ -86,6 +95,15 @@ export function ContextObjectProps({ obj, quantities }: { obj: ContextObject; qu const hasSource = (host.project.context ?? []).some((o) => o.type === "contourSet"); return (
+ {cat && ( )} + {!hasSource && ( + + )} diff --git a/src/plan/pickTypes.ts b/src/plan/pickTypes.ts index c50e1e46..8232f852 100644 --- a/src/plan/pickTypes.ts +++ b/src/plan/pickTypes.ts @@ -97,8 +97,25 @@ export interface PickContextMesh { contextObjectId: string; } -/** [137] Stütze für den Raycast: WORLD-Dreiecke ihres Prismas (Konvention wie {@link PickContextMesh}). */ +/** [137] Stütze für den Raycast: WORLD-Dreiecke ihres Prismas (x, Höhe, y — wie Wände/Dächer, ohne die + * Nord-Negation der Kontext-Meshes). */ export interface PickColumnMesh { tris: ReadonlyArray; columnId: string; } + +/** + * [137] Freier Körper (`extrudedSolids`, Loft/Rotation/Abzug/B-Rep) für den Raycast: WORLD-Dreiecke + * (x, Höhe, y). Der Kern liefert das Prisma über dem Umriss; sobald das truck-Netz geladen ist, ersetzt + * `pickGeometry` (plan/toWalls3d.ts) es durch dessen Dreiecke. + */ +export interface PickSolidMesh { + tris: ReadonlyArray; + solidId: string; +} + +/** [137] Öffnung ohne Wand (Dachfenster, Deckenöffnung, Gaubenfenster): WORLD-Dreiecke ihrer 3D-Teile. */ +export interface PickOpeningMesh { + tris: ReadonlyArray; + openingId: string; +} diff --git a/src/plan/toWalls3d.pickSolids.test.ts b/src/plan/toWalls3d.pickSolids.test.ts new file mode 100644 index 00000000..82d6da7a --- /dev/null +++ b/src/plan/toWalls3d.pickSolids.test.ts @@ -0,0 +1,81 @@ +// [137] Alles Sichtbare anwählbar im 3D: freie Körper (Prisma aus dem Kern, truck-Netz sobald geladen), +// Stützen lagerichtig (x, Höhe, y wie die Darstellung), Hervorhebung beider, Gelände einzeln ausgeblendet. + +import { describe, expect, it, afterEach } from "vitest"; +import type { Project, TerrainMesh } from "../model/types"; +import { sampleProject } from "../model/sampleProject"; +import { pickGeometry, selectionHighlightLines } from "./toWalls3d"; +import { __setTruckMeshForTest } from "./toWalls3d/extrusions"; +import { pickNearest, type Ray } from "../viewport/raycast3d"; + +const base: Project = { + ...sampleProject, + walls: [], + openings: [], + ceilings: [], + roofs: [], + stairs: [], + context: [], + columns: [ + { id: "k1", type: "column", floorId: "eg", categoryCode: "25", position: { x: 20, y: 3 }, profile: { kind: "rect", width: 0.4, depth: 0.4 }, rotation: 0, height: 2.5 }, + ], + extrudedSolids: [ + { id: "s1", type: "extrudedSolid", levelId: "og", points: [{ x: 30, y: 2 }, { x: 32, y: 2 }, { x: 32, y: 5 }, { x: 30, y: 5 }], height: 1.5, baseOffset: 0.5 }, + { id: "v1", type: "extrudedSolid", levelId: "eg", points: [{ x: 40, y: 0 }, { x: 41, y: 0 }, { x: 41, y: 1 }], height: 1, operation: "subtract" }, + ], +} as Project; + +/** Senkrechter Strahl von oben auf Welt (x, z) — Welt-z = Modell-y bei Bauteilen. */ +const down = (x: number, z: number): Ray => ({ origin: [x, 50, z], dir: [0, -1, 0] }); +const pick = (p: Project, ray: Ray) => { + const g = pickGeometry(p); + return pickNearest(ray, g.walls, g.slabs, g.openings, g.stairs, g.roofs, g.contextMeshes, g.drawings, g.columns, g.solids); +}; + +afterEach(() => __setTruckMeshForTest("s1", null)); + +describe("[137] 3D-Pick freie Körper und Stützen", () => { + it("freier Körper: Prisma über dem Umriss, Abzugskörper nicht; Treffer von oben auf OK", () => { + const g = pickGeometry(base); + expect(g.solids.map((s) => s.solidId)).toEqual(["s1"]); + const hit = pick(base, down(31, 3.5)); + expect(hit?.kind).toBe("solid"); + expect(hit?.id).toBe("s1"); + // OK = OG 2.6 + 0.5 + 1.5 = 4.6 → t = 50 − 4.6. + expect(hit!.t).toBeCloseTo(50 - 4.6, 6); + expect(pick(base, down(40.5, 0.3))).toBeNull(); + }); + + it("geladenes truck-Netz ersetzt die Prisma-Näherung (z. B. Pyramide statt Quader)", () => { + // Pyramide über demselben Umriss, Spitze bei (31, 3.5) auf 4.6 m (Modell x, y, z). + __setTruckMeshForTest("s1", { + positions: [30, 2, 3.1, 32, 2, 3.1, 32, 5, 3.1, 30, 5, 3.1, 31, 3.5, 4.6], + indices: [0, 1, 4, 1, 2, 4, 2, 3, 4, 3, 0, 4, 0, 2, 1, 0, 3, 2], + kind: "extrusion", + color: [1, 1, 1], + } as never); + const hit = pick(base, down(30.1, 2.1)); + expect(hit?.id).toBe("s1"); + // Am Rand der Pyramide nahe der UK statt auf der Prisma-OK. + expect(50 - hit!.t).toBeLessThan(3.3); + }); + + it("Stütze lagerichtig: Welt-z = +y (wie gezeichnet), nicht gespiegelt", () => { + expect(pick(base, down(20, 3))?.kind).toBe("column"); + expect(pick(base, down(20, -3))).toBeNull(); + }); + + it("Hervorhebung für gewählte Stütze und freien Körper", () => { + const rgb: [number, number, number] = [1, 0, 0]; + expect(selectionHighlightLines(base, [], [], rgb, [], [], [], [], 0, ["k1"]).length).toBe(4 * 3 * 12); + expect(selectionHighlightLines(base, [], [], rgb, [], [], [], [], 0, [], ["s1"]).length).toBe(4 * 3 * 12); + }); + + it("einzeln ausgeblendetes Gelände fängt im 3D keinen Klick", () => { + const terrain: TerrainMesh = { id: "t1", type: "terrainMesh", name: "G", positions: [0, 0, 0, 10, 0, 0, 10, 10, 0], indices: [0, 1, 2] }; + const shown = { ...base, context: [{ ...terrain }] } as Project; + expect(pickGeometry(shown).contextMeshes.map((m) => m.contextObjectId)).toEqual(["t1"]); + const hidden = { ...base, context: [{ ...terrain, hidden: true }] } as Project; + expect(pickGeometry(hidden).contextMeshes).toEqual([]); + }); +}); diff --git a/src/plan/toWalls3d.test.ts b/src/plan/toWalls3d.test.ts index cc3ffc99..fcdf7226 100644 --- a/src/plan/toWalls3d.test.ts +++ b/src/plan/toWalls3d.test.ts @@ -2499,8 +2499,9 @@ describe("pickGeometry — Dächer (Ray-Dreieck-Pick)", () => { // sampleProject trägt das Demo-Satteldach RF1. expect(roofs.length).toBe(1); expect(roofs[0].roofId).toBe("RF1"); - // Sattel: 2 Flächen (je 4 Ecken → 2 Dreiecke) + 2 Giebel (je 1 Dreieck) = 6. - expect(roofs[0].tris.length).toBe(6); + // [137] Dachkörper wie gezeichnet (Schichten mit Dicke, Gauben, Löcher der Dachfenster) + 2 Giebel — + // vorher nur die 2 Flächen (4 Dreiecke) + 2 Giebel = 6. + expect(roofs[0].tris.length).toBeGreaterThan(6); // Höhe liegt in der WORLD-Y-Komponente (Index 1) — alle über der Traufe > 0. for (const tri of roofs[0].tris) for (const p of tri) expect(p[1]).toBeGreaterThan(0); }); diff --git a/src/plan/toWalls3d.ts b/src/plan/toWalls3d.ts index 37436933..074a766c 100644 --- a/src/plan/toWalls3d.ts +++ b/src/plan/toWalls3d.ts @@ -44,7 +44,7 @@ import type { Project, Vec2 } from "../model/types"; import type { DetailLevel } from "../model/viewTypes"; import { documentFor } from "../core/document"; import { coreEpoch } from "../engine/coreWasm"; -import type { PickOpening, PickRoof, PickStair, PickContextMesh, PickColumnMesh, PickDrawingSeg } from "./pickTypes"; +import type { PickOpening, PickRoof, PickStair, PickContextMesh, PickColumnMesh, PickSolidMesh, PickOpeningMesh, PickDrawingSeg } from "./pickTypes"; import { type RMesh, type RModel3d, @@ -53,7 +53,7 @@ import { type RVec2, type RWall, } from "./toWalls3d/shared"; -import { emitExtrudedSolids, TRUCK_MESH_READY_EVENT } from "./toWalls3d/extrusions"; +import { emitExtrudedSolids, truckSolidPickTris, TRUCK_MESH_READY_EVENT } from "./toWalls3d/extrusions"; import { applyVoids3d, type VoidCuts } from "./toWalls3d/voids3d"; // Re-Export des gemeinsamen Vokabulars — externe Konsumenten (viewport/, @@ -329,9 +329,20 @@ export function pickGeometry( roofs: PickRoof[]; contextMeshes: PickContextMesh[]; columns: PickColumnMesh[]; + solids: PickSolidMesh[]; + openingMeshes: PickOpeningMesh[]; drawings: PickDrawingSeg[]; } { - return documentFor(project).query("pickGeometry", [explodeGap(explode)]); + const g = documentFor(project).query("pickGeometry", [explodeGap(explode)]) as ReturnType; + // [137] Freie Körper: das geladene truck-Netz (Loft, Rotation, Verjüngung, Rundung) statt der Prisma-Näherung des Kerns. + const gap = explodeGap(explode); + const offsets = gap > 0 ? explodeFloorOffsets(project, gap) : undefined; + const levelOf = new Map((project.extrudedSolids ?? []).map((s) => [s.id, s.levelId])); + g.solids = (g.solids ?? []).map((s) => { + const tris = truckSolidPickTris(s.solidId, offsets?.[levelOf.get(s.solidId) ?? ""] ?? 0); + return tris ? { ...s, tris } : s; + }); + return g; } /** @@ -373,8 +384,11 @@ export function selectionHighlightLines( contextObjectIds: string[] = [], /** Explosionsabstand ([65]); 0 = aus. */ explode = 0, + /** [137] Stützen und freie Körper (Prisma-Umriss). */ + columnIds: string[] = [], + solidIds: string[] = [], ): Float32Array { - const sel = { walls: wallIds, ceilings: ceilingIds, openings: openingIds, stairs: stairIds, roofs: roofIds, context: contextObjectIds }; + const sel = { walls: wallIds, ceilings: ceilingIds, openings: openingIds, stairs: stairIds, roofs: roofIds, context: contextObjectIds, columns: columnIds, solids: solidIds }; if (Object.values(sel).every((l) => l.length === 0)) return new Float32Array(0); // Gerechnet im Kern (`highlight3d.rs`); Antwort f32-LE. const b = documentFor(project).queryBin("selectionHighlight", [], JSON.stringify({ ...sel, rgb, explode: explodeGap(explode) })); diff --git a/src/plan/toWalls3d/extrusions.ts b/src/plan/toWalls3d/extrusions.ts index 0980b505..f04ef614 100644 --- a/src/plan/toWalls3d/extrusions.ts +++ b/src/plan/toWalls3d/extrusions.ts @@ -7,6 +7,7 @@ import { getFloor } from "../../model/types"; import { buildSolidMesh, extrudeCircle, extrudePolygon } from "../../engine/truckSolid"; import { extrudedSolidSpec, needsBrepPath } from "../extrudedSolidSpec"; import type { RMesh, RRgb } from "./shared"; +import type { Vec3 } from "../pickTypes"; /** Warmes Orange für truck-Profil-Extrusionen (hebt sie klar von Wand/Decke/Kontext ab). */ const EXTRUSION_RGB: RRgb = [0.85, 0.55, 0.25]; @@ -104,3 +105,27 @@ export function emitExtrudedSolids( } return out; } + +/** + * [137] Dreiecke des geladenen truck-Netzes eines freien Körpers in WORLD-Koordinaten (x, Höhe, y — wie + * render3d `Extrusion`), um `dz` (Explosion) angehoben; `null`, solange das Netz nicht geladen ist. + */ +export function truckSolidPickTris(solidId: string, dz = 0): [Vec3, Vec3, Vec3][] | null { + const mesh = truckMeshCache.get(solidId)?.mesh; + if (!mesh || mesh.indices.length < 3) return null; + const pos = mesh.positions; + const n = pos.length / 3; + const at = (i: number): Vec3 => [pos[i * 3], pos[i * 3 + 2] + dz, pos[i * 3 + 1]]; + const tris: [Vec3, Vec3, Vec3][] = []; + for (let k = 0; k + 2 < mesh.indices.length; k += 3) { + const [a, b, c] = [mesh.indices[k], mesh.indices[k + 1], mesh.indices[k + 2]]; + if (a < n && b < n && c < n) tris.push([at(a), at(b), at(c)]); + } + return tris.length ? tris : null; +} + +/** Nur für Tests: ein truck-Netz für einen Körper in den Cache legen. */ +export function __setTruckMeshForTest(solidId: string, mesh: RMesh | null): void { + if (mesh) truckMeshCache.set(solidId, { signature: "test", mesh }); + else truckMeshCache.delete(solidId); +} diff --git a/src/state/siteSelection.test.ts b/src/state/siteSelection.test.ts index 91d7d2b2..589424a8 100644 --- a/src/state/siteSelection.test.ts +++ b/src/state/siteSelection.test.ts @@ -78,3 +78,33 @@ describe("[137] Gelände neu glätten", () => { expect(terrain().smooth).toBe(2); }); }); + +describe("[137] Raster-Gelände (swissALTI3D) nachglätten", () => { + it("additive Durchgänge, nur z ändert sich, Undo; TIN aus Höhenlinien wird abgelehnt", () => { + const positions: number[] = []; + for (let j = 0; j < 6; j++) for (let i = 0; i < 6; i++) positions.push(i * 2, j * 2, i === 3 && j === 3 ? 10 : 0); + const indices: number[] = []; + for (let j = 0; j < 5; j++) + for (let i = 0; i < 5; i++) { + const a = j * 6 + i; + indices.push(a, a + 1, a + 7, a, a + 7, a + 6); + } + const grid: TerrainMesh = { id: "alti", type: "terrainMesh", name: "swissALTI3D", positions, indices, smooth: 1 }; + setState({ project: { ...p, context: [grid] }, undoDepth: 0, redoDepth: 0, canUndo: false, canRedo: false }); + getState().clearHistory(); + const cur = () => getState().project.context!.find((c) => c.id === "alti") as TerrainMesh; + expect(getState().resmoothTerrain("alti", 2)).toBe(true); + expect(cur().smooth).toBe(3); + const peak = cur().positions[(3 * 6 + 3) * 3 + 2]; + expect(peak).toBeLessThan(10); + expect(peak).toBeGreaterThan(0); + expect(cur().positions.filter((_, k) => k % 3 !== 2)).toEqual(positions.filter((_, k) => k % 3 !== 2)); + expect(cur().indices).toEqual(indices); + getState().undo(); + expect(cur().positions).toEqual(positions); + expect(cur().smooth).toBe(1); + // Musterhaus-Gelände (TIN aus Höhenlinien) ist kein Raster. + setState({ project: p }); + expect(getState().resmoothTerrain(terrainId, 1)).toBe(false); + }); +}); diff --git a/src/state/siteSlice.ts b/src/state/siteSlice.ts index 3cb12c2f..7a1700a9 100644 --- a/src/state/siteSlice.ts +++ b/src/state/siteSlice.ts @@ -9,7 +9,7 @@ // // Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). -import { generateTerrainFromContours, type TerrainOptions } from "../model/terrain"; +import { generateTerrainFromContours, resmoothGridTerrain, type TerrainOptions } from "../model/terrain"; import type { ContextObject, Project } from "../model/types"; import { addItems, fieldOps, patchItem, removeItems } from "../core/opsBuild"; import type { CoreOp } from "../core/ops"; @@ -41,6 +41,11 @@ export interface SiteSlice { * `false`, wenn es keine Quelle gibt oder kein Netz entsteht. */ regenerateTerrain: (terrainId: string, smooth: number) => boolean; + /** + * [137] Raster-Gelände (swissALTI3D, ohne Höhenlinien-Quelle) um `passes` Durchgänge nachglätten: + * gleiche Id, nur z geändert, `smooth` zählt die Durchgänge; ein Undo-Schritt. false = kein Raster. + */ + resmoothTerrain: (terrainId: string, passes: number) => boolean; /** Leert die gesamte Kontext-Schicht. */ clearContext: () => void; } @@ -119,6 +124,16 @@ export function createSiteSlice( return true; }, + resmoothTerrain: (terrainId, passes) => { + const terrain = (get().project.context ?? []).find((o) => o.id === terrainId && o.type === "terrainMesh"); + if (!terrain || terrain.type !== "terrainMesh" || !(passes > 0)) return false; + const positions = resmoothGridTerrain(terrain.positions, passes); + if (!positions) return false; + const smooth = (terrain.smooth ?? 0) + passes; + get().applyChange((p) => patchItem(p, "context", terrainId, (o) => ({ ...o, positions, smooth }) as ContextObject)); + return true; + }, + clearContext: () => get().applyChange((p) => fieldOps(p, "context", [])), }; } diff --git a/src/state/useMouseSelectionHandlers.ts b/src/state/useMouseSelectionHandlers.ts index a73e6089..39b708c9 100644 --- a/src/state/useMouseSelectionHandlers.ts +++ b/src/state/useMouseSelectionHandlers.ts @@ -387,6 +387,11 @@ export function useMouseSelectionHandlers(opts: { setSelection({ ...clearKinds(), columns: [hit.id] }); return; } + // [137] Freier Körper (Loft, Rotation, Extrusion): Objekt-Info wie im Grundriss. + if (hit.kind === "solid") { + setSelection({ ...clearKinds(), solids: [hit.id] }); + return; + } if (hit.kind === "roof") { // Schnittlinien bleiben hier (wie bisher) gewählt. setSelection({ ...clearKinds(...ELEMENT_KINDS.filter((k) => k !== "sectionLines")), roofs: [hit.id] }); diff --git a/src/ui/ContextImportDialog.tsx b/src/ui/ContextImportDialog.tsx index 55feefa6..d08ae518 100644 --- a/src/ui/ContextImportDialog.tsx +++ b/src/ui/ContextImportDialog.tsx @@ -280,7 +280,8 @@ export function ContextImportDialog({ let terrain: TerrainMesh | null = null; if (terrainResult?.grid) { const mesh = terrainMeshFromGrid(smoothTerrainGrid(terrainResult.grid, terrainSmooth)); - if (mesh.positions.length >= 9) terrain = mesh; + // [137] Glättung (Durchgänge) merken: die Objekt-Info glättet Raster-Gelände additiv nach. + if (mesh.positions.length >= 9) terrain = { ...mesh, smooth: terrainSmooth }; } // SWISSIMAGE-Luftbild (WMS) → georeferenziertes Rasterbild (EIN ContextImage). diff --git a/src/viewport/Wasm3DViewport.tsx b/src/viewport/Wasm3DViewport.tsx index d366cd19..0616a37b 100644 --- a/src/viewport/Wasm3DViewport.tsx +++ b/src/viewport/Wasm3DViewport.tsx @@ -81,7 +81,7 @@ import { /** Ein per 3D-Klick getroffenes Bauteil, oder null (Leerraum). */ export type Pick3dHit = - | { kind: "wall" | "ceiling" | "opening" | "stair" | "roof" | "contextObject" | "drawing" | "column"; id: string } + | { kind: "wall" | "ceiling" | "opening" | "stair" | "roof" | "contextObject" | "drawing" | "column" | "solid"; id: string } | null; /** Klick-vs-Drag-Schwelle (Pixel): bleibt die Maus zwischen pointerdown und @@ -1406,7 +1406,7 @@ export function Wasm3DViewport({ const ndc = toNdc(clientX, clientY); if (!cb || !o || !ndc) return; const ray = cameraRay(orbitCamera(o), ndc.ndcX, ndc.ndcY, ndc.aspect); - const { walls, slabs, openings, stairs, roofs, contextMeshes, drawings, columns } = pickGeometry( + const { walls, slabs, openings, stairs, roofs, contextMeshes, drawings, columns, solids, openingMeshes } = pickGeometry( projectRef.current, explodeRef.current, ); @@ -1414,7 +1414,7 @@ export function Wasm3DViewport({ // Meshes + freie 2D-Zeichnungen (Linie/Polylinie/Rechteck, s. // `pickDrawingSegs`) — sonst wären im WASM-Viewport 2D-Elemente NIE // anwählbar gewesen (Nutzer-Report). - const hit = pickNearest(ray, walls, slabs, openings, stairs, roofs, contextMeshes, drawings, columns); + const hit = pickNearest(ray, walls, slabs, openings, stairs, roofs, contextMeshes, drawings, columns, solids, openingMeshes); cb(hit ? { kind: hit.kind, id: hit.id } : null, additive); }; diff --git a/src/viewport/raycast3d.ts b/src/viewport/raycast3d.ts index bda0df8f..2f8c2ab0 100644 --- a/src/viewport/raycast3d.ts +++ b/src/viewport/raycast3d.ts @@ -18,7 +18,7 @@ import { DRAWING_PICK_TOLERANCE } from "../core"; -import type { Vec3, PickWall, PickOpening, PickDrawingSeg, PickSlab, PickStair, PickRoof, PickContextMesh, PickColumnMesh } from "../core"; +import type { Vec3, PickWall, PickOpening, PickDrawingSeg, PickSlab, PickStair, PickRoof, PickContextMesh, PickColumnMesh, PickSolidMesh, PickOpeningMesh } from "../core"; /** Kamera-Parameter für den Pick-Strahl (Teilmenge von Camera3d). */ export interface RayCamera { @@ -42,7 +42,7 @@ export interface Ray { /** Ergebnis eines Picks: getroffenes Bauteil + Distanz entlang des Strahls. */ export interface PickHit { - kind: "wall" | "ceiling" | "opening" | "stair" | "roof" | "contextObject" | "drawing" | "column"; + kind: "wall" | "ceiling" | "opening" | "stair" | "roof" | "contextObject" | "drawing" | "column" | "solid"; id: string; t: number; /** Bei `kind:"opening"` dieselbe Id wie `id` (ausdrucksstärkerer Zugriff). */ @@ -358,6 +358,8 @@ export function pickNearest( contextMeshes?: readonly PickContextMesh[], drawings?: readonly PickDrawingSeg[], columns?: readonly PickColumnMesh[], + solids?: readonly PickSolidMesh[], + openingMeshes?: readonly PickOpeningMesh[], ): PickHit | null; /** * Nächstes getroffenes Bauteil (kleinstes t) über Wände, Decken, Öffnungen und @@ -378,6 +380,8 @@ export function pickNearest( contextMeshes: readonly PickContextMesh[] = [], drawings: readonly PickDrawingSeg[] = [], columns: readonly PickColumnMesh[] = [], + solids: readonly PickSolidMesh[] = [], + openingMeshes: readonly PickOpeningMesh[] = [], ): PickHit | null { const TIE_EPS = 1e-6; let hit: PickHit | null = null; @@ -433,6 +437,16 @@ export function pickNearest( const t = rayContextMeshTris(ray, { tris: c.tris, contextObjectId: c.columnId }); if (t !== null) consider({ kind: "column", id: c.columnId, t }, 1); } + // [137] Freie Körper (truck-Netz bzw. Prisma-Näherung), Rang wie Wand/Decke. + for (const s of solids) { + const t = rayContextMeshTris(ray, { tris: s.tris, contextObjectId: s.solidId }); + if (t !== null) consider({ kind: "solid", id: s.solidId, t }, 1); + } + // [137] Dachfenster/Deckenöffnungen (Netz): Rang wie Öffnungen in Wänden. + for (const o of openingMeshes) { + const t = rayContextMeshTris(ray, { tris: o.tris, contextObjectId: o.openingId }); + if (t !== null) consider({ kind: "opening", id: o.openingId, t, openingId: o.openingId }, 0); + } return hit; } diff --git a/src/views/viewportContent.tsx b/src/views/viewportContent.tsx index a74eccfa..da423c35 100644 --- a/src/views/viewportContent.tsx +++ b/src/views/viewportContent.tsx @@ -279,7 +279,7 @@ export const Content = memo(function Content({ () => (explode > 0 ? (explodeFloorOffsets(project, explode)[level.id] ?? 0) : 0), [project, explode, level.id], ); - const { walls, ceilings, openings, stairs, roofs, contextObjects } = selection; + const { walls, ceilings, openings, stairs, roofs, contextObjects, columns, solids } = selection; const selectionLines = useMemo( () => walls.length === 0 && @@ -287,10 +287,12 @@ export const Content = memo(function Content({ openings.length === 0 && stairs.length === 0 && roofs.length === 0 && - contextObjects.length === 0 + contextObjects.length === 0 && + columns.length === 0 && + solids.length === 0 ? null - : selectionHighlightLines(project, walls, ceilings, HIGHLIGHT_RGB, openings, stairs, roofs, contextObjects, explode), - [project, explode, walls, ceilings, openings, stairs, roofs, contextObjects], + : selectionHighlightLines(project, walls, ceilings, HIGHLIGHT_RGB, openings, stairs, roofs, contextObjects, explode, columns, solids), + [project, explode, walls, ceilings, openings, stairs, roofs, contextObjects, columns, solids], ); // Kollisionen der letzten Prüfung: rote Hüllquader zusätzlich zur Auswahl-Hervorhebung. const highlightLines = useMemo(() => {