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.

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)Naive grid-sample raycast within a screen rectangle and additively select all hits.
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.