[K4] S2 (Zwischenstand): Oeffnungs-Einbauteile (3D) aus dem Dokument

This commit is contained in:
karim committed 2026-10-28 01:57:14 +01:00
1 parent 9db2122aae
commit 6ebe85fdf6
4 files changed
+184 -2

No files matched your search

+166
View File
@@ -535,6 +535,172 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result<Vec<RWall>, String> {
Ok(out)
}
// ── Öffnungs-Einbauteile (Glas, Rahmen, Sprossen, Bank, Kasten) ─────────────
/// Farbe je Bauteil-Klasse (Index = `Part` in `openings3d.rs`).
const PART_RGB: [Rgb; 6] = [
[0.62, 0.76, 0.85],
[0.85, 0.85, 0.83],
[0.88, 0.88, 0.9],
[0.8, 0.8, 0.78],
[0.25, 0.27, 0.3],
[0.93, 0.9, 0.85],
];
/// Dreiecke eines Öffnungs-Quaders (Ecken-Bits: bit0 = Achse, bit1 = Höhe, bit2 = quer).
const OPENING_BOX_TRIS: [u32; 36] = [0, 1, 3, 0, 3, 2, 4, 5, 7, 4, 7, 6, 0, 1, 5, 0, 5, 4, 2, 3, 7, 2, 7, 6, 0, 2, 6, 0, 6, 4, 1, 3, 7, 1, 7, 5];
fn opt(v: Option<f64>) -> f64 {
v.unwrap_or(f64::NAN)
}
fn flag(b: bool) -> f64 {
if b {
1.0
} else {
0.0
}
}
fn join_code(j: Option<FrameCornerJoin>) -> f64 {
match j {
Some(FrameCornerJoin::Horizontal) => 1.0,
Some(FrameCornerJoin::Gehrung) => 2.0,
_ => 0.0,
}
}
fn opening_kind_code(k: Option<OpeningKind>) -> f64 {
match k {
None => 0.0,
Some(OpeningKind::Dreh) => 1.0,
Some(OpeningKind::Kipp) => 2.0,
Some(OpeningKind::Drehkipp) => 3.0,
Some(OpeningKind::Fest) => 4.0,
Some(OpeningKind::Schiebe) => 5.0,
}
}
fn write_common(w: &mut FlatWriter, frame_depth: Option<f64>, inset: Option<f64>, inner: bool, join: Option<FrameCornerJoin>, frame_width: Option<f64>, transom: Option<f64>) {
w.nums(&[opt(frame_depth), opt(inset), flag(inner), join_code(join), opt(frame_width), opt(transom)]);
}
fn glazing_panes_of(wt: &WindowType) -> f64 {
match wt.glazing_panes {
Some(p) if p != 0.0 => p,
_ => match wt.glazing {
WindowTypeGlazing::Dreifach => 3.0,
WindowTypeGlazing::Zweifach => 2.0,
_ => 1.0,
},
}
}
fn write_opening(w: &mut FlatWriter, p: &Project, op: &Opening) {
if op.kind == ElementKind::Window {
let Some(wt) = p.window_type(op) else {
w.num(0.0);
return;
};
w.num(1.0);
write_common(w, wt.frame_depth, wt.inset_from_face, wt.inset_face == Some(WindowTypeInsetFace::Innen), wt.frame_corner_join, wt.frame_width, wt.transom_height);
let shading = wt.shading.as_ref().filter(|s| s.create).map(|s| &s.r#box);
w.nums(&[
glazing_panes_of(wt),
opt(wt.mullion_rows),
opt(wt.mullion_cols),
match wt.sill_board {
Some(WindowTypeSillBoard::Keine) => 1.0,
Some(WindowTypeSillBoard::Innen) => 2.0,
Some(WindowTypeSillBoard::Beide) => 3.0,
_ => 0.0,
},
flag(shading.is_some()),
shading.map_or(0.0, |b| b.width),
shading.map_or(0.0, |b| b.height),
shading.map_or(0.0, |b| b.depth),
op.wing_count.unwrap_or(wt.wing_count),
opening_kind_code(Some(wt.kind)),
]);
let sashes = wt.sashes.as_deref().unwrap_or(&[]);
w.num(sashes.len() as f64);
for s in sashes {
w.nums(&[
if s.kind == SashDefKind::Fluegel { 0.0 } else { 1.0 },
flag(s.auto_width == Some(false)),
opt(s.width),
opt(s.post_width),
opening_kind_code(s.opening),
flag(s.hinge_side != Some(SashDefHingeSide::Right)),
]);
}
return;
}
let Some(dt) = p.door_type(op) else {
w.num(0.0);
return;
};
w.num(1.0);
write_common(w, dt.frame_depth, dt.inset_from_face, dt.inset_face == Some(DoorTypeInsetFace::Innen), dt.frame_corner_join, dt.frame_width, dt.transom_height);
w.nums(&[
flag(dt.threshold == Some(true)),
dt.leaf_count,
match dt.leaf_style {
DoorTypeLeafStyle::Glas => 1.0,
DoorTypeLeafStyle::Kassette => 2.0,
_ => 0.0,
},
opt(dt.glazing_ratio),
flag(dt.frame_kind != Some(DoorTypeFrameKind::Blockrahmen)),
opt(dt.panel_cols),
opt(dt.panel_rows),
]);
}
/// Öffnungs-Einbauteile als Quader-Meshes (`emitOpeningMeshes`); `detail`: 0 grob, 1 mittel, 2 fein.
pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec<RMesh> {
let mut w = FlatWriter::new();
w.num(detail).num(p.walls.len() as f64);
for wall in &p.walls {
w.nums(&[wall.start.x, wall.start.y, wall.end.x, wall.end.y]);
let slot = w.slot();
let mut count = 0.0;
let wr = wall_ref(p, wall);
let (zb, zt) = p.wall_vertical_extent(wall);
let mut thickness: Option<f64> = None;
for op in p.openings_of_wall(&wall.id) {
let Some((from, to)) = opening_geom::opening_interval(&wr, op.position, op.width) else { continue };
let o_bottom = zb + op.sill_height.max(0.0);
let o_top = zt.min(o_bottom + op.height);
let t = *thickness.get_or_insert_with(|| p.wall_thickness(wall, 0.2));
w.nums(&[from, to, o_bottom, o_top, flag(op.kind != ElementKind::Window), t]);
write_opening(&mut w, p, op);
count += 1.0;
}
w.set(slot, count);
}
let buf = crate::openings3d::opening_meshes_flat(&w.done());
let n = buf.first().copied().unwrap_or(0.0).max(0.0) as usize;
let mut out = Vec::new();
let mut i = 1;
for _ in 0..n {
if i + 25 > buf.len() {
break;
}
let part = buf[i] as usize;
out.push(RMesh {
positions: buf[i + 1..i + 25].to_vec(),
indices: OPENING_BOX_TRIS.to_vec(),
kind: "extrusion",
color: PART_RGB.get(part).copied().unwrap_or(PART_RGB[1]),
vertex_colors: None,
material_index: None,
});
i += 25;
}
out
}
#[cfg(test)]
mod tests {
use super::*;
+1
View File
@@ -84,6 +84,7 @@ pub fn doc_query_args(h: u32, name: &str, args: &[f64]) -> String {
"buildingFootprint" => serde_json::to_string(&site_rules::building_footprint(&p)),
"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])),
"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 => {
+1 -1
View File
@@ -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", args: number[] = []): T {
query<T>(name: "kennzahlen" | "siteCheck" | "buildingFootprint" | "modelTop" | "shadows" | "slabs" | "columnMeshes" | "walls" | "openingMeshes", 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;
+16 -1
View File
@@ -4,6 +4,7 @@ import { documentFor } from "../core/document";
import { emitSlabs } from "./toWalls3d/ceilings";
import { emitColumns } from "./toWalls3d/columns";
import { projectToWalls3d } from "./toWalls3d";
import { emitOpeningMeshes } from "./toWalls3d/openings";
const plain = <T,>(v: T): T => JSON.parse(JSON.stringify(v));
let seed = 21;
@@ -39,8 +40,22 @@ describe("model3d walls", () => {
...(sampleProject.ceilingTypes?.length && rnd() < 0.5 ? { ceilingTypeId: pick(sampleProject.ceilingTypes).id } : {}) }));
const roofs = rnd() < 0.5 ? [{ id: "R1", type: "roof", floorId: pick(lvl).id, categoryCode: "35", outline: [{ x: -1, y: -1 }, { x: 7, y: -1 }, { x: 7, y: 5 }, { x: -1, y: 5 }],
shape: pick(["sattel", "walm", "pult", "flach"]), pitchDeg: 30, overhang: 0.3, ridgeAxis: pick(["x", "y"]), thickness: 0.2 }] : [];
const project: any = { ...sampleProject, walls, openings, ceilings, roofs };
const kinds = ["fest", "dreh", "kipp", "drehkipp", "schiebe"];
const wts = Array.from({ length: 2 }, (_, k) => ({ ...sampleProject.windowTypes![0], id: "wt" + k, kind: pick(kinds), wingCount: 1 + Math.floor(rnd() * 3),
frameWidth: rnd() < 0.5 ? pick([0.04, 0.06, 0.09]) : undefined, transomHeight: rnd() < 0.5 ? pick([0.2, 0.4]) : undefined,
mullionRows: rnd() < 0.5 ? pick([1, 2, 3]) : undefined, mullionCols: rnd() < 0.5 ? pick([1, 2]) : undefined,
sillBoard: pick(["keine", "innen", "aussen", "beide", undefined]), glazingPanes: pick([1, 2, 3, undefined]), glazing: pick(["einfach", "zweifach", "dreifach"]),
frameCornerJoin: pick(["vertikal", "horizontal", "gehrung", undefined]), insetFromFace: rnd() < 0.5 ? 0.1 : undefined, insetFace: pick(["aussen", "innen", undefined]),
innerLayerRecess: rnd() < 0.3 ? true : undefined, shading: rnd() < 0.4 ? { create: true, kind: "rollladen", box: { width: 1, height: 0.2, depth: 0.2 } } : undefined,
sashes: rnd() < 0.6 ? Array.from({ length: 1 + Math.floor(rnd() * 3) }, () => ({ kind: pick(["fluegel", "fluegel", "pfosten"]), autoWidth: pick([true, false, undefined]), width: rnd() < 0.5 ? 0.4 : undefined, postWidth: rnd() < 0.5 ? 0.08 : undefined, opening: pick([...kinds, undefined]), hingeSide: pick(["left", "right", undefined]) })) : undefined }));
const dts = Array.from({ length: 2 }, (_, k) => ({ ...sampleProject.doorTypes![0], id: "dt" + k, leafStyle: pick(["glatt", "glas", "kassette"]), glazingRatio: rnd() < 0.5 ? pick([0.3, 1]) : undefined,
frameKind: pick(["zarge", "blockrahmen", undefined]), threshold: pick([true, false, undefined]), leafCount: pick([1, 2]) , panelCols: rnd() < 0.5 ? 2 : undefined, panelRows: rnd() < 0.5 ? 3 : undefined }));
const openings2 = openings.map((o: any) => ({ ...o, ...(rnd() < 0.8 ? { typeId: o.kind === "door" ? pick(dts).id : pick(wts).id } : {}), ...(rnd() < 0.3 ? { wingCount: 2 } : {}) }));
const project: any = { ...sampleProject, walls, openings: openings2, ceilings, roofs, windowTypes: wts, doorTypes: dts };
const doc = documentFor(project);
for (const [dc, dn] of [[0, "grob"], [1, "mittel"], [2, "fein"]] as const) {
expect(doc.query<unknown[]>("openingMeshes", [dc])).toEqual(plain(emitOpeningMeshes(project, dn)));
}
for (const layered of [true, false]) {
let want: unknown;
try { want = plain(projectToWalls3d(project, layered)); } catch { want = undefined; }