---
title: Geometry and the viewers
summary: How an IFC file becomes triangles, how the viewers stream, cull, cache and place that geometry, why selection, x-ray and fade state live outside them, how walking finds the floor and the room, and what the server renders.
order: 80
see-also: [explanation/identifiers, explanation/alignment, how-to/rendering, explanation/geo-referencing-in-ifc, how-to/viewer3d, how-to/viewer3d/embed-the-viewer, tutorials/javascript-viewer, reference/viewer3d/key-bindings, how-to/debugging/javascript-logging]
terms: [derivative, mid, model-manager, object-state-manager, qid, section-plane, alignment, geo-reference, gis-layer, point-cloud, bvl]
---

# Geometry and the viewers

The viewers are the part of BIM.works most people see first and the part whose behaviour is hardest to guess from the outside: why a model needs processing before it can be shown, why loading is fast on the second visit, why selecting in the 3D view selects in the 2D view. This page explains the pipeline from file to pixels and the architecture of the JavaScript packages. The how-tos start at [[page:how-to/viewer3d]]; the course is [[page:tutorials/javascript-viewer]].

## From IFC to triangles

An IFC file contains geometry as parameters — extrusions, boolean operations, sweeps — not as triangles, and evaluating those parameters is expensive. BIM.works does it once, on the server, when a version is uploaded: the model is parsed, every product's representation is turned into triangle meshes, identical shapes are recognised and shared, per-object bounding boxes and an oriented bounding box are computed, floor plans are cut per storey, footprints and exterior surfaces are detected, and the result is written in the form the viewers consume. That output is part of the version's [[term:derivative|derivative set]], stored under its [[term:mid]], and it is why a version cannot be viewed until processing has completed — the viewers refuse a version without `im_metadata`, the summary that processing produces.

The viewer format is built for streaming: geometry is written in chunks that the browser can start drawing before the last one arrives, vertex positions are quantised to integers with a per-model unquantisation matrix (so a coordinate costs 16 bits instead of 32 or 64), positions are stored relative to the model's centre so that a building at survey coordinates does not lose precision in single-precision GPU arithmetic, and each chunk is compressed with zstd. The server negotiates the compression with the client and falls back to ordinary compression when a client cannot accept zstd. A large model — a million objects, hundreds of megabytes compressed — loads in seconds on a fast connection because nothing is evaluated on the client; it is decompressed, unpacked into GPU buffers and drawn.

## The two viewers and their shared state

`@bimworks/viewer3d` and `@bimworks/viewer2d` are the renderers. `@bimworks/viewercommon` holds what they share, and its two classes are the architecture.

The [[term:model-manager|ModelManager]] owns *which* versions are loaded. `addModels`, `removeModels`, `setModels`, `showModels` and `hideModels` take version objects, and every viewer attached to the manager reacts — loads the geometry, drops it, hides it. It also knows every loaded [[term:qid]], per model and per IFC type, which is the population that queries and visualisations resolve against.

The [[term:object-state-manager|ObjectStateManager]] owns the *state* of those objects: the visible set, the hidden set, the selected set, the colour overrides. Its methods accept a set of Qids or a BQL query; a query is resolved on the server into Qids, so `setToSelectionSet("type = IFCDOOR AND property.*.FireRating = null")` is one call. Every viewer attached to the same manager shows the same state, which is why a click in the 3D view highlights the object on the 2D plan: neither viewer holds selection; both listen to the manager. An application that needs two views with *different* states runs two managers over one ModelManager. The geometry stays the ModelManager's: the WebGPU viewer keeps it on the graphics card once for all its 3D viewers, each drawing it with its own state and camera ([[page:how-to/viewer3d/several-viewports]]). This is also the seam [[term:bvl|BVL]] plugs into: a visualisation is evaluated into sets and colours and applied through the state manager, not drawn by the viewer directly.

