Using mesh.getVerticesData("uv") to find if a point is inside a uv map shape


I was wondering if it was possible to use the resulting array from mesh.getVerticesData(“uv”) to determine whether a random point lies inside (the Blue dot) the UV Map’s shapes or if it lies in outside of the shapes (the red dot)?

Does BabylonJS have a preexisting method to determine this?

Thank you,

Yes, the uv coordinates can help, but you may end up doing a lot of work…

What you can do is:

  • loop over all the triangles of your mesh
    • for each triangle
      • retrieve the uv coordinates of the 3 vertices
      • determine if the point you want to check is inside the 2D triangle delimited by the uv coordinates

It can be quite involved if your mesh has a lot of vertices/faces.

An easier way would be to provide a texture where the “inside” is painted in full red (for eg), and the “outside” in black. Then, the check is only a matter of retrieving the pixel in the texture and verify if it’s red or black.

You could build this texture at runtime, by looping over all the triangles as described above and drawing the 2D triangles in the texture in red.

ooo truly, you are a jedi master.
thanks, Evgeni. For both options.