CesiumGS / CesiumGS/cesium

globe.pick() sometimes returns a hit which isn't closest

Open
#3,423 1 comment 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

This occurs when geometry is overlapping. The points circled in red are actually obscured by the mountain in front so shouldn't have been picked.

![image](https://cloud.githubusercontent.com/assets/484870/12314980/04128bce-baca-11e5-929d-6b4d3c0f3790.png)

I ran this repro from the current Cesium sandcastle with a relatively small window size (as pictured) on Ubuntu Chrome.

```
var viewer = new Cesium.Viewer('cesiumContainer');
var camera = viewer.camera;
var scene = viewer.scene;
var globe = scene.globe;

var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
url: '//assets.agi.com/stk-terrain/world',
requestWaterMask: true,
requestVertexNormals: true
});
viewer.terrainProvider = cesiumTerrainProviderMeshes;

var target = new Cesium.Cartesian3(-2489625.0836225147, -4393941.44443024, 3882535.9454173897);
var offset = new Cesium.Cartesian3(-6857.40902037546, 412.3284835694358, 2147.5545426812023);
viewer.camera.lookAt(target, offset);
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);

function runTest() {
console.log("Running test now!");
var n = 200;
for (var y = 0; y <= n; ++y) {
for (var x = 0; x <= n; ++x) {
var name = "<" + x + "," + y + ">";
var windowCoordinates = {
x: x * window.innerWidth / n + Math.random(),
y: y * window.innerHeight / n + Math.random()
};
var ray = camera.getPickRay(windowCoordinates);
var intersection = globe.pick(ray, scene);
if(!Cesium.defined(intersection)){
continue;
}

viewer.entities.add({
name: name,
position: intersection,
billboard: {
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
scale: 0.3,
image: '../images/facility.gif'
}
});

}
}
}

console.log("Just waiting for terrain to load...");
setTimeout(runTest, 10000);
```

Possibly related to https://github.com/AnalyticalGraphicsInc/cesium/issues/3411

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied Sandcastle reproduction with terrain enabled and inspect globe.pick(), camera.getPickRay(), and the related issue #3411. Compare picked terrain intersections for overlapping geometry and verify that obscured points are excluded and the closest visible intersection is returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
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.