Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(experimental): optionally handle 360 icon intersection #4539

Merged
merged 5 commits into from
May 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions viewer/packages/api/src/public/migration/Cognite3DViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1554,11 +1554,8 @@ 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);
}
Expand All @@ -1570,7 +1567,14 @@ export class Cognite3DViewer {
* returns `null` if there were no intersections.
* @beta
*/
public async getAnyIntersectionFromPixel(pixelCoords: THREE.Vector2): Promise<AnyIntersection | undefined> {
public async getAnyIntersectionFromPixel(
pixelCoords: THREE.Vector2,
options?: { breakOnHitting360Icon?: boolean }
): Promise<AnyIntersection | undefined> {
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
Expand All @@ -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
Expand Down
Loading