[K4] S2 (Zwischenstand): Treppen (3D) aus dem Dokument

This commit is contained in:
karim committed 2026-10-28 01:58:06 +01:00
1 parent 6ebe85fdf6
commit 478135e204
5 files changed
+157 -1

No files matched your search

+33
View File
@@ -181,3 +181,36 @@ impl Roof {
}
}
}
impl Stair {
/// Treppen-Parameter als 16 Zahlen (Aufbau: `stair.rs`, `encodeStair` in TS); fehlend = NaN.
pub fn encode(&self) -> [f64; 16] {
let n = |v: Option<f64>| v.unwrap_or(f64::NAN);
[
match self.shape {
StairShape::Straight => 0.0,
StairShape::L => 1.0,
StairShape::Spiral => 2.0,
},
self.start.x,
self.start.y,
self.dir.x,
self.dir.y,
self.run_length,
n(self.run2_length),
n(self.turn),
n(self.center.map(|c| c.x)),
n(self.center.map(|c| c.y)),
n(self.radius),
n(self.sweep),
self.width,
self.step_count,
self.up.map_or(f64::NAN, |u| if u { 1.0 } else { 0.0 }),
match self.referenz {
Some(StairReferenz::Links) => 1.0,
Some(StairReferenz::Rechts) => 2.0,
_ => 0.0,
},
]
}
}
+90
View File
@@ -701,6 +701,96 @@ pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec<RMesh> {
out
}
// ── Treppen ─────────────────────────────────────────────────────────────────
fn stair_rgb() -> Rgb {
hex_to_rgb("#9aa0a6", SLAB_RGB)
}
fn rail_rgb() -> Rgb {
hex_to_rgb("#74797f", SLAB_RGB)
}
/// Flache Eingabe der Treppen für `stairs3d` (23 Zahlen je Treppe); `wanted` wählt vor.
fn stair_input<'a>(p: &'a Project, wanted: impl Fn(&Stair, Option<&StairType>) -> bool) -> Option<(Vec<&'a Stair>, Vec<f64>)> {
let mut stairs: Vec<&Stair> = Vec::new();
let mut types: Vec<Option<&StairType>> = Vec::new();
for s in p.stairs.as_deref().unwrap_or(&[]) {
let st = p.stair_type(s);
if !wanted(s, st) {
continue;
}
stairs.push(s);
types.push(st);
}
if stairs.is_empty() {
return None;
}
let mut buf = vec![stairs.len() as f64];
for (s, st) in stairs.iter().zip(&types) {
let (z_bottom, z_top) = p.stair_vertical_extent(s);
buf.extend(s.encode());
buf.push(z_bottom);
buf.push(z_top);
buf.push(match st.map(|t| t.structure) {
None | Some(StairTypeStructure::Massiv) => 0.0,
Some(StairTypeStructure::Beton) => 1.0,
_ => 2.0,
});
buf.push(st.map_or(0.04, |t| t.tread_thickness));
buf.push(st.and_then(|t| t.nosing).unwrap_or(0.0));
buf.push(if st.is_some_and(|t| t.closed_risers) { 1.0 } else { 0.0 });
buf.push(match st.and_then(|t| t.railing) {
Some(StairTypeRailing::Links) => 1.0,
Some(StairTypeRailing::Rechts) => 2.0,
Some(StairTypeRailing::Beide) => 3.0,
_ => 0.0,
});
}
Some((stairs, buf))
}
/// Treppen als extrudierte Platten (`emitStairs`); `for_section`: auch gerade Betontreppen als Tritte.
pub fn emit_stairs(p: &Project, for_section: bool) -> Vec<RSlab> {
let Some((stairs, buf)) = stair_input(p, |_, _| true) else { return vec![] };
crate::stairs3d::slabs(&buf, for_section)
.into_iter()
.map(|s| {
let stair = stairs[s.src];
RSlab {
outline: s.pts,
z_bottom: s.z_bottom,
z_top: s.z_top,
color: stair_rgb(),
ceiling_id: stair.id.clone(),
hatch: None,
cut: None,
monolith: s.monolith.then(|| stair.id.clone()),
}
})
.collect()
}
fn meshes_of(meshes: Vec<crate::mesh3d::Mesh>, color: Rgb) -> Vec<RMesh> {
meshes.into_iter().map(|m| RMesh { positions: m.positions, indices: m.indices, kind: "extrusion", color, vertex_colors: None, material_index: None }).collect()
}
/// Glatte Ortbeton-Laufplatten gerader Treppen (`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::Straight) {
Some((_, buf)) => meshes_of(crate::stairs3d::slab_meshes(&buf), stair_rgb()),
None => vec![],
}
}
/// Handlauf und Pfosten gerader Treppen (`emitStairRailings`).
pub fn emit_stair_railings(p: &Project) -> Vec<RMesh> {
match stair_input(p, |s, st| s.shape == StairShape::Straight && st.and_then(|t| t.railing).is_some_and(|r| r != StairTypeRailing::Keine)) {
Some((_, buf)) => meshes_of(crate::stairs3d::railings(&buf), rail_rgb()),
None => vec![],
}
}
#[cfg(test)]
mod tests {
use super::*;
+3
View File
@@ -85,6 +85,9 @@ pub fn doc_query_args(h: u32, name: &str, args: &[f64]) -> String {
"modelTop" => serde_json::to_string(&site_rules::model_top(&p)),
"walls" if args.len() == 1 => crate::model3d::emit_walls(&p, args[0] != 0.0).map_err(|_| ()).and_then(|w| serde_json::to_string(&w).map_err(|_| ())).map_err(|_| serde_json::Error::io(std::io::Error::other("walls"))),
"openingMeshes" if args.len() == 1 => serde_json::to_string(&crate::model3d::emit_opening_meshes(&p, args[0])),
"stairSlabs" if args.len() == 1 => serde_json::to_string(&crate::model3d::emit_stairs(&p, args[0] != 0.0)),
"stairMeshes" => serde_json::to_string(&crate::model3d::emit_stair_meshes(&p)),
"stairRailings" => serde_json::to_string(&crate::model3d::emit_stair_railings(&p)),
"slabs" => serde_json::to_string(&crate::model3d::emit_slabs(&p)),
"columnMeshes" => serde_json::to_string(&crate::model3d::emit_columns(&p)),
"shadows" if args.len() == 2 => {