Section planes
Start section planes on the sides of the models, on a right-clicked face or as a section box around them, let the user place and drag planes with Ctrl + left drag, list the planes by name, and remove them one by one or all at once.
A Section plane cuts the loaded models along a plane and draws hatched end caps where solids are cut; a section box cuts with six planes at once. Both are managed by the SectionPlanes object of the viewer. The planes cut the models only: GIS layers (3D Tiles such as the 3D BAG, uploaded GIS layers, terrain and imagery) stay whole around them.
Up to six planes cut at the same time, one per normal. Every way of starting one takes the next free one of six slots, so the planes a user places sit next to each other: a top plane, then a plane on a wall's face, then a second one on another face. A new plane with the normal of one that cuts already (within 1°) takes that plane's slot and replaces it: a second plane facing the same way would only cut where the first does. While all six cut with other normals, nothing new starts; a section box takes all six. Your code and your users tell the planes apart by their names, never by slot.
Before you start#
You have a viewer with models loaded (Embed the viewer). The bounds the planes start from are the main bounds of the loaded models (viewer.getMainBounds()), which leave out geometry such as far-away lines.
Steps#
-
Start a standard plane.
startStandardPlane(side)places a plane on the top, bottom, left, right, front or back of the box around the models, named Top, Bottom and so on, and returns itsSectionPlane;startTopPlane()and the other five starters are the same calls. A new standard plane replaces the plane that cuts with its normal, or else takes the next free slot, and leaves the other planes alone. Started again, a standard plane that cuts already goes back to its place on that side, keeping its name.nullwhen no model is loaded or all six slots cut.JavaScript#const sectionPlanes = viewer.getSectionPlanes(); const top = sectionPlanes.startStandardPlane("top"); const left = sectionPlanes.startStandardPlane("left"); // a second plane: the top one stays // "bottom", "right", "front", "back"; or startTopPlane(), startLeftPlane(), ... top.disable(); // remove this oneAn option moves a standard plane through a point of your own, keeping the side's normal, for a cut at a storey's elevation:
startStandardPlane("top", {coordinate}). -
Or start a box.
startSectionBox()puts a box around the main bounds, or around the bounding box you pass; it takes all six slots, in place of the planes there are. Its faces are listed as the six standard planes, and dragging one resizes the box. Once a face is removed or put back withstartStandardPlane, the other faces stay where they are, as planes of their own.JavaScript#const box = sectionPlanes.startSectionBox(); -
Let the user work with the mouse. With the default bindings, Ctrl + left drag on an object starts a new plane on the face under the pointer and moves it while dragging; Ctrl + left drag on a plane where no object is under the pointer moves that plane, and a plane's icon drags it from anywhere. While all six slots cut, Ctrl + left drag only moves planes. The binding is the
sectionaction (reference/viewer3d/key-bindings#section) and can be moved to another button in a navigation mode. -
Clear.
plane.disable()removes one plane and frees its slot;sectionPlanes.disableAll()(orviewer.disableSectionPlanes()) removes every plane and box, cut and visualisation alike.
List, name and remove the planes#
The BIM.works Sections menu lists the planes that cut by name, shows a plane in the view while the pointer is on its row, hides or shows it with its eye, renames it on a click and removes it with its cross. The same calls give your application such a list:
| Call | What it does |
|---|---|
sectionPlanes.getPlanes() |
The planes that cut, oldest first: single planes and the faces of a box alike. |
sectionPlanes.onPlanesChange(fn) |
Calls fn when a plane is started or put back, removed, renamed, hidden or shown, or a box is started; not while a plane is dragged. Returns the unsubscribe. |
plane.getName(), plane.setName(name) |
Top and so on for a standard plane and a face of a box, Plane 1, Plane 2 and so on for a plane on a face, or a name of your own. An empty name throws. |
plane.getStandard() |
"top", "bottom", ... for a standard plane, null for a plane on a face. |
plane.setHighlighted(true) |
Shows the plane as hovered, as when the pointer is on its icon; false stops it. |
plane.setVisible(false), plane.isVisible() |
Hides the plane while it keeps cutting (how-to/viewer3d/section-planes#hide); true draws it again. |
sectionPlanes.canStartPlane(normal?) |
Whether another plane fits; false while all six slots cut. With a normal, also true when one of them cuts with that normal, as the new plane replaces it. |
const list = document.querySelector("#planes"); // a <ul> of your own
function renderList() {
list.replaceChildren(...sectionPlanes.getPlanes().map((plane) => {
const row = document.createElement("li");
row.textContent = plane.getName();
row.onmouseenter = () => plane.setHighlighted(true);
row.onmouseleave = () => plane.setHighlighted(false);
const remove = document.createElement("button");
remove.textContent = "×";
remove.onclick = () => plane.disable(); // the list follows through onPlanesChange
row.append(remove);
return row;
}));
}
sectionPlanes.onPlanesChange(renderList);
renderList();getState() keeps the names, the standard planes, which planes are hidden and the order of the list, so setState gives a user's planes back as they were.
Hide a plane that keeps cutting#
A plane draws its face, its wireframe and its drag icon over the model. When the cut is what matters, for a screenshot or for annotations in the view from above, setVisible(false) hides the plane while it keeps cutting: the model stays cut, with its end caps, and the plane stays in getPlanes(). A hidden plane is not hovered, highlighted or grabbed with Ctrl + left drag, so the user cannot move it; your code still can. A SectionBox has the same method for all six faces.
const top = sectionPlanes.startTopPlane();
top.setVisible(false); // the model stays cut; no plane, wireframe or icon over it
top.isVisible(); // false
const box = sectionPlanes.startSectionBox();
box.setVisible(false); // all six faces; box.isVisible() is null while they differ- Every new plane and box is drawn. A standard plane put back with
startStandardPlanestays hidden, as it keeps its name. getState()keeps whether each plane, and each face of a box, is drawn, andsetStatehides them again.sectionPlanes.showIconsshows the icons of the planes that are drawn; a hidden plane has none.
Start a plane from a context menu on a face#
The context menu of the BIM.works 3D view has a Section plane entry: it starts a plane on the face that was right-clicked, cutting away what lies on the camera's side of that face, and the user then drags the plane into the model by its icon. The public API gives your application the same in three calls:
| Call | What it does |
|---|---|
The rightMouseClick(event, qid, pick) setting |
Called on a right click on the canvas after the viewer has picked what is under the pointer. qid is the Qid of the object, null over empty space. pick is a PickResult: qid, coordinate (the point hit) and normal (the unit face normal, facing the camera); the vectors are null when no surface was hit, and pick itself is null when the viewer could not pick. |
viewer.getSectionPlanes().startPlaneAt(coordinate, normal) |
Starts a new plane through coordinate that cuts away the side normal points to, and returns its SectionPlane; null when no model is loaded or all six slots cut. A zero normal throws. |
objectStateManager.setToSelectionSet([]) |
Optional: the app also clears the selection (ObjectStateManager). |
Keep the pick of the right click for the menu's action: its vectors are copies, so a later pick does not change them. When your interface picks at another moment, for example a tool that waits for the next click on a face, await viewer.pick(x, y) returns the same PickResult for a canvas position in CSS pixels (event.offsetX and event.offsetY of an event on the canvas).
Every call starts another plane in the next free slot, named Plane 1, Plane 2 and so on, as Ctrl + left drag does, and the other planes stay; a plane that cuts with the same normal is replaced instead, in its slot; plane.setName gives it a name of your own. Coordinates are in the viewer's render space, millimetres with the global base translation included; pass the picked values through unchanged.
Annotations on the cut-away side#
A plane hides the annotations on the side it cuts away, as it hides the geometry there. setAnnotationMode on a SectionPlane chooses per plane what happens to them instead; a SectionBox has the same method, which sets all six faces at once.
| Mode | The annotations this plane cuts away |
|---|---|
"hide" |
are hidden. The default. |
"ignore" |
stay where they are: this plane does not hide them, another plane still can. |
"project" |
stay visible, drawn on this plane: each is moved along the plane's normal onto it. |
const top = sectionPlanes.startTopPlane();
top.setAnnotationMode("project"); // the labels of the floors above sit on the cut
const box = sectionPlanes.startSectionBox();
box.setAnnotationMode("ignore"); // the box hides no annotation- Annotations on the side a plane keeps are never affected.
- With several planes, every
"project"plane first moves the annotation onto itself, so a box of"project"faces keeps the annotations inside the box; the annotation is then hidden when a"hide"plane cuts where it ended up. getAnnotationMode()returns the current mode; on a box it returnsnullwhile the faces differ. A box that is no longer the active one (a plane or another box was started) ignoressetAnnotationMode.- A section plane's drag icon is never hidden by a plane, its own or another, as the planes themselves are drawn whole. The drag icons of movable planes keep being hidden by every plane that cuts them, whatever its mode.
How far past the plane#
"ignore" and "project" have no limit: a plane through the 3rd floor of a 30-storey tower keeps the annotations of all 27 storeys above it. setAnnotationReach(mm) limits how far past the plane its mode goes: an annotation further along the normal on the side the plane cuts away is hidden, whatever the mode. A SectionBox has the same method, for all six faces.
const top = sectionPlanes.startTopPlane();
top.setAnnotationMode("project");
top.setAnnotationReach(3500); // the storey above sits on the cut, the storeys above that are hidden
const box = sectionPlanes.startSectionBox(await viewer.getObjectsAabb(storeyQids)); // around one storey
box.setAnnotationMode("project");
box.setAnnotationReach(3500); // the storeys just above and below sit on its top and bottom faces- The distance is measured from the annotation's own position, before a
"project"plane moves it, in millimetres along the plane's normal.Infinityis no limit, the default;0hides everything past the plane, as"hide"does. - The reach belongs to its plane: it moves along when the plane is dragged.
getAnnotationReach()returns it; on a box it returnsnullwhile the faces differ.
Defaults for the planes a user draws#
Every start of a plane or box (the starters, startPlaneAt, Ctrl + left drag, the face widget, startSectionBox) begins with the mode and reach of sectionPlanes.annotationDefaults, {mode: "hide", reach: Infinity} unless you change it. Setting it is how an application gives the planes its users draw a mode and reach, since no code runs for them after they start; the planes already started keep theirs, and a field left out keeps its value.
sectionPlanes.annotationDefaults = {mode: "project", reach: 3500};The realtime settings sectionPlaneAnnotationMode and sectionPlaneAnnotationReach give the defaults a viewer starts with; a value the viewer does not know is ignored.
To switch between the three on a live model, a button each, see how-to/viewer3d/annotations#section-plane-modes, and on a plane from the top through a storey, how-to/viewer3d/annotations#section-plane-from-above.
Movable planes#
A movable plane looks and drags like a section plane but cuts nothing: it is a plane with a drag icon that your application reads, for example to cut a vector drawing where the user puts it (how-to/rendering/export-a-vector-drawing#a-cut-plane-that-follows-the-viewer). There can be any number of them, next to the section planes.
| Call | What it does |
|---|---|
viewer.getMovablePlanes().addTopPlane() |
Places a plane at the top of the model, like the Top section plane but without cutting. null when no model is loaded. |
addAxisPlane([1, 0, 0]) |
Places one upright at the far side of the model along a world axis, so that a drag moves it over that axis. |
addPlane(coordinate, normal) |
Places one anywhere. |
A plane fires move on every drag step, moveEnd when a drag ends, and remove once, to the listeners of addListener. Its normal and offset (the position along the normal) are what a vector export takes as its direction and cut; setOffset and setCoordinate move it from code. The left button drags it along its normal, and the middle button on its icon removes it; list(), remove(plane) and removeAll() on getMovablePlanes() manage them. Coordinates are render space, millimetres with the global base translation included.
Appearance#
sectionPlanes.hatching = false switches the hatched end caps off and true on again. Section culling (skipping the objects that are entirely on the removed side) is off by default and is enabled with the sectionCulling realtime setting.
Check#
startTopPlane() shows the model cut horizontally with a hatched cap; startStandardPlane("left") then cuts it from the left as well, and getPlanes() names both, Top and Left; setVisible(false) on Top takes its plane, wireframe and icon away and leaves the cut and its cap; disableAll() restores it whole. With annotations above the cut, they disappear; after setAnnotationMode("project") on that plane they show again, on the cut, and after setAnnotationReach only those within that distance of it. Section plane on a right-clicked wall shows the plane on that wall's face, with its icon; dragging the icon into the wall cuts it.