Intersect ray with most detailed terrain - viewer.scene.pickFromRayMostDetailed

Dear all,

I am trying to intersect a ray with the terrain in order to obtain the coordinates of the intersection point.

While I do know that there is viewer.globe.pick to do this, within this function only the currently rendered terrain is used but I am in the need to intersect the ray with the most detailed terrain.

I had a look at the source code and saw, that there is an additional function located within Scene.js called pickFromRayMostDetailed which, based on the description, should exactly do what I need.

Here you find a small example on how I use this function (I am using Cesium 1.66):

cam_to_pnt_ray = new Cesium.Ray(viewer.scene.camera.position, viewer.scene.camera.direction)
var promise = viewer.scene.pickFromRayMostDetailed(cam_to_pnt_ray)
Cesium.when(promise, function(pick_pos) {
cam_pos_src.entities.add({
position: pick_pos.position,
id: “intersect_point”,
point : {
pixelSize : 10,
color : Cesium.Color.BLUE,
outlineColor : Cesium.Color.WHITE,
outlineWidth : 2,
}
});
});

In order to visualise the intersection point I add the picked position as an point entity to the scene. As it seems, the intersection point is not calculated based on the most detailed terrain as I do get the same result when I use viewer.globe.pick.

Do i misunderstand something with the functionality of “pickFromRayMostDetailed”?

Thank you for your help
Flu Tschi

I think pickFromRayMostDetailed works only for 3D Tilesets. It’s also a private function so I would not rely on its behavior to remain consistent between releases.

I think it’s used by examples like this to clamp a line to 3D Tiles even if they are offscreen: https://sandcastle.cesium.com/index.html?src=Sample%20Height%20from%203D%20Tiles.html

Have you tried using sampleTerrainMostDetailed to get the elevation at a particular point (https://cesium.com/docs/cesiumjs-ref-doc/sampleTerrainMostDetailed.html?classFilter=sample) or use globe.pick to get an approximation and then fly the camera there to get a more detailed value?