Merge branch 'worktree-agent-a8430b7822fb50a76' into claude/practical-noether-1hb2s1
# Conflicts: # TODO.md # doc/ARCHITEKTUR.md
This commit is contained in:
27 files changed
+874
-159
No files matched your search
@@ -0,0 +1,270 @@
|
||||
//! [180] Klassen im 3D: jedes 3D-Teil gehört zum Element, aus dem es stammt, und verschwindet mit dessen
|
||||
//! Klasse (`categoryCode`). Ausgeblendet ist eine Klasse, wenn sie selbst oder eine Elternklasse im
|
||||
//! Ebenen-Baum aus ist (`LayerCategory.visible`; Ebenen-Kombinationen und Vorlagen setzen dieselben
|
||||
//! Schalter) oder der Aufrufer sie nicht zeichnet (`norender` des Darstellungsmodus, `text` =
|
||||
//! `{"hide": [codes]}`). Gefiltert wird beim Ausgeben, nicht beim Rechnen: Der 3D-Cache bleibt
|
||||
//! klassenunabhängig (`model3d_cache.rs`), Umschalten rechnet keine Wand neu.
|
||||
//!
|
||||
//! Öffnungs-Einbauteile werden je Wand gemeinsam gerechnet (ohne Zuordnung zur Öffnung): dort wirkt der
|
||||
//! Filter auf die Eingabe (nur sichtbare Öffnungen, [`ClassFilter::keep_opening`]); das Loch in der Wand
|
||||
//! bleibt. Eine Öffnung verschwindet auch mit ihrem Wirt (Wand, Dach, Decke), wie in der Ansicht.
|
||||
|
||||
use super::*;
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// Herkunft eines `RMesh`/`RRoofLayer` (nur im Kern, nicht serialisiert): Index in der Element-Liste.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum Owner {
|
||||
#[default]
|
||||
None,
|
||||
Roof(usize),
|
||||
Column(usize),
|
||||
Tree(usize),
|
||||
Stair(usize),
|
||||
Context(usize),
|
||||
}
|
||||
|
||||
impl Owner {
|
||||
/// Element-id der Herkunft.
|
||||
pub fn id<'a>(&self, p: &'a Project) -> Option<&'a str> {
|
||||
fn at<T>(v: &Option<Vec<T>>, i: usize) -> Option<&T> {
|
||||
v.as_deref().and_then(|v| v.get(i))
|
||||
}
|
||||
match *self {
|
||||
Owner::None => None,
|
||||
Owner::Roof(i) => at(&p.roofs, i).map(|e| e.id.as_str()),
|
||||
Owner::Column(i) => at(&p.columns, i).map(|e| e.id.as_str()),
|
||||
Owner::Tree(i) => at(&p.trees, i).map(|e| e.id.as_str()),
|
||||
Owner::Stair(i) => at(&p.stairs, i).map(|e| e.id.as_str()),
|
||||
Owner::Context(i) => at(&p.context, i).map(|e| e.id()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Ausgeblendete Klassen und die ids der Elemente darauf.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ClassFilter {
|
||||
codes: HashSet<String>,
|
||||
ids: HashSet<String>,
|
||||
}
|
||||
|
||||
impl ClassFilter {
|
||||
/// Nichts ausgeblendet.
|
||||
pub fn none() -> ClassFilter {
|
||||
ClassFilter::default()
|
||||
}
|
||||
|
||||
/// Ebenen-Baum des Projekts plus die Codes `extra` (Darstellungsmodus des Aufrufers).
|
||||
pub fn new(p: &Project, extra: &[String]) -> ClassFilter {
|
||||
let mut codes: HashSet<String> = hidden_category_codes(&p.layers).into_iter().map(String::from).collect();
|
||||
codes.extend(extra.iter().cloned());
|
||||
let mut ids = HashSet::new();
|
||||
if codes.is_empty() {
|
||||
return ClassFilter { codes, ids };
|
||||
}
|
||||
let mut add = |code: &str, id: &str| {
|
||||
if codes.contains(code) {
|
||||
ids.insert(id.to_owned());
|
||||
}
|
||||
};
|
||||
for w in &p.walls {
|
||||
add(&w.category_code, &w.id);
|
||||
}
|
||||
for c in p.ceilings.as_deref().unwrap_or(&[]) {
|
||||
add(&c.category_code, &c.id);
|
||||
}
|
||||
for r in p.roofs.as_deref().unwrap_or(&[]) {
|
||||
add(&r.category_code, &r.id);
|
||||
}
|
||||
for s in p.stairs.as_deref().unwrap_or(&[]) {
|
||||
add(&s.category_code, &s.id);
|
||||
}
|
||||
for c in p.columns.as_deref().unwrap_or(&[]) {
|
||||
add(&c.category_code, &c.id);
|
||||
}
|
||||
for t in p.trees.as_deref().unwrap_or(&[]) {
|
||||
add(&t.category_code, &t.id);
|
||||
}
|
||||
for s in p.extruded_solids.as_deref().unwrap_or(&[]) {
|
||||
add(&s.category_code, &s.id);
|
||||
}
|
||||
for c in p.context.as_deref().unwrap_or(&[]) {
|
||||
add(c.category_code(), c.id());
|
||||
}
|
||||
for d in &p.drawings2d {
|
||||
add(&d.category_code, &d.id);
|
||||
}
|
||||
// Öffnungen nach den Wirten (Wand, Dach, Decke), die jetzt schon in `ids` stehen.
|
||||
let hidden_openings: Vec<String> = p
|
||||
.openings
|
||||
.as_deref()
|
||||
.unwrap_or(&[])
|
||||
.iter()
|
||||
.filter(|o| codes.contains(&o.category_code) || ids.contains(&o.host_wall_id))
|
||||
.map(|o| o.id.clone())
|
||||
.collect();
|
||||
ids.extend(hidden_openings);
|
||||
ClassFilter { codes, ids }
|
||||
}
|
||||
|
||||
/// `text` der 3D-Abfragen: `{"hide": [codes], …}` (fehlt/kein JSON: nur der Ebenen-Baum).
|
||||
pub fn from_text(p: &Project, text: &str) -> ClassFilter {
|
||||
let t = text.trim();
|
||||
let extra: Vec<String> = if t.starts_with('{') {
|
||||
serde_json::from_str::<serde_json::Value>(t)
|
||||
.ok()
|
||||
.and_then(|v| v.get("hide").and_then(|a| a.as_array()).map(|a| a.iter().filter_map(|s| s.as_str().map(String::from)).collect()))
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
ClassFilter::new(p, &extra)
|
||||
}
|
||||
|
||||
/// Kein Element ausgeblendet.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.ids.is_empty()
|
||||
}
|
||||
|
||||
/// Klasse `code` ausgeblendet.
|
||||
pub fn hides_code(&self, code: &str) -> bool {
|
||||
self.codes.contains(code)
|
||||
}
|
||||
|
||||
/// Element `id` ausgeblendet.
|
||||
pub fn hides(&self, id: &str) -> bool {
|
||||
self.ids.contains(id)
|
||||
}
|
||||
|
||||
/// Öffnung sichtbar (eigene Klasse und Wirt).
|
||||
pub fn keep_opening(&self, o: &Opening) -> bool {
|
||||
!self.ids.contains(&o.id)
|
||||
}
|
||||
|
||||
/// Teil mit Herkunft `o` (Index in den Listen von `p`) sichtbar.
|
||||
pub fn keep_owner(&self, p: &Project, o: Owner) -> bool {
|
||||
o.id(p).is_none_or(|id| !self.ids.contains(id))
|
||||
}
|
||||
|
||||
/// Teile ohne die Wand-/Öffnungs-Einbauteile filtern (die filtert der Aufrufer, s. Modulkopf).
|
||||
pub fn retain_rest(&self, p: &Project, parts: &mut Parts) {
|
||||
if self.is_empty() {
|
||||
return;
|
||||
}
|
||||
parts.slabs.retain(|s| !self.hides(&s.ceiling_id));
|
||||
for list in [&mut parts.context_meshes, &mut parts.column_meshes, &mut parts.stair_meshes, &mut parts.stair_railings, &mut parts.roof_meshes] {
|
||||
list.retain(|m| self.keep_owner(p, m.owner));
|
||||
}
|
||||
parts.roof_layers.retain(|l| self.keep_owner(p, l.owner));
|
||||
}
|
||||
|
||||
/// Wandkörper filtern.
|
||||
pub fn retain_walls(&self, parts: &mut Parts) {
|
||||
if !self.is_empty() {
|
||||
parts.walls.retain(|w| !self.hides(&w.wall_id));
|
||||
}
|
||||
}
|
||||
|
||||
/// Pick-Geometrie: ausgeblendete Elemente sind nicht anwählbar.
|
||||
pub fn retain_pick(&self, g: &mut PickGeometry) {
|
||||
if self.is_empty() {
|
||||
return;
|
||||
}
|
||||
let k = |id: &str| !self.ids.contains(id);
|
||||
g.walls.retain(|w| k(&w.wall_id));
|
||||
g.slabs.retain(|s| k(&s.ceiling_id));
|
||||
g.openings.retain(|o| k(&o.opening_id));
|
||||
g.stairs.retain(|s| k(&s.stair_id));
|
||||
g.roofs.retain(|r| k(&r.roof_id));
|
||||
g.context_meshes.retain(|c| k(&c.context_object_id));
|
||||
g.columns.retain(|c| k(&c.column_id));
|
||||
g.solids.retain(|s| k(&s.solid_id));
|
||||
g.opening_meshes.retain(|o| k(&o.opening_id));
|
||||
g.drawings.retain(|d| k(&d.drawing_id));
|
||||
g.stair_meshes.retain(|s| k(&s.stair_id));
|
||||
g.drawing_meshes.retain(|d| k(&d.drawing_id));
|
||||
g.trees.retain(|t| k(&t.tree_id));
|
||||
}
|
||||
}
|
||||
|
||||
/// Wie [`parts`], ohne die Teile ausgeblendeter Klassen.
|
||||
pub fn parts_filtered(p: &Project, layered: bool, detail: f64, for_section: bool, f: &ClassFilter) -> Result<Parts, String> {
|
||||
let mut slabs = emit_slabs(p);
|
||||
slabs.extend(emit_stairs(p, for_section));
|
||||
let mut out = Parts {
|
||||
walls: emit_walls(p, layered)?,
|
||||
slabs,
|
||||
context_meshes: emit_context_meshes(p),
|
||||
column_meshes: {
|
||||
let mut m = emit_columns(p);
|
||||
m.extend(emit_trees(p));
|
||||
m
|
||||
},
|
||||
opening_meshes: emit_opening_meshes_with(p, detail, &|o| f.keep_opening(o)),
|
||||
stair_meshes: emit_stair_meshes(p),
|
||||
stair_railings: emit_stair_railings(p),
|
||||
roof_meshes: emit_roofs(p, None)?,
|
||||
roof_layers: emit_roof_cut_layers(p)?,
|
||||
};
|
||||
f.retain_walls(&mut out);
|
||||
f.retain_rest(p, &mut out);
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Stütze (25), Baum (13), Treppe mit Geländer (35) und eine Linie (60) auf zwei Geschossen.
|
||||
fn project(hidden: &[&str]) -> Project {
|
||||
let layers: Vec<serde_json::Value> = ["25", "13", "35", "60"].iter().map(|c| serde_json::json!({"code": c, "name": c, "color": "#000000", "visible": !hidden.contains(c)})).collect();
|
||||
serde_json::from_value(serde_json::json!({
|
||||
"id": "p", "name": "t", "lineStyles": [], "hatches": [], "components": [], "wallTypes": [], "layers": layers, "openings": [], "walls": [],
|
||||
"drawingLevels": [
|
||||
{"id": "EG", "name": "EG", "kind": "floor", "visible": true, "locked": false, "floorHeight": 3.0, "baseElevation": 0.0},
|
||||
{"id": "OG", "name": "OG", "kind": "floor", "visible": true, "locked": false, "floorHeight": 3.0, "baseElevation": 3.0}],
|
||||
"columns": [{"id": "k1", "type": "column", "floorId": "OG", "categoryCode": "25", "position": {"x": 2, "y": 3}, "profile": {"kind": "rect", "width": 0.3, "depth": 0.3}, "rotation": 0, "height": 2.5}],
|
||||
"trees": [{"id": "T1", "type": "tree", "floorId": "EG", "categoryCode": "13", "position": {"x": 20, "y": 5}, "trunkDiameter": 0.4, "crownDiameter": 6.0, "crownBase": 3.0, "height": 12.0}],
|
||||
"stairTypes": [{"id": "t", "name": "T", "structure": "massiv", "closedRisers": false, "treadThickness": 0.04, "railing": "beide", "defaultWidth": 1.0}],
|
||||
"stairs": [{"id": "s1", "type": "stair", "floorId": "EG", "categoryCode": "35", "shape": "straight", "start": {"x": 0, "y": 0}, "dir": {"x": 1, "y": 0},
|
||||
"runLength": 3.0, "width": 1.0, "stepCount": 16, "totalRise": 2.8, "typeId": "t"}],
|
||||
"drawings2d": [{"id": "L", "type": "drawing2d", "levelId": "EG", "categoryCode": "60", "geom": {"shape": "line", "a": {"x": 0, "y": 0}, "b": {"x": 5, "y": 0}}}]
|
||||
}))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Teile je Klasse: Stütze, Baum, Treppe (Tritte + Geländer), Linie.
|
||||
fn counts(p: &Project, f: &ClassFilter, gap: f64) -> [usize; 4] {
|
||||
let parts = crate::explode3d::parts_filtered(p, true, 2.0, false, gap, f).unwrap();
|
||||
let col = parts.column_meshes.iter().filter(|m| matches!(m.owner, Owner::Column(_))).count();
|
||||
let tree = parts.column_meshes.iter().filter(|m| matches!(m.owner, Owner::Tree(_))).count();
|
||||
let stair = parts.slabs.iter().filter(|s| s.ceiling_id == "s1").count() + parts.stair_railings.len();
|
||||
let lines = crate::explode3d::drawing_line_verts_filtered(p, gap, f).len();
|
||||
[col, tree, stair, lines]
|
||||
}
|
||||
|
||||
/// Jede Klasse einzeln aus (Ebenen-Baum bzw. `hide`): nur ihr Teil fehlt im 3D (auch in der Explosion) und im Pick.
|
||||
#[test]
|
||||
fn klasse_aus_teil_fehlt_in_parts_und_pick() {
|
||||
let p = project(&[]);
|
||||
for gap in [0.0, 2.0] {
|
||||
let all = counts(&p, &ClassFilter::from_text(&p, ""), gap);
|
||||
assert!(all.iter().all(|&n| n > 0), "{all:?}");
|
||||
for (k, code) in ["25", "13", "35", "60"].into_iter().enumerate() {
|
||||
for (q, text) in [(project(&[code]), String::new()), (p.clone(), format!(r#"{{"hide":["{code}"]}}"#))] {
|
||||
let f = ClassFilter::from_text(&q, &text);
|
||||
let got = counts(&q, &f, gap);
|
||||
for (i, n) in got.iter().enumerate() {
|
||||
assert_eq!(*n == 0, i == k, "Klasse {code} aus, Abstand {gap}: {got:?}");
|
||||
}
|
||||
let mut g = crate::explode3d::pick_geometry(&q, gap).unwrap();
|
||||
f.retain_pick(&mut g);
|
||||
let picks = [g.columns.len(), g.trees.len(), g.stairs.len() + g.stair_meshes.len(), g.drawings.len()];
|
||||
for (i, n) in picks.iter().enumerate() {
|
||||
assert_eq!(*n == 0, i == k, "Pick, Klasse {code} aus, Abstand {gap}: {picks:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ pub fn column_slabs(p: &Project) -> Vec<RSlab> {
|
||||
/// Stützen als Prisma-Meshes (`emitColumns`).
|
||||
pub fn emit_columns(p: &Project) -> Vec<RMesh> {
|
||||
let mut out = Vec::new();
|
||||
for col in p.columns.as_deref().unwrap_or(&[]) {
|
||||
for (ci, col) in p.columns.as_deref().unwrap_or(&[]).iter().enumerate() {
|
||||
if col.height <= 0.0 {
|
||||
continue;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ pub fn emit_columns(p: &Project) -> Vec<RMesh> {
|
||||
.map_or(COLUMN_RGB, |c| hex_to_rgb(&c.color, COLUMN_RGB));
|
||||
// [169] Runde Stütze glatt schattiert (Mantel ohne Facetten), eckige kantig.
|
||||
let crease_angle = matches!(col.profile, ColumnProfile::Round { .. }).then_some(COLUMN_CREASE_DEG);
|
||||
out.push(RMesh { crease_angle, positions, indices, kind: "extrusion", color, vertex_colors: None, material_index: None });
|
||||
out.push(RMesh { crease_angle, positions, indices, kind: "extrusion", color, vertex_colors: None, material_index: None, owner: Owner::Column(ci) });
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -168,9 +168,9 @@ pub fn emit_trees(p: &Project) -> Vec<RMesh> {
|
||||
for (i, g) in crate::tree::geoms(p) {
|
||||
let (trunk_rgb, crown_rgb) = crate::tree::colors(&trees[i]);
|
||||
let (positions, indices) = g.trunk_mesh(8);
|
||||
out.push(RMesh { crease_angle: None, positions, indices, kind: "extrusion", color: trunk_rgb, vertex_colors: None, material_index: None });
|
||||
out.push(RMesh { crease_angle: None, positions, indices, kind: "extrusion", color: trunk_rgb, vertex_colors: None, material_index: None, owner: Owner::Tree(i) });
|
||||
let (positions, indices) = g.crown_mesh(8, 12);
|
||||
out.push(RMesh { crease_angle: None, positions, indices, kind: "extrusion", color: crown_rgb, vertex_colors: None, material_index: None });
|
||||
out.push(RMesh { crease_angle: None, positions, indices, kind: "extrusion", color: crown_rgb, vertex_colors: None, material_index: None, owner: Owner::Tree(i) });
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn emit_context_meshes(p: &Project) -> Vec<RMesh> {
|
||||
let mut out = Vec::new();
|
||||
// [T6]/[114] Ebenen-Sichtbarkeit: ein ausgeblendetes Gelände (Kategorie „02") verschwindet auch im 3D.
|
||||
let hidden = hidden_category_codes(&p.layers);
|
||||
for obj in p.context.as_deref().unwrap_or(&[]) {
|
||||
for (ci, obj) in p.context.as_deref().unwrap_or(&[]).iter().enumerate() {
|
||||
// [181] Sichtbarkeit allein über die Klasse.
|
||||
if hidden.contains(obj.category_code()) {
|
||||
continue;
|
||||
@@ -48,6 +48,7 @@ pub fn emit_context_meshes(p: &Project) -> Vec<RMesh> {
|
||||
color: TERRAIN_RGB,
|
||||
vertex_colors: crate::excavation::terrain_vertex_colors(p, m),
|
||||
material_index: None,
|
||||
owner: Owner::Context(ci),
|
||||
})
|
||||
}
|
||||
ContextObject::ImportedMesh(m) if m.positions.len() >= 9 && m.indices.len() >= 3 => out.push(RMesh {
|
||||
@@ -57,6 +58,7 @@ pub fn emit_context_meshes(p: &Project) -> Vec<RMesh> {
|
||||
color: IMPORTED_RGB,
|
||||
vertex_colors: None,
|
||||
material_index: None,
|
||||
owner: Owner::Context(ci),
|
||||
crease_angle: (m.smooth_shading == Some(true)).then(|| m.crease_angle.filter(|a| a.is_finite() && *a > 0.0).unwrap_or(DEFAULT_CREASE_DEG).min(180.0)),
|
||||
}),
|
||||
_ => {}
|
||||
|
||||
@@ -27,7 +27,8 @@ fn drawing_color(
|
||||
|
||||
/// Packt die darstellbaren Zeichnungen (Linie, Polylinie, Rechteck) in Chargen für `drawing2d_3d`.
|
||||
/// `lift`: zusätzliche Höhe je Geschoss-id (Explosionsaxonometrie [65], `explode3d.rs`; leer = keine).
|
||||
fn for_each_drawing_chunk(p: &Project, with_color: bool, lift: &HashMap<String, f64>, mut f: impl FnMut(&[f64], &[&Drawing2D])) {
|
||||
/// `filter`: Zeichnungen ausgeblendeter Klassen fallen weg ([180]).
|
||||
fn for_each_drawing_chunk(p: &Project, with_color: bool, lift: &HashMap<String, f64>, filter: &ClassFilter, mut f: impl FnMut(&[f64], &[&Drawing2D])) {
|
||||
if p.drawings2d.is_empty() {
|
||||
return;
|
||||
}
|
||||
@@ -46,7 +47,7 @@ fn for_each_drawing_chunk(p: &Project, with_color: bool, lift: &HashMap<String,
|
||||
ids.clear();
|
||||
buf.truncate(1);
|
||||
};
|
||||
for d in &p.drawings2d {
|
||||
for d in p.drawings2d.iter().filter(|d| !filter.hides(&d.id)) {
|
||||
// Teile einer Zeichnung: (Art, Punkte); ein Achsraster mit `show3d` liefert je Achse eines.
|
||||
let parts: Vec<(f64, Vec<Vec2>)> = match &d.geom {
|
||||
Drawing2DGeom::Line { a, b } => vec![(1.0, vec![*a, *b])],
|
||||
@@ -80,8 +81,13 @@ pub fn drawing_line_verts(p: &Project) -> Vec<f32> {
|
||||
|
||||
/// Wie [`drawing_line_verts`], jede Spur um `lift[level_id]` angehoben (Explosion [65]).
|
||||
pub fn drawing_line_verts_lifted(p: &Project, lift: &HashMap<String, f64>) -> Vec<f32> {
|
||||
drawing_line_verts_filtered(p, lift, &ClassFilter::none())
|
||||
}
|
||||
|
||||
/// Wie [`drawing_line_verts_lifted`], ohne Zeichnungen ausgeblendeter Klassen ([180]).
|
||||
pub fn drawing_line_verts_filtered(p: &Project, lift: &HashMap<String, f64>, filter: &ClassFilter) -> Vec<f32> {
|
||||
let mut out = Vec::new();
|
||||
for_each_drawing_chunk(p, true, lift, |buf, _| out.extend(crate::drawing2d_3d::line_verts(buf)));
|
||||
for_each_drawing_chunk(p, true, lift, filter, |buf, _| out.extend(crate::drawing2d_3d::line_verts(buf)));
|
||||
out
|
||||
}
|
||||
|
||||
@@ -97,7 +103,7 @@ pub struct PickDrawingSeg {
|
||||
|
||||
pub(crate) fn pick_drawing_segs(p: &Project, lift: &HashMap<String, f64>) -> Vec<PickDrawingSeg> {
|
||||
let mut out = Vec::new();
|
||||
for_each_drawing_chunk(p, false, lift, |buf, drawings| {
|
||||
for_each_drawing_chunk(p, false, lift, &ClassFilter::none(), |buf, drawings| {
|
||||
let f = crate::drawing2d_3d::pick_segs(buf, DRAWING_PICK_TOLERANCE);
|
||||
for c in f.chunks_exact(6) {
|
||||
out.push(PickDrawingSeg { start: [c[0], c[1]], end: [c[2], c[3]], base_elevation: c[4], drawing_id: drawings[c[5] as usize].id.clone() });
|
||||
|
||||
@@ -31,6 +31,7 @@ mod roofs;
|
||||
mod context;
|
||||
mod drawings;
|
||||
mod pick;
|
||||
mod classes;
|
||||
|
||||
pub use ceilings::*;
|
||||
pub use columns::*;
|
||||
@@ -41,6 +42,7 @@ pub use roofs::*;
|
||||
pub use context::*;
|
||||
pub use drawings::*;
|
||||
pub use pick::*;
|
||||
pub use classes::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -110,6 +112,9 @@ pub struct RMesh {
|
||||
/// [T4] Glatt schattieren mit Knickwinkel (Grad), s. `render3d::types::MeshInput.creaseAngle`.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub crease_angle: Option<f64>,
|
||||
/// [180] Herkunft (Element) für den Klassen-Filter; nur im Kern.
|
||||
#[serde(skip)]
|
||||
pub owner: Owner,
|
||||
}
|
||||
|
||||
/// [T4] Vorgabe-Knickwinkel (Grad) für glatt schattierte Import-Meshes.
|
||||
@@ -135,18 +140,7 @@ pub struct Parts {
|
||||
}
|
||||
|
||||
/// `detail`: 0 grob, 1 mittel, 2 fein.
|
||||
/// Ohne Klassen-Filter (nur Kontext nach dem Ebenen-Baum); gefiltert: [`parts_filtered`].
|
||||
pub fn parts(p: &Project, layered: bool, detail: f64, for_section: bool) -> Result<Parts, String> {
|
||||
let mut slabs = emit_slabs(p);
|
||||
slabs.extend(emit_stairs(p, for_section));
|
||||
Ok(Parts {
|
||||
walls: emit_walls(p, layered)?,
|
||||
slabs,
|
||||
context_meshes: emit_context_meshes(p),
|
||||
column_meshes: { let mut m = emit_columns(p); m.extend(emit_trees(p)); m },
|
||||
opening_meshes: emit_opening_meshes(p, detail),
|
||||
stair_meshes: emit_stair_meshes(p),
|
||||
stair_railings: emit_stair_railings(p),
|
||||
roof_meshes: emit_roofs(p, None)?,
|
||||
roof_layers: emit_roof_cut_layers(p)?,
|
||||
})
|
||||
parts_filtered(p, layered, detail, for_section, &ClassFilter::none())
|
||||
}
|
||||
@@ -174,18 +174,24 @@ fn write_opening(w: &mut FlatWriter, p: &Project, op: &Opening) {
|
||||
/// Bogenwände ([T2]): je Wand auf der abgewickelten Ersatzwand gerechnet und die Ecken gebogen — die
|
||||
/// Einbauteile bleiben gerade (Sehne zwischen den Laibungen), ihre Enden sitzen radial in der Laibung.
|
||||
pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec<RMesh> {
|
||||
emit_opening_meshes_with(p, detail, &|_| true)
|
||||
}
|
||||
|
||||
/// Wie [`emit_opening_meshes`], nur für die Öffnungen mit `keep` ([180] Klassen-Filter: die Teile einer
|
||||
/// Wand werden gemeinsam gerechnet, darum wirkt der Filter auf die Eingabe).
|
||||
pub fn emit_opening_meshes_with(p: &Project, detail: f64, keep: &dyn Fn(&Opening) -> bool) -> Vec<RMesh> {
|
||||
let arcs: Vec<usize> = p.walls.iter().enumerate().filter(|(_, w)| crate::wall_arc::WallArc::of_wall(w).is_some()).map(|(i, _)| i).collect();
|
||||
if arcs.is_empty() {
|
||||
return emit_opening_meshes_plain(p, detail);
|
||||
return emit_opening_meshes_plain(p, detail, keep);
|
||||
}
|
||||
let mut q = p.clone();
|
||||
let arc_ids: std::collections::HashSet<&str> = arcs.iter().map(|&i| p.walls[i].id.as_str()).collect();
|
||||
q.openings = p.openings.as_ref().map(|v| v.iter().filter(|o| !arc_ids.contains(o.host_wall_id.as_str())).cloned().collect());
|
||||
let mut out = emit_opening_meshes_plain(&q, detail);
|
||||
q.openings = p.openings.as_ref().map(|v| v.iter().filter(|o| keep(o) && !arc_ids.contains(o.host_wall_id.as_str())).cloned().collect());
|
||||
let mut out = emit_opening_meshes_plain(&q, detail, &|_| true);
|
||||
for &i in &arcs {
|
||||
let Some((arc, v)) = crate::wall_arc::unrolled_wall(&p.walls[i]) else { continue };
|
||||
q.walls = vec![v];
|
||||
let own: Vec<Opening> = p.openings.as_deref().unwrap_or(&[]).iter().filter(|o| o.host_wall_id == p.walls[i].id).cloned().collect();
|
||||
let own: Vec<Opening> = p.openings.as_deref().unwrap_or(&[]).iter().filter(|o| o.host_wall_id == p.walls[i].id && keep(o)).cloned().collect();
|
||||
// [106] Öffnungen mit Schichteinzug liegen gerade auf der Sehne über `reveal_zone` (wie die
|
||||
// Teilwand mit dem Loch, `wall_arc::chord_walls`); die übrigen werden gebogen.
|
||||
let zone = |o: &Opening| -> Option<(f64, f64)> {
|
||||
@@ -195,7 +201,7 @@ pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec<RMesh> {
|
||||
};
|
||||
let (zoned, bent): (Vec<Opening>, Vec<Opening>) = own.into_iter().partition(|o| zone(o).is_some());
|
||||
q.openings = Some(bent);
|
||||
for mut m in emit_opening_meshes_plain(&q, detail) {
|
||||
for mut m in emit_opening_meshes_plain(&q, detail, &|_| true) {
|
||||
for c in m.positions.chunks_exact_mut(3) {
|
||||
let w = arc.point(c[0], c[1]);
|
||||
c[0] = w.x;
|
||||
@@ -207,7 +213,7 @@ pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec<RMesh> {
|
||||
let Some((sa, sb)) = zone(&o) else { continue };
|
||||
let (pa, u, chord) = crate::wall_arc::chord_of(&arc, sa, sb);
|
||||
q.openings = Some(vec![o]);
|
||||
for mut m in emit_opening_meshes_plain(&q, detail) {
|
||||
for mut m in emit_opening_meshes_plain(&q, detail, &|_| true) {
|
||||
for c in m.positions.chunks_exact_mut(3) {
|
||||
let t = (c[0] - sa) / (sb - sa) * chord;
|
||||
let (x, y) = (pa.x + u.x * t - u.y * c[1], pa.y + u.y * t + u.x * c[1]);
|
||||
@@ -221,11 +227,14 @@ pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec<RMesh> {
|
||||
out
|
||||
}
|
||||
|
||||
fn emit_opening_meshes_plain(p: &Project, detail: f64) -> Vec<RMesh> {
|
||||
let by_wall = p.openings_by_wall();
|
||||
fn emit_opening_meshes_plain(p: &Project, detail: f64, keep: &dyn Fn(&Opening) -> bool) -> Vec<RMesh> {
|
||||
let mut by_wall = p.openings_by_wall();
|
||||
for v in by_wall.values_mut() {
|
||||
v.retain(|o| keep(o));
|
||||
}
|
||||
let per: Vec<WallOpeningMeshes> = p.walls.iter().map(|wall| wall_opening_meshes(p, wall, by_wall.get(wall.id.as_str()).map_or(&[][..], |v| v.as_slice()), detail)).collect();
|
||||
let mut out = assemble_opening_meshes(per);
|
||||
out.extend(surface_window_meshes(p));
|
||||
out.extend(surface_window_meshes_with(p, keep));
|
||||
out
|
||||
}
|
||||
|
||||
@@ -239,7 +248,7 @@ pub(crate) struct WallOpeningMeshes {
|
||||
}
|
||||
|
||||
/// Reihenfolge des ganzen Modells: alle Wände je Durchgang, dann alle Zargen, dann alle Formöffnungen
|
||||
/// (ohne die Dach-/Deckenfenster, s. [`surface_window_meshes`]).
|
||||
/// (ohne die Dach-/Deckenfenster, s. [`surface_window_meshes_with`]).
|
||||
pub(crate) fn assemble_opening_meshes(per: Vec<WallOpeningMeshes>) -> Vec<RMesh> {
|
||||
let mut lists: [Vec<RMesh>; 5] = Default::default();
|
||||
for m in per {
|
||||
@@ -251,10 +260,10 @@ pub(crate) fn assemble_opening_meshes(per: Vec<WallOpeningMeshes>) -> Vec<RMesh>
|
||||
lists.into_iter().flatten().collect()
|
||||
}
|
||||
|
||||
/// Dach-/Deckenfenster ([103]).
|
||||
pub(crate) fn surface_window_meshes(p: &Project) -> Vec<RMesh> {
|
||||
/// Dach-/Deckenfenster ([103]) der Öffnungen mit `keep` ([180] Klassen-Filter).
|
||||
pub(crate) fn surface_window_meshes_with(p: &Project, keep: &dyn Fn(&Opening) -> bool) -> Vec<RMesh> {
|
||||
let mut out = Vec::new();
|
||||
for op in p.openings.as_deref().unwrap_or(&[]) {
|
||||
for op in p.openings.as_deref().unwrap_or(&[]).iter().filter(|o| keep(o)) {
|
||||
if let Some(f) = crate::opening_shape::host_frame(p, op) {
|
||||
for (part, positions) in crate::opening_shape::surface_window_boxes(p, op, &f) {
|
||||
out.push(box_mesh(positions, PART_RGB[part as usize]));
|
||||
@@ -335,6 +344,7 @@ fn box_meshes_of_flat(buf: &[f64]) -> Vec<RMesh> {
|
||||
color: PART_RGB.get(part).copied().unwrap_or(PART_RGB[1]),
|
||||
vertex_colors: None,
|
||||
material_index: None,
|
||||
owner: Owner::None,
|
||||
});
|
||||
i += 25;
|
||||
}
|
||||
@@ -342,7 +352,7 @@ fn box_meshes_of_flat(buf: &[f64]) -> Vec<RMesh> {
|
||||
}
|
||||
|
||||
fn box_mesh(positions: [f64; 24], color: Rgb) -> RMesh {
|
||||
RMesh { crease_angle: None, positions: positions.to_vec(), indices: OPENING_BOX_TRIS.to_vec(), kind: "extrusion", color, vertex_colors: None, material_index: None }
|
||||
RMesh { crease_angle: None, positions: positions.to_vec(), indices: OPENING_BOX_TRIS.to_vec(), kind: "extrusion", color, vertex_colors: None, material_index: None, owner: Owner::None }
|
||||
}
|
||||
|
||||
/// Schichten einer Wand für die Füllkörper einer Formöffnung ([G3]): Dicke (auf `total` skaliert)
|
||||
@@ -513,7 +523,7 @@ fn door_frame_boxes(out: &mut Vec<RMesh>, wall: &Wall, wr: &WallRef, op: &Openin
|
||||
];
|
||||
for b in boxes.into_iter().flatten() {
|
||||
out.push(RMesh {
|
||||
crease_angle: None, positions: b.to_vec(), indices: OPENING_BOX_TRIS.to_vec(), kind: "extrusion", color: rgb, vertex_colors: None, material_index: None });
|
||||
crease_angle: None, positions: b.to_vec(), indices: OPENING_BOX_TRIS.to_vec(), kind: "extrusion", color: rgb, vertex_colors: None, material_index: None, owner: Owner::None });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ pub struct RRoofLayer {
|
||||
pub color: Rgb,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub cut: Option<RCutMeta>,
|
||||
/// [180] Herkunft (Dach) für den Klassen-Filter; nur im Kern.
|
||||
#[serde(skip)]
|
||||
pub owner: Owner,
|
||||
}
|
||||
|
||||
fn push_fan_triangles(positions: &mut Vec<f64>, indices: &mut Vec<u32>, pts: &[V3], flip: bool) {
|
||||
@@ -547,7 +550,7 @@ pub fn emit_roofs(p: &Project, only_roof: Option<&str>) -> Result<Vec<RMesh>, St
|
||||
let color = override_color.unwrap_or_else(|| p.component(comp_id).map_or(WALL_RGB, |c| hex_to_rgb(&c.color, WALL_RGB)));
|
||||
let material_index = if override_color.is_none() && !comp_id.is_empty() { material_layer(p, &maps, comp_id) } else { None };
|
||||
let m = crate::roof_parapet::mesh(&pp);
|
||||
out.push(RMesh { crease_angle: None, positions: m.positions, indices: m.indices, kind: "extrusion", color, vertex_colors: None, material_index });
|
||||
out.push(RMesh { crease_angle: None, positions: m.positions, indices: m.indices, kind: "extrusion", color, vertex_colors: None, material_index, owner: Owner::Roof(ri) });
|
||||
}
|
||||
// Verschnittene Dächer und Gauben ([G5]): Körper aus `roof_assembly`.
|
||||
if let Some(solids) = crate::roof_assembly::roof_solids_with(p, ri, &nb) {
|
||||
@@ -561,7 +564,7 @@ pub fn emit_roofs(p: &Project, only_roof: Option<&str>) -> Result<Vec<RMesh>, St
|
||||
let material_index = if (wall || override_color.is_none()) && !part.component_id.is_empty() { material_layer(p, &maps, &part.component_id) } else { None };
|
||||
let (positions, indices) = crate::roof_assembly::unshared(&part.mesh);
|
||||
out.push(RMesh {
|
||||
crease_angle: None, positions, indices, kind: "extrusion", color, vertex_colors: None, material_index });
|
||||
crease_angle: None, positions, indices, kind: "extrusion", color, vertex_colors: None, material_index, owner: Owner::Roof(ri) });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -592,7 +595,7 @@ pub fn emit_roofs(p: &Project, only_roof: Option<&str>) -> Result<Vec<RMesh>, St
|
||||
}
|
||||
if !indices.is_empty() {
|
||||
out.push(RMesh {
|
||||
crease_angle: None, positions, indices, kind: "extrusion", color, vertex_colors: None, material_index });
|
||||
crease_angle: None, positions, indices, kind: "extrusion", color, vertex_colors: None, material_index, owner: Owner::Roof(ri) });
|
||||
}
|
||||
offset_above += t;
|
||||
}
|
||||
@@ -622,7 +625,7 @@ pub fn emit_roof_cut_layers(p: &Project) -> Result<Vec<RRoofLayer>, String> {
|
||||
let polygon: Vec<V3> = plane.iter().map(|q| [q[0] - nrm[0] * offset_above, q[1] - nrm[1] * offset_above, q[2] - nrm[2] * offset_above]).collect();
|
||||
// Dachfenster ([103]): Reststücke statt der ganzen Fläche (Loch im Live-Schnitt).
|
||||
for polygon in clip_plane_holes(&polygon, &holes[i]) {
|
||||
out.push(RRoofLayer { polygon, normal: nrm, thickness: t, color, cut: cut.clone() });
|
||||
out.push(RRoofLayer { polygon, normal: nrm, thickness: t, color, cut: cut.clone(), owner: Owner::Roof(ri) });
|
||||
}
|
||||
}
|
||||
offset_above += t;
|
||||
|
||||
@@ -85,8 +85,10 @@ fn stair_slabs(stairs: &[(usize, &Stair)], slabs: Vec<crate::stairs3d::Slab>) ->
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn meshes_of(meshes: Vec<crate::mesh3d::Mesh>, color: Rgb) -> Vec<RMesh> {
|
||||
/// `owner`: Treppe (Index in `p.stairs`) eines Netzes aus seinem `src` ([180] Klassen-Filter).
|
||||
fn meshes_of(meshes: Vec<crate::mesh3d::Mesh>, color: Rgb, owner: impl Fn(usize) -> Option<usize>) -> Vec<RMesh> {
|
||||
meshes.into_iter().map(|m| RMesh {
|
||||
owner: owner(m.src).map_or(Owner::None, Owner::Stair),
|
||||
crease_angle: None, positions: m.positions, indices: m.indices, kind: "extrusion", color, vertex_colors: None, material_index: None }).collect()
|
||||
}
|
||||
|
||||
@@ -94,7 +96,7 @@ fn meshes_of(meshes: Vec<crate::mesh3d::Mesh>, color: Rgb) -> Vec<RMesh> {
|
||||
/// von Wendeltreppen (`emitStairMeshes`).
|
||||
pub fn emit_stair_meshes(p: &Project) -> Vec<RMesh> {
|
||||
match stair_input(p, |s, st| st.is_some_and(|t| t.structure == StairTypeStructure::Beton) && s.shape != StairShape::Unknown) {
|
||||
Some((_, buf)) => meshes_of(crate::stairs3d::slab_meshes(&buf), stair_rgb()),
|
||||
Some((stairs, buf)) => meshes_of(crate::stairs3d::slab_meshes(&buf), stair_rgb(), |i| stairs.get(i).map(|s| s.0)),
|
||||
None => vec![],
|
||||
}
|
||||
}
|
||||
@@ -129,7 +131,7 @@ pub fn stair_view_meshes(p: &Project) -> Vec<(usize, crate::mesh3d::Mesh, bool)>
|
||||
/// Podesttreppen (L, U, gerade mit Podest) über die Podeste ([151]).
|
||||
pub fn emit_stair_handrails(p: &Project) -> Vec<RMesh> {
|
||||
match stair_input(p, |s, st| s.shape != StairShape::Unknown && st.and_then(|t| t.railing).is_some_and(|r| r != StairTypeRailing::Keine)) {
|
||||
Some((_, buf)) => meshes_of(crate::stairs3d::railings(&buf), rail_rgb()),
|
||||
Some((stairs, buf)) => meshes_of(crate::stairs3d::railings(&buf), rail_rgb(), |i| stairs.get(i).map(|s| s.0)),
|
||||
None => vec![],
|
||||
}
|
||||
}
|
||||
@@ -162,12 +164,19 @@ pub fn stair_guard_meshes_by_floor(p: &Project) -> Vec<(usize, String, crate::me
|
||||
|
||||
/// Absturzsicherungen, die auf dem Geschoss `floor_id` stehen (Körper wie in [`emit_stair_railings`]).
|
||||
pub fn emit_stair_guards_on(p: &Project, floor_id: &str) -> Vec<RMesh> {
|
||||
meshes_of(stair_guard_meshes_by_floor(p).into_iter().filter(|(_, f, _)| f == floor_id).map(|(_, _, m)| m).collect(), rail_rgb())
|
||||
guard_meshes(stair_guard_meshes_by_floor(p).into_iter().filter(|(_, f, _)| f == floor_id).map(|(si, _, m)| (si, m)).collect())
|
||||
}
|
||||
|
||||
/// Handlauf, Pfosten und Absturzsicherung der Treppen (`emitStairRailings`).
|
||||
pub fn emit_stair_railings(p: &Project) -> Vec<RMesh> {
|
||||
let mut out = emit_stair_handrails(p);
|
||||
out.extend(meshes_of(stair_guard_meshes(p).into_iter().map(|(_, m)| m).collect(), rail_rgb()));
|
||||
out.extend(guard_meshes(stair_guard_meshes(p)));
|
||||
out
|
||||
}
|
||||
|
||||
/// Absturzsicherungen je Treppe (Index in `p.stairs`) als `RMesh`.
|
||||
fn guard_meshes(v: Vec<(usize, crate::mesh3d::Mesh)>) -> Vec<RMesh> {
|
||||
let owners: Vec<usize> = v.iter().map(|(si, _)| *si).collect();
|
||||
let meshes = v.into_iter().enumerate().map(|(k, (_, m))| crate::mesh3d::Mesh { src: k, ..m }).collect();
|
||||
meshes_of(meshes, rail_rgb(), |k| owners.get(k).copied())
|
||||
}
|
||||
Reference in new issue
Block a user