DemoJavaScript

One model, several viewports

A 3D view, plans and elevations of the same models side by side, loaded once; open and close viewports in any order.

The S1 models in a 3D view and a plan of one storey, with room for two more viewports. Every viewport is a viewer on the same ModelManager, so the WebGPU viewer loads the models once for all of them.

One model, several viewportsLive demo
Uses the demo API token of your account: sign in to BIM.works once in this browser.

Try it#

  1. Add a viewport. Add 3D view, Add plan or Add elevation opens one more, four at most. Its caption says how long it took to show the models: at once, because they were already on the graphics card. With the WebGL viewer every viewport loads its own copy, so the demo stops at two there.
  2. Close one. × closes a viewport, any of them and in any order, the first included: the others keep their models and keep working.
  3. Pick a storey. Storey sets the floor the plans show; the 3D views keep the whole building, because each viewport has its own ObjectStateManager.
  4. Select. A click selects an object in one viewport; the demo passes the selection on to the others.
  5. Point the 3D views. A double click in a plan turns every 3D view to the spot, at the distance it had.
  6. Share the state. Same state in every viewport puts all viewports on one ObjectStateManager: a storey picked now hides the rest in the 3D views too, and the selection needs no passing on.

How it is built#

The code is in BimRepository/www/docs-runtime/demos/viewports.js.

What How Where it is explained
Viewports One Viewer3d per viewport on the frame's ModelManager, each on an ObjectStateManager of its own, or all on one. destroy() closes one; removeObjectStateManager lets go of its state. Show models in several viewports
Loaded once The models go into the ModelManager with addModels; a viewer created later shows what it holds. Its versionLoaded comes at once with the WebGPU viewer. how-to/viewer3d/several-viewports#shared
Plans An orthographic camera (getCamera().fov = 0), 2D mode, setBuildingStoreysVisibleExclusive for the storey, the coverings left out, viewFit from above. Show a floor plan
Elevations An orthographic camera fitted with viewDirection: [0, -1, 0]. Set the camera from code
The selection in every viewport A selection listener on each ObjectStateManager calls setToSelectionSet on the others. Select and colour objects
A plan points the 3D views pick at the double click, then getCamera().interpolateView in each 3D view, keeping its eye-to-target offset. Set the camera from code