I am currently grappling with the task of determining the visible view width and height of a ThreeJS mesh object in pixel units.
In the image provided below, you can observe objects suspended in 3D space. Upon clicking the mouse, I need to be able to discern the exact view width and height they occupy in pixels. https://i.sstatic.net/esBr7.jpg
Due to my novice status in ThreeJS, finding a solution is proving to be time-consuming. Any help or guidance would be greatly appreciated.
The function outlined below showcases the various approaches I have been experimenting with.
getObjectSizeInViewSpace(object){
const size = new THREE.Vector3()
const box = new THREE.Box3().setFromObject(object).getSize(size)
size.project(this.camera)
let halfWidth = window.innerWidth / 2;
let halfHeight = window.innerHeight / 2;
size.x = (size.x*halfWidth)
size.y = (size.y*halfHeight)
return new THREE.Vector2(size.x,size.y)
}