Hi guys… someone knows how to project mouse 2D position into World space with orthographic camera ?
Try this:
const vector = new THREE.Vector3();
vector.set( mouse.x, mouse.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) );
vector.unproject( camera );
BTW: You do not project. You unproject^^.
4 Likes
Although perhaps obvious to the initiated, I additionally had to convert to normalized device coordinates.
const { left, top, width, height } = e.currentTarget.getBoundingClientRect();
mouseWorld.set(
((e.clientX - left) / width) * 2 - 1,
-((e.clientY - top) / height) * 2 + 1,
(camera.near + camera.far) / (camera.near - camera.far),
);
mouseWorld.unproject(camera);
See also this stackoverflow thread.
1 Like