Merge github/master
This commit is contained in:
commit
a211cad7cc
16 files changed
+60
-1259
No files matched your search
@@ -141,6 +141,11 @@ truck (`trucksolid`) bleibt eigenes WASM-Modul (Panic-Isolation), wird vom Kern
|
||||
Pick-Geometrie und 2D-Boden-Spuren im 3D ebenfalls im Kern. **IFC-Export** (`export_ifc.rs`, `js_fmt.rs` für JS-`toFixed`, `geo_rebase.rs`)
|
||||
byte-genau zur TS-Fassung (Vergleich über Zufallsprojekte; das Salz der GUID-Ableitung beginnt mit U+0001 — so seit jeher, bleibt für
|
||||
stabile GUIDs). Modell verlustfrei (`Extra`-Felder), typisierte Sicht wird nach Ops feldweise nachgeführt.
|
||||
**Zusammenführung 28.10. (Cloud):** Der IFC- und OBJ/STL-Export liefen parallel auch in `src-tauri/fileio` weiter
|
||||
([B5]/[C11]: IFC2x3, Basismengen, Öffnungen, Zonen, Klassifikation, glTF …). Behalten ist die `fileio`-Fassung; die
|
||||
Kern-Duplikate `export_ifc.rs`, `export_mesh.rs`, `geo_rebase.rs`, `web/export_ifc.rs`, `doc_export_ifc` und die
|
||||
Abfragen `objFile`/`stlFile` sind gelöscht. Die Exporte holen ihre 3D-Teile über `export/model3dParts.ts` aus dem
|
||||
Dokument (`queries.rs`). Offen: `fileio`-Schreiber direkt aus dem Dokument füttern statt über den TS-Sammler.
|
||||
Nächste: Export (Schedule/CSV, STL/OBJ, STEP), Plan/Schnitt/Ansicht-Sammler (generatePlan, toSection, toElevation) — hängt an Plan-Puffer v2.
|
||||
Ziel: Plan/Schnitt/Ansicht, 3D, Export rechnen mit `doc`-Handle statt flach gesammelter Arrays; TS-Sammler/-Adapter werden gelöscht
|
||||
([K3d] hängt hier dran: Plan-Puffer v2 mit Pick-IDs und vollem Primitive-Umfang).
|
||||
|
||||
@@ -1,759 +0,0 @@
|
||||
//! IFC4-Export (STEP Physical File, ISO-10303-21) des Modells ([K4] S2, vorher
|
||||
//! `src/export/exportIfc.ts`): Project → Site → Building → Storeys; Wände als öffnungsgenaue
|
||||
//! Dreiecks-Netze (gleicher Loch-Ausschnitt wie STL/OBJ), Decken/Treppen/Körper/Stützen/Räume als
|
||||
//! Profil-Extrusionen, Dächer als Schicht-Netze, Wand-/Deckentypen mit Materialschichten.
|
||||
//! GUIDs deterministisch aus der Element-ID (zwei FNV-1a-64-Läufe, IFC-Base64-Kompression).
|
||||
//! Geometrie in realen Weltkoordinaten (LV95), wenn `geoAnchor` gesetzt ist. Einheit: Meter.
|
||||
//! Byte-genau wie die TS-Fassung (Zahlenformat über [`crate::js_fmt::to_fixed`]).
|
||||
|
||||
use crate::geo_rebase::project_to_world_coords;
|
||||
use crate::js_fmt::to_fixed;
|
||||
use crate::model::*;
|
||||
use crate::model3d;
|
||||
use crate::wall_mesh_cut::{is_watertight, wall_cut_mesh, CutWall};
|
||||
use std::collections::HashMap;
|
||||
|
||||
// ── IFC-GUID ────────────────────────────────────────────────────────────────
|
||||
|
||||
const IFC_GUID_CHARS: &[u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$";
|
||||
|
||||
fn guid_b64(v: u64, len: usize) -> String {
|
||||
(0..len).rev().map(|i| IFC_GUID_CHARS[((v / 64u64.pow(i as u32)) % 64) as usize] as char).collect()
|
||||
}
|
||||
|
||||
fn compress_guid(bytes: [u8; 16]) -> String {
|
||||
let mut out = guid_b64(bytes[0] as u64, 2);
|
||||
let mut i = 1;
|
||||
while i < 16 {
|
||||
let v = ((bytes[i] as u64) << 16) + ((bytes[i + 1] as u64) << 8) + bytes[i + 2] as u64;
|
||||
out.push_str(&guid_b64(v, 4));
|
||||
i += 3;
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn fnv1a64(s: &str, seed: u64) -> u64 {
|
||||
let mut hash = seed;
|
||||
// Wie TS: über UTF-16-Code-Einheiten (`charCodeAt`).
|
||||
for u in s.encode_utf16() {
|
||||
hash ^= u as u64;
|
||||
hash = hash.wrapping_mul(0x100000001b3);
|
||||
}
|
||||
hash
|
||||
}
|
||||
|
||||
/// Deterministische 22-stellige IFC-GUID aus einer beliebigen Element-ID.
|
||||
pub fn ifc_guid(id: &str) -> String {
|
||||
let h1 = fnv1a64(id, 0xcbf29ce484222325);
|
||||
// Das Salz beginnt mit U+0001 (so steht es seit jeher in der TS-Fassung); beibehalten, damit
|
||||
// GUIDs über Re-Exporte und Versionen stabil bleiben.
|
||||
let h2 = fnv1a64(&format!("{id}\u{1}salt"), 0x9e3779b97f4a7c15);
|
||||
let mut bytes = [0u8; 16];
|
||||
bytes[..8].copy_from_slice(&h1.to_be_bytes());
|
||||
bytes[8..].copy_from_slice(&h2.to_be_bytes());
|
||||
compress_guid(bytes)
|
||||
}
|
||||
|
||||
// ── STEP-Formatierung ───────────────────────────────────────────────────────
|
||||
|
||||
/// STEP-String-Literal: druckbares ASCII bleibt, `\` und `'` werden verdoppelt, alles andere als
|
||||
/// `\X2\HHHH…\X0\` (BMP) bzw. `\X4\HHHHHHHH…\X0\`.
|
||||
pub fn ifc_string(s: &str) -> String {
|
||||
let mut out = String::new();
|
||||
let mut run: Vec<u32> = Vec::new();
|
||||
fn flush(out: &mut String, run: &mut Vec<u32>) {
|
||||
if run.is_empty() {
|
||||
return;
|
||||
}
|
||||
let wide = run.iter().any(|&c| c > 0xffff);
|
||||
let hex: String = run.iter().map(|c| if wide { format!("{c:08X}") } else { format!("{c:04X}") }).collect();
|
||||
out.push_str(if wide { "\\X4\\" } else { "\\X2\\" });
|
||||
out.push_str(&hex);
|
||||
out.push_str("\\X0\\");
|
||||
run.clear();
|
||||
}
|
||||
for ch in s.chars() {
|
||||
let c = ch as u32;
|
||||
if (0x20..=0x7e).contains(&c) {
|
||||
flush(&mut out, &mut run);
|
||||
match ch {
|
||||
'\\' => out.push_str("\\\\"),
|
||||
'\'' => out.push_str("''"),
|
||||
_ => out.push(ch),
|
||||
}
|
||||
} else {
|
||||
if !run.is_empty() && (run[0] > 0xffff) != (c > 0xffff) {
|
||||
flush(&mut out, &mut run);
|
||||
}
|
||||
run.push(c);
|
||||
}
|
||||
}
|
||||
flush(&mut out, &mut run);
|
||||
format!("'{out}'")
|
||||
}
|
||||
|
||||
fn s(x: &str) -> String {
|
||||
ifc_string(x)
|
||||
}
|
||||
|
||||
/// STEP-REAL — immer mit Dezimalpunkt, ohne unnötige Nachkommastellen.
|
||||
fn r(x: f64) -> String {
|
||||
let v = if x == 0.0 { 0.0 } else { x };
|
||||
let mut t = to_fixed(v, 6);
|
||||
let trimmed = t.trim_end_matches('0').len();
|
||||
t.truncate(trimmed);
|
||||
if t.ends_with('.') {
|
||||
t.push('0');
|
||||
}
|
||||
if !t.contains('.') {
|
||||
t.push_str(".0");
|
||||
}
|
||||
t
|
||||
}
|
||||
|
||||
fn en(v: &str) -> String {
|
||||
format!(".{v}.")
|
||||
}
|
||||
|
||||
fn list(items: &[String]) -> String {
|
||||
format!("({})", items.join(","))
|
||||
}
|
||||
|
||||
fn refs(ids: &[usize]) -> String {
|
||||
list(&ids.iter().map(|i| format!("#{i}")).collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
struct StepWriter {
|
||||
lines: Vec<String>,
|
||||
next_id: usize,
|
||||
}
|
||||
|
||||
impl StepWriter {
|
||||
fn add(&mut self, ty: &str, params: String) -> usize {
|
||||
let id = self.next_id;
|
||||
self.next_id += 1;
|
||||
self.lines.push(format!("#{id}={ty}({params});"));
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
// ── Geometrie-Helfer ────────────────────────────────────────────────────────
|
||||
|
||||
fn normalize(v: Vec2) -> Vec2 {
|
||||
let len = crate::jsmath::hypot2(v.x, v.y);
|
||||
let len = if len == 0.0 || len.is_nan() { 1.0 } else { len };
|
||||
Vec2 { x: v.x / len, y: v.y / len }
|
||||
}
|
||||
|
||||
fn left_normal(u: Vec2) -> Vec2 {
|
||||
Vec2 { x: -u.y, y: u.x }
|
||||
}
|
||||
|
||||
fn add_scaled(p: Vec2, d: Vec2, k: f64) -> Vec2 {
|
||||
Vec2 { x: p.x + d.x * k, y: p.y + d.y * k }
|
||||
}
|
||||
|
||||
/// Rechteck-Footprint einer Öffnung im Wandloch (volle Wanddicke tief), CCW.
|
||||
fn opening_footprint(p: &Project, wall: &Wall, o: &Opening) -> Vec<Vec2> {
|
||||
let u = normalize(Vec2 { x: wall.end.x - wall.start.x, y: wall.end.y - wall.start.y });
|
||||
let n = left_normal(u);
|
||||
let t = p.wall_type(wall).map_or(0.0, |wt| Project::type_thickness(&wt.layers));
|
||||
let off = crate::joins::reference_offset(model3d_reference(wall), t);
|
||||
let inner = -t / 2.0 + off;
|
||||
let outer = t / 2.0 + off;
|
||||
let a = add_scaled(wall.start, u, o.position);
|
||||
let b = add_scaled(wall.start, u, o.position + o.width);
|
||||
vec![add_scaled(a, n, inner), add_scaled(b, n, inner), add_scaled(b, n, outer), add_scaled(a, n, outer)]
|
||||
}
|
||||
|
||||
fn model3d_reference(w: &Wall) -> crate::joins::Reference {
|
||||
use crate::joins::Reference;
|
||||
match (w.reference_offset, w.reference_line) {
|
||||
(Some(v), _) => Reference::Offset(v),
|
||||
(None, Some(WallReferenceLine::Left)) => Reference::Left,
|
||||
(None, Some(WallReferenceLine::Right)) => Reference::Right,
|
||||
_ => Reference::Center,
|
||||
}
|
||||
}
|
||||
|
||||
/// Vereinfachter Bounding-Footprint einer Treppe (Lauf-Rechteck bzw. Box der Kontrollpunkte).
|
||||
fn stair_footprint(st: &Stair) -> Vec<Vec2> {
|
||||
let half_w = st.width.max(0.0) / 2.0;
|
||||
if st.shape == StairShape::Straight {
|
||||
let u = normalize(st.dir);
|
||||
let n = left_normal(u);
|
||||
let end = add_scaled(st.start, u, st.run_length);
|
||||
return vec![add_scaled(st.start, n, -half_w), add_scaled(end, n, -half_w), add_scaled(end, n, half_w), add_scaled(st.start, n, half_w)];
|
||||
}
|
||||
let mut pts = vec![st.start];
|
||||
let u = normalize(st.dir);
|
||||
let corner = add_scaled(st.start, u, st.run_length);
|
||||
pts.push(corner);
|
||||
if st.shape == StairShape::L {
|
||||
if let (Some(run2), Some(turn)) = (st.run2_length.filter(|v| *v != 0.0), st.turn.filter(|v| *v != 0.0)) {
|
||||
let n = left_normal(u);
|
||||
let turn_dir = Vec2 { x: n.x * turn, y: n.y * turn };
|
||||
pts.push(add_scaled(corner, turn_dir, run2));
|
||||
}
|
||||
}
|
||||
if st.shape == StairShape::Spiral {
|
||||
if let Some(c) = st.center {
|
||||
let rr = st.radius.unwrap_or(0.0) + half_w;
|
||||
return vec![
|
||||
Vec2 { x: c.x - rr, y: c.y - rr },
|
||||
Vec2 { x: c.x + rr, y: c.y - rr },
|
||||
Vec2 { x: c.x + rr, y: c.y + rr },
|
||||
Vec2 { x: c.x - rr, y: c.y + rr },
|
||||
];
|
||||
}
|
||||
}
|
||||
let (mut min_x, mut min_y, mut max_x, mut max_y) = (f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY);
|
||||
for q in &pts {
|
||||
min_x = min_x.min(q.x);
|
||||
min_y = min_y.min(q.y);
|
||||
max_x = max_x.max(q.x);
|
||||
max_y = max_y.max(q.y);
|
||||
}
|
||||
min_x -= half_w;
|
||||
min_y -= half_w;
|
||||
max_x += half_w;
|
||||
max_y += half_w;
|
||||
vec![Vec2 { x: min_x, y: min_y }, Vec2 { x: max_x, y: min_y }, Vec2 { x: max_x, y: max_y }, Vec2 { x: min_x, y: max_y }]
|
||||
}
|
||||
|
||||
fn opening_label(o: &Opening) -> String {
|
||||
format!("{} {}×{}", if o.kind == ElementKind::Door { "Tür" } else { "Fenster" }, to_fixed(o.width * 100.0, 0), to_fixed(o.height * 100.0, 0))
|
||||
}
|
||||
|
||||
fn column_label(c: &Column) -> String {
|
||||
match &c.profile {
|
||||
ColumnProfile::Round { radius } => format!("Stütze Ø{}", to_fixed(radius * 200.0, 0)),
|
||||
ColumnProfile::Rect { width, depth } => format!("Stütze {}×{}", to_fixed(width * 100.0, 0), to_fixed(depth * 100.0, 0)),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct Structure {
|
||||
entity_id: usize,
|
||||
placement_id: usize,
|
||||
base_elevation: f64,
|
||||
}
|
||||
|
||||
struct ElementTypeRef {
|
||||
type_id: usize,
|
||||
occurrences: Vec<usize>,
|
||||
}
|
||||
|
||||
/// Unix-Sekunden/ISO-Zeit aus Millisekunden seit 1970 (UTC), wie `Date.now()` / `toISOString()`.
|
||||
fn iso_from_ms(ms: f64) -> String {
|
||||
let secs = (ms / 1000.0).floor() as i64;
|
||||
let days = secs.div_euclid(86_400);
|
||||
let tod = secs.rem_euclid(86_400);
|
||||
// Zivildatum aus Tagen (Howard Hinnant).
|
||||
let z = days + 719_468;
|
||||
let era = z.div_euclid(146_097);
|
||||
let doe = z.rem_euclid(146_097);
|
||||
let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365;
|
||||
let y = yoe + era * 400;
|
||||
let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
|
||||
let mp = (5 * doy + 2) / 153;
|
||||
let d = doy - (153 * mp + 2) / 5 + 1;
|
||||
let m = if mp < 10 { mp + 3 } else { mp - 9 };
|
||||
let y = if m <= 2 { y + 1 } else { y };
|
||||
format!("{y:04}-{m:02}-{d:02}T{:02}:{:02}:{:02}", tod / 3600, (tod % 3600) / 60, tod % 60)
|
||||
}
|
||||
|
||||
/// Baut aus einem Projekt einen vollständigen IFC4-SPF-String. `now_ms`: Zeitpunkt des Exports
|
||||
/// (ms seit 1970). Leeres Projekt ⇒ valider Minimal-IFC. `Err`: das Modell lässt sich nicht
|
||||
/// ableiten (z. B. unbekannter Wandtyp bei der Verschneidung).
|
||||
pub fn export_ifc_spf(project_in: &Project, now_ms: f64) -> Result<String, String> {
|
||||
let project = project_to_world_coords(project_in);
|
||||
let p = &project;
|
||||
let mut w = StepWriter { lines: Vec::new(), next_id: 1 };
|
||||
|
||||
let origin_point = w.add("IFCCARTESIANPOINT", list(&[r(0.0), r(0.0), r(0.0)]));
|
||||
let extrude_dir = w.add("IFCDIRECTION", list(&[r(0.0), r(0.0), r(1.0)]));
|
||||
let identity_axis = w.add("IFCAXIS2PLACEMENT3D", format!("#{origin_point},$,$"));
|
||||
|
||||
let org = w.add("IFCORGANIZATION", format!("$,{},$,$,$", s("dossier")));
|
||||
let person = w.add("IFCPERSON", format!("{},$,$,$,$,$,$,$", s("dossier")));
|
||||
let person_org = w.add("IFCPERSONANDORGANIZATION", format!("#{person},#{org},$"));
|
||||
let app = w.add("IFCAPPLICATION", format!("#{org},{},{},{}", s("1.0"), s("dossier"), s("dossier")));
|
||||
let now = (now_ms / 1000.0).floor() as i64;
|
||||
let owner_history = w.add("IFCOWNERHISTORY", format!("#{person_org},#{app},$,{},{now},$,$,{now}", en("ADDED")));
|
||||
|
||||
let len_unit = w.add("IFCSIUNIT", format!("*,{},$,{}", en("LENGTHUNIT"), en("METRE")));
|
||||
let area_unit = w.add("IFCSIUNIT", format!("*,{},$,{}", en("AREAUNIT"), en("SQUARE_METRE")));
|
||||
let vol_unit = w.add("IFCSIUNIT", format!("*,{},$,{}", en("VOLUMEUNIT"), en("CUBIC_METRE")));
|
||||
let angle_unit = w.add("IFCSIUNIT", format!("*,{},$,{}", en("PLANEANGLEUNIT"), en("RADIAN")));
|
||||
let unit_assignment = w.add("IFCUNITASSIGNMENT", refs(&[len_unit, area_unit, vol_unit, angle_unit]));
|
||||
|
||||
let context = w.add("IFCGEOMETRICREPRESENTATIONCONTEXT", format!("$,{},3,{},#{identity_axis},$", s("Model"), r(0.00001)));
|
||||
|
||||
if p.geo_anchor.is_some() {
|
||||
let crs = w.add(
|
||||
"IFCPROJECTEDCRS",
|
||||
format!("{},{},{},$,{},$,#{len_unit}", s("EPSG:2056"), s("CH1903+ / LV95"), s("CH1903+"), s("Swiss Oblique Mercator")),
|
||||
);
|
||||
w.add("IFCMAPCONVERSION", format!("#{context},#{crs},{},{},{},{},{},{}", r(0.0), r(0.0), r(0.0), r(1.0), r(0.0), r(1.0)));
|
||||
}
|
||||
|
||||
let site_axis = w.add("IFCAXIS2PLACEMENT3D", format!("#{origin_point},$,$"));
|
||||
let site_placement = w.add("IFCLOCALPLACEMENT", format!("$,#{site_axis}"));
|
||||
let building_axis = w.add("IFCAXIS2PLACEMENT3D", format!("#{origin_point},$,$"));
|
||||
let building_placement = w.add("IFCLOCALPLACEMENT", format!("#{site_placement},#{building_axis}"));
|
||||
|
||||
let project_id = w.add(
|
||||
"IFCPROJECT",
|
||||
format!(
|
||||
"{},#{owner_history},{},$,$,$,$,{},#{unit_assignment}",
|
||||
s(&ifc_guid(&format!("{}:project", p.id))),
|
||||
s(if p.name.is_empty() { "Projekt" } else { &p.name }),
|
||||
refs(&[context])
|
||||
),
|
||||
);
|
||||
let site_ref_elev = p.geo_anchor.as_ref().and_then(|a| a.height).map_or("$".to_string(), r);
|
||||
let site_id = w.add(
|
||||
"IFCSITE",
|
||||
format!(
|
||||
"{},#{owner_history},{},$,$,#{site_placement},$,$,{},$,$,{site_ref_elev},$,$",
|
||||
s(&ifc_guid(&format!("{}:site", p.id))),
|
||||
s("Standort"),
|
||||
en("ELEMENT")
|
||||
),
|
||||
);
|
||||
let building_id = w.add(
|
||||
"IFCBUILDING",
|
||||
format!(
|
||||
"{},#{owner_history},{},$,$,#{building_placement},$,$,{},$,$,$",
|
||||
s(&ifc_guid(&format!("{}:building", p.id))),
|
||||
s(if p.name.is_empty() { "Gebäude" } else { &p.name }),
|
||||
en("ELEMENT")
|
||||
),
|
||||
);
|
||||
w.add("IFCRELAGGREGATES", format!("{},#{owner_history},$,$,#{project_id},{}", s(&ifc_guid(&format!("{}:agg-site", p.id))), refs(&[site_id])));
|
||||
w.add("IFCRELAGGREGATES", format!("{},#{owner_history},$,$,#{site_id},{}", s(&ifc_guid(&format!("{}:agg-building", p.id))), refs(&[building_id])));
|
||||
|
||||
let floors: Vec<&DrawingLevel> = p.drawing_levels.iter().filter(|l| l.kind == DrawingLevelKind::Floor).collect();
|
||||
let mut storey_by_floor: HashMap<&str, Structure> = HashMap::new();
|
||||
let mut storey_ids = Vec::new();
|
||||
for floor in &floors {
|
||||
let base = floor.base_elevation.unwrap_or(0.0);
|
||||
let pt = w.add("IFCCARTESIANPOINT", list(&[r(0.0), r(0.0), r(base)]));
|
||||
let axis = w.add("IFCAXIS2PLACEMENT3D", format!("#{pt},$,$"));
|
||||
let placement_id = w.add("IFCLOCALPLACEMENT", format!("#{building_placement},#{axis}"));
|
||||
let entity_id = w.add(
|
||||
"IFCBUILDINGSTOREY",
|
||||
format!("{},#{owner_history},{},$,$,#{placement_id},$,$,{},{}", s(&ifc_guid(&format!("{}:storey", floor.id))), s(&floor.name), en("ELEMENT"), r(base)),
|
||||
);
|
||||
storey_by_floor.entry(floor.id.as_str()).or_insert(Structure { entity_id, placement_id, base_elevation: base });
|
||||
storey_ids.push(entity_id);
|
||||
}
|
||||
if !storey_ids.is_empty() {
|
||||
w.add("IFCRELAGGREGATES", format!("{},#{owner_history},$,$,#{building_id},{}", s(&ifc_guid(&format!("{}:agg-storeys", p.id))), refs(&storey_ids)));
|
||||
}
|
||||
|
||||
let resolve_structure = |floor_id: &str| -> Structure {
|
||||
storey_by_floor.get(floor_id).copied().unwrap_or(Structure { entity_id: building_id, placement_id: building_placement, base_elevation: 0.0 })
|
||||
};
|
||||
|
||||
// Räumliche Eingliederung je Trägerstruktur, in Einfüge-Reihenfolge.
|
||||
let mut containment: Vec<(usize, Vec<usize>)> = Vec::new();
|
||||
let mut add_to_containment = |structure: usize, element: usize| match containment.iter_mut().find(|(k, _)| *k == structure) {
|
||||
Some((_, v)) => v.push(element),
|
||||
None => containment.push((structure, vec![element])),
|
||||
};
|
||||
|
||||
macro_rules! emit_box_product {
|
||||
($footprint:expr, $z_bottom_rel:expr, $depth:expr, $placement_rel_to:expr) => {{
|
||||
let footprint: &[Vec2] = $footprint;
|
||||
let mut closed: Vec<Vec2> = footprint.to_vec();
|
||||
closed.push(footprint[0]);
|
||||
let pt_ids: Vec<usize> = closed.iter().map(|q| w.add("IFCCARTESIANPOINT", list(&[r(q.x), r(q.y)]))).collect();
|
||||
let polyline = w.add("IFCPOLYLINE", refs(&pt_ids));
|
||||
let profile = w.add("IFCARBITRARYCLOSEDPROFILEDEF", format!("{},$,#{polyline}", en("AREA")));
|
||||
let solid = w.add("IFCEXTRUDEDAREASOLID", format!("#{profile},#{identity_axis},#{extrude_dir},{}", r(($depth as f64).max(0.001))));
|
||||
let shape_rep = w.add("IFCSHAPEREPRESENTATION", format!("#{context},{},{},{}", s("Body"), s("SweptSolid"), refs(&[solid])));
|
||||
let shape = w.add("IFCPRODUCTDEFINITIONSHAPE", format!("$,$,{}", refs(&[shape_rep])));
|
||||
let elem_origin = w.add("IFCCARTESIANPOINT", list(&[r(0.0), r(0.0), r($z_bottom_rel)]));
|
||||
let elem_axis = w.add("IFCAXIS2PLACEMENT3D", format!("#{elem_origin},$,$"));
|
||||
let placement = w.add("IFCLOCALPLACEMENT", format!("#{},#{elem_axis}", $placement_rel_to));
|
||||
(placement, shape)
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! emit_triangulated_product {
|
||||
($positions:expr, $indices:expr, $placement_rel_to:expr, $closed:expr) => {{
|
||||
let positions: &[f64] = $positions;
|
||||
let indices: &[u32] = $indices;
|
||||
let coords: Vec<String> = positions.chunks_exact(3).map(|c| format!("({},{},{})", r(c[0]), r(c[1]), r(c[2]))).collect();
|
||||
let point_list = w.add("IFCCARTESIANPOINTLIST3D", format!("({})", coords.join(",")));
|
||||
let tris: Vec<String> = indices.chunks_exact(3).map(|t| format!("({},{},{})", t[0] + 1, t[1] + 1, t[2] + 1)).collect();
|
||||
let closed_flag = if $closed { ".T." } else { "$" };
|
||||
let face_set = w.add("IFCTRIANGULATEDFACESET", format!("#{point_list},$,{closed_flag},({}),$", tris.join(",")));
|
||||
let shape_rep = w.add("IFCSHAPEREPRESENTATION", format!("#{context},{},{},{}", s("Body"), s("Tessellation"), refs(&[face_set])));
|
||||
let shape = w.add("IFCPRODUCTDEFINITIONSHAPE", format!("$,$,{}", refs(&[shape_rep])));
|
||||
let elem_origin = w.add("IFCCARTESIANPOINT", list(&[r(0.0), r(0.0), r(0.0)]));
|
||||
let elem_axis = w.add("IFCAXIS2PLACEMENT3D", format!("#{elem_origin},$,$"));
|
||||
let placement = w.add("IFCLOCALPLACEMENT", format!("#{},#{elem_axis}", $placement_rel_to));
|
||||
(placement, shape)
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! emit_building_element {
|
||||
($ty:expr, $guid:expr, $name:expr, $placement:expr, $shape:expr, $predefined:expr) => {
|
||||
w.add($ty, format!("{},#{owner_history},{},$,$,#{},#{},$,{}", s(&$guid), s(&$name), $placement, $shape, $predefined.unwrap_or_else(|| "$".to_string())))
|
||||
};
|
||||
}
|
||||
|
||||
// ── Bauteiltypen mit Materialschichten ──
|
||||
let mut material_by_component: HashMap<String, usize> = HashMap::new();
|
||||
let mut element_types: Vec<(String, ElementTypeRef)> = Vec::new();
|
||||
macro_rules! material_of {
|
||||
($component_id:expr) => {{
|
||||
let cid: &str = $component_id;
|
||||
match material_by_component.get(cid) {
|
||||
Some(&id) => id,
|
||||
None => {
|
||||
let name = p.component(cid).map_or(cid.to_string(), |c| c.name.clone());
|
||||
let id = w.add("IFCMATERIAL", format!("{},$,$", s(&name)));
|
||||
material_by_component.insert(cid.to_string(), id);
|
||||
id
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
macro_rules! type_for {
|
||||
($ifc_type:expr, $predefined:expr, $t_id:expr, $t_name:expr, $layers:expr) => {{
|
||||
let key = format!("{}:{}", $ifc_type, $t_id);
|
||||
match element_types.iter().position(|(k, _)| *k == key) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
let layers: &[Layer] = $layers;
|
||||
let layer_ids: Vec<usize> = layers
|
||||
.iter()
|
||||
.map(|l| {
|
||||
let mat = material_of!(&l.component_id);
|
||||
let th = if l.thickness.is_finite() { l.thickness } else { 0.0 };
|
||||
w.add("IFCMATERIALLAYER", format!("#{mat},{},$,$,$,$,$", r(th.max(0.0))))
|
||||
})
|
||||
.collect();
|
||||
let type_id = w.add($ifc_type, format!("{},#{owner_history},{},$,$,$,$,$,$,{}", s(&ifc_guid(&key)), s($t_name), en($predefined)));
|
||||
if !layer_ids.is_empty() {
|
||||
let set = w.add("IFCMATERIALLAYERSET", format!("{},{},$", refs(&layer_ids), s($t_name)));
|
||||
w.add("IFCRELASSOCIATESMATERIAL", format!("{},#{owner_history},$,$,{},#{set}", s(&ifc_guid(&format!("{key}:material"))), refs(&[type_id])));
|
||||
}
|
||||
element_types.push((key, ElementTypeRef { type_id, occurrences: vec![] }));
|
||||
element_types.len() - 1
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
// ── Wände (öffnungsgenaues Dreiecks-Mesh) ──
|
||||
let bands = model3d::emit_walls(p, true)?;
|
||||
let mut bands_by_wall: HashMap<&str, Vec<usize>> = HashMap::new();
|
||||
for (i, b) in bands.iter().enumerate() {
|
||||
bands_by_wall.entry(b.wall_id.as_str()).or_default().push(i);
|
||||
}
|
||||
let mut wall_entity_by_id: HashMap<&str, usize> = HashMap::new();
|
||||
for wall in &p.walls {
|
||||
let Some(idxs) = bands_by_wall.get(wall.id.as_str()).filter(|v| !v.is_empty()) else { continue };
|
||||
let structure = resolve_structure(&wall.floor_id);
|
||||
let mut positions: Vec<f64> = Vec::new();
|
||||
let mut indices: Vec<u32> = Vec::new();
|
||||
for &bi in idxs {
|
||||
let b = &bands[bi];
|
||||
let cw = CutWall {
|
||||
start: b.start,
|
||||
end: b.end,
|
||||
thickness: b.thickness,
|
||||
base_elevation: b.base_elevation,
|
||||
height: b.height,
|
||||
holes: b.holes.as_ref().map_or(vec![], |hs| hs.iter().map(|h| [h.from, h.to, h.z_bottom, h.z_top]).collect()),
|
||||
};
|
||||
let finite = cw.start.iter().chain(&cw.end).all(|v| v.is_finite()) && [cw.thickness, cw.base_elevation, cw.height].iter().all(|v| v.is_finite()) && cw.holes.iter().flatten().all(|v| v.is_finite());
|
||||
let cut = if finite { wall_cut_mesh(&cw) } else { Vec::new() };
|
||||
let base = (positions.len() / 3) as u32;
|
||||
for c in cut.chunks_exact(3) {
|
||||
positions.extend([c[0], c[2], c[1] - structure.base_elevation]);
|
||||
}
|
||||
// Wicklung umkehren (Reflexions-Ausgleich des Achsentauschs): (a, b, c) → (a, c, b).
|
||||
let n_tris = (cut.len() / 3) as u32 / 3;
|
||||
for t in 0..n_tris {
|
||||
let i = t * 3;
|
||||
indices.extend([base + i, base + i + 2, base + i + 1]);
|
||||
}
|
||||
}
|
||||
if indices.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let closed = is_watertight(&positions, &indices, 1e-6);
|
||||
let (placement, shape) = emit_triangulated_product!(&positions, &indices, structure.placement_id, closed);
|
||||
let mut name = wall.id.clone();
|
||||
let mut type_idx = None;
|
||||
if let Some(wt) = p.wall_type(wall) {
|
||||
name = wt.name.clone();
|
||||
type_idx = Some(type_for!("IFCWALLTYPE", "STANDARD", wt.id, &wt.name, &wt.layers));
|
||||
}
|
||||
let entity = emit_building_element!("IFCWALL", ifc_guid(&wall.id), name, placement, shape, None::<String>);
|
||||
if let Some(i) = type_idx {
|
||||
element_types[i].1.occurrences.push(entity);
|
||||
}
|
||||
wall_entity_by_id.insert(wall.id.as_str(), entity);
|
||||
add_to_containment(structure.entity_id, entity);
|
||||
}
|
||||
|
||||
// ── Decken ──
|
||||
for ceiling in p.ceilings.as_deref().unwrap_or(&[]) {
|
||||
if ceiling.outline.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
let (z_bottom, z_top) = p.ceiling_vertical_extent(ceiling);
|
||||
let structure = resolve_structure(&ceiling.floor_id);
|
||||
let (placement, shape) = emit_box_product!(&ceiling.outline, z_bottom - structure.base_elevation, z_top - z_bottom, structure.placement_id);
|
||||
let mut name = ceiling.id.clone();
|
||||
let mut type_idx = None;
|
||||
if let Some((tid, tname, layers)) = model3d::ceiling_type_ref(p, ceiling) {
|
||||
name = tname.to_string();
|
||||
type_idx = Some(type_for!("IFCSLABTYPE", "FLOOR", tid, tname, layers));
|
||||
}
|
||||
let entity = emit_building_element!("IFCSLAB", ifc_guid(&ceiling.id), name, placement, shape, Some(en("FLOOR")));
|
||||
if let Some(i) = type_idx {
|
||||
element_types[i].1.occurrences.push(entity);
|
||||
}
|
||||
add_to_containment(structure.entity_id, entity);
|
||||
}
|
||||
|
||||
// ── Fenster/Türen als eigene Objekte ──
|
||||
for opening in p.openings.as_deref().unwrap_or(&[]) {
|
||||
let Some(wall) = p.walls.iter().find(|wl| wl.id == opening.host_wall_id) else { continue };
|
||||
if !wall_entity_by_id.contains_key(wall.id.as_str()) {
|
||||
continue;
|
||||
}
|
||||
let (wall_z_bottom, _) = p.wall_vertical_extent(wall);
|
||||
let structure = resolve_structure(&wall.floor_id);
|
||||
let footprint = opening_footprint(p, wall, opening);
|
||||
let z_sill_abs = wall_z_bottom + opening.sill_height;
|
||||
let (fill_placement, fill_shape) = emit_box_product!(&footprint, z_sill_abs - structure.base_elevation, opening.height, structure.placement_id);
|
||||
let fill_guid = ifc_guid(&format!("{}:fill", opening.id));
|
||||
let fill_name = opening_label(opening);
|
||||
let entity = if opening.kind == ElementKind::Door {
|
||||
w.add(
|
||||
"IFCDOOR",
|
||||
format!("{},#{owner_history},{},$,$,#{fill_placement},#{fill_shape},$,{},{},{},$,$", s(&fill_guid), s(&fill_name), r(opening.height), r(opening.width), en("DOOR")),
|
||||
)
|
||||
} else {
|
||||
w.add(
|
||||
"IFCWINDOW",
|
||||
format!("{},#{owner_history},{},$,$,#{fill_placement},#{fill_shape},$,{},{},{},$,$", s(&fill_guid), s(&fill_name), r(opening.height), r(opening.width), en("WINDOW")),
|
||||
)
|
||||
};
|
||||
add_to_containment(structure.entity_id, entity);
|
||||
}
|
||||
|
||||
// ── Treppen ──
|
||||
for stair in p.stairs.as_deref().unwrap_or(&[]) {
|
||||
let footprint = stair_footprint(stair);
|
||||
if footprint.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
let (z_bottom, z_top) = p.stair_vertical_extent(stair);
|
||||
let structure = resolve_structure(&stair.floor_id);
|
||||
let (placement, shape) = emit_box_product!(&footprint, z_bottom - structure.base_elevation, z_top - z_bottom, structure.placement_id);
|
||||
let predefined = match stair.shape {
|
||||
StairShape::Straight => en("STRAIGHT_RUN_STAIR"),
|
||||
StairShape::Spiral => en("SPIRAL_STAIR"),
|
||||
_ => en("QUARTER_TURN_STAIR"),
|
||||
};
|
||||
let entity = emit_building_element!("IFCSTAIR", ifc_guid(&stair.id), "Treppe".to_string(), placement, shape, Some(predefined));
|
||||
add_to_containment(structure.entity_id, entity);
|
||||
}
|
||||
|
||||
// ── Extrudierte Körper ──
|
||||
for solid in p.extruded_solids.as_deref().unwrap_or(&[]) {
|
||||
if solid.points.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
let base = floors.iter().find(|f| f.id == solid.level_id).map_or(0.0, |f| f.base_elevation.unwrap_or(0.0));
|
||||
let structure = resolve_structure(&solid.level_id);
|
||||
let (placement, shape) = emit_box_product!(&solid.points, base - structure.base_elevation, solid.height, structure.placement_id);
|
||||
let entity = emit_building_element!("IFCBUILDINGELEMENTPROXY", ifc_guid(&solid.id), "Extrusion".to_string(), placement, shape, None::<String>);
|
||||
add_to_containment(structure.entity_id, entity);
|
||||
}
|
||||
|
||||
// ── Räume → IfcSpace ──
|
||||
let mut spaces_by_structure: Vec<(usize, Vec<usize>)> = Vec::new();
|
||||
for room in p.rooms.as_deref().unwrap_or(&[]) {
|
||||
if room.boundary.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
let structure = resolve_structure(&room.floor_id);
|
||||
let height = floors.iter().find(|f| f.id == room.floor_id).and_then(|f| f.floor_height).filter(|h| *h > 0.0).unwrap_or(2.5);
|
||||
let (placement, shape) = emit_box_product!(&room.boundary, 0.0, height, structure.placement_id);
|
||||
let number = room.stamp.as_ref().and_then(|st| st.number.as_deref()).filter(|n| !n.is_empty()).unwrap_or(&room.id);
|
||||
let space_id = w.add(
|
||||
"IFCSPACE",
|
||||
format!("{},#{owner_history},{},$,$,#{placement},#{shape},{},{},{},$", s(&ifc_guid(&room.id)), s(number), s(&room.name), en("ELEMENT"), en("INTERNAL")),
|
||||
);
|
||||
match spaces_by_structure.iter_mut().find(|(k, _)| *k == structure.entity_id) {
|
||||
Some((_, v)) => v.push(space_id),
|
||||
None => spaces_by_structure.push((structure.entity_id, vec![space_id])),
|
||||
}
|
||||
let pts: Vec<[f64; 2]> = room.boundary.iter().map(|v| [v.x, v.y]).collect();
|
||||
let area = crate::room_area::evaluate(&pts, 0.0);
|
||||
let q_net = w.add("IFCQUANTITYAREA", format!("{},$,$,{},$", s("NetFloorArea"), r(area.net)));
|
||||
let q_gross = w.add("IFCQUANTITYAREA", format!("{},$,$,{},$", s("GrossFloorArea"), r(area.gross)));
|
||||
let q_height = w.add("IFCQUANTITYLENGTH", format!("{},$,$,{},$", s("Height"), r(height)));
|
||||
let qto = w.add(
|
||||
"IFCELEMENTQUANTITY",
|
||||
format!("{},#{owner_history},{},$,$,{}", s(&ifc_guid(&format!("{}:qto", room.id))), s("Qto_SpaceBaseQuantities"), refs(&[q_net, q_gross, q_height])),
|
||||
);
|
||||
w.add("IFCRELDEFINESBYPROPERTIES", format!("{},#{owner_history},$,$,{},#{qto}", s(&ifc_guid(&format!("{}:rel-qto", room.id))), refs(&[space_id])));
|
||||
let sia_name = serde_json::to_value(room.sia_category).ok().and_then(|v| v.as_str().map(str::to_owned)).unwrap_or_default();
|
||||
let sia = w.add("IFCPROPERTYSINGLEVALUE", format!("{},$,IFCLABEL({}),$", s("SIA416"), s(&sia_name)));
|
||||
let pset = w.add("IFCPROPERTYSET", format!("{},#{owner_history},{},$,{}", s(&ifc_guid(&format!("{}:pset", room.id))), s("CH_Raum"), refs(&[sia])));
|
||||
w.add("IFCRELDEFINESBYPROPERTIES", format!("{},#{owner_history},$,$,{},#{pset}", s(&ifc_guid(&format!("{}:rel-pset", room.id))), refs(&[space_id])));
|
||||
}
|
||||
for (structure_id, space_ids) in &spaces_by_structure {
|
||||
w.add("IFCRELAGGREGATES", format!("{},#{owner_history},$,$,#{structure_id},{}", s(&ifc_guid(&format!("spaces:{structure_id}"))), refs(space_ids)));
|
||||
}
|
||||
|
||||
// ── Dächer → IfcRoof ──
|
||||
for roof in p.roofs.as_deref().unwrap_or(&[]) {
|
||||
let structure = resolve_structure(&roof.floor_id);
|
||||
let mut positions: Vec<f64> = Vec::new();
|
||||
let mut indices: Vec<u32> = Vec::new();
|
||||
for mesh in model3d::emit_roofs(p, Some(&roof.id))? {
|
||||
let base = (positions.len() / 3) as u32;
|
||||
for c in mesh.positions.chunks_exact(3) {
|
||||
positions.extend([c[0], c[1], c[2] - structure.base_elevation]);
|
||||
}
|
||||
indices.extend(mesh.indices.iter().map(|ix| base + ix));
|
||||
}
|
||||
if indices.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut closed = is_watertight(&positions, &indices, 1e-6);
|
||||
if !closed {
|
||||
let flipped: Vec<u32> = indices.chunks_exact(3).flat_map(|t| [t[0], t[2], t[1]]).collect();
|
||||
if is_watertight(&positions, &flipped, 1e-6) {
|
||||
indices = flipped;
|
||||
closed = true;
|
||||
}
|
||||
}
|
||||
let (placement, shape) = emit_triangulated_product!(&positions, &indices, structure.placement_id, closed);
|
||||
let predefined = match roof.shape {
|
||||
RoofShape::Flach => "FLAT_ROOF",
|
||||
RoofShape::Pult => "SHED_ROOF",
|
||||
RoofShape::Sattel => "GABLE_ROOF",
|
||||
RoofShape::Walm => "HIP_ROOF",
|
||||
RoofShape::Mansarde => "MANSARD_ROOF",
|
||||
RoofShape::Zelt => "HIPPED_GABLE_ROOF",
|
||||
RoofShape::Unknown => "NOTDEFINED",
|
||||
};
|
||||
let roof_type = roof.roof_type_id.as_deref().and_then(|id| p.roof_types.as_deref()?.iter().find(|t| t.id == id));
|
||||
let name = roof_type.map_or("Dach".to_string(), |t| t.name.clone());
|
||||
let entity = emit_building_element!("IFCROOF", ifc_guid(&roof.id), name, placement, shape, Some(en(predefined)));
|
||||
if let Some(rt) = roof_type {
|
||||
let i = type_for!("IFCROOFTYPE", predefined, rt.id, &rt.name, &rt.layers);
|
||||
element_types[i].1.occurrences.push(entity);
|
||||
}
|
||||
add_to_containment(structure.entity_id, entity);
|
||||
}
|
||||
|
||||
// ── Stützen → IfcColumn ──
|
||||
let mut material_assoc: Vec<(usize, Vec<usize>)> = Vec::new();
|
||||
for col in p.columns.as_deref().unwrap_or(&[]) {
|
||||
let footprint = model3d::column_footprint(col);
|
||||
if footprint.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
let (z_bottom, z_top) = p.column_vertical_extent(col);
|
||||
if !(z_top > z_bottom) {
|
||||
continue;
|
||||
}
|
||||
let structure = resolve_structure(&col.floor_id);
|
||||
let (placement, shape) = emit_box_product!(&footprint, z_bottom - structure.base_elevation, z_top - z_bottom, structure.placement_id);
|
||||
let entity = emit_building_element!("IFCCOLUMN", ifc_guid(&col.id), column_label(col), placement, shape, Some(en("COLUMN")));
|
||||
add_to_containment(structure.entity_id, entity);
|
||||
if let Some(cid) = col.component_id.as_deref().filter(|c| !c.is_empty()) {
|
||||
let mat = material_of!(cid);
|
||||
match material_assoc.iter_mut().find(|(k, _)| *k == mat) {
|
||||
Some((_, v)) => v.push(entity),
|
||||
None => material_assoc.push((mat, vec![entity])),
|
||||
}
|
||||
}
|
||||
}
|
||||
for (mat, ids) in &material_assoc {
|
||||
w.add("IFCRELASSOCIATESMATERIAL", format!("{},#{owner_history},$,$,{},#{mat}", s(&ifc_guid(&format!("material:{mat}"))), refs(ids)));
|
||||
}
|
||||
|
||||
// ── Typ-Zuordnung ──
|
||||
for (key, rf) in &element_types {
|
||||
if rf.occurrences.is_empty() {
|
||||
continue;
|
||||
}
|
||||
w.add("IFCRELDEFINESBYTYPE", format!("{},#{owner_history},$,$,{},#{}", s(&ifc_guid(&format!("{key}:occurrences"))), refs(&rf.occurrences), rf.type_id));
|
||||
}
|
||||
|
||||
// ── Räumliche Eingliederung ──
|
||||
for (structure_id, element_ids) in &containment {
|
||||
w.add("IFCRELCONTAINEDINSPATIALSTRUCTURE", format!("{},#{owner_history},$,$,{},#{structure_id}", s(&ifc_guid(&format!("contain:{structure_id}"))), refs(element_ids)));
|
||||
}
|
||||
|
||||
// ── Kopf + Zusammenbau ──
|
||||
let iso = iso_from_ms(now_ms);
|
||||
let file_name = format!("{}.ifc", if p.name.is_empty() { "modell" } else { &p.name });
|
||||
let mut out = vec![
|
||||
"ISO-10303-21;".to_string(),
|
||||
"HEADER;".to_string(),
|
||||
format!("FILE_DESCRIPTION({},{});", list(&[s("")]), s("2;1")),
|
||||
format!("FILE_NAME({},{},{},{},{},{},{});", s(&file_name), s(&iso), list(&[s("dossier")]), list(&[s("dossier")]), s("dossier"), s("dossier"), s("")),
|
||||
"FILE_SCHEMA(('IFC4'));".to_string(),
|
||||
"ENDSEC;".to_string(),
|
||||
String::new(),
|
||||
"DATA;".to_string(),
|
||||
];
|
||||
out.extend(w.lines);
|
||||
out.push("ENDSEC;".to_string());
|
||||
out.push("END-ISO-10303-21;".to_string());
|
||||
Ok(out.join("\n") + "\n")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn guid_ist_stabil_und_22_zeichen_lang() {
|
||||
let g = ifc_guid("wall-1");
|
||||
assert_eq!(g.len(), 22);
|
||||
assert_eq!(g, ifc_guid("wall-1"));
|
||||
assert_ne!(g, ifc_guid("wall-2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string_und_zahl_literale() {
|
||||
assert_eq!(ifc_string("A'b\\ü😀"), "'A''b\\\\\\X2\\00FC\\X0\\\\X4\\0001F600\\X0\\'");
|
||||
assert_eq!(r(1.0), "1.0");
|
||||
assert_eq!(r(-0.0), "0.0");
|
||||
assert_eq!(r(0.1234567), "0.123457");
|
||||
assert_eq!(r(2.5), "2.5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iso_datum() {
|
||||
assert_eq!(iso_from_ms(0.0), "1970-01-01T00:00:00");
|
||||
assert_eq!(iso_from_ms(1_700_000_000_000.0), "2023-11-14T22:13:20");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn beispielprojekt_exportiert() {
|
||||
let p: Project = serde_json::from_str(include_str!("../tests/fixtures/sample_project.json")).unwrap();
|
||||
let ifc = export_ifc_spf(&p, 1_700_000_000_000.0).unwrap();
|
||||
assert!(ifc.starts_with("ISO-10303-21;\nHEADER;"));
|
||||
assert!(ifc.contains("IFCWALL("));
|
||||
assert!(ifc.ends_with("END-ISO-10303-21;\n"));
|
||||
}
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
//! OBJ-/STL-Export des 3D-Gebäudemodells als reines Dreiecks-Netz ([K4] S2, vorher
|
||||
//! `src/export/exportMesh.ts`). Wände: dieselben Schicht-Bänder wie der 3D-Viewer, gelochte Bänder
|
||||
//! öffnungsgenau ausgeschnitten (`wall_mesh_cut`); Decken und Extrusionen als Umriss-Prismen
|
||||
//! (Ear-Clipping-Kappen, Seitenmantel, optional verjüngt). Achsen: Modell (x, y) → Welt (x, Höhe, y),
|
||||
//! Y-up, rechtshändig, Meter.
|
||||
|
||||
use crate::js_fmt::to_fixed;
|
||||
use crate::model::*;
|
||||
use crate::model3d;
|
||||
use crate::wall_mesh_cut::{wall_cut_mesh, CutWall};
|
||||
|
||||
struct MeshGroup {
|
||||
name: String,
|
||||
positions: Vec<f64>,
|
||||
indices: Vec<u32>,
|
||||
}
|
||||
|
||||
/// OBJ-Gruppennamen dürfen keine Whitespaces/Sonderzeichen enthalten.
|
||||
fn sanitize_name(id: &str) -> String {
|
||||
let s: String = id.chars().map(|c| if c.is_ascii_alphanumeric() || c == '_' || c == '-' { c } else { '_' }).collect();
|
||||
if s.is_empty() {
|
||||
"x".into()
|
||||
} else {
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
/// Die 6 Quader-Seiten als Eckpunkt-Quadrupel, nach aussen gewunden.
|
||||
const BOX_QUADS: [[u32; 4]; 6] = [[4, 6, 7, 5], [1, 3, 2, 0], [2, 3, 7, 6], [4, 5, 1, 0], [1, 5, 7, 3], [2, 6, 4, 0]];
|
||||
|
||||
fn push_wall_box(g: &mut MeshGroup, w: &model3d::RWall) {
|
||||
let [sx, sy] = w.start;
|
||||
let [ex, ey] = w.end;
|
||||
let dx = ex - sx;
|
||||
let dz = ey - sy;
|
||||
let len = crate::jsmath::hypot2(dx, dz);
|
||||
if len < 1e-9 || w.height <= 1e-9 || w.thickness <= 1e-9 {
|
||||
return;
|
||||
}
|
||||
let (ax, az) = (dx / len, dz / len);
|
||||
let (nx, nz) = (az, -ax);
|
||||
let (half_len, half_height, half_thick) = (len / 2.0, w.height / 2.0, w.thickness / 2.0);
|
||||
let (cx, cz) = ((sx + ex) / 2.0, (sy + ey) / 2.0);
|
||||
let cy = w.base_elevation + w.height / 2.0;
|
||||
let base = (g.positions.len() / 3) as u32;
|
||||
for i in 0..8u32 {
|
||||
let s_l = if i & 1 != 0 { 1.0 } else { -1.0 };
|
||||
let s_h = if i & 2 != 0 { 1.0 } else { -1.0 };
|
||||
let s_t = if i & 4 != 0 { 1.0 } else { -1.0 };
|
||||
g.positions.extend([cx + s_l * half_len * ax + s_t * half_thick * nx, cy + s_h * half_height, cz + s_l * half_len * az + s_t * half_thick * nz]);
|
||||
}
|
||||
for [a, b, c, d] in BOX_QUADS {
|
||||
g.indices.extend([base + a, base + b, base + c, base + a, base + c, base + d]);
|
||||
}
|
||||
}
|
||||
|
||||
fn signed_area_xy(pts: &[Vec2]) -> f64 {
|
||||
let mut a = 0.0;
|
||||
let mut j = pts.len().wrapping_sub(1);
|
||||
for i in 0..pts.len() {
|
||||
a += pts[j].x * pts[i].y - pts[i].x * pts[j].y;
|
||||
j = i;
|
||||
}
|
||||
a / 2.0
|
||||
}
|
||||
|
||||
fn push_prism(g: &mut MeshGroup, outline: &[Vec2], z_bottom: f64, z_top: f64, taper: f64) {
|
||||
if outline.len() < 3 || z_top - z_bottom <= 1e-9 {
|
||||
return;
|
||||
}
|
||||
let ccw: Vec<Vec2> = if signed_area_xy(outline) >= 0.0 { outline.to_vec() } else { outline.iter().rev().copied().collect() };
|
||||
let n = ccw.len() as u32;
|
||||
let (mut cx, mut cy_model) = (0.0, 0.0);
|
||||
for p in &ccw {
|
||||
cx += p.x;
|
||||
cy_model += p.y;
|
||||
}
|
||||
cx /= n as f64;
|
||||
cy_model /= n as f64;
|
||||
let t = taper.clamp(0.0, 1.0);
|
||||
let base = (g.positions.len() / 3) as u32;
|
||||
for p in &ccw {
|
||||
g.positions.extend([p.x, z_bottom, p.y]);
|
||||
}
|
||||
for p in &ccw {
|
||||
let tx = cx + (p.x - cx) * (1.0 - t);
|
||||
let ty = cy_model + (p.y - cy_model) * (1.0 - t);
|
||||
g.positions.extend([tx, z_top, ty]);
|
||||
}
|
||||
let pts: Vec<crate::hatch::V2> = ccw.iter().map(|p| crate::hatch::V2 { x: p.x, y: p.y }).collect();
|
||||
let cap = crate::gpu_compile::triangulate(&pts);
|
||||
for tri in cap.chunks_exact(3) {
|
||||
let (a, b, c) = (tri[0], tri[1], tri[2]);
|
||||
g.indices.extend([base + a, base + b, base + c]);
|
||||
g.indices.extend([base + n + a, base + n + c, base + n + b]);
|
||||
}
|
||||
for i in 0..n {
|
||||
let j = (i + 1) % n;
|
||||
let (bi, bj, ti, tj) = (base + i, base + j, base + n + i, base + n + j);
|
||||
g.indices.extend([bi, ti, tj]);
|
||||
g.indices.extend([bi, tj, bj]);
|
||||
}
|
||||
}
|
||||
|
||||
fn build_groups(p: &Project) -> Result<Vec<MeshGroup>, String> {
|
||||
let mut groups: Vec<MeshGroup> = Vec::new();
|
||||
let walls = model3d::emit_walls(p, true)?;
|
||||
let mut by_id: Vec<(String, usize)> = Vec::new();
|
||||
for w in &walls {
|
||||
let gi = match by_id.iter().find(|(id, _)| *id == w.wall_id) {
|
||||
Some((_, gi)) => *gi,
|
||||
None => {
|
||||
groups.push(MeshGroup { name: format!("Wand_{}", sanitize_name(&w.wall_id)), positions: vec![], indices: vec![] });
|
||||
by_id.push((w.wall_id.clone(), groups.len() - 1));
|
||||
groups.len() - 1
|
||||
}
|
||||
};
|
||||
let g = &mut groups[gi];
|
||||
if w.holes.as_ref().is_some_and(|h| !h.is_empty()) {
|
||||
let cw = CutWall {
|
||||
start: w.start,
|
||||
end: w.end,
|
||||
thickness: w.thickness,
|
||||
base_elevation: w.base_elevation,
|
||||
height: w.height,
|
||||
holes: w.holes.as_ref().map_or(vec![], |hs| hs.iter().map(|h| [h.from, h.to, h.z_bottom, h.z_top]).collect()),
|
||||
};
|
||||
let finite = cw.start.iter().chain(&cw.end).all(|v| v.is_finite()) && [cw.thickness, cw.base_elevation, cw.height].iter().all(|v| v.is_finite()) && cw.holes.iter().flatten().all(|v| v.is_finite());
|
||||
let cut = if finite { wall_cut_mesh(&cw) } else { Vec::new() };
|
||||
let base = (g.positions.len() / 3) as u32;
|
||||
g.positions.extend_from_slice(&cut);
|
||||
g.indices.extend((0..(cut.len() / 3) as u32).map(|i| base + i));
|
||||
} else {
|
||||
push_wall_box(g, w);
|
||||
}
|
||||
}
|
||||
for s in model3d::emit_slabs(p) {
|
||||
let mut g = MeshGroup { name: format!("Decke_{}", sanitize_name(&s.ceiling_id)), positions: vec![], indices: vec![] };
|
||||
let outline: Vec<Vec2> = s.outline.iter().map(|&[x, y]| Vec2 { x, y }).collect();
|
||||
push_prism(&mut g, &outline, s.z_bottom, s.z_top, 0.0);
|
||||
groups.push(g);
|
||||
}
|
||||
for solid in p.extruded_solids.as_deref().unwrap_or(&[]) {
|
||||
if solid.points.len() < 3 || solid.height <= 0.0 {
|
||||
continue;
|
||||
}
|
||||
let base_z = p.floor(&solid.level_id).map_or(0.0, |f| f.base_elevation.unwrap_or(0.0));
|
||||
let mut g = MeshGroup { name: format!("Extrusion_{}", sanitize_name(&solid.id)), positions: vec![], indices: vec![] };
|
||||
push_prism(&mut g, &solid.points, base_z, base_z + solid.height, solid.taper.unwrap_or(0.0));
|
||||
groups.push(g);
|
||||
}
|
||||
Ok(groups.into_iter().filter(|g| !g.indices.is_empty()).collect())
|
||||
}
|
||||
|
||||
/// Kompakte Zahlformatierung (bis 6 Nachkommastellen, ohne Nullen, mindestens `.0`).
|
||||
fn fmt(v: f64) -> String {
|
||||
if !v.is_finite() {
|
||||
return "0.0".into();
|
||||
}
|
||||
let mut s = to_fixed(v, 6);
|
||||
let trimmed = s.trim_end_matches('0').len();
|
||||
s.truncate(trimmed);
|
||||
if s.ends_with('.') {
|
||||
s.push('0');
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
/// Wavefront-OBJ des Gebäudemodells.
|
||||
pub fn export_obj(p: &Project) -> Result<String, String> {
|
||||
let groups = build_groups(p)?;
|
||||
let mut lines: Vec<String> = vec![
|
||||
"# DOSSIER OBJ-Export - Dreiecks-Mesh des 3D-Gebaeudemodells".into(),
|
||||
"# Achsen: rechtshaendig, Y-up (Y = Hoehe ueber OKFF), wie der 3D-Viewer.".into(),
|
||||
"# Waende: Schicht-Baender mit oeffnungsgenau ausgeschnittenen Loechern (inkl. Laibungen).".into(),
|
||||
"# Decken/Extrusionen: Umriss-Prisma (Ear-Clipping-Triangulierung).".into(),
|
||||
];
|
||||
let mut offset = 0u32;
|
||||
for g in &groups {
|
||||
let vert_count = (g.positions.len() / 3) as u32;
|
||||
if vert_count == 0 {
|
||||
continue;
|
||||
}
|
||||
lines.push(format!("o {}", g.name));
|
||||
for c in g.positions.chunks_exact(3) {
|
||||
lines.push(format!("v {} {} {}", fmt(c[0]), fmt(c[1]), fmt(c[2])));
|
||||
}
|
||||
for t in g.indices.chunks_exact(3) {
|
||||
lines.push(format!("f {} {} {}", t[0] + 1 + offset, t[1] + 1 + offset, t[2] + 1 + offset));
|
||||
}
|
||||
offset += vert_count;
|
||||
}
|
||||
Ok(lines.join("\n") + "\n")
|
||||
}
|
||||
|
||||
/// ASCII-STL des Gebäudemodells.
|
||||
pub fn export_stl(p: &Project) -> Result<String, String> {
|
||||
let groups = build_groups(p)?;
|
||||
let mut lines: Vec<String> = vec!["solid dossier".into()];
|
||||
for g in &groups {
|
||||
for t in g.indices.chunks_exact(3) {
|
||||
let pt = |i: u32| -> [f64; 3] {
|
||||
let k = i as usize * 3;
|
||||
[g.positions[k], g.positions[k + 1], g.positions[k + 2]]
|
||||
};
|
||||
let (a, b, c) = (pt(t[0]), pt(t[1]), pt(t[2]));
|
||||
let (ux, uy, uz) = (b[0] - a[0], b[1] - a[1], b[2] - a[2]);
|
||||
let (vx, vy, vz) = (c[0] - a[0], c[1] - a[1], c[2] - a[2]);
|
||||
let (mut nx, mut ny, mut nz) = (uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx);
|
||||
let len = crate::jsmath::hypot(&[nx, ny, nz]);
|
||||
if len > 1e-12 {
|
||||
nx /= len;
|
||||
ny /= len;
|
||||
nz /= len;
|
||||
} else {
|
||||
nx = 0.0;
|
||||
ny = 0.0;
|
||||
nz = 0.0;
|
||||
}
|
||||
lines.push(format!("facet normal {} {} {}", fmt(nx), fmt(ny), fmt(nz)));
|
||||
lines.push("outer loop".into());
|
||||
for v in [a, b, c] {
|
||||
lines.push(format!("vertex {} {} {}", fmt(v[0]), fmt(v[1]), fmt(v[2])));
|
||||
}
|
||||
lines.push("endloop".into());
|
||||
lines.push("endfacet".into());
|
||||
}
|
||||
}
|
||||
lines.push("endsolid dossier".into());
|
||||
Ok(lines.join("\n") + "\n")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn zahlformat() {
|
||||
assert_eq!(fmt(1.0), "1.0");
|
||||
assert_eq!(fmt(1.5), "1.5");
|
||||
assert_eq!(fmt(0.0), "0.0");
|
||||
assert_eq!(fmt(10.0), "10.0");
|
||||
assert_eq!(fmt(0.1234567), "0.123457");
|
||||
assert_eq!(fmt(f64::NAN), "0.0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn beispielprojekt() {
|
||||
let p: Project = serde_json::from_str(include_str!("../tests/fixtures/sample_project.json")).unwrap();
|
||||
let obj = export_obj(&p).unwrap();
|
||||
assert!(obj.contains("\no Wand_"));
|
||||
let stl = export_stl(&p).unwrap();
|
||||
assert!(stl.starts_with("solid dossier\n") && stl.ends_with("endsolid dossier\n"));
|
||||
assert!(export_obj(&Project::default()).unwrap().lines().count() == 4);
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
//! Ursprungs-Verschiebung des ganzen Projekts ([K4] S2, vorher `model/geoRebase.ts`): reine,
|
||||
//! verlustfreie Translation aller Modell-Koordinaten um einen festen Vektor. `geoAnchor` wandert
|
||||
//! mit, damit der LV95-Bezug exakt erhalten bleibt. Nur Translation — keine Rotation (Achsen- und
|
||||
//! Winkelfelder blieben sonst falsch). Richtungsvektoren (z. B. `Stair.dir`) bleiben unangetastet.
|
||||
|
||||
use crate::model::*;
|
||||
|
||||
fn shift(p: Vec2, dx: f64, dy: f64) -> Vec2 {
|
||||
Vec2 { x: p.x + dx, y: p.y + dy }
|
||||
}
|
||||
|
||||
fn shift_all(pts: &mut [Vec2], dx: f64, dy: f64) {
|
||||
for p in pts {
|
||||
*p = shift(*p, dx, dy);
|
||||
}
|
||||
}
|
||||
|
||||
fn shift_geom(g: &mut Drawing2DGeom, dx: f64, dy: f64) {
|
||||
use Drawing2DGeom::*;
|
||||
match g {
|
||||
Line { a, b } | Xline { a, b } | Ray { a, b } => {
|
||||
*a = shift(*a, dx, dy);
|
||||
*b = shift(*b, dx, dy);
|
||||
}
|
||||
Polyline { pts, .. } | Bezier { pts } | Spline { pts, .. } | Dimension { pts, .. } => shift_all(pts, dx, dy),
|
||||
Rect { min, max } | Image { min, max, .. } => {
|
||||
*min = shift(*min, dx, dy);
|
||||
*max = shift(*max, dx, dy);
|
||||
}
|
||||
Circle { center, .. } | Arc { center, .. } | Ellipse { center, .. } => *center = shift(*center, dx, dy),
|
||||
Kote { at, .. } | Detailref { at, .. } | Scalebar { at, .. } | Pointmarker { at } | Block { at, .. } => *at = shift(*at, dx, dy),
|
||||
Text { at, leader_target, leader_bend_points, path_pts, .. } => {
|
||||
*at = shift(*at, dx, dy);
|
||||
if let Some(t) = leader_target {
|
||||
*t = shift(*t, dx, dy);
|
||||
}
|
||||
if let Some(v) = leader_bend_points {
|
||||
shift_all(v, dx, dy);
|
||||
}
|
||||
if let Some(v) = path_pts {
|
||||
shift_all(v, dx, dy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn shift_context(o: &mut ContextObject, dx: f64, dy: f64) {
|
||||
match o {
|
||||
ContextObject::ContourSet(s) => {
|
||||
for c in &mut s.contours {
|
||||
shift_all(&mut c.pts, dx, dy);
|
||||
if let Some(cv) = &mut c.curve {
|
||||
cv.cx += dx;
|
||||
cv.cy += dy;
|
||||
}
|
||||
}
|
||||
}
|
||||
ContextObject::Image(i) => {
|
||||
i.min = shift(i.min, dx, dy);
|
||||
i.max = shift(i.max, dx, dy);
|
||||
}
|
||||
ContextObject::ImportedMesh(m) => shift_positions(&mut m.positions, dx, dy),
|
||||
ContextObject::TerrainMesh(m) => shift_positions(&mut m.positions, dx, dy),
|
||||
}
|
||||
}
|
||||
|
||||
/// Nur x/y (Grundriss) verschieben, die Höhe bleibt.
|
||||
fn shift_positions(pos: &mut [f64], dx: f64, dy: f64) {
|
||||
for c in pos.chunks_exact_mut(3) {
|
||||
c[0] += dx;
|
||||
c[1] += dy;
|
||||
}
|
||||
}
|
||||
|
||||
/// Verschiebt sämtliche Modell-Koordinaten (`translateProject`).
|
||||
pub fn translate_project(p: &Project, dx: f64, dy: f64) -> Project {
|
||||
if dx == 0.0 && dy == 0.0 {
|
||||
return p.clone();
|
||||
}
|
||||
let mut out = p.clone();
|
||||
for w in &mut out.walls {
|
||||
w.start = shift(w.start, dx, dy);
|
||||
w.end = shift(w.end, dx, dy);
|
||||
}
|
||||
for c in out.ceilings.iter_mut().flatten() {
|
||||
shift_all(&mut c.outline, dx, dy);
|
||||
for h in c.openings.iter_mut().flatten() {
|
||||
shift_all(h, dx, dy);
|
||||
}
|
||||
}
|
||||
for r in out.roofs.iter_mut().flatten() {
|
||||
shift_all(&mut r.outline, dx, dy);
|
||||
}
|
||||
for s in out.stairs.iter_mut().flatten() {
|
||||
s.start = shift(s.start, dx, dy);
|
||||
s.center = s.center.map(|c| shift(c, dx, dy));
|
||||
}
|
||||
for r in out.rooms.iter_mut().flatten() {
|
||||
shift_all(&mut r.boundary, dx, dy);
|
||||
r.stamp_anchor = r.stamp_anchor.map(|a| shift(a, dx, dy));
|
||||
}
|
||||
for c in out.columns.iter_mut().flatten() {
|
||||
c.position = shift(c.position, dx, dy);
|
||||
}
|
||||
for s in out.extruded_solids.iter_mut().flatten() {
|
||||
shift_all(&mut s.points, dx, dy);
|
||||
if let Some(c) = &mut s.circle {
|
||||
c.center = shift(c.center, dx, dy);
|
||||
}
|
||||
}
|
||||
for d in &mut out.drawings2d {
|
||||
shift_geom(&mut d.geom, dx, dy);
|
||||
}
|
||||
for o in out.context.iter_mut().flatten() {
|
||||
shift_context(o, dx, dy);
|
||||
}
|
||||
for l in &mut out.drawing_levels {
|
||||
if let Some(pts) = &mut l.line_points {
|
||||
pts[0] = shift(pts[0], dx, dy);
|
||||
pts[1] = shift(pts[1], dx, dy);
|
||||
}
|
||||
}
|
||||
if let Some(a) = &mut out.geo_anchor {
|
||||
a.model = shift(a.model, dx, dy);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// LV95-Ursprung: die reale Landeskoordinate, die auf den Modell-Nullpunkt abgebildet wird.
|
||||
pub fn project_geo_origin(p: &Project) -> Option<(f64, f64)> {
|
||||
let a = p.geo_anchor.as_ref()?;
|
||||
Some((a.lv95.e - a.model.x, a.lv95.n - a.model.y))
|
||||
}
|
||||
|
||||
/// Kopie mit Geometrie in realen Weltkoordinaten (LV95) für Modell-Exporte; ohne Bezug unverändert.
|
||||
pub fn project_to_world_coords(p: &Project) -> Project {
|
||||
match project_geo_origin(p) {
|
||||
Some((e, n)) => translate_project(p, e, n),
|
||||
None => p.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn verschiebt_alles_und_haelt_den_anker() {
|
||||
let mut p: Project = serde_json::from_str(include_str!("../tests/fixtures/sample_project.json")).unwrap();
|
||||
p.geo_anchor = Some(ProjectGeoAnchor { lv95: ProjectGeoAnchorLv95 { e: 2_600_000.0, n: 1_200_000.0, ..Default::default() }, model: Vec2 { x: 1.0, y: 2.0 }, ..Default::default() });
|
||||
let w = project_to_world_coords(&p);
|
||||
assert_eq!(w.walls[0].start.x, p.walls[0].start.x + 2_599_999.0);
|
||||
assert_eq!(w.walls[0].start.y, p.walls[0].start.y + 1_199_998.0);
|
||||
// Der Anker wandert mit: das verschobene Modell liegt bereits in Landeskoordinaten (Ursprung 0, 0).
|
||||
assert_eq!(project_geo_origin(&w), Some((0.0, 0.0)));
|
||||
assert_eq!(project_to_world_coords(&Project { geo_anchor: None, ..p.clone() }), Project { geo_anchor: None, ..p });
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,8 @@
|
||||
//!
|
||||
//! Datenübergabe: flache `f64`-Puffer (s. [`flat`]), kein JSON — schnell und ohne Serde-Kosten.
|
||||
|
||||
pub mod export_ifc;
|
||||
pub mod export_mesh;
|
||||
pub mod export_schedule;
|
||||
pub mod flat;
|
||||
pub mod geo_rebase;
|
||||
pub mod flat_write;
|
||||
pub mod polygon_bool;
|
||||
pub mod roof;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! antwortet. TS ruft sie über `ProjectDocument.query(name, args, text)`.
|
||||
|
||||
use crate::model::Project;
|
||||
use crate::{export_mesh, export_schedule, kennzahlen, model3d, site_rules, sun};
|
||||
use crate::{export_schedule, kennzahlen, model3d, site_rules, sun};
|
||||
|
||||
fn json<T: serde::Serialize>(v: &T) -> Result<String, String> {
|
||||
serde_json::to_string(v).map_err(|e| e.to_string())
|
||||
@@ -28,8 +28,6 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
("roofCutLayers", _) => json(&model3d::emit_roof_cut_layers(p)?),
|
||||
("scheduleRows", _) => json(&export_schedule::schedule_rows(p)),
|
||||
("scheduleCsv", 1) => Ok(export_schedule::export_schedule_csv(p, text, args[0] != 0.0)),
|
||||
("objFile", _) => Ok(export_mesh::export_obj(p)?),
|
||||
("stlFile", _) => Ok(export_mesh::export_stl(p)?),
|
||||
("pickGeometry", _) => json(&model3d::pick_geometry(p)?),
|
||||
("model3dParts", 3) => json(&model3d::parts(p, args[0] != 0.0, args[1], args[2] != 0.0)?),
|
||||
_ => Err(format!("Unbekannte Abfrage: {name}")),
|
||||
|
||||
@@ -91,20 +91,6 @@ pub fn doc_drawing_line_verts(h: u32) -> Vec<f32> {
|
||||
with_doc(h, |d| d.project().ok().map(|p| crate::model3d::drawing_line_verts(&p))).flatten().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// IFC4-Datei des Projekts (`now_ms`: Zeitpunkt des Exports); Fehler mit vorangestelltem `\u{1}`.
|
||||
#[wasm_bindgen]
|
||||
pub fn doc_export_ifc(h: u32, now_ms: f64) -> String {
|
||||
let result = with_doc(h, |d| {
|
||||
let p = d.project().map_err(|e| format!("Projekt passt nicht zum Kern-Modell: {e}"))?;
|
||||
crate::export_ifc::export_ifc_spf(p, now_ms)
|
||||
})
|
||||
.unwrap_or_else(|| Err("Dokument nicht offen".to_string()));
|
||||
match result {
|
||||
Ok(text) => text,
|
||||
Err(e) => format!("\u{1}{e}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Das Projekt als Datei-Text (Formatversion vorn, Einrückung 2); leer, wenn das Dokument nicht offen ist.
|
||||
#[wasm_bindgen]
|
||||
pub fn doc_serialize(h: u32) -> String {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
//! Bindungen kleiner IFC-Bausteine (`crate::export_ifc`); die Datei selbst liefert `doc_export_ifc`.
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// Deterministische 22-stellige IFC-GUID aus einer Element-ID.
|
||||
#[wasm_bindgen]
|
||||
pub fn ifc_guid(id: &str) -> String {
|
||||
crate::export_ifc::ifc_guid(id)
|
||||
}
|
||||
|
||||
/// STEP-String-Literal (ISO 10303-21) mit Escapes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ifc_string(s: &str) -> String {
|
||||
crate::export_ifc::ifc_string(s)
|
||||
}
|
||||
@@ -25,7 +25,6 @@ mod plan_stairs;
|
||||
mod plan_walls;
|
||||
mod plan_openings;
|
||||
mod delaunay;
|
||||
mod export_ifc;
|
||||
mod document;
|
||||
mod mesh_section;
|
||||
mod plan_elevation;
|
||||
|
||||
@@ -27,8 +27,6 @@ export type QueryName =
|
||||
| "roofCutLayers"
|
||||
| "scheduleRows"
|
||||
| "scheduleCsv"
|
||||
| "objFile"
|
||||
| "stlFile"
|
||||
| "pickGeometry"
|
||||
| "model3dParts";
|
||||
|
||||
@@ -86,14 +84,6 @@ export class ProjectDocument {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** IFC4-Datei (STEP-Text) des Projekts; `nowMs` = Zeitpunkt des Exports. */
|
||||
exportIfc(nowMs: number): string {
|
||||
if (!this.handle) throw new Error("IFC-Export: Dokument nicht offen");
|
||||
const out = core().doc_export_ifc(this.handle, nowMs);
|
||||
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Datei-Text des Projekts (Formatversion vorn, Einrückung 2). */
|
||||
serialize(): string {
|
||||
return this.handle ? core().doc_serialize(this.handle) : "";
|
||||
|
||||
@@ -109,7 +109,6 @@ import { isWatertight, wallCutMeshes, type CutMesh } from "../plan/wallMeshCut";
|
||||
import { evaluateRoom } from "../geometry/roomArea";
|
||||
import { columnFootprint } from "../geometry/column";
|
||||
import { openingInterval, openingVerticalExtent } from "../geometry/opening";
|
||||
import { emitRoofs } from "../plan/toWalls3d";
|
||||
import { fileio } from "../engine/fileioWasm";
|
||||
import { lv95ToWgs84 } from "../io/lv95";
|
||||
import { fillParams, type FillParams } from "./ifcOpenings";
|
||||
@@ -126,6 +125,7 @@ import {
|
||||
} from "./ifcQuantities";
|
||||
import { roofBaseElevation, roofGeometry } from "../geometry/roof";
|
||||
import { SIA_CATEGORIES, balance, siaLabel, type SiaCategory } from "../geometry/roomArea";
|
||||
import { emitRoofs } from "./model3dParts";
|
||||
import {
|
||||
EBKPH_SYSTEM,
|
||||
LAYER_SYSTEM,
|
||||
|
||||
@@ -7,10 +7,7 @@ import { exportGlb, exportGltf, exportObj, exportStl } from "./exportMesh";
|
||||
import { orientOutward } from "./meshOrient";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { Column, ImportedMesh, Project, TerrainMesh } from "../model/types";
|
||||
import { emitOpeningMeshes } from "../plan/toWalls3d";
|
||||
import { emitRoofs } from "../plan/toWalls3d";
|
||||
import { emitColumns } from "../plan/toWalls3d";
|
||||
import { emitStairMeshes, emitStairRailings, emitStairs } from "../plan/toWalls3d";
|
||||
import { emitColumns, emitOpeningMeshes, emitRoofs, emitStairMeshes, emitStairRailings, emitStairs } from "./model3dParts";
|
||||
|
||||
interface Gltf {
|
||||
nodes: { name: string; mesh?: number; children?: number[]; extras?: { type: string; id: string } }[];
|
||||
|
||||
@@ -49,14 +49,11 @@ import { pickGeometry } from "../plan/toWalls3d";
|
||||
import type { RWall } from "../plan/toWalls3d";
|
||||
import { wallCutMeshes, type CutMesh } from "../plan/wallMeshCut";
|
||||
import { triangulate } from "../plan/glPlan/glPlanCompile";
|
||||
import { emitOpeningMeshes } from "../plan/toWalls3d";
|
||||
import { emitRoofs } from "../plan/toWalls3d";
|
||||
import { emitColumns } from "../plan/toWalls3d";
|
||||
import { emitStairMeshes, emitStairRailings, emitStairs } from "../plan/toWalls3d";
|
||||
import type { RMesh } from "../plan/toWalls3d/shared";
|
||||
import { IMPORTED_RGB, TERRAIN_RGB, hexToRgb } from "../plan/toWalls3d/shared";
|
||||
import { fileio } from "../engine/fileioWasm";
|
||||
import { orientOutward } from "./meshOrient";
|
||||
import { emitColumns, emitOpeningMeshes, emitRoofs, emitStairMeshes, emitStairRailings, emitStairs } from "./model3dParts";
|
||||
|
||||
/**
|
||||
* Ein Teil-Mesh mit EINEM Material und LOKALEN (0-basierten) Vertex-/Dreiecks-Indizes. Der Rust-Schreiber
|
||||
|
||||
@@ -13,10 +13,10 @@ import type { Project, Stair, Vec2 } from "../model/types";
|
||||
import { getStairType } from "../model/types";
|
||||
import { stairVerticalExtent } from "../model/wall";
|
||||
import { stairGeometry } from "../geometry/stair";
|
||||
import { emitStairMeshes, emitStairRailings, emitStairs } from "../plan/toWalls3d";
|
||||
import type { RSlab } from "../plan/toWalls3d";
|
||||
import { orientOutward } from "./meshOrient";
|
||||
import { flightQuantities, meshVolume, railingQuantities, ringArea, slabQuantities, type Qty } from "./ifcQuantities";
|
||||
import { emitStairMeshes, emitStairRailings, emitStairs } from "./model3dParts";
|
||||
|
||||
/** Ein Prisma (Profil in Welt-XY, Unterkante relativ zum Geschoss, Tiefe). */
|
||||
export interface StairSolid {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// 3D-Teile einzelner Bauteile für die Exporte (OBJ/STL/glTF, IFC): dieselben Ableitungen wie das 3D,
|
||||
// gerechnet im Kern auf dem Projekt-Dokument (`queries.rs`, [K4]). Die Exporte rufen sie je Bauteil
|
||||
// mit einem Ein-Bauteil-Projekt auf (die Ableitungen liefern keine ids); damit das gemeinsame
|
||||
// Dokument der App nicht bei jedem Aufruf umgebaut wird, bekommt jeder Aufruf ein eigenes, kurzlebiges
|
||||
// Dokument.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import type { RMesh, RSlab } from "../plan/toWalls3d/shared";
|
||||
import { ProjectDocument, type QueryName } from "../core/document";
|
||||
|
||||
const DETAIL_CODE: Record<string, number> = { grob: 0, mittel: 1, fein: 2 };
|
||||
|
||||
function queryOnce<T>(project: Project, name: QueryName, args: number[] = [], text = ""): T {
|
||||
const doc = new ProjectDocument(project);
|
||||
try {
|
||||
return doc.query<T>(name, args, text);
|
||||
} finally {
|
||||
doc.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** Dach-Meshes (geschlossene Schicht-Körper je Dach). */
|
||||
export function emitRoofs(project: Project): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "roofMeshes");
|
||||
}
|
||||
|
||||
/** Stützen als Profil-Extrusionen. */
|
||||
export function emitColumns(project: Project): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "columnMeshes");
|
||||
}
|
||||
|
||||
/** Öffnungs-Einbauteile (Rahmen, Glas, Blatt) im Detailgrad `detail`. */
|
||||
export function emitOpeningMeshes(project: Project, detail: "grob" | "mittel" | "fein" = "fein"): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "openingMeshes", [DETAIL_CODE[detail] ?? 2]);
|
||||
}
|
||||
|
||||
/** Treppentritte (und Podeste) als extrudierte Platten; `forSection` wie im Schnitt. */
|
||||
export function emitStairs(project: Project, forSection = false): RSlab[] {
|
||||
return queryOnce<RSlab[]>(project, "stairSlabs", [forSection ? 1 : 0]);
|
||||
}
|
||||
|
||||
/** Glatte Ortbeton-Laufplatten. */
|
||||
export function emitStairMeshes(project: Project): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "stairMeshes");
|
||||
}
|
||||
|
||||
/** Handläufe und Pfosten. */
|
||||
export function emitStairRailings(project: Project): RMesh[] {
|
||||
return queryOnce<RMesh[]>(project, "stairRailings");
|
||||
}
|
||||
@@ -107,36 +107,6 @@ export function roofMeshes(project: Project, onlyRoofId?: string): RMesh[] {
|
||||
return documentFor(project).query<RMesh[]>("roofMeshes", [], onlyRoofId ?? "");
|
||||
}
|
||||
|
||||
/** Einbauteile der Öffnungen als Quader-Meshes (Kern); für Exporter, die je Bauteil ein Mini-Projekt übergeben. */
|
||||
export function emitOpeningMeshes(project: Project, detail: DetailLevel = "fein"): RMesh[] {
|
||||
return documentFor(project).query<RMesh[]>("openingMeshes", [DETAIL_CODE[detail] ?? 2]);
|
||||
}
|
||||
|
||||
/** Stützen-Meshes (Kern). */
|
||||
export function emitColumns(project: Project): RMesh[] {
|
||||
return documentFor(project).query<RMesh[]>("columnMeshes");
|
||||
}
|
||||
|
||||
/** Dach-Meshes aller Dächer des Projekts (Kern). */
|
||||
export function emitRoofs(project: Project): RMesh[] {
|
||||
return roofMeshes(project);
|
||||
}
|
||||
|
||||
/** Treppen-Tritte/Podeste als Prismen (Kern); `forSection`: auch gerade Betontreppen. */
|
||||
export function emitStairs(project: Project, opts: { forSection?: boolean } = {}): RSlab[] {
|
||||
return documentFor(project).query<RSlab[]>("stairSlabs", [opts.forSection ? 1 : 0]);
|
||||
}
|
||||
|
||||
/** Glatte Ortbeton-Laufplatten (Kern). */
|
||||
export function emitStairMeshes(project: Project): RMesh[] {
|
||||
return documentFor(project).query<RMesh[]>("stairMeshes");
|
||||
}
|
||||
|
||||
/** Treppen-Handläufe (Kern). */
|
||||
export function emitStairRailings(project: Project): RMesh[] {
|
||||
return documentFor(project).query<RMesh[]>("stairRailings");
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionen für {@link projectToModel3d}. `layeredWalls` steuert, ob eine
|
||||
* mehrschichtige Wand als eigene Box je Materiallage (Default, 3D-Viewer) oder
|
||||
|
||||
Reference in new issue
Block a user