Globe.pick for intersect ray and scene return undefined

Hi

I will calculate position of intersection of a ray with earth terrain . i use this command but it return undefined.
‘’’
var terrainIntersect = viewer.scene.globe.pick(ray, viewer.scene);

‘’’

Hi @mohamad,

I would start by ensuring that your ray object is in world coordinates! The pick documentation specifies that the ray object must be in world coordinates.

https://cesium.com/learn/cesiumjs/ref-doc/Globe.html#pick

Can you please confirm this?

Best,
Sam

Hi @mohamad It seems like your requirement is similar as this post.

1 Like

my problem resolved by using in time interval .

var tilesToRender = viewer.scene.globe._surface._tilesToRender;
setInterval(function() {

if(tilesToRender.length !== 0){
var terrainIntersect = viewer.scene.globe.pick(ray, viewer.scene);
}

}, 200);

@mohamad

Thank you for sharing this with the community! I am glad to hear that your issue has been resolved.

Best,
Sam

… but note that variables that involve an _ underscore in their name (like _surface and _tilesToRender) are considered to be private variables, and this code might no longer work in a future version…