The three.js Raycaster example shows how to highlight objects using intersectObjects:
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
function onMouseMove( event ) {
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
}
function render() {
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( scene.children );
for ( var i = 0; i < intersects.length; i++ ) {
intersects[ i ].object.material.color.set( 0xff0000 );
}
renderer.render( scene, camera );
}
window.addEventListener( 'mousemove', onMouseMove, false );
window.requestAnimationFrame(render);
https://threejs.org/docs/#api/en/core/Raycaster
However this intersects objects even if they are obscured behind another object. I've created a demo showing that you can highlight objects even if they are behind the sphere object:
https://codepen.io/kmturley/pen/gObgKee
Notice how in the demo you can highlight objects behind the sphere. How can we ignore objects which are obscured by other objects? even if they exist within the Camera Frustrum and are rendered by Three.js?
My use-case is that I actually want to hide the objects which are at the back of the sphere and their labels.
Examples showing intersections: