Thank, will look more into the ray method. Another problem with vertex lookup method is in case of large triangles, for example, considering a cube, I wont be able to find a point in the middle of the square but only in one of 4 vertices, which is a problem.
Yes, using a longer ray seems to be ok https://www.babylonjs-playground.com/#H8GZIG#31
but it points to the center, is there a way to find the closest triangle? The ray method doesnt work if it just points toward the center. For example this point should snap around eye bone, but due to the fact that the ray points towards the center, it ends inside the skull, which is wrong.
Maybe the best approach would be, correct if I’m wrong:
- find the closest 3 vertices (or triangle)
- cast a ray in the middle of that triangle
- pick location intersection from ray (or calculate triangle middle point)
or if there is a method to find the adiacent triangles of a point
- find closest point
- find adiacent(connected triangles)
- cast ray for each of them and measure distance
- return the triangle intersection with shorter ray distance