@thatopen/services 0.3.16 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +62 -62
  2. package/dist/cli/commands/rhino.d.ts +11 -0
  3. package/dist/cli/lib/plugin-install.d.ts +24 -0
  4. package/dist/cli.js +124 -1
  5. package/dist/core/client.d.ts +1 -0
  6. package/dist/core/platform-client.d.ts +7 -0
  7. package/dist/index.cjs.js +2 -2
  8. package/dist/index.es.js +382 -370
  9. package/dist/vite-env.d.ts +1 -1
  10. package/docs/ai-quickstart.md +130 -130
  11. package/docs/cli/create.md +29 -29
  12. package/docs/cli/local-server.md +38 -38
  13. package/docs/cli/login.md +32 -32
  14. package/docs/cli/publish.md +31 -31
  15. package/docs/cli/run.md +26 -26
  16. package/docs/cli/serve.md +43 -43
  17. package/docs/cli/swap.md +30 -30
  18. package/docs/cloud/GaussianSplatConverter.md +43 -43
  19. package/docs/cloud/PointCloudConverter.md +53 -53
  20. package/docs/revit-collab-quickstart.md +256 -256
  21. package/package.json +95 -95
  22. package/resources/AGENTS.md +40 -40
  23. package/src/built-in/CDEManager/example.ts +214 -214
  24. package/src/built-in/CDEManager/examples/FileEditing/example.ts +226 -226
  25. package/src/built-in/CDEManager/examples/FileMoves/example.ts +186 -186
  26. package/src/built-in/CDEManager/examples/FileOperations/example.ts +295 -295
  27. package/src/built-in/CDEManager/examples/FileTransfers/example.ts +210 -210
  28. package/src/built-in/CDEManager/examples/FolderManagement/example.ts +230 -230
  29. package/src/built-in/CDEManager/examples/MetadataSchema/example.ts +230 -230
  30. package/src/built-in/CDEManager/examples/MetadataViews/example.ts +166 -166
  31. package/src/built-in/CDEManager/examples/ProjectConfig/example.ts +177 -177
  32. package/src/built-in/ClashesManager/example.ts +283 -283
  33. package/src/built-in/UIManager/src/app/example.ts +97 -97
  34. package/src/built-in/UIManager/src/app/examples/AppState/example.ts +140 -140
  35. package/src/built-in/UIManager/src/app/examples/Banner/example.ts +159 -159
  36. package/src/built-in/UIManager/src/app/examples/Contexts/example.ts +123 -123
  37. package/src/built-in/UIManager/src/app/examples/FileDrop/example.ts +124 -124
  38. package/src/built-in/UIManager/src/app/examples/FloatingLayout/example.ts +90 -90
  39. package/src/built-in/UIManager/src/app/examples/Modal/example.ts +163 -163
  40. package/src/built-in/UIManager/src/app/examples/Notifications/example.ts +133 -133
  41. package/src/built-in/UIManager/src/app/examples/Sidebar/example.ts +102 -102
  42. package/src/cli/templates/app/README.md +217 -217
  43. package/src/cli/templates/app/index.html +35 -35
  44. package/src/cli/templates/app/package.json +32 -32
  45. package/src/cli/templates/app/src/app.ts +37 -37
  46. package/src/cli/templates/app/src/assets/tool-placeholder.ts +50 -50
  47. package/src/cli/templates/app/src/bim-components/CloudRunner/index.ts +95 -95
  48. package/src/cli/templates/app/src/bim-components/CloudRunner/src/index.ts +1 -1
  49. package/src/cli/templates/app/src/bim-components/CloudRunner/src/types.ts +5 -5
  50. package/src/cli/templates/app/src/bim-components/index.ts +1 -1
  51. package/src/cli/templates/app/src/globals.ts +1 -1
  52. package/src/cli/templates/app/src/main.ts +199 -199
  53. package/src/cli/templates/app/src/setups/reality-capture/lib/hidden-tiles-plugin.ts +88 -88
  54. package/src/cli/templates/app/src/setups/reality-capture/lib/point-tile-plugin.ts +166 -166
  55. package/src/cli/templates/app/src/setups/reality-capture/lib/render-frame.ts +31 -31
  56. package/src/cli/templates/app/src/setups/reality-capture/lib/splat-tile-plugin.ts +51 -51
  57. package/src/cli/templates/app/src/setups/reality-capture-viewer.ts +1383 -1383
  58. package/src/cli/templates/app/src/ui-components/app-info-section/index.ts +26 -26
  59. package/src/cli/templates/app/src/ui-components/app-info-section/src/index.ts +1 -1
  60. package/src/cli/templates/app/src/ui-components/app-info-section/src/types.ts +15 -15
  61. package/src/cli/templates/app/src/ui-components/cloud-runner-section/index.ts +37 -37
  62. package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/index.ts +1 -1
  63. package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/types.ts +14 -14
  64. package/src/cli/templates/app/src/ui-components/index.ts +2 -2
  65. package/src/cli/templates/app/tsconfig.json +16 -16
  66. package/src/cli/templates/app/vite.config.js +57 -57
  67. package/src/cli/templates/cloud-component/README.md +205 -205
  68. package/src/cli/templates/cloud-component/_thatopen +5 -5
  69. package/src/cli/templates/cloud-component/declarations.json +4 -4
  70. package/src/cli/templates/cloud-component/package.json +21 -21
  71. package/src/cli/templates/cloud-component/src/main.ts +70 -70
  72. package/src/cli/templates/cloud-component/tsconfig.json +16 -16
  73. package/src/cli/templates/cloud-component/vite.config.js +46 -46
  74. package/src/cli/templates/shared/AGENTS.md +8 -8
  75. package/src/cli/templates/shared/CLAUDE.md +1 -1
  76. package/src/cli/templates/shared/_gitignore +5 -5
