Implement the raycasting technique for accurate object intersection. Here's a simple guide to get you started:
(using revision 70 and vanilla JavaScript)
1) Define Targets
var targets = [],
// Use the push method when creating your 3D objects to add them to the target list.
// targets.push(objectMesh);
2) Set Up Raycaster
var raycaster = new THREE.Raycaster(),
mouse = new THREE.Vector2(),
intersects;
3) Intersect Objects
searchTarget(event){
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
intersects = raycaster.intersectObjects(targets);
if (intersects.length > 0){
// Handle the intersected objects here:
// intersects[0] refers to the object at the front
}
}
4) Add Event Listener
renderer.domElement.addEventListener('mousemove', searchTarget, false);
You can also use jQuery:
$( "#canvas" ).mousemove( searchTarget );