Merge branch 'worktree-agent-a6589ce996b5be4f8' into claude/practical-noether-1hb2s1
This commit is contained in:
23 files changed
+2185
-53
No files matched your search
@@ -110,7 +110,9 @@ Neues Modul: `<modul>.rs` und `mod` in `lib.rs`, Bindungen in `web/<modul>.rs` u
|
||||
| `import_ifc.rs`, `import_context.rs` | IFC zu Bauteilen bzw. Kontext-Netzen (gelesen hat vorher `fileio`) |
|
||||
| `import_drawing.rs`, `import_terrain.rs`, `geo_mesh.rs` | DXF/DWG-Zeichnungen ins Projekt (`import_terrain`: Höhenlinien erkennen, [143]); swissBUILDINGS3D-Netze |
|
||||
| `ifc_data.rs`, `ifc_quantities.rs`, `ifc_stairs.rs` | IFC-Export-Sammler, Basismengen, Treppen |
|
||||
| `mesh_data.rs` | Sammler für OBJ, STL, glTF |
|
||||
| `mesh_data.rs` | Sammler für OBJ, STL, glTF (und die Cycles-Szene) |
|
||||
| `cycles_scene.rs` | [215] Cycles-XML-Szene aus dem Projekt (Netze, Materialien, Kamera, Sonne); Abfrage `cyclesScene` |
|
||||
| `cycles_post.rs` | [215] Tonwert linear → sRGB 8 Bit für das Cycles-Bild |
|
||||
| `export_schedule.rs`, `opening_schedule.rs` | Bauteilliste, Fenster- und Türliste |
|
||||
|
||||
## Tests
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
//! [215] Nachbearbeitung des Cycles-Bildes: lineares Licht (EXR, Fliesskomma) → Tonwert → sRGB, 8 Bit.
|
||||
//!
|
||||
//! Das Standalone-Programm `cycles` hat weder Tonwert-Abbildung noch Farbverwaltung (ohne OCIO gebaut, s. `doc/CYCLES.md`):
|
||||
//! ein PNG von ihm wäre lineares Licht in 8 Bit. Dossier rechnet darum selbst. Die Belichtung steckt schon in der Szene
|
||||
//! (`<film exposure>`, `cycles_scene.rs`); hier gibt es nur einen optionalen Zusatz in EV.
|
||||
//!
|
||||
//! Look `filmic` (Standard; ein einfacher Verlauf in der Art von Filmic/AgX, ohne Tabellen):
|
||||
//! 1. Helligkeit L = 0.2126 R + 0.7152 G + 0.0722 B; Kurve `aces(x) = x(2.51x + 0.03) / (x(2.43x + 0.59) + 0.14)`
|
||||
//! (Narkowicz-Näherung von ACES: weicher Fuss, flache Schulter, 0.18 → 0.27, Weiss läuft aus).
|
||||
//! 2. Farbton erhalten: Pixel · aces(L)/L; Lichter entsättigen: je heller, desto mehr Anteil der Kurve je Kanal
|
||||
//! (Mischung t = L/(1+L)) — sehr helle Farben laufen zu Weiss statt zu knalligem Gelb/Cyan.
|
||||
//! 3. Begrenzen auf 0…1, sRGB-Übertragungsfunktion, auf 8 Bit runden.
|
||||
//! Look `standard`: nur begrenzen und sRGB (für Vergleiche und Kontrollen).
|
||||
//! Unterschied zu AgX in Blender: AgX bleibt auch bei sehr hellen Flächen farbiger und hat mehr Kontrastspielraum; für
|
||||
//! Architekturbilder (Weiss besonnt ≈ 1.2 nach der Belichtung) genügt der einfache Verlauf. Nicht endliche Werte werden 0.
|
||||
|
||||
use crate::jsnum;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Look {
|
||||
Filmic,
|
||||
Standard,
|
||||
}
|
||||
|
||||
impl Look {
|
||||
pub fn parse(s: &str) -> Look {
|
||||
if s.eq_ignore_ascii_case("standard") {
|
||||
Look::Standard
|
||||
} else {
|
||||
Look::Filmic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn aces(x: f64) -> f64 {
|
||||
(x * (2.51 * x + 0.03) / (x * (2.43 * x + 0.59) + 0.14)).clamp(0.0, 1.0)
|
||||
}
|
||||
|
||||
/// Lineares sRGB → Anzeigewert (Übertragungsfunktion).
|
||||
fn oetf(x: f64) -> f64 {
|
||||
let x = x.clamp(0.0, 1.0);
|
||||
if x <= 0.003_130_8 {
|
||||
x * 12.92
|
||||
} else {
|
||||
1.055 * jsnum::pow(x, 1.0 / 2.4) - 0.055
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Pixel: lineares RGB (Szenenwerte) → 8 Bit sRGB.
|
||||
pub fn tonemap_pixel(rgb: [f64; 3], ev: f64, look: Look) -> [u8; 3] {
|
||||
let gain = if ev.is_finite() && ev != 0.0 { jsnum::pow(2.0, ev.clamp(-16.0, 16.0)) } else { 1.0 };
|
||||
let c = rgb.map(|v| if v.is_finite() { v.max(0.0) * gain } else { 0.0 });
|
||||
let out = match look {
|
||||
Look::Standard => c,
|
||||
Look::Filmic => {
|
||||
let l = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
|
||||
let ratio = if l > 1e-9 { aces(l) / l } else { 0.0 };
|
||||
let t = l / (1.0 + l);
|
||||
[0, 1, 2].map(|k| (c[k] * ratio * (1.0 - t) + aces(c[k]) * t).clamp(0.0, 1.0))
|
||||
}
|
||||
};
|
||||
out.map(|v| (oetf(v) * 255.0 + 0.5).floor().clamp(0.0, 255.0) as u8)
|
||||
}
|
||||
|
||||
/// Pixelpuffer (RGB oder RGBA, Fliesskomma, zeilenweise von oben) → RGB 8 Bit. Ein Puffer mit anderer Kanalzahl oder
|
||||
/// unvollständigen Pixeln ergibt einen leeren Puffer (nie Panic).
|
||||
pub fn tonemap(data: &[f32], channels: usize, ev: f64, look: Look) -> Vec<u8> {
|
||||
if !(channels == 3 || channels == 4) || data.is_empty() || data.len() % channels != 0 {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut out = Vec::with_capacity(data.len() / channels * 3);
|
||||
for px in data.chunks_exact(channels) {
|
||||
out.extend_from_slice(&tonemap_pixel([f64::from(px[0]), f64::from(px[1]), f64::from(px[2])], ev, look));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn schwarz_bleibt_schwarz_weiss_laeuft_aus() {
|
||||
assert_eq!(tonemap_pixel([0.0; 3], 0.0, Look::Filmic), [0, 0, 0]);
|
||||
let hi = tonemap_pixel([50.0; 3], 0.0, Look::Filmic);
|
||||
assert_eq!(hi, [255, 255, 255]);
|
||||
// Weisser Putz nach der Belichtung (≈ 1.2) liegt unter Weiss, Mittelgrau (0.27) in der Mitte.
|
||||
let putz = tonemap_pixel([1.2; 3], 0.0, Look::Filmic)[0];
|
||||
let grau = tonemap_pixel([0.27; 3], 0.0, Look::Filmic)[0];
|
||||
assert!((220..=255).contains(&putz), "{putz}");
|
||||
assert!((110..=170).contains(&grau), "{grau}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn monoton_und_farbton_erhalten() {
|
||||
let mut last = 0;
|
||||
for i in 0..200 {
|
||||
let v = tonemap_pixel([f64::from(i) * 0.02; 3], 0.0, Look::Filmic)[1];
|
||||
assert!(v >= last, "bei {i}");
|
||||
last = v;
|
||||
}
|
||||
// Rotstich bleibt rot (mittlere Helligkeit), sehr helles Rot läuft Richtung Weiss.
|
||||
let rot = tonemap_pixel([0.6, 0.1, 0.1], 0.0, Look::Filmic);
|
||||
assert!(rot[0] > rot[1] + 60 && rot[1] == rot[2], "{rot:?}");
|
||||
let hell = tonemap_pixel([30.0, 3.0, 3.0], 0.0, Look::Filmic);
|
||||
assert!(hell[1] > rot[1], "Lichter entsättigen: {hell:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zusatzbelichtung_in_ev() {
|
||||
let a = tonemap_pixel([0.2; 3], 0.0, Look::Standard)[0];
|
||||
let b = tonemap_pixel([0.1; 3], 1.0, Look::Standard)[0];
|
||||
assert_eq!(a, b, "ein Blendenwert mehr = doppelt so hell");
|
||||
// sRGB-Punkte: 0.2140411 linear = 0.5 → 128.
|
||||
assert!((127..=128).contains(&tonemap_pixel([0.2140411; 3], 0.0, Look::Standard)[0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kaputte_eingaben_ohne_panik() {
|
||||
assert!(tonemap(&[], 3, 0.0, Look::Filmic).is_empty());
|
||||
assert!(tonemap(&[1.0, 1.0], 3, 0.0, Look::Filmic).is_empty());
|
||||
assert!(tonemap(&[1.0; 6], 2, 0.0, Look::Filmic).is_empty());
|
||||
let o = tonemap(&[f32::NAN, f32::INFINITY, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0], 4, f64::NAN, Look::Filmic);
|
||||
assert_eq!(o.len(), 6);
|
||||
assert_eq!(&o[..3], &[0, 0, 0]);
|
||||
assert_eq!(tonemap(&[0.5; 8], 4, 0.0, Look::Filmic).len(), 6, "RGBA → RGB");
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -90,6 +90,8 @@ pub mod ifc_quantities;
|
||||
pub mod ifc_stairs;
|
||||
pub mod ifc_data;
|
||||
pub mod mesh_data;
|
||||
pub mod cycles_scene;
|
||||
pub mod cycles_post;
|
||||
pub mod solid_bool;
|
||||
pub mod solid_mesh;
|
||||
pub mod dormer;
|
||||
|
||||
@@ -48,19 +48,19 @@ impl Default for MeshOptions {
|
||||
}
|
||||
|
||||
/// Teil-Netz mit EINEM Material, lokale Indizes.
|
||||
struct Prim {
|
||||
material: f64,
|
||||
positions: Vec<f64>,
|
||||
indices: Vec<f64>,
|
||||
pub(crate) struct Prim {
|
||||
pub(crate) material: f64,
|
||||
pub(crate) positions: Vec<f64>,
|
||||
pub(crate) indices: Vec<f64>,
|
||||
}
|
||||
|
||||
/// Ein Bauteil-Vorkommen mit ≥ 1 Teil-Netz.
|
||||
struct Group {
|
||||
name: String,
|
||||
kind: &'static str,
|
||||
id: String,
|
||||
level: f64,
|
||||
prims: Vec<Prim>,
|
||||
pub(crate) struct Group {
|
||||
pub(crate) name: String,
|
||||
pub(crate) kind: &'static str,
|
||||
pub(crate) id: String,
|
||||
pub(crate) level: f64,
|
||||
pub(crate) prims: Vec<Prim>,
|
||||
}
|
||||
|
||||
impl Group {
|
||||
@@ -74,17 +74,17 @@ impl Group {
|
||||
}
|
||||
|
||||
/// Material der Szene: Farbe sRGB 0..1, Alpha < 1 = transparent (Glas).
|
||||
struct Material {
|
||||
name: String,
|
||||
rgba: [f64; 4],
|
||||
metallic: f64,
|
||||
roughness: f64,
|
||||
pub(crate) struct Material {
|
||||
pub(crate) name: String,
|
||||
pub(crate) rgba: [f64; 4],
|
||||
pub(crate) metallic: f64,
|
||||
pub(crate) roughness: f64,
|
||||
}
|
||||
|
||||
/// Materialtabelle: gleiche Farbe + Name = ein Material (Schlüssel wie in TS als Text).
|
||||
#[derive(Default)]
|
||||
struct Materials {
|
||||
list: Vec<Material>,
|
||||
pub(crate) struct Materials {
|
||||
pub(crate) list: Vec<Material>,
|
||||
by_key: HashMap<String, usize>,
|
||||
}
|
||||
|
||||
@@ -338,8 +338,47 @@ fn same_rgb(a: &Rgb, b: &Rgb) -> bool {
|
||||
a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-9)
|
||||
}
|
||||
|
||||
/// Gesammelte Szene: Bauteil-Gruppen mit Teil-Netzen, Materialtabelle, Geschosse (gemeinsame Quelle von
|
||||
/// glTF/OBJ/STL und der Cycles-Szene [215], `cycles_scene.rs`).
|
||||
pub(crate) struct SceneData {
|
||||
pub(crate) groups: Vec<Group>,
|
||||
pub(crate) mats: Materials,
|
||||
pub(crate) levels: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
/// Die Szene als flacher Puffer (s. Modulkopf).
|
||||
pub fn mesh_export_data(src: &Project, opt: &MeshOptions) -> Result<Flat, String> {
|
||||
let SceneData { groups, mats, levels } = collect_scene(src, opt)?;
|
||||
// Flacher Puffer (Gegenstück zu `mesh_export.rs`).
|
||||
let mut f = Flat::new(FLAT_VERSION);
|
||||
f.num(if opt.by_level { 1.0 } else { 0.0 });
|
||||
f.num(mats.list.len() as f64);
|
||||
for m in &mats.list {
|
||||
let n = f.str(&m.name);
|
||||
f.nums(&[n, m.rgba[0], m.rgba[1], m.rgba[2], m.rgba[3], m.metallic, m.roughness]);
|
||||
}
|
||||
f.num(levels.len() as f64);
|
||||
for (id, name) in &levels {
|
||||
let (a, b) = (f.str(id), f.str(name));
|
||||
f.nums(&[a, b]);
|
||||
}
|
||||
let groups: Vec<&Group> = groups.iter().filter(|g| g.prims.iter().any(|p| !p.indices.is_empty())).collect();
|
||||
f.num(groups.len() as f64);
|
||||
for g in groups {
|
||||
let (name, kind, id) = (f.str(&g.name), f.str(g.kind), f.str(&g.id));
|
||||
f.nums(&[name, kind, id, g.level, g.prims.len() as f64]);
|
||||
for pr in &g.prims {
|
||||
f.nums(&[pr.material, (pr.positions.len() / 3) as f64]);
|
||||
f.nums(&pr.positions);
|
||||
f.num((pr.indices.len() / 3) as f64);
|
||||
f.nums(&pr.indices);
|
||||
}
|
||||
}
|
||||
Ok(f)
|
||||
}
|
||||
|
||||
/// Sammelt die Szene aus dem Projekt (Dreiecke in Welt-Achsen (x, Höhe, y), nach aussen gewickelt).
|
||||
pub(crate) fn collect_scene(src: &Project, opt: &MeshOptions) -> Result<SceneData, String> {
|
||||
let mut p = src.clone();
|
||||
let mut groups: Vec<Group> = Vec::new();
|
||||
let mut mats = Materials::default();
|
||||
@@ -533,32 +572,7 @@ pub fn mesh_export_data(src: &Project, opt: &MeshOptions) -> Result<Flat, String
|
||||
}
|
||||
}
|
||||
|
||||
// Flacher Puffer (Gegenstück zu `mesh_export.rs`).
|
||||
let mut f = Flat::new(FLAT_VERSION);
|
||||
f.num(if opt.by_level { 1.0 } else { 0.0 });
|
||||
f.num(mats.list.len() as f64);
|
||||
for m in &mats.list {
|
||||
let n = f.str(&m.name);
|
||||
f.nums(&[n, m.rgba[0], m.rgba[1], m.rgba[2], m.rgba[3], m.metallic, m.roughness]);
|
||||
}
|
||||
f.num(levels.len() as f64);
|
||||
for (id, name) in &levels {
|
||||
let (a, b) = (f.str(id), f.str(name));
|
||||
f.nums(&[a, b]);
|
||||
}
|
||||
let groups: Vec<&Group> = groups.iter().filter(|g| g.prims.iter().any(|p| !p.indices.is_empty())).collect();
|
||||
f.num(groups.len() as f64);
|
||||
for g in groups {
|
||||
let (name, kind, id) = (f.str(&g.name), f.str(g.kind), f.str(&g.id));
|
||||
f.nums(&[name, kind, id, g.level, g.prims.len() as f64]);
|
||||
for pr in &g.prims {
|
||||
f.nums(&[pr.material, (pr.positions.len() / 3) as f64]);
|
||||
f.nums(&pr.positions);
|
||||
f.num((pr.indices.len() / 3) as f64);
|
||||
f.nums(&pr.indices);
|
||||
}
|
||||
}
|
||||
Ok(f)
|
||||
Ok(SceneData { groups, mats, levels })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -82,7 +82,7 @@ fn ring_pts(r: &[[f64; 2]]) -> Vec<Vec2> {
|
||||
}
|
||||
|
||||
/// Breite/Länge des Projekts aus `geoAnchor` (LV95), sonst Zürich.
|
||||
fn project_lat_lon(p: &Project) -> (f64, f64) {
|
||||
pub(crate) fn project_lat_lon(p: &Project) -> (f64, f64) {
|
||||
match &p.geo_anchor {
|
||||
Some(a) => crate::geo_rebase::lv95_to_wgs84(a.lv95.e, a.lv95.n),
|
||||
None => (47.3769, 8.5417),
|
||||
|
||||
@@ -91,6 +91,11 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
json(&room_program::layout(p, &opt))
|
||||
}
|
||||
("siteCheck", _) => json(&site_rules::check_project(p)),
|
||||
// [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(p, &o)?)
|
||||
}
|
||||
("dormerStatus", _) => json(&crate::dormer::status(p)),
|
||||
("excavationQuantities", _) => json(&crate::excavation::quantities(p)),
|
||||
("buildingFootprint", _) => json(&site_rules::building_footprint(p)),
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//! Bindung der Cycles-Nachbearbeitung ([215], `crate::cycles_post`): lineares Fliesskomma-Bild → sRGB 8 Bit.
|
||||
|
||||
use crate::cycles_post::{tonemap, Look};
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// `data`: RGB oder RGBA (`channels` 3/4), zeilenweise von oben, lineares Licht; `ev`: Zusatzbelichtung in Blenden;
|
||||
/// `look`: "filmic" (Standard) oder "standard". Ergebnis: RGB 8 Bit; leer bei kaputtem Puffer.
|
||||
#[wasm_bindgen]
|
||||
pub fn cycles_tonemap(data: &[f32], channels: u32, ev: f64, look: &str) -> Vec<u8> {
|
||||
tonemap(data, channels as usize, ev, Look::parse(look))
|
||||
}
|
||||
@@ -52,6 +52,7 @@ pub mod furniture_lib;
|
||||
pub mod solid_bool;
|
||||
pub mod line_pattern;
|
||||
pub mod fonts;
|
||||
pub mod cycles;
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
|
||||
Reference in new issue
Block a user