Contents
How to move the closest point on mesh?
Move the point pt on (-0.28, -0.07, -1): It works. Move the point pt on (-0.28, 0.02, -1): It fails. This worked out fine for me, until I got a mesh from a client that had ridiculously long, thin tris, where the closest verts weren’t actuallt connected to the closest triangle. Any suggestions? Besides retopoing the mesh, obviously.
When do you know if a point is inside a mesh?
When at some point the face index returns -1, you know there are no more faces between the checked point and the end point, then you add up the total number of intersections. If that number is even, it went in and out, and is currently out.
What’s the problem with the closest point in Unity?
The problem seems to be that the KDTree finds a vertex that is closest, but doesn’t take into account that there can be vertices that are in the exact same spot. Unity takes meshes and duplicates the vertices in order to have the normals be calculated properly.
Is the nearest point inside a triangle responsable?
But, sometimes, the nearest point returned is an edge when it should be a point inside a triangle. The NearestPointOnTri function seems to be responsable. I hope you will read this thread and comment my reply if I am in fault. EDIT: The problem appears on a simple Cube GameObject. Replace the target by a Cube on position (0,0,0).
How do you find the closest point in Unity?
Unity takes meshes and duplicates the vertices in order to have the normals be calculated properly. I have added a fix to the KDTree with the method FindNearestEpsilon and SearchEpsilon which will find all the nearest that are within epsilon range of eachother.
Is the closest vertex always the closest triangle?
Edit – There is another issue with the kdtree in that it only searches for the closest vertex and then uses that as the closest triangle, when in reality the closest vertex does not have to be the closest triangle.
Is there a problem finding the closest vertex in Unity?
Sorry to bump up an old thread, but it has been very useful in the ever so dry land of custom collision detection in unity. I also ran into this problem and found the issue. The problem seems to be that the KDTree finds a vertex that is closest, but doesnt take into account that there can be vertices that are in the exact same spot.