Reacting to clicks in point cloud models
While point clouds doesn't have a concept of nodes, applications can detect clicked points. Just like with
CAD models, Cognite3DViewer.getIntersectionFromPixel
is used to determine world position and point from
a mouse click.
Detecting clicked positions
The following example detects intersections at clicked positions and marks the intersected positions using a red sphere.
Getting information about object assigned to a clicked point
Using Cognite's Annotations API or Cognite's 3D Contextualization Editor in CDF , a user can define objects within a point cloud model.
In order to retrieve information about a clicked object, users may get the annotationId
or the volumeInstanceRef
or the assetRef
that is assigned to each point.
The annotationId
and assetRef
or volumeInstanceRef
and assetRef
are available in the intersection
object returned from viewer.getIntersectionFromPixel
.
An annotation id of 0 and a volumeInstanceRef of undefined
means that the clicked point is not assigned to any object. assetRef
will only be defined if the annotation associated with the point is linked to an asset in CDF. The objects in this point cloud example have no assets associated to them.
Cognite core data model point cloud volume click example
viewer.on('click', async event => {
const intersection = await viewer.getIntersectionFromPixel(
event.offsetX, event.offsetY
);
if (intersection) {
alert(`Clicked object with point cloud volume reference externalId ${intersection.volumeInstanceRef.externalId} and assetId ${intersection.assetRef?.id}`);
};
});