diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl index 43851e4..f34e167 100644 --- a/.beads/issues.jsonl +++ b/.beads/issues.jsonl @@ -3,6 +3,8 @@ {"id":"ifcurl-p60","title":"Viewer: no element click-to-identify — can't get GlobalId or properties","description":"There is no way to click on a mesh in the viewer and see which IFC element it represents. Reviewers can see geometry but cannot reference specific elements — they can't discover a GlobalId to put in a selector URL, can't see the element name/type/Psets, and can't say 'this specific wall' in a BCF or Forgejo comment. This breaks the collaboration workflow at its foundation: every useful feedback comment needs to identify specific elements. Need: click or hover on a surface to highlight it and show a properties panel (name, type, GlobalId, key Psets). The GlobalId should be copyable into the selector field or URL. The ThatOpen components library provides the tools for this (OBC.IfcRelationsIndexer, element property queries).","status":"closed","priority":1,"issue_type":"feature","assignee":"Bruno Postle","owner":"bruno@postle.net","created_at":"2026-04-24T11:02:33Z","created_by":"Bruno Postle","updated_at":"2026-04-24T11:47:23Z","started_at":"2026-04-24T11:14:57Z","closed_at":"2026-04-24T11:47:23Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0} {"id":"ifcurl-4l7","title":"viewer.html: scale= URLs don't load in orthographic mode","description":"applyCameraParam() reads the camera= and fov= parameters from the URL and applies them, but never reads scale= or switches the camera to orthographic (parallel) projection. URLs like ?camera=...\u0026scale=50 will load in perspective mode instead of orthographic. The OBC OrthoPerspectiveCamera can switch modes, but the code path to set parallel projection and apply the scale value is missing from applyCameraParam.","status":"closed","priority":1,"issue_type":"bug","assignee":"Bruno Postle","owner":"bruno@postle.net","created_at":"2026-04-24T09:04:51Z","created_by":"Bruno Postle","updated_at":"2026-04-24T10:56:29Z","started_at":"2026-04-24T10:50:19Z","closed_at":"2026-04-24T10:56:29Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0} {"id":"ifcurl-362","title":"Add missing server-config files: gitconfig-ifcmerge and gitattributes","description":"forgejo/README.md documents deploying two files that don't exist in the repo: forgejo/server-config/gitconfig-ifcmerge and forgejo/server-config/gitattributes. Both are required for the ifcmerge git merge driver to work in bare Forgejo repos. The README even includes 'sudo cp forgejo/server-config/gitattributes /etc/gitattributes' and 'sudo git config --system include.path .../gitconfig-ifcmerge', but the files themselves are absent. Anyone following the deployment instructions will hit a 'file not found' error. Need to create both files with the content described in the README.","status":"closed","priority":1,"issue_type":"bug","assignee":"Bruno Postle","owner":"bruno@postle.net","created_at":"2026-04-24T09:04:31Z","created_by":"Bruno Postle","updated_at":"2026-04-24T10:51:47Z","started_at":"2026-04-24T10:50:15Z","closed_at":"2026-04-24T10:51:47Z","close_reason":"Files already exist: forgejo/server-config/gitconfig-ifcmerge and gitattributes are both present and correct. Missed in initial review.","dependency_count":0,"dependent_count":0,"comment_count":0} +{"id":"ifcurl-ntm","title":"Avoid full model reload when only view params change (camera, clip, visibility)","description":"When editing the ifc:// URL field in the viewer, any parameter change triggers a full fetch, parse, and 3D rebuild. This is unnecessary for parameters that only affect the rendered view — camera, clipping planes, visibility mode, selector highlighting — all of which can be applied to the already-loaded model without re-fetching the IFC file from the server. A full reload should only happen when the source changes: host, repo, ref, or path.","status":"in_progress","priority":2,"issue_type":"bug","assignee":"Bruno Postle","owner":"bruno@postle.net","created_at":"2026-05-17T05:43:36Z","created_by":"Bruno Postle","updated_at":"2026-05-17T05:44:26Z","started_at":"2026-05-17T05:44:26Z","dependency_count":0,"dependent_count":0,"comment_count":0} +{"id":"ifcurl-c8t","title":"Black screen flash before screenshot transition on model reload","description":"When the model is re-fetched, a screenshot of the current view is taken and faded into the new model. However, immediately before the screenshot appears there is a brief black screen, breaking the seamless transition. The screenshot (or the last rendered frame) should be displayed immediately when a reload begins — before the WebGL context is torn down or the canvas is cleared — so that the old view stays visible without interruption until the fade-in completes.","status":"open","priority":2,"issue_type":"bug","owner":"bruno@postle.net","created_at":"2026-05-17T05:43:06Z","created_by":"Bruno Postle","updated_at":"2026-05-17T05:43:06Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"id":"ifcurl-eaf","title":"Preview image camera is offset ~5m laterally vs JS viewer","description":"When opening a Forgejo markdown preview image (rendered by Python service via /preview), the camera position appears ~5m to the left compared to the same URL opened in the JS viewer.\n\nConfirmed: the model geometry IS shifted, not just a display scaling issue.\n\nWhat's known:\n- render.py uses IfcOpenShell with use-world-coords=True (world-space vertices)\n- _apply_camera() sets PyVista camera directly in IFC coordinates (no axis conversion)\n- JS viewer uses toThree() to convert IFC (Z-up) → Three.js (Y-up) coords\n- Python test from source correctly fetches the file (fetch works, rendering is the issue)\n\nHypothesis to investigate:\n- Does IfcOpenShell's geom iterator output vertices in IFC world coords (Z-up) or does it apply an axis swap?\n- Does PyVista/VTK interpret the camera position in the same axis convention as the IFC geometry?\n- Is plotter.show() triggering a reset_camera() that overrides the explicitly set camera?\n\nTest URL: ifc://localhost/bruno/simple-ifc@6af61b5454ac10ee2651da2d7363f54faa4f5b70?path=_test_simple.ifc\u0026camera=13.4983,-3.5129,4.4906,-0.8673,-0.4901,-0.0869,0,0,1\u0026fov=60\n\nRelevant code: ifcurl/render.py _apply_camera() line 88, _render_iterator() line 269.","notes":"Investigation so far (2026-05-16):\n\nRoot cause hypothesis: web-ifc uses COORDINATE_TO_ORIGIN=True when loading IFC for the JS viewer. This moves the model's IFC WorldCoordinateSystem to Three.js origin. IfcOpenShell with use-world-coords=True gives raw IFC world coordinates. If COORDINATE_TO_ORIGIN applies a non-identity transform to this specific model, that explains the offset.\n\nModel coordinate facts:\n- WorldCoordinateSystem: at origin (0,0,0) with standard axes\n- Site/Building/Storey placements: all at origin (identity matrix)\n- Model Y range (IFC): -15.9 to 4.1m, bbox center Y=-5.9m\n- This ~5.9m Y-offset matches the reported ~5m lateral offset\n\nKey findings:\n- COORDINATE_TO_ORIGIN=True is set in IfcImporter.webIfcSettings (engine_fragment)\n- The autoCoordinate=true in FragmentsModels does NOT center a single model — only aligns subsequent models to the first one's coordinate system\n- MCP tool .mcp.json configured: ifcmcp installed at /usr/bin/ifcmcp\n\nNext step: use ifcmcp to inspect what web-ifc actually outputs for this model's bounding box vs IfcOpenShell. Need to determine: does web-ifc COORDINATE_TO_ORIGIN shift the model's geometry even when WorldCoordinateSystem is at origin?","status":"closed","priority":2,"issue_type":"bug","assignee":"Bruno Postle","owner":"bruno@postle.net","created_at":"2026-05-16T00:13:00Z","created_by":"Bruno Postle","updated_at":"2026-05-16T11:30:35Z","started_at":"2026-05-16T11:03:44Z","closed_at":"2026-05-16T11:30:35Z","close_reason":"Fixed by adding webIfc: { COORDINATE_TO_ORIGIN: false } to ifcLoader.setup() in viewer.js. Root cause: web-ifc COORDINATE_TO_ORIGIN shifts all model geometry (by ~12m for this model's first-element position) but GetCoordinationMatrix returns identity, hiding the shift. Camera URL stores IFC world coords but model was in shifted space. Fix keeps model in IFC world coords (per spec §5) which matches IfcOpenShell's unshifted output in the Python renderer.","dependency_count":0,"dependent_count":0,"comment_count":0} {"id":"ifcurl-b1c","title":"Implement OpenCDE BCF API on Forgejo","description":"Expose a BCF 3.0 REST API as a Python route group in the preview service, proxied at /bcf/3.0/ on the Forgejo hostname via nginx/Caddy.\n\n## Architecture\n\nPython routes added to service.py alongside the existing /preview and /bcf endpoints. No new Forgejo Go code — the service forwards the user's Authorization: Bearer header verbatim to Forgejo's REST API on localhost, so Forgejo's own auth middleware enforces per-user permissions. No service account or machine token required.\n\nBCF \u003c-\u003e ifc:// conversion stays entirely in Python: bcf.py (ifc:// -\u003e BCF, already exists) and the reverse direction implemented in ifcurl-l50.\n\n## Design\n\nThe BCF API is a stateless translation layer over Forgejo's REST API. No Forgejo recompilation, no schema changes, no new Go code.\n\n**Storage:** ifc:// URLs in issue and comment bodies are the viewpoint format. This is already what the viewer Issue button produces. The BCF\u003c-\u003eifc:// conversion is specified in SPECIFICATION.md §6.\n\n**Mapping:**\n\n| BCF resource | Forgejo |\n|---|---|\n| Project | Repository (project_id = owner/repo) |\n| Topic | Issue |\n| Topic guid | Derived from issue ID |\n| Comment | Issue comment |\n| Viewpoint | ifc:// URL found in issue/comment body |\n| Viewpoint guid | Derived from comment ID |\n| Snapshot | ifc:// URL proxied through preview service |\n\n**Auth:** BCF client sends Authorization: Bearer \u003cforgejo-token\u003e. Service forwards it to Forgejo REST API. No credential storage, no service token.\n\n**Read viewpoints:** scan issue/comment bodies for ifc:// URLs, convert each to a BCF viewpoint object on the fly via the §6 mapping.\n\n**Write viewpoints:** convert incoming BCF viewpoint to an ifc:// URL (ifcurl-l50), post as a new Forgejo comment.\n\n**Snapshot:** GET .../viewpoints/{guid}/snapshot proxies the stored ifc:// URL through the existing /preview endpoint.\n\n## Minimum viable endpoints\n\n- GET /bcf/3.0/projects\n- GET /bcf/3.0/projects/{id}\n- GET/POST /bcf/3.0/projects/{id}/topics\n- GET/PUT /bcf/3.0/projects/{id}/topics/{guid}\n- GET/POST /bcf/3.0/projects/{id}/topics/{guid}/comments\n- GET/POST /bcf/3.0/projects/{id}/topics/{guid}/viewpoints\n- GET /bcf/3.0/projects/{id}/topics/{guid}/viewpoints/{guid}\n- GET /bcf/3.0/projects/{id}/topics/{guid}/viewpoints/{guid}/snapshot\n- GET /bcf/3.0/projects/{id}/extensions (static minimal response)\n\n## Prerequisites\n\n- ifcurl-lwl: Foundation API discovery so BCF clients can locate this endpoint via OpenCDE auto-discovery\n- ifcurl-l50: BCF -\u003e ifc:// URL conversion needed for POST /viewpoints","status":"closed","priority":2,"issue_type":"feature","owner":"bruno@postle.net","created_at":"2026-04-28T22:55:11Z","created_by":"Bruno Postle","updated_at":"2026-04-29T18:39:11Z","closed_at":"2026-04-29T18:39:11Z","close_reason":"Closed","dependencies":[{"issue_id":"ifcurl-b1c","depends_on_id":"ifcurl-l50","type":"blocks","created_at":"2026-04-29T18:44:06Z","created_by":"Bruno Postle","metadata":"{}"},{"issue_id":"ifcurl-b1c","depends_on_id":"ifcurl-lwl","type":"blocks","created_at":"2026-04-29T18:44:05Z","created_by":"Bruno Postle","metadata":"{}"}],"dependency_count":2,"dependent_count":0,"comment_count":0} {"id":"ifcurl-962","title":"forgejo: replace Go markdown extension with JS, eliminate required Go compile","description":"ifc_url.go is a Goldmark AST extension that requires patching and recompiling Forgejo to work. This is painful when dev environment (Fedora) differs from deployment (Docker) — compiler flags, static linking, build tags must all match. The goal is to make the ifc:// preview feature work with zero Go compilation, via pure JS asset deployment.\n\nPlan:\n1. Add querySelectorAll('a[href^=\"ifc://\"]') scanning to ifcurl.js — replace matched anchors with figure elements (preview image + viewer link + ifc:// URL). Goldmark already renders [title](ifc://...) as \u003ca href=\"ifc://...\"\u003etitle\u003c/a\u003e without any extension, so this covers all markdown link syntax.\n2. Change the Issue button in viewer.js to emit [view](ifc://...) markdown link syntax instead of a bare URL — so that user-generated issue bodies produce linkable anchors Goldmark will render, not plain text.\n3. The existing Go extension (ifc_url.go) and its markdown.go registration can be removed on the next Forgejo upgrade; the current patched binary continues to work in the meantime.\n\nAcceptance: after this change, deploying new ifcurl features only requires copying JS assets — no Forgejo rebuild needed.","status":"closed","priority":2,"issue_type":"feature","assignee":"Bruno Postle","owner":"bruno@postle.net","created_at":"2026-04-27T06:58:15Z","created_by":"Bruno Postle","updated_at":"2026-04-27T07:25:09Z","started_at":"2026-04-27T06:58:48Z","closed_at":"2026-04-27T07:25:09Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0} @@ -116,6 +118,6 @@ {"id":"ifcurl-vam","title":"Phase 6: Bonsai offer ifc:// URL when saving linked model reference","description":"When saving an IFCDOCUMENTREFERENCE in Bonsai, offer the option to write the location as an ifc:// URL rather than a relative path. When a relative path would traverse above the repository root, prompt the user to convert it to an ifc:// URL. Requires Phase 4 federation (ifcurl-bqt).","status":"deferred","priority":4,"issue_type":"feature","owner":"bruno@postle.net","created_at":"2026-04-23T05:49:16Z","created_by":"Bruno Postle","updated_at":"2026-04-23T06:15:13Z","defer_until":"2026-12-01T00:00:00Z","dependencies":[{"issue_id":"ifcurl-vam","depends_on_id":"ifcurl-bqt","type":"blocks","created_at":"2026-04-23T06:49:23Z","created_by":"Bruno Postle","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} {"id":"ifcurl-9k2","title":"Phase 5: IFC Viewer integration (equivalent of Phase 4)","description":"Add ifc:// OS protocol handler and 'Copy view URL' button to the IFC Viewer desktop application, equivalent to the Bonsai Phase 4 integration. Depends on Phase 4 being complete as a reference implementation.","status":"deferred","priority":4,"issue_type":"feature","owner":"bruno@postle.net","created_at":"2026-04-23T05:49:08Z","created_by":"Bruno Postle","updated_at":"2026-04-23T06:15:12Z","defer_until":"2026-12-01T00:00:00Z","dependencies":[{"issue_id":"ifcurl-9k2","depends_on_id":"ifcurl-0oj","type":"blocks","created_at":"2026-04-23T06:49:14Z","created_by":"Bruno Postle","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} {"id":"ifcurl-prc","title":"Phase 3c: 3D diff view for IFC PR merges","description":"After a PR merge completes, surface a 'View merge in 3D' button using the Phase 3b viewer. Use @thatopen/components highlighter to colour added, removed, and modified elements differently, driven by comparing the merged IFC against either parent. Requires Phase 3b viewer (ifcurl-i1s) to be working.","status":"closed","priority":4,"issue_type":"feature","owner":"bruno@postle.net","created_at":"2026-04-23T05:48:30Z","created_by":"Bruno Postle","updated_at":"2026-04-26T17:15:07Z","closed_at":"2026-04-26T17:15:07Z","close_reason":"Rendered diff already implemented in footer.tmpl Case 3; static PNG via /render_diff endpoint, not interactive 3D","dependencies":[{"issue_id":"ifcurl-prc","depends_on_id":"ifcurl-i1s","type":"blocks","created_at":"2026-04-23T06:48:36Z","created_by":"Bruno Postle","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} -{"_type":"memory","key":"forgejo-build-and-deploy-procedure-go-build-c","value":"Forgejo build and deploy procedure: go build -C /home/bruno/src/forgejo -tags 'sqlite sqlite_unlock_notify' -ldflags \"-X 'forgejo.org/modules/setting.StaticRootPath=/usr/share/forgejo'\" -o /home/bruno/src/forgejo/forgejo . — then sudo cp forgejo /usr/bin/forgejo. StaticRootPath=/usr/share/forgejo. CustomPath=/var/lib/forgejo/custom. Custom templates go to /var/lib/forgejo/custom/templates/custom/ (e.g. footer.tmpl → /var/lib/forgejo/custom/templates/custom/footer.tmpl). Custom static files go to /var/lib/forgejo/custom/public/assets/ (NOT /etc/forgejo/public/assets/) and are served at /assets/*."} {"_type":"memory","key":"ifcurl-service-names-are-ifcurl-api-service-and","value":"ifcurl service names are ifcurl-api.service and ifcurl-render.service (not ifcurl.service). Install path for Python package: /opt/ifcurl/lib/python3.14/site-packages/ifcurl/. Python binary: /opt/ifcurl/bin/python3."} {"_type":"memory","key":"torawurl-in-viewer-url-js-must-support-github","value":"toRawUrl in viewer-url.js must support GitHub, GitLab, Forgejo/Gitea (codeberg.org, self-hosted), and localhost. Tests in forgejo/tests/viewer-url.test.js cover all four. The localhost check (http vs https) is based on host.startsWith('localhost'), so subdomain.localhost gets https."} +{"_type":"memory","key":"forgejo-build-and-deploy-procedure-go-build-c","value":"Forgejo build and deploy procedure: go build -C /home/bruno/src/forgejo -tags 'sqlite sqlite_unlock_notify' -ldflags \"-X 'forgejo.org/modules/setting.StaticRootPath=/usr/share/forgejo'\" -o /home/bruno/src/forgejo/forgejo . — then sudo cp forgejo /usr/bin/forgejo. StaticRootPath=/usr/share/forgejo. CustomPath=/var/lib/forgejo/custom. Custom templates go to /var/lib/forgejo/custom/templates/custom/ (e.g. footer.tmpl → /var/lib/forgejo/custom/templates/custom/footer.tmpl). Custom static files go to /var/lib/forgejo/custom/public/assets/ (NOT /etc/forgejo/public/assets/) and are served at /assets/*."} diff --git a/forgejo/custom/public/assets/viewer.js b/forgejo/custom/public/assets/viewer.js index 5b41011..3e859ce 100644 --- a/forgejo/custom/public/assets/viewer.js +++ b/forgejo/custom/public/assets/viewer.js @@ -5,7 +5,7 @@ import { parseIfcUrl, toRawUrl, buildIfcUrl as _buildIfcUrl } from "./viewer-url import { isSimpleTypeSelector, subtractIdMap, isCommitHash } from "./viewer-util.js"; const params = new URLSearchParams(window.location.search); -const ifcUrl = params.get("url") ?? ""; +let currentIfcUrl = params.get("url") ?? ""; const statusEl = document.getElementById("status"); const urlInput = document.getElementById("url-input"); const fovInput = document.getElementById("fov-input"); @@ -37,16 +37,21 @@ const resizeObs = new ResizeObserver(() => { }); resizeObs.observe(toolbar); +let components = null; +let world = null; let cameraControls = null; let threeCamera = null; let activeClipper = null; let loadedModel = null; let rendererCanvas = null; +// Raw HTTP URL of the loaded IFC file, captured once at model load time. +// Used to decide whether a loadUrl call needs a full reload or an in-place update. +let modelRawUrl = null; // Show previous-view snapshot while the new model loads. { const snap = sessionStorage.getItem("viewerSnapshot"); - if (snap && ifcUrl) { + if (snap && currentIfcUrl) { const el = document.createElement("div"); el.id = "snapshot-overlay"; el.style.backgroundImage = `url("${snap}")`; @@ -70,8 +75,8 @@ function buildIfcUrl() { ); } -// Populate structured fields from the current ifcUrl. -const parsed = parseIfcUrl(ifcUrl); +// Populate structured fields from the current URL. +const parsed = parseIfcUrl(currentIfcUrl); if (parsed) { repoInput.value = parsed.repo; refInput.value = parsed.ref; @@ -79,13 +84,13 @@ if (parsed) { selectorInput.value = parsed.selector; queryInput.value = parsed.query; } -urlInput.value = ifcUrl; +urlInput.value = currentIfcUrl; // Initialise visibility dropdown from URL and show it when selector is non-empty. { - const qIdx = ifcUrl.indexOf("?"); + const qIdx = currentIfcUrl.indexOf("?"); const visVal = qIdx < 0 ? "highlight" - : (new URLSearchParams(ifcUrl.slice(qIdx + 1)).get("visibility") ?? "highlight"); + : (new URLSearchParams(currentIfcUrl.slice(qIdx + 1)).get("visibility") ?? "highlight"); visibilitySelect.value = visVal; } function syncVisibilityField() { @@ -108,9 +113,9 @@ if (parsed && isCommitHash(parsed.ref)) { refSwitchBtn.textContent = `→ ${targetRef}`; refSwitchBtn.style.display = ""; refSwitchBtn.addEventListener("click", () => { - const qI = ifcUrl.indexOf("?"); - const base = qI < 0 ? ifcUrl : ifcUrl.slice(0, qI); - const tail = qI < 0 ? "" : ifcUrl.slice(qI); + const qI = currentIfcUrl.indexOf("?"); + const base = qI < 0 ? currentIfcUrl : currentIfcUrl.slice(0, qI); + const tail = qI < 0 ? "" : currentIfcUrl.slice(qI); loadUrl(base.slice(0, base.lastIndexOf("@") + 1) + targetRef + tail); }); }) @@ -123,11 +128,115 @@ if (parsed?.host && parsed?.repoSuffix) { populateRefList(parsed.host, parsed.repoSuffix).catch(() => { /* silent */ }); } +// ----------------------------------------------------------------------- +// Apply view-only param changes (camera, clip, selector, visibility, query) +// in-place without re-fetching the IFC file. +// ----------------------------------------------------------------------- +async function applyViewChanges(newUrl) { + const oldQIdx = currentIfcUrl.indexOf("?"); + const oldQs = new URLSearchParams(oldQIdx < 0 ? "" : currentIfcUrl.slice(oldQIdx + 1)); + const newQIdx = newUrl.indexOf("?"); + const newQs = new URLSearchParams(newQIdx < 0 ? "" : newUrl.slice(newQIdx + 1)); + + // Update currentIfcUrl and the URL bar first so any triggered syncCameraUrl + // calls use the correct base. + currentIfcUrl = newUrl; + urlInput.value = newUrl; + const pageUrl = new URL(window.location.href); + pageUrl.searchParams.set("url", newUrl); + history.replaceState(null, "", pageUrl.toString()); + + // Sync structured form fields. + const parsedNew = parseIfcUrl(newUrl); + if (parsedNew) { + selectorInput.value = parsedNew.selector; + queryInput.value = parsedNew.query; + } + const newVisibility = newQs.get("visibility") ?? "highlight"; + visibilitySelect.value = newVisibility; + syncVisibilityField(); + + // Camera / projection. + const oldCamera = oldQs.get("camera") ?? ""; + const newCamera = newQs.get("camera") ?? ""; + const oldFov = oldQs.get("fov") ?? ""; + const newFov = newQs.get("fov") ?? ""; + const oldScale = oldQs.get("scale") ?? ""; + const newScale = newQs.get("scale") ?? ""; + if (newCamera !== oldCamera || newFov !== oldFov || newScale !== oldScale) { + await applyCameraParam(cameraControls, world.camera, newUrl); + // Flush camera-controls position into the Three.js camera matrix before rendering. + // setLookAt(false) sets the destination but doesn't write to Three.js until update(). + cameraControls.update(0); + threeCamera = world.camera.three; + if (loadedModel) loadedModel.useCamera(threeCamera); + await components.get(OBC.FragmentsManager).core.update(true); + } + + // Clipping planes. + const oldClips = oldQs.getAll("clip"); + const newClips = newQs.getAll("clip"); + if (JSON.stringify(newClips) !== JSON.stringify(oldClips) && activeClipper) { + activeClipper.deleteAll(); + const planes = newClips.map(s => s.split(",").map(Number)) + .filter(v => v.length === 6 && !v.some(isNaN)); + for (const [px, py, pz, nx, ny, nz] of planes) { + activeClipper.createFromNormalAndCoplanarPoint( + world, toThree(nx, ny, nz).normalize(), toThree(px, py, pz) + ); + } + const clipClearBtn = document.getElementById("clip-clear-btn"); + clipClearBtn.style.display = activeClipper.list.size > 0 ? "" : "none"; + } + + // Selector / visibility. + const oldSelector = oldQs.get("selector") ?? ""; + const newSelector = newQs.get("selector") ?? ""; + const oldVisibility = oldQs.get("visibility") ?? "highlight"; + if (newSelector !== oldSelector || newVisibility !== oldVisibility) { + const frags = components.get(OBC.FragmentsManager); + const hider = components.get(OBC.Hider); + await frags.resetHighlight(); + await hider.set(true); + if (newSelector) { + statusEl.textContent = "Applying selector…"; + await applySelector(components, loadedModel, newSelector, newUrl, newVisibility); + } + await frags.core.update(true); + } + + // Query. + const oldQuery = oldQs.get("query") ?? ""; + const newQuery = newQs.get("query") ?? ""; + if (newQuery !== oldQuery) { + if (newQuery) await applyQuery(newUrl, newQuery); + else queryPanel.style.display = "none"; + } + + statusEl.textContent = ""; +} + // ----------------------------------------------------------------------- // Navigate to the viewer with a different ifc:// URL. -// Captures a canvas snapshot for the transition overlay, then fades out. +// If only view params changed (camera, clip, selector, visibility, query) +// the changes are applied in-place without re-fetching the IFC model. +// A full page reload only happens when the source changes (host/repo/ref/path). // ----------------------------------------------------------------------- function loadUrl(url) { + // In-place update when the loaded IFC file is unchanged (only view params differ). + if (modelRawUrl) { + let rawUrl; + try { rawUrl = toRawUrl(url); } catch (_) { /* malformed url — fall through */ } + if (rawUrl && rawUrl === modelRawUrl) { + applyViewChanges(url).catch(err => { + statusEl.textContent = `Update error: ${err.message}`; + console.error(err); + }); + return; + } + } + + // Source changed → capture snapshot for seamless transition, then navigate. if (rendererCanvas) { try { const snap = rendererCanvas.toDataURL("image/jpeg", 0.6); @@ -375,9 +484,9 @@ function syncCameraUrl(camera) { f(iu.x), f(iu.y), f(iu.z), ].join(","); - const qIdx = ifcUrl.indexOf("?"); - const base = qIdx < 0 ? ifcUrl : ifcUrl.slice(0, qIdx); - const qs = new URLSearchParams(qIdx < 0 ? "" : ifcUrl.slice(qIdx + 1)); + const qIdx = currentIfcUrl.indexOf("?"); + const base = qIdx < 0 ? currentIfcUrl : currentIfcUrl.slice(0, qIdx); + const qs = new URLSearchParams(qIdx < 0 ? "" : currentIfcUrl.slice(qIdx + 1)); qs.set("camera", cameraParam); if (camera.isPerspectiveCamera) { qs.set("fov", f(camera.fov).toString()); @@ -402,6 +511,7 @@ function syncCameraUrl(camera) { const newIfcUrl = base + "?" + qs.toString() .replace(/%2C/g, ",").replace(/%2B/g, "+").replace(/%24/g, "$"); + currentIfcUrl = newIfcUrl; urlInput.value = newIfcUrl; const pageUrl = new URL(window.location.href); @@ -598,10 +708,10 @@ async function applyQuery(srcUrl, queryPath) { // Place the camera from ifc:// URL camera=/fov=/scale= params. // obcCamera is the OBC OrthoPerspectiveCamera instance (world.camera). // ----------------------------------------------------------------------- -async function applyCameraParam(controls, obcCamera) { - const qIdx = ifcUrl.indexOf("?"); +async function applyCameraParam(controls, obcCamera, url) { + const qIdx = url.indexOf("?"); if (qIdx < 0) return false; - const qs = new URLSearchParams(ifcUrl.slice(qIdx + 1)); + const qs = new URLSearchParams(url.slice(qIdx + 1)); const camStr = qs.get("camera"); if (!camStr) return false; @@ -1046,16 +1156,16 @@ async function fetchBranchForCommit(host, repoSuffix, hash) { // Main // ----------------------------------------------------------------------- async function main() { - if (!ifcUrl) { + if (!currentIfcUrl) { statusEl.textContent = "Fill in the fields above and press Enter, or paste an ifc:// URL."; return; } statusEl.textContent = "Loading…"; - const components = new OBC.Components(); + components = new OBC.Components(); const worlds = components.get(OBC.Worlds); - const world = worlds.create(); + world = worlds.create(); const container = document.getElementById("viewer"); world.scene = new OBC.SimpleScene(components); @@ -1091,7 +1201,7 @@ async function main() { statusEl.textContent = "Fetching IFC file…"; let buffer; try { - const resp = await fetch(toRawUrl(ifcUrl)); + const resp = await fetch(toRawUrl(currentIfcUrl)); if (!resp.ok) throw new Error(`HTTP ${resp.status} ${resp.statusText}`); const contentLength = resp.headers.get("Content-Length"); const total = contentLength ? parseInt(contentLength, 10) : 0; @@ -1125,18 +1235,19 @@ async function main() { try { const model = await ifcLoader.load(buffer, true, "model"); loadedModel = model; + modelRawUrl = toRawUrl(currentIfcUrl); world.scene.three.add(model.object); - const hasCam = await applyCameraParam(cameraControls, world.camera); + const hasCam = await applyCameraParam(cameraControls, world.camera, currentIfcUrl); threeCamera = world.camera.three; // refresh: may now be ortho if (!hasCam && !model.box.isEmpty()) { await cameraControls.fitToBox(model.box, false); } model.useCamera(threeCamera); - const qIdxPost = ifcUrl.indexOf("?"); + const qIdxPost = currentIfcUrl.indexOf("?"); const qsPost = new URLSearchParams( - qIdxPost < 0 ? "" : ifcUrl.slice(qIdxPost + 1) + qIdxPost < 0 ? "" : currentIfcUrl.slice(qIdxPost + 1) ); const clips = qsPost.getAll("clip") @@ -1182,11 +1293,11 @@ async function main() { if (selectorStr) { statusEl.textContent = "Applying selector…"; - await applySelector(components, model, selectorStr, ifcUrl, visibility); + await applySelector(components, model, selectorStr, currentIfcUrl, visibility); } if (selectorStr && queryStr) { - await applyQuery(ifcUrl, queryStr); + await applyQuery(currentIfcUrl, queryStr); } await fragments.core.update(true);