import { Intersection , PerspectiveCamera , Raycaster , Vector3 } from "three" ; import { Offset } from "../../../services/HtmlDomService" ; import { SoftVis3dMesh } from "../domain/SoftVis3dMesh" ; export class SelectionCalculator { public static RAYCASTER = new Raycaster ( ) ; public static makeSelection ( x , y , width , height , camera , objectsInView ) { const mouseDownX = ( x / width ) * 2 - 1 ; const mouseDownY = - ( y / height ) * 2 + 1 ; const vector = new Vector3 ( mouseDownX , mouseDownY , 1 ) . unproject ( camera ) ; const cameraPosition = camera . position ; SelectionCalculator . RAYCASTER . set ( cameraPosition , vector . sub ( cameraPosition ) . normalize ( ) ) ; const intersected = SelectionCalculator . RAYCASTER . intersectObjects ( objectsInView , true ) ; let result = null ; if ( intersected . length > 0 ) { const object = intersected [ 0 ] . object as SoftVis3dMesh ; result = object . getSoftVis3dId ( ) ; } return result ; } public static calculateSelectionPosition ( event , offset ) { let x = event . clientX + document . body . scrollLeft + document . documentElement . scrollLeft ; let y = event . clientY + document . body . scrollTop + document . documentElement . scrollTop ; x -= offset . left ; y -= offset . top ; return { x , y } ; } }