I am currently working on a 3D scatter plot where spheres are used to represent the points, and I am attempting to show information from the points when they are clicked. After researching various answers on this platform, I believe I am moving in the right direction. Here is the snippet of code for my onCanvasMouseDown function:
event.preventDefault();
mouse.x = ( (event.clientX - renderer.domElement.offsetLeft) / renderer.domElement.width ) * 2 - 1;
mouse.y = - ( (event.clientY - renderer.domElement.offsetTop) / renderer.domElement.height ) * 2 + 1;
mouse.z = 0.5;
projector.unprojectVector( mouse, camera);
raycaster.setFromCamera( mouse, camera);
var intersects = raycaster.intersectObjects( scene.children );
if( intersects.length > 0 ) {
intersects.map(function(d) {
if(d.object.name === "sphere") {
//etc...
}
})
}
However, I am encountering an issue where intersects consistently returns empty. I suspect that the problem may be related to how I am setting up the mouse coordinates, but I am uncertain about how to address it.
EDIT: I have observed that I am able to detect a sphere when I rotate the plot to view it from above, but I need to be able to detect it regardless of the rotation. Does this provide any specific insights?