Raycasting Point Clouds has mistake and slow

Hi, first of all thanks to authors and the community for this wonderfull framework. It looks very promising for our project. I want to learn more and utilize fully in my project too.

Right now I am using threejs to visualize Point Clouds. I want to be able to pick individual points from the cloud. I used raycaster to get intersects of my points object.
in mouse move event:

  mouse.x = ( ( event.clientX - renderer.domElement.offsetLeft ) / window.innerWidth ) * 2 - 1;
  mouse.y = - ( ( event.clientY - renderer.domElement.offsetTop ) / window.innerHeight ) * 2 + 1;

in animate fnc:

    raycaster.setFromCamera( mouse, this.camera );
    intersects = raycaster.intersectObject( particles );

then I change attributes of the particles which is a Points object. Then render. I can get the selected point to change color. I get the mouse position by mousemove event. So ray casting has to run every time I move mouse over the document. With 100 000 points it is quite slow. Also when there are many points close by it outputs quite off from what mouse points to.

Why is the a mistake in selecting correct point by raycaster? Do I need to do some setting?
Also is there a faster way to get points which my mouse points to? Is this raycasting done on CPU? Can we utilize GPU to make it faster?

Thanks in advance

Yes, Points.raycast() holds the actual implementation.

The ray/points intersection test is an approximation and uses a threshold value, see https://threejs.org/docs/index.html#api/en/core/Raycaster.params. You can try to tweak this value in order to get more precise results.

You can try to use some sort of GPU picking. However, I don’t know how good it works with points.

I see. Ok I will try some GPU based solutions and let you know of the result. Thanks.

If the point cloud is static, you can benefit greatly from employing a spatial index (still on CPU!). You will need to replace the raycast method, as I did with Mesh.raycast here: Octree injection for faster raycasting/raytracing

The principle is that you build the spatial index once, and then use it to accelerate multiple searches afterwards. An octree is just one among several possible options, and my implementation above is a bit naïve.