@@ -1,283 +1,283 @@
1
- /* MD
2
- ## ClashesManager
3
- ---
4
- Structural engineers and BIM coordinators routinely detect geometric clashes
5
- between disciplines — structural steel penetrating ductwork, pipes clashing
6
- with slabs — and need to track the status of each issue through resolution
7
- without leaving their BIM environment.
8
-
9
- ClashesManager is the platform-side component that owns clash data: it loads and
10
- persists jobs, runs, and clashes; launches cloud-based clash detection in a Web
11
- Worker; and exposes the events and methods needed to build review workflows on
12
- top of it.
13
-
14
- This tutorial covers initializing the manager from the platform client; the
15
- recommended `clashes-panel` UI that works out of the box once `init` has been
16
- called; defining queries and detection matrices for fine-grained control;
17
- launching a detection run and tracking progress; updating clash status
18
- programmatically; and rendering sphere markers and element highlights without
19
- the built-in panel.
20
-
21
- By the end, you'll understand every public surface of ClashesManager and know
22
- which parts are handled automatically by `clashes-panel` so you can decide how
23
- much of the stack you need for your use case.
24
- */
25
-
26
- import * as THREE from "three";
27
- import * as OBC from "@thatopen/components";
28
- import * as OBF from "@thatopen/components-front";
29
- import * as FRAGS from "@thatopen/fragments";
30
- import * as BUI from "@thatopen/ui";
31
- import { PlatformClient, ClashesManager } from "@thatopen/services";
32
-
33
-
34
- const client = PlatformClient.fromPlatformContext();
35
-
36
- const { components } = (await client.setup(
37
- { OBC, OBF, BUI, THREE, FRAGS },
38
- { uuid: ClashesManager.uuid },
39
- )) as { components: OBC.Components };
40
-
41
- /* MD
42
- ### 🚀 Initializing the manager
43
-
44
- `init(client)` is the only call required before using the manager. It:
45
-
46
- - Loads all persisted clash data (jobs, runs, clashes, queries, matrices) from
47
- the project's cloud storage into memory.
48
- - Registers `save` and `reload` callbacks so writes are debounced to storage
49
- automatically and the manager can refresh its data after a run completes.
50
- - Reads any in-flight cloud executions so that a page reload mid-run doesn't
51
- lose track of the job.
52
- - Resolves the engine's active `World` in the background — if no world exists
53
- yet, it waits until one is created, so the order of initialization does not
54
- matter.
55
-
56
- After `init` resolves, `manager.ready` is `true` and all data properties
57
- (`jobs`, `runs`, `clashes`, `queries`, `matrices`) are populated.
58
- */
59
-
60
- const manager = components.get(ClashesManager);
61
- await manager.init(client);
62
-
63
- console.log(
64
- `Loaded ${manager.jobs.length} jobs, ` +
65
- `${manager.runs.length} runs, ` +
66
- `${manager.clashes.length} clashes.`,
67
- );
68
-
69
- /* MD
70
- ### 🖥️ Adding the built-in panel (recommended)
71
-
72
- Once `init` has been called, the `<top-clashes-panel>` web component is the
73
- recommended way to interact with `ClashesManager`. It covers the full
74
- review workflow — detection matrix, clash table, sphere markers, status
75
- filters, run progress — with zero additional wiring.
76
-
77
- `clashes-panel` is registered when `UIManager` is included in the platform
78
- setup call. See the **clashes-panel** tutorial for the complete setup and a
79
- detailed breakdown of everything the panel manages automatically.
80
-
81
- The sections below are for cases where you need direct control: building a
82
- custom UI, integrating clash data into your own panels, or automating status
83
- updates from outside the panel.
84
- */
85
-
86
- /* MD
87
- ### 📐 Queries and matrices
88
-
89
- A `ClashQuery` defines a named set of model elements: which files to scan and,
90
- optionally, which IFC categories or attribute conditions to match. Queries have
91
- no detection logic of their own — they are inputs to a matrix.
92
-
93
- A `ClashMatrix` pairs queries in an upper-triangle grid. Each active cell
94
- corresponds to one `ClashJob` that the cloud worker will execute. The matrix
95
- also carries the clash type (`hard` or `clearance`) and, for clearance checks,
96
- the tolerance in metres.
97
-
98
- Assigning to `manager.queries` or `manager.matrices` triggers a debounced
99
- auto-save (2 s). Call `await manager.flush()` to persist immediately before
100
- navigating away.
101
- */
102
-
103
- const structuralFileId = "file-id-of-structural-model";
104
- const mepFileId = "file-id-of-mep-model";
105
-
106
- manager.queries = [
107
- {
108
- id: "q-structural",
109
- name: "Structural",
110
- modelFileIds: [structuralFileId],
111
- query: { categories: ["IFCBEAM", "IFCCOLUMN", "IFCSLAB"] },
112
- },
113
- {
114
- id: "q-mep",
115
- name: "MEP",
116
- modelFileIds: [mepFileId],
117
- // Omitting `query` matches all elements with geometry in the listed files.
118
- },
119
- ];
120
-
121
- // The matrix below defines a single hard-clash job between Structural and MEP.
122
- // `activePairs` lists the upper-triangle cell keys (queryAId:queryBId).
123
- // `jobIds` is managed by the platform when the matrix is saved; leave it empty
124
- // on first creation and the backend fills it after the first save.
125
- manager.matrices = [
126
- {
127
- id: "matrix-main",
128
- name: "Structural vs MEP",
129
- queryIds: ["q-structural", "q-mep"],
130
- activePairs: ["q-structural:q-mep"],
131
- jobIds: [],
132
- jobType: "hard",
133
- },
134
- ];
135
-
136
- await manager.flush();
137
-
138
- /* MD
139
- ### ▶️ Running clash detection
140
-
141
- `run(jobId)` launches a Web Worker that calls the cloud clash-detection
142
- endpoint. It returns immediately — all feedback arrives through events.
143
-
144
- | Event | Payload | When |
145
- |-------|---------|------|
146
- | `onRunProgress` | `{ message, progress }` | Periodically while the worker runs |
147
- | `onRunComplete` | `{ runId, clashCount }` | Worker finished successfully |
148
- | `onRunError` | `{ code?, message }` | Worker or cloud error |
149
- | `onRunningJobsChanged` | `Set<string>` | A job starts or finishes |
150
- | `onReloadingChanged` | `boolean` | Data reload after a successful run |
151
-
152
- If the page is reloaded while a run is in progress, `init` re-reads the
153
- in-flight execution from storage and populates `runningJobIds`. Call
154
- `reconnectIfRunning(jobId)` to resume receiving progress events for that job.
155
- */
156
-
157
- manager.onRunProgress.add(({ message, progress }) => {
158
- console.log(`[${progress}%] ${message}`);
159
- });
160
-
161
- manager.onRunComplete.add(({ runId, clashCount }) => {
162
- console.log(`Run ${runId} complete — ${clashCount} clash(es) found.`);
163
- });
164
-
165
- manager.onRunError.add(({ code, message }) => {
166
- console.error(`Run failed (${code ?? "unknown"}): ${message}`);
167
- });
168
-
169
- manager.onReloadingChanged.add((reloading) => {
170
- // Use this flag to show a loading state in a custom UI while fresh data
171
- // is fetched from storage after the run. clashes-panel handles this automatically.
172
- console.log(reloading ? "Reloading clash data…" : "Clash data ready.");
173
- });
174
-
175
- // Guard: only run if the manager is ready and the job is not already running.
176
- const jobToRun = manager.jobs[0];
177
- if (jobToRun && manager.ready && !manager.runningJobIds.has(jobToRun.id)) {
178
- manager.run(jobToRun.id);
179
- }
180
-
181
- // If a run was already in progress before this page loaded, reconnect to it.
182
- for (const jobId of manager.runningJobIds) {
183
- manager.reconnectIfRunning(jobId);
184
- }
185
-
186
- /* MD
187
- ### ✅ Updating clash status
188
-
189
- Each clash starts with status `"new"`. Reviewers move clashes through a
190
- workflow by calling `updateClash`. Valid statuses are:
191
-
192
- - `"new"` — detected, not yet reviewed
193
- - `"active"` — under investigation
194
- - `"acknowledged"` — known issue, not blocking
195
- - `"resolved"` — fixed and verified
196
-
197
- Status changes and comments are persisted automatically via the same
198
- auto-save mechanism as queries and matrices.
199
-
200
- `runsForJob(jobId)` and `clashesForRun(runId)` let you navigate the history:
201
- a clash's `firstSeenRunId` / `lastSeenRunId` span shows across which runs it
202
- was present, so you can determine whether a resolution actually closed it.
203
- */
204
-
205
- manager.onClashStatusChanged.add((allClashes) => {
206
- const open = allClashes.filter(c => c.status === "new" || c.status === "active");
207
- console.log(`Open clashes: ${open.length}`);
208
- });
209
-
210
- const clashToAcknowledge = manager.clashes[0];
211
- if (clashToAcknowledge) {
212
- manager.updateClash(clashToAcknowledge.id, {
213
- status: "acknowledged",
214
- comments: "Coordination with MEP team scheduled for next sprint.",
215
- });
216
- }
217
-
218
- // Navigate run history for the first job.
219
- const firstJob = manager.jobs[0];
220
- if (firstJob) {
221
- const runs = manager.runsForJob(firstJob.id); // newest first
222
- const latestRun = runs[0];
223
- if (latestRun) {
224
- const clashesInRun = manager.clashesForRun(latestRun.id);
225
- console.log(`Latest run has ${clashesInRun.length} active clash(es).`);
226
- }
227
- }
228
-
229
- /* MD
230
- ### 📍 Visualization without the built-in panel
231
-
232
- If you are building a custom UI and not using `clashes-panel`, you can drive
233
- the visualization layer directly.
234
-
235
- **Sphere markers** — `showMarkers` places colored 3D spheres at clash
236
- locations in the viewer. Call `hideMarkers` to remove them and re-enable
237
- hover highlighting. Points are automatically transformed from IFC world space
238
- to Three.js viewer space using `FragmentsManager.baseCoordinationMatrix`.
239
-
240
- **Element highlights** — `highlightAllClashes` colors element A (green) and
241
- element B (red) for every new/active clash in the provided list.
242
- `clearClashHighlight` removes both styles. For single-clash focus, use
243
- `highlightClash` and pair it with `ghostClashes` to dim everything else.
244
-
245
- **Clustering** — `cluster(clashes, threshold)` groups spatially close clashes
246
- into a single marker. Pass `threshold = 0` to show one sphere per clash.
247
- `toViewerPoint` converts a raw IFC point to viewer space if you need to
248
- position custom objects.
249
- */
250
-
251
- const jobClashes = manager.clashes.filter(c => c.jobId === firstJob?.id);
252
-
253
- // Show one marker per clash, colored by status.
254
- manager.showMarkers(
255
- jobClashes.map(c => ({ id: c.id, point: c.point, count: 1, status: c.status })),
256
- );
257
-
258
- // Highlight all open clashes across both element sets.
259
- manager.highlightAllClashes(jobClashes);
260
-
261
- // --- Clustered view ---
262
- // Group clashes within 2 m of each other into a single sphere.
263
- const clusters = manager.cluster(jobClashes, 2);
264
- manager.showMarkers(
265
- clusters.map(group => ({
266
- point: group[0].point,
267
- count: group.length,
268
- status: group[0].status,
269
- })),
270
- );
271
-
272
- // Focus on a single clash: ghost everything else and zoom in.
273
- const focusClash = jobClashes[0];
274
- if (focusClash) {
275
- manager.clearClashHighlight();
276
- manager.highlightClash(focusClash);
277
- await manager.ghostClash(focusClash);
278
- }
279
-
280
- // Restore full scene when done.
281
- manager.hideMarkers();
282
- manager.clearClashHighlight();
283
- await manager.clearGhostClash();
1
+ /* MD
2
+ ## ClashesManager
3
+ ---
4
+ Structural engineers and BIM coordinators routinely detect geometric clashes
5
+ between disciplines — structural steel penetrating ductwork, pipes clashing
6
+ with slabs — and need to track the status of each issue through resolution
7
+ without leaving their BIM environment.
8
+
9
+ ClashesManager is the platform-side component that owns clash data: it loads and
10
+ persists jobs, runs, and clashes; launches cloud-based clash detection in a Web
11
+ Worker; and exposes the events and methods needed to build review workflows on
12
+ top of it.
13
+
14
+ This tutorial covers initializing the manager from the platform client; the
15
+ recommended `clashes-panel` UI that works out of the box once `init` has been
16
+ called; defining queries and detection matrices for fine-grained control;
17
+ launching a detection run and tracking progress; updating clash status
18
+ programmatically; and rendering sphere markers and element highlights without
19
+ the built-in panel.
20
+
21
+ By the end, you'll understand every public surface of ClashesManager and know
22
+ which parts are handled automatically by `clashes-panel` so you can decide how
23
+ much of the stack you need for your use case.
24
+ */
25
+
26
+ import * as THREE from "three";
27
+ import * as OBC from "@thatopen/components";
28
+ import * as OBF from "@thatopen/components-front";
29
+ import * as FRAGS from "@thatopen/fragments";
30
+ import * as BUI from "@thatopen/ui";
31
+ import { PlatformClient, ClashesManager } from "@thatopen/services";
32
+
33
+
34
+ const client = PlatformClient.fromPlatformContext();
35
+
36
+ const { components } = (await client.setup(
37
+ { OBC, OBF, BUI, THREE, FRAGS },
38
+ { uuid: ClashesManager.uuid },
39
+ )) as { components: OBC.Components };
40
+
41
+ /* MD
42
+ ### 🚀 Initializing the manager
43
+
44
+ `init(client)` is the only call required before using the manager. It:
45
+
46
+ - Loads all persisted clash data (jobs, runs, clashes, queries, matrices) from
47
+ the project's cloud storage into memory.
48
+ - Registers `save` and `reload` callbacks so writes are debounced to storage
49
+ automatically and the manager can refresh its data after a run completes.
50
+ - Reads any in-flight cloud executions so that a page reload mid-run doesn't
51
+ lose track of the job.
52
+ - Resolves the engine's active `World` in the background — if no world exists
53
+ yet, it waits until one is created, so the order of initialization does not
54
+ matter.
55
+
56
+ After `init` resolves, `manager.ready` is `true` and all data properties
57
+ (`jobs`, `runs`, `clashes`, `queries`, `matrices`) are populated.
58
+ */
59
+
60
+ const manager = components.get(ClashesManager);
61
+ await manager.init(client);
62
+
63
+ console.log(
64
+ `Loaded ${manager.jobs.length} jobs, ` +
65
+ `${manager.runs.length} runs, ` +
66
+ `${manager.clashes.length} clashes.`,
67
+ );
68
+
69
+ /* MD
70
+ ### 🖥️ Adding the built-in panel (recommended)
71
+
72
+ Once `init` has been called, the `<top-clashes-panel>` web component is the
73
+ recommended way to interact with `ClashesManager`. It covers the full
74
+ review workflow — detection matrix, clash table, sphere markers, status
75
+ filters, run progress — with zero additional wiring.
76
+
77
+ `clashes-panel` is registered when `UIManager` is included in the platform
78
+ setup call. See the **clashes-panel** tutorial for the complete setup and a
79
+ detailed breakdown of everything the panel manages automatically.
80
+
81
+ The sections below are for cases where you need direct control: building a
82
+ custom UI, integrating clash data into your own panels, or automating status
83
+ updates from outside the panel.
84
+ */
85
+
86
+ /* MD
87
+ ### 📐 Queries and matrices
88
+
89
+ A `ClashQuery` defines a named set of model elements: which files to scan and,
90
+ optionally, which IFC categories or attribute conditions to match. Queries have
91
+ no detection logic of their own — they are inputs to a matrix.
92
+
93
+ A `ClashMatrix` pairs queries in an upper-triangle grid. Each active cell
94
+ corresponds to one `ClashJob` that the cloud worker will execute. The matrix
95
+ also carries the clash type (`hard` or `clearance`) and, for clearance checks,
96
+ the tolerance in metres.
97
+
98
+ Assigning to `manager.queries` or `manager.matrices` triggers a debounced
99
+ auto-save (2 s). Call `await manager.flush()` to persist immediately before
100
+ navigating away.
101
+ */
102
+
103
+ const structuralFileId = "file-id-of-structural-model";
104
+ const mepFileId = "file-id-of-mep-model";
105
+
106
+ manager.queries = [
107
+ {
108
+ id: "q-structural",
109
+ name: "Structural",
110
+ modelFileIds: [structuralFileId],
111
+ query: { categories: ["IFCBEAM", "IFCCOLUMN", "IFCSLAB"] },
112
+ },
113
+ {
114
+ id: "q-mep",
115
+ name: "MEP",
116
+ modelFileIds: [mepFileId],
117
+ // Omitting `query` matches all elements with geometry in the listed files.
118
+ },
119
+ ];
120
+
121
+ // The matrix below defines a single hard-clash job between Structural and MEP.
122
+ // `activePairs` lists the upper-triangle cell keys (queryAId:queryBId).
123
+ // `jobIds` is managed by the platform when the matrix is saved; leave it empty
124
+ // on first creation and the backend fills it after the first save.
125
+ manager.matrices = [
126
+ {
127
+ id: "matrix-main",
128
+ name: "Structural vs MEP",
129
+ queryIds: ["q-structural", "q-mep"],
130
+ activePairs: ["q-structural:q-mep"],
131
+ jobIds: [],
132
+ jobType: "hard",
133
+ },
134
+ ];
135
+
136
+ await manager.flush();
137
+
138
+ /* MD
139
+ ### ▶️ Running clash detection
140
+
141
+ `run(jobId)` launches a Web Worker that calls the cloud clash-detection
142
+ endpoint. It returns immediately — all feedback arrives through events.
143
+
144
+ | Event | Payload | When |
145
+ |-------|---------|------|
146
+ | `onRunProgress` | `{ message, progress }` | Periodically while the worker runs |
147
+ | `onRunComplete` | `{ runId, clashCount }` | Worker finished successfully |
148
+ | `onRunError` | `{ code?, message }` | Worker or cloud error |
149
+ | `onRunningJobsChanged` | `Set<string>` | A job starts or finishes |
150
+ | `onReloadingChanged` | `boolean` | Data reload after a successful run |
151
+
152
+ If the page is reloaded while a run is in progress, `init` re-reads the
153
+ in-flight execution from storage and populates `runningJobIds`. Call
154
+ `reconnectIfRunning(jobId)` to resume receiving progress events for that job.
155
+ */
156
+
157
+ manager.onRunProgress.add(({ message, progress }) => {
158
+ console.log(`[${progress}%] ${message}`);
159
+ });
160
+
161
+ manager.onRunComplete.add(({ runId, clashCount }) => {
162
+ console.log(`Run ${runId} complete — ${clashCount} clash(es) found.`);
163
+ });
164
+
165
+ manager.onRunError.add(({ code, message }) => {
166
+ console.error(`Run failed (${code ?? "unknown"}): ${message}`);
167
+ });
168
+
169
+ manager.onReloadingChanged.add((reloading) => {
170
+ // Use this flag to show a loading state in a custom UI while fresh data
171
+ // is fetched from storage after the run. clashes-panel handles this automatically.
172
+ console.log(reloading ? "Reloading clash data…" : "Clash data ready.");
173
+ });
174
+
175
+ // Guard: only run if the manager is ready and the job is not already running.
176
+ const jobToRun = manager.jobs[0];
177
+ if (jobToRun && manager.ready && !manager.runningJobIds.has(jobToRun.id)) {
178
+ manager.run(jobToRun.id);
179
+ }
180
+
181
+ // If a run was already in progress before this page loaded, reconnect to it.
182
+ for (const jobId of manager.runningJobIds) {
183
+ manager.reconnectIfRunning(jobId);
184
+ }
185
+
186
+ /* MD
187
+ ### ✅ Updating clash status
188
+
189
+ Each clash starts with status `"new"`. Reviewers move clashes through a
190
+ workflow by calling `updateClash`. Valid statuses are:
191
+
192
+ - `"new"` — detected, not yet reviewed
193
+ - `"active"` — under investigation
194
+ - `"acknowledged"` — known issue, not blocking
195
+ - `"resolved"` — fixed and verified
196
+
197
+ Status changes and comments are persisted automatically via the same
198
+ auto-save mechanism as queries and matrices.
199
+
200
+ `runsForJob(jobId)` and `clashesForRun(runId)` let you navigate the history:
201
+ a clash's `firstSeenRunId` / `lastSeenRunId` span shows across which runs it
202
+ was present, so you can determine whether a resolution actually closed it.
203
+ */
204
+
205
+ manager.onClashStatusChanged.add((allClashes) => {
206
+ const open = allClashes.filter(c => c.status === "new" || c.status === "active");
207
+ console.log(`Open clashes: ${open.length}`);
208
+ });
209
+
210
+ const clashToAcknowledge = manager.clashes[0];
211
+ if (clashToAcknowledge) {
212
+ manager.updateClash(clashToAcknowledge.id, {
213
+ status: "acknowledged",
214
+ comments: "Coordination with MEP team scheduled for next sprint.",
215
+ });
216
+ }
217
+
218
+ // Navigate run history for the first job.
219
+ const firstJob = manager.jobs[0];
220
+ if (firstJob) {
221
+ const runs = manager.runsForJob(firstJob.id); // newest first
222
+ const latestRun = runs[0];
223
+ if (latestRun) {
224
+ const clashesInRun = manager.clashesForRun(latestRun.id);
225
+ console.log(`Latest run has ${clashesInRun.length} active clash(es).`);
226
+ }
227
+ }
228
+
229
+ /* MD
230
+ ### 📍 Visualization without the built-in panel
231
+
232
+ If you are building a custom UI and not using `clashes-panel`, you can drive
233
+ the visualization layer directly.
234
+
235
+ **Sphere markers** — `showMarkers` places colored 3D spheres at clash
236
+ locations in the viewer. Call `hideMarkers` to remove them and re-enable
237
+ hover highlighting. Points are automatically transformed from IFC world space
238
+ to Three.js viewer space using `FragmentsManager.baseCoordinationMatrix`.
239
+
240
+ **Element highlights** — `highlightAllClashes` colors element A (green) and
241
+ element B (red) for every new/active clash in the provided list.
242
+ `clearClashHighlight` removes both styles. For single-clash focus, use
243
+ `highlightClash` and pair it with `ghostClashes` to dim everything else.
244
+
245
+ **Clustering** — `cluster(clashes, threshold)` groups spatially close clashes
246
+ into a single marker. Pass `threshold = 0` to show one sphere per clash.
247
+ `toViewerPoint` converts a raw IFC point to viewer space if you need to
248
+ position custom objects.
249
+ */
250
+
251
+ const jobClashes = manager.clashes.filter(c => c.jobId === firstJob?.id);
252
+
253
+ // Show one marker per clash, colored by status.
254
+ manager.showMarkers(
255
+ jobClashes.map(c => ({ id: c.id, point: c.point, count: 1, status: c.status })),
256
+ );
257
+
258
+ // Highlight all open clashes across both element sets.
259
+ manager.highlightAllClashes(jobClashes);
260
+
261
+ // --- Clustered view ---
262
+ // Group clashes within 2 m of each other into a single sphere.
263
+ const clusters = manager.cluster(jobClashes, 2);
264
+ manager.showMarkers(
265
+ clusters.map(group => ({
266
+ point: group[0].point,
267
+ count: group.length,
268
+ status: group[0].status,
269
+ })),
270
+ );
271
+
272
+ // Focus on a single clash: ghost everything else and zoom in.
273
+ const focusClash = jobClashes[0];
274
+ if (focusClash) {
275
+ manager.clearClashHighlight();
276
+ manager.highlightClash(focusClash);
277
+ await manager.ghostClash(focusClash);
278
+ }
279
+
280
+ // Restore full scene when done.
281
+ manager.hideMarkers();
282
+ manager.clearClashHighlight();
283
+ await manager.clearGhostClash();