I'm using following code to get 2D coordinates on 3D point "p" on screen:
var v = p.clone().project(camera);
var percX = (v.x + 1) / 2;
var percY = (-v.y + 1) / 2;
if (v.z > 1) {
console.log('point behind camera')
}
var x = percX * window.innerWidth;
var y = percY * window.innerHeight;
This works fine for points in front of camera. But as camera moves towards the point, point moves slowly out of screen (as it should, I'm moving not directly towards it), e.g. to upper right corner. I'm drawing line from center of screen to that point. But when point leaves the screen, it's 2D coordinates become nonsensical. It is still somewhere in upper right corner but it's 2D [x,y] shows it elsewhere.
Is it possible to calculate point's 2D position that would be somehow sane even when it's just left camera view?