X-ray a set of objects
Put any set of objects in x-ray from code, without selecting them, so the viewer draws them with translucent faces and edges through the walls, floors and ceilings in front of them.
The ObjectStateManager keeps an x-ray set, and the 3D viewer draws the objects in it with translucent faces and edges through whatever hides them. Selection is not involved: selecting, deselecting or clearing the selection leaves the x-ray set alone. That lets a page show where all the columns, ducts or doors are while the user keeps clicking around. This is not X-ray selection, the older display option that draws the selection this way (how-to/using-bimworks/navigate-the-3d-viewer#selection-appearance).
Live demo#
The stairs are x-rayed when the demo starts: you see the stairwell through the façade. Orbit around the building to follow it. The buttons put the columns or the doors in the x-ray set instead, and the colour, opacity, Faces and Edges controls change how the set is drawn. Click an object to select it: selection works as before and is drawn on top of the x-ray. Hide them hides the x-rayed objects. Hidden objects are not x-rayed, but they stay in the set, so they come back x-rayed when you untick it.
Steps#
-
Fill the set.
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 xrayColumns = document.createElement("button"); xrayColumns.innerText = "X-ray the columns"; xrayColumns.addEventListener("click", async () => { // The x-ray set is independent of selection: these objects are drawn with translucent // faces and edges through the walls in front of them, and stay what they were otherwise await osm.setXRaySet("type = IFCCOLUMN"); }); toolbar.appendChild(xrayColumns); const orange = document.createElement("button"); orange.innerText = "Orange x-ray"; orange.addEventListener("click", () => { // Face color with the overlay opacity as alpha, then the edge color viewer.setXRayVisualization(new XRayVisualization([1, 0.5, 0, 0.25], "#ffd0a0")); }); toolbar.appendChild(orange); const clear = document.createElement("button"); clear.innerText = "Clear x-ray"; clear.addEventListener("click", async () => { await osm.clearXRaySet(); }); toolbar.appendChild(clear); 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;X-rays the columns with a BQL condition, switches to an orange style and clears the set again.
setXRaySettakes a BQL condition or a set of Qids and replaces the set.addToXRaySet,removeFromXRaySetandclearXRaySetedit it, andgetXRayQidsandisXRayedread it. -
Style it.
viewer.setXRayVisualization(new XRayVisualization(faceColor, edgeColor))sets the style: a face colour whose alpha is the overlay opacity, an edge colour, and switches for faces and edges. The default is blue, so the x-ray set is easy to tell apart from the green of X-ray selection. To change the current style, edit the object you get fromgetXRayVisualization()(faceColor,color,facesEnabled,wireframeEnabled) and pass it back tosetXRayVisualization.
How it combines with the other states#
- The set lives in the ObjectStateManager, so every 3D viewer connected to it x-rays the same objects. The 2D viewer ignores it.
- The x-ray is an overlay. The objects are still drawn normally underneath, keep their colour and stay pickable the same way as before. The overlay is drawn without depth testing, which is what makes it visible through other objects.
- Visibility wins. Hiding an x-rayed object removes its overlay but keeps it in the set. Section planes clip the overlay like the rest of the model.
- The selection is drawn after the x-ray: a selected object that is also x-rayed shows its selection highlight on top.
In the app#
The app has no control for the x-ray set yet. View → Selection → X-ray selection is the older, separate feature that x-rays the selection.
Limits#
Overlapping x-rayed faces add up their opacity, so a dense set looks darker where many objects overlap. Every x-rayed pixel is drawn once more, so x-raying a large part of a big model costs about as much as selecting it with X-ray selection. The overlay cannot be picked: clicking an x-rayed column behind a wall selects the wall.
Check#
After setXRaySet("type = IFCCOLUMN") the columns show through the façade; clicking another object selects it and the columns stay x-rayed.