Keep in mind the thread you linked is from 2011-2012 - it’s nice and nostalgic, but at the very least, it is also risky to use it as a source of information.
Since you need to add an additional dimension, you can try either:
Use a Raycaster to cast a ray on your 3D scene - it will return a 3D position of mouse cursor as long as the cursor is over a 3D object on the scene.
Place a PlaneBufferGeometry parallel to the viewport, in front of the camera - at any depth you’d like. Then use Raycaster to cast mouse position onto that plane (this can be useful, if you need a 3D position of the mouse at a specific depth level, regardless of whether there’s any object there or not.)
Thanks for the quick response, its really like a sunshine for me.
I am following the 2nd way but i am getting always getting point in xz plane due to my code and i am new to THREE js so i dont know how to make it work in all the direction
let plane = new THREE.Plane();
plane.setFromCoplanarPoints(new THREE.Vector3(), new THREE.Vector3(1, 0, 0), new THREE.Vector3(0, 0, 1));
Can you please help me with this so i can get points in x,y,z in all the planes
Hm - I don’t understand how you’d imagine that to behave
If you use the second option, z-value is the z-position of the plane - so it’s kinda faked, otherwise z is any value between -Infinity and +Infinity (there’s no way to determine depth without a reference object / point.)
If you’d like z to be taken from object over which mouse is placed, you can try the first option.
so due to my plane settings i am able to create a dynamic line in x,z plane but i need this line to measure distance like a measurement tool so i can move in all the direction so your first point is not valid to my use case
In your example its only working when the mouse is over the point cloud but in my use case we may have objects at the plane or in the air so let say one object is at ground and one is in the air so i need to measure the distance between them and also show it like a measurement tool so how i can
[…] we may have objects at the plane or in the air so let say one object is at ground and one is in the air […]
I don’t understand how that’s different - please take a look at the example and the code, try to use it before judging that’s not it.
(Position in 3D space has no context of “being on the ground” or “being in the air”. You can raycast any 2 objects and calculate the difference / line between hit points - these are just vectors.)
No worries. If you get to a point that you get stuck on something specific - and can share a live example on codepen / jsfiddle - it’ll be much easier to help you out.
But please try things before judging they just won’t work.