Skip to content

Commit d3b76d4

Browse files
committed
Create the scenes widget
1 parent 3682ba4 commit d3b76d4

13 files changed

Lines changed: 818 additions & 67 deletions

.env

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,3 @@ IMJS_AUTH_AUTHORITY="https://ims.bentley.com"
88
# ---- Test ids ----
99
IMJS_ITWIN_ID = ""
1010
IMJS_IMODEL_ID = ""
11-
12-
# Advanced CRA Config: https://create-react-app.dev/docs/advanced-configuration/
13-
SKIP_PREFLIGHT_CHECK=true
14-
15-
# # Advanced iTwin.js CRA Config: https://github.com/imodeljs/create-react-app/blob/imodeljs/packages/react-scripts/README-imodeljs.md
16-
# USE_FAST_SASS=true
17-
# USE_FULL_SOURCEMAP=true
18-
# TRANSPILE_DEPS=false
19-
# # Remove the following env var if using a different package manager
20-
# USING_NPM=true

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
registry=https://registry.npmjs.org/
12
@bentley:registry=https://registry.npmjs.org/
23
@itwin:registry=https://registry.npmjs.org/
34
legacy-peer-deps=true

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22

3-
Copyright © 2017-2021 Bentley Systems, Incorporated. All rights reserved.
3+
Copyright © Bentley Systems, Incorporated. All rights reserved.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

README.md

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,77 @@
1-
# Getting Started with the iTwin Viewer Template
1+
# iTwin Scenes Tutorial
22

