Skip to content

Commit

Permalink
feat(experimental): optionally handle 360 icon intersection (#4539)
Browse files Browse the repository at this point in the history
* feat(experimental): optionally handle 360 icon intersection

* chore: lint fix
  • Loading branch information
haakonflatval-cognite authored May 28, 2024
1 parent 3aedf46 commit f437f76
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
33 changes: 27 additions & 6 deletions viewer/packages/api/src/public/migration/Cognite3DViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1554,23 +1554,29 @@ export class Cognite3DViewer {
* ```
*/
async getIntersectionFromPixel(offsetX: number, offsetY: number): Promise<null | Intersection> {
if (this._image360ApiHelper !== undefined) {
const image360Intersection = this._image360ApiHelper.intersect360ImageIcons(offsetX, offsetY);
if (image360Intersection !== undefined) {
return null;
}
if (this.isIntersecting360Icon(new THREE.Vector2(offsetX, offsetY))) {
return null;
}
return this.intersectModels(offsetX, offsetY);
}

/**
* Raycasting model(s) for finding where the ray intersects with all models, including custom objects.
* @param pixelCoords Pixel coordinate in pixels (relative to the domElement).
* @param options
* @param options.stopOnHitting360Icon
* @returns A promise that if there was an intersection then return the intersection object - otherwise it
* returns `null` if there were no intersections.
* @beta
*/
public async getAnyIntersectionFromPixel(pixelCoords: THREE.Vector2): Promise<AnyIntersection | undefined> {
public async getAnyIntersectionFromPixel(
pixelCoords: THREE.Vector2,
options?: { stopOnHitting360Icon?: boolean }
): Promise<AnyIntersection | undefined> {
if ((options?.stopOnHitting360Icon ?? true) && this.isIntersecting360Icon(pixelCoords)) {
return undefined;
}

const modelIntersection = await this.intersectModels(pixelCoords.x, pixelCoords.y, { asyncCADIntersection: false });

// Find any custom object intersection closer to the camera than the model intersection
Expand All @@ -1588,6 +1594,21 @@ export class Cognite3DViewer {
}
return undefined;
}

private isIntersecting360Icon(vector: THREE.Vector2): boolean {
if (this._image360ApiHelper === undefined) {
return false;
}

const image360Intersection = this._image360ApiHelper.intersect360ImageIcons(vector.x, vector.y);

if (image360Intersection !== undefined) {
return true;
}

return false;
}

/**
* Check for intersections with 360 annotations through the given pixel.
* Similar to {getIntersectionFromPixel}, but checks 360 image annotations
Expand Down
4 changes: 3 additions & 1 deletion viewer/reveal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ export class Cognite3DViewer {
get360ImageCollections(): Image360Collection[];
getActive360ImageInfo(): Image360WithCollection | undefined;
// @beta
getAnyIntersectionFromPixel(pixelCoords: THREE.Vector2): Promise<AnyIntersection | undefined>;
getAnyIntersectionFromPixel(pixelCoords: THREE.Vector2, options?: {
stopOnHitting360Icon?: boolean;
}): Promise<AnyIntersection | undefined>;
// @deprecated
getClippingPlanes(): THREE.Plane[];
getGlobalClippingPlanes(): THREE.Plane[];
Expand Down

0 comments on commit f437f76

Please sign in to comment.