Find nearest vertex

Hi, how to find nearest vertex in mesh. Please anyone guide me…

Thankyou

Hi @Jenifer

Can you please be more explicit? Do you want to do picking from the mouse pointer or get the nearest vertex from a particular Vector3 position? or something else?

Hi, @Cedric want to get the nearest vertex from a particular Vector3 position.

i have one curve, the curve have 4 vertex and having a another object. that object have a more vertex, i take one curve vector to compare a nearest vertex from another object…

To get the nearest position from mesh vertices, you first need to get its position data:

var geometry = mesh.geometry;
var positions = geometry.getVertexBuffer(BABYLON.VertexBuffer.PositionKind);
var positionData = positions.getData();

positionData is an array containing x1,y1,z1, x2,y2,z2, …xn,yn,zn;
Then, iteration on each position and get the distance for each. Keep the small distance.

Yeah Thankyou :blush: @Cedric But my doubt is how to get distance…my need is want to find distance.

You can use Vector3 Distance method:

1 Like

Thankyou so much @Cedric :smiley:

1 Like

Hi, Can you please give us any example code

https://playground.babylonjs.com/#I0TSSC#7

@Lakshmi_quest Please check this link… this is find the nearest vertex

In this example one may find the first nearest and farthest vertices - https://playground.babylonjs.com/#CPRHN1#9

image

The sphere is the point to measure from.
Green sphere = nearest vertex
Red sphere = farthest vertex

2 Likes