Get the distance between two objects on mousemove

i need to calculate the distance between the two objects in three js. suppose an object already present at some position and when i drag another object besides or top or bottom of the previous object, the distance will show in the canvas…

see the image for detail.

image

any help will be greatly appreciated…

Do you want to calculate the distance between the center points of the objects? Or between their bounds?

between their bounds…

It’s computationally expensive to find the closest distance between to meshes. You might want to approximate both meshes with an AABB and compute the distance between both bounding volumes.

can u please explain. cant understand what did you tried to mean…

Read this to understand why it’s expensive to compute the closest point between meshes.

The following post explains the computation between the distance between two AABBs.