Two newer states follow the same pattern. The **soft-occluder set** names the objects that fade out as the camera comes close — the envelope of a building, so zooming in reveals the rooms ([[page:how-to/viewer3d/proximity-fade]]). The fade is computed in the vertex shader from the camera position and each object's bounds, so it costs nothing per frame on the CPU, and it applies to picking as well, which is what makes a faded wall click-through. The **x-ray set** names objects drawn through everything in front of them ([[page:how-to/viewer3d/xray-set]]): an overlay drawn without depth testing on top of the normal rendering, so the objects keep their colour and their picking. Because both are state rather than drawing, every 3D viewer connected to the manager fades and x-rays the same objects, and a selection made meanwhile is independent of them.

## Inside the 3D viewer

The 3D viewer renders with WebGL2, which is required. It can use web workers for decompression and unpacking so the main thread stays responsive, share buffers with them through `SharedArrayBuffer` where the page is cross-origin isolated and transfer ownership otherwise, and use WebGPU — not for rendering, but for compute: culling and the spatial queries behind picking and section planes run on the GPU when it is available, in WebGL or on the CPU when it is not. Each of these is a setting, and the package's defaults leave them off, so an embedded viewer with default settings does this work on the main thread and the CPU; the BIM.works UI switches them all on. Keeping workers off also suits build systems that mangle worker scripts. The settings and their defaults are on [[page:reference/viewer3d#technologyallowed]] and [[page:reference/viewer3d#spatialquerying]], and [[page:how-to/viewer3d/embed-the-viewer#same-origin-module-urls-and-workers]] says what workers need from the page.

With culling switched on (the [[page:reference/viewer3d#realtimesettings-culling|culling setting]], off in the package and on in the BIM.works UI), a spatial query decides after every camera move which objects are inside the view frustum and large enough on screen to be worth drawing; the rest are skipped. On top of that, distance-based culling and simplification keep very large scenes fluid while the camera moves, within a triangle budget measured from the frame rate; in the BIM.works UI the view options turn culling off or set a fixed budget. [[term:section-plane|Section planes]] and the section box cut geometry per fragment and draw hatched end caps on the cut; objects can opt out of sectioning through BVL. Picking is done by rendering object ids to an off-screen buffer, so it is exact and costs the same for a million objects as for ten. Screenshots, measurements, annotations, labels, navigation modes (default, walk, game, drone and custom ones; key bindings on [[page:reference/viewer3d/key-bindings]]) and view fitting are viewer features layered on the same pipeline. The reference grid is one more render layer with its own shader, drawn against the depth of the model; it is also a pickable surface, so the orbit pivot, the fly-to and the measuring tools work over empty ground, and its intersections are seeded into the vertex-snapping buffer ([[page:how-to/viewer3d/grid]]). The lasers and the object distance measure the triangles themselves, which the viewer reads back from the GPU on first use ([[page:how-to/viewer3d/measure]]).

## Walkable surfaces and the room you are in {#walkable-surfaces}

First-person walking needs more than triangles: where a person can stand, which edges are steps, where the doors are. The server derives that as a *walkable-surfaces* artifact from the geometry, and the viewer fetches it on the first walk and uses it for collision, ground clamping, step climbing and the jump to the next storey ([[page:how-to/viewer3d/walk-mode]]). Routes are computed over the same surfaces.

Knowing which room the camera is in is a separate, smaller index. Check-in writes a *space index* per model: for every `IfcSpace` (and `IfcSpatialZone` with geometry) the vertical range plus the floor and ceiling triangles of its footprint, in the model's own frame — a few hundred kilobytes for a large model. The viewer downloads it once and tests the eye against those prisms on camera changes, throttled and with a grace period at doors, mapping the camera into each model's frame so rotated and geo-placed models work. An L-shaped corridor does not claim the room in its notch, and a nested space wins over the wing that encloses it. The names, zones and extra features of every space are fetched with one query up front, so walking from room to room never queries the server.

## Caching and offline use {#caching}

Loading the same model twice should not stream it twice. The viewer has an IndexedDB cache for geometry chunks, keyed by the mid that *owns* the geometry — so a version created by a data-only transaction, which inherits its parent's geometry, replays the parent's cache instead of downloading again. The cache is off by default (`cacheGeometry` in the settings) because it takes disk space the embedding application may not want to spend; switch it on for kiosks and returning users.

Offline mode is a stronger contract for tablets and site use: while online, the application asks the viewer to *prepare* a set of versions, which fetches everything a load needs — version metadata, geometry metadata, geometry chunks, and for PDF models the tiles and vertices — into a dedicated store; then it switches the viewer to offline mode, in which no request leaves the browser and loading anything unprepared fails with a clear error. It is a viewing facility; queries and exports still need the server. GEO mode is not available offline, since map and terrain tiles are not prepared. [[page:how-to/viewer3d/work-offline]] shows the calls.

## LOCAL and GEO placement

In LOCAL mode each model is placed by its own coordinates, plus its [[term:alignment]] if it has one — right for the discipline models of one project. In GEO mode, which requires a [[term:geo-reference]] on every loaded model, the viewer lays a local east-north-up plane through the reference model's anchor and places every other model by the difference in geo position, computed in the browser from the stored references; [[term:gis-layer|GIS layers]] — imagery, terrain, 3D Tiles — are placed on the same plane, and the alignment composes identically in both modes. The switch is `setMode("LOCAL" | "GEO")`; [[page:how-to/viewer3d/geo-mode]] and [[page:explanation/geo-referencing-in-ifc]] have the rest.

## The 2D viewer, sheets, drawings and point clouds

The 2D viewer draws the per-storey floor plans BIM.works generated on the server, with WebGL: one plan per building storey, the storey most of the fitted objects are on shown on view fit, rotation options to align the plan with the model or an object axis, and the same selection, visibility and colour state as the 3D view. It draws IFC models only. A PDF is shown in the 3D viewer: by default the server renders its first page as a tiled raster with pickable vertices, which the viewer lays flat as one sheet, placed with the [[term:alignment]] like any other model. An instance configured with `pdf.pipeline: GEOMETRY` converts the pages into line and fill geometry instead, and each page becomes a sheet of the 3D viewer, the way the layouts of a DWG do.

DWG drawings are always converted to geometry: BIM.works reads the file itself, without a CAD library on the server, and converts it into the same geometry as every other model, so a drawing loads into the 3D viewer, is picked, sectioned and measured, and its paper-space layouts are sheets of the 3D viewer ([[page:how-to/viewer3d/dwg-drawings]]). A DWG has no geo reference and no object tree; it is placed with the [[term:alignment]], under the building it belongs to.

[[term:point-cloud|Point clouds]] (E57, LAS and LAZ) take a separate path: the file is decoded on the server — LAZ by BIM.works's own LASzip decoder, in parallel over the chunk table — the points are sorted into an octree, and the 3D viewer fetches octree chunks as the camera moves, so a scan of billions of points is browsable without loading it ([[page:how-to/viewer3d/point-clouds]]). They have no objects, so they are not part of the state model; they are placed by their geo reference next to the models they are compared with.

## Rendering on the server {#rendering-on-the-server}

The server renders too: the thumbnails of the tree, the screenshots of the API, the snapshots in a BCF export, the images and plans of a BRL report. It has an OpenGL and a Vulkan backend, and Vulkan has software devices — Mesa's lavapipe or SwiftShader run the same shaders on the CPU — so an instance without a GPU renders the same images, ten to fifty times slower. A software device is only used when the configuration allows it, so a production instance never slows down by accident ([[page:how-to/rendering/configure-the-render-backend]]).

Vector drawings are rendered differently from screenshots. The exporter decides the visibility of every product on the GPU with an id and depth raster, then writes what is visible as SVG: filled silhouettes in painter's order, edges from the model's stored line work, and the cut where a plane slices the building, capped so that what is inside a cut solid stays hidden. The result is deterministic, so a drawing is cached with its version and served again without rendering ([[page:how-to/rendering/export-a-vector-drawing]]).
