Finding offset of intersected raycaster object

If I use this to get local coordinates of an insersected object. Currently using mouse coordinates for a set.


Is there a way to work out the offset it is from the start and end bounding box position coordinates ?

I need to determine the range, and then turn it into a percentage. To change the scale using percentage of another mesh.

I’m not sure this approach is the right one for you but maybe it will help as an orientation.

  • Compute the bounding box of your geometry with geometry.computeBoundingBox()
  • When there is an intersection, copy the box and apply the world matrix of your intersection object via box.applyMatrix4( object.worldMatrix ) (You don’t want to change geometry.boundingBox).
  • Calculate the displacement vectors between the intersection point (in world space) and the min/max vectors of the bounding box by vector subtraction.
  • If you need the distance between your intersection point and the min/max vectors, calculate the length of the displacement vectors from the previous step via .length().

Thanks. apologies I figured it out not long after. It required nutting out some maths from min and max bounding box.

The min and max bounding box on the goemtry is

 var maxX = INTERSECTED.mesh.geometry.boundingBox.max.x;
 var minX = INTERSECTED.mesh.geometry.boundingBox.min.x;

Then I get the local point and a percentage of that range. The min and max for me was -1 and 1. The local point is anywhere between that.

 var localPoint = INTERSECTED.mesh.worldToLocal(INTERSECTED.point);
 var currentX = localPoint.x;
 var pos = (currentX - minX) / (maxX - minX);

Then I do a scale from that percentage. The max scale for the bar is 1. So 1 is hardcoded there.

bar.progress.scale.x = pos * 1;

If there a better methods. I have not seen any.

1 Like