[213] Kameras als Modell-Elemente und Begehen (WASD) im 3D
Project.cameras (Rust Camera: Standpunkt + Augenhöhe über Geschoss, Ziel, Bildwinkel, Perspektive/ Axonometrie/Parallel, Sonnenstand) auf der neuen Klasse "Kameras" (92). Grundriss-Symbol im Kern (plan/cameras.rs: Gehäuse, Sichtkegel, Ziel, Name, schmale Pick-Bänder), Griffe im Kern (camera.rs, grips.rs: Standpunkt, Ziel, Bildwinkel/Sichtbreite), Auswahl/Entf, Objekt-Info CameraSection, Liste im Panel Ausschnitte, "Kamera aus aktueller Ansicht anlegen", "Kamera öffnen" (auch per Doppelklick auf das Symbol), cameraToView() für das Rendering [211]. Begehen im 3D: Umschalt+F, W/A/S/D/Pfeile, Q/E, Umschalt/Alt, Umschauen um den Augpunkt (viewport/walk.ts). Beispiel: Kamera im Musterhaus komplex.
This commit is contained in:
64 files changed
+2031
-50
No files matched your search
@@ -63,7 +63,7 @@ Neues Modul: `<modul>.rs` und `mod` in `lib.rs`, Bindungen in `web/<modul>.rs` u
|
||||
| `mesh_section.rs`, `mesh_view.rs`, `mesh_repair.rs` | Ebenenschnitt beliebiger Netze; importierte Netze; Netz-Reparatur |
|
||||
| `voids.rs` | Abzugskörper in Grundriss und Schnitt |
|
||||
| `surface_pattern.rs` | Ansichtsschraffur (Lattung, Verband, Schindeln …) |
|
||||
| `grid.rs`, `tree.rs`, `auto_dimensions.rs` | Achsraster, Bäume, automatische Aussenbemassung |
|
||||
| `grid.rs`, `tree.rs`, `camera.rs`, `auto_dimensions.rs` | Achsraster, Bäume, Kameras (Auflösung, Griffe, Brennweite), automatische Aussenbemassung |
|
||||
|
||||
## Befehle, Griffe, Auswahl, Verwaltung
|
||||
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
//! [213] Kameras (`Project.cameras`): Auflösung zu Augpunkt, Ziel und Blickrichtung in Modell-Koordinaten
|
||||
//! (z oben, Meter), Brennweite ↔ Bildwinkel. Das Planzeichen entsteht in `plan/cameras.rs`; die TS-Seite
|
||||
//! (`src/model/cameraView.ts`) liefert daraus die Ansicht der 3D-Kamera (`cameraToView`).
|
||||
|
||||
use crate::jsnum;
|
||||
use crate::model::*;
|
||||
|
||||
/// Präfix der Pick-Id im Feld `contextObjectId` der Plan-Primitive (`@` = keine Kontext-Element-Id).
|
||||
pub const CAMERA_PICK_PREFIX: &str = "@camera:";
|
||||
/// Vorgabe der Augenhöhe über dem Geschoss (m) und des vertikalen Bildwinkels (Grad; wie `FOV_Y` des 3D).
|
||||
pub const DEFAULT_EYE_HEIGHT: f64 = 1.6;
|
||||
pub const DEFAULT_FOV_DEG: f64 = 50.0;
|
||||
/// Sichthöhe bei Axonometrie/Parallel ohne Angabe (m).
|
||||
pub const DEFAULT_ORTHO_HEIGHT: f64 = 10.0;
|
||||
/// Bildverhältnis für den Sichtkegel im Grundriss (Breite/Höhe).
|
||||
pub const ASPECT: f64 = 16.0 / 9.0;
|
||||
/// Sensorhöhe für die Kleinbild-Brennweite (mm).
|
||||
pub const SENSOR_HEIGHT_MM: f64 = 24.0;
|
||||
/// Bildwinkel-Grenzen (Grad), wie `camera3dFromViewCamera`.
|
||||
pub const MIN_FOV_DEG: f64 = 5.0;
|
||||
pub const MAX_FOV_DEG: f64 = 120.0;
|
||||
|
||||
/// Aufgelöste Kamera in Modell-Koordinaten.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct CameraGeom {
|
||||
pub eye: [f64; 3],
|
||||
pub target: [f64; 3],
|
||||
/// Grundriss-Richtung (Bogenmass, 0 = +x), aus Standpunkt → Ziel.
|
||||
pub yaw: f64,
|
||||
/// Abstand Standpunkt → Ziel im Grundriss (m, ≥ 0).
|
||||
pub plan_dist: f64,
|
||||
pub fov_deg: f64,
|
||||
pub perspective: bool,
|
||||
pub ortho_height: f64,
|
||||
}
|
||||
|
||||
/// Brennweite (mm, Kleinbild, 24 mm Sensorhöhe) zum vertikalen Bildwinkel.
|
||||
pub fn focal_mm(fov_deg: f64) -> f64 {
|
||||
SENSOR_HEIGHT_MM / 2.0 / jsnum::tan(fov_deg.to_radians() / 2.0)
|
||||
}
|
||||
|
||||
/// Vertikaler Bildwinkel (Grad) zur Brennweite (mm).
|
||||
pub fn fov_deg_from_focal(mm: f64) -> f64 {
|
||||
2.0 * jsnum::atan(SENSOR_HEIGHT_MM / 2.0 / mm).to_degrees()
|
||||
}
|
||||
|
||||
/// Bildwinkel in den zulässigen Bereich (Vorgabe bei NaN/≤ 0).
|
||||
pub fn clamp_fov(fov_deg: f64) -> f64 {
|
||||
if fov_deg.is_finite() && fov_deg > 0.0 {
|
||||
fov_deg.clamp(MIN_FOV_DEG, MAX_FOV_DEG)
|
||||
} else {
|
||||
DEFAULT_FOV_DEG
|
||||
}
|
||||
}
|
||||
|
||||
impl CameraGeom {
|
||||
/// Auflösung gegen das Projekt; `None` bei unbrauchbarer Lage (NaN).
|
||||
pub fn of(p: &Project, c: &Camera) -> Option<CameraGeom> {
|
||||
let floor_z = p.floor(&c.floor_id).and_then(|l| l.base_elevation).filter(|z| z.is_finite()).unwrap_or(0.0);
|
||||
Self::at(c, floor_z)
|
||||
}
|
||||
|
||||
/// Wie [`CameraGeom::of`] mit gegebener Höhe der Geschoss-OK.
|
||||
pub fn at(c: &Camera, floor_z: f64) -> Option<CameraGeom> {
|
||||
let eye_h = if c.eye_height.is_finite() { c.eye_height } else { DEFAULT_EYE_HEIGHT };
|
||||
let (px, py, tx, ty, tz) = (c.position.x, c.position.y, c.target.x, c.target.y, c.target_height);
|
||||
if ![px, py, tx, ty, tz].iter().all(|v| v.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let (dx, dy) = (tx - px, ty - py);
|
||||
let plan_dist = dx.hypot(dy);
|
||||
let eye_z = floor_z + eye_h;
|
||||
Some(CameraGeom {
|
||||
eye: [px, py, eye_z],
|
||||
target: [tx, ty, tz],
|
||||
yaw: if plan_dist > 1e-9 { jsnum::atan2(dy, dx) } else { 0.0 },
|
||||
plan_dist,
|
||||
fov_deg: clamp_fov(c.fov_deg),
|
||||
perspective: c.projection == CameraProjection::Perspective || c.projection == CameraProjection::Unknown,
|
||||
ortho_height: c.ortho_height.filter(|h| h.is_finite() && *h > 0.0).unwrap_or(DEFAULT_ORTHO_HEIGHT),
|
||||
})
|
||||
}
|
||||
|
||||
/// Blickrichtung (normiert); `None`, wenn Standpunkt und Ziel zusammenfallen.
|
||||
pub fn direction(&self) -> Option<[f64; 3]> {
|
||||
let d = [self.target[0] - self.eye[0], self.target[1] - self.eye[1], self.target[2] - self.eye[2]];
|
||||
let l = d[0].hypot(d[1]).hypot(d[2]);
|
||||
(l > 1e-9).then(|| [d[0] / l, d[1] / l, d[2] / l])
|
||||
}
|
||||
}
|
||||
|
||||
/// Griffe im Grundriss (Modell-Meter) beim Massstab 1:`scale`: 0 Standpunkt, 1 Ziel, 2 rechter Rand der fernen
|
||||
/// Sichtlinie (Perspektive: Bildwinkel, Axonometrie/Parallel: Sichtbreite).
|
||||
pub fn grip_points(c: &Camera, scale: f64) -> Vec<(f64, f64)> {
|
||||
let Some(g) = CameraGeom::at(c, 0.0) else { return vec![] };
|
||||
let a = crate::plan::cameras::view_area(&g, if scale.is_finite() && scale > 0.0 { scale / 1000.0 } else { 0.1 });
|
||||
vec![(g.eye[0], g.eye[1]), (g.target[0], g.target[1]), (a[2].x, a[2].y)]
|
||||
}
|
||||
|
||||
/// Kamera nach dem Ziehen des Griffs `index` an `(x, y)`; `None` bei unbekanntem Griff oder NaN.
|
||||
/// 0 setzt den Standpunkt (Ziel bleibt), 1 das Ziel, 2 den Bildwinkel (Perspektive: aus dem Winkel zur Blickachse,
|
||||
/// 5° bis 120° vertikal) bzw. die Sichtbreite (Axonometrie/Parallel: aus dem Abstand zur Blickachse).
|
||||
pub fn grip_edit(c: &Camera, index: f64, x: f64, y: f64) -> Option<Camera> {
|
||||
if !(x.is_finite() && y.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let g = CameraGeom::at(c, 0.0)?;
|
||||
let mut n = c.clone();
|
||||
match index {
|
||||
i if i == 0.0 => n.position = Vec2 { x, y },
|
||||
i if i == 1.0 => n.target = Vec2 { x, y },
|
||||
i if i == 2.0 => {
|
||||
let (dx, dy) = (x - g.eye[0], y - g.eye[1]);
|
||||
if g.perspective {
|
||||
if dx.hypot(dy) < 1e-9 {
|
||||
return None;
|
||||
}
|
||||
let mut a = jsnum::atan2(dy, dx) - g.yaw;
|
||||
a = jsnum::atan2(jsnum::sin(a), jsnum::cos(a)).abs();
|
||||
let h = a.clamp(0.5_f64.to_radians(), 75.0_f64.to_radians());
|
||||
n.fov_deg = clamp_fov((2.0 * jsnum::atan(jsnum::tan(h) / ASPECT)).to_degrees());
|
||||
} else {
|
||||
let side = (-jsnum::sin(g.yaw)) * dx + jsnum::cos(g.yaw) * dy;
|
||||
n.ortho_height = Some((2.0 * side.abs() / ASPECT).max(0.1));
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
}
|
||||
Some(n)
|
||||
}
|
||||
|
||||
/// Kamera um `(dx, dy)` verschoben (Standpunkt und Ziel).
|
||||
pub fn moved(c: &Camera, dx: f64, dy: f64) -> Option<Camera> {
|
||||
if !(dx.is_finite() && dy.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let mut n = c.clone();
|
||||
n.position = Vec2 { x: c.position.x + dx, y: c.position.y + dy };
|
||||
n.target = Vec2 { x: c.target.x + dx, y: c.target.y + dy };
|
||||
Some(n)
|
||||
}
|
||||
|
||||
/// Bezeichnung (Objekt-Info, Beschriftung): Name, sonst „Kamera".
|
||||
pub fn label(c: &Camera) -> String {
|
||||
let n = c.name.trim();
|
||||
if n.is_empty() { "Kamera".to_string() } else { n.to_string() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn camera(json: serde_json::Value) -> Camera {
|
||||
let mut base = serde_json::json!({
|
||||
"id": "k1", "type": "camera", "name": "Süd", "floorId": "eg", "categoryCode": "92", "position": {"x": 1, "y": 2},
|
||||
"eyeHeight": 1.6, "target": {"x": 1, "y": 12}, "targetHeight": 1.6, "fovDeg": 50, "projection": "perspective"
|
||||
});
|
||||
for (k, v) in json.as_object().unwrap() {
|
||||
base[k] = v.clone();
|
||||
}
|
||||
serde_json::from_value(base).unwrap()
|
||||
}
|
||||
|
||||
fn project() -> Project {
|
||||
serde_json::from_value(serde_json::json!({
|
||||
"id": "p", "name": "p", "walls": [], "layers": [],
|
||||
"drawingLevels": [{"id": "eg", "name": "EG", "kind": "floor", "visible": true, "locked": false, "baseElevation": 3.0}]
|
||||
}))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn augenhoehe_ueber_geschoss_und_richtung() {
|
||||
let g = CameraGeom::of(&project(), &camera(serde_json::json!({}))).unwrap();
|
||||
assert_eq!(g.eye, [1.0, 2.0, 4.6]);
|
||||
assert!((g.yaw - std::f64::consts::FRAC_PI_2).abs() < 1e-12);
|
||||
assert!((g.plan_dist - 10.0).abs() < 1e-12);
|
||||
assert!(g.perspective);
|
||||
let d = g.direction().unwrap();
|
||||
assert!(d[1] > 0.9 && d[2] < 0.0, "Ziel liegt tiefer als das Auge");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ohne_geschoss_null_und_nan_verworfen() {
|
||||
let g = CameraGeom::of(&Project::default(), &camera(serde_json::json!({"projection": "parallel", "orthoHeight": 6}))).unwrap();
|
||||
assert_eq!(g.eye[2], 1.6);
|
||||
assert!(!g.perspective);
|
||||
assert_eq!(g.ortho_height, 6.0);
|
||||
let mut c = camera(serde_json::json!({}));
|
||||
c.position.x = f64::NAN;
|
||||
assert!(CameraGeom::of(&project(), &c).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn brennweite_und_bildwinkel_umkehrbar() {
|
||||
assert!((focal_mm(fov_deg_from_focal(35.0)) - 35.0).abs() < 1e-9);
|
||||
// 24 mm Sensorhöhe, 35 mm Brennweite: rund 37.8°.
|
||||
assert!((fov_deg_from_focal(35.0) - 37.85).abs() < 0.05);
|
||||
assert_eq!(clamp_fov(f64::NAN), DEFAULT_FOV_DEG);
|
||||
assert_eq!(clamp_fov(500.0), MAX_FOV_DEG);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn griffe_standpunkt_ziel_winkel() {
|
||||
let c = camera(serde_json::json!({}));
|
||||
let pts = grip_points(&c, 100.0);
|
||||
assert_eq!(pts.len(), 3);
|
||||
assert_eq!(pts[0], (1.0, 2.0));
|
||||
assert_eq!(pts[1], (1.0, 12.0));
|
||||
// Ziehen des Winkel-Griffs auf den heutigen Punkt ändert den Bildwinkel nicht.
|
||||
let same = grip_edit(&c, 2.0, pts[2].0, pts[2].1).unwrap();
|
||||
assert!((same.fov_deg - 50.0).abs() < 1e-9, "{}", same.fov_deg);
|
||||
// Weiter öffnen: 45° zur Blickachse ergibt einen grösseren Bildwinkel.
|
||||
let wide = grip_edit(&c, 2.0, 1.0 + 10.0, 2.0 + 10.0).unwrap();
|
||||
assert!(wide.fov_deg > 50.0);
|
||||
assert_eq!(grip_edit(&c, 0.0, 5.0, 6.0).unwrap().position, Vec2 { x: 5.0, y: 6.0 });
|
||||
assert_eq!(grip_edit(&c, 1.0, 5.0, 6.0).unwrap().target, Vec2 { x: 5.0, y: 6.0 });
|
||||
assert!(grip_edit(&c, 7.0, 0.0, 0.0).is_none());
|
||||
assert!(grip_edit(&c, 0.0, f64::NAN, 0.0).is_none());
|
||||
// Parallelprojektion: Sichtbreite aus dem Abstand zur Achse.
|
||||
let par = camera(serde_json::json!({"projection": "parallel", "orthoHeight": 4}));
|
||||
let w = grip_points(&par, 100.0)[2];
|
||||
let edit = grip_edit(&par, 2.0, w.0 - 1.0, w.1).unwrap();
|
||||
assert!((edit.ortho_height.unwrap() - 2.0 * (4.0 * ASPECT / 2.0 + 1.0) / ASPECT).abs() < 1e-9);
|
||||
let m = moved(&c, 1.0, -1.0).unwrap();
|
||||
assert_eq!((m.position, m.target), (Vec2 { x: 2.0, y: 1.0 }, Vec2 { x: 2.0, y: 11.0 }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modell_aus_json_verlustfrei() {
|
||||
let c = camera(serde_json::json!({"sunWhen": "2026-06-21T08:00:00Z", "orthoHeight": 8}));
|
||||
let back: Camera = serde_json::from_value(serde_json::to_value(&c).unwrap()).unwrap();
|
||||
assert_eq!(back, c);
|
||||
assert_eq!(label(&Camera::default()), "Kamera");
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,10 @@ pub fn translate_project(p: &Project, dx: f64, dy: f64) -> Project {
|
||||
for t in out.trees.iter_mut().flatten() {
|
||||
t.position = shift(t.position, dx, dy);
|
||||
}
|
||||
for c in out.cameras.iter_mut().flatten() {
|
||||
c.position = shift(c.position, dx, dy);
|
||||
c.target = shift(c.target, dx, dy);
|
||||
}
|
||||
if let Some(r) = &mut out.site_rules {
|
||||
shift_all(&mut r.parcel, dx, dy);
|
||||
for l in r.building_lines.iter_mut().flatten() {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
use serde_json::{json, Map, Value};
|
||||
|
||||
/// Projekt-Listen, die verschoben werden (jedes Element hat eine `id`), in Op-Reihenfolge.
|
||||
pub const TRANSLATED_LISTS: [&str; 11] = ["walls", "ceilings", "roofs", "stairs", "rooms", "columns", "extrudedSolids", "drawings2d", "context", "drawingLevels", "trees"];
|
||||
pub const TRANSLATED_LISTS: [&str; 12] = ["walls", "ceilings", "roofs", "stairs", "rooms", "columns", "extrudedSolids", "drawings2d", "context", "drawingLevels", "trees", "cameras"];
|
||||
|
||||
fn shift(p: &Value, dx: f64, dy: f64) -> Value {
|
||||
let c = |k: &str| p.get(k).and_then(Value::as_f64).unwrap_or(f64::NAN);
|
||||
@@ -164,6 +164,7 @@ fn shift_element(key: &str, e: &Value, dx: f64, dy: f64) -> (Value, bool) {
|
||||
}
|
||||
"columns" => shift_pts_fields(&mut m, &["position"], dx, dy, &[]),
|
||||
"trees" => shift_pts_fields(&mut m, &["position"], dx, dy, &[]),
|
||||
"cameras" => shift_pts_fields(&mut m, &["position", "target"], dx, dy, &[]),
|
||||
"extrudedSolids" => {
|
||||
shift_pts_fields(&mut m, &[], dx, dy, &["points"]);
|
||||
let c = if truthy(e.get("circle")) {
|
||||
|
||||
@@ -282,6 +282,19 @@ pub fn run(lk: &Lookup, req: &Request) -> Result<GripResult, String> {
|
||||
.into()
|
||||
}
|
||||
}
|
||||
// [213] Kamera: Griff 0 Standpunkt, 1 Ziel, 2 Bildwinkel/Sichtbreite; `cameraBy` verschiebt Standpunkt und Ziel.
|
||||
"cameraGrip" | "cameraBy" => {
|
||||
let (index, (x, y), (dx, dy)) = (r.n("index"), r.p("pt"), r.p("delta"));
|
||||
patch("cameras", r.s("id"), &|e| {
|
||||
if truthy(field(e, "locked")) {
|
||||
return None;
|
||||
}
|
||||
let cam: crate::model::Camera = serde_json::from_value(e.clone()).ok()?;
|
||||
let next = if op == "cameraGrip" { crate::camera::grip_edit(&cam, index, x, y)? } else { crate::camera::moved(&cam, dx, dy)? };
|
||||
serde_json::to_value(next).ok()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
"ceilingGrip" | "roomGrip" => {
|
||||
let (coll, field) = if op == "ceilingGrip" { ("ceilings", "outline") } else { ("rooms", "boundary") };
|
||||
let (index, (x, y)) = (r.n("index"), r.p("pt"));
|
||||
|
||||
@@ -20,6 +20,7 @@ pub mod roof_parapet;
|
||||
pub mod flat_read;
|
||||
pub mod sun;
|
||||
pub mod tree;
|
||||
pub mod camera;
|
||||
pub mod site_rules;
|
||||
pub mod auto_dimensions;
|
||||
pub mod kennzahlen;
|
||||
|
||||
@@ -4885,6 +4885,71 @@ pub struct Tree {
|
||||
pub extra: Extra,
|
||||
}
|
||||
|
||||
/// Projektion einer Kamera ([213]): Perspektive, Axonometrie (Parallelprojektion mit schrägem Blick, z. B.
|
||||
/// Isometrie) oder Parallelprojektion (frei ausgerichtet). Axonometrie und Parallel zeichnen im 3D orthografisch.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, TS)]
|
||||
pub enum CameraProjection {
|
||||
#[default]
|
||||
#[serde(rename = "perspective")]
|
||||
Perspective,
|
||||
#[serde(rename = "axonometric")]
|
||||
Axonometric,
|
||||
#[serde(rename = "parallel")]
|
||||
Parallel,
|
||||
#[serde(other)]
|
||||
#[ts(skip)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
/// Eine Kamera ([213]) — gespeicherter Standpunkt für die 3D-Ansicht (und das Rendering): Standpunkt im
|
||||
/// Grundriss mit Augenhöhe über dem Geschoss, Ziel (Grundriss und absolute Höhe), Bildwinkel, Projektion
|
||||
/// und optional Datum/Uhrzeit für den Sonnenstand. Im Grundriss als Symbol mit Sichtkegel auf der Klasse
|
||||
/// „Kameras" (Vorgabe "92"); „Kamera öffnen" setzt die 3D-Ansicht exakt.
|
||||
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default)]
|
||||
pub struct Camera {
|
||||
pub id: String,
|
||||
#[ts(type = "\"camera\"")]
|
||||
pub r#type: String,
|
||||
pub name: String,
|
||||
/// Geschoss, auf dem das Symbol im Grundriss steht und auf das sich die Augenhöhe bezieht.
|
||||
#[serde(rename = "floorId")]
|
||||
pub floor_id: String,
|
||||
/// Klasse (Ebene), Vorgabe "92" (Kameras).
|
||||
#[serde(rename = "categoryCode")]
|
||||
pub category_code: String,
|
||||
/// Objekt-Sperre, analog `Wall.locked`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub locked: Option<bool>,
|
||||
/// Standpunkt im Grundriss (Meter).
|
||||
pub position: Vec2,
|
||||
/// Augenhöhe über OK Fertigboden des Geschosses (m).
|
||||
#[serde(rename = "eyeHeight")]
|
||||
pub eye_height: f64,
|
||||
/// Ziel im Grundriss (Meter); der Abstand Standpunkt–Ziel ist die Länge des Sichtkegels.
|
||||
pub target: Vec2,
|
||||
/// Höhe des Ziels (m, absolut, z des Modells).
|
||||
#[serde(rename = "targetHeight")]
|
||||
pub target_height: f64,
|
||||
/// Vertikaler Bildwinkel (Grad, perspektivisch). Die Kleinbild-Brennweite folgt daraus (24-mm-Sensorhöhe).
|
||||
#[serde(rename = "fovDeg")]
|
||||
pub fov_deg: f64,
|
||||
pub projection: CameraProjection,
|
||||
/// Sichthöhe in Metern (volle Bildhöhe) bei Axonometrie/Parallel; fehlt = 10 m.
|
||||
#[serde(rename = "orthoHeight", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub ortho_height: Option<f64>,
|
||||
/// Zeitpunkt für den Sonnenstand (ISO-8601 in UTC wie `SunStudy.when`); „Kamera öffnen" setzt ihn in der
|
||||
/// Sonnenstudie. Fehlt er, bleibt die Sonne der Studie.
|
||||
#[serde(rename = "sunWhen", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub sun_when: Option<String>,
|
||||
#[serde(flatten)]
|
||||
#[ts(skip)]
|
||||
pub extra: Extra,
|
||||
}
|
||||
|
||||
/// Gruppe (Vectorworks-artig) — reine Mitgliedschaft je Elementart, siehe
|
||||
/// {@link Project.groups}. Alle ID-Listen sind additiv; ein Element gehört
|
||||
/// NIE zu mehr als einer Gruppe auf derselben Ebene (das Werkzeug/der Befehl
|
||||
@@ -5919,6 +5984,11 @@ pub struct Project {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub trees: Option<Vec<Tree>>,
|
||||
/// Kameras ([213]) — gespeicherte Standpunkte für 3D-Ansicht und Rendering, siehe {@link Camera}. Optional
|
||||
/// (Default: leer behandeln).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub cameras: Option<Vec<Camera>>,
|
||||
/// Gruppen (Vectorworks-artig: Cmd+G fasst die Auswahl zu einer Einheit
|
||||
/// zusammen; Doppelklick betritt die Gruppe zum Bearbeiten, alles andere
|
||||
/// wird dabei gedimmt/gesperrt — s. `state/useGroupState.ts`). Eine Gruppe
|
||||
|
||||
@@ -37,6 +37,7 @@ impl Project {
|
||||
"extrudedSolids" => put_opt(&mut self.extruded_solids, i, v),
|
||||
"columns" => put_opt(&mut self.columns, i, v),
|
||||
"trees" => put_opt(&mut self.trees, i, v),
|
||||
"cameras" => put_opt(&mut self.cameras, i, v),
|
||||
"groups" => put_opt(&mut self.groups, i, v),
|
||||
"layouts" => put_opt(&mut self.layouts, i, v),
|
||||
_ => Ok(false),
|
||||
|
||||
@@ -26,6 +26,7 @@ Herkunft, kein Wegweiser.
|
||||
| `floor_finish.rs` | Bodenbelag-Muster nach Massstab |
|
||||
| `model_view.rs` | Modelldarstellung ([173]): Optionen je Bauteilart über dem Detailgrad, Rangfolge Element > Typ > Stufe > Basis |
|
||||
| `trees.rs` | Bäume in Grundriss, Schnitt und Ansicht |
|
||||
| `cameras.rs` | [213] Kameras im Grundriss: Gehäuse, Sichtkegel, Ziel, Name, Pick-Bänder (Klasse „Kameras“) |
|
||||
| `stamp_place.rs` | Hindernisse für die Lage der Raumstempel |
|
||||
| `view_range.rs` | Ansichtsbereich: Schnitthöhe, Ober- und Unterkante der Sicht |
|
||||
| `extras.rs` | Zutaten: Schatten und Baurecht, Abzugskörper, Strichstärken nach Massstab, Schwarz-Weiss, Ausmass |
|
||||
|
||||
@@ -30,6 +30,7 @@ pub const NOT_FOR_DRAWINGS: &[&str] = &[
|
||||
"rooms",
|
||||
"columns",
|
||||
"trees",
|
||||
"cameras",
|
||||
"extrudedSolids",
|
||||
// [157] `context` lesen die Zeichnungen: die Aussenbemassung rückt hinter die sichtbare Baugrube.
|
||||
"groups",
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
//! [213] Kameras im Grundriss: Kamerakörper (Gehäuse mit Objektiv) am Standpunkt, Sichtkegel mit dem
|
||||
//! horizontalen Öffnungswinkel (Perspektive) bzw. parallele Sichtgrenzen (Axonometrie/Parallel), Ziel als
|
||||
//! Kreuz mit gestrichelter Blicklinie, Name als Beschriftung. Grösse in fester Papiergrösse (unabhängig vom
|
||||
//! Massstab). Alles liegt auf der Klasse der Kamera (Vorgabe „92", `standards::CAMERA_CATEGORY`); fehlt die
|
||||
//! Klasse im Projekt, bleibt das Symbol sichtbar (wie die übrige abgeleitete Darstellung, [180]).
|
||||
//! Pick: unsichtbare Fläche (Körper + Kegel) mit `contextObjectId = "@camera:<id>"`.
|
||||
|
||||
use super::domains::Ctx;
|
||||
use super::prim::Primitive;
|
||||
use super::style::MONO_INK;
|
||||
use super::trees::{line, poly};
|
||||
use crate::camera::{CameraGeom, CAMERA_PICK_PREFIX};
|
||||
use crate::jsnum;
|
||||
use crate::model::*;
|
||||
|
||||
const BODY_MM: f64 = 0.25;
|
||||
const CONE_MM: f64 = 0.18;
|
||||
const AIM_MM: f64 = 0.13;
|
||||
const AIM_DASH: [f64; 2] = [1.5, 1.0];
|
||||
/// Gehäuse: Länge entlang der Blickrichtung und Breite (Papier-mm), Objektiv davor.
|
||||
const BODY_LEN: f64 = 4.0;
|
||||
const BODY_WID: f64 = 3.2;
|
||||
const LENS_LEN: f64 = 1.6;
|
||||
const LENS_WID: f64 = 2.0;
|
||||
/// Zielkreuz (Halbarm, Papier-mm).
|
||||
const CROSS: f64 = 1.6;
|
||||
/// Grösster Winkel zur Achse für den Kegel (Grad), damit sehr grosse Bildwinkel keine endlosen Kanten geben.
|
||||
/// Halbe Breite der Pick-Bänder entlang der Linien (Papier-mm).
|
||||
const PICK_BAND: f64 = 1.2;
|
||||
const MAX_HALF_DEG: f64 = 75.0;
|
||||
|
||||
fn v(x: f64, y: f64) -> Vec2 {
|
||||
Vec2 { x, y }
|
||||
}
|
||||
|
||||
/// Pick-Id einer Kamera (Feld `contextObjectId`).
|
||||
pub fn pick_id(id: &str) -> String {
|
||||
format!("{CAMERA_PICK_PREFIX}{id}")
|
||||
}
|
||||
|
||||
/// Halber horizontaler Öffnungswinkel (Radiant) aus dem vertikalen Bildwinkel und dem Bildverhältnis.
|
||||
pub fn half_h_angle(fov_deg: f64) -> f64 {
|
||||
let h = jsnum::atan(jsnum::tan(fov_deg.to_radians() / 2.0) * crate::camera::ASPECT);
|
||||
h.min(MAX_HALF_DEG.to_radians())
|
||||
}
|
||||
|
||||
/// Ecken des Sichtkegels (Standpunkt, linke Ecke, rechte Ecke) bzw. des Streifens bei Parallelprojektion.
|
||||
pub fn view_area(g: &CameraGeom, mm: f64) -> Vec<Vec2> {
|
||||
let (px, py) = (g.eye[0], g.eye[1]);
|
||||
// Mindestlänge: damit auch ein Ziel unmittelbar am Standpunkt ein sichtbares Symbol gibt.
|
||||
let len = g.plan_dist.max(8.0 * mm);
|
||||
let (u, n) = ((jsnum::cos(g.yaw), jsnum::sin(g.yaw)), (-jsnum::sin(g.yaw), jsnum::cos(g.yaw)));
|
||||
if g.perspective {
|
||||
let h = half_h_angle(g.fov_deg);
|
||||
let edge = len / jsnum::cos(h);
|
||||
let at = |s: f64| v(px + edge * jsnum::cos(g.yaw + s * h), py + edge * jsnum::sin(g.yaw + s * h));
|
||||
vec![v(px, py), at(-1.0), at(1.0)]
|
||||
} else {
|
||||
// Breite = Sichthöhe × Bildverhältnis.
|
||||
let w = g.ortho_height * crate::camera::ASPECT / 2.0;
|
||||
let q = |a: f64, b: f64| v(px + u.0 * a + n.0 * b, py + u.1 * a + n.1 * b);
|
||||
vec![q(0.0, -w), q(len, -w), q(len, w), q(0.0, w)]
|
||||
}
|
||||
}
|
||||
|
||||
/// Planzeichen einer Kamera: Pick-Fläche, Sichtgrenzen, Gehäuse mit Objektiv, Blicklinie und Zielkreuz.
|
||||
pub fn camera_symbol(cam: &Camera, g: &CameraGeom, scale: f64, cat: Option<&LayerCategory>, greyed: Option<bool>) -> Vec<Primitive> {
|
||||
let mm = scale / 1000.0;
|
||||
let color = cat.map(|k| k.color.as_str()).filter(|c| !c.is_empty()).unwrap_or(MONO_INK).to_string();
|
||||
let (px, py) = (g.eye[0], g.eye[1]);
|
||||
let (cs, sn) = (jsnum::cos(g.yaw), jsnum::sin(g.yaw));
|
||||
let at = |a: f64, b: f64| v(px + (cs * a - sn * b) * mm, py + (sn * a + cs * b) * mm);
|
||||
// Gehäuse hinter dem Standpunkt, Objektiv davor: der Standpunkt liegt an der Vorderkante des Objektivs.
|
||||
let (bw, lw) = (BODY_WID / 2.0, LENS_WID / 2.0);
|
||||
let body = vec![at(-BODY_LEN - LENS_LEN, -bw), at(-LENS_LEN, -bw), at(-LENS_LEN, bw), at(-BODY_LEN - LENS_LEN, bw)];
|
||||
let lens = vec![at(-LENS_LEN, -lw), at(0.0, -lw * 1.5), at(0.0, lw * 1.5), at(-LENS_LEN, lw)];
|
||||
let area = view_area(g, mm);
|
||||
// Pick-Flächen (unsichtbar): Gehäuse mit Objektiv, Zielkreuz und schmale Bänder entlang der Sichtgrenzen und der
|
||||
// Blicklinie — nicht der ganze Kegel, sonst finge er jeden Klick auf Räume und Wände darin ab.
|
||||
let id = pick_id(&cam.id);
|
||||
let mut out = Vec::new();
|
||||
let mut pick = |pts: Vec<Vec2>| out.push(poly(pts, "none", "none", 0.0, Some(id.clone()), greyed));
|
||||
pick(vec![at(-BODY_LEN - LENS_LEN, -bw), at(0.0, -lw * 1.5), at(0.0, lw * 1.5), at(-BODY_LEN - LENS_LEN, bw)]);
|
||||
let band = |a: Vec2, b: Vec2| -> Option<Vec<Vec2>> {
|
||||
let (dx, dy) = (b.x - a.x, b.y - a.y);
|
||||
let l = dx.hypot(dy);
|
||||
if !(l > 1e-9) {
|
||||
return None;
|
||||
}
|
||||
let (nx, ny) = (-dy / l * PICK_BAND * mm, dx / l * PICK_BAND * mm);
|
||||
Some(vec![v(a.x + nx, a.y + ny), v(b.x + nx, b.y + ny), v(b.x - nx, b.y - ny), v(a.x - nx, a.y - ny)])
|
||||
};
|
||||
let m = area.len();
|
||||
for k in 0..m {
|
||||
// Perspektive: Kanten 0–1, 0–2 und 1–2; Streifen: Umriss.
|
||||
let (a, b) = if g.perspective { [(0, 1), (0, 2), (1, 2)][k.min(2)] } else { (k, (k + 1) % m) };
|
||||
if g.perspective && k > 2 {
|
||||
break;
|
||||
}
|
||||
if let Some(b) = band(area[a], area[b]) {
|
||||
pick(b);
|
||||
}
|
||||
}
|
||||
if g.plan_dist > 1e-6 {
|
||||
if let Some(b) = band(v(px, py), v(g.target[0], g.target[1])) {
|
||||
pick(b);
|
||||
}
|
||||
}
|
||||
let kk = CROSS * mm;
|
||||
pick(vec![v(g.target[0] - kk, g.target[1] - kk), v(g.target[0] + kk, g.target[1] - kk), v(g.target[0] + kk, g.target[1] + kk), v(g.target[0] - kk, g.target[1] + kk)]);
|
||||
// Sichtgrenzen: Kegel (zwei Kanten und die ferne Linie) bzw. Streifen (Umriss).
|
||||
if g.perspective {
|
||||
out.push(line(area[0], area[1], "camera-cone", CONE_MM, &color, None, greyed));
|
||||
out.push(line(area[0], area[2], "camera-cone", CONE_MM, &color, None, greyed));
|
||||
out.push(line(area[1], area[2], "camera-cone", CONE_MM, &color, Some(&AIM_DASH), greyed));
|
||||
} else {
|
||||
for k in 0..m {
|
||||
let dash = (k == 0).then_some(&AIM_DASH[..]);
|
||||
out.push(line(area[k], area[(k + 1) % m], "camera-cone", CONE_MM, &color, dash, greyed));
|
||||
}
|
||||
}
|
||||
out.push(poly(body, "#ffffff", &color, BODY_MM, None, greyed));
|
||||
out.push(poly(lens, &color, &color, BODY_MM, None, greyed));
|
||||
// Blicklinie zum Ziel und Zielkreuz.
|
||||
let (tx, ty) = (g.target[0], g.target[1]);
|
||||
if g.plan_dist > 1e-6 {
|
||||
out.push(line(v(px, py), v(tx, ty), "camera-aim", AIM_MM, &color, Some(&AIM_DASH), greyed));
|
||||
}
|
||||
let k = CROSS * mm;
|
||||
out.push(line(v(tx - k, ty), v(tx + k, ty), "camera-aim", CONE_MM, &color, None, greyed));
|
||||
out.push(line(v(tx, ty - k), v(tx, ty + k), "camera-aim", CONE_MM, &color, None, greyed));
|
||||
// Name hinter dem Gehäuse (Schrift bleibt waagrecht, der Block rückt so weit ab, dass er das Gehäuse nicht berührt).
|
||||
let name = cam.name.trim();
|
||||
if !name.is_empty() && scale.is_finite() && scale > 0.0 {
|
||||
let doc = super::domains::doc_from_text(name);
|
||||
let pt = super::trees::label_pt(scale);
|
||||
let (w, h) = crate::text_layout::stamp_block_size(&doc, &[], pt, crate::text_layout::PT_TO_MM * mm);
|
||||
let back = (BODY_LEN + LENS_LEN + 1.0) * mm;
|
||||
let reach = cs.abs() * w / 2.0 + sn.abs() * h / 2.0 + 0.5 * mm;
|
||||
let c = v(px - cs * (back + reach), py - sn * (back + reach));
|
||||
out.push(Primitive::Text { at: c, doc, extra_lines: vec![], base_pt: pt, color: color.clone(), room_id: None, greyed, opacity: None });
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Kamera-Symbole des Grundrisses (Kameras dieses Geschosses mit sichtbarer Klasse).
|
||||
pub(super) fn plan_cameras(c: &Ctx, out: &mut Vec<Primitive>) {
|
||||
let Some(cams) = c.p.cameras.as_deref() else { return };
|
||||
let scale = if c.a.scale.is_finite() && c.a.scale > 0.0 { c.a.scale } else { 100.0 };
|
||||
for cam in cams {
|
||||
if cam.floor_id != c.a.floor || !c.derived_shown(&cam.category_code) || c.rule_hidden(&cam.id) {
|
||||
continue;
|
||||
}
|
||||
let Some(g) = CameraGeom::of(c.p, cam) else { continue };
|
||||
let greyed = Some(c.greyed(&cam.category_code));
|
||||
out.extend(camera_symbol(cam, &g, scale, c.cat(&cam.category_code), greyed));
|
||||
}
|
||||
}
|
||||
|
||||
/// Ist `q` ein Planzeichen einer Kamera?
|
||||
pub(super) fn is_symbol_part(q: &Primitive) -> bool {
|
||||
match q {
|
||||
Primitive::Line { cls, .. } => cls == "camera-cone" || cls == "camera-aim",
|
||||
Primitive::Polygon { context_object_id: Some(id), .. } => id.starts_with(CAMERA_PICK_PREFIX),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::plan::domains::{plan_domains_buf, PlanArgs};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
fn project(extra: Value) -> Project {
|
||||
let mut v: Value = serde_json::from_str(include_str!("../../tests/fixtures/sample_project.json")).unwrap();
|
||||
v["layers"].as_array_mut().unwrap().push(json!({"code": "92", "name": "Kameras", "color": "#123456", "lw": 0.18, "visible": true, "locked": false}));
|
||||
v["cameras"] = json!([{"id": "k1", "type": "camera", "name": "Süd", "floorId": "eg", "categoryCode": "92", "position": {"x": 2, "y": -3},
|
||||
"eyeHeight": 1.6, "target": {"x": 2, "y": 3}, "targetHeight": 1.6, "fovDeg": 50, "projection": "perspective"}]);
|
||||
if let Some(o) = extra.as_object() {
|
||||
for (k, val) in o {
|
||||
v["cameras"][0][k] = val.clone();
|
||||
}
|
||||
}
|
||||
serde_json::from_value(v).unwrap()
|
||||
}
|
||||
|
||||
fn plan(p: &Project, floor: &str, show: &[String]) -> Vec<Primitive> {
|
||||
let a = PlanArgs::parse(1.0, &json!({"floor": floor, "show": show, "global": true, "scale": 100}).to_string()).unwrap();
|
||||
let buf = plan_domains_buf(p, &a).unwrap();
|
||||
crate::plan::buf::View::parse(&buf).unwrap().prims().unwrap()
|
||||
}
|
||||
|
||||
fn all_codes(p: &Project) -> Vec<String> {
|
||||
let mut c: Vec<String> = p.flat_categories().iter().map(|c| c.code.clone()).collect();
|
||||
c.extend(p.walls.iter().map(|w| w.category_code.clone()));
|
||||
c
|
||||
}
|
||||
|
||||
fn camera_prims(prims: &[Primitive]) -> Vec<&Primitive> {
|
||||
prims.iter().filter(|q| is_symbol_part(q)).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn symbol_auf_der_klasse_der_kamera() {
|
||||
let p = project(json!({}));
|
||||
let all = all_codes(&p);
|
||||
let prims = plan(&p, "eg", &all);
|
||||
let mine = camera_prims(&prims);
|
||||
assert!(mine.iter().any(|q| matches!(q, Primitive::Polygon { context_object_id: Some(id), .. } if id == "@camera:k1")), "Pick-Fläche");
|
||||
assert!(mine.iter().any(|q| matches!(q, Primitive::Line { cls, .. } if cls == "camera-cone")), "Sichtkegel");
|
||||
assert!(prims.iter().any(|q| matches!(q, Primitive::Text { color, .. } if color == "#123456")), "Name in der Klassenfarbe");
|
||||
// Klasse aus: nichts mehr.
|
||||
let without: Vec<String> = all.iter().filter(|c| *c != "92").cloned().collect();
|
||||
let prims = plan(&p, "eg", &without);
|
||||
assert!(camera_prims(&prims).is_empty(), "Klasse 92 aus");
|
||||
assert!(!prims.iter().any(|q| matches!(q, Primitive::Text { color, .. } if color == "#123456")), "Name mit der Klasse aus");
|
||||
// Anderes Geschoss: nichts.
|
||||
if let Some(o) = p.drawing_levels.iter().find(|l| l.id != "eg" && l.kind == DrawingLevelKind::Floor) {
|
||||
assert!(camera_prims(&plan(&p, &o.id, &all)).is_empty(), "anderes Geschoss");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kegel_oeffnet_sich_um_den_bildwinkel() {
|
||||
let p = project(json!({"fovDeg": 40}));
|
||||
let g = CameraGeom::of(&p, &p.cameras.as_ref().unwrap()[0]).unwrap();
|
||||
let a = view_area(&g, 0.1);
|
||||
// Blick nach +y: die Ecken liegen links/rechts davon, symmetrisch.
|
||||
assert!((a[1].x - 2.0 + (a[2].x - 2.0)).abs() < 1e-9);
|
||||
let half = ((a[2].x - 2.0) / (a[2].y + 3.0)).atan().abs();
|
||||
assert!((half - half_h_angle(40.0)).abs() < 1e-9);
|
||||
// Die ferne Kante geht durch das Ziel (Abstand 6 m).
|
||||
assert!((a[1].y - 3.0).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parallelprojektion_zeichnet_streifen() {
|
||||
let p = project(json!({"projection": "axonometric", "orthoHeight": 4}));
|
||||
let g = CameraGeom::of(&p, &p.cameras.as_ref().unwrap()[0]).unwrap();
|
||||
let a = view_area(&g, 0.1);
|
||||
assert_eq!(a.len(), 4);
|
||||
// Breite = 4 m × 16/9.
|
||||
assert!(((a[3].x - a[0].x).abs() - 4.0 * crate::camera::ASPECT).abs() < 1e-9);
|
||||
}
|
||||
}
|
||||
@@ -1744,6 +1744,16 @@ fn domains_after(c: &Ctx, out: &mut DomainPrims, bounds: &mut Bounds) {
|
||||
}
|
||||
// Räume vor dem Kontext: Stempel ausserhalb ihres Raums (eigener Anker im Gelände) sind Hindernisse der
|
||||
// Höhenlinien-Beschriftungen; Stempel im Raum liegen im Fussabdruck, wo keine Beschriftung steht.
|
||||
// [213] Kameras: Planzeichen mit Sichtkegel obenauf (Gruppe der Schnittführungen).
|
||||
let first_camera = out.sections.len();
|
||||
super::cameras::plan_cameras(c, &mut out.sections);
|
||||
// Das Symbol (Kegel, Ziel) gehört zum Ausmass, damit es beim Einpassen nicht abgeschnitten wird.
|
||||
for q in &out.sections[first_camera..] {
|
||||
if let Primitive::Line { a, b, .. } = q {
|
||||
bounds.acc(a.x, a.y);
|
||||
bounds.acc(b.x, b.y);
|
||||
}
|
||||
}
|
||||
let obstacles = stamp_obstacles_with(out, drawn.clone());
|
||||
rooms(c, &mut out.rooms, bounds, &obstacles);
|
||||
if c.a.global {
|
||||
|
||||
@@ -38,6 +38,7 @@ pub mod stamp_place;
|
||||
pub mod floor_finish;
|
||||
pub mod model_view;
|
||||
pub mod trees;
|
||||
pub mod cameras;
|
||||
pub mod mesh_plan;
|
||||
pub mod arc_fit;
|
||||
pub(crate) mod seams;
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn pick_id(id: &str) -> String {
|
||||
format!("{TREE_PICK_PREFIX}{id}")
|
||||
}
|
||||
|
||||
fn poly(pts: Vec<Vec2>, fill: &str, stroke: &str, w: f64, pick: Option<String>, greyed: Option<bool>) -> Primitive {
|
||||
pub(super) fn poly(pts: Vec<Vec2>, fill: &str, stroke: &str, w: f64, pick: Option<String>, greyed: Option<bool>) -> Primitive {
|
||||
Primitive::Polygon {
|
||||
pts,
|
||||
fill: fill.into(),
|
||||
@@ -67,7 +67,7 @@ fn poly(pts: Vec<Vec2>, fill: &str, stroke: &str, w: f64, pick: Option<String>,
|
||||
}
|
||||
}
|
||||
|
||||
fn line(a: Vec2, b: Vec2, cls: &str, w: f64, color: &str, dash: Option<&[f64]>, greyed: Option<bool>) -> Primitive {
|
||||
pub(super) fn line(a: Vec2, b: Vec2, cls: &str, w: f64, color: &str, dash: Option<&[f64]>, greyed: Option<bool>) -> Primitive {
|
||||
Primitive::Line {
|
||||
a,
|
||||
b,
|
||||
|
||||
@@ -15,7 +15,7 @@ const REQUIRED_ARRAYS: [&str; 3] = ["walls", "layers", "drawingLevels"];
|
||||
const DEFAULT_ARRAYS: [&str; 5] = ["lineStyles", "hatches", "components", "wallTypes", "drawings2d"];
|
||||
|
||||
/// Bekannte Felder von `Project` (für die Meldung unbekannter Felder).
|
||||
const KNOWN_KEYS: [&str; 56] = [
|
||||
const KNOWN_KEYS: [&str; 57] = [
|
||||
"formatVersion", "id", "name", "lineStyles", "textStyles", "hatches", "components", "wallTypes",
|
||||
"ceilingTypes", "roofTypes", "blockDefs", "doorTypes", "windowTypes", "stairTypes", "pens",
|
||||
"penSets", "activePenSetId", "customPalettes", "builtinPaletteBanks", "drawingLevels", "layers",
|
||||
@@ -24,7 +24,7 @@ const KNOWN_KEYS: [&str; 56] = [
|
||||
"viewSnapshotFolders", "viewTemplates", "layouts", "masterLayouts", "layoutFolders", "publishSets", "publishLog", "projectNumber", "referenceElevationMasl",
|
||||
"geoAnchor", "roomProgram", "roomProgramTolerance", "parcelArea", "sunStudy", "siteRules", "scaleLineWeights",
|
||||
"lineCap", "lineJoin", "trees", "uiState",
|
||||
"modelViewOptions",
|
||||
"modelViewOptions", "cameras",
|
||||
];
|
||||
|
||||
/// Ergebnis des Einlesens.
|
||||
|
||||
@@ -99,6 +99,9 @@ pub fn dangling_refs(p: &Project) -> Vec<String> {
|
||||
for r in p.rooms.as_deref().unwrap_or(&[]) {
|
||||
miss(&mut out, "Raum", &r.id, "Geschoss", &r.floor_id, &levels);
|
||||
}
|
||||
for c in p.cameras.as_deref().unwrap_or(&[]) {
|
||||
miss(&mut out, "Kamera", &c.id, "Geschoss", &c.floor_id, &levels);
|
||||
}
|
||||
for d in &p.drawings2d {
|
||||
miss(&mut out, "Zeichnung", &d.id, "Ebene", &d.level_id, &levels);
|
||||
miss(&mut out, "Zeichnung", &d.id, "Linienstil", d.line_style_id.as_deref().unwrap_or(""), &line_styles);
|
||||
|
||||
@@ -363,13 +363,16 @@ pub const AUTO_DIM_CATEGORY: &str = "81";
|
||||
pub const LEVEL_MARK_CATEGORY: &str = "82";
|
||||
/// Schnitt- und Ansichtsmarken im Grundriss (Schnittführung mit Pfeilen und Beschriftung).
|
||||
pub const SECTION_MARK_CATEGORY: &str = "91";
|
||||
/// Kameras ([213]): Symbol mit Sichtkegel im Grundriss (Element `Project.cameras`, Klasse je Element änderbar).
|
||||
pub const CAMERA_CATEGORY: &str = "92";
|
||||
|
||||
/// Die Klassen der abgeleiteten Darstellung (Code, Name, Farbe, Strichstärke).
|
||||
pub const DERIVED_CATEGORIES: [(&str, &str, &str, f64); 4] = [
|
||||
pub const DERIVED_CATEGORIES: [(&str, &str, &str, f64); 5] = [
|
||||
(SHADOW_CATEGORY, "Schatten", "#707078", 0.13),
|
||||
(AUTO_DIM_CATEGORY, "Auto-Bemassung", "#303038", 0.13),
|
||||
(LEVEL_MARK_CATEGORY, "Höhenkoten", "#1a1a1a", 0.13),
|
||||
(SECTION_MARK_CATEGORY, "Schnittmarken", "#1a1a1a", 0.18),
|
||||
(CAMERA_CATEGORY, "Kameras", "#1a1a1a", 0.18),
|
||||
];
|
||||
|
||||
pub fn derived_categories() -> Vec<Value> {
|
||||
@@ -841,7 +844,7 @@ mod tests {
|
||||
// Andere Kategorien bleiben, die neue kommt ans Ende.
|
||||
own.insert("layers".into(), json!([{"code": "20", "name": "Wände", "color": "#000", "lw": 0.35, "visible": true, "locked": false}]));
|
||||
let op = merge_ops(&own).into_iter().find(|o| o["key"] == "layers").unwrap();
|
||||
assert_eq!(op["value"].as_array().unwrap().iter().map(|l| l["code"].as_str().unwrap()).collect::<Vec<_>>(), ["20", "65", "08", "81", "82", "91"]);
|
||||
assert_eq!(op["value"].as_array().unwrap().iter().map(|l| l["code"].as_str().unwrap()).collect::<Vec<_>>(), ["20", "65", "08", "81", "82", "91", "92"]);
|
||||
}
|
||||
|
||||
/// [180] Klassen der abgeleiteten Darstellung: „Standards laden" legt sie an, einmal; vorhandene (Code oder Name) bleiben.
|
||||
@@ -857,7 +860,7 @@ mod tests {
|
||||
own.insert("layers".into(), json!([{"code": "77", "name": "schatten", "color": "#000", "lw": 0.13, "visible": true, "locked": false}]));
|
||||
let op = merge_ops(&own).into_iter().find(|o| o["key"] == "layers").unwrap();
|
||||
let codes: Vec<&str> = op["value"].as_array().unwrap().iter().map(|l| l["code"].as_str().unwrap()).collect();
|
||||
assert_eq!(codes, ["77", "65", "81", "82", "91"]);
|
||||
assert_eq!(codes, ["77", "65", "81", "82", "91", "92"]);
|
||||
// Sichtbar, solange die Klasse fehlt; sonst nach der Klassen-Sichtbarkeit.
|
||||
assert!(derived_visible(&p, SHADOW_CATEGORY, |c| c == SHADOW_CATEGORY));
|
||||
assert!(!derived_visible(&p, SHADOW_CATEGORY, |_| false));
|
||||
|
||||
@@ -58,6 +58,14 @@ pub fn grip_vertices(drawing_json: &str, scale: f64) -> Vec<f64> {
|
||||
}
|
||||
}
|
||||
|
||||
/// [213] Griffe einer Kamera (JSON) beim Massstab 1:`scale`: `[x0, y0, x1, y1, x2, y2]` (Standpunkt, Ziel,
|
||||
/// Bildwinkel/Sichtbreite), `[]` bei kaputtem JSON.
|
||||
#[wasm_bindgen]
|
||||
pub fn camera_grip_points(camera_json: &str, scale: f64) -> Vec<f64> {
|
||||
let Ok(c) = serde_json::from_str::<crate::model::Camera>(camera_json) else { return vec![] };
|
||||
crate::camera::grip_points(&c, scale).into_iter().flat_map(|p| [p.0, p.1]).collect()
|
||||
}
|
||||
|
||||
/// Editier-Griffe einer Polylinie aus flachen Puffern (grosse Kataster-Umrisse ohne JSON): `pts = [x0, y0, …]`,
|
||||
/// `bulge` je Segment (fehlend/NaN = gerade) → `[x0, y0, …]` (Eckpunkte, dann je Segment die Bogen-Mitte).
|
||||
#[wasm_bindgen]
|
||||
|
||||
Reference in new issue
Block a user