[271][272][215] Exporte und Rendering folgen Umbaufilter und Variantenkombination der Ansicht

Gemeinsame Ansicht export/exportView.ts (Umbaufilter, Etappe, Kombination der aktiven Ebene) als EIN Weg in IFC, OBJ/STL/glTF, STEP,
Blender-Paket und Cycles-Szene (Text der Kern-Abfragen, renovation::view_from_text). Cycles-Szene: Ausgeblendetes fehlt, Umbau-Farben nur
auf Wunsch (renovationColors, cycles_scene_styled); Explosionsaxonometrie bekommt die Umbau-Farben, Pick/Explosion folgten dem Filter schon.
App: Export-Dialog und Rendering-Dialog zeigen die Ansicht und lassen Hauptvarianten/kein Filter wählen; Häkchen Umbau-Farben im Bild.
CLI: --renovation/--phase auch für ifc, obj, stl, glb, gltf, step, render, blend; render --engine cycles --renovation-colors.
Tests: Kern export_view_tests.rs, vitest exportView/exportViewState/render, e2e exportView271; Bilder doc/review-272/07-09.
This commit is contained in:
Claude committed 2026-11-17 15:40:12 +00:00
1 parent 78791a347a
commit 2fb42aac07
32 files changed
+695 -42

No files matched your search

