Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chris-cooper opened this issue Jan 14, 2016 · 1 comment
Open

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

chris-cooper opened this issue Jan 14, 2016 · 1 comment

Comments

@chris-cooper
Copy link
Contributor

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

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 #3411

@duvifn
Copy link
Contributor

duvifn commented Dec 7, 2016

You can find the reasons for this behavior here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants