Fade walls near the camera
Mark 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.
Looking inside a building otherwise means hiding walls or cutting with a section plane. The proximity fade does it for you: the objects you mark as soft occluders dither out when the camera gets near them, and while they are faded the mouse picks through them. Move away and they are back.
Live demo#
The fade is on when the demo starts. Zoom towards the building and push the camera through a wall; the walls, roof and windows in front of you fade and the rooms behind them show. The two sliders set where the fade starts and where it is complete, in model units; Automatic distances derives them from the size of the occluders.
Before you start#
You have a viewer with a model loaded (Embed the viewer). The soft-occluder set is an object state held by the ObjectStateManager, next to visible, selected and coloured, so every viewer connected to it fades the same objects.
Steps#
-
Choose the occluders. Put the envelope types in the soft-occluder set and set the distances:
const factory = new BimWorksClientFactory("https://bim.works"); const client = await factory.createClientWithApiToken("<your API token>"); const versionUuid = "<version uuid of the second demo model>"; const modelManager = new ModelManager(client); const osm = new ObjectStateManager(modelManager, { multiSelect: true, pickability: true }); const viewer = new Viewer3d(osm); await viewer.initializeViewer(); const toolbar = document.createElement("div"); const enableFade = document.createElement("button"); enableFade.innerText = "Fade enclosure near camera"; enableFade.addEventListener("click", async () => { // Walls, roofs and coverings fade out (and become pick-through) when the camera gets // close, so zooming towards the building automatically reveals the interior. // Slabs are excluded on purpose: fading the floor under the camera looks broken. await osm.setSoftOccluderSet("type IN (IFCWALL, IFCWALLSTANDARDCASE, IFCROOF, IFCCOVERING, IFCCURTAINWALL, IFCPLATE, IFCWINDOW, IFCDOOR)"); }); toolbar.appendChild(enableFade); const disableFade = document.createElement("button"); disableFade.innerText = "Clear soft occluders"; disableFade.addEventListener("click", async () => { await osm.setSoftOccluderSet([]); }); toolbar.appendChild(disableFade); const aggressive = document.createElement("button"); aggressive.innerText = "Wider fade range"; aggressive.addEventListener("click", () => { // Distances are in model units (usually mm): start fading at 15m, fully faded at 6m viewer.setProximityFadeConfig({fadeNear: 6000, fadeFar: 15000}); }); toolbar.appendChild(aggressive); document.body.style["flex-direction"] = "column"; document.body.appendChild(toolbar); document.body.appendChild(viewer.container); const version = await client.fs.getNodeVersion(versionUuid); await modelManager.addModels([version]); // Debugging convenience: expose the viewer and osm on the console window.viewer = viewer; window.osm = osm;Puts the envelope types in the soft-occluder set and changes the distances. Distances are in model units, usually millimetres.
setSoftOccluderSettakes a BQL condition or a set of Qids;addToSoftOccluderSetandremoveFromSoftOccluderSetedit the set. The envelope a camera has to get through is the useful set: the BIM.works app uses walls, windows and doors, the demo above adds curtain walls, roofs, coverings and plates. Leave slabs out: fading the floor under the camera looks broken. -
Tune the ramp.
viewer.setProximityFadeConfig({fadeNear, fadeFar, minRampRatio, smoothingTauMs})sets where the fade starts and where it is complete;"auto"for a distance derives it from the median height of the occluders. -
Or switch it on from a visualisation. BVL has the
SOFT_OCCLUDERandNO_SOFT_OCCLUDERverbs, so a visualisation action can switch the fade on for a type set (BVL).
The viewer setting proximityFade: {enabled: false} disables the feature entirely.
How it behaves#
The fade is computed in the vertex shader from the camera position and the 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.
In the app#
The Proximity group of the viewer's view options (the camera button in the toolbar) switches the fade on and off. Default fades walls, windows and doors; Custom takes a BQL condition of your own, as after WHERE in a query, and starts from the default's type IN (IFCWALL, IFCWINDOW, IFCDOOR). There is no key binding.
Limits#
An object without a bounding volume, or with a pick id outside the range the shader supports, is skipped with a warning in the console. The fade is one ramp for the whole set: there is no per-object distance.
Check#
Zoom into the building through a wall: the wall fades as the camera reaches it, and a click lands on what is behind it.