[307] 3D-Dokument: Gelände als helle Fläche mit Randlinie, Keller unter Terrain verdeckt, Baugruben und Klasse berücksichtigt
check / check (push) Has been cancelled
check / licenses (push) Has been cancelled
check / e2e (push) Has been cancelled
macos / native (push) Has been cancelled

This commit is contained in:
Claude committed 2026-11-20 03:06:43 +00:00
1 parent 0161f0089c
commit ef0e55ceb0
10 files changed
+314 -17

No files matched your search

+3 -2
View File
@@ -11,7 +11,7 @@ Wer zu einer ID mehr wissen will (Entscheide, Tests, Bilder), sucht dort nach `*
stehen im Archiv („Bewusst nicht übernommen“).
- **Grösse** (eine Person mit Agenten): S ≤ 1 Tag · M ≤ 1 Woche · L ≤ 1 Monat · XL > 1 Monat.
Steht keine Grösse im Archiv, ist sie hier geschätzt.
- **IDs sind stabil.** Neue ID = nächste freie Zahl nach der höchsten im Archiv und hier (aktuell 306);
- **IDs sind stabil.** Neue ID = nächste freie Zahl nach der höchsten im Archiv und hier (aktuell 307);
nie eine ID wiederverwenden oder umnummerieren. Präfix-IDs (`[K]`, `[G]`, `[T]`, `[B]`, `[C]`) bleiben.
- **Pro Punkt:** was fehlt · wo im Code · Grösse. Höchstens ein bis drei Sätze je Punkt;
Messwerte und Befunde gehören in den Commit.
@@ -55,7 +55,8 @@ Raumprogramm gegen Modell → Grundrisse/Schnitte/Ansichten 1:200 (Vorprojekt 1:
3D-Bilder/Axonometrie/Schatten → Flächen/Volumen SIA 416 und Kennzahlen → Kostenschätzung grob → Abgabe-Layouts (Plakate A0/A1,
Kennwort, anonym) als PDF; Austausch mit Fachplanern über DXF/IFC.
- ◐ **[266]** Wettbewerb einmal ganz durchgespielt (16.11., Bilder `doc/review-266/`). Offen: GV (`flaechen.rs`) — Studienkörper (frei, ≥ 9 m², ≥ 2.4 m) zählen nur ausserhalb der Geschossgrundrisse, Bodenplatte zählt von UK bis Fertigboden (FRAGE: SIA-416-Wortlaut zu Fundamenten/Sauberkeitsschicht nicht im Repo, gegen die Norm prüfen; Schwellen 9 m²/2.4 m sind Annahmen, Alternative: Merkmal „Gebäudekörper“). 3D-Dokument (`plan/axo.rs`): nicht auf dem Mac geprüft, kein eigener Reiter, kein Live-Schnitt, Gelände fehlt. Nicht geprüft: Tauri-App/Mac (Metal, 3D-Bild, Schatten, Rendering), Druck des A1-Plakats, DXF/IFC in Fremdsoftware; Plakat-Reste in [296]. · M
- ◐ **[266]** Wettbewerb einmal ganz durchgespielt (16.11., Bilder `doc/review-266/`). Offen: GV (`flaechen.rs`) — Studienkörper (frei, ≥ 9 m², ≥ 2.4 m) zählen nur ausserhalb der Geschossgrundrisse, Bodenplatte zählt von UK bis Fertigboden (FRAGE: SIA-416-Wortlaut zu Fundamenten/Sauberkeitsschicht nicht im Repo, gegen die Norm prüfen; Schwellen 9 m²/2.4 m sind Annahmen, Alternative: Merkmal „Gebäudekörper“). 3D-Dokument (`plan/axo.rs`): nicht auf dem Mac geprüft, kein eigener Reiter, kein Live-Schnitt (Gelände: [307]). Nicht geprüft: Tauri-App/Mac (Metal, 3D-Bild, Schatten, Rendering), Druck des A1-Plakats, DXF/IFC in Fremdsoftware; Plakat-Reste in [296]. · M
- ◐ **[307]** 3D-Dokument: Gelände als helle Fläche mit Randlinie (20.11., Bild `doc/review-307/axo.png`; `plan/axo_terrain.rs`, Netz-Quelle `excavation::terrain_model_mesh` wie 3D/Ansicht, mit Baugruben, Klasse über Sichtbarkeit/Ebene, Parameter `terrain` Vorgabe an). Verdeckt den Keller, wird vom Haus verdeckt. Zu dichte Netze (> 12 000 Dreiecke im Ausschnitt um das Gebäude) werden auf ein ~3000-Zellen-Raster umgerechnet (Baugruben-Böschung dort gröber). Offen: keine Höhenlinien (Linien im Gelände), keine Durchdringungslinie Haus/Gelände; Wettbewerb hat kein Gelände, nur Musterhaus komplex geprüft; Mac/Tauri nicht geprüft. · S
- ◐ **[305]** 3D-Dokument: Fenster mit Rahmen und Glas (20.11., Bild `doc/review-305/axo.png`). Offen: Glaskanten meist vom Rahmen gedeckt; Öffnungsteile ohne eigene Id (`plan/axo.rs`, `section::model_view_faces`); Dach-/Deckenfenster ([103]) nicht geprüft; Mac/Tauri und Kern-WASM in der App nicht geprüft. · S
- ◐ **[304]** 3D nur EG: Geländer oben bleibt sichtbar (20.11.). Offen: kein Browser-/Mac-Lauf (Kern-WASM nicht neu gebaut); Pick der Absturzsicherung hängt weiter an der Treppe (`retain_pick`: mit UG aus nicht anwählbar, obwohl sichtbar). · S
- ◐ **[303]** Aus [300]: Bogenmasskette und Öffnungssymbole in der Ansicht (19.11., Bild `doc/review-303/plan.png`). Offen: Mac/Tauri und Druck-PDF nicht geprüft; Dreh-Linien-Strichlänge (2.2 mm) bei 1:100 unverändert; Treppe-Hilfslinien und Möbel im Schnitt aus [300] offen. · S
Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

+1 -1
View File
@@ -11,7 +11,7 @@ fn indices_u32(v: &[f64]) -> Vec<u32> {
}
/// Codes ausgeblendeter Kategorien samt Kindern einer ausgeblendeten Elternebene.
pub(super) fn hidden_category_codes(cats: &[crate::model::LayerCategory]) -> std::collections::HashSet<&str> {
pub(crate) fn hidden_category_codes(cats: &[crate::model::LayerCategory]) -> std::collections::HashSet<&str> {
fn walk<'a>(list: &'a [crate::model::LayerCategory], parent_hidden: bool, out: &mut std::collections::HashSet<&'a str>) {
for c in list {
let hidden = parent_hidden || !c.visible;
+1
View File
@@ -71,6 +71,7 @@ Herkunft, kein Wegweiser.
| `elevation/patterns.rs` | Oberflächenmuster auf Ansichtsflächen |
| `elevation/tests.rs` | Tests der Ansicht |
| `axo.rs` | [266] 3D-Dokument: Vektor-Axonometrie/-Perspektive mit verdeckten Kanten (Flächen aus `section::model_view_faces`, `hlr.rs`, Tönung über `hlr_fill.rs`), Vorgaben, Kamera, Abfrage `axo_plan_buf()`; Tests `axo_tests.rs` |
| `axo_terrain.rs` | [307] Gelände im 3D-Dokument: Netz aus `excavation::terrain_model_mesh` als Flächen (Ausschnitt um das Gebäude, Raster bei zu dichten Netzen), Kanten nur am Rand |
| `elevation_geom.rs` | Geometrie der Ansicht: Verdeckung, Schlagschatten, Eck-Verlängerung, Öffnungen |
| `grid_view.rs` | Achsraster in Schnitt und Ansicht |
| `underlay.rs` | Grundriss ausgerichtet unter Schnitt und Ansicht (Ausrichtung der Pausfolie „Grundriss hinter Schnitt“) |
+24 -8
View File
@@ -286,7 +286,7 @@ fn perspective_pass(faces: Vec<hlr::Face>, model_n: Vec<V3>, zref: f64, tan_half
}
/// Flächen des Modells in der Projektion; `None`, wenn die Projektion entartet ist.
fn prepare(p: &Project, proj: &Projection, vis: &Visibility, context: bool, scale: f64) -> Result<Option<(Prepared, Vec<OwnerRef>)>, String> {
fn prepare(p: &Project, proj: &Projection, vis: &Visibility, context: bool, terrain: bool, scale: f64) -> Result<Option<(Prepared, Vec<OwnerRef>)>, String> {
match *proj {
Projection::Parallel { m, o } => {
let Some(cof) = cofactor(&m) else { return Ok(None) };
@@ -307,9 +307,12 @@ fn prepare(p: &Project, proj: &Projection, vis: &Visibility, context: bool, scal
Some(q) => (q, true),
None => (p, context && ortho),
};
let (mut vf, refs) = super::section::model_view_faces(pp, vis, &view, &view_n, meshes, Some(opening_detail(scale)))?;
let (mut vf, mut refs) = super::section::model_view_faces(pp, vis, &view, &view_n, meshes, Some(opening_detail(scale)))?;
if vf.faces.len() > FACE_BUDGET && (context || ent.is_some()) {
(vf, _) = super::section::model_view_faces(p, vis, &view, &view_n, false, Some(opening_detail(scale)))?;
(vf, refs) = super::section::model_view_faces(p, vis, &view, &view_n, false, Some(opening_detail(scale)))?;
}
if terrain {
super::axo_terrain::add_terrain(p, vis, &view, &view_n, &mut vf, &mut refs);
}
// Modell-Normale = Mᵀ · Normale (die Normale ging über M⁻ᵀ).
let model_n = vf.faces.iter().map(|f| unit([0, 1, 2].map(|k| m[0][k] * f.normal[0] + m[1][k] * f.normal[1] + m[2][k] * f.normal[2])).unwrap_or([0.0, 0.0, 1.0])).collect();
@@ -329,9 +332,12 @@ fn prepare(p: &Project, proj: &Projection, vis: &Visibility, context: bool, scal
Some(q) => (q, true),
None => (p, context),
};
let (mut vf, refs) = super::section::model_view_faces(pp, vis, &view, &view_n, meshes, Some(opening_detail(scale)))?;
let (mut vf, mut refs) = super::section::model_view_faces(pp, vis, &view, &view_n, meshes, Some(opening_detail(scale)))?;
if vf.faces.len() > FACE_BUDGET && (context || ent.is_some()) {
(vf, _) = super::section::model_view_faces(p, vis, &view, &view_n, false, Some(opening_detail(scale)))?;
(vf, refs) = super::section::model_view_faces(p, vis, &view, &view_n, false, Some(opening_detail(scale)))?;
}
if terrain {
super::axo_terrain::add_terrain(p, vis, &view, &view_n, &mut vf, &mut refs);
}
let model_n: Vec<V3> = vf.faces.iter().map(|q| unit([0, 1, 2].map(|k| r[k] * q.normal[0] + u[k] * q.normal[1] + f[k] * q.normal[2])).unwrap_or([0.0, 0.0, 1.0])).collect();
Ok(Some((perspective_pass(vf.faces, model_n, zref, tan_half, aspect), refs)))
@@ -604,6 +610,13 @@ const GLASS_FILL: &str = "#cfd6dc";
const WINDOW_GLASS_FILL: &str = "#c6d6e0";
const GLASS_EDGE_MM: f64 = 0.09;
/// [307] Geländefläche: helle, leicht grünliche Tönung (Grauwert `g` der Lage zum Licht moduliert sie).
fn terrain_tint(g: f64) -> String {
let k = 0.93 + 0.07 * ((g - 0.78) / 0.19).clamp(0.0, 1.0);
let c = |v: f64| (v * k * 255.0).round().clamp(0.0, 255.0) as u32;
format!("#{:02x}{:02x}{:02x}", c(0.90), c(0.93), c(0.87))
}
fn grey_hex(g: f64) -> String {
let v = (g.clamp(0.0, 1.0) * 255.0).round() as u32;
format!("#{v:02x}{v:02x}{v:02x}")
@@ -615,6 +628,8 @@ pub struct AxoArgs {
pub proj: Projection,
pub opts: AxoOpts,
pub context: bool,
/// [307] Gelände zeichnen (Vorgabe an; Klasse des Geländes bleibt massgebend).
pub terrain: bool,
pub vis: Visibility,
/// Zeichenmassstab (Nenner) für den Detailgrad der Öffnungen ([305]); die Abfrage `axoPlan` setzt ihn.
pub scale: f64,
@@ -670,7 +685,7 @@ impl AxoArgs {
None if !s("cameraId").is_empty() => project_camera(p, s("cameraId"), aspect, center)?,
None => preset(s("view"), if s("projection").is_empty() { "iso" } else { s("projection") })?,
};
Some(AxoArgs { proj, opts: AxoOpts { hidden: b("hidden", false) || b("hiddenLines", false), fills: b("fills", true) }, context: b("context", false), vis: Visibility::from_json(v), scale: 100.0 })
Some(AxoArgs { proj, opts: AxoOpts { hidden: b("hidden", false) || b("hiddenLines", false), fills: b("fills", true) }, context: b("context", false), terrain: b("terrain", true), vis: Visibility::from_json(v), scale: 100.0 })
}
}
@@ -694,7 +709,7 @@ pub fn snapshot_text(p: &Project, snap: &ViewSnapshot, invisible: &[String]) ->
/// Plan-Primitive der Axonometrie und ihr Ausmass; `None` ohne sichtbares Bauteil.
pub fn axo_primitives(p: &Project, a: &AxoArgs, mono: bool) -> Result<Option<(Vec<Primitive>, [f64; 4])>, String> {
let Some((mut prep, refs)) = prepare(p, &a.proj, &a.vis, a.context, a.scale)? else { return Ok(None) };
let Some((mut prep, refs)) = prepare(p, &a.proj, &a.vis, a.context, a.terrain, a.scale)? else { return Ok(None) };
// [279] Glas der Glasgeländer verdeckt nichts (Linien und Flächen dahinter bleiben sichtbar).
for f in &mut prep.faces {
f.occludes = !refs.get(f.owner as usize).is_some_and(|r| r.glass);
@@ -709,10 +724,11 @@ pub fn axo_primitives(p: &Project, a: &AxoArgs, mono: bool) -> Result<Option<(Ve
let owner = |o: u32| refs.get(o as usize);
// Glas ([279]) zuletzt und durchscheinend, damit Flächen dahinter durchschimmern.
let is_glass = |o: u32| refs.get(o as usize).is_some_and(|r| r.glass);
let is_terrain = |o: u32| refs.get(o as usize).is_some_and(|r| r.terrain);
let is_window = |o: u32| refs.get(o as usize).is_some_and(|r| r.opening);
let ordered = out.fills.iter().filter(|f| !is_glass(f.2)).chain(out.fills.iter().filter(|f| is_glass(f.2)));
for (polys, g, o) in ordered {
let fill = if is_window(*o) && is_glass(*o) { WINDOW_GLASS_FILL.to_string() } else if is_glass(*o) { GLASS_FILL.to_string() } else { grey_hex(*g) };
let fill = if is_terrain(*o) { terrain_tint(*g) } else if is_window(*o) && is_glass(*o) { WINDOW_GLASS_FILL.to_string() } else if is_glass(*o) { GLASS_FILL.to_string() } else { grey_hex(*g) };
for poly in polys {
let ring = simplify(&if poly.len() > 1 { crate::voids::keyhole(poly).0 } else { poly[0].clone() });
if ring.len() < 3 {
+220
View File
@@ -0,0 +1,220 @@
//! [307] Gelände im 3D-Dokument (`axo.rs`): dieselbe Netz-Quelle wie 3D und Ansicht (`excavation::terrain_model_mesh`,
//! mit Baugruben, Höhen im Modellbezug) als deckende Flächen. Kanten nur am Rand (Netzrand und Schnittkante des
//! Ausschnitts), keine Dreiecksfugen. Das Netz wird auf einen Ausschnitt um das Gebäude zugeschnitten (Umfang des
//! Gebäudes + Rand), damit grosse Geländemodelle das Flächenbudget nicht sprengen. Klasse über `Visibility` und die
//! Ebenensichtbarkeit des Projekts ([180], [181]).
use super::section::{Kind, OwnerRef, ViewFaces, Visibility};
use crate::hlr;
use crate::model::*;
use std::collections::HashMap;
type V3 = [f64; 3];
/// Höchstens so viele Dreiecke je Gelände nach dem Zuschnitt (sonst wird der Rand enger).
const TRI_BUDGET: usize = 12_000;
/// Zellen des Rasters, auf das zu dichte Netze umgerechnet werden (je zwei Dreiecke).
const GRID_CELLS: f64 = 3_000.0;
/// Grundrissausdehnung des Gebäudes (Wände, Decken); `None` ohne Bauteile.
fn building_bounds(p: &Project) -> Option<[f64; 4]> {
let mut b = [f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY];
let mut add = |x: f64, y: f64| {
if x.is_finite() && y.is_finite() {
b = [b[0].min(x), b[1].min(y), b[2].max(x), b[3].max(y)];
}
};
for w in &p.walls {
add(w.start.x, w.start.y);
add(w.end.x, w.end.y);
}
for c in p.ceilings.as_deref().unwrap_or(&[]) {
for q in c.ring_xy() {
add(q[0], q[1]);
}
}
(b[0].is_finite() && b[2].is_finite()).then_some(b)
}
/// Dreieck an das Rechteck `r` = [x0, y0, x1, y1] zuschneiden (Sutherland-Hodgman); `rim[i]`: Kante i → i+1 zeichnen.
/// Neue Kanten am Rechteck werden gezeichnet (Schnittkante des Ausschnitts).
fn clip_rect(tri: [V3; 3], rim: [bool; 3], r: [f64; 4]) -> Option<(Vec<V3>, Vec<bool>)> {
let mut pts: Vec<V3> = tri.to_vec();
let mut flags: Vec<bool> = rim.to_vec();
let sides: [&dyn Fn(V3) -> f64; 4] = [&|p| p[0] - r[0], &|p| r[2] - p[0], &|p| p[1] - r[1], &|p| r[3] - p[1]];
for g in sides {
let n = pts.len();
let vals: Vec<f64> = pts.iter().map(|&p| g(p)).collect();
if vals.iter().all(|v| *v >= 0.0) {
continue;
}
let (mut op, mut of) = (Vec::new(), Vec::new());
for i in 0..n {
let j = (i + 1) % n;
let (p, q, gp, gq) = (pts[i], pts[j], vals[i], vals[j]);
let x = || {
let t = gp / (gp - gq);
[p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t, p[2] + (q[2] - p[2]) * t]
};
match (gp >= 0.0, gq >= 0.0) {
(true, true) => {
op.push(p);
of.push(flags[i]);
}
(true, false) => {
op.push(p);
of.push(flags[i]);
op.push(x());
of.push(true);
}
(false, true) => {
op.push(x());
of.push(flags[i]);
}
(false, false) => {}
}
}
if op.len() < 3 {
return None;
}
pts = op;
flags = of;
}
Some((pts, flags))
}
type K3 = (i64, i64, i64);
fn key(p: V3) -> K3 {
((p[0] * 1e6).round() as i64, (p[1] * 1e6).round() as i64, (p[2] * 1e6).round() as i64)
}
fn ekey(a: V3, b: V3) -> (K3, K3) {
let (ka, kb) = (key(a), key(b));
if ka <= kb { (ka, kb) } else { (kb, ka) }
}
/// Netz auf ein regelmässiges Raster (höchstens `GRID_CELLS` Zellen) im Ausschnitt `rect` (sonst Netzausdehnung)
/// umrechnen; Zellen mit einer Ecke ausserhalb des Netzes entfallen, offene Zellkanten sind der Rand.
fn resample(pos: &[f64], idx: &[f64], rect: Option<[f64; 4]>) -> Vec<(Vec<V3>, Vec<bool>)> {
let tin = crate::terrain::Tin::from_flat(pos, idx);
let tb = tin.bbox();
let r = match rect {
Some(r) => [r[0].max(tb[0]), r[1].max(tb[1]), r[2].min(tb[2]), r[3].min(tb[3])],
None => tb,
};
let (w, h) = (r[2] - r[0], r[3] - r[1]);
if !(w > 1e-6 && h > 1e-6 && w.is_finite() && h.is_finite()) {
return Vec::new();
}
let step = (w * h / GRID_CELLS).sqrt().max(1e-3);
let (nx, ny) = (((w / step).ceil() as usize).clamp(1, 400), ((h / step).ceil() as usize).clamp(1, 400));
let (dx, dy) = (w / nx as f64, h / ny as f64);
let ix = crate::terrain::TinIndex::new(&tin);
let z: Vec<Option<V3>> = (0..=ny).flat_map(|j| (0..=nx).map(move |i| (i, j))).map(|(i, j)| {
let (x, y) = (r[0] + i as f64 * dx, r[1] + j as f64 * dy);
ix.z_at(x, y).map(|z| [x, y, z])
}).collect();
let at = |i: usize, j: usize| z[j * (nx + 1) + i];
let cell = |i: isize, j: isize| -> Option<[V3; 4]> {
if i < 0 || j < 0 || i >= nx as isize || j >= ny as isize {
return None;
}
let (i, j) = (i as usize, j as usize);
Some([at(i, j)?, at(i + 1, j)?, at(i + 1, j + 1)?, at(i, j + 1)?])
};
let mut out = Vec::new();
for j in 0..ny as isize {
for i in 0..nx as isize {
let Some([a, b, c, d]) = cell(i, j) else { continue };
// Kanten des Vierecks a-b (unten), b-c (rechts), c-d (oben), d-a (links): Rand, wenn dort keine Zelle liegt.
let (bot, right, top, left) = (cell(i, j - 1).is_none(), cell(i + 1, j).is_none(), cell(i, j + 1).is_none(), cell(i - 1, j).is_none());
out.push((vec![a, b, c], vec![bot, right, false]));
out.push((vec![a, c, d], vec![false, top, left]));
}
}
out
}
/// Modell (x, y, Höhe) → Welt (x, Höhe, y) (Umkehrung von `model_of`).
fn to_world(m: V3) -> V3 {
[m[0], m[2], m[1]]
}
/// Gelände-Flächen an `vf` / `refs` anhängen. `view`/`view_n`: wie bei `model_view_faces` (Welt: x, Höhe, y).
pub(super) fn add_terrain(p: &Project, vis: &Visibility, view: &dyn Fn(V3) -> V3, view_n: &dyn Fn(V3) -> V3, vf: &mut ViewFaces, refs: &mut Vec<OwnerRef>) {
let hidden = crate::model3d::hidden_category_codes(&p.layers);
let bounds = building_bounds(p);
for t in crate::excavation::terrains(p) {
if hidden.contains(t.category_code.as_str()) || !(vis.visible(&t.category_code) && vis.render(&t.category_code)) || t.positions.len() < 9 || t.indices.len() < 3 {
continue;
}
let (pos, idx, _) = crate::excavation::terrain_model_mesh(p, t);
let nv = pos.len() / 3;
let vert = |i: usize| [pos[3 * i], pos[3 * i + 1], pos[3 * i + 2]];
let tris: Vec<[V3; 3]> = idx
.chunks_exact(3)
.filter(|c| c.iter().all(|x| x.is_finite() && *x >= 0.0 && x.fract() == 0.0 && (*x as usize) < nv))
.map(|c| [vert(c[0] as usize), vert(c[1] as usize), vert(c[2] as usize)])
.filter(|t| t.iter().all(|v| v.iter().all(|x| x.is_finite())))
.collect();
// Kanten, die nur ein Dreieck hat, sind Netzrand.
let mut count: HashMap<(K3, K3), u32> = HashMap::new();
for t in &tris {
for k in 0..3 {
*count.entry(ekey(t[k], t[(k + 1) % 3])).or_default() += 1;
}
}
// Ausschnitt: Umfang des Gebäudes + Rand.
let margin = bounds.map_or(f64::INFINITY, |b| (0.6 * (b[2] - b[0]).max(b[3] - b[1])).max(8.0));
let rect = bounds.map(|b| [b[0] - margin, b[1] - margin, b[2] + margin, b[3] + margin]);
let mut clipped: Vec<(Vec<V3>, Vec<bool>)> = Vec::new();
for t in &tris {
let rim = [0, 1, 2].map(|k| count.get(&ekey(t[k], t[(k + 1) % 3])).copied().unwrap_or(0) < 2);
match rect {
Some(r) => {
let (lo, hi) = t.iter().fold(([f64::INFINITY; 2], [f64::NEG_INFINITY; 2]), |(l, h), v| ([l[0].min(v[0]), l[1].min(v[1])], [h[0].max(v[0]), h[1].max(v[1])]));
if hi[0] < r[0] || lo[0] > r[2] || hi[1] < r[1] || lo[1] > r[3] {
continue;
}
if let Some(c) = clip_rect(*t, rim, r) {
clipped.push(c);
}
}
None => clipped.push((t.to_vec(), rim.to_vec())),
}
}
// Zu dicht (Vermessungsnetze, Zentimeter-Dreiecke): auf ein regelmässiges Raster umrechnen.
if clipped.len() > TRI_BUDGET {
clipped = resample(&pos, &idx, rect);
}
if clipped.is_empty() {
continue;
}
let owner = refs.len() as u32;
refs.push(OwnerRef { kind: Kind::Mesh, id: Some(t.id.clone()), stair: false, column: false, railing: false, glass: false, perforated: false, opening: false, terrain: true });
vf.owners.push((Kind::Mesh, usize::MAX));
for (pts, rim) in clipped {
let (a, b, c) = (pts[0], pts[1], pts[2]);
let (u, w) = ([b[0] - a[0], b[1] - a[1], b[2] - a[2]], [c[0] - a[0], c[1] - a[1], c[2] - a[2]]);
let mut n = [u[1] * w[2] - u[2] * w[1], u[2] * w[0] - u[0] * w[2], u[0] * w[1] - u[1] * w[0]];
let l = (n[0] * n[0] + n[1] * n[1] + n[2] * n[2]).sqrt();
if !(l > 1e-12) {
continue;
}
let (mut pts, mut rim) = (pts, rim);
// Normale nach oben (Höhe = z im Modell).
if n[2] < 0.0 {
n = [-n[0], -n[1], -n[2]];
pts.reverse();
// Kante i → i+1 des umgedrehten Rings ist die Kante (m−2−i) → (m−1−i) des alten.
let m = rim.len();
rim = (0..m).map(|i| rim[(2 * m - 2 - i) % m]).collect();
}
let n = [n[0] / l, n[1] / l, n[2] / l];
let mut f = hlr::Face::new(pts.iter().map(|&q| view(to_world(q))).collect(), view_n(to_world(n)), owner);
f.no_edge = rim.iter().map(|r| !r).collect();
vf.faces.push(f);
}
}
}
+59 -3
View File
@@ -266,7 +266,7 @@ fn axo_zeit() {
let p: Project = serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap();
let a = args(serde_json::json!({"view": "southeast"}), &p);
let t = std::time::Instant::now();
let (prep, refs) = prepare(&p, &a.proj, &a.vis, false, 100.0).unwrap().unwrap();
let (prep, refs) = prepare(&p, &a.proj, &a.vis, false, true, 100.0).unwrap().unwrap();
eprintln!("Flächen: {} in {:?}", prep.faces.len(), t.elapsed());
let t = std::time::Instant::now();
let segs = hlr::hidden_lines(&prep.faces, &hlr::Opts { tol: 1e-4, depth_eps: 1e-4, hidden: false, ..hlr::Opts::default() });
@@ -382,7 +382,7 @@ fn fenster_mit_rahmen_und_glas() {
let p: Project = serde_json::from_str(include_str!("../../tests/fixtures/robust/wettbewerb.json")).unwrap();
let a = args(serde_json::json!({"view": "southeast"}), &p);
let parts = |scale: f64| {
let (prep, refs) = prepare(&p, &a.proj, &a.vis, false, scale).unwrap().expect("Flächen");
let (prep, refs) = prepare(&p, &a.proj, &a.vis, false, true, scale).unwrap().expect("Flächen");
let n = |glass: bool| prep.faces.iter().filter(|f| refs.get(f.owner as usize).is_some_and(|r| r.opening && r.glass == glass)).count();
(n(false), n(true))
};
@@ -401,6 +401,62 @@ fn fenster_mit_rahmen_und_glas() {
codes.sort();
codes.dedup();
let off = args(serde_json::json!({"view": "southeast", "hasVis": true, "invisible": codes}), &p);
let (prep, refs) = prepare(&p, &off.proj, &off.vis, false, 100.0).unwrap().expect("Flächen");
let (prep, refs) = prepare(&p, &off.proj, &off.vis, false, true, 100.0).unwrap().expect("Flächen");
assert!(prep.faces.iter().all(|f| !refs.get(f.owner as usize).is_some_and(|r| r.opening)));
}
/// [307] Gelände: Rechteck 13 × 13 m auf Höhe 0 (zwei Dreiecke), Klasse „02“.
fn with_terrain(mut p: Project) -> Project {
let t = TerrainMesh { id: "t".into(), category_code: "02".into(), positions: vec![-6.0, -6.0, 0.0, 7.0, -6.0, 0.0, 7.0, 7.0, 0.0, -6.0, 7.0, 0.0], indices: vec![0.0, 1.0, 2.0, 0.0, 2.0, 3.0], ..Default::default() };
p.context = Some(vec![ContextObject::TerrainMesh(t)]);
p.layers.push(serde_json::from_value(serde_json::json!({"code": "02", "name": "Gelände", "color": "#000", "lw": 0.5, "visible": true, "locked": false})).unwrap());
p
}
fn terrain_fills(prims: &[Primitive]) -> usize {
prims.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: Some(id), .. } if id == "t")).count()
}
#[test]
fn gelaende_flaeche_mit_umriss_ohne_dreiecksfuge() {
let p = with_terrain(cubes(&[(0.0, 0.0, 0.0)]));
let prims = prims_of(&p, serde_json::json!({"view": "southeast"}));
assert!(terrain_fills(&prims) >= 1, "Geländefläche fehlt");
// Würfel auf dem Gelände: 9 Würfelkanten + 4 Geländekanten, die Diagonale der zwei Dreiecke fehlt.
let l = lines(&prims_of(&p, serde_json::json!({"view": "southeast", "terrain": false})));
assert_eq!(l.len(), 9, "ohne Gelände nur der Würfel");
let with = lines(&prims);
assert!(with.len() <= 9 + 4 + 2 && with.len() >= 9 + 4 - 2, "Würfel + Geländerand, keine Diagonale: {}", with.len());
// Reines Gelände: genau vier Randkanten, eine getönte Fläche.
let mut q = with_terrain(cubes(&[(0.0, 0.0, 0.0)]));
q.walls.clear();
q.drawing_levels.clear();
let prims = prims_of(&q, serde_json::json!({"view": "southeast"}));
assert_eq!(lines(&prims).len(), 4, "{:?}", lines(&prims));
assert_eq!(terrain_fills(&prims), 1);
}
#[test]
fn keller_unter_gelaende_verdeckt() {
// Würfel unter dem Gelände (Oberkante −0.5): kein Würfel-Strich, nur der Geländerand.
let p = with_terrain(cubes(&[(0.0, 0.0, -1.5)]));
let l = lines(&prims_of(&p, serde_json::json!({"view": "southeast"})));
assert_eq!(l.len(), 4, "{l:?}");
// Gelände aus (Parameter) bzw. Klasse „02“ ausgeblendet: der Würfel erscheint.
assert_eq!(lines(&prims_of(&p, serde_json::json!({"view": "southeast", "terrain": false}))).len(), 9);
let a = args(serde_json::json!({"view": "southeast", "hasVis": true, "invisible": ["02"]}), &p);
let prims = axo_primitives(&p, &a, false).unwrap().unwrap().0;
assert_eq!(terrain_fills(&prims), 0);
assert_eq!(lines(&prims).len(), 9);
}
#[test]
fn baugrube_gibt_das_haus_im_gelaende_frei() {
// Versenkter Würfel in einer Baugrube: er schaut aus der Grube heraus (mehr als der Geländerand).
let mut q = with_terrain(cubes(&[(0.0, 0.0, -1.5)]));
let v = |x: f64, y: f64| Vec2 { x, y };
let pit = Excavation { id: "bg".into(), outline: vec![v(-3.0, -3.0), v(4.0, -3.0), v(4.0, 4.0), v(-3.0, 4.0)], bottom: -1.5, ..Default::default() };
q.context.as_mut().unwrap().push(ContextObject::Excavation(pit));
let n = lines(&prims_of(&q, serde_json::json!({"view": "southeast"}))).len();
assert!(n > 4 + 3, "Würfel in der Baugrube sichtbar: {n}");
}
+1
View File
@@ -47,6 +47,7 @@ pub mod cameras;
pub mod mesh_plan;
pub mod situation;
pub mod axo;
mod axo_terrain;
pub mod contrast;
pub mod arc_fit;
pub(crate) mod seams;
+1 -1
View File
@@ -36,7 +36,7 @@ pub use bands::*;
use shapes::*;
use voids::*;
pub(crate) use meshes::*;
pub(crate) use projection::{model_view_faces, OwnerRef};
pub(crate) use projection::{model_view_faces, OwnerRef, ViewFaces};
use projection::*;
pub use primitives::*;
pub use openings::*;
@@ -334,6 +334,8 @@ pub(crate) struct OwnerRef {
pub perforated: bool,
/// [305] Einbauteil einer Öffnung (Rahmen; mit `glass` die Scheibe): kein Wandkörper, nur im 3D-Dokument.
pub opening: bool,
/// [307] Gelände (Netz mit Baugruben, nur im 3D-Dokument): helle Tönung, Kanten nur am Rand.
pub terrain: bool,
}
/// [305] Besitzer-Nummern der Öffnungsteile in `ViewFaces::owners` (Index `usize::MAX` bzw. `- 1` der Art `Wall`).
@@ -374,7 +376,7 @@ pub(crate) fn model_view_faces(p: &Project, vis: &Visibility, view: &dyn Fn([f64
.iter()
.map(|&(kind, i)| {
if kind == Kind::Wall && (i == OPENING_FRAME || i == OPENING_GLASS) {
return OwnerRef { kind, id: None, stair: false, column: false, railing: false, glass: i == OPENING_GLASS, perforated: false, opening: true };
return OwnerRef { kind, id: None, stair: false, column: false, railing: false, glass: i == OPENING_GLASS, perforated: false, opening: true, terrain: false };
}
let (id, stair, column, railing) = match kind {
Kind::Wall => (walls_r.get(i).map(|w| w.wall_id.clone()), false, false, false),
@@ -392,7 +394,7 @@ pub(crate) fn model_view_faces(p: &Project, vis: &Visibility, view: &dyn Fn([f64
};
let glass = railing && matches!(kind, Kind::Slab) && matches!(slabs.get(i), Some(SlabOwner::Railing(_, Some(RailingKind::Glass))));
let perforated = railing && matches!(kind, Kind::Slab) && matches!(slabs.get(i), Some(SlabOwner::Railing(_, Some(RailingKind::Perforated))));
OwnerRef { kind, id, stair, column, railing, glass, perforated, opening: false }
OwnerRef { kind, id, stair, column, railing, glass, perforated, opening: false, terrain: false }
})
.collect();
Ok((vf, refs))