Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SnapPointPicker

Helper class for implementing Snap-to features in an application

To snap to a point on while checking if the point is visible (not obscured by the model(s)):

   // Get the ray at mouse position
  const ray = myViewer.rayFromMouseCoordinate(myView, event.clientX, event.clientY);

  // Find the radius to use based on model extent
  const modelBoundingBox = myModel.getBoundingBox();
  const radius = modelBoundingBox.getExtent().getLength()/100;
  let closestPoint = null;

  // Snap to point, check if visible
  const snapPointPicker = new cee.SnapPointPicker(myView, ray, radius);
  const pointIndex = snapPointPicker.findClosestPoint(myHotSpots);

  if (pointIndex >= 0) {
      closestPoint = new cee.Vec3(myHotSpots[3*pointIndex],
         myHotSpots[3*pointIndex + 1], myHotSpots[3*pointIndex + 2]);
  }

To just find the closest point to the view, not checking the model if the point is visible:

  // Snap to closest point, not checking the model
  const pointIndex = cee.RaySphereIntersector.findClosestIntersectedSphereToRay(ray, radius, g.hotSpots);

  if (pointIndex >= 0) {
      closestPoint = new cee.Vec3(g.hotSpots[3*pointIndex],
         g.hotSpots[3*pointIndex + 1], g.hotSpots[3*pointIndex + 2]);
  }

Hierarchy

  • SnapPointPicker

Index

Constructors

Methods

Constructors

constructor

Methods

findClosestPoint

  • findClosestPoint(pointsArr: ArrayLike<number>): number
  • Find the point closest to the ray that is visible (not obsured by the model).

    The radius determines the maximum distance from the point in order to snap to it.

    The pointsArr array contains a number of points (sphere centers) in a 1d array: <s1.x, s1.y, s1.z, s2.x, s2.y, s2.z> ...

    Returns the index of the closest visible point. -1 if there was not hit.

    Parameters

    • pointsArr: ArrayLike<number>

    Returns number

Generated using TypeDoc