Get the coordinates from the intersection between a line and a mesh

Hello! So I’ve been trying to get the vertex from the intersections between a group of lines and a mesh, my project is hold by a lot of npm libraries so it’s gonna be hard to show a playground of it but let me explain.

There are lines in the ground that makes the shape of a shadow and there is the yellow base on the ground, I need on the shape to get the specific dots that intersect those lines.

(the shape in question)

Is there’s a function that can help me to achieve what I need? I just need to get the dots that intersects between the base and the shadow lines. Does a collision detection gonna help me achieve this? Remember that the shadows are lines, not meshes.

Edit: I made it to apply a collision detection (intersectsMesh function), the thing that I can’t find out yet is to detect the intersecting vertex, that function helps to do that?

Ray | Babylon.js Documentation might be useful.

1 Like

I’m gonna take a look at it, I got a few ideas of how to solve the problem

Ok, after implementing ray on my project it detects if there is an intersection or not, but what I can’t find is the next step, is there any function where I can get the coordinates of the intersection point?, I modified the base a bit and I added invisible lines to the coordinates of the base so I can grab that edge easier.

ray origin + ( returned length * ray direction ) ??

not exactly, I tried it but it doesn’t show me the point between the base edge and the shadow ray :frowning:

ray.intersectsMesh() return a PickingInfo object, which has the property “pickedPoint” that you’re looking for I think…


Thanks for the answer! I solved my problem using turf.js to get coordinates and then applying intersect and difference algorithms. I think doing it with the babylonJS way that I was thinking would be a longer route. But thanks for the answer!

1 Like