The intersects
result is empty in the code below when the camera type is orthographic. Can anyone please help with this?
private dblClick(event: MouseEvent) {
const mousePosition = this.getCanvasRelativePosition(event);
this.selectObject3D(mousePosition);
if (this.selected.isDefined) {
this.focusObject3D(this.camera, this.cameraControlService.cameraControl, this.selected.get);
}
}
private selectObject3D(mousePosition: MousePosition) {
// update the picking ray with the camera and mouse position
this.raycaster.setFromCamera(new Vector2(mousePosition.mouseX, mousePosition.mouseY), this.camera);
// calculate objects intersecting the picking ray
const intersects = this.raycaster.intersectObjects(this.dataLayer.children, true);
if (intersects.length > 0) {
const selectedObject = this.findObject3DRecursively(intersects[0].object);
if (selectedObject || (this.selected.isDefined && selectedObject.uuid !== this.selected.get.uuid)) {
this.object3DSelectionChange.next(RtSome(selectedObject));
this.selected = RtSome(selectedObject);
} else {
this.selected = RtNone();
this.object3DSelectionChange.next(RtNone());
}
} else {
this.selected = RtNone();
this.object3DSelectionChange.next(RtNone());
}
}
private getCanvasRelativePosition(event: MouseEvent): MousePosition {
const rect = this.renderer.domElement.getBoundingClientRect();
// calculate mouse position in normalized device coordinates
// (-1 to +1) for both components
const mouseX = ((event.clientX - rect.left) / rect.width) * 2 - 1;
const mouseY = - ((event.clientY - rect.top) / rect.height) * 2 + 1;
return { mouseX, mouseY };
}