3D viewer changes in 3.0
Every change an application built on the 2.x 3D viewer meets in 3.0 — packaging, the declared types, behaviour behind unchanged methods, section planes, measurements and GIS — with what to do for each.
@bimworks/viewer3d keeps its package name, its entry point (www/viewer3d-index.js) and its type definitions (viewer3d.d.ts). It still needs WebGL2, and the technologyAllowed defaults are unchanged: web workers stay off unless you enable them. This page lists everything else an application built on the 2.x 3D viewer sees change in 3.0, and what to do about it. The new features are on BIM.works 3.0; changelog/v3-0/from-2-to-3#javascript has the short version, next to the other packages.
Every change has a class:
- Breaking: 2.x code fails or gives a wrong result.
- Behaviour: the same code runs, but the result or what the user sees differs.
- Requirement: how the viewer is installed or served.
- Deprecated: still works for now; use the replacement.
Overview#
| Change | 2.x | 3.0 | Class | What to do |
|---|---|---|---|---|
| Dependencies | — | needs the 3.0 @bimworks/viewercommon (about 40 new imports) and matching type definitions |
Requirement | upgrade the packages together (below) |
Version export |
Version |
BuildVersion |
Breaking | rename |
| Deep imports | the selection-visualization files, cesium/, draco_decoder.*, viewobjects.js |
removed; the classes come from the package | Breaking | import from the package |
| Undeclared helpers | createBox, createCylinder, createCone, createSphere, resetCollections, startVerticalMove |
removed | Breaking | overlays, resetResults(), startObjectTransform() |
bimSurfer |
declared | gone from the types; its internals changed | Breaking for code that reaches into it | use the declared API (below) |
MultiSelectMode |
an enum | "SHIFT" | "AUTO" |
Breaking (TypeScript) | use the strings |
WireframeSelectionVisualization |
(color, thickness) |
(color); a colour may be a CSS string |
Breaking (TypeScript) | drop the thickness |
startTopPlane() and the other side starters |
return a SectionPlane |
SectionPlane | null; planes share six slots, one per normal, without fixed positions; Ctrl+drag no longer replaces the top plane; a section box turns into six planes; GIS layers are not cut |
Breaking for code that uses slot numbers; Behaviour | find planes with getPlanes() and getStandard() (below) |
rightMouseClick(event, qid) |
the second argument was an internal number | a qid, plus a pick; also on a touch long press |
Behaviour | drop workarounds for the number |
| Background | opaque white; setBackgroundColor came out white |
grey-blue gradient; setBackgroundColor works |
Behaviour | set a colour to keep white |
| Transparency | orderIndependentTransparency: false |
true |
Behaviour | set false to keep the 2.x look |
| Keys and mouse | — | PageUp/PageDown jump storeys; O and M are bound; Space jumps in walk and game mode; Escape leaves any mode but the default; a right or middle click leaves pointer lock; the canvas takes focus | Behaviour | review your own key handling |
| Walk mode | speed from the depth under the cursor | a fixed 1.5 m/s; collision and gravity where the instance has walkable surfaces | Behaviour | — |
| Loading | addModels never settled on a failure |
initializeViewer() waits for models already in the ModelManager; addModels rejects |
Behaviour | add error handling |
| Geometry transport | WebSocket | an HTTP stream (fetch), with the WebSocket as fallback |
Behaviour | a page on another origin needs CORS |
Camera.setViewpoint |
the direction used as given | the direction scaled ×1000, so the orbit target lies at the real distance | Behaviour | check restored views |
| GEO mode | offsets from the server | computed in the browser on one plane, with elevation and true north | Breaking (GEO mode only) | store GEO-mode viewpoints and measurements again |
| Annotations | always drawn | hidden behind geometry (occlusion: "hide"); an explicit position wins over the qid's box |
Behaviour | set occlusion |
| Measurements | fixed when finished; toString() printed millimetres with "m" |
points can be dragged (committed fires again), a loupe, edge snapping, a delete button; toString() in metres |
Behaviour | handle repeated committed |
| GIS | — | invisible layers are only registered, toggleGisLayer returns a Promise, imagery drapes over terrain, content within 500 m of the models |
Behaviour | — |
| WebGL context loss | — | stops the viewer and calls the engine-failure listeners | Behaviour | listen for it |
| Flat scenes (a PDF or DWG on its own) | 3D navigation | 2D interaction: a turning dial, a pan that follows the pointer, pinch | Behaviour | — |
Packages and loading#
The 3.0 viewercommon (Requirement). The 3.0 viewer imports about 40 names that only the 3.0 @bimworks/viewercommon exports: the selection visualizations, the mouse-button and selection-mode constants, versionOfQid, the error classes, the cursor loupe, viewpoints and the annotation templates. A module that imports a missing name does not load at all, so next to a 2.x viewercommon the 3.0 viewer never starts. Its type definitions import types from viewercommon, @bimworks/jssdk and @sascom/commonjs. Upgrade @bimworks/jssdk, @bimworks/viewercommon, @bimworks/viewer3d, @sascom/commonjs and @sascom/jsclient together, to the version of the instance (JavaScript and TypeScript).
BuildVersion (Breaking). The export Version, the viewer's build string, is now BuildVersion; import {Version} from "@bimworks/viewer3d" fails when the module links. jssdk uses the name Version for a model version, which is why it changed. The same rename happened in jssdk, viewercommon and viewer2d.
Deep imports (Breaking). The files wireframeselectionvisualization.js, fatwireframeselectionvisualization.js, noneselectionvisualization.js, selectionvisualization.js, viewobjects.js, compactbounds.js, terrainrenderlayer.js, tiledrenderlayerwithterrain.js, the vendored cesium/ folder, draco_decoder.js and .wasm and the terrain shaders are gone. The selection visualizations are the viewercommon classes, exported again from the package root, so both 3D viewers share one class identity. Import from @bimworks/viewer3d or @bimworks/viewercommon, never from @bimworks/viewer3d/www/….
The single-file build (Requirement). viewer3d.bimworks.js loads its workers from workers/, and their code from assets/, next to the file; 2.x loaded them from /workers/ at the root of the site. Copy both folders next to the file (Downloads).
The npm package. It ships www/ and viewer3d.d.ts only, and its JavaScript without comments; the type definitions are the documentation. The Draco decoder is still fetched at run time from www.gstatic.com (now 1.5.9), so a page's Content-Security-Policy has to allow it, as in 2.x. The viewer needs no stylesheet.
The declared API#
bimSurfer (Breaking for code that uses it). readonly bimSurfer is gone from the type definitions. The object still exists at run time, but placement, picking and the camera classes inside it changed, so a 2.x reach-in such as bimSurfer.viewer.pick or bimSurfer.globalBaseTranslation breaks. Use the declared API instead: pick(x, y), getCamera() with eye, target, up, viewMatrix and projMatrix, measurementToRenderCoordinates() and the other conversions, overlays, resetResults() and isRunning().
Undeclared helpers (Breaking). createBox, createCylinder, createCone, createSphere, resetCollections() and startVerticalMove() were never declared and are gone. Draw helper geometry with viewer.overlays.add(...) (arrows, areas, labels, paths, meshes and glTF), clear what a BVL or BCL result drew with resetResults(), and move or rotate objects with startObjectTransform(qids, {mode: "move"}) or {mode: "rotate"}.
Declarations that never worked. getName(), activateHistory(), getHistoryItem(), updateCameraTargetToAabbOf() and addVertexClickListener() were declared in 2.x but threw a TypeError when called. They are gone from the types; nothing that worked stops working.
Dropped from the types, still at run time (Deprecated). colorChanged(qids, color), which the ObjectStateManager never calls; createDefaultRenderLayer(), which now takes a render mode; internalLoadGisLayer(), which now returns a promise. Use ObjectStateManager.changeColor, overlays and toggleGisLayer instead.
MultiSelectMode (Breaking, TypeScript only). The enum is the string type "SHIFT" | "AUTO". The 2.x enum never existed at run time, so MultiSelectMode.SHIFT did not work then either. Pass "SHIFT" or "AUTO". getMultiSelectMode() is new, and the mode may be set before the viewer is initialized.
Selection visualizations (Breaking, TypeScript only). WireframeSelectionVisualization(color, thickness) is (color), and the colour may be a CSS colour, an array or a Float32Array; in 2.x a CSS string did not work. Every visualization has extendedObbEnabled and extendedObbColor. The default is still an orange wireframe. FaceAndWireframeSelectionVisualization, XRaySelectionVisualization and XRayVisualization are new.
Side starters may return null (Breaking with strictNullChecks). startTopPlane(), startBottomPlane(), startLeftPlane(), startRightPlane(), startFrontPlane() and startBackPlane() are typed SectionPlane | null (below).
Type corrections. These change no behaviour:
- Return types are concrete:
addModels()andviewFit()returnPromise<void>,toggleFullScreen()andtoggleAnimationEnabled()aboolean,getCanvas()anHTMLCanvasElement.toggleGisLayerandupdateModelreturn promises at run time too. - The listener methods the managers call take a
QidSetand further arguments, so TypeScript that calls them with arrays no longer compiles.removeModelstakes versions andmodelsShowntakes vids, as the code always did. LoadProgressHandlercallbacks get themanagerIndex.GisLayer.urlis optional;typeincludes"UPLOADED_GIS";GisLayerandScreenshotOptionsare exported.KeyBindingActionincludestoggleAreaHoles,storeyUpandstoreyDown.MAIN_MOUSE_BUTTON,AUX_MOUSE_BUTTONandSECONDARY_MOUSE_BUTTONare declared with the values they had at run time.- Two descriptions are corrected: the section planes and the section box follow the models' oriented box, as they already did, and
fatWireframes.enabledandcachedefault tofalse.
Behaviour behind the same API#
The context menu (Behaviour). rightMouseClick(event, qid, pick) gets a real qid; 2.x passed the viewer's internal number although the types said qid. The third argument is the pick: the qid, the point in render coordinates and the unit normal. On a touch screen a long press selects the object under the finger, when nothing is selected, and calls the callback too. Drop any conversion from the internal number, and use pick instead of picking a second time (reference/viewer3d#rightmouseclick).
The background (Behaviour). The canvas is a vertical gradient from #EDF1F4 at the top to #BFCAD3 at the bottom; 2.x cleared it white. setBackgroundColor(c) now shows the colour (in 2.x almost every colour came out white) and switches the gradient off; setBackgroundGradientEnabled(true) puts it back. Screenshots show the gradient too. Call setBackgroundColor("#FFFFFF") to keep the 2.x look.
Transparency (Behaviour). realtimeSettings.orderIndependentTransparency defaults to true: spaces, glass and every transparent colour blend without draw-order artefacts, look different and cost differently. Pass realtimeSettings: {orderIndependentTransparency: false} to keep the 2.x rendering.
Keys and mouse (Behaviour). Changed defaults:
- PageUp and PageDown jump a storey up or down (
storeyUp,storeyDown), which needs walk physics; in 2.x they moved the camera up and down. Free vertical movement is Q and Z only. - O switches an area measurement between gross, net and hull, or the reference of an object distance.
- M switches the measuring loupe on and off.
- Space still toggles auto-rotation, but in walk and game mode it jumps.
- Escape returns any navigation mode but the default to the default, walk included, and deselects a selected measurement when no tool runs.
- A right or middle click while the pointer is locked (game, drone, or a custom mode with
pointerLock) leaves the mode. - Ctrl+Shift+F12 opens a diagnostics panel.
- The canvas can take focus and is in the tab order, so a page's
:focus-visiblestyle may draw on it;focus()no longer scrolls the page to it.
Unchanged: WSADQZ and the arrow keys in every mode, the mouse buttons (orbit, pan with the middle button or Shift, section with Ctrl, look around with Alt), hideObjectOnMiddleClick, and H, C, D, F, Home, Insert, Enter and Delete. Override a key per mode with navigationModes.<mode>.keyBindings (an empty array disables an action), or claim it with addKeyHandler (Default key bindings).
Walking (Behaviour). Walk mode moves at a fixed 1.5 m/s and turns 25° a second; 2.x took its pace from the depth under the cursor, so it surged and stalled. navigationSpeed scales walk mode too, and every mode's movement no longer depends on the frame rate. When the instance generates walkable surfaces (the walkable_surfaces feature, off by default), walk and game mode get collision, gravity, steps, jumps and storey jumps; without them navigation is as before. Pass collision: false in a custom mode to keep free walking (Walk through a building).
Wheel zoom (Behaviour). A touchpad zooms by how far it scrolls (100 pixels or three lines make one notch) instead of a full notch per event, and notches queue into one animated approach. Shift still zooms five times as far. zoomSteps(steps, pos) does the same from code.
Flat scenes (Behaviour). A scene without height, such as a PDF or a DWG on its own, gets 2D interaction: a drag turns the plan around the point pressed, with a dial and square snapping; a pan follows the pointer one to one; two fingers pan and pinch. When a model with height joins or leaves, the default view is redone. set2dMode and is2dMode are new (Show a floor plan).
Loading (Behaviour). initializeViewer() resolves when the models already in the ModelManager have loaded, so creating the viewer after loading models takes longer; errors there are logged, not thrown. addModels rejects when loading fails (2.x never settled), with IncompleteVersionError for a version without its metadata ModelNotAvailableOfflineError in offline mode, and GeometryNotAvailableError for a model the instance has no geometry for, once the other models of the call have loaded; pointClouds: false leaves point clouds out. For a raster PDF, a GLB and a chunked E57 the promise still resolves before their content has loaded. updateModel waits for the model to be placed again and rejects on failure. Add error handling where you await them.
Geometry transport (Behaviour). Geometry comes over an HTTP stream (DownloadGeometry3DStream, then fetch with CORS) and falls back to the WebSocket when the stream fails before its first chunk. A model the instance has no geometry for (DATA_NOT_FOUND) is no such failure: it is not asked again. A viewer page on another origin than the instance needs the instance to allow that origin, otherwise every model logs a fallback warning and loads over the WebSocket; so does a page behind a proxy that blocks streamed responses.
GEO mode (Breaking for stored GEO-mode coordinates). 2.x took GEO offsets from the server, picked a UTM zone per model and used the first model's offset as the render offset. 3.0 places the models in the browser on one east-north-up plane at the first model's georeference, with their elevation, and rotates by the grid convergence so north is true north; a stored alignment applies in GEO mode too, and the render offset is zero. So in GEO mode Camera.getViewpoint(), measurement coordinates, point labels, getMainBounds() and section-plane positions are in another frame than in 2.x, and models in one scene can shift in height and turn by the convergence angle (models across a UTM zone border are no longer scattered). LOCAL mode is unchanged. Store GEO-mode viewpoints and measurements again, or keep them in LOCAL mode or in model coordinates (renderToMeasurementCoordinates, measurementToModelCoordinates) (Geo mode).
Camera.setViewpoint (Behaviour). The direction is scaled ×1000, so a view from getViewpoint() orbits around its real target; a BCF unit direction puts the target 1 m ahead. In 2.x the target landed millimetres in front of the eye. Code that scaled the direction itself now puts the target 1000 times too far (Set the camera from code).
Annotations (Behaviour). Annotation.occlusion defaults to "hide": an annotation whose point or object is behind other geometry is hidden once the camera settles. An explicit position wins over the qid; without one, the anchor is the centre of the object's box in its model's own axes. Section planes still hide what they cut away. Set occlusion = "none" for the 2.x behaviour (how-to/viewer3d/annotations#occlusion).
WebGL context loss (Behaviour). When the browser takes the WebGL context away, the viewer stops drawing and picking and calls the addEngineFailureListener listeners once, with {engine: "webgl", reason: "context-lost"}; it does not restore itself. 2.x did not notice. Rebuild the viewer, or reload, from the listener.
viewFitModels (Behaviour, a fix). It skips models that are not loaded in the viewer (2.x threw) and fits correctly in GEO mode.
Smaller changes:
- The container gets
aria-busy,data-viewer-loading,data-viewer-modelsanddata-viewer-load-errors; the loading indicator hasrole="status". setMode("GEO")returnsfalsein offline mode; GEO mode shows a DWG's model space only.- On touch-only devices
realtimeSettings.progressiveFullDetaildefaults totrue, and culling budgets adapt when culling is on. setMultiSelectMode,setObjectHoverEnabledandaddGisLayerwith an invisible layer may be called before the viewer is initialized.hoverOnnever did anything; that is now documented, andlinkCamera()is new.
Section planes#
In 2.x the six side starters each owned a slot: startTopPlane() slot 0, bottom 1, left 2, right 3, front 4, back 5. A Ctrl+drag plane always took slot 0, and a starter without a loaded model threw a TypeError.
No fixed slots (Breaking for code that uses slot numbers). startTopPlane() is startStandardPlane("top"). When the top plane already cuts, it goes back to its place; otherwise it takes the slot of a plane that cuts with the same normal (within 1°), replacing it, or else the lowest free slot. get(0) is no longer the top plane. startAabbPlane(index) is deprecated and maps the index to a side. Planes have names ("Top", "Plane 1", …). Keep the returned SectionPlane, or find it with getPlanes() and getStandard() (how-to/viewer3d/section-planes#list).
Ctrl+drag adds a plane (Behaviour). Ctrl+drag, the face widget and the context-menu recipe take the slot of the plane with the same normal or a free one, so a user can cut with several planes; in 2.x each replaced the top plane.
One plane per normal (Behaviour). Every start, startPlaneWithCoordinateAndNormal with an explicit slot and setState included, switches off another plane that cuts with the same normal (within 1°). Two parallel planes facing the same way cannot cut together; opposite normals can.
null (Behaviour). The starters and startPlaneAt return null when no model is loaded, or when all six slots cut with other normals.
The section box (Behaviour). The box's six faces are the side planes "Top" to "Back". A starter puts its face back on the model's face and dissolves the box: the other five faces stay where they are, as separate planes; switching one face off does the same. 2.x cleared the box and every plane. startSectionBox still clears all planes, and also takes {min, max} and {padding}.
GIS layers are not cut (Behaviour). 3D Tiles and uploaded GIS objects are not sectionable; in 2.x a section plane also cut every 3D Tiles building. Terrain and imagery were never cut; GLB models still are.
Unchanged: disableAll(), hatching, endcaps and showIcons (all on by default), and SectionPlane.disable().
Measurements#
Finished measurements can be edited (Behaviour). Measurement.editable defaults to true: the points of a finished area, path or point measurement, and a laser as a whole, can be dragged. During the drag startedUpdate fires, and on release committed fires again for the same measurement; Escape fires cancelled and puts it back. An application that stores measurements in committed has to update by id instead of inserting. Set measurement.editable = false to keep the 2.x behaviour (Measure areas, angles and with the laser).
Loupe, edge snapping, delete button (Behaviour). While a point tool aims with a mouse or pen, a loupe follows the cursor (magnifier, on by default; M toggles it). Snapping includes model edges, not only vertices. A selected measurement shows a delete button. Escape with no tool running deselects the selected measurement; Escape that stops a tool, stopActiveMeasurement() and removeAllMeasurements() give the clicks back to the viewer's selection mode, rectangle selection included.
toString() in metres (Behaviour, a fix). DistanceMeasurement and PathMeasurement printed the length in millimetres followed by "m" ("4235.12m" for 4.24 m); they print metres now. length is still in millimetres.
Unchanged: addDistanceMeasurement, addPathMeasurement, the start…Measurement methods (a distance is still constrained by default), listMeasurements, removeMeasurement, removeAllMeasurements, the order of startedNew, cancelled and deleted, ids unique across viewers, and the point measurement's default label. GEO-mode coordinates differ (above).
GIS layers#
GIS layers (Behaviour):
addGisLayerwithvisiblenottrueonly registers the layer.toggleGisLayerreturns a Promise that resolves when the layer has loaded. It still throws the string"Unknown GIS layer: …"for an unknown id, and returnsundefinedwhen nothing changes.- Imagery (TMS, WMS, WMTS) drapes over a visible terrain layer, and a terrain with imagery on it is not drawn on its own; a terrain alone is flat light blue.
- GIS content is drawn and requested within the models' bounding circle plus
gisRadiusMeters(500 m by default). - 3D Tiles are placed in height with
heightDatum,heightOffsetMetersandsnapToZero(on by default).
New, nothing to change#
Nothing below changes unless you use it; 3D viewer settings describes each.
- Offline mode:
prepareOfflineModels,removeOfflineModels,getOfflineModels,getOfflineVersions,setOfflineMode,isOfflineMode(Work offline). - Picking and tools:
pick(x, y),selectObject,cancelObjectSelection,setClickHandler,selectVertex(fn, {snapping}),startObjectTransform,startExtrusionDrawing,addKeyHandler. - Coordinates:
CoordinateFrame,modelToMeasurementCoordinatesand the other conversions,getModelLengthUnitMm,getModelBounds,getModelFrameBounds,getObjectsObb,getObjectsAabb,frames. - Camera:
getMillimetresPerPixel,eye,target,center,up, the view and projection matrices,interpolateView,orbitYaw,viewFit({box}),isAtRest,linkCamera,zoomSteps,resetToDefaultView. - View state:
captureViewState,restoreViewState,viewpoints,SectionPlanes.getStateandsetState. - Section planes:
startStandardPlane,startPlaneAt,getPlanes,canStartPlane,onPlanesChange,onEnabledChange, plane names, visibility, highlighting and annotation modes, the section box's annotation and visibility methods, icons, end caps per object and cap styles,MovablePlanes. - Measurements: area, angle, object distance, the laser, reference geometry (levels, grids, centre lines), snapping, the loupe, undo, touch,
viewFitMeasurement(Measure the distance between two objects). - Rendering: the grid, sun and shadows, the x-ray visualization, wireframe overrides, triangle lines, proximity fade,
setBackgroundGradientEnabled, the culling budget (Show the reference grid, Fade walls near the camera, X-ray a set of objects). - Overlays, figure layers, quantity figures, routes (
showRoute,followRoute), the current-space tracker,walkPhysicsAvailable. - 2D mode and plan labels (
set2dMode,is2dMode,setPlanLabelsEnabled,planLabels), DWG layouts (getDwgSemanticsMap,showDwgLayout,hideDwgSheets) (Show DWG drawings). - Models:
setModelVisible,getModelAlignment,setModelAlignment,getModelsWithoutGeoReference, clusters, thepointCloudssetting. - GIS:
getGisLayer,getGisLayers,setGisLayerOpacity,removeGisLayer,UPLOADED_GIS, terrain options. - Annotations: text mode, scaling by distance, limits, groups, annotation layers,
clearAnnotations,setAnnotationsVisible. - Life cycle:
isRunning,needsRepaint, repaint and engine-failure listeners,getDiagnostics,showDiagnostics, navigation-mode listeners,usesPointerLock,isPointerLocked,isFullScreen,saveScreenshot, and the screenshot optionswidth,height,viewpoint,annotationsandincludeText. - The constructor's
canvasandcontainerarguments are declared; they existed at run time in 2.x.