About sampleHeightMostDetailed (objectsToExclude)

Hello Cesium community,

I am having some trouble with the sampleHeightMostDetailed function using the objectsToExclude option. As per documentation I am passing an array of objects to exclude from the sampling and when using entities for this, it seems to work no problem. However when I try to ignore a 3dtile feature (a building feature from a 3dtileset) it doesn’t seem to work.

In detail, what I want to do is sample 3dtiles that represent a floodheight beneath the building. So I drillpick, grab the building and pass it to sampleHeighMostDetailed to exclude, but it doesn’t seem to work as expected. I have tried to passing the entire object, .primitive, .content, .tileset, .content.tileset and .content.tile but nothing seems to work. So my question is, what object do I need to pass to the function for it to ignore the 3dtilefeature? The result height of the 2 heightsamples is always identical. Below is a snippet of the code I am using inside a setInputAction function.

...
      const scene = viewer.scene;
      let position: any;
      const cartesian: any = scene.pickPosition(input.position, position);
      const cartographic: any = Cesium.Cartographic.fromCartesian(cartesian);
      const terrainHeight = await Cesium.sampleTerrainMostDetailed(terrain, [cartographic]);
      const tHeightForCalc = terrainHeight[0].height;
      const objectsToIgnore = [];
      const drillPick: any = scene.drillPick(input.position);

      console.log(drillPick); // length always 2, 0 is always building, 1 is always floodtiles
      
      for (let i = 0; i < drillPick.length - 1; i++) {
        if (drillPick[i].tileset) {
          objectsToIgnore.push(drillPick[i].primitive); 
        }
      }
     
      console.log(objectsToIgnore);
      const tilesHeight = await scene.sampleHeightMostDetailed([cartographic], objectsToIgnore); 
       // floodtiles height expected but returns building height
      const bldgHeight = await scene.sampleHeightMostDetailed([cartographic]); // same height as above

Best Regards,
Jacques

I have sort of solved it myself by now I guess. It seems that calling sampleHeightMostDetailed twice in quick succession is what causes the problem. When I insert other lines of code in between (f.i. console.log or variable declarations), then it works as expected. I don’t have the time to do much more experimenting, but it seemed like the result of the second call was overwriting the result of the first call.

Hi there,

As per the reference documentation, the positions are updated in place. Is this part of the behevior you are seeing?

Hi Gabby,

I don’t think this is what I am experiencing since I am defining 2 separate variables with 2 different calls of the function. The input variable (input.position) is the same for both, is that the problem maybe? Although it says in the documentation that the height of the input is ignored …