Goal:
I want to find out which vertice/vertex is the closest to the point I clicked.
Setup:
Code I already have for the click handler:
mouse = new THREE.Vector2();
mouse.x = (event.clientX / renderer.domElement.clientWidth) * 2 - 1;
mouse.y = - (event.clientY / renderer.domElement.clientHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObject(icosahedron);
// 3D point: intersects[0].point
// Object face: intersects[0].face
Thanks!
Three steps:
-
vertices = [
intersects[0].face.a,
intersects[0].face.b,
intersects[0].face.c
];
vertices.forEach( function(vId,i){
vertices[i] = mesh.geometry.vertices[vId].clone();
vertices[i].l2w = mesh.localToWorld(vertices[i].clone());
vertices[i].id = vId;
vertices[i].index = i;
vertices[i].distance = vertices[i].l2w.distanceTo(intersects[0].point);
})
vertices.sort( function(a,b){
return a.distance - b.distance;
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.