From dac670c3613c8a2515c965aa0de326214806b1c3 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 15:50:56 +0000 Subject: [PATCH] =?UTF-8?q?[BCF][27]=20Kamera-Br=C3=BCcke=20f=C3=BCr=20den?= =?UTF-8?q?=203D-Viewport:=20Viewpoints=20setzen/aufnehmen,=20Schnappschus?= =?UTF-8?q?s,=20Einpassen=20mit=20Punktwolken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit viewport/cameraBridge.ts (getCamera/setCamera/captureSnapshot/setSection/fitView in Modell-Koordinaten, Achsabbildung gegen projectToModel3d belegt), panels/bcfView.ts (BCF-Weltkoordinaten = Modell + LV95-Versatz wie der IFC-Export). BCF-Panel: Klick auf Thema/Viewpoint stellt Kamera (perspektivisch, orthogonal) und senkrechte Schnittebene ein; Thema aus Auswahl, Ansicht aufnehmen und Kommentar legen Viewpoints mit Kamera + Schnappschuss an. Erste sichtbare Punktwolke passt die Kamera ein. Nicht geprüft: Schnappschuss mit echtem Bild (leerer WebGPU-Frame im Container), nativer macOS-Pfad. TODO.md [BCF]/[27] nachgeführt. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67 --- TODO.md | 30 +++- scripts/probe-bcf-camera.mjs | 128 +++++++++++++ src/i18n/de.ts | 15 ++ src/i18n/en.ts | 15 ++ src/panels/BcfPanel.tsx | 116 ++++++++++-- src/panels/bcfView.test.ts | 157 ++++++++++++++++ src/panels/bcfView.ts | 106 +++++++++++ src/styles.css | 33 ++++ src/viewport/Wasm3DViewport.tsx | 180 ++++++++++++------- src/viewport/cameraBridge.test.ts | 221 +++++++++++++++++++++++ src/viewport/cameraBridge.ts | 287 ++++++++++++++++++++++++++++++ src/viewport/useWasm3dRenderer.ts | 74 ++++++++ 12 files changed, 1272 insertions(+), 90 deletions(-) create mode 100644 scripts/probe-bcf-camera.mjs create mode 100644 src/panels/bcfView.test.ts create mode 100644 src/panels/bcfView.ts create mode 100644 src/viewport/cameraBridge.test.ts create mode 100644 src/viewport/cameraBridge.ts diff --git a/TODO.md b/TODO.md index 35801ed8..bec9258f 100644 --- a/TODO.md +++ b/TODO.md @@ -328,10 +328,12 @@ Format · [90] Versionsvergleich · [91] Assistent · [92] Speckle. 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. + - **Einpassen (28.10.):** `set_view_preset` und der Orbit-Seed (`view_fit`) beziehen sichtbare Punktwolken in + die Bounding-Box ein (`math::merge_bounds`/`fit_target_dist`, Rust-Test); die erste sichtbare Wolke passt + die Kamera automatisch ein. Nicht im Browser mit Bild geprüft (leerer WebGPU-Frame im Container). - 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 + (JS-Store + Rust-CPU-Kopie für Farbwechsel + GPU); 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] @@ -517,10 +519,26 @@ Ganzes nicht WASM-tauglich (rayon, tempfile, SystemTime) — nur einzelne Module alle 71 buildingSMART-Beispieldateien (Test Cases v2.1/v3.0, lokal; CC BY-ND, deshalb nicht im Repo, Test `buildingsmart_beispiele` über `BCF_TESTCASES`), vitest Fassade und GlobalId-Zuordnung gegen den IFC-Export des Demo-Hauses. Nicht geprüft: Austausch mit echter Solibri/BIMcollab-Software, Tauri-App. - Offen: Kamera des Viewpoints setzen und für neue Themen aus dem 3D-Viewport lesen (`Wasm3DViewport` hält - die Orbit-Kamera intern, ohne Setter/Getter; Achsen Z-oben wie IFC, Viewport vermutlich Y-oben); - Snapshot aus dem Viewport; `extensions.xml` (3.0), Farbgruppen/Linien, BimSnippet, Dokument-Referenzen - und verwandte Themen gehen beim Speichern verloren; Panel in den Standard-Dock aufnehmen. · M + **Kamera (28.10.):** `viewport/cameraBridge.ts` (`getCamera`/`setCamera({animate})`/`captureSnapshot`/`setSection`/ + `fitView`; der Viewport meldet sich an, ohne Viewport null/false) in MODELL-Koordinaten (z oben); Achsen + Modell (x, y, Höhe) → world (x, Höhe, y) (Tausch, belegt gegen `projectToModel3d`; Gelände/Punktwolken + negieren y, s. [27]). `panels/bcfView.ts`: BCF-Weltkoordinaten = Modell + LV95-Versatz `projectGeoOrigin` + (genau wie `exportIfcSpf`/`projectToWorldCoords`, Höhe unverändert). Klick auf Thema/Viewpoint-Vorschau + setzt Kamera (perspektivisch + orthogonal, Fahrt 350 ms) und eine senkrechte Schnittebene (live, + Knopf zum Aufheben), Auswahl wie zuvor; „Thema aus Auswahl", „Ansicht aufnehmen" und Kommentar + (Häkchen „Aktuelle 3D-Ansicht anhängen") legen einen Viewpoint mit Kamera + PNG-Schnappschuss an. + Annahmen: FieldOfView vertikal, ViewToWorldScale = sichtbare Breite, ClippingPlane.Direction zeigt auf + die weggeschnittene Seite (wie `set_section_plane`). render3d additiv: `camera_state`, `view_fit` + (`math::fit_target_dist`/`merge_bounds`). Geprüft: vitest Achsabbildung + Rundreisen (inkl. echter + .bcfzip 2.1/3.0), Chromium-Build (`scripts/probe-bcf-camera.mjs`): Kamera setzen/lesen/aufnehmen + per Debug-Handle `window.__dossierCamera`. NICHT geprüft: Schnappschuss mit echtem Bild (im Container + ist der WebGPU-Frame leer → `captureSnapshot` liefert null, Viewpoint trägt dann nur die Kamera), + nativer macOS-Pfad (Metal-Fenster `native.rs` hat eigene Orbit-Kamera, NICHT angebunden: dort nur Anzeige + und Auswahl), Austausch mit echter Solibri/BIMcollab-Software (Achsen-/FOV-Annahmen oben). + Offen: Kamera im nativen Metal-Fenster; Schnittebene beim Anlegen eines Themas aus dem Live-Schnitt + übernehmen; Roll der Kamera (Orbit kennt keinen); schräge Schnittebenen nur angezeigt; + `extensions.xml` (3.0), Farbgruppen/Linien, BimSnippet, Dokument-Referenzen und verwandte Themen gehen + beim Speichern verloren; Panel in den Standard-Dock aufnehmen. · M - ○ **[B6] Wand unter Dach als Prismen zwischen Ebenen** (für [G2]). `walls.rs:413–472, 592–654`. · M - ○ **[B7] Dach-Verschneidung und Gauben in 2.5D** (für [G5]). · M · nach [B2]/[B6]. - ○ **[B8] Bogenwände, schneller Weg** (für [T2]). · S/M–L diff --git a/scripts/probe-bcf-camera.mjs b/scripts/probe-bcf-camera.mjs new file mode 100644 index 00000000..377fe4ba --- /dev/null +++ b/scripts/probe-bcf-camera.mjs @@ -0,0 +1,128 @@ +// Browser-Prüfung der BCF-Kamera ([BCF]): Panel öffnen, .bcfzip laden, Themen anklicken und den +// Kamerazustand über das Debug-Handle `window.__dossierCamera` (s. `viewport/cameraBridge.ts`) +// lesen. WebGPU-Frames sind im Container oft leer — deshalb zählt der Kamerazustand, nicht das Bild. +// +// Aufruf: PROBE_URL=http://localhost:5191/ BCF_FILE=pfad/test.bcfzip [PROJECT_FILE=pfad/demo.obp] node scripts/probe-bcf-camera.mjs +// Die Datei hat zwei Themen: "Perspektive" (Position 12/10/8, Blick -12/-10/-7, Z oben, Schnittebene +// y=2) und "Ortho Grundriss" (Position 2.5/2/30, Blick -Z, ViewToWorldScale 16). +import { chromium } from "playwright"; + +const URL = process.env.PROBE_URL || "http://localhost:5191/"; +const FILE = process.env.BCF_FILE; +if (!FILE) throw new Error("BCF_FILE fehlt"); +const OUT = process.env.PROBE_OUT || "."; + +const browser = await chromium.launch({ + headless: true, + executablePath: process.env.CHROMIUM_BIN || undefined, + args: ["--no-sandbox", "--enable-unsafe-webgpu", "--enable-features=Vulkan", "--use-angle=swiftshader"], +}); +const page = await browser.newPage({ viewport: { width: 1500, height: 900 } }); +const errors = []; +page.on("pageerror", (e) => errors.push(e.message)); +page.on("console", (m) => { + if (m.type() === "error") errors.push(m.text()); +}); +await page.goto(URL, { waitUntil: "load" }); +// Startbildschirm: neues Projekt, danach (falls angegeben) das Demo-Projekt über das versteckte +// .obp-Input der App laden (der Dateidialog des Startbildschirms ist nur in der Tauri-App aktiv). +await page.getByText("Neues Projekt", { exact: true }).first().click(); +if (process.env.PROJECT_FILE) { + await page.setInputFiles('input[accept="application/json,.json,.obp"]', process.env.PROJECT_FILE); + await page.waitForTimeout(800); +} +await page.waitForSelector("canvas", { timeout: 30000 }); +await page.waitForTimeout(2500); + +// 3D-Ansicht (Isometrie-Preset) einschalten; der Viewport meldet sich erst bei bereitem Renderer an. +await page.locator('button[title^="Isometrie —"]').first().click().catch(() => {}); +await page.waitForFunction(() => window.__dossierCamera?.viewportAvailable() === true, null, { timeout: 15000 }).catch(() => {}); +console.log("INFO WebGPU im Browser:", await page.evaluate(async () => (navigator.gpu ? !!(await navigator.gpu.requestAdapter()) : false))); + +const results = []; +const check = (name, ok, detail = "") => { + results.push({ name, ok }); + console.log(`${ok ? "OK " : "FAIL"} ${name}${detail ? " — " + detail : ""}`); +}; +const cam = () => page.evaluate(() => window.__dossierCamera?.getCamera() ?? null); +const near = (a, b, tol = 1e-3) => a.every((v, i) => Math.abs(v - b[i]) <= tol); +const norm = (v) => { + const l = Math.hypot(...v); + return v.map((x) => x / l); +}; + +check("Viewport meldet sich an", await page.evaluate(() => window.__dossierCamera?.viewportAvailable() === true)); + +// Panel öffnen: Menü Fenster > BCF-Themen +await page.getByText("Fenster", { exact: true }).first().click(); +await page.getByText("BCF-Themen", { exact: true }).first().click(); +await page.waitForSelector(".bcf-panel", { timeout: 5000 }); +await page.setInputFiles(".bcf-panel input[type=file]", FILE); +await page.waitForSelector(".bcf-topic", { timeout: 10000 }); +check("Datei geladen, 3 Themen", (await page.locator(".bcf-topic").count()) === 3); + +// Perspektivisches Thema +await page.locator(".bcf-topic", { hasText: "Perspektive" }).click(); +await page.waitForTimeout(900); // Kamerafahrt 350 ms +let c = await cam(); +check("Perspektive: Kamera gesetzt", !!c && c.kind === "perspective", JSON.stringify(c && { p: c.position, d: c.direction, fov: c.fovDeg })); +if (c) { + check("Perspektive: Position 12/10/8", near(c.position, [12, 10, 8], 0.01), c.position.map((x) => x.toFixed(3)).join("/")); + check("Perspektive: Blickrichtung", near(c.direction, norm([-12, -10, -7]), 1e-4)); + check("Perspektive: Sichtfeld 60°", Math.abs(c.fovDeg - 60) < 1e-6); + check("Perspektive: Up zeigt nach oben (z)", c.up[2] > 0.5); +} +check("Schnittebene aus dem Viewpoint: Schnitt-Knopf sichtbar", (await page.locator('button[aria-label][title*="BCF"]').count()) >= 1); +await page.screenshot({ path: `${OUT}/bcf-camera-perspective.png` }); + +// Orthogonales Thema +await page.locator(".bcf-topic", { hasText: "Ortho" }).click(); +await page.waitForTimeout(900); +c = await cam(); +check("Ortho: Kamera gesetzt", !!c && c.kind === "orthogonal", JSON.stringify(c && { p: c.position, d: c.direction, h: c.orthoHeight, a: c.aspect })); +if (c) { + check("Ortho: Position 2.5/2/30", near(c.position, [2.5, 2, 30], 0.01), c.position.map((x) => x.toFixed(4)).join("/")); + check("Ortho: Blick nach unten", near(c.direction, [0, 0, -1], 1e-3)); + check("Ortho: Breite 16 m", Math.abs(c.orthoHeight * c.aspect - 16) < 0.01, `Höhe ${c.orthoHeight.toFixed(3)} · Aspekt ${c.aspect.toFixed(3)}`); +} +check("Ortho: Schnitt wieder aufgehoben", (await page.locator('button[aria-label][title*="BCF"]').count()) === 0); + +// Rundreise: Kamera lesen → setzen → lesen +const before = await cam(); +await page.evaluate((v) => window.__dossierCamera.setCamera(v, { animate: false }), before); +await page.waitForTimeout(200); +const after = await cam(); +check("getCamera → setCamera → getCamera unverändert", !!before && !!after && near(before.position, after.position, 1e-4) && near(before.direction, after.direction, 1e-4) && Math.abs(before.orthoHeight - after.orthoHeight) < 1e-4); + +// Ansicht aufnehmen: aktuelle Kamera (+ Schnappschuss) als weiterer Viewpoint des Themas. (Die Auswahl +// "Thema aus Auswahl" nutzt denselben Aufnahmeweg; hier ohne Auswahl, weil das Demo-Projekt im +// Browser-Lauf keine passenden GlobalIds liefert.) +await page.locator(".bcf-topic", { hasText: "Perspektive" }).click(); +await page.waitForTimeout(900); +await page.locator('button[title^="Axonometrie"]').first().click().catch(() => {}); +await page.waitForTimeout(600); +const atCapture = await cam(); +await page.getByRole("button", { name: "Ansicht aufnehmen" }).click(); +await page.waitForTimeout(1200); +check("Ansicht aufnehmen: zweiter Viewpoint", (await page.locator(".bcf-vp").count()) === 2); +const snaps = await page.locator(".bcf-vp img.bcf-snapshot").count(); +console.log(`INFO Schnappschuss im Viewpoint: ${snaps > 0 ? "ja" : "nein (Container: WebGPU-Frame leer, Kamera trotzdem gespeichert)"}`); +// Zurück auf den ersten Viewpoint, dann auf den neuen: die aufgenommene Kamera kommt wieder. +await page.locator(".bcf-vp").nth(0).click(); +await page.waitForTimeout(900); +const first = await cam(); +check("Viewpoint 1 stellt die Perspektive wieder her", !!first && near(first.position, [12, 10, 8], 0.01)); +await page.locator(".bcf-vp").nth(1).click(); +await page.waitForTimeout(900); +const restored = await cam(); +check("Viewpoint 2 stellt die aufgenommene Kamera wieder her", !!atCapture && !!restored && near(atCapture.position, restored.position, 0.01) && near(atCapture.direction, restored.direction, 1e-3) && atCapture.kind === restored.kind, restored ? restored.position.map((x) => x.toFixed(2)).join("/") : ""); +// Kommentar mit angehängter Ansicht (Häkchen ist voreingestellt) +await page.locator(".bcf-input").fill("Prüfen bitte"); +await page.getByRole("button", { name: "Kommentieren" }).click(); +await page.waitForTimeout(1200); +check("Kommentar mit Ansicht: dritter Viewpoint", (await page.locator(".bcf-vp").count()) === 3); +await page.screenshot({ path: `${OUT}/bcf-camera-topic.png` }); + +console.log("Konsolenfehler:", errors.length ? errors.slice(0, 5) : "keine"); +await browser.close(); +process.exit(results.every((r) => r.ok) ? 0 : 1); diff --git a/src/i18n/de.ts b/src/i18n/de.ts index a20512b1..7e3856ca 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -2138,6 +2138,7 @@ export const de = { "viewport3d.section.show": "Schnittebene ein", "viewport3d.section.hide": "Schnittebene aus", "viewport3d.section.bound": "3D-Schnitt aufheben (an Schnittlinie gebunden)", + "viewport3d.section.bcf": "3D-Schnitt aufheben (aus BCF-Viewpoint)", "viewport3d.grip.vertex": "Wandende ziehen", "viewport3d.grip.height": "Höhe ziehen", "viewport3d.grip.move": "Verschieben", @@ -2326,6 +2327,20 @@ export const de = { "bcf.openFailed": "BCF-Datei nicht lesbar: {error}", "bcf.saved": "BCF gespeichert.", "bcf.saveFailed": "BCF nicht gespeichert: {error}", + "bcf.viewpoints": "Ansichten", + "bcf.viewpoint.go": "Ansicht {n} im 3D einstellen", + "bcf.viewpoint.snapshot": "Ansicht {n}", + "bcf.noViewport": "Keine 3D-Ansicht geöffnet: die Kamera des Viewpoints wurde nicht gesetzt.", + "bcf.cameraSet": "Kamera aus dem Viewpoint gesetzt.", + "bcf.cameraFailed": "Die Kamera des Viewpoints ist unbrauchbar und wurde nicht gesetzt.", + "bcf.sectionSet": "Schnittebene aus dem Viewpoint im 3D gesetzt.", + "bcf.sectionTilted": "Der Viewpoint enthält eine schräge Schnittebene: sie wird nur angezeigt, der 3D-Schnitt kann nur senkrechte Ebenen.", + "bcf.clipping": "Schnittebenen", + "bcf.clipping.item": "bei {x} / {y} / {z} m, Richtung {dx} / {dy} / {dz}", + "bcf.attachView": "Aktuelle 3D-Ansicht anhängen", + "bcf.addViewpoint": "Ansicht aufnehmen", + "bcf.addViewpoint.hint": "Hängt die aktuelle 3D-Kamera mit Bild und der Auswahl als Viewpoint an das Thema.", + "bcf.noSnapshot": "Kein Bild aufgenommen (3D-Bild nicht lesbar); die Kamera ist trotzdem gespeichert.", } as const; export type TranslationKey = keyof typeof de; diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 87044db4..43dba2b6 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -2125,6 +2125,7 @@ export const en: Record = { "viewport3d.section.show": "Section plane on", "viewport3d.section.hide": "Section plane off", "viewport3d.section.bound": "Clear 3D section (bound to section line)", + "viewport3d.section.bcf": "Clear 3D section (from BCF viewpoint)", "viewport3d.grip.vertex": "Drag wall endpoint", "viewport3d.grip.edge": "Drag edge", "viewport3d.grip.height": "Drag height", @@ -2312,4 +2313,18 @@ export const en: Record = { "bcf.openFailed": "BCF file not readable: {error}", "bcf.saved": "BCF saved.", "bcf.saveFailed": "BCF not saved: {error}", + "bcf.viewpoints": "Views", + "bcf.viewpoint.go": "Go to view {n} in 3D", + "bcf.viewpoint.snapshot": "View {n}", + "bcf.noViewport": "No 3D view open: the viewpoint camera was not applied.", + "bcf.cameraSet": "Camera set from the viewpoint.", + "bcf.cameraFailed": "The viewpoint camera is unusable and was not applied.", + "bcf.sectionSet": "Section plane from the viewpoint set in 3D.", + "bcf.sectionTilted": "The viewpoint contains an inclined section plane: it is only listed, the 3D section supports vertical planes only.", + "bcf.clipping": "Section planes", + "bcf.clipping.item": "at {x} / {y} / {z} m, direction {dx} / {dy} / {dz}", + "bcf.attachView": "Attach current 3D view", + "bcf.addViewpoint": "Capture view", + "bcf.addViewpoint.hint": "Attaches the current 3D camera with image and selection to the topic as a viewpoint.", + "bcf.noSnapshot": "No image captured (3D image not readable); the camera is saved anyway.", }; diff --git a/src/panels/BcfPanel.tsx b/src/panels/BcfPanel.tsx index 3140818f..4e9b9f7e 100644 --- a/src/panels/BcfPanel.tsx +++ b/src/panels/BcfPanel.tsx @@ -4,9 +4,11 @@ // IFC-GlobalId, dieselbe Ableitung wie im IFC-Export: `io/bcfMatch.ts`). Kommentar hinzufügen, // Status ändern, neues Thema aus der Auswahl, als .bcfzip speichern. // -// Die Themen gehören nicht zum Projekt (eigene Datei, `bcfSession.ts`). Die Kamera eines Viewpoints -// wird angezeigt, aber noch nicht gesetzt: `Wasm3DViewport` hält seine Orbit-Kamera intern und bietet -// keine Setz-Funktion (s. TODO.md [BCF]). +// Die Themen gehören nicht zum Projekt (eigene Datei, `bcfSession.ts`). Kamera und Schnittebene +// eines Viewpoints setzt die Kamera-Brücke des 3D-Viewports (`viewport/cameraBridge.ts`, Umrechnung +// samt LV95-Versatz in `bcfView.ts`); neue Themen und Kommentare nehmen die aktuelle Kamera plus +// Schnappschuss als Viewpoint auf. Ohne offenen WASM-3D-Viewport (kein 3D, nativer macOS-Pfad) +// bleibt es bei Anzeige und Auswahl. // // Bezeichner englisch, UI-Text deutsch/englisch über t(). @@ -21,13 +23,13 @@ import { addTopic, emptyBcf, newTopic, - newViewpoint, parseBcf, setTopicStatus, writeBcf, type BcfCamera, type BcfFile, type BcfTopic, + type BcfViewpoint, type BcfVersion, } from "../io/bcf"; import { @@ -39,6 +41,9 @@ import { type BcfSelection, } from "../io/bcfMatch"; import { fileioLoaded, loadFileio } from "../engine/fileioWasm"; +import { projectGeoOrigin } from "../core"; +import { captureSnapshot, getCamera, setCamera, setSection, viewportAvailable } from "../viewport/cameraBridge"; +import { firstViewpointWithCamera, sectionFromBcfClipping, viewCameraFromBcf, viewpointForTopic } from "./bcfView"; import { setBcfSession, useBcfSession } from "./bcfSession"; const AUTHOR_KEY = "dossier.bcf.author"; @@ -109,6 +114,7 @@ export function BcfPanel() { const inputRef = useRef(null); const authorRef = useRef(null); const commentRef = useRef(null); + const attachRef = useRef(null); const { file, selectedGuid } = session; const topic = file?.topics.find((x) => x.guid === selectedGuid) ?? null; @@ -125,9 +131,29 @@ export function BcfPanel() { } }; - const selectTopic = (tp: BcfTopic) => { - setBcfSession({ selectedGuid: tp.guid }); - const guids = [...new Set(tp.viewpoints.flatMap(viewpointGuids))]; + /** Kamera, Schnittebene und Bauteile eines Viewpoints im Modell zeigen. */ + const showViewpoint = (vp: BcfViewpoint | null, topicGuids: string[]) => { + const origin = projectGeoOrigin(host.project); + if (vp?.camera || (vp && vp.clippingPlanes.length > 0)) { + if (!viewportAvailable()) { + notify(t("bcf.noViewport"), "warning"); + } else { + if (vp.camera) { + const vc = viewCameraFromBcf(vp.camera, origin, getCamera()?.aspect ?? 1); + if (vc && setCamera(vc, { animate: true })) notify(t("bcf.cameraSet"), "info"); + else notify(t("bcf.cameraFailed"), "warning"); + } + // Schnitt: die erste senkrechte Ebene wird live gesetzt; ohne Ebenen fällt ein früherer Schnitt weg. + const planes = vp.clippingPlanes; + const live = planes.map((c) => sectionFromBcfClipping(c, origin)).find((x) => x !== null) ?? null; + setSection(live); + if (live) notify(t("bcf.sectionSet"), "info"); + else if (planes.length > 0) notify(t("bcf.sectionTilted"), "warning"); + } + } else if (vp && viewportAvailable()) { + setSection(null); + } + const guids = vp ? viewpointGuids(vp) : topicGuids; if (guids.length === 0) return; // GlobalIds brauchen das Format-Modul (Rust-Hash); nach dem Öffnen ist es geladen. void loadFileio().then(() => { @@ -138,6 +164,26 @@ export function BcfPanel() { }); }; + const selectTopic = (tp: BcfTopic) => { + setBcfSession({ selectedGuid: tp.guid }); + // Kamera/Schnitt vom ersten Viewpoint mit Kamera, sonst vom ersten überhaupt; die Auswahl + // gilt dem ganzen Thema (alle Viewpoints). + const topicGuids = [...new Set(tp.viewpoints.flatMap(viewpointGuids))]; + const vp = firstViewpointWithCamera(tp) ?? tp.viewpoints[0] ?? null; + showViewpoint(vp, topicGuids); + }; + + /** Neuer Viewpoint aus Auswahl + aktueller Kamera + Schnappschuss. */ + const captureViewpoint = async (): Promise => { + await loadFileio(); + const sel = currentSelection(); + const guids = bcfSelectionSize(sel) > 0 ? selectionToGuids(host.project, sel) : []; + const camera = getCamera(); + const png = camera ? await captureSnapshot() : null; + if (camera && !png) notify(t("bcf.noSnapshot"), "info"); + return viewpointForTopic({ guid: uuid(), ifcGuids: guids, camera, snapshotPng: png, origin: projectGeoOrigin(host.project) }); + }; + const save = async () => { if (!file) return; try { @@ -158,24 +204,40 @@ export function BcfPanel() { notify(t("bcf.needSelection"), "warning"); return; } - await loadFileio(); - const guids = selectionToGuids(host.project, sel); + const vp = await captureViewpoint(); const topicGuid = uuid(); const tp = newTopic({ guid: topicGuid, title: t("bcf.defaultTitle"), author: author(), now: now(), - viewpoints: guids.length > 0 ? [newViewpoint(uuid(), guids)] : [], + viewpoints: vp.selection.length > 0 || vp.camera ? [vp] : [], }); const base = file ?? emptyBcf(host.project.id, host.project.name ?? ""); setBcfSession({ file: addTopic(base, tp), dirty: true, selectedGuid: topicGuid }); }; - const submitComment = () => { + /** Aktuelle 3D-Ansicht (Kamera + Bild + Auswahl) als weiteren Viewpoint ans gewählte Thema hängen. */ + const addViewpointToTopic = async () => { + if (!file || !topic) return; + if (!viewportAvailable()) { + notify(t("bcf.noViewport"), "warning"); + return; + } + const vp = await captureViewpoint(); + update({ ...file, topics: file.topics.map((x) => (x.guid === topic.guid ? { ...x, viewpoints: [...x.viewpoints, vp], modifiedDate: now(), modifiedAuthor: author() } : x)) }); + }; + + const submitComment = async () => { const el = commentRef.current; if (!file || !topic || !el || el.value.trim() === "") return; - update(addComment(file, topic.guid, { guid: uuid(), date: now(), author: author(), comment: el.value.trim(), viewpointGuid: "", modifiedDate: "", modifiedAuthor: "" })); + const text = el.value.trim(); + // Optional die aktuelle 3D-Ansicht als Viewpoint des Kommentars. + let vp: BcfViewpoint | null = null; + if (attachRef.current?.checked && viewportAvailable()) vp = await captureViewpoint(); + const withVp = vp && (vp.camera || vp.selection.length > 0) ? vp : null; + const next = addComment(file, topic.guid, { guid: uuid(), date: now(), author: author(), comment: text, viewpointGuid: withVp?.guid ?? "", modifiedDate: "", modifiedAuthor: "" }); + update(withVp ? { ...next, topics: next.topics.map((x) => (x.guid === topic.guid ? { ...x, viewpoints: [...x.viewpoints, withVp] } : x)) } : next); el.value = ""; }; @@ -184,7 +246,7 @@ export function BcfPanel() { update({ ...file, topics: file.topics.map((x) => (x.guid === topic.guid ? { ...x, title, modifiedDate: now(), modifiedAuthor: author() } : x)) }); }; - const snapshot = topic?.viewpoints.find((v) => v.snapshot)?.snapshot; + const clipping = topic?.viewpoints.flatMap((v) => v.clippingPlanes) ?? []; const camera = topic?.viewpoints.find((v) => v.camera)?.camera ?? null; const topicGuids = topic ? [...new Set(topic.viewpoints.flatMap(viewpointGuids))] : []; const project = host.project; @@ -250,8 +312,25 @@ export function BcfPanel() { {topic.labels.length > 0 &&
{t("bcf.labels")}{topic.labels.join(", ")}
} {topic.description &&
{topic.description}
} - {snapshot && } + {topic.viewpoints.length > 0 && ( + <> +
{t("bcf.viewpoints")}
+
+ {topic.viewpoints.map((vp, i) => ( + + ))} +
+ + )} {camera &&
{t("bcf.camera")}: {cameraText(camera)}
} + {clipping.length > 0 && ( +
+ {t("bcf.clipping")}:{" "} + {clipping.map((c) => t("bcf.clipping.item", { x: f1(c.location[0]), y: f1(c.location[1]), z: f1(c.location[2]), dx: f1(c.direction[0]), dy: f1(c.direction[1]), dz: f1(c.direction[2]) })).join("; ")} +
+ )}
{topicGuids.length > 0 ? t("bcf.components", { found: foundCount, total: topicGuids.length }) : t("bcf.components.none")}
{topicGuids.length > 0 && } @@ -264,7 +343,14 @@ export function BcfPanel() {
))}