[115][G1][180] 3D: freie Körper aus den Kern-Netzen statt truck
Eine Quelle für die Geometrie freier Körper: 3D-Bild, Pick, Explosion, Abzugskörper an Wänden/Decken und die Kennwerte der Objekt-Info nehmen dieselben Kern-Netze (solid_mesh.rs, Manifold) wie Grundriss, Schnitt und Ansicht. - model3d/solids.rs: Teil solidMeshes (Owner::Solid für den Klassen-Filter, Farbe/Textur aus componentId, glatt schattiert), 3D-Facettierung mindestens 48 je Vollkreis (Fugen unter dem 15°-Kantenwinkel von render3d), Explosion hebt mit dem Geschoss. - pick_solids: Dreiecke des Kern-Netzes statt Prisma-Näherung. - solid_specs::void_meshes: Wand/Decke minus Abzugskörper im Kern (Teil voidMeshes) statt truck-Boolean in TS. - Abfrage solidProps (Volumen, Oberfläche, Schwerpunkt) statt truck. - Volle Verjüngung ergibt eine Pyramide (Netz-Spezifikation). - Entfernt: toWalls3d/extrusions.ts, TRUCK_MESH_READY_EVENT, truck-Wrapper extrudePolygon/extrudeCircle/buildSolidMesh, needsBrepPath. truck bleibt für STEP und Kollisionsprüfung. - Golden komplex-model3d: drei Körper neu im Modell.
This commit is contained in:
38 files changed
+507
-505
No files matched your search
@@ -39,12 +39,12 @@ Neues Modul: `<modul>.rs` und `mod` in `lib.rs`, Bindungen in `web/<modul>.rs` u
|
||||
|
||||
| Datei | Inhalt |
|
||||
|---|---|
|
||||
| `model3d/` | 3D-Ableitung aus dem Projekt: `parts()` in `mod.rs`; je eine Datei für Decken, Stützen und Bäume, Wände, Öffnungen, Treppen, Dächer, Kontext, Zeichnungs-Spuren, Pick-Geometrie, Klassen-Filter (`classes.rs`, [180]); Tests in `tests.rs` |
|
||||
| `model3d/` | 3D-Ableitung aus dem Projekt: `parts()` in `mod.rs`; je eine Datei für Decken, Stützen und Bäume, Wände, Öffnungen, Treppen, Dächer, Kontext, freie Körper (`solids.rs`, [115]), Zeichnungs-Spuren, Pick-Geometrie, Klassen-Filter (`classes.rs`, [180]); Tests in `tests.rs` |
|
||||
| `model3d_cache.rs` | inkrementelle 3D-Ableitung (Cache je Wand und Öffnung) |
|
||||
| `wall_bands.rs`, `wall_mesh_cut.rs` | Schichtbänder einer Wand; Wandnetz mit echtem Loch für Datei-Exporte |
|
||||
| `ceilings3d.rs`, `columns3d.rs`, `stairs3d.rs`, `openings3d.rs`, `drawing2d_3d.rs`, `mesh3d.rs` | Netze je Bauteilart |
|
||||
| `explode3d.rs`, `highlight3d.rs`, `surface_pattern3d.rs` | Explosionsaxonometrie, Auswahl-Umrisse, Ansichtsschraffur auf 3D-Flächen |
|
||||
| `solid_bool.rs`, `solid_specs.rs`, `solid_mesh.rs` | Körper-Booleans über Manifold; B-Rep-Spezifikationen für truck; Netze der freien Körper für Schnitt/Ansicht ([115]) |
|
||||
| `solid_bool.rs`, `solid_specs.rs`, `solid_mesh.rs` | Körper-Booleans über Manifold; B-Rep-Spezifikationen für truck; Netze der freien Körper für Grundriss, Schnitt, Ansicht, 3D und Kennwerte ([115]) |
|
||||
|
||||
## Geometrie
|
||||
|
||||
|
||||
@@ -96,7 +96,21 @@ pub fn extruded_solid_spec(solid: &Value, floor_z: f64) -> Option<Value> {
|
||||
),
|
||||
]));
|
||||
}
|
||||
None
|
||||
// [115] Volle Verjüngung: Pyramide über dem Profil (Spitze über dem Punkt-Schwerpunkt) als Netz.
|
||||
let n = pts.len();
|
||||
let ccw = (0..n).map(|i| pts[i].0 * pts[(i + 1) % n].1 - pts[(i + 1) % n].0 * pts[i].1).sum::<f64>() >= 0.0;
|
||||
let ring: Vec<V> = if ccw { pts.clone() } else { pts.iter().rev().copied().collect() };
|
||||
let (cx, cy) = (ring.iter().fold(0.0, |a, p| a + p.0) / n as f64, ring.iter().fold(0.0, |a, p| a + p.1) / n as f64);
|
||||
let mut pos: Vec<f64> = ring.iter().flat_map(|p| [p.0, p.1, base_z]).collect();
|
||||
pos.extend([cx, cy, base_z + height]);
|
||||
let mut idx: Vec<usize> = Vec::new();
|
||||
for t in crate::solid_bool::ear_clip(&ring.iter().map(|p| [p.0, p.1]).collect::<Vec<_>>()) {
|
||||
idx.extend([t[0], t[2], t[1]]);
|
||||
}
|
||||
for i in 0..n {
|
||||
idx.extend([i, (i + 1) % n, n]);
|
||||
}
|
||||
Some(obj(vec![("kind", s("mesh")), ("positions", Value::Array(pos.into_iter().map(js_num).collect())), ("indices", Value::Array(idx.into_iter().map(|i| json!(i)).collect()))]))
|
||||
}
|
||||
|
||||
// ═════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -146,6 +146,7 @@ pub fn parts_filtered(p: &Project, layered: bool, detail: f64, for_section: bool
|
||||
walls,
|
||||
slabs,
|
||||
context_meshes: model3d::emit_context_meshes(p),
|
||||
solid_meshes: model3d::emit_solids(p),
|
||||
column_meshes: vec![],
|
||||
opening_meshes: vec![],
|
||||
stair_meshes: vec![],
|
||||
@@ -187,10 +188,16 @@ pub fn parts_filtered(p: &Project, layered: bool, detail: f64, for_section: bool
|
||||
filter.retain_walls(&mut out);
|
||||
out.slabs.retain(|s| !filter.hides(&s.ceiling_id));
|
||||
out.context_meshes.retain(|m| filter.keep_owner(p, m.owner));
|
||||
// [115] Freie Körper heben sich mit ihrem Geschoss.
|
||||
out.solid_meshes.retain(|m| filter.keep_owner(p, m.owner));
|
||||
for m in &mut out.solid_meshes {
|
||||
let dz = m.owner.id(p).map_or(0.0, |id| ex.of(id));
|
||||
shift_mesh(m, dz);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Versatz je Geschoss-id (für die TS-seitigen truck-Extrusionen, `levelId`).
|
||||
/// Versatz je Geschoss-id (3D-Griffe und Arbeitsebene, `levelId`).
|
||||
pub fn floor_offsets(p: &Project, gap: f64) -> HashMap<String, f64> {
|
||||
Explode::new(p, gap).map(|ex| ex.by_floor.iter().map(|(k, v)| (k.to_string(), *v)).collect()).unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -4520,9 +4520,9 @@ pub struct ExtrudedSolidBrep {
|
||||
|
||||
// ── Extrudierter Körper (truck-Integration, docs/design/truck-plan.md) ─────
|
||||
// Ein per `extrude`-Befehl aus einem geschlossenen 2D-Profil (Polylinie-Ring/
|
||||
// Rechteck) erzeugter 3D-Körper. Die eigentliche B-Rep-Extrusion (truck-WASM,
|
||||
// `engine/truckSolid.ts`) läuft NICHT hier, sondern asynchron in
|
||||
// `toWalls3d.ts` (emitExtrudedSolids) — dieser Typ hält nur die Rohdaten.
|
||||
// Rechteck) erzeugter 3D-Körper. Die Beschreibung baut `cmd_solid::extruded_solid_spec`, das Netz
|
||||
// für Grundriss, Schnitt, Ansicht und 3D `solid_mesh.rs` ([115]), STEP truck — dieser Typ hält nur
|
||||
// die Rohdaten.
|
||||
|
||||
/// Ein extrudierter Körper: geschlossenes Profil (Modell-Meter) + Höhe.
|
||||
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, TS)]
|
||||
@@ -4540,7 +4540,7 @@ pub struct ExtrudedSolid {
|
||||
/// Geschlossenes Profil in der XY-Ebene (Grundriss), ≥3 Punkte. Bei einem
|
||||
/// Kreis-Profil (`circle` gesetzt) eine Tessellierung des Kreises (48-Eck) —
|
||||
/// für 2D-Footprint/Auswahl/bbox/Verschieben; die 3D-Extrusion nutzt in dem
|
||||
/// Fall stattdessen `circle` (echte runde truck-Extrusion, `extrudeCircle`).
|
||||
/// Fall stattdessen `circle` (Zylinder bzw. Kegel, `solid_mesh.rs`).
|
||||
pub points: Vec<Vec2>,
|
||||
/// Extrusionshöhe in Metern (> 0), nach +Z ab der Geschoss-UK.
|
||||
pub height: f64,
|
||||
@@ -4550,7 +4550,7 @@ pub struct ExtrudedSolid {
|
||||
pub base_offset: Option<f64>,
|
||||
/// Boolesche Rolle im Gebäude: "subtract" = Abzugskörper (Aussparung/Durchbruch/Nische).
|
||||
/// Er zieht sich von allen Wänden, Decken und Stützen ab, die er durchdringt — in 3D
|
||||
/// (truck-Boolean), im Grundriss und im Schnitt; selbst wird er nur als Umriss gezeigt.
|
||||
/// (Manifold-Boolean im Kern), im Grundriss und im Schnitt; selbst wird er nur als Umriss gezeigt.
|
||||
/// Fehlt = normaler Körper.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional, type = "\"subtract\"")]
|
||||
@@ -4561,8 +4561,8 @@ pub struct ExtrudedSolid {
|
||||
#[ts(optional)]
|
||||
pub site_projection: Option<bool>,
|
||||
/// Gesetzt, wenn das Profil ein Kreis ist (aus einem `Drawing2D` mit
|
||||
/// `shape:"circle"`) — `points` bleibt die Tessellierung, `toWalls3d.ts`
|
||||
/// (emitExtrudedSolids) nutzt `circle` für die runde 3D-Extrusion.
|
||||
/// `shape:"circle"`) — `points` bleibt die Tessellierung, der Kern
|
||||
/// (`solid_mesh.rs`) nutzt `circle` für den runden Körper.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional, inline)]
|
||||
pub circle: Option<ExtrudedSolidCircle>,
|
||||
|
||||
@@ -22,6 +22,8 @@ pub enum Owner {
|
||||
Tree(usize),
|
||||
Stair(usize),
|
||||
Context(usize),
|
||||
/// [115] Index in `Project::extruded_solids`.
|
||||
Solid(usize),
|
||||
}
|
||||
|
||||
impl Owner {
|
||||
@@ -37,6 +39,7 @@ impl Owner {
|
||||
Owner::Tree(i) => at(&p.trees, i).map(|e| e.id.as_str()),
|
||||
Owner::Stair(i) => at(&p.stairs, i).map(|e| e.id.as_str()),
|
||||
Owner::Context(i) => at(&p.context, i).map(|e| e.id()),
|
||||
Owner::Solid(i) => at(&p.extruded_solids, i).map(|e| e.id.as_str()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,7 +155,7 @@ impl ClassFilter {
|
||||
return;
|
||||
}
|
||||
parts.slabs.retain(|s| !self.hides(&s.ceiling_id));
|
||||
for list in [&mut parts.context_meshes, &mut parts.column_meshes, &mut parts.stair_meshes, &mut parts.stair_railings, &mut parts.roof_meshes] {
|
||||
for list in [&mut parts.context_meshes, &mut parts.solid_meshes, &mut parts.column_meshes, &mut parts.stair_meshes, &mut parts.stair_railings, &mut parts.roof_meshes] {
|
||||
list.retain(|m| self.keep_owner(p, m.owner));
|
||||
}
|
||||
parts.roof_layers.retain(|l| self.keep_owner(p, l.owner));
|
||||
@@ -195,6 +198,7 @@ pub fn parts_filtered(p: &Project, layered: bool, detail: f64, for_section: bool
|
||||
walls: emit_walls(p, layered)?,
|
||||
slabs,
|
||||
context_meshes: emit_context_meshes(p),
|
||||
solid_meshes: emit_solids(p),
|
||||
column_meshes: {
|
||||
let mut m = emit_columns(p);
|
||||
m.extend(emit_trees(p));
|
||||
|
||||
@@ -32,6 +32,7 @@ mod context;
|
||||
mod drawings;
|
||||
mod pick;
|
||||
mod classes;
|
||||
mod solids;
|
||||
|
||||
pub use ceilings::*;
|
||||
pub use columns::*;
|
||||
@@ -43,6 +44,7 @@ pub use context::*;
|
||||
pub use drawings::*;
|
||||
pub use pick::*;
|
||||
pub use classes::*;
|
||||
pub use solids::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -124,7 +126,7 @@ pub const DEFAULT_CREASE_DEG: f64 = 30.0;
|
||||
// ── Bündel ───────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
/// Das 3D-Modell in Teilen: TS fügt die truck-Körper (asynchron) zwischen Kontext und Stützen ein.
|
||||
/// Das 3D-Modell in Teilen.
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Parts {
|
||||
@@ -137,6 +139,8 @@ pub struct Parts {
|
||||
pub stair_railings: Vec<RMesh>,
|
||||
pub roof_meshes: Vec<RMesh>,
|
||||
pub roof_layers: Vec<RRoofLayer>,
|
||||
/// [115] Freie Körper (`extrudedSolids` ohne Abzugskörper) als Kern-Netze ([`emit_solids`]).
|
||||
pub solid_meshes: Vec<RMesh>,
|
||||
}
|
||||
|
||||
/// `detail`: 0 grob, 1 mittel, 2 fein.
|
||||
|
||||
@@ -101,7 +101,7 @@ pub struct PickGeometry {
|
||||
pub context_meshes: Vec<PickContextMesh>,
|
||||
/// [137] Stützen (vorher im 3D nicht anwählbar).
|
||||
pub columns: Vec<PickColumn>,
|
||||
/// [137] Freie Körper (Prisma-Näherung; TS ersetzt sie durch das truck-Netz).
|
||||
/// [137] Freie Körper (Dreiecke des Kern-Netzes, [115]).
|
||||
pub solids: Vec<PickSolid>,
|
||||
/// [137] Öffnungen in Dach/Decke/Gaube als Netz.
|
||||
#[serde(rename = "openingMeshes")]
|
||||
@@ -385,22 +385,28 @@ pub fn pick_hosted_openings(p: &Project) -> Vec<PickOpeningMesh> {
|
||||
out
|
||||
}
|
||||
|
||||
/// [137] Freie Körper (`extrudedSolids`, ohne Abzugskörper) als Prisma über dem Grundriss-Umriss: UK =
|
||||
/// Geschoss-UK + `baseOffset`, OK = UK + `height`. Näherung für Loft/Rotation/Abzug/Verjüngung — die Hülle
|
||||
/// (`pickGeometry` in `plan/toWalls3d.ts`) ersetzt die Dreiecke durch das truck-Netz, sobald es geladen ist.
|
||||
/// [137] Freie Körper (`extrudedSolids`, ohne Abzugskörper) als Welt-Dreiecke ihres 3D-Netzes aus dem Kern
|
||||
/// ([115], `solid_mesh::body_mesh_3d`, dasselbe Netz wie im Bild). Ohne Netz (unbaubare Beschreibung) das
|
||||
/// Prisma über dem Grundriss-Umriss (UK = Geschoss-UK + `baseOffset`, OK = UK + `height`).
|
||||
pub fn pick_solids(p: &Project) -> Vec<PickSolid> {
|
||||
let mut out = Vec::new();
|
||||
for s in p.extruded_solids.as_deref().unwrap_or(&[]) {
|
||||
if s.operation.as_deref() == Some("subtract") || !(s.height > 0.0) || s.points.len() < 3 {
|
||||
if s.operation.as_deref() == Some("subtract") || !(s.height > 0.0) {
|
||||
continue;
|
||||
}
|
||||
let z0 = solid_base_z(p, s);
|
||||
let foot: Vec<[f64; 2]> = s.points.iter().map(|q| [q.x, q.y]).collect();
|
||||
if !(z0.is_finite() && foot.iter().all(|q| q[0].is_finite() && q[1].is_finite())) {
|
||||
continue;
|
||||
}
|
||||
let (pos, idx) = crate::columns3d::prism(&foot, z0, z0 + s.height);
|
||||
let tris = extrusion_tris(&pos, &idx);
|
||||
let mesh = crate::solid_mesh::body_mesh_3d(p, s);
|
||||
let tris = match mesh.as_deref().and_then(Option::as_ref) {
|
||||
Some(m) => extrusion_tris(&m.positions, &m.indices),
|
||||
None => {
|
||||
let z0 = solid_base_z(p, s);
|
||||
let foot: Vec<[f64; 2]> = s.points.iter().map(|q| [q.x, q.y]).collect();
|
||||
if foot.len() < 3 || !(z0.is_finite() && foot.iter().all(|q| q[0].is_finite() && q[1].is_finite())) {
|
||||
continue;
|
||||
}
|
||||
let (pos, idx) = crate::columns3d::prism(&foot, z0, z0 + s.height);
|
||||
extrusion_tris(&pos, &idx)
|
||||
}
|
||||
};
|
||||
if !tris.is_empty() {
|
||||
out.push(PickSolid { tris, solid_id: s.id.clone() });
|
||||
}
|
||||
@@ -408,7 +414,7 @@ pub fn pick_solids(p: &Project) -> Vec<PickSolid> {
|
||||
out
|
||||
}
|
||||
|
||||
/// UK eines freien Körpers (Geschoss-UK + `baseOffset`), wie `emitExtrudedSolids`.
|
||||
/// UK eines freien Körpers (Geschoss-UK + `baseOffset`).
|
||||
pub fn solid_base_z(p: &Project, s: &ExtrudedSolid) -> f64 {
|
||||
p.floor(&s.level_id).map_or(0.0, |f| f.base_elevation.unwrap_or(0.0)) + s.base_offset.unwrap_or(0.0)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
//! [115] Freie Körper (`extrudedSolids`) im 3D: das Netz aus dem Kern (`solid_mesh::body_mesh_3d`, dieselbe
|
||||
//! B-Rep-Beschreibung wie Grundriss, Schnitt, Ansicht und STEP), Farbe und Textur aus dem Bauteil
|
||||
//! (`componentId`), sonst das Körper-Orange. Abzugskörper sind kein Material (sie wirken über
|
||||
//! `solid_specs::void_cuts` auf Wände und Decken). Ersetzt die früheren asynchronen truck-Netze der TS-Seite.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Körper ohne Bauteil: warmes Orange (hebt sie von Wand/Decke/Kontext ab, wie bisher im 3D).
|
||||
pub const SOLID_RGB: Rgb = [0.85, 0.55, 0.25];
|
||||
/// Knickwinkel (Grad) der glatten Schattierung: Facetten gekrümmter Flächen glatt, echte Kanten scharf.
|
||||
const SOLID_CREASE_DEG: f64 = 30.0;
|
||||
|
||||
/// Die freien Körper als Netze (Modell-Meter, z = Höhe), Herkunft `Owner::Solid(Index)`.
|
||||
pub fn emit_solids(p: &Project) -> Vec<RMesh> {
|
||||
let maps = material_color_maps(p, None);
|
||||
let mut out = Vec::new();
|
||||
for (i, s) in p.extruded_solids.as_deref().unwrap_or(&[]).iter().enumerate() {
|
||||
if s.operation.as_deref() == Some("subtract") || !(s.height > 0.0) {
|
||||
continue;
|
||||
}
|
||||
let Some(m) = crate::solid_mesh::body_mesh_3d(p, s) else { continue };
|
||||
let Some(m) = m.as_ref() else { continue };
|
||||
let comp = s.component_id.as_deref().filter(|c| !c.is_empty());
|
||||
let color = comp.and_then(|c| p.component(c)).map_or(SOLID_RGB, |c| hex_to_rgb(&c.color, SOLID_RGB));
|
||||
let material_index = comp.and_then(|c| material_layer(p, &maps, c));
|
||||
out.push(RMesh {
|
||||
positions: m.positions.clone(),
|
||||
indices: m.indices.clone(),
|
||||
kind: "extrusion",
|
||||
color,
|
||||
vertex_colors: None,
|
||||
material_index,
|
||||
crease_angle: Some(SOLID_CREASE_DEG),
|
||||
owner: Owner::Solid(i),
|
||||
});
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Zwei Geschosse, ein Zylinder-Körper (OG, Klasse 40, Bauteil „holz"), ein Quader (EG, ohne Bauteil), ein
|
||||
/// Abzugskörper und eine Wand, die er trifft.
|
||||
fn project(hidden: &[&str]) -> Project {
|
||||
let layers: Vec<serde_json::Value> = ["20", "40", "41"].iter().map(|c| serde_json::json!({"code": c, "name": c, "color": "#000000", "visible": !hidden.contains(c)})).collect();
|
||||
let sq = |x: f64, y: f64, s: f64| serde_json::json!([{"x": x, "y": y}, {"x": x + s, "y": y}, {"x": x + s, "y": y + s}, {"x": x, "y": y + s}]);
|
||||
serde_json::from_value(serde_json::json!({
|
||||
"id": "p", "name": "t", "lineStyles": [], "hatches": [], "wallTypes": [], "layers": layers, "openings": [],
|
||||
"components": [{"id": "holz", "name": "Holz", "color": "#336699", "hatchId": "", "joinPriority": 5}],
|
||||
"drawingLevels": [
|
||||
{"id": "EG", "name": "EG", "kind": "floor", "visible": true, "locked": false, "floorHeight": 3.0, "baseElevation": 0.0},
|
||||
{"id": "OG", "name": "OG", "kind": "floor", "visible": true, "locked": false, "floorHeight": 3.0, "baseElevation": 3.0}],
|
||||
"walls": [{"id": "w1", "type": "wall", "floorId": "EG", "categoryCode": "20", "start": {"x": 0, "y": 10}, "end": {"x": 6, "y": 10}, "wallTypeId": "", "height": 2.8}],
|
||||
"extrudedSolids": [
|
||||
{"id": "zyl", "type": "extrudedSolid", "levelId": "OG", "categoryCode": "40", "componentId": "holz", "points": [], "circle": {"center": {"x": 2, "y": 2}, "r": 0.5}, "height": 1.0},
|
||||
{"id": "box", "type": "extrudedSolid", "levelId": "EG", "categoryCode": "41", "points": sq(5.0, 0.0, 1.0), "height": 2.0},
|
||||
{"id": "loch", "type": "extrudedSolid", "levelId": "EG", "categoryCode": "41", "points": sq(2.0, 9.5, 1.0), "height": 2.0, "baseOffset": 0.5, "operation": "subtract"}]
|
||||
}))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn solid_ids(p: &Project, parts: &Parts) -> Vec<String> {
|
||||
parts.solid_meshes.iter().filter_map(|m| m.owner.id(p).map(String::from)).collect()
|
||||
}
|
||||
|
||||
/// [115] Freie Körper reisen als Kern-Netz in den 3D-Teilen: Herkunft, Farbe aus dem Bauteil, glatt
|
||||
/// schattiert, feine Facetten (Fugen unter dem Kantenwinkel), ohne Abzugskörper.
|
||||
#[test]
|
||||
fn parts_enthalten_freie_koerper_als_netz() {
|
||||
let p = project(&[]);
|
||||
let parts = parts(&p, true, 2.0, false).unwrap();
|
||||
assert_eq!(solid_ids(&p, &parts), ["zyl", "box"]);
|
||||
let zyl = &parts.solid_meshes[0];
|
||||
assert_eq!(zyl.color, hex_to_rgb("#336699", SOLID_RGB));
|
||||
assert_eq!(parts.solid_meshes[1].color, SOLID_RGB);
|
||||
assert!(zyl.crease_angle.is_some());
|
||||
// Zylinder r 0.5 auf dem OG (UK 3, OK 4): ≥ 48 Ecken auf dem Umfang.
|
||||
let zs: Vec<f64> = zyl.positions.chunks_exact(3).map(|q| q[2]).collect();
|
||||
assert!(zs.iter().all(|z| (z - 3.0).abs() < 1e-9 || (z - 4.0).abs() < 1e-9), "{zs:?}");
|
||||
assert!(zs.iter().filter(|z| (*z - 3.0).abs() < 1e-9).count() >= crate::solid_mesh::MIN_SEG_3D);
|
||||
let m = crate::solid_bool::Mesh { positions: zyl.positions.clone(), indices: zyl.indices.clone() };
|
||||
let exact = std::f64::consts::PI * 0.25;
|
||||
assert!(m.is_closed() && (m.volume() - exact).abs() < 0.01 * exact, "{}", m.volume());
|
||||
// JSON-Teil `solidMeshes` (der Kern-Cache schreibt denselben Text, s. model3d_cache-Tests).
|
||||
let v = serde_json::to_value(&parts).unwrap();
|
||||
assert_eq!(v["solidMeshes"].as_array().unwrap().len(), 2);
|
||||
}
|
||||
|
||||
/// [180] Klasse aus ⇒ Körper fehlt im 3D und im Pick; Explosion hebt ihn mit seinem Geschoss.
|
||||
#[test]
|
||||
fn klasse_und_explosion() {
|
||||
for (q, text) in [(project(&["40"]), String::new()), (project(&[]), r#"{"hide":["40"]}"#.to_string())] {
|
||||
let f = ClassFilter::from_text(&q, &text);
|
||||
let parts = parts_filtered(&q, true, 2.0, false, &f).unwrap();
|
||||
assert_eq!(solid_ids(&q, &parts), ["box"]);
|
||||
let ex = crate::explode3d::parts_filtered(&q, true, 2.0, false, 2.0, &f).unwrap();
|
||||
assert_eq!(solid_ids(&q, &ex), ["box"]);
|
||||
let mut g = crate::explode3d::pick_geometry(&q, 0.0).unwrap();
|
||||
f.retain_pick(&mut g);
|
||||
assert_eq!(g.solids.iter().map(|s| s.solid_id.as_str()).collect::<Vec<_>>(), ["box"]);
|
||||
}
|
||||
let p = project(&[]);
|
||||
let ex = crate::explode3d::parts(&p, true, 2.0, false, 2.0).unwrap();
|
||||
let dz = crate::explode3d::floor_offsets(&p, 2.0)["OG"];
|
||||
assert!(dz > 0.0);
|
||||
let zmin = ex.solid_meshes[0].positions.chunks_exact(3).map(|q| q[2]).fold(f64::INFINITY, f64::min);
|
||||
assert!((zmin - 3.0 - dz).abs() < 1e-9, "{zmin}");
|
||||
// Pick: Dreiecke des Netzes (Welt: x, Höhe, y), angehoben wie das Bild.
|
||||
let g = crate::explode3d::pick_geometry(&p, 2.0).unwrap();
|
||||
let zyl = g.solids.iter().find(|s| s.solid_id == "zyl").unwrap();
|
||||
assert_eq!(zyl.tris.len(), ex.solid_meshes[0].indices.len() / 3);
|
||||
let hmin = zyl.tris.iter().flatten().map(|v| v[1]).fold(f64::INFINITY, f64::min);
|
||||
assert!((hmin - 3.0 - dz).abs() < 1e-9, "{hmin}");
|
||||
}
|
||||
|
||||
/// [115] Abzugskörper schneiden Wände im Kern (Netz statt truck-Spezifikation); Kennwerte aus dem Kern-Netz.
|
||||
#[test]
|
||||
fn abzug_als_netz_und_kennwerte() {
|
||||
let p = project(&[]);
|
||||
let parts = parts(&p, false, 2.0, false).unwrap();
|
||||
let cuts = crate::solid_specs::void_cuts(&p, &parts.walls, &parts.slabs);
|
||||
assert_eq!(cuts.walls.len(), 1);
|
||||
let vm = crate::solid_specs::void_meshes(&cuts, &parts.walls, &parts.slabs);
|
||||
assert_eq!(vm.walls.len(), 1);
|
||||
let (i, _, m) = &vm.walls[0];
|
||||
let w = &parts.walls[*i];
|
||||
assert_eq!(m.color, w.color);
|
||||
let mesh = crate::solid_bool::Mesh { positions: m.positions.clone(), indices: m.indices.clone() };
|
||||
let full = 6.0 * w.thickness * 2.8;
|
||||
assert!((mesh.volume() - (full - w.thickness * 1.0 * 2.0)).abs() < 1e-6, "{}", mesh.volume());
|
||||
let box_props = crate::solid_mesh::solid_props(&p, "box").unwrap();
|
||||
assert!((box_props.volume - 2.0).abs() < 1e-9 && (box_props.area - 10.0).abs() < 1e-9 && box_props.closed);
|
||||
assert!((box_props.centroid[0] - 5.5).abs() < 1e-9 && (box_props.centroid[2] - 1.0).abs() < 1e-9);
|
||||
assert!(crate::solid_mesh::solid_props(&p, "nix").is_none());
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,14 @@ pub fn material_color_maps(p: &Project, only_roof: Option<&str>) -> Vec<String>
|
||||
}
|
||||
}
|
||||
}
|
||||
// [115] Freie Körper mit Bauteil (nicht beim Dach-Export).
|
||||
if only_roof.is_none() {
|
||||
for s in p.extruded_solids.as_deref().unwrap_or(&[]) {
|
||||
if let Some(c) = s.component_id.as_deref().filter(|c| !c.is_empty()) {
|
||||
consider(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
list
|
||||
}
|
||||
|
||||
|
||||
@@ -312,6 +312,7 @@ impl Model3dCache {
|
||||
walls: Vec::new(),
|
||||
slabs,
|
||||
context_meshes: model3d::emit_context_meshes(p),
|
||||
solid_meshes: model3d::emit_solids(p),
|
||||
column_meshes: { let mut m = model3d::emit_columns(p); m.extend(model3d::emit_trees(p)); m },
|
||||
opening_meshes: Vec::new(),
|
||||
stair_meshes: model3d::emit_stair_meshes(p),
|
||||
@@ -367,6 +368,7 @@ impl Model3dCache {
|
||||
js(&parts.stair_railings)?,
|
||||
js(&parts.roof_meshes)?,
|
||||
js(&parts.roof_layers)?,
|
||||
js(&parts.solid_meshes)?,
|
||||
];
|
||||
let mut json = String::new();
|
||||
if let Some(mark) = delta {
|
||||
@@ -400,6 +402,8 @@ impl Model3dCache {
|
||||
json.push_str(&rest[5]);
|
||||
json.push_str(",\"roofLayers\":");
|
||||
json.push_str(&rest[6]);
|
||||
json.push_str(",\"solidMeshes\":");
|
||||
json.push_str(&rest[7]);
|
||||
json.push('}');
|
||||
}
|
||||
if structs {
|
||||
@@ -437,7 +441,7 @@ struct OpenOut<'a> {
|
||||
/// [180] `wallKeep`/`openingKeep` (nur wenn nicht leer): Einträge ausgeblendeter Klassen, die der Aufrufer
|
||||
/// behält, aber nicht zeigt (je `[gezeigt, behalten]` übergeben). Gültig nur, wenn der Aufrufer die Einträge
|
||||
/// ≤ `mark` aus seiner letzten Antwort hat (sonst `mark` 0).
|
||||
fn write_delta(mark: u64, walls: [&[(u64, &str)]; 2], openings: [&[(u64, &[String; 5])]; 2], opening_tail: &str, rest: &[String; 7]) -> String {
|
||||
fn write_delta(mark: u64, walls: [&[(u64, &str)]; 2], openings: [&[(u64, &[String; 5])]; 2], opening_tail: &str, rest: &[String; 8]) -> String {
|
||||
use std::fmt::Write;
|
||||
let fresh = |serial: u64| mark == 0 || serial > mark || mark > current_serial();
|
||||
let cap = walls.iter().flat_map(|v| v.iter()).filter(|e| fresh(e.0)).map(|e| e.1.len() + 32).sum::<usize>()
|
||||
@@ -487,8 +491,8 @@ fn write_delta(mark: u64, walls: [&[(u64, &str)]; 2], openings: [&[(u64, &[Strin
|
||||
}
|
||||
let _ = write!(
|
||||
out,
|
||||
"],\"openingTail\":[{opening_tail}],\"slabs\":{},\"contextMeshes\":{},\"columnMeshes\":{},\"stairMeshes\":{},\"stairRailings\":{},\"roofMeshes\":{},\"roofLayers\":{}}}",
|
||||
rest[0], rest[1], rest[2], rest[3], rest[4], rest[5], rest[6]
|
||||
"],\"openingTail\":[{opening_tail}],\"slabs\":{},\"contextMeshes\":{},\"columnMeshes\":{},\"stairMeshes\":{},\"stairRailings\":{},\"roofMeshes\":{},\"roofLayers\":{},\"solidMeshes\":{}}}",
|
||||
rest[0], rest[1], rest[2], rest[3], rest[4], rest[5], rest[6], rest[7]
|
||||
);
|
||||
out
|
||||
}
|
||||
@@ -583,7 +587,7 @@ mod tests {
|
||||
out.insert(k.into(), r[k].clone());
|
||||
}
|
||||
out.insert("openingMeshes".into(), Value::Array(meshes));
|
||||
for k in ["stairMeshes", "stairRailings", "roofMeshes", "roofLayers", "voidCuts"] {
|
||||
for k in ["stairMeshes", "stairRailings", "roofMeshes", "roofLayers", "solidMeshes", "voidMeshes"] {
|
||||
if let Some(v) = r.get(k) {
|
||||
out.insert(k.into(), v.clone());
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn run_doc(d: &mut crate::document::Document, name: &str, args: &[f64], text
|
||||
if voids {
|
||||
let p = d.project()?;
|
||||
let cuts = crate::solid_specs::void_cuts(p, &out.parts.walls, &out.parts.slabs);
|
||||
return with_void_cuts(out.json, &cuts);
|
||||
return with_void_meshes(out.json, &crate::solid_specs::void_meshes(&cuts, &out.parts.walls, &out.parts.slabs));
|
||||
}
|
||||
return Ok(out.json);
|
||||
}
|
||||
@@ -30,12 +30,12 @@ pub fn run_doc(d: &mut crate::document::Document, name: &str, args: &[f64], text
|
||||
run(p, name, args, text)
|
||||
}
|
||||
|
||||
/// Das JSON-Objekt der Teile um `voidCuts` ergänzen (hinten angefügt statt über `serde_json::Value`).
|
||||
fn with_void_cuts(mut parts: String, cuts: &crate::solid_specs::VoidCuts) -> Result<String, String> {
|
||||
/// Das JSON-Objekt der Teile um `voidMeshes` ergänzen (hinten angefügt statt über `serde_json::Value`).
|
||||
fn with_void_meshes(mut parts: String, cuts: &crate::solid_specs::VoidMeshes) -> Result<String, String> {
|
||||
if parts.pop() != Some('}') {
|
||||
return Err("model3dParts: kein JSON-Objekt".into());
|
||||
}
|
||||
parts.push_str(",\"voidCuts\":");
|
||||
parts.push_str(",\"voidMeshes\":");
|
||||
parts.push_str(&json(cuts)?);
|
||||
parts.push('}');
|
||||
Ok(parts)
|
||||
@@ -116,10 +116,12 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
model3d::ClassFilter::from_text(p, text).retain_pick(&mut g);
|
||||
json(&g)
|
||||
}
|
||||
// [115] Kennwerte eines freien Körpers (`text` = id) aus seinem Kern-Netz; `null` ohne Netz.
|
||||
("solidProps", _) => json(&crate::solid_mesh::solid_props(p, text)),
|
||||
("modelJson", _) => crate::model::to_value_typed_only(p).map(|v| v.to_string()).map_err(|e| e.to_string()),
|
||||
// Mit Abzugskörpern (`args[3]` ≠ 0) zusätzlich `voidCuts`: die getroffenen Wände/Decken als
|
||||
// truck-Spezifikationen (`solid_specs.rs`).
|
||||
// `args[4]`: Explosionsabstand ([65], `explode3d.rs`; > 0 zusätzlich `floorOffsets`, Abzugskörper wandern mit).
|
||||
// Mit Abzugskörpern (`args[3]` ≠ 0) zusätzlich `voidMeshes`: die getroffenen Wände/Decken als
|
||||
// Netze „Bauteil − Körper" (`solid_specs::void_meshes`, Manifold).
|
||||
// `args[4]`: Explosionsabstand ([65], `explode3d.rs`; Körper und Abzugskörper wandern mit dem Geschoss).
|
||||
// [180] Ohne die Teile ausgeblendeter Klassen (`text` = `{"hide": [codes], "modelView": …}`).
|
||||
("model3dParts", n) if n >= 3 => {
|
||||
let explode = args.get(4).copied().filter(|g| g.is_finite() && *g > 0.0);
|
||||
@@ -127,9 +129,9 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
if let Some(gap) = explode {
|
||||
let parts = crate::explode3d::parts_filtered(p, args[0] != 0.0, args[1], args[2] != 0.0, gap, &filter)?;
|
||||
let mut v = serde_json::to_value(&parts).map_err(|e| e.to_string())?;
|
||||
v["floorOffsets"] = serde_json::to_value(crate::explode3d::floor_offsets(p, gap)).map_err(|e| e.to_string())?;
|
||||
if args.get(3).is_some_and(|v| *v != 0.0) {
|
||||
v["voidCuts"] = serde_json::to_value(crate::explode3d::void_cuts(p, &parts, gap)).map_err(|e| e.to_string())?;
|
||||
let cuts = crate::explode3d::void_cuts(p, &parts, gap);
|
||||
v["voidMeshes"] = serde_json::to_value(crate::solid_specs::void_meshes(&cuts, &parts.walls, &parts.slabs)).map_err(|e| e.to_string())?;
|
||||
}
|
||||
return Ok(v.to_string());
|
||||
}
|
||||
@@ -140,7 +142,7 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
|
||||
}
|
||||
if args.get(3).is_some_and(|v| *v != 0.0) {
|
||||
let cuts = crate::solid_specs::void_cuts(p, &parts.walls, &parts.slabs);
|
||||
return with_void_cuts(json(&parts)?, &cuts);
|
||||
return with_void_meshes(json(&parts)?, &crate::solid_specs::void_meshes(&cuts, &parts.walls, &parts.slabs));
|
||||
}
|
||||
json(&parts)
|
||||
}
|
||||
|
||||
@@ -1026,8 +1026,8 @@ fn solid_selection(root: &Map<String, Value>, s: &Value) -> J {
|
||||
.n("chamfer", num_or(field(s, "chamfer"), 0.0))
|
||||
.o("brepLabel", brep.map(|b| nn(field(b, "label")).cloned().unwrap_or_else(|| "B-Rep".into())))
|
||||
.n("area", polygon_area(field(s, "points")))
|
||||
// Platzhalter: `spec` (B-Rep für truck) setzt die TS-Fassade ein.
|
||||
.v("spec", Value::Null)
|
||||
// Platzhalter: `props` (Kennwerte aus dem Kern-Netz, Abfrage `solidProps`) setzt die TS-Fassade ein.
|
||||
.v("props", Value::Null)
|
||||
.v("subtract", Value::Bool(subtract))
|
||||
.v("canSubtract", Value::Bool(brep.is_none() && taper < 1e-6))
|
||||
.n("baseOffset", num_or(field(s, "baseOffset"), 0.0))
|
||||
|
||||
@@ -72,10 +72,16 @@ fn ccw(mut r: Vec<[f64; 2]>) -> Vec<[f64; 2]> {
|
||||
r
|
||||
}
|
||||
|
||||
/// Facetten eines Kreises vom Radius `r` für die Sehnenabweichung [`TOL`] (Vielfaches von 4, 12…128).
|
||||
fn segments(r: f64) -> usize {
|
||||
/// Mindestzahl Facetten je Vollkreis für Grundriss, Schnitt und Ansicht (5 mm Sehnenabweichung genügen dort).
|
||||
const MIN_SEG_PLAN: usize = 12;
|
||||
/// Mindestzahl Facetten je Vollkreis im 3D-Bild: Schritt ≤ 7.5° (wie runde Stützen), damit die Facettenfugen
|
||||
/// unter dem Knickwinkel der Kantenlinien von render3d (15°) bleiben und nur echte Kanten gezeichnet werden.
|
||||
pub const MIN_SEG_3D: usize = 48;
|
||||
|
||||
/// Facetten eines Kreises vom Radius `r` für die Sehnenabweichung [`TOL`] (Vielfaches von 4, `min`…128).
|
||||
fn segments(r: f64, min: usize) -> usize {
|
||||
let n = if r > TOL { (PI / (1.0 - TOL / r).acos()).ceil() } else { 12.0 };
|
||||
let n = (n as usize).clamp(12, 128);
|
||||
let n = (n as usize).clamp(min, 128.max(min));
|
||||
n.div_ceil(4) * 4
|
||||
}
|
||||
|
||||
@@ -100,7 +106,7 @@ fn chamfer_ring(ring: &[[f64; 2]], d: f64) -> Vec<[f64; 2]> {
|
||||
|
||||
/// Ecken mit Kreisbögen vom Radius `radius` verrunden (wie truck `rounded_ring_wire`: je Ecke auf die halbe
|
||||
/// kürzere Nachbarkante begrenzt, fast gestreckte Ecken bleiben scharf), Bögen als Facetten.
|
||||
fn round_ring(ring: &[[f64; 2]], radius: f64) -> Vec<[f64; 2]> {
|
||||
fn round_ring(ring: &[[f64; 2]], radius: f64, min_seg: usize) -> Vec<[f64; 2]> {
|
||||
let n = ring.len();
|
||||
let mut out = Vec::new();
|
||||
for i in 0..n {
|
||||
@@ -132,7 +138,7 @@ fn round_ring(ring: &[[f64; 2]], radius: f64) -> Vec<[f64; 2]> {
|
||||
while a1 - a0 < -PI {
|
||||
a1 += 2.0 * PI;
|
||||
}
|
||||
let k = ((segments(r) as f64) * (a1 - a0).abs() / (2.0 * PI)).ceil().max(1.0) as usize;
|
||||
let k = ((segments(r, min_seg) as f64) * (a1 - a0).abs() / (2.0 * PI)).ceil().max(1.0) as usize;
|
||||
for j in 0..=k {
|
||||
let ang = a0 + (a1 - a0) * j as f64 / k as f64;
|
||||
out.push([c[0] + r * ang.cos(), c[1] + r * ang.sin()]);
|
||||
@@ -286,6 +292,12 @@ fn affine(m: &Mesh, f: &dyn Fn(P3) -> P3) -> Mesh {
|
||||
|
||||
/// Körper einer B-Rep-Beschreibung (`SolidSpec`, Felder wie `trucksolid::brep::SolidSpec`).
|
||||
pub fn spec_solid(spec: &Value, depth: usize) -> Option<Solid> {
|
||||
spec_solid_q(spec, depth, MIN_SEG_PLAN)
|
||||
}
|
||||
|
||||
/// Wie [`spec_solid`] mit `min_seg` Facetten je Vollkreis mindestens ([`MIN_SEG_3D`] fürs 3D-Bild).
|
||||
pub fn spec_solid_q(spec: &Value, depth: usize, min_seg: usize) -> Option<Solid> {
|
||||
let segments = |r: f64| segments(r, min_seg);
|
||||
if depth > 64 {
|
||||
return None;
|
||||
}
|
||||
@@ -301,7 +313,7 @@ pub fn spec_solid(spec: &Value, depth: usize) -> Option<Solid> {
|
||||
}
|
||||
let cr = num_or(spec, "cornerRadius", 0.0);
|
||||
if cr > 1e-6 {
|
||||
outer = round_ring(&outer, cr);
|
||||
outer = round_ring(&outer, cr, min_seg);
|
||||
}
|
||||
let body = solid(&tube(&[ring_at(&outer, z0), ring_at(&outer, z0 + h)], false))?;
|
||||
let e = 1e-3;
|
||||
@@ -415,7 +427,7 @@ pub fn spec_solid(spec: &Value, depth: usize) -> Option<Solid> {
|
||||
}
|
||||
"translate" => {
|
||||
let v = vec3(spec, "v")?;
|
||||
let inner = spec_solid(spec.get("solid")?, depth + 1)?.to_mesh_raw();
|
||||
let inner = spec_solid_q(spec.get("solid")?, depth + 1, min_seg)?.to_mesh_raw();
|
||||
solid(&affine(&inner, &|q| [q[0] + v[0], q[1] + v[1], q[2] + v[2]]))
|
||||
}
|
||||
"transform" => {
|
||||
@@ -423,14 +435,14 @@ pub fn spec_solid(spec: &Value, depth: usize) -> Option<Solid> {
|
||||
if m.len() != 12 {
|
||||
return None;
|
||||
}
|
||||
let inner = spec_solid(spec.get("solid")?, depth + 1)?.to_mesh_raw();
|
||||
let inner = spec_solid_q(spec.get("solid")?, depth + 1, min_seg)?.to_mesh_raw();
|
||||
solid(&affine(&inner, &|q| {
|
||||
[m[0] * q[0] + m[1] * q[1] + m[2] * q[2] + m[3], m[4] * q[0] + m[5] * q[1] + m[6] * q[2] + m[7], m[8] * q[0] + m[9] * q[1] + m[10] * q[2] + m[11]]
|
||||
}))
|
||||
}
|
||||
"boolean" => {
|
||||
let a = spec_solid(spec.get("a")?, depth + 1)?;
|
||||
let b = spec_solid(spec.get("b")?, depth + 1)?;
|
||||
let a = spec_solid_q(spec.get("a")?, depth + 1, min_seg)?;
|
||||
let b = spec_solid_q(spec.get("b")?, depth + 1, min_seg)?;
|
||||
match spec.get("op")?.as_str()? {
|
||||
"union" => a.union(&b).ok(),
|
||||
"difference" => a.difference(&b).ok(),
|
||||
@@ -444,7 +456,12 @@ pub fn spec_solid(spec: &Value, depth: usize) -> Option<Solid> {
|
||||
|
||||
/// Netz einer B-Rep-Beschreibung (geschlossen, aussen orientiert); unbaubar oder leer ⇒ `None`.
|
||||
pub fn spec_mesh(spec: &Value) -> Option<Mesh> {
|
||||
let m = spec_solid(spec, 0)?.to_mesh_raw();
|
||||
spec_mesh_q(spec, MIN_SEG_PLAN)
|
||||
}
|
||||
|
||||
/// Wie [`spec_mesh`] mit `min_seg` Facetten je Vollkreis mindestens.
|
||||
pub fn spec_mesh_q(spec: &Value, min_seg: usize) -> Option<Mesh> {
|
||||
let m = spec_solid_q(spec, 0, min_seg)?.to_mesh_raw();
|
||||
(!m.is_empty()).then_some(m)
|
||||
}
|
||||
|
||||
@@ -454,12 +471,62 @@ fn is_prism_void(s: &crate::model::ExtrudedSolid) -> bool {
|
||||
s.operation.as_deref() == Some("subtract") && s.brep.is_none() && s.taper.unwrap_or(0.0) < 1e-6 && s.points.len() >= 3 && s.height > 0.0
|
||||
}
|
||||
|
||||
/// Netz eines Körpers mit UK auf seinem Geschoss (gemerkt nach Inhalt).
|
||||
/// Netz eines Körpers mit UK auf seinem Geschoss (gemerkt nach Inhalt), für Grundriss, Schnitt und Ansicht.
|
||||
pub fn body_mesh(p: &Project, s: &crate::model::ExtrudedSolid) -> Option<std::rc::Rc<Option<Mesh>>> {
|
||||
body_mesh_q(p, s, MIN_SEG_PLAN)
|
||||
}
|
||||
|
||||
/// [115] Netz eines Körpers fürs 3D (Viewer, Pick, Explosion, Kennwerte): dieselbe Beschreibung, Rundungen
|
||||
/// feiner facettiert ([`MIN_SEG_3D`]).
|
||||
pub fn body_mesh_3d(p: &Project, s: &crate::model::ExtrudedSolid) -> Option<std::rc::Rc<Option<Mesh>>> {
|
||||
body_mesh_q(p, s, MIN_SEG_3D)
|
||||
}
|
||||
|
||||
fn body_mesh_q(p: &Project, s: &crate::model::ExtrudedSolid, min_seg: usize) -> Option<std::rc::Rc<Option<Mesh>>> {
|
||||
let floor_z = if s.level_id.is_empty() { 0.0 } else { p.floor(&s.level_id).map_or(0.0, |f| f.base_elevation.unwrap_or(0.0)) };
|
||||
let v = serde_json::to_value(s).ok()?;
|
||||
let hash = crate::solid_bool::ContentHash::default().json(&v).f64(floor_z).finish();
|
||||
Some(crate::solid_bool::cached(&format!("body-mesh:{}", s.id), hash, || crate::cmd_solid::extruded_solid_spec(&v, floor_z).and_then(|spec| spec_mesh(&spec))))
|
||||
let hash = crate::solid_bool::ContentHash::default().json(&v).f64(floor_z).u64(min_seg as u64).finish();
|
||||
let key = if min_seg == MIN_SEG_PLAN { format!("body-mesh:{}", s.id) } else { format!("body-mesh-{min_seg}:{}", s.id) };
|
||||
Some(crate::solid_bool::cached(&key, hash, || crate::cmd_solid::extruded_solid_spec(&v, floor_z).and_then(|spec| spec_mesh_q(&spec, min_seg))))
|
||||
}
|
||||
|
||||
/// Kennwerte eines freien Körpers aus seinem 3D-Netz ([`body_mesh_3d`], Manifold): Volumen (m³), Oberfläche (m²),
|
||||
/// Volumen-Schwerpunkt und Hüllquader (Modell-Meter, z = Höhe). Ersetzt die Kennwerte über truck (gleiche
|
||||
/// Facettierung, 5 mm Sehnenabweichung); `None` ohne Netz.
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct SolidProps {
|
||||
pub volume: f64,
|
||||
pub area: f64,
|
||||
pub centroid: [f64; 3],
|
||||
pub min: [f64; 3],
|
||||
pub max: [f64; 3],
|
||||
pub closed: bool,
|
||||
}
|
||||
|
||||
pub fn solid_props(p: &Project, id: &str) -> Option<SolidProps> {
|
||||
let s = p.extruded_solids.as_deref()?.iter().find(|s| s.id == id)?;
|
||||
let m = body_mesh_3d(p, s)?;
|
||||
let m = m.as_ref().as_ref()?;
|
||||
mesh_props(m)
|
||||
}
|
||||
|
||||
/// Volumen, Oberfläche, Schwerpunkt und Hüllquader eines Netzes (Divergenzsatz über Tetraeder zum Ursprung).
|
||||
pub fn mesh_props(m: &Mesh) -> Option<SolidProps> {
|
||||
let (min, max) = m.bounds()?;
|
||||
let at = |i: u32| -> P3 { let i = i as usize * 3; [m.positions[i], m.positions[i + 1], m.positions[i + 2]] };
|
||||
let (mut vol, mut area, mut c) = (0.0, 0.0, [0.0; 3]);
|
||||
for t in m.indices.chunks_exact(3) {
|
||||
let (a, b, d) = (at(t[0]), at(t[1]), at(t[2]));
|
||||
let v6 = dot(a, cross(b, d));
|
||||
vol += v6;
|
||||
for k in 0..3 {
|
||||
c[k] += v6 * (a[k] + b[k] + d[k]);
|
||||
}
|
||||
let n = cross([b[0] - a[0], b[1] - a[1], b[2] - a[2]], [d[0] - a[0], d[1] - a[1], d[2] - a[2]]);
|
||||
area += dot(n, n).sqrt() / 2.0;
|
||||
}
|
||||
let centroid = if vol.abs() > 1e-15 { [c[0] / (4.0 * vol), c[1] / (4.0 * vol), c[2] / (4.0 * vol)] } else { [(min[0] + max[0]) / 2.0, (min[1] + max[1]) / 2.0, (min[2] + max[2]) / 2.0] };
|
||||
Some(SolidProps { volume: vol.abs() / 6.0, area, centroid, min, max, closed: m.is_closed() })
|
||||
}
|
||||
|
||||
/// Die Netze der freien Körper für Schnitt und Ansicht (Index in `extrudedSolids` + Netz). Senkrechte
|
||||
|
||||
@@ -225,13 +225,48 @@ fn subtract(base: Value, voids: &[&VoidPrism], dz: f64) -> Value {
|
||||
}
|
||||
|
||||
/// Bauteile des 3D-Modells, die ein Abzugskörper trifft: (Index im Modell, Spezifikation Bauteil −
|
||||
/// Körper). TS tesselliert sie über truck und ersetzt das Bauteil durch das Mesh.
|
||||
/// Körper). Das 3D baut daraus Netze im Kern ([`void_meshes`], Manifold), der STEP-Export B-Rep über truck.
|
||||
#[derive(serde::Serialize, Default, Debug)]
|
||||
pub struct VoidCuts {
|
||||
pub walls: Vec<(usize, Value)>,
|
||||
pub slabs: Vec<(usize, Value)>,
|
||||
}
|
||||
|
||||
/// [115] Netze der von Abzugskörpern getroffenen Wände und Decken (Index im Modell, Inhalts-Schlüssel für die
|
||||
/// Teil-id des Viewers, Netz in Farbe/Textur des Bauteils), gebaut im Kern über Manifold (`solid_mesh::spec_mesh`, gemerkt nach Inhalt) statt über truck in
|
||||
/// TS. Scheitert ein Boolean, fehlt der Eintrag: das 3D zeigt das Bauteil ungeschnitten.
|
||||
#[derive(serde::Serialize, Default, Debug)]
|
||||
pub struct VoidMeshes {
|
||||
pub walls: Vec<(usize, String, crate::model3d::RMesh)>,
|
||||
pub slabs: Vec<(usize, String, crate::model3d::RMesh)>,
|
||||
}
|
||||
|
||||
fn cut_mesh(spec: &Value) -> Option<(String, crate::solid_bool::Mesh)> {
|
||||
let hash = crate::solid_bool::ContentHash::default().json(spec).finish();
|
||||
let key = format!("{hash:x}");
|
||||
let m = (*crate::solid_bool::cached(&format!("void-cut:{key}"), hash, || crate::solid_mesh::spec_mesh(spec))).clone()?;
|
||||
Some((key, m))
|
||||
}
|
||||
|
||||
pub fn void_meshes(cuts: &VoidCuts, walls: &[RWall], slabs: &[RSlab]) -> VoidMeshes {
|
||||
let mesh = |i: usize, spec: &Value, color: crate::style::Rgb, material_index: Option<f64>| {
|
||||
cut_mesh(spec).map(|(key, m)| (i, format!("{key}{}", material_index.unwrap_or(0.0)), crate::model3d::RMesh {
|
||||
positions: m.positions,
|
||||
indices: m.indices,
|
||||
kind: "extrusion",
|
||||
color,
|
||||
vertex_colors: None,
|
||||
material_index,
|
||||
crease_angle: None,
|
||||
owner: Default::default(),
|
||||
}))
|
||||
};
|
||||
VoidMeshes {
|
||||
walls: cuts.walls.iter().filter_map(|(i, s)| walls.get(*i).and_then(|w| mesh(*i, s, w.color, w.material_index))).collect(),
|
||||
slabs: cuts.slabs.iter().filter_map(|(i, s)| slabs.get(*i).and_then(|b| mesh(*i, s, b.color, None))).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Abzugskörper auf Wände und Decken des Modells anwenden (früher `applyVoids3d`, Spezifikationsteil).
|
||||
pub fn void_cuts(p: &Project, walls: &[RWall], slabs: &[RSlab]) -> VoidCuts {
|
||||
void_cuts_lifted(p, walls, slabs, &|_| 0.0, &|_| 0.0)
|
||||
|
||||
Reference in new issue
Block a user