How can I get the thickness of the plane (or box) with the aid of ray cast

Hello everyone

I want to get the thickness of the layers (which are planes in my model) with the aid of the ray cast.
here is my code for using ray cast to get the thickness, but it’s not working :

const ray = new BABYLON.Ray(new BABYLON.Vector3(0, 0, 0), new BABYLON.Vector3(0, 0, -1), 60);

    scene.onPointerObservable.add((evt, pickInfo) => {
        if (evt.pickInfo.hit) {

            let b1 = ray.intersectsMesh(box);
            let b2 = ray.intersectsMesh(box2);
            let b3 = ray.intersectsMesh(box3);
            let b4 = ray.intersectsMesh(box4);

            let d1 = BABYLON.Vector3.Distance(evt.pickInfo.pickedPoint, b1.pickedPoint);
            let d2 = BABYLON.Vector3.Distance(evt.pickInfo.pickedPoint, b2.pickedPoint);
            let d3 = BABYLON.Vector3.Distance(evt.pickInfo.pickedPoint, b3.pickedPoint);
            let d4 = BABYLON.Vector3.Distance(evt.pickInfo.pickedPoint, b4.pickedPoint);
            console.log("Dis", d1,d2,d3,d4)

  , 1, { x: evt.pickInfo.pickedPoint.x, y: evt.pickInfo.pickedPoint.y, z: evt.pickInfo.pickedPoint.z })
            console.log("G", evt.pickInfo.pickedPoint);
            impact.position = evt.pickInfo.pickedPoint;


actually I am trying to build something like the following app:

which is showing the thickness of the layers and showing them on the left chart.

how can I get the thickness of the planes when they are sticking together with just give the location on the top plane ?

and here is my PG:

What you can do is calculating the intersection of a ray that comes from “above” and that goes “down”, you get a point A.

Then calculate the intersection of a ray that comes from “below” and that goes “up”, you get a point B.

The thickness is the distance between A and B.

For eg, in your PG:

The code is computing the thickness of the green box: depending on where you click, you will get either 20 (which is the thickness of the box along the z axis) or 0 if the ray does not intersect the box.


It’s great ,You are incredible.
Thank you so much :pray: :pray: @Evgeni_Popov