Getting mouseposition outside of Editor Window in Scene View

So I have an Editor Window which has a bunch of OnGUI() code. In that code I’m triggering a function in another script. In that function I’m trying to get the mouse’s accurate position inside the scene view (outside the aforementioned editor window), normalized according to the scene view’s width and height.

Here’s the code:

Vector3 mousePos;

mousePos.x = Event.current.mousePosition.x / SceneView.lastActiveSceneView.camera.pixelRect.xMax * -1;

mousePos.y = Event.current.mousePosition.y / SceneView.lastActiveSceneView.camera.pixelRect.height * -1;

mousePos.z = 1000;

Ray ray = SceneView.lastActiveSceneView.camera.ViewportPointToRay(mousePos);

The resulting ray is hugely inaccurate. And I have no idea where the mouse position is gotten from, as it sometimes gives some absolutely ridiculous values. I also have to multiply the mousePos values by -1, because getting the mouse position gives me negative results (because why not?).

If anyone could help me understand why this returns values out of this world, that’d be great. I’ve been trying to get this to work for a few days now, and this one is really making me pull my hairs out.

Thanks,
TAP

Have a look here:

https://forum.unity.com/threads/mouse-position-in-scene-view.250399/#post-3760579