Pick the vertices around a sphere

say for example if I have a flat mesh (for the sake of example), let say a flat terrain,
how can I get which vertices are around a picked vertex (or face)?
I see some samples that picked vertices of a mesh, but i want to know the pixels around that picked mesh using picked mesh ± a sphere radius.?

Got any idea and/or link about this?

1 Like

By distance from selected vertice to other vertices

‘Vertex within a second geometry’ (a.k.a spatial queries) functionality is not implemented in core three.js. As @Chaser_Code is suggesting, you can construct it by traversing geometry vertices and checking the distance to sphere center against its radius, like: “if the distance is smaller than radius, current vertex is inside”. Please remember that since version r125, vertices data is stored in a buffergeometry special attribute.

As long as the vertex count is moderate, looping all vertex positions shouldn’t be a problem. For large geometries (specially with terrains) you should consider using an object subdivision method (i.e. BVH) to minimize the total list of vertex to check against. If that is the case, consider giving a try to three-mesh-bvh, which happend to provide the method bvh.intersectsSphere( sphere );

On the other hand, if you need to query multiple objects, space subdivision methods (i.e. Octree, BSP, kD-Tree, etc.) are suggested instead. Several versions ago we had three-octree, but it is no longer active.