Select vertex of a mesh, snapping to it

I would like to select a point in a mesh, but just if it’s a vertex of the mesh. So I would like to move the mouse over the mesh and, if the pointer of the mouse is “near” a vertex, snap the mouse position over the vertex to help the user selecting the right point. Do you have any suggestion about it?

Thank you

Toni

1 Like

Hey Toni,

I’ve done something similar to this before to highlight faces when the cursor moves, similar to a 3d modeling program.

What you can do is cast a ray when the mouse moves, if that ray hits a mesh, get the faceId - from the faceId you can get the 3 vertices that make up that “face” by accessing the meshes vertex data.

Then convert those 3 vertices to screen space → calculate the distance between the cursor and the vertices and see if they within your desired distance.

1 Like

Here’s a great playground from the old forum that looks helpful. It adds a little sphere at the vertex position when the cursor is near a vertex. :face_with_monocle: :slightly_smiling_face:

2 Likes

Thank you guys, you rock!

1 Like

This is super helpful, thanks!!

Is there a way to also highlight the midpoints of edges as well?

Following up in case anyone’s got any ideas. :slight_smile: