Web3D API Reference

Web3D Graphics Library

Overview

Web3D is a graphics library with reusable and extensible graphics environment for viewing and editing of 3D content. It supports different model formats and content types using its plugins, all working together using single unified rendering and interaction architecture.

This is an inner-source project, contributions are welcomed.

Used by

Browser Support

  • Desktop: Chrome, Opera, Safari, Firefox, Edge
  • Mobile: Chrome, Safari

Featured Plugins

  • TrimBim Plugin - Used to view 3D models created by, for example, Tekla Structures or SketchUp. Supported model format is Trimbim (Trimbimconverter should be used to convert formats such as DWG, DGN, IFC, SKP, LandXML, QUADRI, STEP, IGES and more)
  • Markup Plugin - A collection of interactive markup and measurement tools
  • Potree Plugin - Streaming point cloud viewer based on Potree
  • Gltf Plugin - glTF model viewer
  • Materia Plugin - Integration with Materia procedural generation engine
  • Line editing Plugin - CAD style line editing plugin

For more info, docs and demos: https://web3d.trimble.com

Questions

Ask Filipp Keks in Google Chat

Getting started


Component as a dependency

The web3d packages are hosted on Trimble's Artifactory server and thus authentication is required. To authenticate you need to generate your API key on your Artifactory profile page and save it to .npmrc file:

curl -uYOUR_EMAIL:YOUR_KEY "https://artifactory.trimble.tools/artifactory/api/npm/technology-virtual-npm/auth/technology" >> ~/.npmrc

Command above is for bash shell, works on linux, mac and windows with bash shell installed. On default windows installation open the url in the browser and copy-paste response page source to %userprofile%\.npmrc (NB! copy page source, not page html)

After you've setup Artifactory, you can go ahead and add the viewer as a dependency to your project:

$ npm install --save @technology/web3d
$ npm install --save @technology/web3d-plugin-trimbim

Usage in code

For usage in non-transpiled JavaScript, import modules from dist/es, i.e:

import { Web3DViewer } from "./node_modules/@technology/web3d/dist/es/index.js";
import { TrimbimPlugin } from "./node_modules/@technology/web3d-plugin-trimbim/dist/es/index.js";

For usage in TypeScript or transpiled JavaScript import modules by package name, i.e:

import { Web3DViewer } from "@technology/web3d";
import { TrimbimPlugin } from "@technology/web3d-plugin-trimbim";

Make sure your transpiler's (webpack, rollup, esbuild.. etc) module resolution mode is set to node In case of TypeScript, tsconfig.json should contain these lines

"moduleResolution": "node",
"skipLibCheck": true,

NOTE! Avoid importing modules using full path, i.e. @technology/web3d/dist/esnext/Web3DViewer, let transpiler choose the build type, also modules which are not added to index, are not part of the public API.

It is recommended to pack your application code to ES modules, marking web3d as external, importing from dist/es at runtime. ES modules are faster, comparing to i.e. commonjs and browser is able to load those in parallel.

Troubleshooting

Code transpilers might break paths of external resources (i.e. images or worker scripts). To avoid bundling issues it is recommended to configure your transpiler to use external web3d modules, instead of bundling with app code. This would also increase your app compilation and loading time.

See Webpack external or Rollup external documentation

In case if using external modules is not possible you can manually deploy web3d resources and use settings to specify proper urls. i.e. Settings.staticRootUrl for images and TrimbimSettimgs.workerUrl for workers.

Avoid using isolatedModules TypeScript compiler option together with external web3d modules, as it breaks enum constants resolution.

Examples

Check for usage examples code, which are available on https://web3d.trimble.com

Examples of integration with popular frameworks can be found here

Builtin shortcuts


Navigation

  • F - Fit camera view to current selection
  • O - Switch between perspective and orthographic camera projections
  • W, A, S, D, Q, E - Camera movement in Fly (rotation) mode
  • Shift - Fast camera movement in Fly mode
  • Alt + Double Click - Look at clicked surface

Selection

  • Shift, Ctrl, Meta + Click - Add to current selection
  • Alt + Click - Subtract from current selection
  • H - Hide selection
  • Click Hold (1s) - switch to area selection
  • Esc - Deselect or cancel area selection placement

Markups

  • Esc - Cancel markup placement
  • Delete, Backspace - Delete selected markup
  • Tab - Switch selected measurement axis
  • D - Switch selected measurement direction

Clip planes

  • Shift + Mouse Wheel - Move selected clip plane
  • Double Click CP icon - Invert clip plane

Contributing


Project is opened for contributions. Before contributing, please discuss your idea with project developers. Contact Filipp Keks. You are also welcomed to experiment with current code base locally.

Development setup requirements:

Setup artifactory repository for build dependencies

curl -uYOUR_EMAIL:YOUR_KEY "https://artifactory.trimble.tools/artifactory/api/npm/trimblesolutions-technology-npm/auth/technology" >> ~/.npmrc
curl -uYOUR_EMAIL:YOUR_KEY "https://artifactory.trimble.tools/artifactory/api/npm/trimble-fulcrum-npm/auth/fulcrum" >> ~/.npmrc
curl -uYOUR_EMAIL:YOUR_KEY "https://artifactory.trimble.tools/artifactory/api/npm/technology-virtual-npm/auth/materia" >> ~/.npmrc
npm config set @trimble-livesharing:registry https://artifactory.trimble.tools/artifactory/api/npm/technology-virtual-npm/

Commands above is for bash shell, works on linux, mac and windows with bash shell installed. On default windows installation open the urls in the browser and copy-paste response page source to %userprofile%\.npmrc

To build and run demos locally, install dependencies and start development server, from project root directory

npm install
npm run build
npm start

Demo will be available at: http://localhost:8081

Note: Virtual Reality demos require secure https, so use npm run start-https and open https://localhost:8081 instead

Debugging in IDE

Source maps are generated containing full TypeScript sources, so just start viewer in watch mode npm run watch and debug using your favorite IDE.

Running tests in IDE

To run tests inside WebStorm, configure mocha runner working dir as project root (i.e. web3d/) and mocha package as "test" directory (i.e. web3d/test). To make this configuration default, make same changes to mocha run template, go to Run -> Edit configurations -> Edit configuration templates -> Mocha

Troubleshooting

On macOS, in case if npm install fails on canvas package build, install xcode command line tools and Homebrew, then run

xcode-select --install
brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman
npm install canvas

In case if npm install fails on puppeteer package chromium browser download, check your internet connection and run manually

npm install puppeteer

Upgrading


Upgrade guide 4.0 → 4.1

  1. Dropped deprecated plugin webgl-plugin-potree, use webgl-plugin-potreemanager instead
  2. Dropped deprecated plugin webgl-plugin-itowns, use webgl-plugin-3dtiles instead
  3. Settings.environmentMapEncoding is replaced with Settings.environmentMapColorSpace
  4. PublicCamera.projectionType = type setter is now asynchronous, added awaitable alternative await PublicCamera.setProjectionType(type)

Upgrade guide 3.0 → 4.0

  1. web3d-plugin-section plugin is dropped
  2. TrimbimModel.getHierarchyChildren signature changed, hierarchyType parameter added
  3. Trimbim plugin's Long interface (originated from flatbuffers library) is replaced with native bigint primitive type

Upgrade guide 2.1 → 3.0

  1. Upgrade to the latest version 2.1.x and carefully follow all deprecation notes
  2. Packages renamed from webgl-viewer-* to web3d-*
  3. Custom HTML element renamed from webgl-viewer to web3d-viewer
  4. Classes renamed WebglViewer -> Web3DViewer, WebglViewerEventName -> Web3DEventName, WebglViewerPlugin -> Web3DPlugin
  5. Removed Asynchronous Module Definition dist/amd build, use dist/es modules instead
  6. dist/esnext upgraded from es2021 to es2022, make sure your built tools support it, use dist/es otherwise
  7. Dropped WebGL1 support, only browsers with WebGL2 are supported. Check https://caniuse.com/webgl2
  8. Removed setting Settings.useWebgl2
  9. Removed setting PotreePlugin.settings.disableFragDepthExtension
  10. Environment map is rendered without tone mapping by default. Check demos/envmap.html for options
  11. Generator is renamed to TrimbimGenerator
  12. PotreePlugin.settings.workerRootUrl renamed to workerUrl

Upgrade guide 2.0 → 2.1

  1. Trimbim model entity states (selection, visibility, custom materials... etc) are now hierarchical. i.e. adding root entity ID to selection makes whole hierarchy tree (including children) visually selected.
  2. TrimbimSettings.workerRootUrl replaced with full URL TrimbimSettings.workerUrl. defaults to import.meta.url + "dist/workers/TrimbimWorker.js"
  3. TrimbimModel.getHierarchy replaced with getHierarchyRoots, getHierarchyParents and getHierarchyChildren
  4. TrimbimModel.getEntityInfo replaced with getEntities, getProducts and getProperties
  5. IColor interface replaced with Color objects in all public interfaces
  6. Potree settings number values replaced with enums PotreePlugin.pointSizeType, PotreePlugin.pointShape and PotreePlugin.pointColorType
  7. Potree classification color values changed to Vector4 in PotreePlugin.classifications
  8. Settings.materialAttenuation replaced with Settings.darkModeMaterials

Upgrade guide 1.1 → 2.0

  1. Firstly, upgrade to the latest version 1.1.x
  2. Check all deprecates and carefully follow each deprecate note
  3. Remove file paths from import statements, use only package names: @technology/web3d or @technology/web3d-plugin-xxx. i.e. import { WebglViewer } from "@technology/web3d";. Exception: imports from */Examples/* and */Extras/* are unchanged.
  4. Upgrade to latest version 2.0.x
  5. Replace math interfaces and ThreeJS imports (Vector3, Quaternion, Matrix4 and Euler etc.) with classes imported from webgl-viewer package. i.e. import { Vector3 } from "@technology/web3d""
  6. WebglViewer.camera.quaternion is facing opposite direction comparing to 1.1, to be compatible with Threejs builtin camera.
  7. WebglViewer.icons moved to separate plugin, it should be added explicitly and is accessed from WebglViewer.plugins.icons
  8. Use viewer.tools.clipPlane.getClipPlanes() instead of viewer.tools.clipPlanes, and viewer.plugins.markup.getMarkups() instead of viewer.plugins.markup
  9. Add markups using tool i.e. viewer.tools.measurement.add() instead of markup plugin viewer.plugins.markup.add()
  10. TrimbimSettings.hiddenLayers replaced with TrimbimModel.setLayerVisibility
  11. Plane interface removed, all usages replaced by 2 variables position and normal
  12. Color interface renamed to IColor
  13. TrimbimPlugin.getModelIds() replaced with getModels(), TrimbimPlugin.getModel(modelId) replaced with WebglViewer.getModel(modelId, TrimbimModel)
  14. "pick" events are not fired by default, do viewer.tools.picking.enable = true to enable picking events.