+18 -2
View File
@@ -100,6 +100,9 @@ pub struct CyclesOptions {
pub context: bool,
/// Bodenplatte unter dem Modell (der Himmel unter dem Horizont ist dunkel).
pub ground: bool,
/// [271] Umbau-Farben im Bild (Abbruch gelb, Neu rot …; nur mit Umbaufilter, der Farben vorsieht, z. B. „Umbauplan“);
/// Vorgabe aus = Materialfarben. Ausgeblendetes fehlt in jedem Fall.
pub renovation_colors: bool,
/// Bild-URLs, die der Gastgeber laden kann; `None` = alle. Fehlende Karten fallen auf den Ersatzlook zurück.
pub textures: Option<Vec<String>>,
}
@@ -119,6 +122,7 @@ impl Default for CyclesOptions {
backfilled: true,
context: true,
ground: true,
renovation_colors: false,
textures: None,
}
}
@@ -569,6 +573,12 @@ fn auto_exposure(elevation: f64, strength: f64) -> f64 {
/// Schreibt die Cycles-Szene. Fehler nur bei unbrauchbaren Optionen (Bildgrösse, Kamera); ein leeres Projekt ergibt eine
/// gültige Szene ohne Netze (`meshes == 0`).
pub fn cycles_scene(p: &Project, o: &CyclesOptions) -> Result<CyclesScene, String> {
cycles_scene_styled(p, o, &HashMap::new())
}
/// Wie [`cycles_scene`], mit Umbau-Farben (Element-id → Füllfarbe des Status, `renovation::Resolved::styled`): solche Elemente
/// bekommen eine einfarbige Fläche statt ihres Materials (Glas bleibt Glas). Leere Tabelle = Materialfarben.
pub fn cycles_scene_styled(p: &Project, o: &CyclesOptions, styled: &HashMap<String, String>) -> Result<CyclesScene, String> {
let dim = |v: f64, what: &str| -> Result<u32, String> {
if v.is_finite() && (1.0..=32768.0).contains(&v) {
Ok(v.round() as u32)
@@ -644,8 +654,14 @@ pub fn cycles_scene(p: &Project, o: &CyclesOptions) -> Result<CyclesScene, Strin
None => {}
}
}
let (color, rough, metal) = flat_look(role, &comp_name.to_lowercase(), srgb, m.roughness, m.metallic);
Look { label, color, rough, metal, glass: false, tex: t }
match styled.get(&g.id) {
// [271] Umbau-Farbe: einfarbig, ohne Bildkarte (Schnittflächen und Körper wie im 3D-Fenster).
Some(fill) => Look { label: format!("Umbau-{}", fill.trim_start_matches('#')), color: clamp_albedo(lin(hex_to_rgb(fill, [0.8, 0.8, 0.8]))), rough: 0.8, metal: 0.0, glass: false, tex: None },
None => {
let (color, rough, metal) = flat_look(role, &comp_name.to_lowercase(), srgb, m.roughness, m.metallic);
Look { label, color, rough, metal, glass: false, tex: t }
}
}
};
let key = format!("{look:?}");
let sid = match shader_ids.get(&key) {
+114
View File
@@ -0,0 +1,114 @@
//! [271][272] Exporte und Rendering folgen dem Umbaufilter und der Variantenkombination der Ansicht: Cycles-Szene, IFC, Netz-Exporte
//! (Text der Abfrage = `{"renovation", "renovationPhase", "designOptions", …}`), Umbau-Farben im Bild nur auf Wunsch.
use super::*;
use serde_json::{json, Value};
/// Musterhaus mit Umbau-Angaben (W2 Abbruch, W9 Neu Etappe 2) und Satz „Dachform“: W2 in A (Haupt), W9 und Dach RF1 in B.
fn fixture() -> Project {
let mut v = crate::renovation::tests::umbau_fixture();
v["designOptionSets"] = json!([{"id": "dach", "name": "Dachform", "options": [{"id": "a", "name": "A"}, {"id": "b", "name": "B"}], "primary": "a"}]);
for (coll, id, opt) in [("walls", "W2", "a"), ("walls", "W9", "b"), ("roofs", "RF1", "b")] {
for x in v[coll].as_array_mut().unwrap() {
if x["id"] == id {
x["designOption"] = json!({"set": "dach", "option": opt});
}
}
}
serde_json::from_value(v).unwrap()
}
fn scene(p: &Project, text: &str) -> Value {
serde_json::from_str(&run(p, "cyclesScene", &[], text).unwrap()).unwrap()
}
fn triangles(p: &Project, extra: Value) -> u64 {
let mut t = json!({"width": 64, "height": 36, "samples": 1, "context": false});
for (k, x) in extra.as_object().unwrap() {
t[k] = x.clone();
}
scene(p, &t.to_string())["triangles"].as_u64().unwrap()
}
#[test]
fn cycles_szene_ohne_ausgeblendete_elemente() {
let p = fixture();
// Ohne Filter: Hauptvariante A (W2 da, W9 und Dach fehlen).
let alle = triangles(&p, json!({}));
// Abbruch-Wand W2 fehlt im Endzustand.
let end = triangles(&p, json!({"renovation": "endzustand"}));
assert!(end < alle, "Endzustand {end} < ohne Filter {alle}");
// Bestand: nur Bestehendes (kein Neues wie W9), W2 steht noch.
let bestand = triangles(&p, json!({"renovation": "bestand"}));
assert!(bestand < alle, "Bestand {bestand} < ohne Filter {alle} (Neues fehlt)");
}
#[test]
fn cycles_szene_folgt_der_kombination() {
let p = fixture();
let a = triangles(&p, json!({}));
let b = triangles(&p, json!({"designOptions": {"dach": "b"}}));
assert_ne!(a, b, "Variante B hat andere Elemente (W9, Dach statt W2)");
// Text „Satz=Variante“ geht ebenso (Namen).
assert_eq!(b, triangles(&p, json!({"designOptions": "Dachform=B"})));
// Umbaufilter und Kombination wirken zusammen: Endzustand in B ohne Abbruch, mit Neuem (W9 Etappe 2).
let end_b = triangles(&p, json!({"renovation": "endzustand", "designOptions": {"dach": "b"}}));
assert!(end_b > 0 && end_b <= b);
}
#[test]
fn cycles_umbaufarben_nur_auf_wunsch() {
let p = fixture();
let base = json!({"width": 64, "height": 36, "samples": 1, "context": false, "renovation": "umbauplan"});
let ohne = scene(&p, &base.to_string());
assert!(!ohne["xml"].as_str().unwrap().contains("Umbau-"), "Vorgabe: Materialfarben");
let mut mit_opts = base.clone();
mit_opts["renovationColors"] = json!(true);
let mit = scene(&p, &mit_opts.to_string());
let xml = mit["xml"].as_str().unwrap();
assert!(xml.contains("Umbau-ffd800"), "Abbruch gelb");
// Geometrie bleibt gleich.
assert_eq!(ohne["triangles"], mit["triangles"]);
// Ohne Filter keine Farben, auch mit dem Schalter.
let keiner = json!({"width": 64, "height": 36, "samples": 1, "context": false, "renovationColors": true});
assert!(!scene(&p, &keiner.to_string())["xml"].as_str().unwrap().contains("Umbau-"));
}
fn ifc_len(p: &Project, text: &str) -> usize {
run_bin(p, "ifcExportData", &[0.0, 0.0, 0.0, 0.0], text).unwrap().len()
}
#[test]
fn ifc_und_netz_folgen_der_ansicht() {
let p = fixture();
let alle = ifc_len(&p, "2026-01-01T00:00:00");
let end = ifc_len(&p, &json!({"iso": "2026-01-01T00:00:00", "renovation": "endzustand"}).to_string());
assert!(end < alle, "Endzustand ohne Abbruch: {end} < {alle}");
let a = ifc_len(&p, &json!({"iso": "2026-01-01T00:00:00"}).to_string());
let b = ifc_len(&p, &json!({"iso": "2026-01-01T00:00:00", "designOptions": {"dach": "b"}}).to_string());
assert_ne!(a, b, "Kombination wirkt im IFC");
// Netz-Exporte (glTF/OBJ/STL): gleicher Text.
let mesh = |t: &str| run_bin(&p, "meshExportData", &[1.0, 0.0, 0.0], t).unwrap().len();
assert!(mesh(&json!({"renovation": "endzustand"}).to_string()) < mesh(""));
assert_ne!(mesh(&json!({"designOptions": {"dach": "b"}}).to_string()), mesh(""));
}
fn arr_len(v: &Value, key: &str) -> usize {
v[key].as_array().map_or(0, |a| a.len())
}
/// 3D-Pick und Explosionsaxonometrie lassen Ausgeblendetes (Umbaufilter, andere Varianten) aus.
#[test]
fn pick_und_explosion_ohne_ausgeblendete() {
let p = fixture();
let pick = |t: &str| -> Value { serde_json::from_str(&run(&p, "pickGeometry", &[0.0], t).unwrap()).unwrap() };
let parts = |t: &str, gap: f64| -> Value { serde_json::from_str(&run(&p, "model3dParts", &[0.0, 1.0, 0.0, 0.0, gap], t).unwrap()).unwrap() };
let alle = arr_len(&pick(""), "walls");
assert!(arr_len(&pick(&json!({"renovation": "endzustand"}).to_string()), "walls") < alle, "Pick: abgebrochene Wand nicht anwählbar");
assert_ne!(arr_len(&pick(&json!({"designOptions": {"dach": "b"}}).to_string()), "walls"), alle, "Pick: Wände anderer Varianten fehlen");
for gap in [0.0, 3.0] {
let alle = arr_len(&parts("", gap), "walls");
assert!(arr_len(&parts(&json!({"renovation": "endzustand"}).to_string(), gap), "walls") < alle, "Teile (Explosion {gap}): Endzustand ohne Abbruchwand");
assert_ne!(arr_len(&parts(&json!({"designOptions": {"dach": "b"}}).to_string(), gap), "walls"), alle, "Teile (Explosion {gap}): andere Variante");
}
}
+16 -2
View File
@@ -124,7 +124,13 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
// [215] Cycles-Szene (XML + Bilddateien) aus dem Projekt; Text = `CyclesOptions` als JSON (camelCase).
("cyclesScene", _) => {
let o: crate::cycles_scene::CyclesOptions = if text.trim().is_empty() { Default::default() } else { serde_json::from_str(text).map_err(|e| format!("cyclesScene: {e}"))? };
json(&crate::cycles_scene::cycles_scene(&options_state(p, text), &o)?)
// [271] Umbau-Farben nur auf Wunsch (`renovationColors`); Ausgeblendetes (Umbaufilter, Variante) fehlt immer.
let styled: std::collections::HashMap<String, String> = if o.renovation_colors {
crate::renovation::view_from_text(p, text).map(|v| v.resolve(p).styled.into_iter().map(|(k, s)| (k, s.fill)).collect()).unwrap_or_default()
} else {
Default::default()
};
json(&crate::cycles_scene::cycles_scene_styled(&options_state(p, text), &o, &styled)?)
}
("dormerStatus", _) => json(&crate::dormer::status(p)),
("excavationQuantities", _) => json(&crate::excavation::quantities(p)),
@@ -181,7 +187,11 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
let filter = model3d::ClassFilter::from_text(p, text);
if let Some(gap) = explode {
let p = opt_p.as_ref();
let parts = crate::explode3d::parts_filtered(p, args[0] != 0.0, args[1], args[2] != 0.0, gap, &filter)?;
let mut parts = crate::explode3d::parts_filtered(p, args[0] != 0.0, args[1], args[2] != 0.0, gap, &filter)?;
// [271] Umbau-Farben wie im 3D-Fenster ohne Explosion (Ausgeblendetes fehlt schon über `opt_p`).
if let Some(r) = crate::renovation::view_from_text(p, text).map(|v| v.resolve(p)) {
crate::renovation::color_parts(p, &mut parts, &r);
}
let mut v = serde_json::to_value(&parts).map_err(|e| e.to_string())?;
if args.get(3).is_some_and(|v| *v != 0.0) {
let cuts = crate::explode3d::void_cuts(p, &parts, gap);
@@ -493,3 +503,7 @@ fn buf_with(post: Option<crate::plan::extras::Post>, f: impl FnOnce(&mut crate::
w.end_group(start);
Ok(w.finish())
}
#[cfg(test)]
#[path = "export_view_tests.rs"]
mod export_view_tests;