This repository contains the completed sample application for the Working with iTwin Scenes in your Viewer Application tutorial. The app demonstrates how to integrate the Scenes API 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.
Before running this app, you should have:
- A registered application on the iTwin Developer Portal with the
itwin-platformOAuth scope. This scope covers both the viewer and the Scenes API.- See Register an application for step-by-step instructions.
- An iTwin with appropriate permissions to manage scenes.
- An iModel to open in the viewer. The tutorial uses the "House Model" sample iModel.
- See Create a test iModel from a Bentley provided sample for instructions.
Prior to running the app, add your OIDC client configuration to the variables in the .env file:
# ---- Authorization Client Settings ----
IMJS_AUTH_CLIENT_CLIENT_ID=""
IMJS_AUTH_CLIENT_REDIRECT_URI=""
IMJS_AUTH_CLIENT_LOGOUT_URI=""
IMJS_AUTH_CLIENT_SCOPES="itwin-platform"
- The
itwin-platformscope is already set in.envand grants access to both the iModel viewer and the Scenes API. - The redirect URI must match exactly what is registered for your application.
You should also add a valid iTwinId and iModelId in the same file:
# ---- Test ids ----
IMJS_ITWIN_ID = ""
IMJS_IMODEL_ID = ""
- For
IMJS_ITWIN_ID, use the id of one of your existing iTwins. You can obtain iTwin ids via the iTwin REST APIs. - 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. - Alternatively, you can create a test iModel from a sample to get started without an existing iModel.
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).
In the project directory, you can run:
Installs all dependencies listed in package.json.
Runs the app in development mode. It automatically opens http://localhost:3000 in your default browser.
The page will reload if you make edits.
Builds the app for production to the dist folder. The build is minified and filenames include content hashes.
See the Vite static deploy guide for deployment options.
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.
Runs ESLint on all source files to check for code style issues and potential errors.
- Working with iTwin Scenes in your Viewer Application — the tutorial this repository accompanies
- Scenes API documentation
- iTwin Viewer React package
- iTwin Platform