CesiumGS / CesiumGS/cesium

subsequent pickPosition returns wrong value (depth?)

Open
#11,031 13 comments 0 reactions 0 assignees View on GitHub
category - picking type - bug
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

Firstly, this issue is hard to reproduce, that's why I provide images below.

In my application, when the user clicks a point cloud point, we want to find the point closest to the camera within a certain screen environment (`env` currently set to 4). So this is not about hitting *any* point cloud point within that screen rect, but the *closest* one. This function we named `pickPoint` calls Cesium's `viewer.scene.pickPosition()`.
However, sometimes*, `pickPoint` returns a position that is *too* close to the camera, where actually no point cloud is.

The sandcastle implements 2 kinds of picking:
1. "massive pick" (see toolbar) that invokes `pickPoint` all over the screen for every 20 pixel. Might take a minute or longer.
2. "diagonal pick" (double left click) that picks at the clicked position and then goes down-right for the next 100 pixel and invokes `pickPoint` there. Might take a few seconds.

In `pickPoint`, some point entites are created at the positions that were successfully picked. A yellow point means that this position was picked at the very first; a blue point means this position was picked subsequently in the loop to pick around the given screen environment `env`.

**When the bug happens**:
1. "massive pick": you will see that the yellow point is *always* at the correct position, and the blue points *never* are. The blue points are closer to the camera, it seems that all by the same amount. See the images below, it's like the point cloud would exist a second time.
2. "diagonal pick": The very first pick seems to be correct, and there are also some blue points at the correct position, but all other picks are wrong in the diagonal line, doesn't matter if yellow or blue, see the image and GIF below.

**What I think could be wrong**:

Since the first pick seems to be right and subsequent picks that are close to the first one aren't, I think this could be something about the picking cache, or maybe the depth buffer gets interpreted wrongly (logarithmic vs. linear). But this is just my intuition, I have no idea about the Cesium code. Since it's unreliable to reproduce, it might also be a race condition somewhere.

\* sometimes: Happens very often on certain point clouds, sometimes on meshes, and almost never on certain other point clouds. We cannot find any difference in the point clouds that would make them special to this bug. The point cloud which has this bug quite often is also used in the sandcastle, and it also sometimes shows this error in the sandcastle, too. First I thought that `attenuation` might play a role, or the density of the point cloud, or that the point cloud is still loading, or that the globe is still loading, or just overall "busyness" of the browser. But nothing could reliably increase the chance of causing this bug.

## Images: massive pick

It's as if the point cloud exists twice, but closer to the camera position. Easy to spot at the wall ("line") and the tree structures.

(the red and green circles on some images were picked using `debugPickPosition` on the point cloud when the inspector widget was initialized)

Initial position after massive pick:

![initialPosition](https://user-images.githubusercontent.com/5690856/211554261-b402a36c-b138-44da-8aa2-531c69355d60.png)

Shown from above:

![topView](https://user-images.githubusercontent.com/5690856/211554264-97b99e88-2dbe-42d5-aa97-45b16c50c0e6.png)
![above1](https://user-images.githubusercontent.com/5690856/211554242-ffc420e4-b638-469c-b168-41e41072a87a.png)
![above2](https://user-images.githubusercontent.com/5690856/211554255-cce832b8-7a9a-4cfb-b179-ee820a9f6465.png)

Even the globe gets picked wrongly:

![globeAndDebugPosition](https://user-images.githubusercontent.com/5690856/211554258-ea322b9a-1fdd-4f83-bed6-b7f278b4aa0b.png)

From the ground:

![tree](https://user-images.githubusercontent.com/5690856/211554265-3223ee33-5cad-4b99-92be-5fd77c8b215f.png)
![wallAndStreet](https://user-images.githubusercontent.com/5690856/211554268-ab9cf32d-0e3c-4267-a143-0a65f04f4c04.png)

## Images: diagonal pick

Showing the same diagonal pick from different angles.

Inital Position:

![diagonalPickInitialPosition](https://user-images.githubusercontent.com/5690856/211558976-c0f3e4e5-8caf-43e6-bed8-f5226423ccfc.png)

Zooming in:

![diagonal_onePick4](https://user-images.githubusercontent.com/5690856/211561491-6d36fb21-a4ea-4400-bd86-f011b43e4533.gif)

You can clearly see that the diagonal line is in shape as the vegetation in front of the wall, but only the first few picks are correctly *on* the wall.

![diagonal_onePick3](https://user-images.githubusercontent.com/5690856/211559057-0086bd55-f7cb-4577-b58a-d332ab0c32b6.gif)

Sandcastle example:

https://sandcastle.cesium.com/#c=rVj7c9o4EP5XdPnhalpi/OCZR3sJIS1pQnIJbS+dzHSELYLASJwtB9y7/O+3sjDYxqT07pgMsVe7K+1D3ydRqaD3PmYCtUlAw+nFHcKOQ4IACY4iHvqIcoZwEBARPDClo3c5010yxKEnTmLlPp8Qho7Rwx6JL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mMoDnqH6ugAWeVigyzArG0ssDFftllCztomAyn3ncvL6y8oBzSnl586W7z+PC79L9hUhE87YlQpD3P5s+mPAcjKmmTNc534uqiL4rb8Cf7M+kio8Cco8L9S4W59nOvlanm7WraDrR9rFlHl+9tOp/eC6b9rzv+tQbc16e5kujuJbiHTnyfVjctYQrEFA7IRFzGQROjvv+XzEUDKr78iJdyPSkvx27TYBPlGc0q2OgaGy60iprx9N8qLI0Vw2cvj+iWSF8iM1SKWLNLHZvkFdL7ahHCPYXczuGd1niBPHzBzPSmHex2bheIkvjloqysEZ2c8hBZpy9NCfEmKzw2x7cN68604lynOZZAi05APOcpNXZ2zscJlbe159ftDzMQs1wBRsWqUU01fyJ93uleDxa6f1S/pd7mE9qMZ0S875/1vZ9efTi8739qX3fZH6X2vvHcUiMgjb5M1/kan8uojr9yarlcEmcIFGLZHZRDCCVPoThAkARxV0qZHLn1C1D0u+D0bUoODAEaGoRcD1MPe26MK6G+YehzD8fDxGk5yHo6k2sh8e6mEuq4fVeC12FKoH+1ynv8B

Browser: Chrome, Firefox

Operating System: Windows 10, Ubuntu

Contributor guide

Open the contributing guide

Research direction

Start with the linked Sandcastle example and trace the pickPoint wrapper's calls to viewer.scene.pickPosition(), including the massive and diagonal pick paths. Compare the first and subsequent positions, using debugPickPosition where shown. Done means repeated picks return the correct closest point or globe position instead of a camera-near duplicate.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.