[180] 3D nach Klassen: ausgeblendete Klassen fehlen in Viewer, Explosion, Pick und model3dParts
Jedes 3D-Teil kennt sein Element (RMesh/RRoofLayer.owner, Wände/Decken/Treppen über ihre id); model3d::ClassFilter (Ebenen-Baum samt Elternklassen plus `hide` aus dem Darstellungsmodus) filtert nach dem Cache. `layers` ist im 3D-Cache keine globale Änderung, Teil-Updates halten Einträge ausgeblendeter Klassen (wallKeep/openingKeep), Öffnungs-Varianten je Wand gemerkt. Öffnungen gehen mit dem Wirt; 2D-Spuren, Flächenmuster, truck-Körper, 3D-Schatten (08) und zulässige Hülle (01) folgen den Klassen. CLI model3d --hide.
This commit is contained in:
27 files changed
+874
-159
No files matched your search
@@ -39,7 +39,7 @@ Neues Modul: `<modul>.rs` und `mod` in `lib.rs`, Bindungen in `web/<modul>.rs` u
|
||||
|
||||
| Datei | Inhalt |
|
||||
|---|---|
|
||||
| `model3d/` | 3D-Ableitung aus dem Projekt: `parts()` in `mod.rs`; je eine Datei für Decken, Stützen und Bäume, Wände, Öffnungen, Treppen, Dächer, Kontext, Zeichnungs-Spuren, Pick-Geometrie; Tests in `tests.rs` |
|
||||
| `model3d/` | 3D-Ableitung aus dem Projekt: `parts()` in `mod.rs`; je eine Datei für Decken, Stützen und Bäume, Wände, Öffnungen, Treppen, Dächer, Kontext, Zeichnungs-Spuren, Pick-Geometrie, Klassen-Filter (`classes.rs`, [180]); Tests in `tests.rs` |
|
||||
| `model3d_cache.rs` | inkrementelle 3D-Ableitung (Cache je Wand und Öffnung) |
|
||||
| `wall_bands.rs`, `wall_mesh_cut.rs` | Schichtbänder einer Wand; Wandnetz mit echtem Loch für Datei-Exporte |
|
||||
| `ceilings3d.rs`, `columns3d.rs`, `stairs3d.rs`, `openings3d.rs`, `drawing2d_3d.rs`, `mesh3d.rs` | Netze je Bauteilart |
|
||||
|
||||
@@ -801,12 +801,24 @@ impl Document {
|
||||
/// 3D-Modell in Teilen ([58]) wie `model3d::parts`, Wände und Öffnungs-Einbauteile je Wand aus dem
|
||||
/// Cache (`model3d_cache`); `structs` wie dort.
|
||||
pub fn model3d_parts(&mut self, layered: bool, detail: f64, for_section: bool, structs: bool, delta: Option<u64>) -> Result<crate::model3d_cache::CachedParts, String> {
|
||||
self.model3d_parts_with(layered, detail, for_section, structs, delta, "")
|
||||
}
|
||||
|
||||
/// Wie [`Self::model3d_parts`] mit Klassen-Filter ([180], `text` = `{"hide": [codes]}` zusätzlich zum
|
||||
/// Ebenen-Baum, s. `model3d::ClassFilter::from_text`).
|
||||
pub fn model3d_parts_with(&mut self, layered: bool, detail: f64, for_section: bool, structs: bool, delta: Option<u64>, text: &str) -> Result<crate::model3d_cache::CachedParts, String> {
|
||||
self.project()?;
|
||||
let p = self.typed.as_ref().expect("gerade gelesen");
|
||||
let n_open = p.openings.as_ref().map_or(0, Vec::len);
|
||||
let walls = self.revs.items("walls", p.walls.len()).to_vec();
|
||||
let openings = self.revs.items("openings", n_open).to_vec();
|
||||
self.model3d_cache.parts(p, &self.revs, &walls, &openings, layered, detail, for_section, structs, delta)
|
||||
let filter = crate::model3d::ClassFilter::from_text(p, text);
|
||||
self.model3d_cache.parts(p, &self.revs, &walls, &openings, layered, detail, for_section, structs, delta, &filter)
|
||||
}
|
||||
|
||||
/// [180] Letzte Statistik des 3D-Caches (Tests): neu gerechnete Öffnungs-Varianten des Klassen-Filters.
|
||||
pub fn model3d_variants(&self) -> usize {
|
||||
self.model3d_cache.last_variants
|
||||
}
|
||||
|
||||
/// Letzte Statistik des 3D-Caches (Tests): neu gerechnete Wände / Öffnungs-Wände.
|
||||
|
||||
@@ -122,7 +122,12 @@ fn shifted<T>(mut v: Vec<T>, dz: f64, f: fn(&mut T, f64)) -> Vec<T> {
|
||||
|
||||
/// `model3d::parts` mit auseinandergezogenen Geschossen; `gap` ≤ 0 liefert genau `parts`.
|
||||
pub fn parts(p: &Project, layered: bool, detail: f64, for_section: bool, gap: f64) -> Result<Parts, String> {
|
||||
let Some(ex) = Explode::new(p, gap) else { return model3d::parts(p, layered, detail, for_section) };
|
||||
parts_filtered(p, layered, detail, for_section, gap, &model3d::ClassFilter::none())
|
||||
}
|
||||
|
||||
/// Wie [`parts`], ohne die Teile ausgeblendeter Klassen ([180], `model3d::parts_filtered`).
|
||||
pub fn parts_filtered(p: &Project, layered: bool, detail: f64, for_section: bool, gap: f64, filter: &model3d::ClassFilter) -> Result<Parts, String> {
|
||||
let Some(ex) = Explode::new(p, gap) else { return model3d::parts_filtered(p, layered, detail, for_section, filter) };
|
||||
let mut walls = model3d::emit_walls(p, layered)?;
|
||||
for w in &mut walls {
|
||||
shift_wall(w, ex.of(&w.wall_id));
|
||||
@@ -157,21 +162,31 @@ pub fn parts(p: &Project, layered: bool, detail: f64, for_section: bool, gap: f6
|
||||
q.trees = p.trees.as_ref().map(|v| v.iter().filter(|t| pick(&t.floor_id)).cloned().collect());
|
||||
q.stairs = p.stairs.as_ref().map(|v| v.iter().filter(|s| pick(&s.floor_id)).cloned().collect());
|
||||
q.roofs = p.roofs.as_ref().map(|v| v.iter().filter(|r| pick(&r.floor_id)).cloned().collect());
|
||||
q.openings = p.openings.as_ref().map(|v| v.iter().filter(|o| pick(ex.floor_of.get(o.id.as_str()).copied().unwrap_or(""))).cloned().collect());
|
||||
out.column_meshes.extend(shifted(model3d::emit_columns(&q), dz, shift_mesh));
|
||||
out.column_meshes.extend(shifted(model3d::emit_trees(&q), dz, shift_mesh));
|
||||
out.stair_meshes.extend(shifted(model3d::emit_stair_meshes(&q), dz, shift_mesh));
|
||||
q.openings = p.openings.as_ref().map(|v| v.iter().filter(|o| filter.keep_opening(o) && pick(ex.floor_of.get(o.id.as_str()).copied().unwrap_or(""))).cloned().collect());
|
||||
// [180] Herkunft der Teile zeigt in die Listen von `q` (bzw. `p` für die Absturzsicherung).
|
||||
let kept = |pp: &Project, mut v: Vec<RMesh>| {
|
||||
v.retain(|m| filter.keep_owner(pp, m.owner));
|
||||
v
|
||||
};
|
||||
out.column_meshes.extend(shifted(kept(&q, model3d::emit_columns(&q)), dz, shift_mesh));
|
||||
out.column_meshes.extend(shifted(kept(&q, model3d::emit_trees(&q)), dz, shift_mesh));
|
||||
out.stair_meshes.extend(shifted(kept(&q, model3d::emit_stair_meshes(&q)), dz, shift_mesh));
|
||||
// Handläufe folgen der Treppe, die Absturzsicherung der Decke mit dem Loch (Geschoss `g`, [155]).
|
||||
out.stair_railings.extend(shifted(model3d::emit_stair_handrails(&q), dz, shift_mesh));
|
||||
out.stair_railings.extend(shifted(kept(&q, model3d::emit_stair_handrails(&q)), dz, shift_mesh));
|
||||
if let Some(fid) = g {
|
||||
out.stair_railings.extend(shifted(model3d::emit_stair_guards_on(p, fid), dz, shift_mesh));
|
||||
out.stair_railings.extend(shifted(kept(p, model3d::emit_stair_guards_on(p, fid)), dz, shift_mesh));
|
||||
}
|
||||
out.roof_meshes.extend(shifted(model3d::emit_roofs(&q, None)?, dz, shift_mesh));
|
||||
out.roof_layers.extend(shifted(model3d::emit_roof_cut_layers(&q)?, dz, shift_roof_layer));
|
||||
out.roof_meshes.extend(shifted(kept(&q, model3d::emit_roofs(&q, None)?), dz, shift_mesh));
|
||||
let mut layers = model3d::emit_roof_cut_layers(&q)?;
|
||||
layers.retain(|l| filter.keep_owner(&q, l.owner));
|
||||
out.roof_layers.extend(shifted(layers, dz, shift_roof_layer));
|
||||
// Öffnungen brauchen alle Dächer (Dachfenster-Wirt liegt im selben Geschoss, Rest schadet nicht).
|
||||
q.roofs = p.roofs.clone();
|
||||
out.opening_meshes.extend(shifted(model3d::emit_opening_meshes(&q, detail), dz, shift_mesh));
|
||||
}
|
||||
filter.retain_walls(&mut out);
|
||||
out.slabs.retain(|s| !filter.hides(&s.ceiling_id));
|
||||
out.context_meshes.retain(|m| filter.keep_owner(p, m.owner));
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
@@ -194,6 +209,11 @@ pub fn drawing_line_verts(p: &Project, gap: f64) -> Vec<f32> {
|
||||
model3d::drawing_line_verts_lifted(p, &floor_offsets(p, gap))
|
||||
}
|
||||
|
||||
/// Wie [`drawing_line_verts`], ohne Zeichnungen ausgeblendeter Klassen ([180]).
|
||||
pub fn drawing_line_verts_filtered(p: &Project, gap: f64, filter: &model3d::ClassFilter) -> Vec<f32> {
|
||||
model3d::drawing_line_verts_filtered(p, &floor_offsets(p, gap), filter)
|
||||
}
|
||||
|
||||
/// Pick-Geometrie passend zu [`parts`]; Kontext bleibt stehen wie im Modell.
|
||||
pub fn pick_geometry(p: &Project, gap: f64) -> Result<PickGeometry, String> {
|
||||
let mut g = model3d::pick_geometry(p)?;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -84,8 +84,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()
|
||||
}
|
||||
|
||||
@@ -93,7 +95,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![],
|
||||
}
|
||||
}
|
||||
@@ -128,7 +130,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![],
|
||||
}
|
||||
}
|
||||
@@ -160,12 +162,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())
|
||||
}
|
||||
@@ -10,15 +10,21 @@
|
||||
//! - Je Wand (Schlüssel: Element-Stand der Wand, `Revs::items`): gültig bei gleichen Element-Ständen der
|
||||
//! gehosteten Öffnungen und — für die Körper — gleichen Schnittlinien aus der Verschneidung.
|
||||
//!
|
||||
//! Ergebnis inhaltlich und als JSON Byte für Byte gleich wie [`model3d::parts`] (Test unten).
|
||||
//! Ergebnis inhaltlich und als JSON Byte für Byte gleich wie [`model3d::parts_filtered`] (Test unten).
|
||||
//!
|
||||
//! [180] Klassen: Der Cache ist klassenunabhängig (`layers` zählt nicht als globale Änderung), gefiltert
|
||||
//! wird beim Ausgeben ([`ClassFilter`]): Wände ausgeblendeter Klassen fallen weg; Öffnungs-Einbauteile
|
||||
//! einer Wand mit teils ausgeblendeten Öffnungen kommen aus einer Variante nur mit den sichtbaren (je
|
||||
//! Eintrag gemerkt, Umschalten rechnet sie nicht noch einmal).
|
||||
|
||||
use crate::joins::{JoinWall, WallCuts};
|
||||
use crate::model::{Opening, Project};
|
||||
use crate::model3d::{self, Parts, RMesh, RWall, WallOpeningMeshes};
|
||||
use crate::model3d::{self, ClassFilter, Parts, RMesh, RWall, WallOpeningMeshes};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Felder, die das 3D-Modell nicht lesen oder die der Cache selbst je Element verfolgt.
|
||||
const NOT_GLOBAL: &[&str] = &["walls", "openings", "drawings2d", "viewSnapshots", "viewSnapshotFolders", "viewTemplates"];
|
||||
/// `layers` (Klassen-Baum): nur der Filter beim Ausgeben liest ihn ([180]).
|
||||
const NOT_GLOBAL: &[&str] = &["walls", "openings", "drawings2d", "viewSnapshots", "viewSnapshotFolders", "viewTemplates", "layers"];
|
||||
|
||||
/// Laufnummern der Einträge, über alle Dokumente eindeutig: TS hält die gelieferten Einträge unter
|
||||
/// dieser Nummer ([`Model3dCache::parts`] mit `delta`).
|
||||
@@ -49,6 +55,22 @@ struct OpenEntry {
|
||||
meshes: WallOpeningMeshes,
|
||||
/// Je Liste (3 Durchgänge, Zargen, Formöffnungen) JSON ohne Klammern.
|
||||
json: [String; 5],
|
||||
/// [180] Varianten nur mit einem Teil der Öffnungen (Maske je gehostete Öffnung, `true` = sichtbar).
|
||||
variants: Vec<(Vec<bool>, OpenVariant)>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct OpenVariant {
|
||||
serial: u64,
|
||||
meshes: WallOpeningMeshes,
|
||||
json: [String; 5],
|
||||
}
|
||||
|
||||
/// Höchstens so viele Varianten je Wand (älteste fällt weg).
|
||||
const MAX_VARIANTS: usize = 4;
|
||||
|
||||
fn opening_json(m: &WallOpeningMeshes) -> [String; 5] {
|
||||
[&m.passes[0], &m.passes[1], &m.passes[2], &m.zargen, &m.shaped].map(|v| inner_json(v))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -74,6 +96,8 @@ pub struct Model3dCache {
|
||||
openings: Vec<(u64, HashMap<u64, OpenEntry>)>,
|
||||
/// Statistik (Tests): Wände/Öffnungs-Wände, die im letzten Aufruf neu gerechnet wurden.
|
||||
pub last_rebuilt: (usize, usize),
|
||||
/// [180] Statistik (Tests): im letzten Aufruf neu gerechnete Öffnungs-Varianten (Klassen-Filter).
|
||||
pub last_variants: usize,
|
||||
}
|
||||
|
||||
/// Ergebnis: die Teile (Wände/Öffnungen nur mit `structs`) und das JSON wie `serde_json::to_string(&parts)`.
|
||||
@@ -151,6 +175,7 @@ impl Model3dCache {
|
||||
for_section: bool,
|
||||
structs: bool,
|
||||
delta: Option<u64>,
|
||||
filter: &ClassFilter,
|
||||
) -> Result<CachedParts, String> {
|
||||
self.validate(p, revs);
|
||||
let openings = p.openings.as_deref().unwrap_or(&[]);
|
||||
@@ -228,7 +253,7 @@ impl Model3dCache {
|
||||
let mut arc_meshes: Option<Vec<RMesh>> = None;
|
||||
if arcs {
|
||||
self.openings[slot].1.clear();
|
||||
arc_meshes = Some(model3d::emit_opening_meshes(p, detail));
|
||||
arc_meshes = Some(model3d::emit_opening_meshes_with(p, detail, &|o| filter.keep_opening(o)));
|
||||
} else {
|
||||
let mut old_open = std::mem::take(&mut self.openings[slot].1);
|
||||
for (wi, wall) in p.walls.iter().enumerate() {
|
||||
@@ -240,12 +265,13 @@ impl Model3dCache {
|
||||
rebuilt.1 += 1;
|
||||
let refs: Vec<&Opening> = hosted(&wall.id).iter().map(|&i| &openings[i]).collect();
|
||||
let meshes = model3d::wall_opening_meshes(p, wall, &refs, detail);
|
||||
let json = [&meshes.passes[0], &meshes.passes[1], &meshes.passes[2], &meshes.zargen, &meshes.shaped].map(|v| inner_json(v));
|
||||
let json = opening_json(&meshes);
|
||||
OpenEntry {
|
||||
serial: next_serial(),
|
||||
openings: os,
|
||||
meshes,
|
||||
json,
|
||||
variants: Vec::new(),
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -253,6 +279,32 @@ impl Model3dCache {
|
||||
}
|
||||
}
|
||||
self.last_rebuilt = rebuilt;
|
||||
// [180] Öffnungs-Varianten der Wände mit teils ausgeblendeten Öffnungen (Maske je gehostete Öffnung).
|
||||
let masks: Vec<Vec<bool>> = if arcs {
|
||||
Vec::new()
|
||||
} else {
|
||||
p.walls.iter().map(|w| hosted(&w.id).iter().map(|&i| filter.keep_opening(&openings[i])).collect()).collect()
|
||||
};
|
||||
let mut variants_built = 0;
|
||||
for (wi, wall) in p.walls.iter().enumerate() {
|
||||
let Some(mask) = masks.get(wi) else { break };
|
||||
if mask.iter().all(|&b| b) || !mask.iter().any(|&b| b) {
|
||||
continue;
|
||||
}
|
||||
let Some(e) = open_fresh.get_mut(&wall_stamps[wi]) else { continue };
|
||||
if e.variants.iter().any(|(m, _)| m == mask) {
|
||||
continue;
|
||||
}
|
||||
variants_built += 1;
|
||||
let refs: Vec<&Opening> = hosted(&wall.id).iter().zip(mask).filter(|(_, &k)| k).map(|(&i, _)| &openings[i]).collect();
|
||||
let meshes = model3d::wall_opening_meshes(p, wall, &refs, detail);
|
||||
let json = opening_json(&meshes);
|
||||
if e.variants.len() >= MAX_VARIANTS {
|
||||
e.variants.remove(0);
|
||||
}
|
||||
e.variants.push((mask.clone(), OpenVariant { serial: next_serial(), meshes, json }));
|
||||
}
|
||||
self.last_variants = variants_built;
|
||||
|
||||
let mut slabs = model3d::emit_slabs(p);
|
||||
slabs.extend(model3d::emit_stairs(p, for_section));
|
||||
@@ -267,10 +319,42 @@ impl Model3dCache {
|
||||
roof_meshes: model3d::emit_roofs(p, None)?,
|
||||
roof_layers: model3d::emit_roof_cut_layers(p)?,
|
||||
};
|
||||
filter.retain_rest(p, &mut parts);
|
||||
// JSON in einem Zug (wie `serde_json::to_string(&parts)`): Bruchstücke sammeln, dann einmal kopieren.
|
||||
let wall_entries: Vec<&WallEntry> = wall_stamps.iter().map(|s| &fresh[s]).collect();
|
||||
let open_entries: Vec<&OpenEntry> = if arcs { Vec::new() } else { wall_stamps.iter().map(|s| &open_fresh[s]).collect() };
|
||||
let surface = if arcs { Vec::new() } else { model3d::surface_window_meshes(p) };
|
||||
// [180] Ausgeblendete Einträge bleiben beim Aufrufer (`keep`), damit Einblenden nichts neu schickt.
|
||||
let mut wall_entries: Vec<&WallEntry> = Vec::with_capacity(p.walls.len());
|
||||
let mut wall_keep: Vec<&WallEntry> = Vec::new();
|
||||
for (wi, s) in wall_stamps.iter().enumerate() {
|
||||
if filter.hides(&p.walls[wi].id) {
|
||||
wall_keep.push(&fresh[s]);
|
||||
} else {
|
||||
wall_entries.push(&fresh[s]);
|
||||
}
|
||||
}
|
||||
let mut open_entries: Vec<OpenOut> = Vec::new();
|
||||
let mut open_keep: Vec<OpenOut> = Vec::new();
|
||||
if !arcs {
|
||||
for (wi, s) in wall_stamps.iter().enumerate() {
|
||||
let e = &open_fresh[s];
|
||||
let base = OpenOut { serial: e.serial, json: &e.json, meshes: &e.meshes };
|
||||
let mask = &masks[wi];
|
||||
let shown = mask.iter().filter(|&&b| b).count();
|
||||
if shown == mask.len() {
|
||||
open_entries.push(base);
|
||||
} else {
|
||||
open_keep.push(base);
|
||||
}
|
||||
for (m, v) in &e.variants {
|
||||
let out = OpenOut { serial: v.serial, json: &v.json, meshes: &v.meshes };
|
||||
if m == mask && shown > 0 {
|
||||
open_entries.push(out);
|
||||
} else {
|
||||
open_keep.push(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let surface = if arcs { Vec::new() } else { model3d::surface_window_meshes_with(p, &|o| filter.keep_opening(o)) };
|
||||
let opening_tail = match &arc_meshes {
|
||||
Some(m) => inner_json(m),
|
||||
None => inner_json(&surface),
|
||||
@@ -286,7 +370,13 @@ impl Model3dCache {
|
||||
];
|
||||
let mut json = String::new();
|
||||
if let Some(mark) = delta {
|
||||
json = write_delta(mark, &wall_entries, &open_entries, &opening_tail, &rest);
|
||||
fn w<'a>(v: &[&'a WallEntry]) -> Vec<(u64, &'a str)> {
|
||||
v.iter().map(|e| (e.serial, e.json.as_str())).collect()
|
||||
}
|
||||
fn o<'a>(v: &[OpenOut<'a>]) -> Vec<(u64, &'a [String; 5])> {
|
||||
v.iter().map(|e| (e.serial, e.json)).collect()
|
||||
}
|
||||
json = write_delta(mark, [&w(&wall_entries), &w(&wall_keep)], [&o(&open_entries), &o(&open_keep)], &opening_tail, &rest);
|
||||
} else {
|
||||
let walls_frag = wall_entries.iter().map(|e| e.json.as_str());
|
||||
let opening_frags = (0..5).flat_map(|k| open_entries.iter().map(move |e| e.json[k].as_str())).chain([opening_tail.as_str()]);
|
||||
@@ -317,13 +407,13 @@ impl Model3dCache {
|
||||
parts.opening_meshes = match arc_meshes {
|
||||
Some(m) => m,
|
||||
None => {
|
||||
let mut v = model3d::assemble_opening_meshes(open_entries.iter().map(|e| e.meshes.clone()).collect());
|
||||
let mut v = model3d::assemble_opening_meshes(open_entries.iter().map(|e| WallOpeningMeshes::clone(e.meshes)).collect());
|
||||
v.extend(surface);
|
||||
v
|
||||
}
|
||||
};
|
||||
}
|
||||
drop((wall_entries, open_entries));
|
||||
drop((wall_entries, wall_keep, open_entries, open_keep));
|
||||
self.walls[layered as usize] = fresh;
|
||||
if !arcs {
|
||||
self.openings[slot].1 = open_fresh;
|
||||
@@ -332,44 +422,64 @@ impl Model3dCache {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein ausgegebener Öffnungs-Eintrag (Grundfall oder [180] Variante).
|
||||
#[derive(Clone, Copy)]
|
||||
struct OpenOut<'a> {
|
||||
serial: u64,
|
||||
json: &'a [String; 5],
|
||||
meshes: &'a WallOpeningMeshes,
|
||||
}
|
||||
|
||||
/// Änderungs-JSON ([58], TS `ProjectDocument.model3dParts`): statt `walls`/`openingMeshes` die Laufnummern
|
||||
/// je Wand (`wallKeys`, `openingKeys`, Modell-Reihenfolge) und nur die Einträge mit Laufnummer > `mark`
|
||||
/// ausgeschrieben (`wallNew`: `[nr, [Körper…]]`, `openingNew`: `[nr, 3 Durchgänge, Zargen, Formöffnungen]`);
|
||||
/// `openingTail` = Dach-/Deckenfenster (bzw. alles bei Bogenwänden), `mark` = Stand für die nächste Frage.
|
||||
/// Gültig nur, wenn der Aufrufer die Einträge ≤ `mark` aus seiner letzten Antwort hat (sonst `mark` 0).
|
||||
fn write_delta(mark: u64, walls: &[&WallEntry], openings: &[&OpenEntry], opening_tail: &str, rest: &[String; 7]) -> String {
|
||||
/// [180] `wallKeep`/`openingKeep` (nur wenn nicht leer): Einträge ausgeblendeter Klassen, die der Aufrufer
|
||||
/// behält, aber nicht zeigt (je `[gezeigt, behalten]` übergeben). Gültig nur, wenn der Aufrufer die Einträge
|
||||
/// ≤ `mark` aus seiner letzten Antwort hat (sonst `mark` 0).
|
||||
fn write_delta(mark: u64, walls: [&[(u64, &str)]; 2], openings: [&[(u64, &[String; 5])]; 2], opening_tail: &str, rest: &[String; 7]) -> String {
|
||||
use std::fmt::Write;
|
||||
let fresh = |serial: u64| mark == 0 || serial > mark || mark > current_serial();
|
||||
let cap = walls.iter().filter(|e| fresh(e.serial)).map(|e| e.json.len() + 32).sum::<usize>()
|
||||
let cap = walls.iter().flat_map(|v| v.iter()).filter(|e| fresh(e.0)).map(|e| e.1.len() + 32).sum::<usize>()
|
||||
+ openings
|
||||
.iter()
|
||||
.filter(|e| fresh(e.serial))
|
||||
.map(|e| e.json.iter().map(|j| j.len() + 4).sum::<usize>() + 32)
|
||||
.flat_map(|v| v.iter())
|
||||
.filter(|e| fresh(e.0))
|
||||
.map(|e| e.1.iter().map(|j| j.len() + 4).sum::<usize>() + 32)
|
||||
.sum::<usize>()
|
||||
+ (walls.len() + openings.len()) * 12
|
||||
+ (walls[0].len() + walls[1].len() + openings[0].len() + openings[1].len()) * 12
|
||||
+ opening_tail.len()
|
||||
+ rest.iter().map(String::len).sum::<usize>()
|
||||
+ 512;
|
||||
let mut out = String::with_capacity(cap);
|
||||
let _ = write!(out, "{{\"mark\":{},\"wallKeys\":[", current_serial());
|
||||
for (i, e) in walls.iter().enumerate() {
|
||||
let _ = write!(out, "{}{}", if i > 0 { "," } else { "" }, e.serial);
|
||||
let keys = |out: &mut String, name: &str, serials: &mut dyn Iterator<Item = u64>| {
|
||||
let _ = write!(out, "\"{name}\":[");
|
||||
for (i, s) in serials.enumerate() {
|
||||
let _ = write!(out, "{}{}", if i > 0 { "," } else { "" }, s);
|
||||
}
|
||||
out.push_str("],");
|
||||
};
|
||||
let _ = write!(out, "{{\"mark\":{},", current_serial());
|
||||
keys(&mut out, "wallKeys", &mut walls[0].iter().map(|e| e.0));
|
||||
if !walls[1].is_empty() {
|
||||
keys(&mut out, "wallKeep", &mut walls[1].iter().map(|e| e.0));
|
||||
}
|
||||
out.push_str("],\"wallNew\":[");
|
||||
out.push_str("\"wallNew\":[");
|
||||
let mut first = true;
|
||||
for e in walls.iter().filter(|e| fresh(e.serial)) {
|
||||
let _ = write!(out, "{}[{},[{}]]", if first { "" } else { "," }, e.serial, e.json);
|
||||
for e in walls.iter().flat_map(|v| v.iter()).filter(|e| fresh(e.0)) {
|
||||
let _ = write!(out, "{}[{},[{}]]", if first { "" } else { "," }, e.0, e.1);
|
||||
first = false;
|
||||
}
|
||||
out.push_str("],\"openingKeys\":[");
|
||||
for (i, e) in openings.iter().enumerate() {
|
||||
let _ = write!(out, "{}{}", if i > 0 { "," } else { "" }, e.serial);
|
||||
out.push_str("],");
|
||||
keys(&mut out, "openingKeys", &mut openings[0].iter().map(|e| e.0));
|
||||
if !openings[1].is_empty() {
|
||||
keys(&mut out, "openingKeep", &mut openings[1].iter().map(|e| e.0));
|
||||
}
|
||||
out.push_str("],\"openingNew\":[");
|
||||
out.push_str("\"openingNew\":[");
|
||||
let mut first = true;
|
||||
for e in openings.iter().filter(|e| fresh(e.serial)) {
|
||||
let _ = write!(out, "{}[{}", if first { "" } else { "," }, e.serial);
|
||||
for j in &e.json {
|
||||
for e in openings.iter().flat_map(|v| v.iter()).filter(|e| fresh(e.0)) {
|
||||
let _ = write!(out, "{}[{}", if first { "" } else { "," }, e.0);
|
||||
for j in e.1 {
|
||||
let _ = write!(out, ",[{j}]");
|
||||
}
|
||||
out.push(']');
|
||||
@@ -403,15 +513,20 @@ mod tests {
|
||||
|
||||
/// Inkrementell (Cache des Dokuments) = voll (`queries::run` auf einer Kopie), Byte für Byte.
|
||||
fn check(d: &mut Document, clients: &mut [Client; 4], step: &str) {
|
||||
check_with(d, clients, step, "");
|
||||
}
|
||||
|
||||
/// Wie [`check`] mit `text` der Abfrage ([180] Klassen-Filter `{"hide": [...]}`).
|
||||
fn check_with(d: &mut Document, clients: &mut [Client; 4], step: &str, text: &str) {
|
||||
let p = d.project().unwrap().clone();
|
||||
for (a, c) in ARGS.iter().zip(clients.iter_mut()) {
|
||||
let inc = crate::queries::run_doc(d, "model3dParts", a, "").unwrap();
|
||||
let full = crate::queries::run(&p, "model3dParts", a, "").unwrap();
|
||||
let inc = crate::queries::run_doc(d, "model3dParts", a, text).unwrap();
|
||||
let full = crate::queries::run(&p, "model3dParts", a, text).unwrap();
|
||||
assert!(inc == full, "{step}: model3dParts {a:?} weicht ab ({} / {} Zeichen)", inc.len(), full.len());
|
||||
// Änderungs-Antwort wie in TS (`ProjectDocument.model3dParts`) zusammengesetzt = voll.
|
||||
let mut da = a.to_vec();
|
||||
da.push(c.mark as f64);
|
||||
let delta = crate::queries::run_doc(d, "model3dPartsDelta", &da, "").unwrap();
|
||||
let delta = crate::queries::run_doc(d, "model3dPartsDelta", &da, text).unwrap();
|
||||
let got = c.apply(&delta);
|
||||
let want: Value = serde_json::from_str(&full).unwrap();
|
||||
assert!(got == want, "{step}: model3dPartsDelta {a:?} weicht ab");
|
||||
@@ -439,12 +554,21 @@ mod tests {
|
||||
walls.extend(e.iter().cloned());
|
||||
nw.insert(k, e);
|
||||
}
|
||||
// [180] Ausgeblendete Einträge behalten (wie TS `assembleModel3dDelta`), nicht zeigen.
|
||||
for k in r.get("wallKeep").and_then(Value::as_array).into_iter().flatten().map(key) {
|
||||
let e = wn.remove(&k).or_else(|| self.walls.remove(&k)).expect("behaltener Wand-Eintrag fehlt");
|
||||
nw.insert(k, e);
|
||||
}
|
||||
let mut no = std::collections::HashMap::new();
|
||||
let keys: Vec<u64> = r["openingKeys"].as_array().unwrap().iter().map(key).collect();
|
||||
for &k in &keys {
|
||||
let e = on.remove(&k).or_else(|| self.openings.remove(&k)).expect("Öffnungs-Eintrag fehlt");
|
||||
no.insert(k, e);
|
||||
}
|
||||
for k in r.get("openingKeep").and_then(Value::as_array).into_iter().flatten().map(key) {
|
||||
let e = on.remove(&k).or_else(|| self.openings.remove(&k)).expect("behaltener Öffnungs-Eintrag fehlt");
|
||||
no.insert(k, e);
|
||||
}
|
||||
let mut meshes = Vec::new();
|
||||
for l in 0..5 {
|
||||
for k in &keys {
|
||||
@@ -584,6 +708,66 @@ mod tests {
|
||||
assert!(kinds.iter().all(|&k| k > 0), "{kinds:?}");
|
||||
}
|
||||
|
||||
/// [180] Klassen ein-/ausblenden (über `hide` und über den Ebenen-Baum): ausgeblendete Wände, Öffnungen,
|
||||
/// Decken, Dächer, Treppen fehlen, inkrementell = voll = Änderungs-Antwort, und keine Wand wird neu
|
||||
/// gerechnet; Öffnungs-Varianten (teils ausgeblendete Öffnungen einer Wand) nur beim ersten Mal.
|
||||
#[test]
|
||||
fn class_filter_without_rebuild() {
|
||||
let mut d = sample();
|
||||
let mut clients: [Client; 4] = Default::default();
|
||||
// Tür D1 auf eigene Klasse: Wand W1 hat dann eine sichtbare (O1) und eine ausgeblendete Öffnung.
|
||||
let mut o = list(&d, "openings").into_iter().find(|o| o["id"] == "D1").unwrap();
|
||||
o["categoryCode"] = json!("22");
|
||||
d.commit(vec![Op::Replace { collection: "openings".into(), entity: o }], None, 0.0, false).unwrap();
|
||||
check_with(&mut d, &mut clients, "alles sichtbar", "");
|
||||
let parts = |d: &mut Document, text: &str| -> Value { serde_json::from_str(&crate::queries::run_doc(d, "model3dParts", &[1.0, 2.0, 0.0, 0.0, 0.0], text).unwrap()).unwrap() };
|
||||
let len = |v: &Value, k: &str| v[k].as_array().map_or(0, Vec::len);
|
||||
let all = parts(&mut d, "");
|
||||
let (walls, openings, roofs) = (len(&all, "walls"), len(&all, "openingMeshes"), len(&all, "roofMeshes"));
|
||||
assert!(walls > 0 && openings > 0 && roofs > 0 && len(&all, "slabs") > 0);
|
||||
let doors = r#"{"hide":["22"]}"#;
|
||||
for (step, text) in [
|
||||
("Türen aus", doors),
|
||||
("Wände aus", r#"{"hide":["20"]}"#),
|
||||
("Decke, Dach, Treppe aus", r#"{"hide":["30","31","40"]}"#),
|
||||
("alles sichtbar", ""),
|
||||
("Türen wieder aus", doors),
|
||||
] {
|
||||
check_with(&mut d, &mut clients, step, text);
|
||||
d.model3d_parts_with(true, 2.0, false, false, None, text).unwrap();
|
||||
assert_eq!(d.model3d_rebuilt(), (0, 0), "{step}");
|
||||
assert_eq!(d.model3d_variants(), 0, "{step}: Variante schon gemerkt");
|
||||
}
|
||||
let v = parts(&mut d, doors);
|
||||
assert_eq!(len(&v, "walls"), walls);
|
||||
assert!(len(&v, "openingMeshes") < openings && len(&v, "openingMeshes") > 0, "nur die Tür fehlt");
|
||||
let v = parts(&mut d, r#"{"hide":["20"]}"#);
|
||||
assert_eq!((len(&v, "walls"), len(&v, "openingMeshes")), (0, 0), "Öffnungen gehen mit der Wand");
|
||||
assert_eq!(len(&v, "roofMeshes"), roofs);
|
||||
let v = parts(&mut d, r#"{"hide":["30","31","40"]}"#);
|
||||
assert_eq!((len(&v, "slabs"), len(&v, "roofMeshes"), len(&v, "roofLayers"), len(&v, "stairMeshes"), len(&v, "stairRailings")), (0, 0, 0, 0, 0));
|
||||
assert_eq!(len(&v, "walls"), walls);
|
||||
// Ebenen-Baum (Ebenen-Panel, Kombinationen, Vorlagen): Dach aus — ohne Neuberechnung der Wände.
|
||||
let mut layers = d.root()["layers"].clone();
|
||||
for c in layers.as_array_mut().unwrap() {
|
||||
if c["code"] == "31" {
|
||||
c["visible"] = json!(false);
|
||||
}
|
||||
}
|
||||
d.commit(vec![Op::SetField { key: "layers".into(), value: Some(layers), at: None }], None, 1.0, false).unwrap();
|
||||
check_with(&mut d, &mut clients, "Dach-Klasse aus", "");
|
||||
d.model3d_parts(true, 2.0, false, false, None).unwrap();
|
||||
assert_eq!(d.model3d_rebuilt(), (0, 0));
|
||||
let v = parts(&mut d, "");
|
||||
assert_eq!((len(&v, "roofMeshes"), len(&v, "roofLayers")), (0, 0));
|
||||
let pick: Value = serde_json::from_str(&crate::queries::run_doc(&mut d, "pickGeometry", &[0.0], "").unwrap()).unwrap();
|
||||
assert_eq!(len(&pick, "roofs"), 0, "ausgeblendetes Dach nicht anwählbar");
|
||||
assert!(len(&pick, "walls") > 0);
|
||||
let pick: Value = serde_json::from_str(&crate::queries::run_doc(&mut d, "pickGeometry", &[0.0], doors).unwrap()).unwrap();
|
||||
assert!(pick["openings"].as_array().unwrap().iter().all(|o| o["openingId"] != "D1"));
|
||||
assert!(pick["openings"].as_array().unwrap().iter().any(|o| o["openingId"] == "O1"));
|
||||
}
|
||||
|
||||
/// Eine Wandhöhe ändern: nur diese Wand (Körper und Einbauteile) wird neu gerechnet.
|
||||
#[test]
|
||||
fn one_wall_edit_rebuilds_one_wall() {
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn run_doc(d: &mut crate::document::Document, name: &str, args: &[f64], text
|
||||
// [173] Mit Modelldarstellung (`text`) ohne den Cache (eigene Teile, s. `model3d_mv`).
|
||||
if (name == "model3dParts" || delta.is_some()) && args.len() >= 3 && !explode && model3d_mv_id(text).is_none() {
|
||||
let voids = args.get(3).is_some_and(|v| *v != 0.0);
|
||||
let out = d.model3d_parts(args[0] != 0.0, args[1], args[2] != 0.0, voids, delta)?;
|
||||
let out = d.model3d_parts_with(args[0] != 0.0, args[1], args[2] != 0.0, voids, delta, text)?;
|
||||
if voids {
|
||||
let p = d.project()?;
|
||||
let cuts = crate::solid_specs::void_cuts(p, &out.parts.walls, &out.parts.slabs);
|
||||
@@ -110,15 +110,22 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
// `args[0]`: Explosionsabstand ([65], fehlt/0 = aus).
|
||||
// Versatz je Geschoss-id ([65]; `args[0]` = Abstand, ≤ 0 = leer): 3D-Griffe und Arbeitsebene.
|
||||
("explodeOffsets", _) => json(&crate::explode3d::floor_offsets(p, args.first().copied().unwrap_or(0.0))),
|
||||
("pickGeometry", _) => json(&crate::explode3d::pick_geometry(p, args.first().copied().unwrap_or(0.0))?),
|
||||
// [180] Ohne die Elemente ausgeblendeter Klassen (`text` = `{"hide": [codes]}`, s. `model3d::ClassFilter`).
|
||||
("pickGeometry", _) => {
|
||||
let mut g = crate::explode3d::pick_geometry(p, args.first().copied().unwrap_or(0.0))?;
|
||||
model3d::ClassFilter::from_text(p, text).retain_pick(&mut g);
|
||||
json(&g)
|
||||
}
|
||||
("modelJson", _) => crate::model::to_value_typed_only(p).map(|v| v.to_string()).map_err(|e| e.to_string()),
|
||||
// Mit Abzugskörpern (`args[3]` ≠ 0) zusätzlich `voidCuts`: die getroffenen Wände/Decken als
|
||||
// truck-Spezifikationen (`solid_specs.rs`).
|
||||
// `args[4]`: Explosionsabstand ([65], `explode3d.rs`; > 0 zusätzlich `floorOffsets`, Abzugskörper wandern mit).
|
||||
// [180] Ohne die Teile ausgeblendeter Klassen (`text` = `{"hide": [codes], "modelView": …}`).
|
||||
("model3dParts", n) if n >= 3 => {
|
||||
let explode = args.get(4).copied().filter(|g| g.is_finite() && *g > 0.0);
|
||||
let filter = model3d::ClassFilter::from_text(p, text);
|
||||
if let Some(gap) = explode {
|
||||
let parts = crate::explode3d::parts(p, args[0] != 0.0, args[1], args[2] != 0.0, gap)?;
|
||||
let parts = crate::explode3d::parts_filtered(p, args[0] != 0.0, args[1], args[2] != 0.0, gap, &filter)?;
|
||||
let mut v = serde_json::to_value(&parts).map_err(|e| e.to_string())?;
|
||||
v["floorOffsets"] = serde_json::to_value(crate::explode3d::floor_offsets(p, gap)).map_err(|e| e.to_string())?;
|
||||
if args.get(3).is_some_and(|v| *v != 0.0) {
|
||||
@@ -127,7 +134,7 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
return Ok(v.to_string());
|
||||
}
|
||||
let (detail, rails) = model3d_mv(p, text, args[1]);
|
||||
let mut parts = model3d::parts(p, args[0] != 0.0, detail, args[2] != 0.0)?;
|
||||
let mut parts = model3d::parts_filtered(p, args[0] != 0.0, detail, args[2] != 0.0, &filter)?;
|
||||
if !rails {
|
||||
parts.stair_railings.clear();
|
||||
}
|
||||
|
||||
@@ -121,18 +121,23 @@ pub fn pattern_lines_3d(p: &Project) -> Vec<f32> {
|
||||
|
||||
/// Wie `pattern_lines_3d`, mit Explosionsabstand `gap` ([65], ≤ 0 = aus): die Linien heben sich mit dem Geschoss ihres Bauteils.
|
||||
pub fn pattern_lines_3d_exploded(p: &Project, gap: f64) -> Vec<f32> {
|
||||
pattern_lines_3d_filtered(p, gap, &crate::model3d::ClassFilter::none())
|
||||
}
|
||||
|
||||
/// Wie [`pattern_lines_3d_exploded`], ohne die Muster der Bauteile ausgeblendeter Klassen ([180]).
|
||||
pub fn pattern_lines_3d_filtered(p: &Project, gap: f64, filter: &crate::model3d::ClassFilter) -> Vec<f32> {
|
||||
let ex = crate::explode3d::Explode::new(p, gap);
|
||||
let dz_of = |id: &str| ex.as_ref().map_or(0.0, |e| e.of(id));
|
||||
let mut s = Sink { out: Vec::new(), dz: 0.0 };
|
||||
for w in &p.walls {
|
||||
for w in p.walls.iter().filter(|w| !filter.hides(&w.id)) {
|
||||
s.dz = dz_of(&w.id);
|
||||
wall_lines(p, w, &mut s);
|
||||
}
|
||||
for ce in p.ceilings.as_deref().unwrap_or(&[]) {
|
||||
for ce in p.ceilings.as_deref().unwrap_or(&[]).iter().filter(|c| !filter.hides(&c.id)) {
|
||||
s.dz = dz_of(&ce.id);
|
||||
ceiling_lines(p, ce, &mut s);
|
||||
}
|
||||
for roof in p.roofs.as_deref().unwrap_or(&[]) {
|
||||
for roof in p.roofs.as_deref().unwrap_or(&[]).iter().filter(|r| !filter.hides(&r.id)) {
|
||||
s.dz = dz_of(&roof.id);
|
||||
let Some((pat, comp, spec)) = spec_for(p.roof_layers(roof).first().and_then(|l| p.component(&l.component_id)), roof.surface_pattern_angle.unwrap_or(0.0)) else { continue };
|
||||
let rgb = ink_rgb(pat, comp);
|
||||
|
||||
@@ -305,17 +305,19 @@ pub fn doc_query_root(h: u32, name: &str, text: &str) -> String {
|
||||
}
|
||||
|
||||
/// Boden-Spuren aller 2D-Zeichnungen als LineList-Vertices `[px, py, pz, r, g, b]` (Float32);
|
||||
/// leer bei Fehler oder ohne Zeichnungen. `explode`: Explosionsabstand ([65], ≤ 0/NaN = aus).
|
||||
/// leer bei Fehler oder ohne Zeichnungen. `explode`: Explosionsabstand ([65], ≤ 0/NaN = aus). [180] Ohne
|
||||
/// ausgeblendete Klassen (Ebenen-Baum plus `hide` = `{"hide": [codes]}`, s. `model3d::ClassFilter`).
|
||||
#[wasm_bindgen]
|
||||
pub fn doc_drawing_line_verts(h: u32, explode: f64) -> Vec<f32> {
|
||||
with_doc(h, |d| d.project().ok().map(|p| crate::explode3d::drawing_line_verts(&p, explode))).flatten().unwrap_or_default()
|
||||
pub fn doc_drawing_line_verts(h: u32, explode: f64, hide: &str) -> Vec<f32> {
|
||||
with_doc(h, |d| d.project().ok().map(|p| crate::explode3d::drawing_line_verts_filtered(p, explode, &crate::model3d::ClassFilter::from_text(p, hide)))).flatten().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Ansichtsschraffur auf den Flächen für render3d (`surface_pattern3d`, je Linie `ax ay az bx by bz r g b
|
||||
/// maske`, Float32); leer bei Fehler oder ohne Muster. `explode`: Explosionsabstand ([65], ≤ 0/NaN = aus).
|
||||
/// [180] `hide` wie bei [`doc_drawing_line_verts`].
|
||||
#[wasm_bindgen]
|
||||
pub fn doc_surface_pattern_lines(h: u32, explode: f64) -> Vec<f32> {
|
||||
with_doc(h, |d| d.project().ok().map(|p| crate::surface_pattern3d::pattern_lines_3d_exploded(&p, explode))).flatten().unwrap_or_default()
|
||||
pub fn doc_surface_pattern_lines(h: u32, explode: f64, hide: &str) -> Vec<f32> {
|
||||
with_doc(h, |d| d.project().ok().map(|p| crate::surface_pattern3d::pattern_lines_3d_filtered(p, explode, &crate::model3d::ClassFilter::from_text(p, hide)))).flatten().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Das Projekt als Datei-Text (Formatversion vorn, Einrückung 2); leer, wenn das Dokument nicht offen ist.
|
||||
|
||||
Reference in new issue
Block a user