3D viewer

Embedding the Viewer3d in your own page and driving it from JavaScript: switching models, the camera, navigation modes and walking, selection and colours, x-ray and the proximity fade, storeys and floor plans, hiding, section planes, measuring, the grid, DWG drawings, PDF floor plans aligned with a model, point clouds, geo mode, offline use and screenshots.

These guides are for developers who put the 3D viewer (@bimworks/viewer3d) in their own application. They assume the packages are installed (JavaScript and TypeScript) and that you have an API token or an auth token to create a client with; Show your users' models in your web app shows how a page your users open gets its token without ever seeing the API token. The course Build a model viewer builds a viewer step by step; the guides here each solve one task.

Two objects sit between your code and the viewer. The ModelManager knows which model versions are loaded; the ObjectStateManager holds the state of every object — visible, selected, coloured — and pushes it to every viewer connected to it. Most of what you do with a viewer you do through those two, addressing objects by Qid.

The settings the viewer accepts are listed on 3D viewer settings, the default mouse and key bindings on Default key bindings.

Pages#

  • Show your users' models in your web appYour backend keeps the API token and gives each visitor a short-lived versions token for the models they may see; your page loads the 3D viewer with that token and asks for a new one when it expires.
  • Embed the viewerPut a Viewer3d in a page, load a model and know when it is fully loaded; where the viewer's modules come from, calling the API from another origin and switching web workers on.
  • Choose the 3D viewerRun Viewer3D-Next (WebGPU) where the browser can and Viewer3D (WebGL) where it cannot, downloading only the one in use, or keep to one of the two; what decides, how to steer it with rules, and what happens when WebGPU fails.
  • Switch between modelsLoad several models once and switch between them — show one at a time, highlight one with the others grey, or swap the loaded model for another — without reloading.
  • Navigation modesStart the default, walk, game or drone mode, define a custom mode with its own key bindings, and know which forwardMode values the viewer actually implements.
  • Set the camera from codeChoose the first view of a model, jump to the front, side and top views, zoom, switch to orthographic, save and restore a viewpoint, and fly to a viewpoint a BQL query computes.
  • Walk through a buildingWalk through a building at eye height with collision, gravity, stairs, jumps and storey jumps on the walkable surfaces the server computes, show a route, and name the room and zones the camera is in.
  • Select and colour objectsSelect objects by Qid or by query, listen to selection changes, choose SHIFT or AUTO multi-selection, and set, batch and reset colours through the ObjectStateManager.
  • X-ray a set of objectsPut any set of objects in x-ray from code, without selecting them, so the viewer draws them with translucent faces and edges through the walls, floors and ceilings in front of them.
  • Animate state changesChange visibility, ghosts, the selection, the x-ray set, colours and the camera in one ObjectStateManager call that animates, step after step, running together, queued or replacing what runs, and stopped at its start, where it is or its end.
  • Show building storeysList the storeys of one or more models as one set of floors, show a floor on its own and fit the view to it, toggle floors with checkboxes, and show or hide the objects that are in no storey.
  • Show a floor planTurn the 3D viewer into a floor plan — one storey, an orthographic camera looking down, 2D mode (a drag turns the plan, nothing tilts), the ceilings hidden and every room labelled with its number, name and area — the replacement for the 2D viewer.
  • Show models in several viewportsA 3D view and a floor plan of the same models side by side, or more viewports, loaded once: one ModelManager, a Viewer3d per viewport, each with its own state and camera, closable in any order.
  • Hide and isolateHide objects, show only a set, show a storey on its own, fit the view to a selection and bring everything back; what the H key, the middle button and F do.
  • Fade walls near the cameraMark walls, roofs and coverings as soft occluders so they fade out and become click-through as the camera comes close, and zooming into a building reveals the interior without hiding anything by hand.
  • Annotate a modelEvery way to put information on objects in the 3D viewer — labels, icons, templates, live data and BVL — on one model.
  • Section planesStart section planes on the sides of the models, on a right-clicked face or as a section box around them, let the user place and drag planes with Ctrl + left drag, list the planes by name, and remove them one by one or all at once.
  • Show the reference gridSwitch on an infinite metric grid in the ground plane that the camera orbits and zooms over, that double-click flies to, and whose intersections snap like vertices.
  • Geo modeSwitch the viewer between LOCAL and GEO placement, know why the switch can fail, and add basemaps, terrain and 3D Tiles as GIS layers.
  • Measure areas, angles and with the laserStart the distance, path, point, area, angle and laser measurements from code, draw stored measurements again, and listen to what the user measures.
  • Measure the distance between two objectsCompute the shortest distance between the surfaces of two objects, or vertically or horizontally, interactively or from two Qids, and draw or restore the result as a measurement.
  • Show DWG drawingsLoad a DWG drawing into the 3D viewer next to IFC models, switch between model space and its paper-space layouts, read its layers, and align it under the building.
  • Align PDF floor plansPut PDF floor plans under the building in the 3D viewer — two points clicked on the sheet and in the model, in two viewers side by side, give the alignment of one plan, and the storey elevations place the plans of the other floors.
  • Show point cloudsUpload an E57, LAS or LAZ point cloud (COPC included) and stream it into the 3D viewer next to an IFC model, with the upload settings for unit, colour and intensity.
  • Work offlinePrepare models for offline use while online, then load them in the 3D viewer without a connection — what is stored, what works offline and what does not, errors, storage, and keeping the offline set up to date.
  • Take a screenshot in the browserTurn what the 3D viewer shows into a PNG, with or without a background, and render a series of images at a fixed size from a viewer that is never on the page.