From cbae4f0103ba7a1888223249a017ef875040695f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Mon, 27 May 2024 17:04:42 +0200 Subject: [PATCH 1/3] feat(experimental): optionally handle 360 icon intersection --- .../src/public/migration/Cognite3DViewer.ts | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/viewer/packages/api/src/public/migration/Cognite3DViewer.ts b/viewer/packages/api/src/public/migration/Cognite3DViewer.ts index 01c93bf4571..978bf6278eb 100644 --- a/viewer/packages/api/src/public/migration/Cognite3DViewer.ts +++ b/viewer/packages/api/src/public/migration/Cognite3DViewer.ts @@ -1554,11 +1554,8 @@ export class Cognite3DViewer { * ``` */ async getIntersectionFromPixel(offsetX: number, offsetY: number): Promise { - 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); } @@ -1570,7 +1567,14 @@ export class Cognite3DViewer { * returns `null` if there were no intersections. * @beta */ - public async getAnyIntersectionFromPixel(pixelCoords: THREE.Vector2): Promise { + public async getAnyIntersectionFromPixel( + pixelCoords: THREE.Vector2, + options?: { breakOnHitting360Icon?: boolean } + ): Promise { + if ((options?.breakOnHitting360Icon ?? 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 @@ -1588,6 +1592,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 From a457972282f7590dfe7a29ebd968ffc3a8d46897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Tue, 28 May 2024 09:17:30 +0200 Subject: [PATCH 2/3] chore: lint fix --- viewer/packages/api/src/public/migration/Cognite3DViewer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/viewer/packages/api/src/public/migration/Cognite3DViewer.ts b/viewer/packages/api/src/public/migration/Cognite3DViewer.ts index 978bf6278eb..c98b5bb2bbe 100644 --- a/viewer/packages/api/src/public/migration/Cognite3DViewer.ts +++ b/viewer/packages/api/src/public/migration/Cognite3DViewer.ts @@ -1563,15 +1563,17 @@ export class Cognite3DViewer { /** * 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, - options?: { breakOnHitting360Icon?: boolean } + options?: { stopOnHitting360Icon?: boolean } ): Promise { - if ((options?.breakOnHitting360Icon ?? true) && this.isIntersecting360Icon(pixelCoords)) { + if ((options?.stopOnHitting360Icon ?? true) && this.isIntersecting360Icon(pixelCoords)) { return undefined; } From 6e15d1b6aca22afc9ef5383f95a72621e00ba5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Tue, 28 May 2024 09:35:46 +0200 Subject: [PATCH 3/3] chore: update api --- viewer/reveal.api.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/viewer/reveal.api.md b/viewer/reveal.api.md index ae893efa01d..672bbe1c19b 100644 --- a/viewer/reveal.api.md +++ b/viewer/reveal.api.md @@ -438,7 +438,9 @@ export class Cognite3DViewer { get360ImageCollections(): Image360Collection[]; getActive360ImageInfo(): Image360WithCollection | undefined; // @beta - getAnyIntersectionFromPixel(pixelCoords: THREE.Vector2): Promise; + getAnyIntersectionFromPixel(pixelCoords: THREE.Vector2, options?: { + stopOnHitting360Icon?: boolean; + }): Promise; // @deprecated getClippingPlanes(): THREE.Plane[]; getGlobalClippingPlanes(): THREE.Plane[];