Skip to content

SelectionPlugin ​

Higher-level selection workflows on top of SelectionService: click-to-select, region selection, focus-on-selection, neighbour selection. Activating the plugin enables hover and selection on the service.

Usage ​

ts
import { ViewerCore, SelectionPlugin } from "@optellix/xviewr-sdk";

const viewer = new ViewerCore(container, config);
await viewer.ready();
await viewer.loadPlugin(new SelectionPlugin());

const selection = viewer.pluginManager.getPlugin("selection") as SelectionPlugin;
selection.selectAll();
selection.focusOnSelection();

Service dependencies: selection, camera. On activate, the plugin enables enabled, hoverEnabled, and selectableOnly on the service config and activates it.

Since 4.0 ​

  • Canvas-scoped input: pointer events are captured on the renderer canvas element only, not window. Events that started outside the canvas do not affect selection.
  • Clipped raycast: clickToSelect(x, y) and the underlying service raycast filter hits against the active cross-section clipping planes.
  • Edge hover and edge selection highlights: hovering or clicking loaded STEP edge overlays produces a LineSegments2 highlight; edge and mesh highlights are managed independently.
  • Advanced neighbour selection: selectNeighbourByContact and selectNeighbourByRadius route through AdvancedMeshService for spatial-hash / BVH backed neighbour discovery. Options include contact depth, contact threshold, and radius centerMode.
  • Region selection modes: selectByScreenRegion(startX, startY, endX, endY, options?: SelectByScreenRegionOptions) accepts a mode: "intersects" | "contains" for AABB-projected box selection.

Public API ​

MethodDescription
clickToSelect(x, y)Raycast at screen pixel (x, y), select hit object, or clear selection if nothing hit. Returns selected objects.
selectObject(object, addToSelection?)Select a single object. addToSelection defaults to false.
deselectObject(object)Remove an object from selection.
clearSelection()Empty the selection set.
selectByRegion(startX, startY, endX, endY)Screen-rect selection. Delegates to SelectionService.selectByScreenRegion using the plugin's boxSelectionConfig (mode: "intersects" | "contains", addToSelection).
focusOnSelection()Fit the camera to the bounding box of selected objects.
toggleSelection(object)Add if absent, remove if present.
invertSelection()Invert the current selection across the scene.
selectAll()Select every selectable object.
selectNeighbourByContact(depth?)Expand selection to contact-adjacent meshes. depth defaults to 1.
selectNeighbourByRadius(radius, options?)Expand selection to meshes within radius of any selected mesh.
getSelectedObjects()Returns the current selected Object3D[].
isSelected(object)Boolean check.
setHoverObject(object | null)Programmatic hover.
getHoveredObject()Returns current hover target.
updateConfig(config)Partial update of SelectionConfig.

Events ​

The plugin re-uses the events emitted by SelectionService on the bus (e.g. selection:object-selected). It does not emit its own events.

Example ​

ts
const selection = viewer.pluginManager.getPlugin("selection") as SelectionPlugin;

container.addEventListener("click", (e) => {
  const rect = container.getBoundingClientRect();
  selection.clickToSelect(e.clientX - rect.left, e.clientY - rect.top);
});

selection.selectNeighbourByRadius(0.5);
selection.focusOnSelection();

XViewr SDK and xConvert CLI documentation.