3-
This project was scaffolded with [degit](https://github.com/Rich-Harris/degit).
3+
This repository contains the completed sample application for the [Working with iTwin Scenes in your Viewer Application](https://developer.bentley.com/tutorials/scenes-tutorial/) tutorial. The app demonstrates how to integrate the [Scenes API](https://developer.bentley.com/apis/scenes/) into an iTwin Viewer: listing scenes, creating a new scene that captures the current camera position, activating a scene to restore that camera position, and deleting a scene.
4+
5+
## Prerequisites
6+
7+
Before running this app, you should have:
8+
9+
- A registered application on the [iTwin Developer Portal](https://developer.bentley.com/register/) with the `itwin-platform` OAuth scope. This scope covers both the viewer and the Scenes API.
10+
- See [Register an application](https://developer.bentley.com/tutorials/web-application-quick-start/#3-register-an-application) for step-by-step instructions.
11+
- An iTwin with appropriate permissions to manage scenes.
12+
- An iModel to open in the viewer. The tutorial uses the "House Model" sample iModel.
13+
- See [Create a test iModel from a Bentley provided sample](https://developer.bentley.com/tutorials/create-test-imodel-sample/) for instructions.
414

515
## Environment Variables
616

7-
Prior to running the app, you will need to add OIDC client configuration to the variables in the .env file:
17+
Prior to running the app, add your OIDC client configuration to the variables in the `.env` file:
818

919
```
1020
# ---- Authorization Client Settings ----
1121
IMJS_AUTH_CLIENT_CLIENT_ID=""
1222
IMJS_AUTH_CLIENT_REDIRECT_URI=""
1323
IMJS_AUTH_CLIENT_LOGOUT_URI=""
14-
IMJS_AUTH_CLIENT_SCOPES=""
24+
IMJS_AUTH_CLIENT_SCOPES="itwin-platform"
1525
```
1626

17-
- You can generate a [test client](https://developer.bentley.com/tutorials/web-application-quick-start/#3-register-an-application) to get started.
18-
19-
- Viewer expects the `itwin-platform` scope to be set.
27+
- The `itwin-platform` scope is already set in `.env` and grants access to both the iModel viewer and the Scenes API.
28+
- The redirect URI must match exactly what is registered for your application.
2029

21-
- The application will use the path of the redirect URI to handle the redirection, it must simply match what is defined in your client.
22-
23-
- When you are ready to build a production application, [register here](https://developer.bentley.com/register/).
24-
25-
You should also add a valid iTwinId and iModelId for your user in the this file:
30+
You should also add a valid iTwinId and iModelId in the same file:
2631

2732
```
2833
# ---- Test ids ----
2934
IMJS_ITWIN_ID = ""
3035
IMJS_IMODEL_ID = ""
3136
```
3237

33-
- For the IMJS_ITWIN_ID variable, you can use the id of one of your existing iTwins. You can obtain their ids via the [iTwin REST APIs](https://developer.bentley.com/apis/itwins/operations/get-itwin/).
34-
35-
- For the IMJS_IMODEL_ID variable, use the id of an iModel that belongs to the iTwin that you specified in the IMJS_ITWIN_ID variable. You can obtain iModel ids via the [iModel REST APIs](https://developer.bentley.com/apis/imodels-v2/operations/get-imodel-details/).
38+
- For `IMJS_ITWIN_ID`, use the id of one of your existing iTwins. You can obtain iTwin ids via the [iTwin REST APIs](https://developer.bentley.com/apis/itwins/operations/get-itwin/).
39+
- For `IMJS_IMODEL_ID`, use the id of an iModel that belongs to the iTwin above. You can obtain iModel ids via the [iModel REST APIs](https://developer.bentley.com/apis/imodels-v2/operations/get-imodel-details/).
40+
- Alternatively, you can [create a test iModel from a sample](https://developer.bentley.com/tutorials/create-test-imodel-sample/) to get started without an existing iModel.
3641

37-
- Alternatively, you can [generate a test iModel](https://developer.bentley.com/tutorials/web-application-quick-start/#4-create-an-imodel) to get started without an existing iModel.
38-
39-
- If at any time you wish to change the iModel that you are viewing, you can change the values of the iTwinId or iModelId query parameters in the url (i.e. localhost:3000?iTwinId=myNewITwinId&iModelId=myNewIModelId)
42+
You can also switch the iModel at runtime by changing the `iTwinId` or `iModelId` query parameters in the URL (e.g. `localhost:3000?iTwinId=myITwinId&iModelId=myIModelId`).
4043

4144
## Available Scripts
4245

4346
In the project directory, you can run:
4447

4548
### `npm install`
4649

47-
Installs all the dependencies listed in your package.json.
50+
Installs all dependencies listed in `package.json`.
4851

4952
### `npm start`
5053

51-
Runs the app in the development mode.\
52-
It automatically opens [http://localhost:3000](http://localhost:3000) in your default browser.
54+
Runs the app in development mode. It automatically opens [http://localhost:3000](http://localhost:3000) in your default browser.
5355

54-
The page will reload if you make edits.\
56+
The page will reload if you make edits.
5557

5658
### `npm run build`
5759

58-
Builds the app for production to the `dist` folder.\
59-
It bundles your code in production mode and applies optimizations for best performance.
60-
61-
The build is minified and the filenames include the hashes.\
62-
Your app is ready to be deployed!
60+
Builds the app for production to the `dist` folder. The build is minified and filenames include content hashes.
6361

64-
See the section about [deployment](https://vite.dev/guide/static-deploy.html) for more information.
62+
See the [Vite static deploy guide](https://vite.dev/guide/static-deploy.html) for deployment options.
6563

6664
### `npm run preview`
6765

68-
Once you have built the app using `npm run build` you may test it locally by running this command.
69-
70-
This will boot up a local static web server that serves the files from `dist` at [http://localhost:3000](http://localhost:3000).
66+
Once you have built the app using `npm run build`, you can test it locally by running this command. It boots up a local static web server that serves the files from `dist` at [http://localhost:3000](http://localhost:3000).
7167

7268
### `npm run lint`
7369

7470
Runs ESLint on all source files to check for code style issues and potential errors.
7571

76-
## Next Steps
77-
78-
- [iTwin Viewer options](https://www.npmjs.com/package/@itwin/web-viewer-react)
79-
80-
- [Extending the iTwin Viewer](https://developer.bentley.com/tutorials/itwin-viewer-hello-world/)
81-
82-
- [Using the iTwin Platform](https://developer.bentley.com/)
72+
## Related Resources
8373

84-
- [iTwin Developer Program](https://www.youtube.com/playlist?list=PL6YCKeNfXXd_dXq4u9vtSFfsP3OTVcL8N)
74+
- [Working with iTwin Scenes in your Viewer Application](https://developer.bentley.com/tutorials/scenes-tutorial/) — the tutorial this repository accompanies
75+
- [Scenes API documentation](https://developer.bentley.com/apis/scenes/overview/)
76+
- [iTwin Viewer React package](https://www.npmjs.com/package/@itwin/web-viewer-react)
77+
- [iTwin Platform](https://developer.bentley.com/)

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<link rel="icon" href="favicon.ico" />
7-
<title>iTwin Viewer React Sample</title>
7+
<title>iTwin Scenes Tutorial</title>
88
</head>
99
<body>
1010
<div id="root"></div>

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "itwin-web-viewer-template",
3-
"version": "5.0.0",
2+
"name": "itwin-scenes-tutorial",
3+
"version": "1.0.0",
44
"private": true,
55
"dependencies": {
66
"@bentley/icons-generic": "^1.0.13",
@@ -59,6 +59,10 @@
5959
"vite": "^7.0.1",
6060
"vite-plugin-static-copy": "^3.1.0"
6161
},
62+
"overrides": {
63+
"lodash": "^4.17.23",
64+
"seroval": "^1.5.0"
65+
},
6266
"scripts": {
6367
"build": "tsc -b && vite build",
6468
"lint": "eslint .",

src/components/App.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import {
1414
FitViewTool,
1515
IModelApp,
16+
IModelConnection,
1617
type ScreenViewport,
1718
StandardViewId,
1819
} from "@itwin/core-frontend";
@@ -25,8 +26,11 @@ import {
2526
MeasureToolsUiItemsProvider,
2627
} from "@itwin/measure-tools-react";
2728
import { selectionStorage } from "../selectionStorage";
28-
import { propertyGridUiProvider, treeWidgetUiProvider } from "./UiProviders";
29+
import { propertyGridUiProvider } from "./UiProviders";
2930
import { useAuthorizationContext } from "./Authorization";
31+
import { ScenesWidgetProvider } from "./ScenesWidget";
32+
import { ScenesClient } from "./ScenesClient";
33+
import { ScenesCache } from "./ScenesCache";
3034

3135
interface AppProps {
3236
iTwinId: string;
@@ -45,6 +49,15 @@ export function App({ iTwinId, iModelId, changesetId }: AppProps) {
4549
MeasurementActionToolbar.setDefaultActionProvider();
4650
}, []);
4751

52+
const onIModelReady = useCallback(
53+
async (iModelConnection: IModelConnection) => {
54+
// Populate the information needed for this app.
55+
await ScenesClient.populateContext(iModelConnection);
56+
await ScenesCache.populateRealityModels(iModelConnection);
57+
},
58+
[],
59+
);
60+
4861
return (
4962
<Viewer
5063
iTwinId={iTwinId}
@@ -54,13 +67,15 @@ export function App({ iTwinId, iModelId, changesetId }: AppProps) {
5467
viewCreatorOptions={viewCreatorOptions}
5568
enablePerformanceMonitors={true} // see description in the README (https://www.npmjs.com/package/@itwin/web-viewer-react)
5669
onIModelAppInit={onIModelAppInit}
70+
onIModelConnected={onIModelReady}
5771
mapLayerOptions={{
5872
BingMaps: {
5973
key: "key",
6074
value: import.meta.env.IMJS_BING_MAPS_KEY ?? "",
6175
},
6276
}}
6377
uiProviders={[
78+
new ScenesWidgetProvider(),
6479
new ViewerNavigationToolsProvider(),
6580
new ViewerContentToolsProvider({
6681
vertical: {
@@ -69,7 +84,6 @@ export function App({ iTwinId, iModelId, changesetId }: AppProps) {
6984
}),
7085
new ViewerStatusbarItemsProvider(),
7186
new MeasureToolsUiItemsProvider(),
72-
treeWidgetUiProvider,
7387
propertyGridUiProvider,
7488
]}
7589
selectionStorage={selectionStorage}
@@ -96,7 +110,7 @@ function viewConfiguration(viewPort: ScreenViewport) {
96110
ViewerPerformance.addMeasure(
97111
"TileTreesLoaded",
98112
"ViewerStarting",
99-
"TilesLoaded"
113+
"TilesLoaded",
100114
);
101115
clearInterval(intvl);
102116
resolve(true);

src/components/Scenes.scss

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
.scenes-wrapper {
7+
display: flex;
8+
flex-direction: column;
9+
width: 100%;
10+
height: 100%;
11+
margin: 0 auto;
12+
padding: 8px;
13+
box-sizing: border-box;
14+
15+
.scenes-banner {
16+
flex: none;
17+
}
18+
19+
.scenes-controls {
20+
height: 40px;
21+
flex: none;
22+
display: flex;
23+
flex-direction: row;
24+
justify-content: flex-start;
25+
gap: 10px;
26+
padding-top: 5px;
27+
padding-bottom: 5px;
28+
}
29+
30+
.scenes-tile-list {
31+
flex: auto;
32+
overflow-y: auto;
33+
}
34+
35+
.scenes-group {
36+
margin-left: 10px;
37+
}
38+
39+
.scenes-tile {
40+
width: -webkit-fill-available;
41+
margin-bottom: 10px;
42+
margin-right: 5px;
43+
}
44+
45+
.scenes-tile-div {
46+
cursor: pointer;
47+
}
48+
}

0 commit comments

Comments
 (0)