[K4] S2 (Zwischenstand): Treppen (3D) aus dem Dokument
This commit is contained in:
1 parent
6ebe85fdf6
commit
478135e204
5 files changed
+157
-1
No files matched your search
@@ -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,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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::*;
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -49,7 +49,7 @@ export class ProjectDocument {
|
||||
* Abfrage auf dem typisierten Projekt im Kern. Das Ergebnis ist JSON; ein Fehler (Projekt passt
|
||||
* nicht zum Modell, unbekannte Abfrage) wirft.
|
||||
*/
|
||||
query<T>(name: "kennzahlen" | "siteCheck" | "buildingFootprint" | "modelTop" | "shadows" | "slabs" | "columnMeshes" | "walls" | "openingMeshes", args: number[] = []): T {
|
||||
query<T>(name: "kennzahlen" | "siteCheck" | "buildingFootprint" | "modelTop" | "shadows" | "slabs" | "columnMeshes" | "walls" | "openingMeshes" | "stairSlabs" | "stairMeshes" | "stairRailings", args: number[] = []): T {
|
||||
const text = this.handle ? core().doc_query_args(this.handle, name, Float64Array.from(args)) : "";
|
||||
if (!text) throw new Error(`Kern-Abfrage „${name}": Projekt passt nicht zum Kern-Modell`);
|
||||
return JSON.parse(text) as T;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { emitSlabs } from "./toWalls3d/ceilings";
|
||||
import { emitColumns } from "./toWalls3d/columns";
|
||||
import { projectToWalls3d } from "./toWalls3d";
|
||||
import { emitOpeningMeshes } from "./toWalls3d/openings";
|
||||
import { emitStairs, emitStairMeshes, emitStairRailings } from "./toWalls3d/stairs";
|
||||
|
||||
const plain = <T,>(v: T): T => JSON.parse(JSON.stringify(v));
|
||||
let seed = 21;
|
||||
@@ -68,6 +69,35 @@ describe("model3d walls", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("model3d stairs", () => {
|
||||
it("random", () => {
|
||||
let n = 0;
|
||||
for (let t = 0; t < 200; t++) {
|
||||
const lvl = sampleProject.drawingLevels.filter((l) => l.kind === "floor");
|
||||
const types = Array.from({ length: 3 }, (_, k) => ({ id: "st" + k, name: "t", structure: pick(["massiv", "beton", "wange", "aufgesattelt", "spindel"]), closedRisers: rnd() < 0.5,
|
||||
treadThickness: pick([0.04, 0.06]), nosing: rnd() < 0.5 ? 0.03 : undefined, railing: pick(["keine", "links", "rechts", "beide", undefined]), defaultWidth: 1 }));
|
||||
const stairs = Array.from({ length: 1 + Math.floor(rnd() * 3) }, (_, k) => {
|
||||
const shape = pick(["straight", "L", "spiral"]);
|
||||
return { id: "s" + k, type: "stair", floorId: pick(lvl).id, categoryCode: "25", shape, start: { x: rnd() * 5, y: rnd() * 5 }, dir: pick([{ x: 1, y: 0 }, { x: 0, y: 1 }, { x: -1, y: 0 }]),
|
||||
runLength: 2 + rnd() * 3, ...(shape === "L" ? { run2Length: 1.5, turn: pick([1, -1]) } : {}), ...(shape === "spiral" ? { center: { x: 2, y: 2 }, radius: 1.2, sweep: 4 } : {}),
|
||||
width: 1, stepCount: 8 + Math.floor(rnd() * 8), ...(rnd() < 0.5 ? { totalRise: 2.6 } : {}), ...(rnd() < 0.5 ? { up: pick([true, false]) } : {}),
|
||||
...(rnd() < 0.7 ? { typeId: pick(types).id } : {}), ...(rnd() < 0.3 ? { referenz: pick(["links", "rechts", "mitte"]) } : {}) };
|
||||
});
|
||||
const project: any = { ...sampleProject, stairs, stairTypes: types };
|
||||
const doc = documentFor(project);
|
||||
for (const fs of [false, true]) {
|
||||
const a = doc.query<unknown[]>("stairSlabs", [fs ? 1 : 0]);
|
||||
const b = plain(emitStairs(project, { forSection: fs }));
|
||||
expect(a).toEqual(b);
|
||||
n += b.length;
|
||||
}
|
||||
expect(doc.query("stairMeshes")).toEqual(plain(emitStairMeshes(project)));
|
||||
expect(doc.query("stairRailings")).toEqual(plain(emitStairRailings(project)));
|
||||
}
|
||||
expect(n).toBeGreaterThan(300);
|
||||
});
|
||||
});
|
||||
|
||||
describe("model3d slabs/columns", () => {
|
||||
it("random", () => {
|
||||
let ns = 0, nc = 0;
|
||||
|
||||
Reference in new issue
Block a user