---
title: One model, several viewports
summary: A 3D view, plans and elevations of the same models side by side, loaded once; open and close viewports in any order.
order: 50
layout: wide
languages: [javascript]
terms: [viewer, model-manager, object-state-manager, building-storey]
see-also: [how-to/viewer3d/several-viewports, how-to/viewer3d/show-a-floor-plan, demos/repair-annotations]
---

# One model, several viewports

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.

```demo
name: viewports
title: One model, several viewports
models: s1, s1-electrical
height: 720
needs: Uses the demo [[term:api-token|API token]] of your [[term:account|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 [[term:model-manager|ModelManager]], each on an [[term:object-state-manager|ObjectStateManager]] of its own, or all on one. `destroy()` closes one; `removeObjectStateManager` lets go of its state. | [[page:how-to/viewer3d/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. | [[page: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. | [[page:how-to/viewer3d/show-a-floor-plan]] |
| Elevations | An orthographic camera fitted with `viewDirection: [0, -1, 0]`. | [[page:how-to/viewer3d/set-the-camera]] |
| The selection in every viewport | A selection listener on each ObjectStateManager calls `setToSelectionSet` on the others. | [[page:how-to/viewer3d/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. | [[page:how-to/viewer3d/set-the-camera]] |
