目标:
我想知道哪个顶点/顶点最接近我点击的点。
设定:
我已经拥有的点击处理程序代码:
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
谢谢!
答案 0 :(得分:5)
三个步骤:
-
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;
})