Retrieving X , Y and Z coordinates of model

Hi everyone!
I’ve been trying to gauge the distance between two points. As I googled it first I come up with this link.
However, I can only get X and Y coordinates but I also need to get Z since I try to calculate distances between 2 points in 3d model

const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();

function onMouseMove( event ) {

// calculate mouse position in normalized device coordinates
// (-1 to +1) for both components

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

I tried to create a Vector3D object but still can’t manage to get the Z value since the event object does not have a function for getting the Z

I’d be so grateful if anyone could help me with the issue

2 points in 3D space or on the screen? :thinking:

Are you looking for something like this? [SOLVED]Mesure distance between two points on a object by clicking


in 3D space… I can only get X and Y coordinates but not Z

But distance is a number - not a vector - it doesn’t have x, y, or z. :thinking:

See link @prisoner849 shared. To get distance between 2 points in 3D it’s usually enough to subtract these points:

const positionA = obj.position;
const positionB = obj.position;
const difference = new Three.Vector3().subVectors(positionB, positionA);

const distanceTotal = difference.length();

const distanceXAxis = Math.abs(difference.x);
const distanceYAxis = Math.abs(difference.y);
const distanceZAxis = Math.abs(difference.z);
1 Like

This was exactly what I’ve been looking for . I was also thinkig to add a mesh at the endpoints of the line. This is a brilliant solution. I was thinking of getting to coordinates of 2 points and calculate it by myself but thats much better! Thanks a lot!

1 Like

@prisoner849 codepen solution helped me to get the solutions. Thanks btw