There are several topics on how to get the 2d screen position of a 3d object in 3d space.
I was wondering how it works the other way around:
How can I get a position in 3d space according to a 2d position?
For example, how can I position a 3D object on the windows upper left corner?
So far I tried it like this:
https://github.com/cheesyeyes/19603.2d.screen.position/blob/master/src/index.js
https://cheesyeyes.github.io/19603.2d.screen.position/
function positionOnScreen(vector, object){
raycaster.setFromCamera( vector, camera );
var intersects = raycaster.intersectObject(plane);
if(intersects.length>0){
object.position.copy(intersects[0].point);
}
}
positionOnScreen(new Vector2(.8,.8), mesh1);
I am sending rays to a plane that is parallel to the screen, but I am pretty sure there must be a better way..