Adjusting zoom to fit in the Forge viewer

A question came up during this week’s Forge Accelerator in Dublin that I thought would be of broader interest. It related to the fact that the Forge viewer’s default behaviour when you double-click the background and perform a zoom-to-fit isn’t always desirable. In this case the developer was fine with a zoom-to-fit being performed, but felt the resultant view wasn’t a good enough fit.

Here’s the default zoom level on double-click in Dasher 360, for instance:

Zoom to fit

As you can see the model remains quite far from the camera.

The good news is that debugging into the Forge viewer source, you can easily see where this calculation happens, and it’s based on a few variables that can be modified in your custom application.

From your GuiViewer3D instance, you can access the following properties via the navigation object:

Default navigation state

The main variables – with the default value of 0.05 – are FIT_TO_VIEW_HORIZONTAL_MARGIN and FIT_TO_VIEW_VERTICAL_MARGIN. This means – as far as I can tell from…

Read more