Skip to content

Commit de7bd5e

Browse files
plardinCopilot
andauthored
[BM-3505] Adds novolib bim viewer sdk documentation. (#300)
* Adds novolib bim viewer sdk documentation. * Addreses CR feedback on novolib bim viewer sdk documentation. * Update example apps and sdks/bim_webviewer/novolib_bim_web_viewer.md Co-authored-by: Copilot <[email protected]> * Adds navigation changes, tweaks to the novorender API doc and addition of a .ruby-version file at the root level of the repo pointing at v3.1.3 * Removes Legacy and adds Experiment for our BIM viewers. --------- Co-authored-by: Copilot <[email protected]>
1 parent a3d65cf commit de7bd5e

File tree

3 files changed

+334
-2
lines changed

3 files changed

+334
-2
lines changed

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.1.3

_data/navigation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@
227227
url: /sdk
228228
- title: Procore Iframe Helper
229229
url: /procore-iframe-helper
230-
# - title: BIM Web Viewer
231-
# items:
232230
- title: BIM Web Viewer API
233231
url: /bim-web-viewer
234232
- title: BIM Web Viewer Demo
235233
url: /bim-web-viewer-demo
234+
- title: Novorender BIM Web Viewer API (Experimental)
235+
url: /novolib-bim-web-viewer
236236

237237
# - title: ERP Integration - EVERYTHING NEEDED BUT NOT INDEXED
238238
# items:
Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
---
2+
permalink: /novolib-bim-web-viewer
3+
title: 'Novorender BIM Web Viewer API (Experimental)'
4+
layout: default
5+
section_title: Example Apps & SDKs
6+
---
7+
8+
<!-- markdownlint-disable no-inline-html -->
9+
10+
## Getting started
11+
12+
<p class="heading-link-container"><a class="heading-link" href="#getting-started"></a></p>
13+
14+
### Installation from NPM (recommended)
15+
16+
<p class="heading-link-container"><a class="heading-link" href="#installation-from-npm-recommended"></a></p>
17+
18+
![npm version](https://img.shields.io/npm/v/@procore/novolib-pilot?color=%23f47e42)
19+
20+
The Novolib BIM Web Viewer is available as a module on `artifactory` as [`@procore/novolib-pilot`](https://artifacts.procoretech.com/ui/packages/npm:%2F%2F@procore%2Fnovolib-pilot).
21+
22+
To install it, open a terminal window in your project folder and run:
23+
24+
```sh
25+
npm install @procore/novolib-pilot
26+
```
27+
28+
## API Introduction
29+
30+
<p class="heading-link-container"><a class="heading-link" href="#api-introduction"></a></p>
31+
32+
When the Webviewer SDK is loaded and parsed on your page, a new global object of type `WebViewer` is added to your window, with the key `viewer`.
33+
The WebViewer class exposes the public SDK and its functions. The functions are grouped into namespaces to indicate primary functionality.
34+
35+
### Webviewer Namespaces
36+
37+
<p class="heading-link-container"><a class="heading-link" href="#webviewer-namespaces"></a></p>
38+
39+
| Namespace | Description |
40+
|-----------|-------------------------------------------------------------------------|
41+
| <_none_> | **Core functions** of the SDK, not related to a particular namespace |
42+
| model | Webviewer model data retrieval and manipulation [Model Namespace](#model-namespace) |
43+
| camera | Webviewer camera retrieval and manipulation [Camera Namespace](#camera-namespace) |
44+
| gui | Webviewer GUI manipulation [GUI Namespace](#gui-namespace) |
45+
46+
---
47+
48+
## The Core Functions
49+
50+
### <u>`Webviewer(container: HTMLElement, initOptions?: InitOptions)`</u>
51+
Creates a new WebViewer instance and attaches it to the specified container element.
52+
53+
This constructor initializes the WebViewer with the provided options, sets up the rendering root, and patches the Mirage fetch if needed. The `initOptions` parameter allows you to specify authentication, scene ID, and beta feature flags.
54+
55+
**Parameters:**
56+
- `container: HTMLElement` — The DOM element to mount the WebViewer into.
57+
- `initOptions?: InitOptions` — Optional configuration for authentication, scene ID, and beta features.
58+
59+
**Example:**
60+
```typescript
61+
const container = document.getElementById("webviewer-container");
62+
const webviewer = new Webviewer(container, { auth, sceneId, enableBetaFeatures });
63+
```
64+
65+
**Throws:** None
66+
67+
---
68+
69+
### `start()`
70+
Initializes and starts the WebViewer instance.
71+
72+
This function must be called before interacting with the viewer or any of its namespaces. It sets up all necessary resources and event listeners required for the viewer to function.
73+
74+
**Returns:** `void`
75+
76+
**Example:**
77+
```typescript
78+
const container = document.createElement("div");
79+
container.style.width = "100vw";
80+
container.style.height = "100vh";
81+
document.body.appendChild(container);
82+
const webviewer = new Webviewer(container);
83+
webviewer.start();
84+
```
85+
86+
**Throws:**
87+
- None
88+
89+
---
90+
91+
### `terminate()`
92+
Terminates the WebViewer instance and releases all resources.
93+
94+
This function should be called when the viewer is no longer needed, such as when navigating away from the page or destroying the component. It ensures that all event listeners and resources are properly cleaned up to prevent memory leaks.
95+
96+
**Returns:** `void`
97+
98+
**Example:**
99+
```typescript
100+
webviewer.terminate();
101+
```
102+
103+
**Throws:**
104+
- None
105+
106+
107+
---
108+
109+
## The `model` Namespace
110+
111+
### `getSelectedObjects()`
112+
Returns the IDs of the objects that are currently selected in the scene.
113+
114+
It checks the state of the selection and returns the array of IDs if available. If no objects are selected, it returns an empty array.
115+
116+
**Returns:** `ObjectId[]` — An array containing the IDs of the selected objects, or an empty array if none are selected.
117+
118+
**Example:**
119+
```typescript
120+
const selectedObjects = webviewer.model.getSelectedObjects();
121+
console.log(selectedObjects); // Logs the IDs of the selected objects.
122+
```
123+
124+
**Throws:** None
125+
126+
---
127+
128+
### `setXRayMode()`
129+
Changes the visibility of all objects to X-Ray mode, allowing for a transparent view of the objects in the scene.
130+
131+
This is particularly useful for inspecting objects that others may obscure or for visualizing the internal structure of complex objects.
132+
133+
**Returns:** `void`
134+
135+
**Example:**
136+
```typescript
137+
webviewer.model.setXRayMode();
138+
```
139+
140+
**Throws:** None — Will log a warning if the rendering mode is not set correctly.
141+
142+
---
143+
144+
### `setNormalMode()`
145+
Resets the visibility of all objects in the scene to their normal state.
146+
147+
It is particularly useful when you want to clear any special rendering effects applied to objects and return to the default view of the scene. It ensures that all objects are rendered with their standard appearance, without any transparency or special effects that may have been applied in other modes like X-Ray.
148+
149+
This function is typically used in scenarios where you want to switch back to a normal view after inspecting objects in a different rendering mode, such as X-Ray mode. It helps maintain a clear and standard view of the scene, making it easier to interact with the objects and understand their relationships in the 3D space.
150+
151+
**Returns:** `void`
152+
153+
**Example:**
154+
```typescript
155+
// Set the scene to normal mode
156+
webviewer.model.setNormalMode();
157+
```
158+
159+
**Throws:** None — Will log a warning if the rendering mode is not set correctly.
160+
161+
---
162+
163+
### `setObjectColor(paletteParams)`
164+
Sets the color override for the specified object IDs, based on palettes provided.
165+
166+
This function allows you to set custom colors for objects in the scene, which can be used for highlighting, categorization, or other visual distinctions. The `paletteParams` parameter should be an array of objects, each containing a palette and an array of object IDs. Each palette object can contain properties for default, x—ray, and selected colors, each with a color, and opacity.
167+
168+
**Parameters:**
169+
- `paletteParams: PaletteParams[]` — An array of objects containing color and object IDs.
170+
171+
The `PaletteParams` type has two attributes:
172+
- `palette: Palette` — An object containing color definitions.
173+
- `objectIds: ObjectId[]` — An array of object IDs to apply the color to.
174+
175+
The `Palette` type has the following properties:
176+
- `default?: Color` — The default color for the objects.
177+
- `xray?: Color` — The color for the objects in X-Ray mode.
178+
- `selected?: Color` — The color for the objects when selected.
179+
180+
The `Color` type has the following properties:
181+
- `color: string` — A hex color string that starts with `#`, followed by exactly 6 (six) hexadecimal digits (e.g., "#FF0000").
182+
- `opacity: number` — A number between 0 and 1 representing the opacity of the color, with 0 being fully transparent and 1 being completely opaque.
183+
184+
**Returns:** `void`
185+
186+
**Example:**
187+
```typescript
188+
const paletteParams = [{
189+
palette: {
190+
default: {color: "#FF0000", opacity: 0.75 },
191+
xray: { color: "#00FF00", opacity: 1 },
192+
selected: { color: "#0000FF", opacity: 1 }
193+
},
194+
objectIds: [1, 2, 3]
195+
}];
196+
webviewer.model.setObjectColor(paletteParams);
197+
```
198+
199+
**Throws:**
200+
- Error — If a palette contains an unknown key.
201+
- Error — If a palette's color hex string is malformed.
202+
- Error — If a palette's opacity is not in the proper range [0, 1].
203+
204+
---
205+
206+
### `clearObjectColor(objectIds)`
207+
Clears the color override for the specified object IDs.
208+
209+
This function allows you to remove any custom color overrides that have been applied to objects in the scene. It is useful when you want to revert objects to their default appearance or when you want to clear any temporary color changes made for highlighting or categorization purposes. The function takes an array of object IDs for which the color override should be cleared. It will remove the color overrides for those objects, allowing them to be rendered with their default colors or styles as defined in the scene configuration.
210+
211+
**Parameters:**
212+
- `objectIds: ObjectId[]` — An array of object IDs for which to clear the color override.
213+
214+
**Returns:** `void`
215+
216+
**Example:**
217+
```typescript
218+
const objectIds = [1, 2, 3];
219+
webviewer.model.clearObjectColor(objectIds);
220+
```
221+
222+
**Throws:** None
223+
224+
---
225+
226+
### `clearAllObjectColor()`
227+
Clears all color overrides for all objects in the scene.
228+
229+
This function is useful when you want to reset the visual appearance of all objects. It removes any custom color overrides that have been applied to objects, allowing them to revert to their default rendering state. This is particularly useful in scenarios where you want to start fresh with the scene's visual representation, such as when switching between different rendering modes or when clearing temporary visual effects.
230+
231+
**Returns:** `void`
232+
233+
**Example:**
234+
```typescript
235+
webviewer.model.clearAllObjectColor();
236+
```
237+
238+
**Throws:** None
239+
240+
---
241+
242+
## The `camera` Namespace
243+
244+
### `zoomToObjects(objectIds)`
245+
246+
This function calculates the bounding sphere of the objects and sets the camera to zoom to that sphere.
247+
248+
**Parameters:**
249+
- `objectIds: ObjectId[]` — An array of object IDs to zoom to.
250+
251+
**Returns:** `Promise<void>`
252+
253+
**Example:**
254+
```typescript
255+
const objectIds = [1, 2, 3];
256+
await webviewer.camera.zoomToObjects(objectIds);
257+
```
258+
259+
**Throws:**
260+
- Error — If the explorer globals or abort controller is not initialized.
261+
- Error — If the bounding sphere enclosing all the objects specified by ID could not be calculated.
262+
263+
---
264+
265+
### `navToHomeView()`
266+
Resets the camera to the initial view.
267+
268+
This function sets the camera to the initial position and rotation defined in the explorer globals. It is typically used to return the camera to a default view after navigating or interacting with the scene. The function uses the `resetView` function defined in the explorer globals to perform the reset. It is important to ensure that the `resetView` function is properly initialized before calling this method. If the `resetView` function is not available, it will throw an error.
269+
270+
**Returns:** `Promise<void>`
271+
272+
**Example:**
273+
```typescript
274+
await webviewer.camera.navToHomeView();
275+
```
276+
277+
**Throws:**
278+
- Error - If the `resetView` function is not initialized.
279+
280+
---
281+
282+
## The `gui` Namespace
283+
284+
### `addContextMenuItem({ label, id, onClick })`
285+
286+
This function allows you to add custom context menu items.
287+
288+
**Parameters:**
289+
- `label: string` — The label for the context menu item.
290+
- `id: string` — A unique ID for the context menu item.
291+
- `onClick: () => void` — A callback function to be executed when the context menu item is clicked.
292+
293+
**Returns:** `void`
294+
295+
**Example:**
296+
```typescript
297+
webviewer.gui.addContextMenuItem({
298+
label: "Custom Action",
299+
id: "custom-action",
300+
onClick: () => {
301+
console.log("Custom action clicked");
302+
},
303+
});
304+
```
305+
306+
**Throws:**
307+
- Error — If the viewer is not parameterized correctly
308+
- Error — If the viewer is not fully initialized yet
309+
310+
---
311+
312+
### `removeContextMenuItems({ contextMenuItemIds })`
313+
Removes context menu items from the Procore UX flavor.
314+
315+
This function allows you to remove custom context menu items in the Procore UX flavor.
316+
317+
**Parameters:**
318+
- `contextMenuItemIds: string[]` — An array of the context menu item IDs to be removed.
319+
320+
**Returns:** `void`
321+
322+
**Example:**
323+
```typescript
324+
webviewer.gui.removeContextMenuItems({ contextMenuItemIds: ["custom-action"] });
325+
```
326+
327+
**Throws:**
328+
- Error — If the viewer is not parameterized correctly
329+
- Error — If the viewer is not fully initialized yet
330+
331+
---

0 commit comments

Comments
 (0)