[128] Kern: Kollisions-Vorstufe (clash_broad) und projectSolidSpecs nach Rust
candidatePairs (Hüllquader-Paare) und projectSolidSpecs (Wände, Decken mit Abzug, Dachplatten, Körper) rechnen im Kern; TS nur noch Fassade. layoutModel.ts bleibt (Rechnung liegt schon im Kern). Griffe offen.
This commit is contained in:
10 files changed
+268
-108
No files matched your search
@@ -1103,8 +1103,14 @@ Prüfung des ganzen Programms (Rust-Kern, TS-Hülle, Build/Sicherheit), nur Code
|
||||
- ○ **[126] `jsnum`/`jsmath` ersetzen** (libm, deterministisch über Plattformen); `plan_*.rs`-Paare nach `plan/`
|
||||
zusammenführen. · M
|
||||
- ○ **[127] 3D-Booleans klären:** BSP in `fileio/csg.rs` stilllegen, Manifold vs. truck dokumentieren. · S
|
||||
- ○ **[128] Restlogik nach Rust:** Griffe (`useGripEditing.ts`), `layoutModel.ts`, Kollisions-Vorprüfung,
|
||||
- ◐ **[128] Restlogik nach Rust:** Griffe (`useGripEditing.ts`), `layoutModel.ts`, Kollisions-Vorprüfung,
|
||||
`exportStep.projectSolidSpecs`. · L
|
||||
3.11. Erledigt: Kollisions-Vorstufe (`clash_broad.rs`, Hüllquader-Paare als flacher Puffer; Feinprüfung bleibt in
|
||||
trucksolid) und `projectSolidSpecs` (`solid_specs::project_solid_specs`, Abfrage `projectSolidSpecs`: Wände, Decken
|
||||
samt Abzug, Dachplatten, Körper + Rückfall-Liste; TS nur noch Fassade). `layoutModel.ts`: Rechnung (Blattgrössen,
|
||||
Bäume, Löschen, Nachfahren, Ordner-PDF, Titelblock) lag schon im Kern ([K4] S3); der Rest sind Fabriken und
|
||||
Listen-`map`/`filter` ohne Logik — bewusst in TS gelassen. **Offen: Griffe** (`useGripEditing.ts`, anderer Agent).
|
||||
Geprüft: cargo test (Kern), vitest; nicht in der Tauri-App.
|
||||
- ✅ **[129] Grenze schärfen.** (3.11.) `i18n/translate.ts` (React-frei: `t`, Sprache, Wörterbücher), `i18n/index.ts` re-exportiert
|
||||
und hält nur `useT`; Kern-Dateien importieren `i18n/translate`. `net/` in `CORE_DIRS`, neuer Test prüft transitive
|
||||
relative Importe (Ausnahmelisten leer). · S
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
//! Kollisionsprüfung, Vorstufe ([128], vorher `candidatePairs` in `analysis/clash.ts`): welche Bauteil-Paare
|
||||
//! kommen für die genaue Prüfung (truck, `solid_clash`) in Frage. Nur Hüllquader (AABB) — die Feinprüfung bleibt
|
||||
//! in `trucksolid`. Wand↔Wand und Wand↔Decke greifen konstruktiv ineinander und werden gar nicht erst geprüft:
|
||||
//! mindestens ein Teil des Paars muss ein „freier" Körper sein.
|
||||
//!
|
||||
//! Kodierung (flach, `Float64Array`): je Bauteil 8 Werte `[frei (0/1), Gruppe, minx, miny, minz, maxx, maxy, maxz]`.
|
||||
//! Bauteile gleicher `Gruppe` (gleiche Ursprungs-id, z. B. mehrere Wandschichten) werden nicht gegeneinander
|
||||
//! geprüft. Ergebnis: `[i0, j0, i1, j1, …]` mit `i < j`, in Reihenfolge (i aussen, j innen).
|
||||
|
||||
/// Toleranz der Überlappung (m): bündige Flächen und Rundung zählen nicht.
|
||||
pub const EPS: f64 = 0.002;
|
||||
|
||||
const STRIDE: usize = 8;
|
||||
|
||||
fn overlaps(a: &[f64], b: &[f64]) -> bool {
|
||||
// a, b = [min3, max3]; Vergleiche wie in TS (NaN → false)
|
||||
(0..3).all(|k| a[k] < b[3 + k] - EPS && b[k] < a[3 + k] - EPS)
|
||||
}
|
||||
|
||||
/// Zu prüfende Paare (Indizes) aus dem flachen Puffer; ein kaputter Puffer (Länge kein Vielfaches von 8) ergibt `[]`.
|
||||
pub fn candidate_pairs(f: &[f64]) -> Vec<f64> {
|
||||
if f.len() % STRIDE != 0 {
|
||||
return Vec::new();
|
||||
}
|
||||
let items: Vec<&[f64]> = f.chunks_exact(STRIDE).collect();
|
||||
let mut out = Vec::new();
|
||||
for i in 0..items.len() {
|
||||
for j in (i + 1)..items.len() {
|
||||
let (a, b) = (items[i], items[j]);
|
||||
if a[0] == 0.0 && b[0] == 0.0 {
|
||||
continue;
|
||||
}
|
||||
if a[1] == b[1] {
|
||||
continue;
|
||||
}
|
||||
if overlaps(&a[2..8], &b[2..8]) {
|
||||
out.push(i as f64);
|
||||
out.push(j as f64);
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn item(free: bool, group: f64, x0: f64, x1: f64) -> [f64; 8] {
|
||||
[if free { 1.0 } else { 0.0 }, group, x0, 0.0, 0.0, x1, 1.0, 1.0]
|
||||
}
|
||||
|
||||
fn flat(items: &[[f64; 8]]) -> Vec<f64> {
|
||||
items.iter().flatten().copied().collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nur_paare_mit_freiem_koerper_und_ueberlappender_huelle() {
|
||||
let f = flat(&[item(false, 0.0, 0.0, 2.0), item(false, 1.0, 1.0, 3.0), item(true, 2.0, 1.5, 2.5), item(true, 3.0, 5.0, 6.0)]);
|
||||
assert_eq!(candidate_pairs(&f), vec![0.0, 2.0, 1.0, 2.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gleiche_gruppe_und_beruehrung_zaehlen_nicht() {
|
||||
let f = flat(&[item(true, 7.0, 0.0, 2.0), item(false, 7.0, 0.0, 2.0)]);
|
||||
assert!(candidate_pairs(&f).is_empty());
|
||||
// Überlappung unter EPS gilt als Berührung
|
||||
let g = flat(&[item(true, 0.0, 0.0, 1.0), item(true, 1.0, 0.999, 2.0)]);
|
||||
assert!(candidate_pairs(&g).is_empty());
|
||||
let h = flat(&[item(true, 0.0, 0.0, 1.0), item(true, 1.0, 0.99, 2.0)]);
|
||||
assert_eq!(candidate_pairs(&h), vec![0.0, 1.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kaputte_eingabe_und_nan() {
|
||||
assert!(candidate_pairs(&[1.0, 2.0, 3.0]).is_empty());
|
||||
assert!(candidate_pairs(&[]).is_empty());
|
||||
let mut a = item(true, 0.0, 0.0, 1.0);
|
||||
a[2] = f64::NAN;
|
||||
assert!(candidate_pairs(&flat(&[a, item(true, 1.0, 0.0, 1.0)])).is_empty());
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,7 @@ pub mod levels;
|
||||
pub mod pens;
|
||||
pub mod folder_tree;
|
||||
pub mod layout_model;
|
||||
pub mod clash_broad;
|
||||
pub mod sheet_viewports;
|
||||
pub mod parametric_walls;
|
||||
pub mod geo_translate;
|
||||
|
||||
@@ -61,6 +61,8 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
}
|
||||
json(&parts)
|
||||
}
|
||||
// STEP-Export: alle Bauteile als truck-Spezifikationen (`solid_specs::project_solid_specs`).
|
||||
("projectSolidSpecs", _) => json(&crate::solid_specs::project_solid_specs(p)?),
|
||||
// Gruppen ([K4] S3, `groups.rs`): `text` = Gruppen-id bzw. JSON der Argumente.
|
||||
("groupMembership", _) => json(&crate::groups::transitive_membership(p, text)),
|
||||
("containingGroup", _) => {
|
||||
|
||||
@@ -191,6 +191,102 @@ pub fn void_cuts(p: &Project, walls: &[RWall], slabs: &[RSlab]) -> VoidCuts {
|
||||
out
|
||||
}
|
||||
|
||||
/// Alle Bauteile des Projekts als B-Rep-Spezifikationen für den STEP-Export (früher `projectSolidSpecs` in
|
||||
/// `export/exportStep.ts`): Wände (je Materiallage) und Decken samt „Bauteil − Abzugskörper", Dachflächen als
|
||||
/// Platten der Gesamt-Schichtdicke, Extrusionskörper (ohne Abzugskörper). `fallbacks`: (Index in `specs`,
|
||||
/// Bauteil ohne Abzug) — scheitert truck am Boolean, exportiert TS das Bauteil ungeschnitten.
|
||||
#[derive(serde::Serialize, Default, Debug)]
|
||||
pub struct ProjectSpecs {
|
||||
pub specs: Vec<Value>,
|
||||
pub fallbacks: Vec<(usize, Value)>,
|
||||
}
|
||||
|
||||
type V3 = [f64; 3];
|
||||
fn sub3(a: V3, b: V3) -> V3 {
|
||||
[a[0] - b[0], a[1] - b[1], a[2] - b[2]]
|
||||
}
|
||||
fn dot3(a: V3, b: V3) -> f64 {
|
||||
a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
|
||||
}
|
||||
fn cross3(a: V3, b: V3) -> V3 {
|
||||
[a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]
|
||||
}
|
||||
|
||||
/// Platte einer ebenen Dachfläche (`pts` ≥ 3 Ecken) der Dicke `total` nach unten; `None` bei entarteter Fläche.
|
||||
fn roof_plane_spec(p: &[V3], total: f64) -> Option<Value> {
|
||||
if p.len() < 3 {
|
||||
return None;
|
||||
}
|
||||
let (e1, e2) = (sub3(p[1], p[0]), sub3(p[2], p[0]));
|
||||
let mut n = cross3(e1, e2);
|
||||
let nl = crate::jsmath::hypot(&n);
|
||||
if nl < EPS {
|
||||
return None;
|
||||
}
|
||||
n = [n[0] / nl, n[1] / nl, n[2] / nl];
|
||||
if n[2] < 0.0 {
|
||||
n = [-n[0], -n[1], -n[2]]; // Normale nach oben
|
||||
}
|
||||
let el = crate::jsmath::hypot(&e1);
|
||||
let u = [e1[0] / el, e1[1] / el, e1[2] / el];
|
||||
let v = cross3(n, u); // u × v = n
|
||||
let pts: Vec<f64> = p
|
||||
.iter()
|
||||
.flat_map(|q| {
|
||||
let d = sub3(*q, p[0]);
|
||||
[dot3(d, u), dot3(d, v)]
|
||||
})
|
||||
.collect();
|
||||
Some(json!({"kind": "extrudePlane", "points": pts, "origin": p[0], "uAxis": u, "vAxis": v, "depth": -total}))
|
||||
}
|
||||
|
||||
pub fn project_solid_specs(p: &Project) -> Result<ProjectSpecs, String> {
|
||||
let mut out = ProjectSpecs::default();
|
||||
// Detail „fein", geschichtete Wände.
|
||||
let parts = crate::model3d::parts(p, true, 2.0, false)?;
|
||||
let cuts = void_cuts(p, &parts.walls, &parts.slabs);
|
||||
let wall_cut: std::collections::HashMap<usize, Value> = cuts.walls.into_iter().collect();
|
||||
let slab_cut: std::collections::HashMap<usize, Value> = cuts.slabs.into_iter().collect();
|
||||
let push = |out: &mut ProjectSpecs, base: Value, cut: Option<&Value>| match cut {
|
||||
Some(c) => {
|
||||
out.fallbacks.push((out.specs.len(), base));
|
||||
out.specs.push(c.clone());
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
for (i, s) in parts.slabs.iter().enumerate() {
|
||||
if s.outline.len() < 3 || s.z_top - s.z_bottom < MIN_THICKNESS {
|
||||
continue;
|
||||
}
|
||||
let pts: Vec<f64> = s.outline.iter().flat_map(|q| [q[0], q[1]]).collect();
|
||||
push(&mut out, json!({"kind": "extrude", "points": pts, "height": s.z_top - s.z_bottom, "z0": s.z_bottom}), slab_cut.get(&i));
|
||||
}
|
||||
for roof in p.roofs.as_deref().unwrap_or(&[]) {
|
||||
let total: f64 = p.roof_layers(roof).iter().map(|l| max(0.0, l.thickness)).sum();
|
||||
if total < MIN_THICKNESS {
|
||||
continue;
|
||||
}
|
||||
let g = crate::roof::roof_geometry(&roof.params(), p.roof_base_elevation(roof));
|
||||
out.specs.extend(g.planes.iter().filter_map(|pl| roof_plane_spec(pl, total)));
|
||||
}
|
||||
for solid in p.extruded_solids.as_deref().unwrap_or(&[]) {
|
||||
if solid.operation.as_deref() == Some("subtract") {
|
||||
continue; // Abzugskörper sind kein Material
|
||||
}
|
||||
let base_z = if solid.level_id.is_empty() { 0.0 } else { p.floor(&solid.level_id).map_or(0.0, |f| f.base_elevation.unwrap_or(0.0)) };
|
||||
let v = serde_json::to_value(solid).map_err(|e| e.to_string())?;
|
||||
if let Some(spec) = crate::cmd_solid::extruded_solid_spec(&v, base_z) {
|
||||
out.specs.push(spec);
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Flache Wand für die Bindung: `[sx, sy, ex, ey, Dicke, Höhe, UK, (von, bis, UK, OK) × n]`.
|
||||
pub fn wall_spec_flat(f: &[f64]) -> String {
|
||||
if f.len() < 7 || (f.len() - 7) % 4 != 0 {
|
||||
@@ -249,4 +345,56 @@ mod tests {
|
||||
assert_eq!(spec["b"]["z0"], json!(p.floor("eg").and_then(|f| f.base_elevation).unwrap_or(0.0) + 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
fn sample() -> Value {
|
||||
serde_json::from_str(include_str!("../tests/fixtures/sample_project.json")).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn projekt_specs_wand_decke_dach_koerper() {
|
||||
let mut v = sample();
|
||||
v["extrudedSolids"] = json!([
|
||||
{"id": "k1", "type": "extrudedSolid", "levelId": "eg", "height": 1.0,
|
||||
"points": [{"x": 0.0, "y": 0.0}, {"x": 1.0, "y": 0.0}, {"x": 1.0, "y": 1.0}, {"x": 0.0, "y": 1.0}]},
|
||||
{"id": "k2", "type": "extrudedSolid", "levelId": "eg", "operation": "subtract", "height": 1.0,
|
||||
"points": [{"x": 0.0, "y": 0.0}, {"x": 1.0, "y": 0.0}, {"x": 1.0, "y": 1.0}, {"x": 0.0, "y": 1.0}]}
|
||||
]);
|
||||
let p: Project = serde_json::from_value(v).unwrap();
|
||||
let r = project_solid_specs(&p).unwrap();
|
||||
let n_plane = r.specs.iter().filter(|s| s["kind"] == "extrudePlane").count();
|
||||
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"));
|
||||
// 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();
|
||||
assert_eq!(r.specs.len(), n0 + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn projekt_specs_abzug_gibt_rueckfall_ohne_schnitt() {
|
||||
let mut v = sample();
|
||||
v["extrudedSolids"] = json!([{"id": "v1", "type": "extrudedSolid", "levelId": "eg", "operation": "subtract", "height": 1.0, "baseOffset": 1.0,
|
||||
"points": [{"x": -100.0, "y": -100.0}, {"x": 100.0, "y": -100.0}, {"x": 100.0, "y": 100.0}, {"x": -100.0, "y": 100.0}]}]);
|
||||
let p: Project = serde_json::from_value(v).unwrap();
|
||||
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_ne!(base["kind"], "boolean");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dachflaeche_entartet_gibt_keine_platte() {
|
||||
let line: Vec<V3> = vec![[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [2.0, 0.0, 0.0]];
|
||||
assert!(roof_plane_spec(&line, 0.2).is_none());
|
||||
assert!(roof_plane_spec(&line[..2], 0.2).is_none());
|
||||
let tri: Vec<V3> = vec![[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]];
|
||||
let s = roof_plane_spec(&tri, 0.2).unwrap();
|
||||
assert_eq!(s["depth"], json!(-0.2));
|
||||
assert_eq!(s["vAxis"], json!([0.0, 1.0, 0.0]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
//! Bindung der Kollisions-Vorstufe (`crate::clash_broad`): Hüllquader-Paare als flache Puffer.
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// Kandidaten-Paare `[i0, j0, …]` aus Bauteil-Hüllen (`[frei, Gruppe, min3, max3]` je Bauteil, s. `clash_broad.rs`).
|
||||
#[wasm_bindgen]
|
||||
pub fn clash_candidate_pairs(items: &[f64]) -> Vec<f64> {
|
||||
crate::clash_broad::candidate_pairs(items)
|
||||
}
|
||||
@@ -33,6 +33,7 @@ mod plan_print_svg;
|
||||
mod layers;
|
||||
mod pens;
|
||||
mod layout_model;
|
||||
mod clash_broad;
|
||||
mod parametric_walls;
|
||||
mod reorder;
|
||||
mod text_layout;
|
||||
|
||||
+13
-13
@@ -3,6 +3,8 @@
|
||||
// (Wandschichten, Decken, andere Körper). Wand↔Wand und Wand↔Decke werden NICHT geprüft —
|
||||
// sie greifen konstruktiv ineinander (Gehrungen, Auflager) und wären reine Falschmeldungen.
|
||||
//
|
||||
// Vorstufe (Hüllquader-Paare) im Rust-Kern (`clash_broad.rs`), Feinprüfung in trucksolid.
|
||||
//
|
||||
// Ergebnis: je Kollision ein Paar + Durchdringungsvolumen + Mittelpunkt. `clashMarkers`
|
||||
// macht daraus rote Markierungen (Kreis + Text, nicht druckend) auf dem passenden Geschoss.
|
||||
|
||||
@@ -13,6 +15,7 @@ import { getFloor } from "../model/types";
|
||||
import { projectToModel3d } from "../plan/toWalls3d";
|
||||
import { extrudedSolidSpec } from "../plan/extrudedSolidSpec";
|
||||
import { wallSpec } from "../plan/wallSpec";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { solidClash, solidProps } from "../engine/truckSolid";
|
||||
import type { SolidSpec } from "../engine/truckSolid";
|
||||
|
||||
@@ -80,21 +83,18 @@ export function clashItems(project: Project): ClashItem[] {
|
||||
|
||||
type Box = { min: [number, number, number]; max: [number, number, number] };
|
||||
|
||||
const overlaps = (a: Box, b: Box, eps = 0.002): boolean =>
|
||||
a.min[0] < b.max[0] - eps && b.min[0] < a.max[0] - eps &&
|
||||
a.min[1] < b.max[1] - eps && b.min[1] < a.max[1] - eps &&
|
||||
a.min[2] < b.max[2] - eps && b.min[2] < a.max[2] - eps;
|
||||
|
||||
/** Zu prüfende Paare: mindestens ein freier Körper, Hüllquader überlappen (reiner Kern). */
|
||||
/** Zu prüfende Paare: mindestens ein freier Körper, Hüllquader überlappen (Rust-Kern, `clash_broad.rs`). */
|
||||
export function candidatePairs(items: ClashItem[], boxes: Box[]): Array<[number, number]> {
|
||||
const groups = new Map<string, number>();
|
||||
const flat = new Float64Array(items.length * 8);
|
||||
items.forEach((it, i) => {
|
||||
const g = groups.get(it.id) ?? groups.size;
|
||||
groups.set(it.id, g);
|
||||
flat.set([FREE.has(it.kind) ? 1 : 0, g, ...boxes[i].min, ...boxes[i].max], i * 8);
|
||||
});
|
||||
const out = core().clash_candidate_pairs(flat);
|
||||
const pairs: Array<[number, number]> = [];
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
for (let j = i + 1; j < items.length; j++) {
|
||||
if (!FREE.has(items[i].kind) && !FREE.has(items[j].kind)) continue;
|
||||
if (items[i].id === items[j].id) continue;
|
||||
if (overlaps(boxes[i], boxes[j])) pairs.push([i, j]);
|
||||
}
|
||||
}
|
||||
for (let k = 0; k < out.length; k += 2) pairs.push([out[k], out[k + 1]]);
|
||||
return pairs;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ export type QueryName =
|
||||
| "scheduleCsv"
|
||||
| "pickGeometry"
|
||||
| "model3dParts"
|
||||
| "projectSolidSpecs"
|
||||
| "planDomains"
|
||||
| "ifcExportData"
|
||||
| "meshExportData"
|
||||
|
||||
@@ -14,115 +14,25 @@
|
||||
// Koordinaten: Modell-Meter, X/Y = Grundriss, Z = Höhe (wie die Eingabe von render3d).
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import { getFloor, roofLayers } from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
import type { RSlab, RWall } from "../plan/toWalls3d/shared";
|
||||
import type { VoidCuts } from "../plan/toWalls3d/voids3d";
|
||||
import { roofBaseElevation, roofGeometry } from "../geometry/roof";
|
||||
import { exportStepSolids } from "../engine/truckSolid";
|
||||
import { extrudedSolidSpec } from "../plan/extrudedSolidSpec";
|
||||
import type { SolidSpec } from "../engine/truckSolid";
|
||||
import { wallSpec } from "../plan/wallSpec";
|
||||
|
||||
export { wallProfile, wallSpec } from "../plan/wallSpec";
|
||||
|
||||
const EPS = 1e-6;
|
||||
/** Schicht/Öffnung so dünn, dass sie als nicht vorhanden gilt. */
|
||||
const MIN_THICKNESS = 1e-4;
|
||||
|
||||
/**
|
||||
* Boolean-Spezifikation (Bauteil − Abzugskörper) → dieselbe ohne Abzug. Scheitert truck am
|
||||
* Boolean, exportiert `exportProjectStep` das Bauteil wenigstens ungeschnitten.
|
||||
*/
|
||||
const VOID_FALLBACK = new WeakMap<SolidSpec, SolidSpec>();
|
||||
|
||||
/** Alle Bauteile des Projekts als B-Rep-Spezifikationen (reiner Kern, kein WASM). */
|
||||
/** Alle Bauteile des Projekts als B-Rep-Spezifikationen (Rust-Kern, `solid_specs.rs::project_solid_specs`; kein truck-WASM). */
|
||||
export function projectSolidSpecs(project: Project): SolidSpec[] {
|
||||
const out: SolidSpec[] = [];
|
||||
// Wände und Decken samt „Bauteil − Abzugskörper" aus dem Kern (`solid_specs.rs`, Abfrage `model3dParts` mit
|
||||
// Abzugskörpern): Detail „fein" (2), geschichtete Wände.
|
||||
const model = documentFor(project).query<{ walls: RWall[]; slabs: RSlab[]; voidCuts?: VoidCuts }>("model3dParts", [1, 2, 0, 1]);
|
||||
const wallCut = new Map(model.voidCuts?.walls ?? []);
|
||||
const slabCut = new Map(model.voidCuts?.slabs ?? []);
|
||||
const withCut = (base: SolidSpec, cut: SolidSpec | undefined): SolidSpec => {
|
||||
if (!cut) return base;
|
||||
VOID_FALLBACK.set(cut, base);
|
||||
return cut;
|
||||
};
|
||||
|
||||
model.walls.forEach((w, i) => {
|
||||
const s = wallSpec(w);
|
||||
if (s) out.push(withCut(s, wallCut.get(i)));
|
||||
});
|
||||
|
||||
model.slabs.forEach((s, i) => {
|
||||
if (s.outline.length < 3 || s.zTop - s.zBottom < MIN_THICKNESS) return;
|
||||
const base: SolidSpec = {
|
||||
kind: "extrude",
|
||||
points: s.outline.flatMap((p) => [p[0], p[1]]),
|
||||
height: s.zTop - s.zBottom,
|
||||
z0: s.zBottom,
|
||||
};
|
||||
out.push(withCut(base, slabCut.get(i)));
|
||||
});
|
||||
|
||||
for (const roof of project.roofs ?? []) {
|
||||
const total = roofLayers(project, roof).reduce((sum, l) => sum + Math.max(0, l.thickness), 0);
|
||||
if (total < MIN_THICKNESS) continue;
|
||||
const g = roofGeometry(roof, roofBaseElevation(project, roof));
|
||||
for (const pl of g.planes) {
|
||||
const p = pl.pts;
|
||||
if (p.length < 3) continue;
|
||||
// Lokales Koordinatensystem der (ebenen, konvexen) Dachfläche.
|
||||
const e1 = sub(p[1], p[0]);
|
||||
const e2 = sub(p[2], p[0]);
|
||||
let n = cross(e1, e2);
|
||||
const nl = Math.hypot(n[0], n[1], n[2]);
|
||||
if (nl < EPS) continue;
|
||||
n = [n[0] / nl, n[1] / nl, n[2] / nl];
|
||||
if (n[2] < 0) n = [-n[0], -n[1], -n[2]]; // Normale nach oben
|
||||
const el = Math.hypot(e1[0], e1[1], e1[2]);
|
||||
const u: [number, number, number] = [e1[0] / el, e1[1] / el, e1[2] / el];
|
||||
const v = cross(n, u); // u × v = n
|
||||
out.push({
|
||||
kind: "extrudePlane",
|
||||
points: p.flatMap((q) => {
|
||||
const d = sub(q, p[0]);
|
||||
return [dot(d, u), dot(d, v)];
|
||||
}),
|
||||
origin: [p[0][0], p[0][1], p[0][2]],
|
||||
uAxis: u,
|
||||
vAxis: [v[0], v[1], v[2]],
|
||||
depth: -total, // nach unten (Eindeckung oben)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const solid of project.extrudedSolids ?? []) {
|
||||
if (solid.operation === "subtract") continue; // Abzugskörper sind kein Material
|
||||
let baseZ = 0;
|
||||
if (solid.levelId) {
|
||||
try {
|
||||
baseZ = getFloor(project, solid.levelId).baseElevation ?? 0;
|
||||
} catch {
|
||||
baseZ = 0;
|
||||
}
|
||||
}
|
||||
const spec = extrudedSolidSpec(solid, baseZ);
|
||||
if (spec) out.push(spec);
|
||||
}
|
||||
return out;
|
||||
const r = documentFor(project).query<{ specs: SolidSpec[]; fallbacks: [number, SolidSpec][] }>("projectSolidSpecs", []);
|
||||
for (const [i, base] of r.fallbacks) VOID_FALLBACK.set(r.specs[i], base);
|
||||
return r.specs;
|
||||
}
|
||||
|
||||
type V3 = [number, number, number];
|
||||
const sub = (a: ArrayLike<number>, b: ArrayLike<number>): V3 => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
||||
const dot = (a: ArrayLike<number>, b: ArrayLike<number>): number => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
||||
const cross = (a: ArrayLike<number>, b: ArrayLike<number>): V3 => [
|
||||
a[1] * b[2] - a[2] * b[1],
|
||||
a[2] * b[0] - a[0] * b[2],
|
||||
a[0] * b[1] - a[1] * b[0],
|
||||
];
|
||||
|
||||
/** Ergebnis des Projekt-Exports. */
|
||||
export interface StepExportResult {
|
||||
text: string;
|
||||
|
||||
Reference in new issue
Block a user