[108] Schräge Wandanschlüsse: IFC-Profile und truck-Körper mit Gehrung
This commit is contained in:
9 files changed
+383
-31
No files matched your search
@@ -2298,8 +2298,16 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]).
|
||||
rechtwinklig an der Band-Mitte (Dreieck-Lücke weg); OBJ/STL/GLB (`mesh_data.rs`) und Live-Schnitt ebenso.
|
||||
SVG-Export des Grundrisses beachtet jetzt `noStrokeEdges` (vorher Stossfugen/Gehrungen gestrichen).
|
||||
Tests: Winkel 15°–165° ein-/mehrschichtig (Joins, Grundriss-Primitive, 3D-Rasterprüfung lückenlos/ohne
|
||||
Doppelung für T, Knoten-T, L, X). Geprüft: cargo/vitest, CLI-Grundriss-SVG angesehen (Linux). Offen: 3D nur
|
||||
per Rust-Test (kein Metal-Render), IFC/truck-Körper noch rechtwinklig, nicht in der Tauri-App geprüft. · S
|
||||
Doppelung für T, Knoten-T, L, X). Geprüft: cargo/vitest, CLI-Grundriss-SVG angesehen (Linux). (5.11.) IFC und
|
||||
truck-Körper folgen: IFC-Wandprofile (SweptSolid je Band, `ifc_data.rs`) sind das Grundriss-Viereck des 3D
|
||||
(`model3d::wall_footprint`), der Netz-Weg verschiebt die Enden wie OBJ (`mesh_data::shift_cut_ends`); truck
|
||||
(`solid_specs::wall_spec` → STEP, Kennwerte, Kollision, Abzugskörper) baut schräge Stirnflächen ohne Boolean:
|
||||
`extrudePlane.pointsBack` = Profilring der Rückseite, trucksolid verbindet beide Ringe mit Regelflächen
|
||||
(`extrude_plane_skew`); Öffnung in der schrägen Endzone → dort rechtwinklig, STEP-Rückfall rechtwinklig.
|
||||
Tests: Rust (schräges L 60°: Profil-Ecken = 3D, Volumen = d·h·(L1+L2), IFC-Gehrungsecken; truck: geschlossen,
|
||||
Volumen mit Fenster, STEP), vitest Musterhaus-Ecken; `validate-ifc.py` grün (Linux). Offen: 3D nur per Rust-Test
|
||||
(kein Metal-Render), nicht in der Tauri-App geprüft; Mesh-Rückfall der truck-Booleans (`boolean.rs`) verschweisst
|
||||
nur bitgleiche Ecken und scheitert darum bei schräg liegenden Körpern (Befund, älter). · S
|
||||
- ✅ **[114] Musterhaus komplex.** (30.10.) Zweites Beispielprojekt (`src/model/sampleProjectComplex.ts`,
|
||||
`buildComplexSampleProject()`), in dem möglichst alle Funktionen vorkommen: Zweifamilienhaus am Südhang, UG (im
|
||||
Hang, Süden frei) / EG / OG / DG mit Sichtbereichen und Ansichtsvorlagen; Gelände aus Höhenlinien (Kern-Befehl
|
||||
|
||||
@@ -869,10 +869,16 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
f.num(bands.len() as f64);
|
||||
let base = base_of(structure);
|
||||
for b in &bands {
|
||||
let (s, e) = (v2(b.start), v2(b.end));
|
||||
let n = left_normal(normalize(sub(e, s)));
|
||||
let h = b.thickness / 2.0;
|
||||
w_pts(&mut f, &[add_scaled(s, n, -h), add_scaled(e, n, -h), add_scaled(e, n, h), add_scaled(s, n, h)]);
|
||||
// Grundriss-Viereck an den Schnittlinien (Gehrung, schräger Stoss, [108]) wie das 3D.
|
||||
match model3d::wall_footprint(b) {
|
||||
Some(q) => w_pts(&mut f, &[v2(q[3]), v2(q[2]), v2(q[1]), v2(q[0])]),
|
||||
None => {
|
||||
let (s, e) = (v2(b.start), v2(b.end));
|
||||
let n = left_normal(normalize(sub(e, s)));
|
||||
let h = b.thickness / 2.0;
|
||||
w_pts(&mut f, &[add_scaled(s, n, -h), add_scaled(e, n, -h), add_scaled(e, n, h), add_scaled(s, n, h)]);
|
||||
}
|
||||
}
|
||||
f.nums(&[b.base_elevation - base, b.height]);
|
||||
}
|
||||
host_extent.insert(wall.id.clone(), extent);
|
||||
@@ -922,7 +928,7 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let cut = wall_cut_mesh_checked(&CutWall {
|
||||
let mut cut = wall_cut_mesh_checked(&CutWall {
|
||||
start: b.start,
|
||||
end: b.end,
|
||||
thickness: b.thickness,
|
||||
@@ -930,6 +936,8 @@ pub fn ifc_export_data(src: &Project, opt: &IfcOptions) -> Result<Flat, String>
|
||||
height: b.height,
|
||||
holes: b.holes.as_deref().unwrap_or(&[]).iter().map(|h| [h.from, h.to, h.z_bottom, h.z_top]).collect(),
|
||||
});
|
||||
// Enden auf die Schnittlinien (Gehrung, schräger Stoss, [108]) wie OBJ/STL/GLB.
|
||||
crate::mesh_data::shift_cut_ends(&mut cut, b);
|
||||
let at = (positions.len() / 3) as u32;
|
||||
for c in cut.chunks_exact(3) {
|
||||
positions.extend_from_slice(&[c[0], c[2], c[1] - base]);
|
||||
@@ -1493,6 +1501,25 @@ mod tests {
|
||||
assert!(full >= 3, "{full}"); // Innenputz durch den T-Anschluss von W9 geteilt
|
||||
}
|
||||
|
||||
/// [108] Schräges L (60°): die Wand-Profile (SweptSolid je Band) tragen die Gehrung des 3D-Körpers
|
||||
/// statt Rechtecken; Summe der Extrusionen = Dicke × Höhe × (L1 + L2), keine Lücke an der Aussenecke.
|
||||
#[test]
|
||||
fn schraeges_l_profile_mit_gehrung() {
|
||||
let p = crate::solid_specs::tests::schraeges_l();
|
||||
let f = ifc_export_data(&p, &IfcOptions::default()).unwrap();
|
||||
// Profile: [4, x0, y0, …, x3, y3, z_rel, Tiefe] mit Tiefe 2.5.
|
||||
let profiles: Vec<&[f64]> = f.nums.windows(11).filter(|w| w[0] == 4.0 && w[9] == 0.0 && w[10] == 2.5).collect();
|
||||
assert_eq!(profiles.len(), 2, "zwei Wände, je ein Band");
|
||||
let area = |w: &[f64]| (0..4).map(|i| { let j = (i + 1) % 4; w[1 + 2 * i] * w[2 + 2 * j] - w[1 + 2 * j] * w[2 + 2 * i] }).sum::<f64>() / 2.0;
|
||||
let vol: f64 = profiles.iter().map(|w| area(w) * 2.5).sum();
|
||||
assert!((vol - 0.3 * 2.5 * 7.0).abs() < 1e-9, "{vol}");
|
||||
assert!(profiles.iter().all(|w| area(w) > 0.0), "CCW");
|
||||
// Aussenecke der Gehrung (−0.15·√3, −0.15) in beiden Profilen, Innenecke (+0.15·√3, +0.15) auch.
|
||||
let has = |w: &[f64], x: f64, y: f64| (0..4).any(|i| (w[1 + 2 * i] - x).abs() < 1e-9 && (w[2 + 2 * i] - y).abs() < 1e-9);
|
||||
let (x, y) = (0.15 * 3f64.sqrt(), 0.15);
|
||||
assert!(profiles.iter().all(|w| has(w, -x, -y) && has(w, x, y)), "{profiles:?}");
|
||||
}
|
||||
|
||||
/// [71] U-Wert aus dem Schichtaufbau landet als ThermalTransmittance in Pset_WallCommon (nur mit λ).
|
||||
#[test]
|
||||
fn u_wert_der_wand_im_pset() {
|
||||
|
||||
@@ -191,7 +191,7 @@ fn push_wall_box(g: &mut Prim, w: &RWall) {
|
||||
/// Ecken an Wandanfang/-ende (Welt x, Höhe, y) längs der Achse auf die Schnittlinien schieben
|
||||
/// (`RWall::start_cut`/`end_cut`); die Mantelflächen bleiben eben, weil sich nur Endpunkte längs
|
||||
/// der Achse verschieben.
|
||||
fn shift_cut_ends(pos: &mut [f64], w: &RWall) {
|
||||
pub(crate) fn shift_cut_ends(pos: &mut [f64], w: &RWall) {
|
||||
if w.start_cut.is_none() && w.end_cut.is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -69,16 +69,37 @@ pub struct WallIn<'a> {
|
||||
pub height: f64,
|
||||
pub base_elevation: f64,
|
||||
pub holes: &'a [RHole],
|
||||
/// Schnittlinien `[px, py, dx, dy]` an Anfang/Ende (`RWall::start_cut`/`end_cut`, [108]).
|
||||
pub start_cut: Option<[f64; 4]>,
|
||||
pub end_cut: Option<[f64; 4]>,
|
||||
}
|
||||
|
||||
impl<'a> WallIn<'a> {
|
||||
pub fn of(w: &'a RWall) -> Self {
|
||||
WallIn { start: w.start, end: w.end, thickness: w.thickness, height: w.height, base_elevation: w.base_elevation, holes: w.holes.as_deref().unwrap_or(&[]) }
|
||||
WallIn { start: w.start, end: w.end, thickness: w.thickness, height: w.height, base_elevation: w.base_elevation, holes: w.holes.as_deref().unwrap_or(&[]), start_cut: w.start_cut, end_cut: w.end_cut }
|
||||
}
|
||||
}
|
||||
|
||||
/// Achsmass (ab Anfang) der Längskante mit Querversatz `o` auf der Schnittlinie `cut`, gesucht ab dem
|
||||
/// Achsmass `base` (Anfang 0, Ende `len`) — wie `model3d::wall_footprint` (kein Treffer: `None`).
|
||||
fn cut_param(start: [f64; 2], u: (f64, f64), len: f64, base: f64, o: f64, cut: [f64; 4]) -> Option<f64> {
|
||||
let (ux, uy) = u;
|
||||
let q = [start[0] + ux * base - uy * o, start[1] + uy * base + ux * o];
|
||||
let [cx, cy, ex, ey] = cut;
|
||||
let den = ux * ey - uy * ex;
|
||||
if den.abs() < 1e-12 {
|
||||
return None;
|
||||
}
|
||||
let t = ((cx - q[0]) * ey - (cy - q[1]) * ex) / den;
|
||||
(t.is_finite() && t.abs() < len).then_some(base + t)
|
||||
}
|
||||
|
||||
/// Wand(schicht) als `extrudePlane`: Profil in der Wandebene, Ursprung auf einer Wandfläche,
|
||||
/// Tiefe = Dicke. `None` bei entarteter Wand.
|
||||
/// Tiefe = Dicke. Mit Schnittlinien an den Enden ([108], Gehrung/schräger Stoss): `points` ist der
|
||||
/// Ring auf der vorderen Fläche (+n), `pointsBack` derselbe Ring auf der hinteren (−n) — nur die
|
||||
/// Stirn-Ecken liegen anders, das Grundriss-Viereck ist `model3d::wall_footprint`. truck baut daraus
|
||||
/// einen Körper mit schrägen Stirnflächen, ohne Boolean. Öffnungen in der schrägen Endzone: rechtwinklig
|
||||
/// wie bisher. `None` bei entarteter Wand.
|
||||
pub fn wall_spec(w: &WallIn) -> Option<Value> {
|
||||
let dx = w.end[0] - w.start[0];
|
||||
let dy = w.end[1] - w.start[1];
|
||||
@@ -88,19 +109,70 @@ pub fn wall_spec(w: &WallIn) -> Option<Value> {
|
||||
}
|
||||
let ux = dx / len;
|
||||
let uy = dy / len;
|
||||
let h = w.thickness / 2.0;
|
||||
// Achsmasse der Stirn-Ecken an den Schnittlinien: [vorne (+n), hinten (−n)].
|
||||
let end_at = |cut: Option<[f64; 4]>, base: f64| -> [f64; 2] {
|
||||
let f = |o: f64| cut.and_then(|c| cut_param(w.start, (ux, uy), len, base, o, c)).unwrap_or(base);
|
||||
[f(h), f(-h)]
|
||||
};
|
||||
let oblique = |e: [f64; 2], base: f64| (e[0] - base).abs() > EPS || (e[1] - base).abs() > EPS;
|
||||
let mut a = end_at(w.start_cut, 0.0);
|
||||
let mut b = end_at(w.end_cut, len);
|
||||
let (mut cut_a, mut cut_b) = (oblique(a, 0.0), oblique(b, len));
|
||||
// Öffnung in einer schrägen Endzone: dort rechtwinklig (Profil-Ecken wären sonst verschoben).
|
||||
if cut_a && w.holes.iter().any(|q| q.from < max(a[0], a[1]) + EPS) {
|
||||
(a, cut_a) = ([0.0; 2], false);
|
||||
}
|
||||
if cut_b && w.holes.iter().any(|q| q.to > min(b[0], b[1]) - EPS) {
|
||||
(b, cut_b) = ([len; 2], false);
|
||||
}
|
||||
let u0 = if cut_a { min(a[0], a[1]) } else { 0.0 };
|
||||
let u1 = if cut_b { max(b[0], b[1]) } else { len };
|
||||
if u1 - u0 < MIN_THICKNESS || (cut_a || cut_b) && (b[0] - a[0] < MIN_THICKNESS || b[1] - a[1] < MIN_THICKNESS) {
|
||||
return None;
|
||||
}
|
||||
// u × v (v = +Z) = (uy, −ux, 0): Extrusionsrichtung. Ursprung = eine Wandfläche.
|
||||
let nx = uy;
|
||||
let ny = -ux;
|
||||
let (outer, holes) = wall_profile(len, w.height, w.holes, w.base_elevation);
|
||||
Some(json!({
|
||||
let shifted: Vec<RHole>;
|
||||
let holes = if u0 != 0.0 {
|
||||
shifted = w.holes.iter().map(|q| RHole { from: q.from - u0, to: q.to - u0, ..*q }).collect();
|
||||
&shifted[..]
|
||||
} else {
|
||||
w.holes
|
||||
};
|
||||
let (outer, holes) = wall_profile(u1 - u0, w.height, holes, w.base_elevation);
|
||||
let mut spec = json!({
|
||||
"kind": "extrudePlane",
|
||||
"points": outer,
|
||||
"holes": holes,
|
||||
"origin": [w.start[0] - (nx * w.thickness) / 2.0, w.start[1] - (ny * w.thickness) / 2.0, w.base_elevation],
|
||||
"origin": [w.start[0] + ux * u0 - (nx * w.thickness) / 2.0, w.start[1] + uy * u0 - (ny * w.thickness) / 2.0, w.base_elevation],
|
||||
"uAxis": [ux, uy, 0.0],
|
||||
"vAxis": [0.0, 0.0, 1.0],
|
||||
"depth": w.thickness,
|
||||
}))
|
||||
});
|
||||
if cut_a || cut_b {
|
||||
// Ring: erstes und letztes Paar = Anfang (Fuss, Kopf), drittletztes und vorletztes = Ende.
|
||||
let n = outer.len() / 2;
|
||||
let ring = |k: usize| -> Vec<f64> {
|
||||
let mut r = outer.clone();
|
||||
for i in [0, n - 1] {
|
||||
r[2 * i] = a[k] - u0;
|
||||
}
|
||||
for i in [n - 3, n - 2] {
|
||||
r[2 * i] = b[k] - u0;
|
||||
}
|
||||
r
|
||||
};
|
||||
spec["points"] = json!(ring(0));
|
||||
spec["pointsBack"] = json!(ring(1));
|
||||
}
|
||||
Some(spec)
|
||||
}
|
||||
|
||||
/// Wie [`wall_spec`], aber rechtwinklig (ohne Schnittlinien): Rückfall, wenn truck am Keil scheitert.
|
||||
pub fn wall_spec_plain(w: &WallIn) -> Option<Value> {
|
||||
wall_spec(&WallIn { start_cut: None, end_cut: None, ..*w })
|
||||
}
|
||||
|
||||
/// Achsparallele Hülle (x0, y0, x1, y1) wie `Math.min(...)`/`Math.max(...)`.
|
||||
@@ -264,8 +336,20 @@ pub fn project_solid_specs(p: &Project) -> Result<ProjectSpecs, String> {
|
||||
None => out.specs.push(base),
|
||||
};
|
||||
for (i, w) in parts.walls.iter().enumerate() {
|
||||
if let Some(s) = wall_spec(&WallIn::of(w)) {
|
||||
push(&mut out, s, wall_cut.get(&i));
|
||||
let win = WallIn::of(w);
|
||||
if let Some(s) = wall_spec(&win) {
|
||||
match wall_cut.get(&i) {
|
||||
// Abzug ist ein Boolean: Rückfall ohne Abzug und rechtwinklig.
|
||||
Some(c) => push(&mut out, wall_spec_plain(&win).unwrap_or(s), Some(c)),
|
||||
// Schräge Stirnflächen ([108]): Rückfall rechtwinklig, falls truck sie nicht baut.
|
||||
None if s.get("pointsBack").is_some() => {
|
||||
if let Some(plain) = wall_spec_plain(&win) {
|
||||
out.fallbacks.push((out.specs.len(), plain));
|
||||
}
|
||||
out.specs.push(s);
|
||||
}
|
||||
None => out.specs.push(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i, s) in parts.slabs.iter().enumerate() {
|
||||
@@ -296,18 +380,20 @@ pub fn project_solid_specs(p: &Project) -> Result<ProjectSpecs, String> {
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Flache Wand für die Bindung: `[sx, sy, ex, ey, Dicke, Höhe, UK, (von, bis, UK, OK) × n]`.
|
||||
/// Flache Wand für die Bindung: `[sx, sy, ex, ey, Dicke, Höhe, UK, hatAnfang, px, py, dx, dy, hatEnde,
|
||||
/// px, py, dx, dy, (von, bis, UK, OK) × n]` (Schnittlinien [108]; ohne: Flag 0, Werte beliebig).
|
||||
pub fn wall_spec_flat(f: &[f64]) -> String {
|
||||
if f.len() < 7 || (f.len() - 7) % 4 != 0 {
|
||||
if f.len() < 17 || (f.len() - 17) % 4 != 0 || f.iter().any(|x| !x.is_finite()) {
|
||||
return String::new();
|
||||
}
|
||||
let holes: Vec<RHole> = f[7..].chunks_exact(4).map(|c| RHole { from: c[0], to: c[1], z_bottom: c[2], z_top: c[3] }).collect();
|
||||
let w = WallIn { start: [f[0], f[1]], end: [f[2], f[3]], thickness: f[4], height: f[5], base_elevation: f[6], holes: &holes };
|
||||
let cut = |i: usize| (f[i] != 0.0).then(|| [f[i + 1], f[i + 2], f[i + 3], f[i + 4]]);
|
||||
let holes: Vec<RHole> = f[17..].chunks_exact(4).map(|c| RHole { from: c[0], to: c[1], z_bottom: c[2], z_top: c[3] }).collect();
|
||||
let w = WallIn { start: [f[0], f[1]], end: [f[2], f[3]], thickness: f[4], height: f[5], base_elevation: f[6], holes: &holes, start_cut: cut(7), end_cut: cut(12) };
|
||||
wall_spec(&w).map_or_else(String::new, |v| v.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
|
||||
fn hole(from: f64, to: f64, zb: f64, zt: f64) -> RHole {
|
||||
@@ -329,9 +415,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn wand_spec_entartet_und_flach() {
|
||||
assert_eq!(wall_spec_flat(&[0.0, 0.0, 0.0, 0.0, 0.2, 2.5, 0.0]), "");
|
||||
let none = [0.0; 10];
|
||||
assert_eq!(wall_spec_flat(&[&[0.0, 0.0, 0.0, 0.0, 0.2, 2.5, 0.0], &none[..]].concat()), "");
|
||||
assert_eq!(wall_spec_flat(&[0.0, 0.0, 1.0]), "");
|
||||
let v: Value = serde_json::from_str(&wall_spec_flat(&[0.0, 0.0, 4.0, 0.0, 0.2, 2.5, 1.0])).unwrap();
|
||||
assert_eq!(wall_spec_flat(&[&[0.0, 0.0, 4.0, 0.0, 0.2, 2.5, f64::NAN], &none[..]].concat()), "");
|
||||
let v: Value = serde_json::from_str(&wall_spec_flat(&[&[0.0, 0.0, 4.0, 0.0, 0.2, 2.5, 1.0], &none[..]].concat())).unwrap();
|
||||
assert_eq!(v["kind"], "extrudePlane");
|
||||
assert_eq!(v["origin"], json!([0.0, 0.1, 1.0]));
|
||||
assert_eq!(v["depth"], json!(0.2));
|
||||
@@ -374,8 +462,9 @@ mod tests {
|
||||
let n_extrude = r.specs.iter().filter(|s| s["kind"] == "extrude").count();
|
||||
assert!(n_plane > 10, "Wandlagen + Dachflächen: {n_plane}");
|
||||
assert!(n_extrude > 1, "Decken + Körper");
|
||||
// Rückfall nur dort, wo der Entwurf einen Abzug trifft (Boolean-Spezifikation an dieser Stelle).
|
||||
assert!(r.fallbacks.iter().all(|(i, _)| r.specs[*i]["kind"] == "boolean"));
|
||||
// Rückfall nur dort, wo der Entwurf einen Abzug trifft (Boolean-Spezifikation an dieser Stelle),
|
||||
// oder für schräge Stirnflächen ([108]).
|
||||
assert!(r.fallbacks.iter().all(|(i, _)| r.specs[*i]["kind"] == "boolean" || r.specs[*i].get("pointsBack").is_some()));
|
||||
// Nur der additive Körper (k1) kommt dazu, der Abzugskörper (k2) nicht.
|
||||
let base: Project = serde_json::from_value(sample()).unwrap();
|
||||
let n0 = project_solid_specs(&base).unwrap().specs.len();
|
||||
@@ -391,8 +480,9 @@ mod tests {
|
||||
let r = project_solid_specs(&p).unwrap();
|
||||
assert!(!r.fallbacks.is_empty());
|
||||
for (i, base) in &r.fallbacks {
|
||||
assert_eq!(r.specs[*i]["kind"], "boolean");
|
||||
assert!(r.specs[*i]["kind"] == "boolean" || r.specs[*i].get("pointsBack").is_some());
|
||||
assert_ne!(base["kind"], "boolean");
|
||||
assert!(base.get("pointsBack").is_none());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,4 +496,96 @@ mod tests {
|
||||
assert_eq!(s["depth"], json!(-0.2));
|
||||
assert_eq!(s["vAxis"], json!([0.0, 1.0, 0.0]));
|
||||
}
|
||||
|
||||
/// [108] Schräges L (60°) aus zwei Wänden, 0.3 m dick, 2.5 m hoch, Achslängen 4 m und 3 m.
|
||||
pub(crate) fn schraeges_l() -> Project {
|
||||
serde_json::from_value(json!({
|
||||
"id": "p", "name": "t", "lineStyles": [], "hatches": [], "layers": [], "drawings2d": [],
|
||||
"wallTypes": [{"id": "aw", "name": "AW", "layers": [{"componentId": "c", "thickness": 0.3}]}], "components": [{"id": "c", "name": "C"}],
|
||||
"drawingLevels": [{"id": "F", "name": "EG", "kind": "floor", "visible": true, "locked": false, "floorHeight": 3.0, "baseElevation": 0}],
|
||||
"walls": [
|
||||
{"id": "A", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": 4, "y": 0}, "end": {"x": 0, "y": 0}, "height": 2.5, "wallTypeId": "aw"},
|
||||
{"id": "B", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": 0, "y": 0}, "end": {"x": 1.5, "y": 2.598076211353316}, "height": 2.5, "wallTypeId": "aw"}
|
||||
]
|
||||
}))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Grundriss eines Wand-Spec (`extrudePlane` mit senkrechter vAxis; mit `pointsBack` schräge Stirn):
|
||||
/// Fuss-Ecken vorne Anfang/Ende, hinten Ende/Anfang, plus Höhe.
|
||||
fn spec_footprint(s: &Value) -> (Vec<[f64; 2]>, f64) {
|
||||
let f = |v: &Value| v.as_f64().unwrap();
|
||||
assert_eq!(s["kind"], "extrudePlane");
|
||||
let o = [f(&s["origin"][0]), f(&s["origin"][1])];
|
||||
let u = [f(&s["uAxis"][0]), f(&s["uAxis"][1])];
|
||||
let d = f(&s["depth"]);
|
||||
let e = [u[1] * d, -u[0] * d];
|
||||
let ends = |k: &str| {
|
||||
let r: Vec<f64> = s[k].as_array().unwrap().iter().map(f).collect();
|
||||
let n = r.len() / 2;
|
||||
assert_eq!(r[2 * (n - 1)], r[0], "Anfang Fuss/Kopf gleich");
|
||||
(r[0], r[2 * (n - 3)])
|
||||
};
|
||||
let (fa, fb) = ends("points");
|
||||
let (ba, bb) = if s.get("pointsBack").is_some() { ends("pointsBack") } else { (fa, fb) };
|
||||
let pts: Vec<f64> = s["points"].as_array().unwrap().iter().map(f).collect();
|
||||
let h = pts.chunks(2).map(|c| c[1]).fold(0.0, f64::max);
|
||||
let at = |t: f64, k: f64| [o[0] + u[0] * t + e[0] * k, o[1] + u[1] * t + e[1] * k];
|
||||
(vec![at(fa, 0.0), at(fb, 0.0), at(bb, 1.0), at(ba, 1.0)], h)
|
||||
}
|
||||
|
||||
fn area(p: &[[f64; 2]]) -> f64 {
|
||||
(0..p.len()).map(|i| p[i][0] * p[(i + 1) % p.len()][1] - p[(i + 1) % p.len()][0] * p[i][1]).sum::<f64>().abs() / 2.0
|
||||
}
|
||||
|
||||
/// [108] Truck-Körper am schrägen L: Gehrung statt Quader; Volumen = Dicke × Höhe × (L1 + L2).
|
||||
#[test]
|
||||
fn schraeges_l_gehrung_im_truck_koerper() {
|
||||
let p = schraeges_l();
|
||||
let walls = crate::model3d::emit_walls(&p, true).unwrap();
|
||||
assert_eq!(walls.len(), 2);
|
||||
let mut vol = 0.0;
|
||||
for w in &walls {
|
||||
let s = wall_spec(&WallIn::of(w)).unwrap();
|
||||
assert!(s.get("pointsBack").is_some(), "{}: schräge Stirn", w.wall_id);
|
||||
let (fp, h) = spec_footprint(&s);
|
||||
// Gleiche Ecken wie der Kern-3D-Körper.
|
||||
for q in crate::model3d::wall_footprint(w).unwrap() {
|
||||
assert!(fp.iter().any(|c| (c[0] - q[0]).abs() < 1e-9 && (c[1] - q[1]).abs() < 1e-9), "{}: Ecke {q:?} fehlt in {fp:?}", w.wall_id);
|
||||
}
|
||||
assert!((area(&fp) * h - crate::model3d::wall_piece_volume(w)).abs() < 1e-9);
|
||||
vol += area(&fp) * h;
|
||||
}
|
||||
assert!((vol - 0.3 * 2.5 * 7.0).abs() < 1e-9, "{vol}");
|
||||
// STEP/Kennwerte: Rückfall rechtwinklig, falls truck am Keil scheitert.
|
||||
let specs = project_solid_specs(&p).unwrap();
|
||||
assert_eq!(specs.fallbacks.len(), 2);
|
||||
assert!(specs.fallbacks[0].1.get("pointsBack").is_none());
|
||||
// Flache Bindung: Schnittlinien übertragen.
|
||||
let w = &walls[0];
|
||||
let c = w.end_cut.unwrap();
|
||||
let flat = [w.start[0], w.start[1], w.end[0], w.end[1], w.thickness, w.height, w.base_elevation, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, c[0], c[1], c[2], c[3]];
|
||||
assert_eq!(serde_json::from_str::<Value>(&wall_spec_flat(&flat)).unwrap(), wall_spec(&WallIn::of(w)).unwrap());
|
||||
assert_eq!(wall_spec_flat(&flat[..7]), "");
|
||||
}
|
||||
|
||||
/// [108] Gehrung mit Fenster: Löcher bleiben an ihrer Achslage (Profil verschoben).
|
||||
#[test]
|
||||
fn gehrung_verschiebt_loecher_mit() {
|
||||
let holes = [RHole { from: 1.0, to: 2.0, z_bottom: 0.9, z_top: 2.1 }];
|
||||
// Wand entlang +x, Anfang mit Gehrung nach aussen: Kante +n endet bei u = −0.2.
|
||||
let w = WallIn { start: [0.0, 0.0], end: [4.0, 0.0], thickness: 0.2, height: 2.5, base_elevation: 0.0, holes: &holes, start_cut: Some([0.0, 0.0, -1.0, 1.0]), end_cut: None };
|
||||
let s = wall_spec(&w).unwrap();
|
||||
assert_eq!(s["origin"][0], json!(-0.1));
|
||||
assert_eq!(s["holes"][0], json!([1.1, 0.9, 2.1, 0.9, 2.1, 2.1, 1.1, 2.1]));
|
||||
// Vorne (+n) beginnt die Kante bei u = −0.1, hinten bei +0.1 (Profil ab −0.1).
|
||||
assert_eq!(s["points"][0], json!(0.0));
|
||||
assert_eq!(s["pointsBack"][0], json!(0.2));
|
||||
let (fp, _) = spec_footprint(&s);
|
||||
assert!((area(&fp) - 4.0 * 0.2).abs() < 1e-12);
|
||||
// Fenster in der Endzone: rechtwinklig wie bisher.
|
||||
let near = [RHole { from: 0.05, to: 1.0, z_bottom: 0.9, z_top: 2.1 }];
|
||||
let s = wall_spec(&WallIn { holes: &near, ..w }).unwrap();
|
||||
assert!(s.get("pointsBack").is_none() && s["origin"][0] == json!(0.0));
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,10 @@ pub enum SolidSpec {
|
||||
#[serde(rename = "vAxis")]
|
||||
v_axis: [f64; 3],
|
||||
depth: f64,
|
||||
/// Ring auf der Rückseite (nach `depth`), gleiche Punktzahl wie `points` ([108]: Wand mit
|
||||
/// schrägen Stirnflächen an Gehrung/schrägem Stoss). Leer = `points` (gerades Prisma).
|
||||
#[serde(default, rename = "pointsBack")]
|
||||
points_back: Vec<f64>,
|
||||
},
|
||||
/// Rotationskörper: Profil = geschlossener Ring aus (r, z)-Paaren in der
|
||||
/// Halbebene r ≥ 0, gedreht um die Z-Achse durch (cx, cy).
|
||||
@@ -318,6 +322,80 @@ fn extrude_plane(
|
||||
Ok(builder::tsweep(&face, dir))
|
||||
}
|
||||
|
||||
/// Wie [`extrude_plane`], aber mit eigenem Ring auf der Rückseite (gleiche Punktzahl, gleiche Löcher):
|
||||
/// Seitenflächen als Regelflächen zwischen entsprechenden Kanten (`try_wire_homotopy`, wie `loft`).
|
||||
/// Für Wände mit schrägen Stirnflächen ([108]) — ohne Boolean.
|
||||
fn extrude_plane_skew(
|
||||
points: &[f64],
|
||||
back: &[f64],
|
||||
holes: &[Vec<f64>],
|
||||
origin: [f64; 3],
|
||||
u: [f64; 3],
|
||||
v: [f64; 3],
|
||||
depth: f64,
|
||||
) -> Res<Solid> {
|
||||
if depth == 0.0 {
|
||||
return Err("depth darf nicht 0 sein".into());
|
||||
}
|
||||
let (uu, vv) = (Vector3::new(u[0], u[1], u[2]), Vector3::new(v[0], v[1], v[2]));
|
||||
let normal = uu.cross(vv);
|
||||
if normal.magnitude() < 1e-9 {
|
||||
return Err("uAxis und vAxis dürfen nicht parallel sein".into());
|
||||
}
|
||||
let o = Point3::new(origin[0], origin[1], origin[2]);
|
||||
let o2 = o + normal.normalize() * depth;
|
||||
let place = |r: &[(f64, f64)], at: Point3| -> Wire {
|
||||
let verts: Vec<Vertex> = r.iter().map(|&(a, b)| builder::vertex(at + uu * a + vv * b)).collect();
|
||||
let n = verts.len();
|
||||
(0..n).map(|i| builder::line(&verts[i], &verts[(i + 1) % n])).collect()
|
||||
};
|
||||
let mut front = pairs(points)?;
|
||||
let mut rear = pairs(back)?;
|
||||
if front.len() != rear.len() {
|
||||
return Err("pointsBack braucht dieselbe Punktanzahl wie points".into());
|
||||
}
|
||||
if signed_area(&front) < 0.0 {
|
||||
front.reverse();
|
||||
rear.reverse();
|
||||
}
|
||||
if signed_area(&rear) <= 0.0 {
|
||||
return Err("pointsBack ist entartet oder anders orientiert".into());
|
||||
}
|
||||
let mut pairs_w = vec![(place(&front, o), place(&rear, o2))];
|
||||
for h in holes {
|
||||
let mut hole = pairs(h)?;
|
||||
if signed_area(&hole) > 0.0 {
|
||||
hole.reverse();
|
||||
}
|
||||
pairs_w.push((place(&hole, o), place(&hole, o2)));
|
||||
}
|
||||
let mut shell = Shell::new();
|
||||
for (a, b) in &pairs_w {
|
||||
shell.extend(builder::try_wire_homotopy(a, b).map_err(|e| format!("{e}"))?);
|
||||
}
|
||||
let fw: Vec<Wire> = pairs_w.iter().map(|p| p.0.clone()).collect();
|
||||
let bw: Vec<Wire> = pairs_w.iter().map(|p| p.1.clone()).collect();
|
||||
let cap0 = builder::try_attach_plane(&fw).map_err(|e| format!("{e}"))?;
|
||||
let cap1 = builder::try_attach_plane(&bw).map_err(|e| format!("{e}"))?;
|
||||
// Orientierung wie in `loft`: eine Kappen-Kombination ergibt einen geschlossenen Rand.
|
||||
for (inv0, inv1) in [(true, false), (false, true), (false, false), (true, true)] {
|
||||
let mut sh = shell.clone();
|
||||
let (mut c0, mut c1) = (cap0.clone(), cap1.clone());
|
||||
if inv0 {
|
||||
c0.invert();
|
||||
}
|
||||
if inv1 {
|
||||
c1.invert();
|
||||
}
|
||||
sh.push(c0);
|
||||
sh.push(c1);
|
||||
if let Ok(s) = Solid::try_new(vec![sh]) {
|
||||
return Ok(s);
|
||||
}
|
||||
}
|
||||
Err("Wand mit schrägen Stirnflächen ergibt keinen geschlossenen Körper".into())
|
||||
}
|
||||
|
||||
fn revolve(profile: &[f64], cx: f64, cy: f64, angle_deg: f64) -> Res<Solid> {
|
||||
let ring = pairs(profile)?;
|
||||
if ring.iter().any(|&(r, _)| r < -1e-9) {
|
||||
@@ -486,8 +564,12 @@ pub fn build_solid(spec: &SolidSpec) -> Res<Solid> {
|
||||
SolidSpec::Extrude { points, holes, height, z0, corner_radius, chamfer } => {
|
||||
extrude(points, holes, *height, *z0, *corner_radius, *chamfer)
|
||||
}
|
||||
SolidSpec::ExtrudePlane { points, holes, origin, u_axis, v_axis, depth } => {
|
||||
extrude_plane(points, holes, *origin, *u_axis, *v_axis, *depth)
|
||||
SolidSpec::ExtrudePlane { points, holes, origin, u_axis, v_axis, depth, points_back } => {
|
||||
if points_back.is_empty() {
|
||||
extrude_plane(points, holes, *origin, *u_axis, *v_axis, *depth)
|
||||
} else {
|
||||
extrude_plane_skew(points, points_back, holes, *origin, *u_axis, *v_axis, *depth)
|
||||
}
|
||||
}
|
||||
SolidSpec::Revolve { profile, cx, cy, angle_deg } => revolve(profile, *cx, *cy, *angle_deg),
|
||||
SolidSpec::Loft { sections } => loft(sections),
|
||||
@@ -888,6 +970,32 @@ mod tests {
|
||||
.abs()
|
||||
}
|
||||
|
||||
/// [108] Wand mit schrägen Stirnflächen (`pointsBack`, wie `dossier-core::solid_specs::wall_spec`).
|
||||
#[test]
|
||||
fn wand_mit_schraegen_stirnflaechen() {
|
||||
// 45°-Gehrung am Anfang, Fenster 1 × 1.2: Grundfläche Trapez 4 × 0.2, minus Fenster.
|
||||
let spec: SolidSpec = serde_json::from_value(serde_json::json!({"kind": "extrudePlane",
|
||||
"points": [0.0, 0.0, 4.1, 0.0, 4.1, 2.5, 0.0, 2.5], "pointsBack": [0.2, 0.0, 4.1, 0.0, 4.1, 2.5, 0.2, 2.5],
|
||||
"holes": [[1.1, 0.9, 2.1, 0.9, 2.1, 2.1, 1.1, 2.1]], "origin": [-0.1, 0.1, 0.0], "uAxis": [1.0, 0.0, 0.0], "vAxis": [0.0, 0.0, 1.0], "depth": 0.2})).unwrap();
|
||||
let m = solid_mesh_core(&spec, 0.01).unwrap();
|
||||
assert!((volume(&m) - 1.76).abs() < 1e-6, "{}", volume(&m));
|
||||
let props = solid_props_core(&spec, 0.01).unwrap();
|
||||
assert!(props.closed && (props.volume - 1.76).abs() < 1e-6, "{:?}", props.volume);
|
||||
assert!(export_step_core(&[spec], &StepHeader::default()).is_ok());
|
||||
// Schräges L (60°): Wand (4,0)→(0,0), 0.3 dick, Gehrung am Ende; Volumen = 4 × 0.3 × 2.5.
|
||||
let e = 0.15 * 3f64.sqrt();
|
||||
let spec: SolidSpec = serde_json::from_value(serde_json::json!({"kind": "extrudePlane",
|
||||
"points": [0.0, 0.0, 4.0 - e, 0.0, 4.0 - e, 2.5, 0.0, 2.5], "pointsBack": [0.0, 0.0, 4.0 + e, 0.0, 4.0 + e, 2.5, 0.0, 2.5],
|
||||
"origin": [4.0, -0.15, 0.0], "uAxis": [-1.0, 0.0, 0.0], "vAxis": [0.0, 0.0, 1.0], "depth": 0.3})).unwrap();
|
||||
let props = solid_props_core(&spec, 0.01).unwrap();
|
||||
assert!(props.closed && (props.volume - 3.0).abs() < 1e-6, "{:?}", props.volume);
|
||||
// Ungleiche Punktzahl: Fehler statt Panic.
|
||||
let bad: SolidSpec = serde_json::from_value(serde_json::json!({"kind": "extrudePlane",
|
||||
"points": [0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0], "pointsBack": [0.0, 0.0, 1.0, 0.0, 1.0, 1.0],
|
||||
"origin": [0.0, 0.0, 0.0], "uAxis": [1.0, 0.0, 0.0], "vAxis": [0.0, 0.0, 1.0], "depth": 0.3})).unwrap();
|
||||
assert!(build_solid(&bad).is_err());
|
||||
}
|
||||
|
||||
fn ring(x0: f64, y0: f64, x1: f64, y1: f64) -> Vec<f64> {
|
||||
vec![x0, y0, x1, y0, x1, y1, x0, y1]
|
||||
}
|
||||
@@ -1049,6 +1157,7 @@ mod tests {
|
||||
u_axis: [1.0, 0.0, 0.0],
|
||||
v_axis: [0.0, 0.0, 1.0],
|
||||
depth: -0.3, // u×v = −Y; negativ ⇒ +Y
|
||||
points_back: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1102,7 +1211,7 @@ mod dbg_step {
|
||||
("torus", SolidSpec::Torus { center: [0.0; 3], major: 2.0, minor: 0.5 }),
|
||||
("revolve", SolidSpec::Revolve { profile: vec![0.0, 0.0, 1.0, 0.0, 1.0, 2.0, 0.0, 2.0], cx: 0.0, cy: 0.0, angle_deg: 360.0 }),
|
||||
("loft", SolidSpec::Loft { sections: vec![LoftSection { z: 0.0, points: ring(0.0, 0.0, 2.0, 2.0) }, LoftSection { z: 3.0, points: ring(0.5, 0.5, 1.5, 1.5) }] }),
|
||||
("wall_window", SolidSpec::ExtrudePlane { points: vec![0.0, 0.0, 5.0, 0.0, 5.0, 2.6, 0.0, 2.6], holes: vec![vec![1.0, 0.9, 2.2, 0.9, 2.2, 2.1, 1.0, 2.1]], origin: [0.0; 3], u_axis: [1.0, 0.0, 0.0], v_axis: [0.0, 0.0, 1.0], depth: -0.3 }),
|
||||
("wall_window", SolidSpec::ExtrudePlane { points: vec![0.0, 0.0, 5.0, 0.0, 5.0, 2.6, 0.0, 2.6], holes: vec![vec![1.0, 0.9, 2.2, 0.9, 2.2, 2.1, 1.0, 2.1]], origin: [0.0; 3], u_axis: [1.0, 0.0, 0.0], v_axis: [0.0, 0.0, 1.0], depth: -0.3, points_back: vec![] }),
|
||||
];
|
||||
for (name, spec) in cases {
|
||||
let step = export_step_core(&[spec], &StepHeader::default()).unwrap();
|
||||
|
||||
@@ -103,6 +103,8 @@ export type SolidSpec =
|
||||
uAxis: [number, number, number];
|
||||
vAxis: [number, number, number];
|
||||
depth: number;
|
||||
/** Ring auf der Rückseite (gleiche Punktzahl): schräge Stirnflächen an Gehrung/Stoss ([108]). */
|
||||
pointsBack?: number[];
|
||||
}
|
||||
| { kind: "revolve"; profile: number[]; cx?: number; cy?: number; angleDeg?: number }
|
||||
| { kind: "loft"; sections: LoftSectionSpec[] }
|
||||
|
||||
@@ -86,4 +86,18 @@ describe("STEP-Export Ende-zu-Ende (truck-WASM)", () => {
|
||||
const step: string = mod.export_step(JSON.stringify({ solids: bools, fileName: "void.stp" }));
|
||||
expect(step.startsWith("ISO-10303-21;")).toBe(true);
|
||||
}, 60_000);
|
||||
|
||||
it("[108] Wände an Ecken: schräge Stirnflächen (pointsBack) werden zu geschlossenen Körpern", async () => {
|
||||
const mod: any = await import("../engine/pkgTruck/trucksolid.js");
|
||||
await mod.default({ module_or_path: readFileSync("src/engine/pkgTruck/trucksolid_bg.wasm") });
|
||||
const skew = projectSolidSpecs(sampleProject).filter((s) => s.kind === "extrudePlane" && s.pointsBack);
|
||||
expect(skew.length).toBeGreaterThan(0);
|
||||
for (const spec of skew) {
|
||||
const props = JSON.parse(mod.solid_props(JSON.stringify({ spec })));
|
||||
expect(props.closed).toBe(true);
|
||||
expect(props.volume).toBeGreaterThan(0);
|
||||
}
|
||||
const step: string = mod.export_step(JSON.stringify({ solids: skew, fileName: "ecken.stp" }));
|
||||
expect(step).toContain("CLOSED_SHELL");
|
||||
}, 60_000);
|
||||
});
|
||||
@@ -158,6 +158,12 @@ export interface RWall {
|
||||
* der 3D-Live-Schnitt die Boolean-Dominanz + Fugenlinien wie der 2D-Schnitt macht.
|
||||
*/
|
||||
cut?: RCutMeta;
|
||||
/**
|
||||
* Schnittlinie `[px, py, dx, dy]` (Grundriss) am Anfang/Ende: Gehrung, T-Stoss-Fläche oder schräge
|
||||
* Aussparungs-Seite ([108], `RWall.startCut/endCut` im Kern).
|
||||
*/
|
||||
startCut?: [number, number, number, number];
|
||||
endCut?: [number, number, number, number];
|
||||
}
|
||||
|
||||
/** Eine extrudierte Deckenplatte: geschlossener Grundriss-Umriss + Z-Ausdehnung. */
|
||||
|
||||
@@ -7,11 +7,15 @@ import type { SolidSpec } from "../engine/truckSolid";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import type { RWall } from "./toWalls3d/shared";
|
||||
|
||||
type WallLike = Pick<RWall, "start" | "end" | "thickness" | "height" | "baseElevation" | "holes">;
|
||||
type WallLike = Pick<RWall, "start" | "end" | "thickness" | "height" | "baseElevation" | "holes" | "startCut" | "endCut">;
|
||||
|
||||
/** Wand als `extrudePlane` (Profil in der Wandebene, Tiefe = Dicke); null bei entarteter Wand. */
|
||||
/**
|
||||
* Wand als `extrudePlane` (Profil in der Wandebene, Tiefe = Dicke; mit Schnittlinien schräge
|
||||
* Stirnflächen über `pointsBack`, [108]); null bei entarteter Wand.
|
||||
*/
|
||||
export function wallSpec(w: WallLike): SolidSpec | null {
|
||||
const f = [w.start[0], w.start[1], w.end[0], w.end[1], w.thickness, w.height, w.baseElevation];
|
||||
for (const c of [w.startCut, w.endCut]) f.push(c ? 1 : 0, ...(c ?? [0, 0, 0, 0]));
|
||||
for (const h of w.holes ?? []) f.push(h.from, h.to, h.zBottom, h.zTop);
|
||||
const s = core().wall_spec_flat(Float64Array.from(f));
|
||||
return s ? (JSON.parse(s) as SolidSpec) : null;
|
||||
|
||||
Reference in new issue
Block a user