Scene.pick returning point inside the globe

Hello Team,

What I am doing ?
I am selecting the point on the globe by mouse click event, using the following code.

cartesian = viewer.scene.pickPosition(mousePos);

What is happening ?
Sometime (2 points out of 10 ) are getting selected inside the earth, under the ground.

What I want ?
I don’t want this behavior to happen when I select the point on the globe.

Also, I have disabled the depthTest against terrain.

viewer.scene.globe.depthTestAgainstTerrain = false;

My observation is when I enable depth test against terrain I can not reproduce the same behavior (getting cartesian under the ground).

Disabling the depth test is essential for me.
and I want to understand why this behavior is occurring when picking cartesian while depth test is disabled.

thank you !!
looking for answers.

Hello,

This is a known bug which we’re tracking in GitHub. Unfortunately, its not a simple fix.

Would you be able to provide a code example? We may be able to suggest a workaround based on the type of data you have loaded.

Thanks,
Gabby

Hello @Gabby_Getz
I am using following code to pick point on the globe.

function pickCartesianOnGlobe(mousePos: Cesium.Cartesian2, viewer: Cesium.Viewer): Cesium.Cartesian3 | undefined {

        //pick will return the cartesian coordinates
        let cartesian: Cesium.Cartesian3 | undefined = undefined;
        cartesian = viewer.scene.pickPosition(mousePos);
        if (!cartesian) {
            const ray = viewer.camera.getPickRay(mousePos);
            cartesian = viewer.scene.globe.pick(ray, viewer.scene);           
        }
        return cartesian;
}

I hope this helps.
Thank you.

Hello @Gabby_Getz ,
I have created a sandcastle for this issue.
Please check out this link for Sandcastel for depth test against terrain issue.

So in this sandcastle,
on left click -
user can select the point on the point cloud and on earth surface.
For each point selected there will be a red sphere rendered and there is polyline passing through all the sphere.
rendering spheres and polyline makes it easy to identify which points are selected under the ground.

on right click -
user can toggle the depth test against the globe.
so that when depth test is true, we can not certain parts of polyline since it is inside the earth.

I hope this examples helps to understand issue in better way.
Also please make sure user select the point when depth test is disabled, because if it is not then issue will not reproduce.
Also please find this attached video to show issue is reproducible in sandcastle.
depthtestlowsize.zip (7.6 MB)

Thank you.
looking for answers\work around for this issue.

Thanks for the example, that’s very helpful to illustrate the issue.

I also found another thread which describes the issue.

You can try using scene.globe.pick to determine positions on terrain instead of pickPosition as a workaround.

Hello @Gabby_Getz ,
I am already using scene.globe.pick for picking on the earthsurface, you can check out the code if possible.

Thank you.

Ah! Picking. So.

The order of picking and other things matter, same with globe with or without transparency, mixed with models with or without opacity in them. In a render cycle, I’d play with the order of picking, like pickPosition() before a drillPick() or pick(), as some picking mechanism triggers a new render cycle (I think this happens if you drillPick() before a pickPosition()).

Anyway, I’ll dig through my code for you, but I have a sceneController which keeps tabs on what items are in a scene and what is transparent or not, and I then do picking based on that information. I’ll keep you posted (just got to do some other stuff first).

Cheers,

Alex

1 Like

Thank you for your reply @Alexander_Johannesen .
Adding comment just to be on same page about this issue, I do understand your description of reason for this bug.
Also I have not updated the transparency of anything in the viewer. I have just disabled the depth test on globe.

Thank you,
Mukund.

Hi @MUKUND_THAKARE,

I checked with our 3D developers, and unfortunately there is no true workaround to this issue until the bug is fixed. The best I can recommend in the meantime is a function we use in our own apps, which is very similar to your approach.

  const ray = scene.camera.getPickRay(mousePosition);
  if (scene.pickPositionSupported) {
    // Don't pick default 3x3, or scene.pick may allow a mousePosition that isn't on the tileset to pickPosition.
    const pickedObject = scene.pick(mousePosition, 1, 1);

    if (
      defined(pickedObject) &&
      (pickedObject instanceof Cesium3DTileFeature ||
        pickedObject.primitive instanceof Cesium3DTileset ||
        pickedObject.primitive instanceof Model)
    ) {
      position = scene.pickPosition(mousePosition);
    }
  }

  if (!defined(position)) {
    position = scene.globe.pick(ray, scene);
  }

Keep an eye on that issue, and we will update if theres’ any progress.

Thanks for your patience!