CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.75k stars 3.45k forks source link

geojson pick confusion when set perPositionHeight #10091

Open znxd-wh opened 2 years ago

znxd-wh commented 2 years ago

hello

I use GeoJsonDataSource to load geojson data, when i set the perPositionHeight=false,single click on the map to pickup a geojson feathure, it may return a wrong result.

image

when i set entity.polygon.perPositionHeight = false, it will happen,but if set entity.polygon.perPositionHeight = true, it works fine. this happens with cesium version 1.88, when change cesium version to 1.74,it works fine as well.

following is the code:

var promise = Cesium.GeoJsonDataSource.load('data/wenmiao.json', { clampToGround: true });
      promise.then(function (dataSource) {
        // viewer.dataSources.add(dataSource);
        var entities = dataSource.entities.values;
        for (var i = 0; i < entities.length; i++) {
          var entity = entities[i];
          entity.polygon.perPositionHeight = false;
          entity.polygon.classificationType = Cesium.ClassificationType.BOTH;
          entity.heightReference = Cesium.HeightReference.CLAMP_TO_GROUND
          entity.polygon.material= Cesium.Color.BLUE;
          viewer.entities.add(entity)
        }
      });
      viewer.flyTo(promise);
      var scene = viewer.scene;

      var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
      handler.setInputAction(function (movement) {
        var pick = viewer.scene.pick(movement.position);
        if(pick){
          selectedEntity = pick.id;
          pick.id.polygon.material = new Cesium.Color(255, 0, 0, 1)
        }
      }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
ggetz commented 2 years ago

@ebogo1 Could you triage this issue by reproducing and seeing if you can find the probable cause?

ebogo1 commented 2 years ago

@znxd-wh I wasn't able to reproduce this with the GeoJson examples we have in our Sandcastle gallery. Are you able to share the data you were testing this with? Thanks!

znxd-wh commented 2 years ago

@ebogo1 attach is my code with data, unzip it and publish with a web container such tomcat,iis,nginx. visit the index.html page,you will see the problem. click a feather several times, different feature will be picked. image

cesium 1.88 does not work,but 1.74 works fine. but if i don't set entity.polygon.perPositionHeight = false,both version work well,when i set entity.polygon.perPositionHeight = false,only version 1.74 works.

look forward to your response and thanks

geojson.zip

ebogo1 commented 2 years ago

This looks like a regression in 1.80 from https://github.com/CesiumGS/cesium/pull/9399. I think something is going wrong with the first logDepthOrDepth != 0.0 check added in the ShadowVolumeAppearance frag shader -

https://github.com/CesiumGS/cesium/blob/ff34e0c4dc3f9e58f44e79d0f283973f546e47ae/Source/Shaders/ShadowVolumeAppearanceFS.glsl#L73-L81

znxd-wh commented 2 years ago

hi @ebogo1

did you mean this bug has appeared since version 1.80?so do you have any idea to fix it? or i do not set the perPositionHeight parameter, but can you please tell me a method to let geojson polygon clamp on 3dtiles model?like the below effect. image

ebogo1 commented 2 years ago

@znxd-wh Yeah, this bug was introduced in 1.80. I edited my first comment with more details. The shader affects all classification types so it's tricky to work out a quick fix. If we have a chance to revisit the issue we'll post updates here.

ShenWeiQun commented 1 year ago

I've also had this issue recently For the time being, you can consider the following ways to solve the problem

handler.setInputAction(function (movement) {
-  var pick = viewer.scene.pick(movement.position);
-  if (pick) {
-    selectedEntity = pick.id;
-    pick.id.polygon.material = new Cesium.Color(255, 0, 0, 1)
-  }
+  const pickedObjects = scene.drillPick(movement.position);
+  if (pickedObjects) {
+    var pick = pickedObjects.pop();
+    selectedEntity = pick.id;
+    pick.id.polygon.material = new Cesium.Color(255, 0, 0, 1)
+  }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
JiaoJianing commented 1 year ago

I've also met this issue and this is the live demo. When setting clampToGround to false everything seems well.It does seems to be the shadowVolume issue. I just provide my geojson data and demo for testing.