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
Show file tree
Hide file tree
Changes from all commits
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
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
Loading