Raycast to select Points in pointcloud - returns all points - intersectObjects

While attempting to do a selection of a single point by clicking in a point cloud(~20000 pts) loaded using XYZLoader, the intersectObject(pointCloud) returns all the points in the point cloud, even when I’m clicking outside of the point cloud.
Tried
geometry.boundingBox=null after load, doesnt work.
geometry.computeBoundingSphere(), doesnt work.

I had seen previous issues where most of them had to do with single point selection or points aligned in a line, but this one seems to be different from those.
I’m doing the basic raycasting from docs.

function onClick( event ) {

// calculate mouse position in normalized device coordinates
// (-1 to +1) for both components

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
raycaster.setFromCamera( mouse, camera );


var intersects = raycaster.intersectObject( scene.children[0] );

for(var i = 0; i < intersects.length; i++){

		intersects[ i ].object.material.color.set( 0xff0000 );
}

}
1 Like

this might be related to the raycasters point threshold and your models size

raycaster.params.Points.threshold = 0.1
3 Likes

yes I just figured that out. Thanks anyway!

can you tell us a bit more about your solution? @mikejernil

This was probably just about adjusting your raycaster params. Nevermind.

this method is not working for my case, when using threshold zooming in and out to the scene affect it if i out it low and camera is at position 10 it will not intersect anything , anw when it intersects it is still intersecting like 44k points, if you have detailed explanation how to click on a point in a point cloud and get its exact position please let me know , thank you !

I spent full day to figure out why my raycaster always return true. This is the solution!