Snapping to closest point in a point cloud

Hi all,

first of all, thanks for all the amazing features available in Cesium. As per problem title, i'm trying to snap the mouse click event to closest point in a point cloud, converted in a 3d tile. If i click on a point in the screen, if no point is present in that precise coordinate, i get snapped to the ground and this is not the desired behaviour. I need to implement this feature for precise calculation of distance beetween two points in the cloud. I'm working with the latest version of Cesium on Windows 10, Google Chrome. Any help will be appreciated.

Greetings,
Gianmarco Stinchi

Hey Gianmarco,

Thanks for the kind words! This is a very good question. The picking system is good for picking out whatever arbitrary geometry happens to be in the direction of the ray, so it might be hard to have it find just the closest point instead. This almost sounds like it would be better to do some kind of spatial query, to get all the points in the area where you clicked, and then filter those for the closest one. This would be easier to do once Cesium support implicating tiling schemes in 3D Tiles (see https://github.com/AnalyticalGraphicsInc/3d-tiles/issues/92).

For now, you could potentially do this by finding the tile you hit, and iterating over the points in its content. However, CesiumJS doesn’t store point positions to preserve memory, it gets stored as a vertex buffer and sent to the GPU, and the CPU copy is discarded:

https://github.com/AnalyticalGraphicsInc/cesium/blob/464d2cd6171e31fc0ce219f01c14bc642212e2c9/Source/Scene/PointCloud.js#L608

It wouldn’t be hard to have a flag to keep this in memory if it can support applications and use cases like the one you’re describing though.