SnapPointPicker

class cee.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.rayFromCssCoordinate(myView, event.offsetX, event.offsetY);

// 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]);
}

Constructors


Constructors

SnapPointPicker.constructor(view, ray, radius)
Arguments:
  • view (View) – None

  • ray (Ray) – None

  • radius (number) – None

Return type:

SnapPointPicker

Methods

findClosestPoint

SnapPointPicker.findClosestPoint(pointsArr)
Arguments:
  • pointsArr (ArrayLike) – None

Find the point closest to the ray that is visible (not obscured 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.

Return type:

number