@thatopen/services 0.0.1
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.
- package/CONTEXT.md +258 -0
- package/README.md +285 -0
- package/dist/built-in/index.d.ts +723 -0
- package/dist/cli/commands/create-tests.d.ts +3 -0
- package/dist/cli/commands/create.d.ts +3 -0
- package/dist/cli/commands/local-server.d.ts +3 -0
- package/dist/cli/commands/login.d.ts +3 -0
- package/dist/cli/commands/publish.d.ts +3 -0
- package/dist/cli/commands/run.d.ts +3 -0
- package/dist/cli/commands/serve-tests.d.ts +3 -0
- package/dist/cli/commands/serve.d.ts +3 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/lib/config.d.ts +25 -0
- package/dist/cli/lib/declarations.d.ts +19 -0
- package/dist/cli/lib/engine-script.d.ts +10 -0
- package/dist/cli/lib/execution-manager.d.ts +52 -0
- package/dist/cli/lib/zip.d.ts +6 -0
- package/dist/cli.js +11566 -0
- package/dist/core/client.d.ts +682 -0
- package/dist/core/client.test.d.ts +1 -0
- package/dist/core/platform-client.d.ts +106 -0
- package/dist/core/platform-client.test.d.ts +1 -0
- package/dist/core/request-error.d.ts +25 -0
- package/dist/core/request-error.test.d.ts +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.es.js +3310 -0
- package/dist/types/base.d.ts +9 -0
- package/dist/types/context.d.ts +20 -0
- package/dist/types/execution.d.ts +19 -0
- package/dist/types/files.d.ts +19 -0
- package/dist/types/item.dto.d.ts +24 -0
- package/dist/types/items.d.ts +57 -0
- package/dist/types/projects.d.ts +59 -0
- package/dist/types/response.d.ts +10 -0
- package/dist/types/storage.d.ts +11 -0
- package/dist/vite-env.d.ts +1 -0
- package/package.json +100 -0
- package/src/built-in/index.ts +755 -0
- package/src/cli/templates/bim/CONTEXT.md +244 -0
- package/src/cli/templates/bim/package.json +26 -0
- package/src/cli/templates/bim/src/app.ts +16 -0
- package/src/cli/templates/bim/src/bim-components/CloudRunner/index.ts +91 -0
- package/src/cli/templates/bim/src/bim-components/CloudRunner/src/index.ts +1 -0
- package/src/cli/templates/bim/src/bim-components/CloudRunner/src/types.ts +5 -0
- package/src/cli/templates/bim/src/bim-components/index.ts +1 -0
- package/src/cli/templates/bim/src/globals.ts +1 -0
- package/src/cli/templates/bim/src/main.ts +90 -0
- package/src/cli/templates/bim/src/setups/cloud-runner.ts +13 -0
- package/src/cli/templates/bim/src/setups/index.ts +3 -0
- package/src/cli/templates/bim/src/setups/ui-manager.ts +27 -0
- package/src/cli/templates/bim/src/setups/viewports-manager.ts +22 -0
- package/src/cli/templates/bim/src/ui-components/app-info-section/index.ts +26 -0
- package/src/cli/templates/bim/src/ui-components/app-info-section/src/index.ts +1 -0
- package/src/cli/templates/bim/src/ui-components/app-info-section/src/types.ts +15 -0
- package/src/cli/templates/bim/src/ui-components/cloud-runner-section/index.ts +37 -0
- package/src/cli/templates/bim/src/ui-components/cloud-runner-section/src/index.ts +1 -0
- package/src/cli/templates/bim/src/ui-components/cloud-runner-section/src/types.ts +14 -0
- package/src/cli/templates/bim/src/ui-components/index.ts +2 -0
- package/src/cli/templates/cloud/CONTEXT.md +205 -0
- package/src/cli/templates/cloud/_thatopen +5 -0
- package/src/cli/templates/cloud/declarations.json +4 -0
- package/src/cli/templates/cloud/package.json +22 -0
- package/src/cli/templates/cloud/src/main.ts +70 -0
- package/src/cli/templates/cloud-test/CONTEXT.md +56 -0
- package/src/cli/templates/cloud-test/_thatopen +5 -0
- package/src/cli/templates/cloud-test/package.json +22 -0
- package/src/cli/templates/cloud-test/src/main.ts +565 -0
- package/src/cli/templates/default/CONTEXT.md +92 -0
- package/src/cli/templates/default/package.json +15 -0
- package/src/cli/templates/default/src/main.ts +62 -0
- package/src/cli/templates/shared/_gitignore +4 -0
- package/src/cli/templates/shared/app/index.html +27 -0
- package/src/cli/templates/shared/app/tsconfig.json +16 -0
- package/src/cli/templates/shared/app/vite.config.js +23 -0
- package/src/cli/templates/shared/cloud/tsconfig.json +16 -0
- package/src/cli/templates/shared/cloud/vite.config.js +27 -0
- package/src/cli/templates/test/CONTEXT.md +53 -0
- package/src/cli/templates/test/package.json +25 -0
- package/src/cli/templates/test/src/main.ts +955 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# ThatOpen BIM App
|
|
2
|
+
|
|
3
|
+
This is a BIM (Building Information Modeling) app built for the That Open Platform.
|
|
4
|
+
It runs in the browser inside the platform's iframe and has access to a 3D viewer,
|
|
5
|
+
UI components, and the platform API.
|
|
6
|
+
|
|
7
|
+
## How this app works
|
|
8
|
+
|
|
9
|
+
- **Entry point**: `src/main.ts` — runs as an IIFE when the platform loads the app.
|
|
10
|
+
- **Build output**: `dist/bundle.js` — a single IIFE file built by Vite.
|
|
11
|
+
- **Platform context**: The platform injects `window.__THATOPEN_CONTEXT__` with:
|
|
12
|
+
- `appId` — this app's unique ID
|
|
13
|
+
- `projectId` — the project this app belongs to
|
|
14
|
+
- `accessToken` — Auth0 JWT for API calls
|
|
15
|
+
- `apiUrl` — base URL for the That Open API
|
|
16
|
+
|
|
17
|
+
## Commands
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm run dev # Start dev server (esbuild watch + serve on :4000)
|
|
21
|
+
npm run build # Build dist/bundle.js (Vite/Rollup production build)
|
|
22
|
+
npm run login # Authenticate with the platform (saves token locally)
|
|
23
|
+
npm run publish # Publish to the platform
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Local development
|
|
27
|
+
|
|
28
|
+
Apps run inside the That Open Platform (platform.thatopen.com) within a project —
|
|
29
|
+
not as standalone websites. To develop locally:
|
|
30
|
+
|
|
31
|
+
1. Run `npm run dev` — this watches source files with esbuild and serves the bundle on port 4000.
|
|
32
|
+
2. Open your project on the platform and click the debug button.
|
|
33
|
+
3. Live reload is enabled — save a file to rebuild automatically.
|
|
34
|
+
|
|
35
|
+
The dev server (`thatopen serve`) uses esbuild for near-instant incremental rebuilds.
|
|
36
|
+
**Important**: Do NOT run `vite`, `vite build --watch`, or `npx vite` directly for development.
|
|
37
|
+
Always use `npm run dev` which runs `thatopen serve` under the hood.
|
|
38
|
+
|
|
39
|
+
## Key libraries
|
|
40
|
+
|
|
41
|
+
| Package | Import | Purpose |
|
|
42
|
+
|---------|--------|---------|
|
|
43
|
+
| `@thatopen/components` | `OBC` | BIM engine — components, fragments, worlds |
|
|
44
|
+
| `@thatopen/components-front` | `OBF` | Front-end BIM components (Highlighter, measurements, etc.) |
|
|
45
|
+
| `@thatopen/fragments` | `FRAGS` | Fragment geometry format |
|
|
46
|
+
| `@thatopen/ui` | `BUI` | UI web components (`<bim-panel>`, `<bim-grid>`, etc.) |
|
|
47
|
+
| `@thatopen/ui-obc` | `CUI` | Pre-built OBC UI tables (used by ModelsPanel) |
|
|
48
|
+
| `three` | `THREE` | 3D rendering engine |
|
|
49
|
+
| `thatopen-services` | `EngineServicesClient` | Platform API client + built-in components |
|
|
50
|
+
|
|
51
|
+
## Architecture pattern
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
1. Create EngineServicesClient from platform context
|
|
55
|
+
2. Call client.setup(globals, ...builtIns) — creates OBC.Components,
|
|
56
|
+
inits BUI, loads built-in components, calls components.init()
|
|
57
|
+
3. Create viewport(s) and UI elements
|
|
58
|
+
4. Configure AppManager with elements + layouts
|
|
59
|
+
5. Call app.init()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Built-in components
|
|
63
|
+
|
|
64
|
+
Built-in components are platform-hosted UI modules loaded at runtime via the API client.
|
|
65
|
+
They are fetched, evaluated, and registered with the OBC component system.
|
|
66
|
+
|
|
67
|
+
| Component | Purpose |
|
|
68
|
+
|-----------|---------|
|
|
69
|
+
| **AppManager** | App shell — CSS grid layout system with sidebar for switching layouts |
|
|
70
|
+
| **ViewportsManager** | Factory for 3D viewports with pre-configured world (scene, camera, renderer) |
|
|
71
|
+
| **LoadModelButton** | Button + dropdown for loading IFC and Fragments files |
|
|
72
|
+
| **ViewerToolbar** | Toolbar with Show/Hide/Focus/Isolate actions and color palette |
|
|
73
|
+
| **ModelsPanel** | Panel listing loaded models with search bar and load button |
|
|
74
|
+
| **ModelsDropdown** | Dropdown selector listing loaded models |
|
|
75
|
+
| **ClassificationsList** | Hierarchical table of IFC classification data |
|
|
76
|
+
| **ClashesList** | Interactive clash detection results with click-to-highlight |
|
|
77
|
+
| **ClippingsList** | Panel listing clipping planes with enable/delete controls |
|
|
78
|
+
| **LengthMeasuringsList** | Panel listing length measurements with cumulative total |
|
|
79
|
+
| **AreaMeasuringsList** | Panel listing area measurements with area/perimeter totals |
|
|
80
|
+
| **ColorsPalette** | Color picker grid with custom input and Highlighter styles |
|
|
81
|
+
| **HighlightersList** | Panel listing Highlighter styles with manage/apply actions |
|
|
82
|
+
| **QtoComparisonList** | Side-by-side quantity comparison for two selected elements |
|
|
83
|
+
| **QueriesHierarchy** | Recursive multi-level query browser for IFC data |
|
|
84
|
+
| **CustomViewLegend** | Color legend overlay with colored circles and labels |
|
|
85
|
+
| **ScreenshotAnnotator** | Modal for annotating screenshots (arrows, text, freehand) via MarkerJS |
|
|
86
|
+
|
|
87
|
+
**Full API reference**: Each component has detailed JSDoc with `@example` blocks in the
|
|
88
|
+
`thatopen-services` package source (`src/built-in/index.ts`). Read that file for config
|
|
89
|
+
interfaces, method signatures, and code examples.
|
|
90
|
+
|
|
91
|
+
### Loading pattern
|
|
92
|
+
|
|
93
|
+
Use `setup` to create the component system and load built-in components in one call:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { PlatformClient, AppManager, ViewportsManager } from "thatopen-services";
|
|
97
|
+
|
|
98
|
+
const client = PlatformClient.fromPlatformContext();
|
|
99
|
+
|
|
100
|
+
// Creates OBC.Components, inits BUI, loads built-ins, calls components.init()
|
|
101
|
+
const { components } = await client.setup(
|
|
102
|
+
{ OBC, OBF, BUI, CUI, THREE, FRAGS },
|
|
103
|
+
AppManager, ViewportsManager,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const app = components.get(AppManager);
|
|
107
|
+
const viewports = components.get(ViewportsManager);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
You can also load components individually if needed:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
// Batch load (parallel)
|
|
114
|
+
await client.initBuiltInComponents(components, AppManager, ViewportsManager);
|
|
115
|
+
|
|
116
|
+
// Or one at a time
|
|
117
|
+
await client.initBuiltInComponent(AppManager, components);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Required globals per component
|
|
121
|
+
|
|
122
|
+
| Component | Globals to pass | Extra npm packages needed |
|
|
123
|
+
|-----------|----------------|--------------------------|
|
|
124
|
+
| AppManager | `{ OBC, BUI }` | — |
|
|
125
|
+
| ViewportsManager | `{ OBC, BUI, THREE, FRAGS }` | — |
|
|
126
|
+
| LoadModelButton | `{ OBC, BUI }` | — |
|
|
127
|
+
| ModelsDropdown | `{ OBC, BUI }` | — |
|
|
128
|
+
| ModelsPanel | `{ OBC, BUI, CUI }` | `@thatopen/ui-obc` |
|
|
129
|
+
| ViewerToolbar | `{ OBC, OBF, BUI, THREE }` | `@thatopen/components-front` |
|
|
130
|
+
| ColorsPalette | `{ OBC, OBF, BUI }` | `@thatopen/components-front` |
|
|
131
|
+
| ClashesList | `{ OBC, OBF, BUI, THREE }` | `@thatopen/components-front` |
|
|
132
|
+
| ClassificationsList | `{ OBC, OBF, BUI }` | `@thatopen/components-front` |
|
|
133
|
+
| ClippingsList | `{ OBC, BUI }` | — |
|
|
134
|
+
| HighlightersList | `{ OBC, OBF, BUI }` | `@thatopen/components-front` |
|
|
135
|
+
| LengthMeasuringsList | `{ OBC, OBF, BUI, THREE }` | `@thatopen/components-front` |
|
|
136
|
+
| AreaMeasuringsList | `{ OBC, OBF, BUI, THREE }` | `@thatopen/components-front` |
|
|
137
|
+
| QtoComparisonList | `{ OBC, OBF, BUI }` | `@thatopen/components-front` |
|
|
138
|
+
| QueriesHierarchy | `{ OBC, OBF, BUI }` | `@thatopen/components-front` |
|
|
139
|
+
| CustomViewLegend | `{ OBC, BUI }` | — |
|
|
140
|
+
| ScreenshotAnnotator | `{ OBC, BUI, MARKERJS }` | `@markerjs/markerjs3` |
|
|
141
|
+
|
|
142
|
+
### Global abbreviations
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import * as OBC from "@thatopen/components";
|
|
146
|
+
import * as OBF from "@thatopen/components-front"; // needed for Toolbar, Highlighters, Clashes, etc.
|
|
147
|
+
import * as BUI from "@thatopen/ui";
|
|
148
|
+
import * as CUI from "@thatopen/ui-obc"; // needed for ModelsPanel
|
|
149
|
+
import * as THREE from "three";
|
|
150
|
+
import * as FRAGS from "@thatopen/fragments";
|
|
151
|
+
import * as MARKERJS from "@markerjs/markerjs3"; // needed for ScreenshotAnnotator
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### AppManager — app shell with CSS grid layouts
|
|
155
|
+
|
|
156
|
+
Creates a grid-based layout system. Define named element slots and named layouts.
|
|
157
|
+
A sidebar for switching layouts appears automatically when multiple layouts exist.
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
const Layouts = ["Viewer", "Split"];
|
|
161
|
+
const Elements = ["viewer", "panel"];
|
|
162
|
+
|
|
163
|
+
await app.init({
|
|
164
|
+
client,
|
|
165
|
+
icons: undefined, // pass Record<K, string> when using typed App interface with icon keys
|
|
166
|
+
grid: (grid: BUI.Grid<Layouts, Elements>) => {
|
|
167
|
+
grid.elements = {
|
|
168
|
+
viewer: viewportElement,
|
|
169
|
+
panel: panelFunction, // Can be HTMLElement, () => BUI.TemplateResult, or { template, initialState }
|
|
170
|
+
};
|
|
171
|
+
grid.layouts = {
|
|
172
|
+
Viewer: { template: `"viewer" 1fr / 1fr` },
|
|
173
|
+
Split: {
|
|
174
|
+
template: `"panel viewer" 1fr / 20rem 1fr`,
|
|
175
|
+
icon: "solar:settings-bold",
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The `template` string uses CSS `grid-template` shorthand: `"areas" rows / columns`.
|
|
183
|
+
|
|
184
|
+
### ViewportsManager — 3D viewport factory
|
|
185
|
+
|
|
186
|
+
Creates viewports with pre-configured world (scene, camera, renderer) and auto-initialized fragments.
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
const viewports = components.get(ViewportsManager);
|
|
190
|
+
const { element, world } = await viewports.create();
|
|
191
|
+
// element is an HTMLElement to place in a layout slot
|
|
192
|
+
// world has world.scene, world.camera, world.renderer
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Loading a BIM model
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
const fragments = components.get(OBC.FragmentsManager);
|
|
199
|
+
|
|
200
|
+
// From URL
|
|
201
|
+
const response = await fetch("https://example.com/model.frag");
|
|
202
|
+
const buffer = await response.arrayBuffer();
|
|
203
|
+
await fragments.core.load(buffer, { modelId: "my-model" });
|
|
204
|
+
|
|
205
|
+
// From platform storage
|
|
206
|
+
const fileResponse = await client.downloadFile(fileId);
|
|
207
|
+
const fileBuffer = await fileResponse.arrayBuffer();
|
|
208
|
+
await fragments.core.load(fileBuffer, { modelId: "my-model" });
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## EngineServicesClient API (commonly used in apps)
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
// Recommended: auto-reads window.__THATOPEN_CONTEXT__ and sets useBearer: true
|
|
215
|
+
const client = PlatformClient.fromPlatformContext();
|
|
216
|
+
console.log(client.context.projectId); // access the platform context
|
|
217
|
+
|
|
218
|
+
// Files
|
|
219
|
+
const files = await client.listFiles();
|
|
220
|
+
const file = await client.getFile(fileId);
|
|
221
|
+
const response = await client.downloadFile(fileId);
|
|
222
|
+
await client.createFile({ file: blob, name: "model.ifc", versionTag: "v1" });
|
|
223
|
+
|
|
224
|
+
// Folders
|
|
225
|
+
const folders = await client.listFolders();
|
|
226
|
+
await client.createFolder("My Folder");
|
|
227
|
+
|
|
228
|
+
// Execute cloud components
|
|
229
|
+
const { executionId } = await client.executeComponent(componentId, { param: "value" });
|
|
230
|
+
client.onExecutionProgress(executionId, (data) => {
|
|
231
|
+
// data.progressUpdate — progress percentage
|
|
232
|
+
// data.messageUpdate — status messages
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Test against a local cloud component (requires thatopen local-server running in the component project)
|
|
236
|
+
client.localServerUrl = "http://localhost:4001";
|
|
237
|
+
const local = await client.executeComponent("any-id", { param: "value" });
|
|
238
|
+
client.localServerUrl = null; // reset to use the cloud API
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Configuration
|
|
242
|
+
|
|
243
|
+
- `.thatopen` — local config (gitignored). Created by `npm run login`. Contains `accessToken`, `apiUrl`, and `appId` after first publish.
|
|
244
|
+
- `vite.config.js` — builds to IIFE format as `dist/bundle.js`. All dependencies are bundled.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{PROJECT_NAME}}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "thatopen serve",
|
|
7
|
+
"build": "vite build",
|
|
8
|
+
"login": "thatopen login --local",
|
|
9
|
+
"publish": "thatopen publish"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@markerjs/markerjs3": "^3.9.0",
|
|
13
|
+
"@thatopen/components": "~3.4.0",
|
|
14
|
+
"@thatopen/components-front": "~3.4.0",
|
|
15
|
+
"@thatopen/fragments": "~3.4.0",
|
|
16
|
+
"@thatopen/ui": "~3.4.0",
|
|
17
|
+
"@thatopen/ui-obc": "~3.4.0",
|
|
18
|
+
"thatopen-services": "file:../../../..",
|
|
19
|
+
"three": "^0.182.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/three": "^0.182.0",
|
|
23
|
+
"typescript": "^5.2.0",
|
|
24
|
+
"vite": "^5.2.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as OBC from "@thatopen/components";
|
|
2
|
+
import * as BUI from "@thatopen/ui";
|
|
3
|
+
import { AppManager } from "thatopen-services";
|
|
4
|
+
import { icons } from "./globals";
|
|
5
|
+
import { AppInfoSectionGridElement, CloudRunnerSectionGridElement } from "./ui-components";
|
|
6
|
+
|
|
7
|
+
export type App = {
|
|
8
|
+
icons: (keyof typeof icons)[];
|
|
9
|
+
grid: BUI.Grid<
|
|
10
|
+
["Viewer", "Split"],
|
|
11
|
+
["viewer", AppInfoSectionGridElement, CloudRunnerSectionGridElement]
|
|
12
|
+
>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const getAppManager = (components: OBC.Components) =>
|
|
16
|
+
components.get(AppManager<App>);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as OBC from "@thatopen/components";
|
|
2
|
+
import { AppManager } from "thatopen-services";
|
|
3
|
+
import { CloudRunnerStatus } from "./src";
|
|
4
|
+
|
|
5
|
+
export class CloudRunner extends OBC.Component {
|
|
6
|
+
static readonly uuid = "7c4e5d3b-2a1f-4e8d-9b6c-0a3f7e2c5d1b" as const;
|
|
7
|
+
|
|
8
|
+
enabled = true;
|
|
9
|
+
|
|
10
|
+
readonly onExecutionUpdated = new OBC.Event<CloudRunnerStatus>();
|
|
11
|
+
|
|
12
|
+
// TODO: Replace with your actual component ID after publishing.
|
|
13
|
+
componentId = "your-component-id";
|
|
14
|
+
localServerUrl = "http://localhost:4001";
|
|
15
|
+
|
|
16
|
+
// Reactive state — read by the UI template on each render.
|
|
17
|
+
status = "Idle";
|
|
18
|
+
progress = 0;
|
|
19
|
+
messages: string[] = [];
|
|
20
|
+
|
|
21
|
+
constructor(components: OBC.Components) {
|
|
22
|
+
super(components);
|
|
23
|
+
components.add(CloudRunner.uuid, this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async run(useLocal: boolean) {
|
|
27
|
+
// Resolve client at call time via AppManager — never store it as a field.
|
|
28
|
+
const app = this.components.get(AppManager);
|
|
29
|
+
const client = app.client;
|
|
30
|
+
|
|
31
|
+
client.localServerUrl = useLocal ? this.localServerUrl : null;
|
|
32
|
+
|
|
33
|
+
this.status = useLocal ? "Starting (local)..." : "Starting (deployed)...";
|
|
34
|
+
this.progress = 0;
|
|
35
|
+
this.messages = [];
|
|
36
|
+
this._trigger();
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const { executionId } = await client.executeComponent(this.componentId, {
|
|
40
|
+
greeting: "Hello from the BIM app!",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
this.status = `Running (${executionId.slice(0, 8)}...)`;
|
|
44
|
+
this._trigger();
|
|
45
|
+
|
|
46
|
+
// Subscribe to real-time progress updates via WebSocket.
|
|
47
|
+
client.onExecutionProgress(executionId, (data) => {
|
|
48
|
+
if (data.progressUpdate) {
|
|
49
|
+
this.progress = data.progressUpdate.progress;
|
|
50
|
+
if (data.progressUpdate.result) {
|
|
51
|
+
this.status = `${data.progressUpdate.result}: ${data.progressUpdate.resultMessage ?? "Done"}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (data.messageUpdate) {
|
|
55
|
+
this.messages.push(data.messageUpdate.content);
|
|
56
|
+
}
|
|
57
|
+
this._trigger();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Poll once after a short delay to catch fast executions that complete
|
|
61
|
+
// before the WebSocket subscription is established.
|
|
62
|
+
setTimeout(async () => {
|
|
63
|
+
try {
|
|
64
|
+
const exec = await client.getExecution(executionId);
|
|
65
|
+
if (exec.result) {
|
|
66
|
+
this.progress = exec.progress;
|
|
67
|
+
this.status = `${exec.result}: ${exec.resultMessage ?? "Done"}`;
|
|
68
|
+
this._trigger();
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
/* WebSocket handles it */
|
|
72
|
+
}
|
|
73
|
+
}, 2000);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
this.status = `Error: ${err}`;
|
|
76
|
+
this._trigger();
|
|
77
|
+
} finally {
|
|
78
|
+
client.localServerUrl = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private _trigger() {
|
|
83
|
+
this.onExecutionUpdated.trigger({
|
|
84
|
+
status: this.status,
|
|
85
|
+
progress: this.progress,
|
|
86
|
+
messages: [...this.messages],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export * from "./src";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./CloudRunner";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const icons = {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import * as OBC from "@thatopen/components";
|
|
3
|
+
import * as OBF from "@thatopen/components-front";
|
|
4
|
+
import * as FRAGS from "@thatopen/fragments";
|
|
5
|
+
import * as BUI from "@thatopen/ui";
|
|
6
|
+
import * as CUI from "@thatopen/ui-obc";
|
|
7
|
+
import * as MARKERJS from "@markerjs/markerjs3"
|
|
8
|
+
import {
|
|
9
|
+
PlatformClient,
|
|
10
|
+
AppManager,
|
|
11
|
+
ViewportsManager,
|
|
12
|
+
UIManager,
|
|
13
|
+
} from "thatopen-services";
|
|
14
|
+
|
|
15
|
+
import { getAppManager } from "./app";
|
|
16
|
+
import { uiManager, cloudRunner, viewportsManager, getUIManager } from "./setups";
|
|
17
|
+
|
|
18
|
+
// Wrap in async function since IIFE format does not support top-level await.
|
|
19
|
+
async function main() {
|
|
20
|
+
// ─── Platform Client ──────────────────────────────────────────
|
|
21
|
+
// Reads auth context from window.__THATOPEN_CONTEXT__ (injected by the
|
|
22
|
+
// platform) and creates a client with Bearer auth.
|
|
23
|
+
const client = PlatformClient.fromPlatformContext();
|
|
24
|
+
|
|
25
|
+
// ─── Built-in Components ──────────────────────────────────────
|
|
26
|
+
// First argument: library globals used by the engine.
|
|
27
|
+
// Subsequent arguments: platform built-in components to initialise.
|
|
28
|
+
const { components } = await client.setup<OBC.Components>(
|
|
29
|
+
{ OBC, OBF, BUI, CUI, THREE, FRAGS, MARKERJS },
|
|
30
|
+
{ uuid: ViewportsManager.uuid },
|
|
31
|
+
{ uuid: AppManager.uuid },
|
|
32
|
+
{ uuid: UIManager.uuid },
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// ─── Viewport ─────────────────────────────────────────────────
|
|
36
|
+
// Must run before app.init() so the element is ready for the grid.
|
|
37
|
+
const viewerElement = await viewportsManager(components);
|
|
38
|
+
|
|
39
|
+
// ─── App Init ─────────────────────────────────────────────────
|
|
40
|
+
const app = getAppManager(components);
|
|
41
|
+
|
|
42
|
+
await app.init({
|
|
43
|
+
client,
|
|
44
|
+
icons: [],
|
|
45
|
+
componentSetups: {
|
|
46
|
+
// core: runs in parallel before the grid mounts.
|
|
47
|
+
core: [uiManager, cloudRunner],
|
|
48
|
+
},
|
|
49
|
+
grid: (grid) => {
|
|
50
|
+
const uis = getUIManager(components);
|
|
51
|
+
|
|
52
|
+
grid.elements = {
|
|
53
|
+
viewer: viewerElement,
|
|
54
|
+
appInfoSection: {
|
|
55
|
+
template: uis.custom.get("appInfoSection").template,
|
|
56
|
+
initialState: { components },
|
|
57
|
+
label: "App Info",
|
|
58
|
+
icon: "solar:info-circle-bold",
|
|
59
|
+
},
|
|
60
|
+
cloudRunnerSection: {
|
|
61
|
+
template: uis.custom.get("cloudRunnerSection").template,
|
|
62
|
+
initialState: { components },
|
|
63
|
+
label: "Cloud Component",
|
|
64
|
+
icon: "solar:code-bold",
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
grid.layouts = {
|
|
69
|
+
Viewer: {
|
|
70
|
+
template: `"viewer" 1fr / 1fr`,
|
|
71
|
+
},
|
|
72
|
+
Split: {
|
|
73
|
+
template: `
|
|
74
|
+
"tabs:left(appInfoSection, cloudRunnerSection) viewer" 1fr
|
|
75
|
+
/ 24rem 1fr
|
|
76
|
+
`,
|
|
77
|
+
icon: "solar:info-circle-bold",
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
grid.areaGroups = {
|
|
82
|
+
left: { switchersFull: true },
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
grid.layout = "Split";
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as OBC from "@thatopen/components";
|
|
2
|
+
import { CloudRunner } from "../bim-components";
|
|
3
|
+
import { getUIManager } from "./ui-manager";
|
|
4
|
+
|
|
5
|
+
export const cloudRunner = (components: OBC.Components) => {
|
|
6
|
+
const runner = components.get(CloudRunner);
|
|
7
|
+
const uis = getUIManager(components);
|
|
8
|
+
|
|
9
|
+
// Re-render all appInfoSection instances whenever execution state changes.
|
|
10
|
+
runner.onExecutionUpdated.add(() => {
|
|
11
|
+
uis.custom.get("cloudRunnerSection").updateInstances();
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as OBC from "@thatopen/components";
|
|
2
|
+
import * as BUI from "@thatopen/ui";
|
|
3
|
+
import { UIManager } from "thatopen-services";
|
|
4
|
+
import {
|
|
5
|
+
appInfoSectionTemplate,
|
|
6
|
+
AppInfoSectionState,
|
|
7
|
+
cloudRunnerSectionTemplate,
|
|
8
|
+
CloudRunnerSectionState,
|
|
9
|
+
} from "../ui-components";
|
|
10
|
+
|
|
11
|
+
export type CustomUIs = {
|
|
12
|
+
appInfoSection: { type: BUI.PanelSection; state: AppInfoSectionState };
|
|
13
|
+
cloudRunnerSection: { type: BUI.PanelSection; state: CloudRunnerSectionState };
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const getUIManager = (components: OBC.Components) =>
|
|
17
|
+
components.get(UIManager<CustomUIs>);
|
|
18
|
+
|
|
19
|
+
export const uiManager = (components: OBC.Components) => {
|
|
20
|
+
const uis = getUIManager(components);
|
|
21
|
+
uis.registerTemplate("appInfoSection", {
|
|
22
|
+
template: appInfoSectionTemplate,
|
|
23
|
+
});
|
|
24
|
+
uis.registerTemplate("cloudRunnerSection", {
|
|
25
|
+
template: cloudRunnerSectionTemplate,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as OBC from "@thatopen/components";
|
|
2
|
+
import { ViewportsManager } from "thatopen-services";
|
|
3
|
+
|
|
4
|
+
export const viewportsManager = async (components: OBC.Components) => {
|
|
5
|
+
const viewports = components.get(ViewportsManager);
|
|
6
|
+
const { element, world } = await viewports.create();
|
|
7
|
+
|
|
8
|
+
// Load a sample model. Replace with client.downloadFile(fileId) to load
|
|
9
|
+
// a model from the platform:
|
|
10
|
+
// const response = await client.downloadFile(fileId);
|
|
11
|
+
// const buffer = await response.arrayBuffer();
|
|
12
|
+
const fragments = components.get(OBC.FragmentsManager);
|
|
13
|
+
const file = await fetch(
|
|
14
|
+
"https://thatopen.github.io/engine_components/resources/frags/school_arq.frag",
|
|
15
|
+
);
|
|
16
|
+
const buffer = await file.arrayBuffer();
|
|
17
|
+
await fragments.core.load(buffer, { modelId: "school_arq" });
|
|
18
|
+
await world.camera.controls.setLookAt(68, 23, -8.5, 21.5, -5.5, 23);
|
|
19
|
+
await fragments.core.update(true);
|
|
20
|
+
|
|
21
|
+
return element;
|
|
22
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as BUI from "@thatopen/ui";
|
|
2
|
+
import { AppInfoSectionComponent } from "./src";
|
|
3
|
+
import { getAppManager } from "../../app";
|
|
4
|
+
|
|
5
|
+
export const appInfoSectionTemplate: AppInfoSectionComponent = ({
|
|
6
|
+
components,
|
|
7
|
+
}) => {
|
|
8
|
+
const app = getAppManager(components);
|
|
9
|
+
|
|
10
|
+
const fileItems =
|
|
11
|
+
app.projectData?.files.map(
|
|
12
|
+
(f: { name: string }) => BUI.html`<bim-label>${f.name}</bim-label>`,
|
|
13
|
+
) ?? [];
|
|
14
|
+
|
|
15
|
+
return BUI.html`
|
|
16
|
+
<bim-panel-section label="App Info" icon="solar:info-circle-bold">
|
|
17
|
+
<bim-label>App ID: ${app.client?.context.appId}</bim-label>
|
|
18
|
+
<bim-label>Project ID: ${app.client?.context.projectId}</bim-label>
|
|
19
|
+
<bim-label>API URL: ${app.client?.context.apiUrl}</bim-label>
|
|
20
|
+
<bim-label>Files: ${fileItems.length}</bim-label>
|
|
21
|
+
${fileItems}
|
|
22
|
+
</bim-panel-section>
|
|
23
|
+
`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export * from "./src";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as BUI from "@thatopen/ui";
|
|
2
|
+
import * as OBC from "@thatopen/components";
|
|
3
|
+
|
|
4
|
+
export interface AppInfoSectionState {
|
|
5
|
+
components: OBC.Components;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type AppInfoSectionComponent =
|
|
9
|
+
BUI.StatefullComponent<AppInfoSectionState>;
|
|
10
|
+
|
|
11
|
+
// Used in App type (app.ts) to type this element slot in the grid.
|
|
12
|
+
export type AppInfoSectionGridElement = {
|
|
13
|
+
name: "appInfoSection";
|
|
14
|
+
state: AppInfoSectionState;
|
|
15
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as BUI from "@thatopen/ui";
|
|
2
|
+
import { CloudRunner } from "../../bim-components";
|
|
3
|
+
import { CloudRunnerSectionComponent } from "./src";
|
|
4
|
+
|
|
5
|
+
export const cloudRunnerSectionTemplate: CloudRunnerSectionComponent = ({
|
|
6
|
+
components,
|
|
7
|
+
}) => {
|
|
8
|
+
const runner = components.get(CloudRunner);
|
|
9
|
+
|
|
10
|
+
const messageItems = runner.messages.map(
|
|
11
|
+
(m) => BUI.html`<bim-label>${m}</bim-label>`,
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return BUI.html`
|
|
15
|
+
<bim-panel-section label="Cloud Component" icon="solar:code-bold">
|
|
16
|
+
<bim-label>Component ID: ${runner.componentId}</bim-label>
|
|
17
|
+
<bim-label>Local server: ${runner.localServerUrl}</bim-label>
|
|
18
|
+
<div style="display:flex;gap:0.5rem;">
|
|
19
|
+
<bim-button
|
|
20
|
+
label="Run Local"
|
|
21
|
+
icon="solar:play-bold"
|
|
22
|
+
@click=${() => runner.run(true)}
|
|
23
|
+
></bim-button>
|
|
24
|
+
<bim-button
|
|
25
|
+
label="Run Deployed"
|
|
26
|
+
icon="solar:cloud-bold-duotone"
|
|
27
|
+
@click=${() => runner.run(false)}
|
|
28
|
+
></bim-button>
|
|
29
|
+
</div>
|
|
30
|
+
<bim-label>${runner.status}</bim-label>
|
|
31
|
+
<bim-label>Progress: ${runner.progress}%</bim-label>
|
|
32
|
+
${messageItems}
|
|
33
|
+
</bim-panel-section>
|
|
34
|
+
`;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export * from "./src";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as OBC from "@thatopen/components";
|
|
2
|
+
import * as BUI from "@thatopen/ui";
|
|
3
|
+
|
|
4
|
+
export interface CloudRunnerSectionState {
|
|
5
|
+
components: OBC.Components;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type CloudRunnerSectionComponent =
|
|
9
|
+
BUI.StatefullComponent<CloudRunnerSectionState>;
|
|
10
|
+
|
|
11
|
+
export type CloudRunnerSectionGridElement = {
|
|
12
|
+
name: "cloudRunnerSection";
|
|
13
|
+
state: CloudRunnerSectionState;
|
|
14
|
+
};
|