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

pickPosition only works on 3D tiles if depthTestAgainstTerrain = true #5676

Closed
hpinkos opened this issue Jul 25, 2017 · 13 comments
Closed

pickPosition only works on 3D tiles if depthTestAgainstTerrain = true #5676

hpinkos opened this issue Jul 25, 2017 · 13 comments

Comments

@hpinkos
Copy link
Contributor

hpinkos commented Jul 25, 2017

This picking example only works if you uncomment the third line

var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
//scene.globe.depthTestAgainstTerrain = true;

var labelEntity = viewer.entities.add({
    label : {
        text: 'X',
        fillColor: Cesium.Color.RED,
        show: false,
        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
        verticalOrigin: Cesium.VerticalOrigin.BOTTOM
    }
});

// Mouse over the globe to see the cartographic position
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(click) {
    var foundPosition = false;
    if (scene.mode !== Cesium.SceneMode.MORPHING) {
        var pickedObject = scene.pick(click.position);
        if (scene.pickPositionSupported && Cesium.defined(pickedObject)) {
            var cartesian = viewer.scene.pickPosition(click.position);

            if (Cesium.defined(cartesian)) {
                labelEntity.position = cartesian;
                foundPosition = true;
            }
        }
    }

    labelEntity.label.show = foundPosition;
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
    url : '../../../Specs/Data/Cesium3DTiles/Tilesets/Tileset'
}));

tileset.readyPromise.then(function() {
    var boundingSphere = tileset.boundingSphere;
    viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius * 2));
    viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
});
@SunBlack
Copy link

SunBlack commented Jul 26, 2017

I have same issue. But one information is missing here in this ticket: pickPosition works not Ellipsoid, but on STK Terrain.
cesium

My test code:

var viewer = new Cesium.Viewer('cesiumContainer');

var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
var positions = [];
var lineStrip;
var floorSpacePolygon;

handler.setInputAction(function(movement) {
    if (!viewer.scene.pickPositionSupported) {
        console.warn("pickPosition not supported!");
        return;
    }

    var pickedPosition = viewer.scene.pickPosition(movement.position);

    if (pickedPosition !== undefined) {
        positions.push(pickedPosition);

        if (positions.length > 1) {
            viewer.entities.remove(lineStrip);

            lineStrip = viewer.entities.add({
                polyline: {
                    positions: positions,
                    width: 5,
                    material: Cesium.Color.ROYALBLUE,
                    followSurface: true
                }
            });
        }
        
        if  (positions.length > 2) {
            viewer.entities.remove(floorSpacePolygon);
            floorSpacePolygon = viewer.entities.add({
                polygon: {
                    hierarchy: new Cesium.PolygonHierarchy(positions),
                    material : Cesium.Color.ORANGE.withAlpha(0.4)
                }
            });
        }
    }
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);

handler.setInputAction(function(movement) {
    positions = [];
    viewer.entities.remove(lineStrip);
    viewer.entities.remove(floorSpacePolygon);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

@hpinkos
Copy link
Contributor Author

hpinkos commented Jul 26, 2017

@SunBlack thanks for the example! Yes, this looks like the same root problem. If you add this line to your example it works: viewer.scene.globe.depthTestAgainstTerrain = true;

It works when you select the STK terrain because the BaseLayerPicker enables depthTestAgainstTerrain when you select that option.

@hpinkos
Copy link
Contributor Author

hpinkos commented Jul 31, 2017

This bug makes the 3D Tiles Interactivity Sandcastle example completely broken.

@hpinkos
Copy link
Contributor Author

hpinkos commented Jul 31, 2017

@pjcozzi Actually, it looks like this works fine in 1.35 but is broken in master right now. Do you think that's a significant enough problem to hold up the 1.36 release, or should we just shoot to fix this for 1.37?

@lilleyse
Copy link
Contributor

I think the problem is with the new render ordering for classification primitives. The order used to be:

Globe
Ground Primitives
Clear Depth
3D Tiles

but is now:

Globe
3D Tiles
Ground Primitives
Clear Depth

So by gaining ground primitives on 3D Tiles we lost pickPosition on 3D Tiles.

@bagnell do you know if there is a quick enough fix for the release tomorrow?

@bagnell
Copy link
Contributor

bagnell commented Aug 1, 2017

There isn't a quick fix for this. I would say have users set depthTestAgainstTerrain to true until we figure out the best solution. We could have a fullscreen pass to copy the globe + 3D Tiles depth for each frustum every frame or have a depth only pass for 3D Tiles after the depth is cleared. Neither solution is ideal.

@pjcozzi
Copy link
Contributor

pjcozzi commented Aug 2, 2017

@bagnell @lilleyse let's discuss to see if we are able to fix this for 1.37.

May also be able to solve #5683 at the same time.

@lilleyse
Copy link
Contributor

lilleyse commented Aug 5, 2017

Added a temporary fix for the 3D Tiles Interactivity demo #5724. That code can be reverted when this issue is solved.

@pjcozzi
Copy link
Contributor

pjcozzi commented Aug 21, 2017

Discussed with @bagnell offline and we will fix this in 1.37 by rendering classification primitives up to 2x with a enum that is 3D Tiles, Terrain, or Both (default).

Longer term, #2160 will fix this since there will be no clear depth step after terrain / 3D Tiles.

@JeanneKahn
Copy link

I'm having this bug now - setting viewer.scene.globe.depthTestAgainstTerrain = false makes pickPosition on the ellipsoid fail.

I want to disable depthTestAgainstTerrain to stop KMLs from digging into the terrain but in doing so I can't pick on the ellipsoid anymore.

@UgniusFE
Copy link

I am having the same issue as @JoshuaKahn

@UgniusFE
Copy link

I believe the bug is here

if (scene.pickTranslucentDepth) {
renderTranslucentDepthForPick(scene, drawingBufferPosition);
} else {
scene.updateFrameState();
uniformState.update(frameState);
scene.updateEnvironment();
}

@michalbie
Copy link

michalbie commented May 31, 2024

Have you found a way to solve this issue? Still encountering it in 2024, Cesium 1.102

Edit: Solved it by using Ray casting pick method mentioned here: https://community.cesium.com/t/scene-pick-returning-point-inside-the-globe/18940/3

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

8 participants