[27] Punktwolken: Import-Dialog, Anzeige im 3D-Viewport, Gelände-Panel
Menü „Punktwolke importieren …“ und Drag & Drop (.las/.laz/.e57/.ply/.xyz/.pts), Dialog mit Voxel/Budget und Bericht; Lage über geoAnchor (LV95) bzw. Projekt-Nullpunkt mit Hinweis. Wolken im UI-Store (kein Projektfeld, nach Neuladen weg); Abgleich mit render3d über pointCloudSync. TODO [27] nachgeführt. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
18 files changed
+1090
-1
No files matched your search
@@ -291,13 +291,49 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]).
|
||||
|
||||
## Priorität 4 — später
|
||||
|
||||
Alle ○: [27] Punktwolken (Leser ✅ [B9], Anzeige/Modell offen) · [28] Phasen · [29] Bauteillisten (◐, Export vorhanden) · [43] Verknüpfte
|
||||
Alle ○: [27] Punktwolken (Leser ✅ [B9], Anzeige ◐ s. u., Modell offen) · [28] Phasen · [29] Bauteillisten (◐, Export vorhanden) · [43] Verknüpfte
|
||||
Modelle · [44] Aus Datei einfügen · [45] Favoriten · [68] Gelände mit Baugrube (= [T6]) · [71] U-Werte ·
|
||||
[72] Graue Energie KBOB · [73] eBKP-H · [74] SIA 500 · [75] Fluchtwege VKF · [83] Befehlspalette ·
|
||||
[84] Undo-Verlauf · [85] Makro-Rekorder · [86] Pipette · [87] Fang mit Begründung · [48] Web-Worker
|
||||
(◐, DXF-Parser, IFC-Import) · [52] Icons (◐, `CommandIcon.tsx`) · [56] Startparameter · [89] Git-freundliches
|
||||
Format · [90] Versionsvergleich · [91] Assistent · [92] Speckle.
|
||||
|
||||
- ◐ **[27] Punktwolken — Stufe 1: Anzeige im 3D.** (28.10.) render3d: eigene Punkt-Pipeline
|
||||
(`render3d/src/points.rs` GPU-frei: Puffer-Aufbau, Farbabbildung, WGSL; `gpu_points.rs`: Pipeline im
|
||||
selben Pass/Tiefen-/MSAA-Ziel wie das Modell). Ein Instanz-Quad je Punkt (6 Vertices aus
|
||||
`vertex_index`, Position 12 B + RGBA8 4 B je Punkt), feste Grösse in Bildschirm-Pixeln (ab 3 px rund),
|
||||
tiefengetestet gegen das Modell, vom Live-Schnitt gekappt. Puffer zu höchstens 4 Mio. Punkten (ein
|
||||
Draw je Puffer). Farbmodi rgb / Intensität (1.–99. Perzentil) / ASPRS-Klasse / Höhe (fehlt das Attribut →
|
||||
Höhe), auf der CPU berechnet; Moduswechsel schreibt nur den Farbpuffer. Eingabe `xyz` f32 relativ zum
|
||||
Ursprung + Modellversatz f64, Summe in f64 (LV95-fest). Achsen wie Gelände/Import (`MeshKind::Terrain`):
|
||||
Modell (x, y, z) → world (x, z, −y). Bindungen `web.rs` (`set_point_cloud`, `set_point_cloud_style`,
|
||||
`remove_point_cloud`, `clear_point_clouds`; Unsinn → 0 Punkte, kein Panic); derselbe `Renderer` im
|
||||
Browser (WebGPU) und nativ (`render_png --points wolke.txt [--point-size] [--point-color]`; das native Fenster `native.rs` hat
|
||||
denselben Renderer, bekommt aber noch keine Wolken geschoben).
|
||||
UI: Menü „Punktwolke importieren …" (Datei-Menü im Browser + natives App-Menü), Drag & Drop
|
||||
`.las/.laz/.e57/.ply/.xyz/.pts`, Dialog mit Voxel/Budget und Bericht (Anzahl, Ausdehnung, tiefste Ecke,
|
||||
EPSG, Attribute, Lage), Abschnitt „Punktwolken" im Gelände-Panel (Sichtbarkeit, Farbmodus, Punktgrösse,
|
||||
Entfernen). Lage (`state/pointCloudPlacement.ts`): mit `geoAnchor` und LV95 (EPSG 2056 oder ohne EPSG mit
|
||||
LV95-Koordinaten) lagerichtig, Höhe aus `geoAnchor.height` (sonst tiefster Punkt auf 0); sonst lokale
|
||||
Koordinaten wie in der Datei bzw. Landeskoordinaten mittig auf den Nullpunkt — jeweils mit Hinweis.
|
||||
Wolken leben im UI-Store `state/pointCloudStore.ts` (kein Projektfeld). Tests: 14 Rust (Puffer, Farben,
|
||||
WGSL) + 2 GPU-Render in eine Textur (Tiefe gegen Wand, Sichtbarkeit, Farbwechsel, feste Pixelgrösse;
|
||||
`cargo test --features render`, im Container Vulkan/lavapipe) + 12 vitest (Lage, Store, Abgleich).
|
||||
Nebenbei behoben: `CAP_WGSL` rief `fwidth` in nicht-uniformem Kontrollfluss → Chrome/Tint verwarf die
|
||||
Cap-Pipeline und damit JEDEN 3D-Frame (im Browser-Build gesehen); Ableitungen jetzt vor den Verzweigungen,
|
||||
Regressionstest `shaders::uniformity_tests`.
|
||||
- Geprüft: Linux-Container — cargo test (lavapipe), `render_png` mit Demo-Haus + synthetischer Wolke
|
||||
(110 000 Punkte; Tiefe, Klassen-/RGB-Farben sichtbar richtig), Browser-Build in Chromium (WebGPU über
|
||||
SwiftShader): Import-Dialog, Bericht, Panel, Moduswechsel ohne WebGPU-Validierungsfehler. NICHT
|
||||
geprüft: Bild im Browser (Chromium präsentiert hier keine WebGPU-Frames, auch nicht headful unter
|
||||
Xvfb), Tauri-App/macOS-Metal, echte LAS/E57-Dateien, 2–5 Mio. Punkte (Zeit/Speicher), Achsrichtung
|
||||
gegen ein echtes swissALTI3D-Gelände desselben Bezugs.
|
||||
- Offen: **beim Neuladen sind die Wolken weg** (kein Autosave) → Stufe 2 mit Modellfeld
|
||||
`Project.pointClouds` + Asset im IndexedDB/neben der Datei (Vorschlag unter [B9]); Speicher doppelt
|
||||
(JS-Store + Rust-CPU-Kopie für Farbwechsel + GPU); Kamera-Einpassen (`set_view_preset`) kennt die
|
||||
Wolke nicht; Grundriss/Schnitt (Punkte in Scheibe), Fang an Punkten, Clip-Box; sRGB-Ziel in
|
||||
`render_png` hellt Punktfarben (wie alle Vertexfarben) auf.
|
||||
|
||||
## Übernahme aus BIMCraft [B]
|
||||
|
||||
Quelle: github.com/IPedrax/BIMCraft v0.9. Lizenz `MIT OR Apache-2.0` (`crates/rvt` nur Apache-2.0),
|
||||
|
||||
@@ -90,6 +90,9 @@ import {
|
||||
import { HatchSwatch } from "./ui/hatchPreview";
|
||||
import { TopBar, ViewRibbonTab } from "./ui/TopBar";
|
||||
import { AppMenuBar } from "./ui/AppMenuBar";
|
||||
import { PointCloudImportHost } from "./ui/PointCloudImportDialog";
|
||||
import { openPointCloudFileDialog, requestPointCloudImport } from "./state/pointCloudStore";
|
||||
import { isPointCloudFile } from "./io/pointCloud";
|
||||
import { EditorField } from "./ui/EditorField";
|
||||
import { useNativeAppMenu } from "./native/appMenu";
|
||||
import { openResourceWindowNative, useResourceWindowHost } from "./native/resourceWindow";
|
||||
@@ -1745,6 +1748,7 @@ export default function App() {
|
||||
};
|
||||
/** Datei aus Import-Dialog oder Drag & Drop: IFC direkt, sonst DXF/DWG-Dialog. */
|
||||
const openImportForAnyFile = (f: File) => {
|
||||
if (isPointCloudFile(f.name)) return requestPointCloudImport(f);
|
||||
if (/\.ifc$/i.test(f.name)) importIfcFile(f);
|
||||
else openImportForFile(f);
|
||||
};
|
||||
@@ -2450,6 +2454,7 @@ export default function App() {
|
||||
onExportStep,
|
||||
onImportStep: () => stepInputRef.current?.click(),
|
||||
onImportIfc: () => ifcInputRef.current?.click(),
|
||||
onImportPointCloud: () => openPointCloudFileDialog(),
|
||||
onClashCheck: () => {
|
||||
const p0 = project;
|
||||
runClashCheck(p0)
|
||||
@@ -3342,6 +3347,8 @@ export default function App() {
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{/* Punktwolken-Import ([27]): verstecktes Datei-Feld + Dialog (UI-Store, nicht im Projekt). */}
|
||||
<PointCloudImportHost project={project} />
|
||||
{/* Verstecktes IFC-Datei-Input (Menü Datei, IFC importieren). */}
|
||||
<input
|
||||
ref={ifcInputRef}
|
||||
@@ -3428,6 +3435,7 @@ export default function App() {
|
||||
onOpenProject={onOpenProject}
|
||||
onSaveProject={onSaveProject}
|
||||
onImport={() => dxfInputRef.current?.click()}
|
||||
onImportPointCloud={() => openPointCloudFileDialog()}
|
||||
onUndo={undo}
|
||||
onRedo={redo}
|
||||
canUndo={canUndo}
|
||||
|
||||
@@ -1765,6 +1765,52 @@ export const de = {
|
||||
"step.import.done": "STEP importiert: {n} Körper",
|
||||
"menu.native.importStep": "STEP importieren …",
|
||||
"menu.native.importIfc": "IFC importieren …",
|
||||
"menu.native.importPointCloud": "Punktwolke importieren …",
|
||||
"pointCloud.title": "Punktwolke importieren",
|
||||
"pointCloud.file": "Datei",
|
||||
"pointCloud.voxel": "Voxel-Raster in m (0 = aus)",
|
||||
"pointCloud.budget": "Höchstzahl Punkte",
|
||||
"pointCloud.budget.unlimited": "unbegrenzt",
|
||||
"pointCloud.budget.millions": "{n} Mio.",
|
||||
"pointCloud.read": "Lesen",
|
||||
"pointCloud.reading": "Punktwolke wird gelesen …",
|
||||
"pointCloud.add": "Hinzufügen",
|
||||
"pointCloud.cancel": "Abbrechen",
|
||||
"pointCloud.error": "Punktwolke nicht lesbar: {message}",
|
||||
"pointCloud.report": "Bericht",
|
||||
"pointCloud.report.format": "Format",
|
||||
"pointCloud.report.points": "{kept} von {read} Punkten werden angezeigt",
|
||||
"pointCloud.report.voxel": "Voxel {v} m",
|
||||
"pointCloud.report.bbox": "Ausdehnung",
|
||||
"pointCloud.report.bboxValue": "{dx} × {dy} × {dz} m",
|
||||
"pointCloud.report.min": "Tiefste Ecke (O / N / H)",
|
||||
"pointCloud.report.epsg": "Koordinatensystem",
|
||||
"pointCloud.report.epsgNone": "nicht angegeben",
|
||||
"pointCloud.report.attrs": "Attribute",
|
||||
"pointCloud.report.truncated": "Datei unvollständig — gelesen, soweit möglich.",
|
||||
"pointCloud.attr.rgb": "Farbe",
|
||||
"pointCloud.attr.intensity": "Intensität",
|
||||
"pointCloud.attr.class": "Klassen",
|
||||
"pointCloud.attr.none": "nur Lage",
|
||||
"pointCloud.placement.georef": "Lage: über den Standort-Bezug eingepasst (LV95).",
|
||||
"pointCloud.placement.georefAssumed": "Lage: LV95 aus den Koordinaten angenommen und über den Standort-Bezug eingepasst.",
|
||||
"pointCloud.placement.noHeight": "Höhe: Standort-Bezug ohne Höhe — tiefster Punkt auf 0.",
|
||||
"pointCloud.placement.local": "Lage: Ursprung der Wolke = Projekt-Nullpunkt (kein LV95-Bezug).",
|
||||
"pointCloud.placement.centered": "Lage: kein passender Standort-Bezug — Wolke mittig auf den Projekt-Nullpunkt gelegt, tiefster Punkt auf 0.",
|
||||
"pointCloud.sessionHint": "Punktwolken werden noch nicht im Projekt gespeichert und sind nach dem Neuladen weg.",
|
||||
"pointCloud.section": "Punktwolken",
|
||||
"pointCloud.empty": "Keine Punktwolke geladen.",
|
||||
"pointCloud.import": "Importieren …",
|
||||
"pointCloud.visible": "Sichtbar",
|
||||
"pointCloud.color": "Farbmodus",
|
||||
"pointCloud.color.rgb": "Farbe (RGB)",
|
||||
"pointCloud.color.intensity": "Intensität",
|
||||
"pointCloud.color.class": "Klasse",
|
||||
"pointCloud.color.height": "Höhe",
|
||||
"pointCloud.size": "Punktgrösse",
|
||||
"pointCloud.remove": "Punktwolke entfernen",
|
||||
"pointCloud.count": "{n} Punkte",
|
||||
"pointCloud.only3d": "Anzeige nur in der 3D-Ansicht.",
|
||||
"ifc.import.failed": "IFC-Import fehlgeschlagen",
|
||||
"ifc.import.done": "{schema} importiert: {n} Bauteile als Kontext-Meshes",
|
||||
"ifc.import.skipped": "{n} Bauteile ohne lesbare Geometrie, übersprungen: {list}",
|
||||
|
||||
@@ -1724,6 +1724,52 @@ export const en: Record<TranslationKey, string> = {
|
||||
"step.import.done": "STEP imported: {n} solids",
|
||||
"menu.native.importStep": "Import STEP …",
|
||||
"menu.native.importIfc": "Import IFC …",
|
||||
"menu.native.importPointCloud": "Import point cloud …",
|
||||
"pointCloud.title": "Import point cloud",
|
||||
"pointCloud.file": "File",
|
||||
"pointCloud.voxel": "Voxel grid in m (0 = off)",
|
||||
"pointCloud.budget": "Maximum points",
|
||||
"pointCloud.budget.unlimited": "unlimited",
|
||||
"pointCloud.budget.millions": "{n} M",
|
||||
"pointCloud.read": "Read",
|
||||
"pointCloud.reading": "Reading point cloud …",
|
||||
"pointCloud.add": "Add",
|
||||
"pointCloud.cancel": "Cancel",
|
||||
"pointCloud.error": "Point cloud not readable: {message}",
|
||||
"pointCloud.report": "Report",
|
||||
"pointCloud.report.format": "Format",
|
||||
"pointCloud.report.points": "Showing {kept} of {read} points",
|
||||
"pointCloud.report.voxel": "voxel {v} m",
|
||||
"pointCloud.report.bbox": "Extent",
|
||||
"pointCloud.report.bboxValue": "{dx} × {dy} × {dz} m",
|
||||
"pointCloud.report.min": "Lowest corner (E / N / H)",
|
||||
"pointCloud.report.epsg": "Coordinate system",
|
||||
"pointCloud.report.epsgNone": "not specified",
|
||||
"pointCloud.report.attrs": "Attributes",
|
||||
"pointCloud.report.truncated": "File incomplete — read as far as possible.",
|
||||
"pointCloud.attr.rgb": "colour",
|
||||
"pointCloud.attr.intensity": "intensity",
|
||||
"pointCloud.attr.class": "classes",
|
||||
"pointCloud.attr.none": "position only",
|
||||
"pointCloud.placement.georef": "Position: fitted via the site reference (LV95).",
|
||||
"pointCloud.placement.georefAssumed": "Position: LV95 assumed from the coordinates and fitted via the site reference.",
|
||||
"pointCloud.placement.noHeight": "Height: site reference has no elevation — lowest point at 0.",
|
||||
"pointCloud.placement.local": "Position: cloud origin = project origin (no LV95 reference).",
|
||||
"pointCloud.placement.centered": "Position: no matching site reference — cloud centred on the project origin, lowest point at 0.",
|
||||
"pointCloud.sessionHint": "Point clouds are not yet saved in the project and are gone after reloading.",
|
||||
"pointCloud.section": "Point clouds",
|
||||
"pointCloud.empty": "No point cloud loaded.",
|
||||
"pointCloud.import": "Import …",
|
||||
"pointCloud.visible": "Visible",
|
||||
"pointCloud.color": "Colour mode",
|
||||
"pointCloud.color.rgb": "Colour (RGB)",
|
||||
"pointCloud.color.intensity": "Intensity",
|
||||
"pointCloud.color.class": "Class",
|
||||
"pointCloud.color.height": "Height",
|
||||
"pointCloud.size": "Point size",
|
||||
"pointCloud.remove": "Remove point cloud",
|
||||
"pointCloud.count": "{n} points",
|
||||
"pointCloud.only3d": "Shown in the 3D view only.",
|
||||
"ifc.import.failed": "IFC import failed",
|
||||
"ifc.import.done": "{schema} imported: {n} elements as context meshes",
|
||||
"ifc.import.skipped": "{n} elements without readable geometry, skipped: {list}",
|
||||
|
||||
@@ -36,6 +36,8 @@ export interface NativeAppMenuHandlers {
|
||||
onExportStep: () => void;
|
||||
onImportStep: () => void;
|
||||
onImportIfc: () => void;
|
||||
/** Punktwolke importieren ([27]); optional für ältere Aufrufer. */
|
||||
onImportPointCloud?: () => void;
|
||||
onClashCheck: () => void;
|
||||
onKennzahlen: () => void;
|
||||
|
||||
@@ -180,6 +182,10 @@ export function useNativeAppMenu(
|
||||
text: t("menu.native.importIfc"),
|
||||
action: () => handlersRef.current.onImportIfc(),
|
||||
}),
|
||||
await MenuItem.new({
|
||||
text: t("menu.native.importPointCloud"),
|
||||
action: () => handlersRef.current.onImportPointCloud?.(),
|
||||
}),
|
||||
await Submenu.new({
|
||||
text: t("menu.native.export"),
|
||||
items: [
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// Punktwolken im Lage-Panel ([27] Stufe 1): Liste der geladenen Wolken mit Sichtbarkeit,
|
||||
// Farbmodus, Punktgrösse und Entfernen, dazu „Importieren …". Die Wolken liegen im UI-Store
|
||||
// (`state/pointCloudStore.ts`), nicht im Projekt — Änderungen hier sind kein Undo-Schritt.
|
||||
|
||||
import { t } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n";
|
||||
import { usePanelHost } from "./host";
|
||||
import {
|
||||
MAX_POINT_SIZE,
|
||||
MIN_POINT_SIZE,
|
||||
POINT_COLOR_MODES,
|
||||
colorModeAvailable,
|
||||
openPointCloudFileDialog,
|
||||
removePointCloud,
|
||||
updatePointCloud,
|
||||
usePointClouds,
|
||||
} from "../state/pointCloudStore";
|
||||
import type { PointColorMode } from "../state/pointCloudStore";
|
||||
import { placementHints, placementOf } from "../ui/PointCloudImportDialog";
|
||||
|
||||
const MODE_KEY: Record<PointColorMode, TranslationKey> = {
|
||||
rgb: "pointCloud.color.rgb",
|
||||
intensity: "pointCloud.color.intensity",
|
||||
class: "pointCloud.color.class",
|
||||
height: "pointCloud.color.height",
|
||||
};
|
||||
|
||||
export function PointCloudSection() {
|
||||
const host = usePanelHost();
|
||||
const clouds = usePointClouds();
|
||||
return (
|
||||
<div className="site-rules" data-testid="pointcloud-section">
|
||||
<div className="site-rules-head">
|
||||
<span>{t("pointCloud.section")}</span>
|
||||
<button type="button" className="site-btn" onClick={() => openPointCloudFileDialog()}>
|
||||
{t("pointCloud.import")}
|
||||
</button>
|
||||
</div>
|
||||
{clouds.length === 0 && <div className="sun-readout">{t("pointCloud.empty")}</div>}
|
||||
{clouds.map((c) => (
|
||||
<div key={c.id} className="site-rules">
|
||||
<div className="sun-row">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={c.visible}
|
||||
title={t("pointCloud.visible")}
|
||||
aria-label={t("pointCloud.visible")}
|
||||
onChange={(e) => updatePointCloud(c.id, { visible: e.target.checked })}
|
||||
/>
|
||||
<span className="site-name" title={c.name}>
|
||||
{c.name}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="site-remove"
|
||||
title={t("pointCloud.remove")}
|
||||
aria-label={t("pointCloud.remove")}
|
||||
onClick={() => removePointCloud(c.id)}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
<div className="sun-row">
|
||||
<select
|
||||
className="kz-input"
|
||||
value={c.colorMode}
|
||||
title={t("pointCloud.color")}
|
||||
aria-label={t("pointCloud.color")}
|
||||
onChange={(e) => updatePointCloud(c.id, { colorMode: e.target.value as PointColorMode })}
|
||||
>
|
||||
{POINT_COLOR_MODES.map((m) => (
|
||||
<option key={m} value={m} disabled={!colorModeAvailable(c.data.report, m)}>
|
||||
{t(MODE_KEY[m])}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
type="range"
|
||||
className="sun-slider"
|
||||
min={MIN_POINT_SIZE}
|
||||
max={MAX_POINT_SIZE}
|
||||
step={1}
|
||||
value={c.pointSize}
|
||||
title={t("pointCloud.size")}
|
||||
aria-label={t("pointCloud.size")}
|
||||
onChange={(e) => updatePointCloud(c.id, { pointSize: Number(e.target.value) })}
|
||||
/>
|
||||
<span className="sun-time">{c.pointSize} px</span>
|
||||
</div>
|
||||
<div className="sun-readout">
|
||||
{t("pointCloud.count", { n: c.data.report.pointsKept.toLocaleString("de-CH") })}
|
||||
{c.data.report.epsg !== null && <> · EPSG {c.data.report.epsg}</>}
|
||||
{" · "}
|
||||
{placementHints(placementOf(c.data, host.project))
|
||||
.map((k) => t(k))
|
||||
.join(" ")}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{clouds.length > 0 && <div className="sun-readout">{t("pointCloud.only3d")} {t("pointCloud.sessionHint")}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import { isTauriRuntime } from "../native/projectFile";
|
||||
import { openContextImportWindowNative } from "../native/contextImportWindow";
|
||||
import { SunStudySection } from "./SunStudySection";
|
||||
import { SiteRulesSection } from "./SiteRulesSection";
|
||||
import { PointCloudSection } from "./PointCloudSection";
|
||||
|
||||
/** Typ-spezifisches Badge-Label (i18n-Key) je Kontext-Objekt-Art. */
|
||||
function typeBadgeKey(obj: ContextObject): TranslationKey {
|
||||
@@ -163,6 +164,8 @@ export function SitePanel() {
|
||||
<div className="site-sep" />
|
||||
<SiteRulesSection />
|
||||
<div className="site-sep" />
|
||||
<PointCloudSection />
|
||||
<div className="site-sep" />
|
||||
|
||||
{/* Kontext-Objekte nach Ebene (`layer`) gruppiert: importierte Gebäude
|
||||
liegen als EINZELNE, getrennt lösch-/anwählbare Elemente unter ihrer
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { looksLikeLv95, placePointCloud } from "./pointCloudPlacement";
|
||||
|
||||
const lv95Cloud = {
|
||||
origin: [2_600_100, 1_200_050, 450] as [number, number, number],
|
||||
bboxMin: [2_600_090, 1_200_040, 440] as [number, number, number],
|
||||
bboxMax: [2_600_120, 1_200_070, 470] as [number, number, number],
|
||||
};
|
||||
|
||||
describe("placePointCloud", () => {
|
||||
it("passt eine LV95-Wolke über den Standort-Bezug ein (Höhe aus dem Anker)", () => {
|
||||
const p = placePointCloud({ ...lv95Cloud, epsg: 2056 }, { e: 2_600_000, n: 1_200_000 }, 445);
|
||||
expect(p.mode).toBe("georef");
|
||||
expect(p.offset).toEqual([100, 50, 5]);
|
||||
expect(p.heightFromAnchor).toBe(true);
|
||||
expect(p.epsgAssumed).toBe(false);
|
||||
});
|
||||
|
||||
it("ohne Ankerhöhe: tiefster Punkt auf 0", () => {
|
||||
const p = placePointCloud({ ...lv95Cloud, epsg: 2056 }, { e: 2_600_000, n: 1_200_000 });
|
||||
expect(p.offset).toEqual([100, 50, 10]);
|
||||
expect(p.heightFromAnchor).toBe(false);
|
||||
});
|
||||
|
||||
it("ohne EPSG, aber mit LV95-Koordinaten: LV95 angenommen", () => {
|
||||
const p = placePointCloud({ ...lv95Cloud, epsg: null }, { e: 2_600_000, n: 1_200_000 }, 440);
|
||||
expect(p.mode).toBe("georef");
|
||||
expect(p.epsgAssumed).toBe(true);
|
||||
});
|
||||
|
||||
it("anderes EPSG mit Bezug: nicht georeferenziert, sondern zentriert", () => {
|
||||
const p = placePointCloud({ ...lv95Cloud, epsg: 4326 }, { e: 2_600_000, n: 1_200_000 });
|
||||
expect(p.mode).toBe("centered");
|
||||
});
|
||||
|
||||
it("ohne Bezug: Landeskoordinaten werden mittig auf den Nullpunkt gelegt", () => {
|
||||
const p = placePointCloud({ ...lv95Cloud, epsg: 2056 }, null);
|
||||
expect(p.mode).toBe("centered");
|
||||
// Mitte (2 600 105 / 1 200 055) → 0, tiefster Punkt 440 → 0.
|
||||
expect(p.offset).toEqual([-5, -5, 10]);
|
||||
});
|
||||
|
||||
it("lokale Koordinaten bleiben wie in der Datei", () => {
|
||||
const p = placePointCloud(
|
||||
{ origin: [3, 4, 0], bboxMin: [-5, -5, -1], bboxMax: [12, 9, 6], epsg: null },
|
||||
{ e: 2_600_000, n: 1_200_000 },
|
||||
);
|
||||
expect(p.mode).toBe("local");
|
||||
expect(p.offset).toEqual([3, 4, 0]);
|
||||
});
|
||||
|
||||
it("erkennt LV95-Bereich", () => {
|
||||
expect(looksLikeLv95(lv95Cloud.bboxMin, lv95Cloud.bboxMax)).toBe(true);
|
||||
expect(looksLikeLv95([600_000, 200_000, 0], [600_100, 200_100, 0])).toBe(false); // LV03
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
// Lage einer importierten Punktwolke im Projekt ([27] Stufe 1). Rein rechnend, ohne UI.
|
||||
//
|
||||
// Der Leser liefert `xyz` (f32) relativ zu `origin` (f64, Dateikoordinaten). Hier entsteht der
|
||||
// Modellversatz dieses Ursprungs (f64, Modell-Meter x = Ost, y = Nord, z = Höhe); render3d bildet
|
||||
// `versatz + xyz` in f64 und rundet erst danach auf f32 (LV95-fest, s. `render3d/src/points.rs`).
|
||||
//
|
||||
// • Projekt hat einen Standort-Bezug (`geoAnchor`) und die Wolke liegt in LV95 (EPSG 2056, oder
|
||||
// ohne EPSG-Angabe mit LV95-typischen Koordinaten): lagerichtig einpassen. Höhe: mit
|
||||
// `geoAnchor.height` (m ü. M. des Bezugspunkts) absolut, sonst tiefster Punkt auf 0 + Hinweis.
|
||||
// • Sonst: Ursprung der Wolke = Projekt-Nullpunkt. Kleine (lokale) Koordinaten bleiben wie in
|
||||
// der Datei; grosse (Landeskoordinaten ohne Bezug) werden mit der Mitte auf den Nullpunkt und
|
||||
// dem tiefsten Punkt auf 0 gelegt. Immer mit Hinweis.
|
||||
|
||||
export type PointCloudPlacementMode = "georef" | "local" | "centered";
|
||||
|
||||
export interface PointCloudPlacement {
|
||||
/** Modell-Meter des Wolken-Ursprungs (x = Ost, y = Nord, z = Höhe); Punkt = offset + xyz. */
|
||||
offset: [number, number, number];
|
||||
mode: PointCloudPlacementMode;
|
||||
/** Höhe absolut übernommen (sonst tiefster Punkt auf 0 bzw. Dateihöhe). */
|
||||
heightFromAnchor: boolean;
|
||||
/** Ohne EPSG-Angabe wurde LV95 aus den Koordinaten erschlossen. */
|
||||
epsgAssumed: boolean;
|
||||
}
|
||||
|
||||
export interface PointCloudPlacementInput {
|
||||
origin: [number, number, number];
|
||||
bboxMin: [number, number, number];
|
||||
bboxMax: [number, number, number];
|
||||
epsg: number | null;
|
||||
}
|
||||
|
||||
/** LV95-Bereich der Schweiz (grosszügig): E 2,45–2,85 Mio., N 1,05–1,32 Mio. m. */
|
||||
export function looksLikeLv95(min: [number, number, number], max: [number, number, number]): boolean {
|
||||
return min[0] >= 2_450_000 && max[0] <= 2_850_000 && min[1] >= 1_050_000 && max[1] <= 1_320_000;
|
||||
}
|
||||
|
||||
/** Ab dieser Ausdehnung vom Nullpunkt gelten Koordinaten als „Landeskoordinaten" (nicht lokal). */
|
||||
const LOCAL_LIMIT_M = 50_000;
|
||||
|
||||
export function placePointCloud(
|
||||
cloud: PointCloudPlacementInput,
|
||||
geoOrigin: { e: number; n: number } | null,
|
||||
geoHeight?: number,
|
||||
): PointCloudPlacement {
|
||||
const [ox, oy, oz] = cloud.origin;
|
||||
const isLv95 = cloud.epsg === 2056;
|
||||
const assumeLv95 = cloud.epsg === null && looksLikeLv95(cloud.bboxMin, cloud.bboxMax);
|
||||
if (geoOrigin && (isLv95 || assumeLv95)) {
|
||||
const heightFromAnchor = geoHeight !== undefined && Number.isFinite(geoHeight);
|
||||
return {
|
||||
offset: [ox - geoOrigin.e, oy - geoOrigin.n, heightFromAnchor ? oz - geoHeight : oz - cloud.bboxMin[2]],
|
||||
mode: "georef",
|
||||
heightFromAnchor,
|
||||
epsgAssumed: assumeLv95,
|
||||
};
|
||||
}
|
||||
const far = [...cloud.bboxMin, ...cloud.bboxMax].some((v) => Math.abs(v) > LOCAL_LIMIT_M);
|
||||
if (!far) return { offset: [ox, oy, oz], mode: "local", heightFromAnchor: false, epsgAssumed: false };
|
||||
const cx = (cloud.bboxMin[0] + cloud.bboxMax[0]) / 2;
|
||||
const cy = (cloud.bboxMin[1] + cloud.bboxMax[1]) / 2;
|
||||
return {
|
||||
offset: [ox - cx, oy - cy, oz - cloud.bboxMin[2]],
|
||||
mode: "centered",
|
||||
heightFromAnchor: false,
|
||||
epsgAssumed: false,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import type { PointCloudData, PointCloudReport } from "../io/pointCloud";
|
||||
import {
|
||||
addPointCloud,
|
||||
clearPointClouds,
|
||||
defaultColorMode,
|
||||
getPointClouds,
|
||||
removePointCloud,
|
||||
resetPointCloudStoreForTests,
|
||||
updatePointCloud,
|
||||
} from "./pointCloudStore";
|
||||
|
||||
function report(p: Partial<PointCloudReport> = {}): PointCloudReport {
|
||||
return {
|
||||
format: "las",
|
||||
version: "1.4",
|
||||
pointFormat: 3,
|
||||
pointsDeclared: 2,
|
||||
pointsRead: 2,
|
||||
pointsKept: 2,
|
||||
pointsInvalid: 0,
|
||||
voxel: 0,
|
||||
bboxMin: [0, 0, 0],
|
||||
bboxMax: [1, 1, 1],
|
||||
origin: [0, 0, 0],
|
||||
hasColor: false,
|
||||
hasIntensity: false,
|
||||
hasClassification: false,
|
||||
intensityRange: null,
|
||||
classCounts: [],
|
||||
epsg: null,
|
||||
truncated: false,
|
||||
warnings: [],
|
||||
...p,
|
||||
};
|
||||
}
|
||||
|
||||
function cloud(p: Partial<PointCloudReport> = {}): PointCloudData {
|
||||
return {
|
||||
origin: [0, 0, 0],
|
||||
xyz: new Float32Array(6),
|
||||
rgb: null,
|
||||
intensity: null,
|
||||
classification: null,
|
||||
report: report(p),
|
||||
};
|
||||
}
|
||||
|
||||
describe("pointCloudStore", () => {
|
||||
beforeEach(() => resetPointCloudStoreForTests());
|
||||
|
||||
it("wählt den Farbmodus nach vorhandenen Attributen", () => {
|
||||
expect(defaultColorMode(report({ hasColor: true, hasIntensity: true }))).toBe("rgb");
|
||||
expect(defaultColorMode(report({ hasIntensity: true }))).toBe("intensity");
|
||||
expect(defaultColorMode(report({ hasClassification: true }))).toBe("class");
|
||||
expect(defaultColorMode(report())).toBe("height");
|
||||
});
|
||||
|
||||
it("fügt hinzu, ändert und entfernt", () => {
|
||||
const a = addPointCloud("a.las", cloud({ hasColor: true }));
|
||||
const b = addPointCloud("b.xyz", cloud());
|
||||
expect(getPointClouds().map((c) => c.id)).toEqual([a, b]);
|
||||
expect(getPointClouds()[0]).toMatchObject({ visible: true, colorMode: "rgb", pointSize: 2 });
|
||||
|
||||
const before = getPointClouds();
|
||||
updatePointCloud(a, { visible: false, pointSize: 99 });
|
||||
expect(getPointClouds()).not.toBe(before); // neue Referenz → React rendert neu
|
||||
expect(getPointClouds()[0]).toMatchObject({ visible: false, pointSize: 10 });
|
||||
updatePointCloud(a, { pointSize: Number.NaN, colorMode: "quatsch" as never });
|
||||
expect(getPointClouds()[0]).toMatchObject({ pointSize: 10, colorMode: "rgb" });
|
||||
|
||||
removePointCloud(a);
|
||||
expect(getPointClouds().map((c) => c.id)).toEqual([b]);
|
||||
const same = getPointClouds();
|
||||
removePointCloud(12345);
|
||||
expect(getPointClouds()).toBe(same);
|
||||
clearPointClouds();
|
||||
expect(getPointClouds()).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,157 @@
|
||||
// Punktwolken im UI-Zustand ([27] Stufe 1). Bewusst KEIN `Project`-Feld: die Punkte (Millionen,
|
||||
// zig MB) gehören nicht ins .obp, und das Modellfeld (`Project.pointClouds`, Vorschlag in TODO.md
|
||||
// [27]) kommt erst mit dem Asset-Speicher. Bis dahin leben die Wolken nur in dieser Sitzung —
|
||||
// nach dem Neuladen sind sie weg (bekannt, s. TODO).
|
||||
//
|
||||
// Kleiner externer Store (Muster `busyStore.ts`, `useSyncExternalStore`), weil Viewport (Anzeige),
|
||||
// Lage-Panel (Liste/Einstellungen) und der Import-Dialog in getrennten Teilbäumen sitzen.
|
||||
|
||||
import { useSyncExternalStore } from "react";
|
||||
import type { PointCloudData, PointCloudReport } from "../io/pointCloud";
|
||||
|
||||
export type PointColorMode = "rgb" | "intensity" | "class" | "height";
|
||||
|
||||
export const POINT_COLOR_MODES: readonly PointColorMode[] = ["rgb", "intensity", "class", "height"];
|
||||
|
||||
export interface PointCloudEntry {
|
||||
/** Laufnummer (auch die id im Renderer). */
|
||||
id: number;
|
||||
name: string;
|
||||
data: PointCloudData;
|
||||
visible: boolean;
|
||||
colorMode: PointColorMode;
|
||||
/** Punktgrösse in Bildschirm-Pixeln. */
|
||||
pointSize: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_POINT_SIZE = 2;
|
||||
export const MIN_POINT_SIZE = 1;
|
||||
export const MAX_POINT_SIZE = 10;
|
||||
|
||||
/** Ist der Farbmodus mit den Attributen der Wolke möglich? (Höhe immer.) */
|
||||
export function colorModeAvailable(report: PointCloudReport, mode: PointColorMode): boolean {
|
||||
if (mode === "rgb") return report.hasColor;
|
||||
if (mode === "intensity") return report.hasIntensity;
|
||||
if (mode === "class") return report.hasClassification;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Voreinstellung: gemessene Farbe, sonst Intensität, sonst Klassen, sonst Höhe. */
|
||||
export function defaultColorMode(report: PointCloudReport): PointColorMode {
|
||||
return POINT_COLOR_MODES.find((m) => colorModeAvailable(report, m)) ?? "height";
|
||||
}
|
||||
|
||||
let clouds: readonly PointCloudEntry[] = [];
|
||||
let nextId = 1;
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function emit(): void {
|
||||
for (const l of listeners) l();
|
||||
}
|
||||
|
||||
function subscribe(l: () => void): () => void {
|
||||
listeners.add(l);
|
||||
return () => listeners.delete(l);
|
||||
}
|
||||
|
||||
export function getPointClouds(): readonly PointCloudEntry[] {
|
||||
return clouds;
|
||||
}
|
||||
|
||||
/** Fügt eine gelesene Wolke hinzu (sichtbar, Voreinstellungen aus dem Bericht); liefert die id. */
|
||||
export function addPointCloud(name: string, data: PointCloudData): number {
|
||||
const id = nextId++;
|
||||
clouds = [
|
||||
...clouds,
|
||||
{ id, name, data, visible: true, colorMode: defaultColorMode(data.report), pointSize: DEFAULT_POINT_SIZE },
|
||||
];
|
||||
emit();
|
||||
return id;
|
||||
}
|
||||
|
||||
/** Ändert Sichtbarkeit/Farbmodus/Punktgrösse/Name (Unbekanntes wird ignoriert, Grösse geklemmt). */
|
||||
export function updatePointCloud(
|
||||
id: number,
|
||||
patch: Partial<Pick<PointCloudEntry, "visible" | "colorMode" | "pointSize" | "name">>,
|
||||
): void {
|
||||
let changed = false;
|
||||
clouds = clouds.map((c) => {
|
||||
if (c.id !== id) return c;
|
||||
changed = true;
|
||||
const next = { ...c, ...patch };
|
||||
if (!Number.isFinite(next.pointSize)) next.pointSize = c.pointSize;
|
||||
next.pointSize = Math.min(MAX_POINT_SIZE, Math.max(MIN_POINT_SIZE, next.pointSize));
|
||||
if (!POINT_COLOR_MODES.includes(next.colorMode)) next.colorMode = c.colorMode;
|
||||
return next;
|
||||
});
|
||||
if (changed) emit();
|
||||
}
|
||||
|
||||
export function removePointCloud(id: number): void {
|
||||
const next = clouds.filter((c) => c.id !== id);
|
||||
if (next.length === clouds.length) return;
|
||||
clouds = next;
|
||||
emit();
|
||||
}
|
||||
|
||||
export function clearPointClouds(): void {
|
||||
if (clouds.length === 0) return;
|
||||
clouds = [];
|
||||
emit();
|
||||
}
|
||||
|
||||
export function usePointClouds(): readonly PointCloudEntry[] {
|
||||
return useSyncExternalStore(subscribe, getPointClouds, getPointClouds);
|
||||
}
|
||||
|
||||
// ── Import-Anfrage (Menü, Drag & Drop, Panel-Knopf → Dialog) ────────────────────────────────
|
||||
|
||||
let pendingFile: File | null = null;
|
||||
const importListeners = new Set<() => void>();
|
||||
let fileInput: HTMLInputElement | null = null;
|
||||
|
||||
function emitImport(): void {
|
||||
for (const l of importListeners) l();
|
||||
}
|
||||
|
||||
/** Öffnet den Import-Dialog für `file` (Drag & Drop, Datei-Auswahl). */
|
||||
export function requestPointCloudImport(file: File): void {
|
||||
pendingFile = file;
|
||||
emitImport();
|
||||
}
|
||||
|
||||
/** Schliesst den Import-Dialog. */
|
||||
export function closePointCloudImport(): void {
|
||||
if (pendingFile === null) return;
|
||||
pendingFile = null;
|
||||
emitImport();
|
||||
}
|
||||
|
||||
export function usePointCloudImportRequest(): File | null {
|
||||
return useSyncExternalStore(
|
||||
(l) => {
|
||||
importListeners.add(l);
|
||||
return () => importListeners.delete(l);
|
||||
},
|
||||
() => pendingFile,
|
||||
() => pendingFile,
|
||||
);
|
||||
}
|
||||
|
||||
/** Der Dialog-Host meldet sein verstecktes Datei-Feld an (oder ab mit `null`). */
|
||||
export function registerPointCloudFileInput(el: HTMLInputElement | null): void {
|
||||
fileInput = el;
|
||||
}
|
||||
|
||||
/** Datei-Auswahl öffnen (Menü „Punktwolke importieren …"). Synchron im Klick, sonst blockt WebKit. */
|
||||
export function openPointCloudFileDialog(): void {
|
||||
fileInput?.click();
|
||||
}
|
||||
|
||||
/** Nur für Tests: Zustand zurücksetzen. */
|
||||
export function resetPointCloudStoreForTests(): void {
|
||||
clouds = [];
|
||||
nextId = 1;
|
||||
pendingFile = null;
|
||||
fileInput = null;
|
||||
}
|
||||
@@ -8243,3 +8243,10 @@ body {
|
||||
gap: 6px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* Punktwolken-Import ([27]): Bericht im Dialog kompakt wie die übrigen Hinweise. */
|
||||
.pc-report {
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--ink-2);
|
||||
}
|
||||
@@ -19,6 +19,8 @@ export interface AppMenuBarProps {
|
||||
onOpenProject: () => void;
|
||||
onSaveProject: () => void;
|
||||
onImport: () => void;
|
||||
/** Datei: Punktwolke importieren ([27]). */
|
||||
onImportPointCloud?: () => void;
|
||||
|
||||
/** Bearbeiten: Undo/Redo (Store) + Löschen der aktuellen Auswahl. */
|
||||
onUndo: () => void;
|
||||
@@ -51,6 +53,7 @@ export function AppMenuBar({
|
||||
onOpenProject,
|
||||
onSaveProject,
|
||||
onImport,
|
||||
onImportPointCloud,
|
||||
onUndo,
|
||||
onRedo,
|
||||
canUndo,
|
||||
@@ -76,6 +79,7 @@ export function AppMenuBar({
|
||||
{ label: t("file.save"), onSelect: onSaveProject },
|
||||
{ divider: true },
|
||||
{ label: t("file.import"), onSelect: onImport },
|
||||
...(onImportPointCloud ? [{ label: t("menu.native.importPointCloud"), onSelect: onImportPointCloud }] : []),
|
||||
];
|
||||
|
||||
const editItems: DropdownItem[] = [
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
// Punktwolken-Import ([27] Stufe 1): verstecktes Datei-Feld + Dialog mit Voxel/Budget-Wahl und
|
||||
// Bericht (Anzahl, Ausdehnung, EPSG, Lage). Einmal in App eingehängt (`PointCloudImportHost`);
|
||||
// geöffnet über Menü (`openPointCloudFileDialog`), Drag & Drop oder das Lage-Panel
|
||||
// (`requestPointCloudImport`). Gelesen wird im Web-Worker (`readPointCloud`), die fertige Wolke
|
||||
// landet im UI-Store (`pointCloudStore.ts`), NICHT im Projekt.
|
||||
//
|
||||
// Muster: ExportDxfDialog (abgedunkeltes Overlay, Esc/Hintergrund schliessen).
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { t } from "../i18n";
|
||||
import type { TranslationKey } from "../i18n";
|
||||
import { Dropdown } from "./Dropdown";
|
||||
import { DEFAULT_MAX_POINTS, POINT_CLOUD_EXTENSIONS, readPointCloud } from "../io/pointCloud";
|
||||
import type { PointCloudData } from "../io/pointCloud";
|
||||
import {
|
||||
addPointCloud,
|
||||
closePointCloudImport,
|
||||
registerPointCloudFileInput,
|
||||
requestPointCloudImport,
|
||||
usePointCloudImportRequest,
|
||||
} from "../state/pointCloudStore";
|
||||
import { placePointCloud } from "../state/pointCloudPlacement";
|
||||
import type { PointCloudPlacement } from "../state/pointCloudPlacement";
|
||||
import { projectGeoOrigin } from "../core";
|
||||
import type { Project } from "../model/types";
|
||||
|
||||
const BUDGETS = [1_000_000, 2_000_000, DEFAULT_MAX_POINTS, 10_000_000, 0];
|
||||
|
||||
const fmtInt = (n: number) => Math.round(n).toLocaleString("de-CH");
|
||||
const fmtM = (n: number) => (Math.abs(n) >= 1000 ? n.toFixed(1) : n.toFixed(2));
|
||||
|
||||
/** Hinweistexte zur Lage (für Dialog und Panel). */
|
||||
export function placementHints(p: PointCloudPlacement): TranslationKey[] {
|
||||
if (p.mode === "georef") {
|
||||
const keys: TranslationKey[] = [
|
||||
p.epsgAssumed ? "pointCloud.placement.georefAssumed" : "pointCloud.placement.georef",
|
||||
];
|
||||
if (!p.heightFromAnchor) keys.push("pointCloud.placement.noHeight");
|
||||
return keys;
|
||||
}
|
||||
return [p.mode === "local" ? "pointCloud.placement.local" : "pointCloud.placement.centered"];
|
||||
}
|
||||
|
||||
export function placementOf(data: PointCloudData, project: Project): PointCloudPlacement {
|
||||
const r = data.report;
|
||||
return placePointCloud(
|
||||
{ origin: data.origin, bboxMin: r.bboxMin, bboxMax: r.bboxMax, epsg: r.epsg },
|
||||
projectGeoOrigin(project),
|
||||
project.geoAnchor?.height,
|
||||
);
|
||||
}
|
||||
|
||||
function PointCloudImportDialog({ file, project }: { file: File; project: Project }) {
|
||||
const [voxel, setVoxel] = useState("0");
|
||||
const [budget, setBudget] = useState(DEFAULT_MAX_POINTS);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [result, setResult] = useState<PointCloudData | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") closePointCloudImport();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, []);
|
||||
|
||||
const onRead = async () => {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setResult(null);
|
||||
try {
|
||||
const v = Number(voxel.replace(",", "."));
|
||||
const data = await readPointCloud(await file.arrayBuffer(), file.name, {
|
||||
voxel: Number.isFinite(v) && v > 0 ? v : 0,
|
||||
maxPoints: budget,
|
||||
});
|
||||
setResult(data);
|
||||
} catch (e) {
|
||||
setError(t("pointCloud.error", { message: e instanceof Error ? e.message : String(e) }));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const onAdd = () => {
|
||||
if (!result) return;
|
||||
addPointCloud(file.name, result);
|
||||
closePointCloudImport();
|
||||
};
|
||||
|
||||
const r = result?.report;
|
||||
const placement = result ? placementOf(result, project) : null;
|
||||
const attrs = r
|
||||
? [
|
||||
r.hasColor && t("pointCloud.attr.rgb"),
|
||||
r.hasIntensity && t("pointCloud.attr.intensity"),
|
||||
r.hasClassification && t("pointCloud.attr.class"),
|
||||
].filter(Boolean)
|
||||
: [];
|
||||
|
||||
return (
|
||||
<div className="imp-overlay" onClick={() => closePointCloudImport()}>
|
||||
<div
|
||||
className="imp-dialog"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={t("pointCloud.title")}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<header className="imp-head">
|
||||
<span className="imp-head-title">{t("pointCloud.title")}</span>
|
||||
<button className="imp-close" onClick={() => closePointCloudImport()} aria-label={t("pointCloud.cancel")}>
|
||||
×
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div className="imp-body">
|
||||
<div className="imp-file">
|
||||
<span className="imp-file-label">{t("pointCloud.file")}</span>
|
||||
<span className="imp-file-name" title={file.name}>
|
||||
{file.name} · {fmtInt(file.size / 1e6)} MB
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("pointCloud.voxel")}</div>
|
||||
<input
|
||||
className="kz-input"
|
||||
type="number"
|
||||
min={0}
|
||||
step={0.05}
|
||||
value={voxel}
|
||||
aria-label={t("pointCloud.voxel")}
|
||||
onChange={(e) => setVoxel(e.target.value)}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("pointCloud.budget")}</div>
|
||||
<Dropdown
|
||||
value={String(budget)}
|
||||
onChange={(v) => setBudget(Number(v))}
|
||||
title={t("pointCloud.budget")}
|
||||
options={BUDGETS.map((b) => ({
|
||||
value: String(b),
|
||||
label: b === 0 ? t("pointCloud.budget.unlimited") : t("pointCloud.budget.millions", { n: b / 1e6 }),
|
||||
}))}
|
||||
/>
|
||||
</section>
|
||||
|
||||
{busy && <div className="imp-note">{t("pointCloud.reading")}</div>}
|
||||
{error && <div className="imp-warn">{error}</div>}
|
||||
|
||||
{r && placement && (
|
||||
<section className="imp-section pc-report" data-testid="pointcloud-report">
|
||||
<div className="imp-section-title">{t("pointCloud.report")}</div>
|
||||
<div>
|
||||
{t("pointCloud.report.format")}: {r.format.toUpperCase()} {r.version}
|
||||
</div>
|
||||
<div>
|
||||
{t("pointCloud.report.points", { kept: fmtInt(r.pointsKept), read: fmtInt(r.pointsRead) })}
|
||||
{r.voxel > 0 && <> · {t("pointCloud.report.voxel", { v: fmtM(r.voxel) })}</>}
|
||||
</div>
|
||||
<div>
|
||||
{t("pointCloud.report.bbox")}:{" "}
|
||||
{t("pointCloud.report.bboxValue", {
|
||||
dx: fmtM(r.bboxMax[0] - r.bboxMin[0]),
|
||||
dy: fmtM(r.bboxMax[1] - r.bboxMin[1]),
|
||||
dz: fmtM(r.bboxMax[2] - r.bboxMin[2]),
|
||||
})}
|
||||
</div>
|
||||
<div>
|
||||
{t("pointCloud.report.min")}: {r.bboxMin.map(fmtM).join(" / ")}
|
||||
</div>
|
||||
<div>
|
||||
{t("pointCloud.report.epsg")}: {r.epsg !== null ? `EPSG ${r.epsg}` : t("pointCloud.report.epsgNone")}
|
||||
</div>
|
||||
<div>
|
||||
{t("pointCloud.report.attrs")}: {attrs.length ? attrs.join(", ") : t("pointCloud.attr.none")}
|
||||
</div>
|
||||
{r.truncated && <div className="imp-warn">{t("pointCloud.report.truncated")}</div>}
|
||||
{r.warnings.map((w) => (
|
||||
<div key={w} className="imp-note">
|
||||
{w}
|
||||
</div>
|
||||
))}
|
||||
{placementHints(placement).map((k) => (
|
||||
<div key={k} className="imp-note">
|
||||
{t(k)}
|
||||
</div>
|
||||
))}
|
||||
<div className="imp-note">{t("pointCloud.sessionHint")}</div>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<footer className="imp-foot">
|
||||
<button className="imp-btn" onClick={() => closePointCloudImport()}>
|
||||
{t("pointCloud.cancel")}
|
||||
</button>
|
||||
<button className="imp-btn" onClick={() => void onRead()} disabled={busy}>
|
||||
{t("pointCloud.read")}
|
||||
</button>
|
||||
<button className="imp-btn primary" onClick={onAdd} disabled={!result || busy}>
|
||||
{t("pointCloud.add")}
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Verstecktes Datei-Feld + Dialog; einmal in der App einhängen. */
|
||||
export function PointCloudImportHost({ project }: { project: Project }) {
|
||||
const file = usePointCloudImportRequest();
|
||||
return (
|
||||
<>
|
||||
<input
|
||||
ref={registerPointCloudFileInput}
|
||||
type="file"
|
||||
accept={POINT_CLOUD_EXTENSIONS.map((e) => "." + e).join(",")}
|
||||
style={{ display: "none" }}
|
||||
data-testid="pointcloud-input"
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0];
|
||||
e.target.value = "";
|
||||
if (f) requestPointCloudImport(f);
|
||||
}}
|
||||
/>
|
||||
{file && <PointCloudImportDialog key={file.name + file.size + file.lastModified} file={file} project={project} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -65,6 +65,9 @@ import type { Camera3d } from "./useWasm3dRenderer";
|
||||
import { cameraRay, pickNearest, rayPlaneY, rayPlane, worldToScreen } from "./raycast3d";
|
||||
import type { Vec3 } from "../core";
|
||||
import { drawingGripVertices, drawingMoveAnchor } from "./drawingGrips";
|
||||
import { pointCloudSyncItems } from "./pointCloudSync";
|
||||
import { usePointClouds } from "../state/pointCloudStore";
|
||||
import { projectGeoOrigin } from "../core";
|
||||
|
||||
/** Ein per 3D-Klick getroffenes Bauteil, oder null (Leerraum). */
|
||||
export type Pick3dHit =
|
||||
@@ -536,9 +539,14 @@ export function Wasm3DViewport({
|
||||
setGroundGrid,
|
||||
setSectionPlane,
|
||||
setHighlightLines,
|
||||
syncPointClouds,
|
||||
ready,
|
||||
failed,
|
||||
} = useWasm3dRenderer(canvasRef, true);
|
||||
// Punktwolken ([27]) aus dem UI-Store (nicht im Projekt). Die Lage folgt dem Standort-Bezug.
|
||||
const pointClouds = usePointClouds();
|
||||
const geoOrigin = projectGeoOrigin(project);
|
||||
const geoKey = geoOrigin ? `${geoOrigin.e},${geoOrigin.n},${project.geoAnchor?.height ?? ""}` : "";
|
||||
// Live-Schnitt: die aktive Ebene kommt jetzt aus `section3d` (App-State, an
|
||||
// eine Schnittlinie gebunden — `sectionPlaneFromLevel`) statt aus einem
|
||||
// lokalen Hardcode-Toggle. `null` = kein Schnitt.
|
||||
@@ -562,6 +570,15 @@ export function Wasm3DViewport({
|
||||
redrawRef.current();
|
||||
}, [ready, project, detail, updateModel]);
|
||||
|
||||
// Punktwolken abgleichen (neu/umgestellt/entfernt) und neu zeichnen, wenn sich etwas tat.
|
||||
useEffect(() => {
|
||||
if (!ready) return;
|
||||
const p = projectRef.current;
|
||||
if (syncPointClouds(pointCloudSyncItems(pointClouds, projectGeoOrigin(p), p.geoAnchor?.height))) {
|
||||
redrawRef.current();
|
||||
}
|
||||
}, [ready, pointClouds, geoKey, syncPointClouds]);
|
||||
|
||||
// truck-Extrusionen (s. toWalls3d.ts emitExtrudedSolids): die WASM-Extrusion
|
||||
// läuft asynchron und ist beim ersten `updateModel` oben typischerweise noch
|
||||
// nicht fertig — ohne diesen Re-Push bliebe sie trotz erfolgreichen Ladens
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { PointCloudData } from "../io/pointCloud";
|
||||
import { planPointCloudSync } from "./pointCloudSync";
|
||||
import type { PointCloudSyncItem, UploadedPointCloud } from "./pointCloudSync";
|
||||
|
||||
const data = (): PointCloudData => ({
|
||||
origin: [0, 0, 0],
|
||||
xyz: new Float32Array(3),
|
||||
rgb: null,
|
||||
intensity: null,
|
||||
classification: null,
|
||||
report: {} as PointCloudData["report"],
|
||||
});
|
||||
|
||||
function item(id: number, d: PointCloudData, p: Partial<PointCloudSyncItem> = {}): PointCloudSyncItem {
|
||||
return { id, data: d, offset: [0, 0, 0], colorMode: "rgb", pointSize: 2, visible: true, ...p };
|
||||
}
|
||||
|
||||
const asUploaded = (i: PointCloudSyncItem): UploadedPointCloud => ({
|
||||
data: i.data,
|
||||
offset: [...i.offset],
|
||||
colorMode: i.colorMode,
|
||||
pointSize: i.pointSize,
|
||||
visible: i.visible,
|
||||
});
|
||||
|
||||
describe("planPointCloudSync", () => {
|
||||
it("lädt neue Wolken hoch und entfernt verschwundene", () => {
|
||||
const d1 = data();
|
||||
const prev = new Map([[9, asUploaded(item(9, data()))]]);
|
||||
expect(planPointCloudSync(prev, [item(1, d1)])).toEqual([
|
||||
{ kind: "remove", id: 9 },
|
||||
{ kind: "set", item: item(1, d1) },
|
||||
]);
|
||||
});
|
||||
|
||||
it("nur Darstellung geändert → style, unverändert → nichts", () => {
|
||||
const d = data();
|
||||
const prev = new Map([[1, asUploaded(item(1, d))]]);
|
||||
expect(planPointCloudSync(prev, [item(1, d)])).toEqual([]);
|
||||
const ops = planPointCloudSync(prev, [item(1, d, { colorMode: "height", visible: false })]);
|
||||
expect(ops.map((o) => o.kind)).toEqual(["style"]);
|
||||
});
|
||||
|
||||
it("neue Daten oder neue Lage → neu hochladen", () => {
|
||||
const d = data();
|
||||
const prev = new Map([[1, asUploaded(item(1, d))]]);
|
||||
expect(planPointCloudSync(prev, [item(1, data())]).map((o) => o.kind)).toEqual(["set"]);
|
||||
expect(planPointCloudSync(prev, [item(1, d, { offset: [0, 0, 1] })]).map((o) => o.kind)).toEqual(["set"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
// Abgleich Punktwolken-Store → render3d ([27]): welche Wolken neu hochgeladen, nur umgestellt
|
||||
// (Farbmodus/Grösse/Sichtbarkeit) oder entfernt werden müssen. Rein rechnend (testbar); der Hook
|
||||
// `useWasm3dRenderer.syncPointClouds` führt die Schritte aus.
|
||||
//
|
||||
// Neu hochladen (teuer: Millionen Punkte über die WASM-Grenze) nur, wenn sich die DATEN (Objekt-
|
||||
// identität) oder die LAGE (Versatz, z. B. neuer Standort-Bezug) geändert haben — Darstellungs-
|
||||
// änderungen gehen über den kleinen `set_point_cloud_style`-Weg.
|
||||
|
||||
import type { PointCloudData } from "../io/pointCloud";
|
||||
import type { PointCloudEntry, PointColorMode } from "../state/pointCloudStore";
|
||||
import { placePointCloud } from "../state/pointCloudPlacement";
|
||||
|
||||
export interface PointCloudSyncItem {
|
||||
id: number;
|
||||
data: PointCloudData;
|
||||
/** Modell-Meter des Wolken-Ursprungs (s. `placePointCloud`). */
|
||||
offset: [number, number, number];
|
||||
colorMode: PointColorMode;
|
||||
pointSize: number;
|
||||
visible: boolean;
|
||||
}
|
||||
|
||||
/** Was im Renderer liegt (je id). */
|
||||
export interface UploadedPointCloud {
|
||||
data: PointCloudData;
|
||||
offset: [number, number, number];
|
||||
colorMode: PointColorMode;
|
||||
pointSize: number;
|
||||
visible: boolean;
|
||||
}
|
||||
|
||||
export type PointCloudSyncOp =
|
||||
| { kind: "set"; item: PointCloudSyncItem }
|
||||
| { kind: "style"; item: PointCloudSyncItem }
|
||||
| { kind: "remove"; id: number };
|
||||
|
||||
export function planPointCloudSync(
|
||||
uploaded: ReadonlyMap<number, UploadedPointCloud>,
|
||||
items: readonly PointCloudSyncItem[],
|
||||
): PointCloudSyncOp[] {
|
||||
const ops: PointCloudSyncOp[] = [];
|
||||
const ids = new Set(items.map((i) => i.id));
|
||||
for (const id of uploaded.keys()) if (!ids.has(id)) ops.push({ kind: "remove", id });
|
||||
for (const item of items) {
|
||||
const prev = uploaded.get(item.id);
|
||||
const sameData =
|
||||
prev !== undefined &&
|
||||
prev.data === item.data &&
|
||||
prev.offset[0] === item.offset[0] &&
|
||||
prev.offset[1] === item.offset[1] &&
|
||||
prev.offset[2] === item.offset[2];
|
||||
if (!sameData) {
|
||||
ops.push({ kind: "set", item });
|
||||
} else if (
|
||||
prev.colorMode !== item.colorMode ||
|
||||
prev.pointSize !== item.pointSize ||
|
||||
prev.visible !== item.visible
|
||||
) {
|
||||
ops.push({ kind: "style", item });
|
||||
}
|
||||
}
|
||||
return ops;
|
||||
}
|
||||
|
||||
/** Store-Einträge → Abgleich-Einträge, Lage aus dem aktuellen Standort-Bezug (nur gelesen). */
|
||||
export function pointCloudSyncItems(
|
||||
clouds: readonly PointCloudEntry[],
|
||||
geoOrigin: { e: number; n: number } | null,
|
||||
geoHeight: number | undefined,
|
||||
): PointCloudSyncItem[] {
|
||||
return clouds.map((c) => {
|
||||
const r = c.data.report;
|
||||
const placement = placePointCloud(
|
||||
{ origin: c.data.origin, bboxMin: r.bboxMin, bboxMax: r.bboxMax, epsg: r.epsg },
|
||||
geoOrigin,
|
||||
geoHeight,
|
||||
);
|
||||
return {
|
||||
id: c.id,
|
||||
data: c.data,
|
||||
offset: placement.offset,
|
||||
colorMode: c.colorMode,
|
||||
pointSize: c.pointSize,
|
||||
visible: c.visible,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import type { DetailLevel } from "../model/viewTypes";
|
||||
import { loadEngine3d } from "../engine/engine3d";
|
||||
import { decodeMaterialTextures } from "./materialTextures";
|
||||
import { decodeImageToRgba } from "../io/swissImage";
|
||||
import { planPointCloudSync } from "./pointCloudSync";
|
||||
import type { PointCloudSyncItem, UploadedPointCloud } from "./pointCloudSync";
|
||||
|
||||
/** Fertige Kamera für einen Frame (world-Meter, Y-up — wie render3d::types::Camera). */
|
||||
export interface Camera3d {
|
||||
@@ -108,6 +110,25 @@ interface WebModelRendererLike {
|
||||
): void;
|
||||
/** Drapiertes Luftbild löschen (Gelände wieder einfarbig/shaded). Optional. */
|
||||
clear_aerial?(): void;
|
||||
/** Punktwolke setzen ([27], `web::set_point_cloud`): `xyz` relativ zum Ursprung, `ox/oy/oz` =
|
||||
* Modell-Meter des Ursprungs (f64, Rust addiert in f64). Leere Attribut-Arrays = fehlt.
|
||||
* Liefert die gezeichnete Punktzahl (0 = verworfen). Optional — ältere WASM-Builds. */
|
||||
set_point_cloud?(
|
||||
id: number,
|
||||
xyz: Float32Array,
|
||||
rgb: Uint8Array,
|
||||
intensity: Uint16Array,
|
||||
classification: Uint8Array,
|
||||
ox: number,
|
||||
oy: number,
|
||||
oz: number,
|
||||
colorMode: string,
|
||||
pointSize: number,
|
||||
visible: boolean,
|
||||
): number;
|
||||
/** Nur Darstellung ändern; `false` = Wolke unbekannt. */
|
||||
set_point_cloud_style?(id: number, colorMode: string, pointSize: number, visible: boolean): boolean;
|
||||
remove_point_cloud?(id: number): void;
|
||||
set_camera(
|
||||
eyeX: number,
|
||||
eyeY: number,
|
||||
@@ -157,6 +178,8 @@ export function useWasm3dRenderer(
|
||||
enabled: boolean,
|
||||
) {
|
||||
const rendererRef = useRef<WebModelRendererLike | null>(null);
|
||||
// Was an Punktwolken im Renderer liegt ([27], s. pointCloudSync.ts).
|
||||
const pointCloudsRef = useRef<Map<number, UploadedPointCloud>>(new Map());
|
||||
const [ready, setReady] = useState(false);
|
||||
const [failed, setFailed] = useState(false);
|
||||
|
||||
@@ -173,6 +196,8 @@ export function useWasm3dRenderer(
|
||||
const renderer = await getRenderer(canvas);
|
||||
if (disposed) return;
|
||||
rendererRef.current = renderer;
|
||||
// Neuer (oder wiederverwendeter) Renderer: Punktwolken neu abgleichen.
|
||||
pointCloudsRef.current = new Map();
|
||||
setReady(true);
|
||||
setFailed(false);
|
||||
} catch (e) {
|
||||
@@ -281,6 +306,60 @@ export function useWasm3dRenderer(
|
||||
})();
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Punktwolken abgleichen ([27]): neue/geänderte Daten hochladen, Darstellung umstellen,
|
||||
* entfernte löschen. Gibt `true` zurück, wenn sich etwas geändert hat (→ neu zeichnen).
|
||||
*/
|
||||
const syncPointClouds = useCallback((items: readonly PointCloudSyncItem[]): boolean => {
|
||||
const r = rendererRef.current;
|
||||
if (!r || typeof r.set_point_cloud !== "function") return false;
|
||||
const uploaded = pointCloudsRef.current;
|
||||
const ops = planPointCloudSync(uploaded, items);
|
||||
const empty8 = new Uint8Array(0);
|
||||
const upload = (it: PointCloudSyncItem) => {
|
||||
const d = it.data;
|
||||
r.set_point_cloud!(
|
||||
it.id,
|
||||
d.xyz,
|
||||
d.rgb ?? empty8,
|
||||
d.intensity ?? new Uint16Array(0),
|
||||
d.classification ?? empty8,
|
||||
it.offset[0],
|
||||
it.offset[1],
|
||||
it.offset[2],
|
||||
it.colorMode,
|
||||
it.pointSize,
|
||||
it.visible,
|
||||
);
|
||||
};
|
||||
for (const op of ops) {
|
||||
try {
|
||||
if (op.kind === "remove") {
|
||||
r.remove_point_cloud?.(op.id);
|
||||
uploaded.delete(op.id);
|
||||
continue;
|
||||
}
|
||||
const it = op.item;
|
||||
if (op.kind === "style") {
|
||||
const ok = r.set_point_cloud_style?.(it.id, it.colorMode, it.pointSize, it.visible) === true;
|
||||
if (!ok) upload(it);
|
||||
} else {
|
||||
upload(it);
|
||||
}
|
||||
uploaded.set(it.id, {
|
||||
data: it.data,
|
||||
offset: [...it.offset],
|
||||
colorMode: it.colorMode,
|
||||
pointSize: it.pointSize,
|
||||
visible: it.visible,
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn("render3d Punktwolke fehlgeschlagen:", e);
|
||||
}
|
||||
}
|
||||
return ops.length > 0;
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Darstellungsart umschalten — reicht die volle `RenderMode`-Union der
|
||||
* Oberleiste ("shaded"/"white"/"textured"/"wireframe"/"hidden") an Rust
|
||||
@@ -438,6 +517,7 @@ export function useWasm3dRenderer(
|
||||
setGroundGrid,
|
||||
setSectionPlane,
|
||||
setHighlightLines,
|
||||
syncPointClouds,
|
||||
ready,
|
||||
failed,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user