How is 3D Tiles distanceToCamera property computed?

1. A concise explanation of the problem you're experiencing.

Hi, I have a large number of 3D Tiles tilesets, each with only one tile containing a few features. I want to process and modify them based on the distance to the camera, and I was wondering how the tile._distanceToCamera property was computed. Is it based on the bounding volume of the tile? Or is it a point at the tile center?

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

for(var i = 0; i < tileset.length; i++){
    tileset[i].tileVisible.addEventListener(function(tile) {
      //console.log(isInArray(tile, visibleTiles));
      if ( isInArray(tile, visibleTiles) < 0 ){
        visibleTiles.push([tile, tile._distanceToCamera]);
      }
    });
  }

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I need to apply modifications (such as color changing) sequentially by distance, so the user should see the closest tiles being changed first, then further, and further.

4. The Cesium version you're using, your operating system and browser.

v1.39, Google Chrome

Thanks,
Aditya

Hi Aditya,

It’s based on the tileBoundingVolume (See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Cesium3DTile.js#L818), which can be a box, oriented box, or sphere each of which have their own implementation. However generally it’s computed based on the closest point on the outside of the bounding volume.

Thanks, hope that helps!

Gabby

Thanks Gabby! One quick follow up, is there a way to check bounding boxes for individual features? I’ve tried a number of properties in both feature.content and feature.primitive, but they all seem to relate to the tile and not the feature itself.

Thanks!

Aditya

feature.content is a private function and subject to change, but you can get the tile it is a part of:

feature.content.tile

``

Thanks,

Gabby

Just to clarify, do any of the objects (feature, tile, tileset) contain bounding volumes for individual features? Primarily I am trying to compute the distance of individual features to the camera.

Thanks,

Aditya

Cesium does not contain bounding volumes for individual features, however a common approach is to encode positional or bounding volume information in the tiles themselves via batch table properties. For example, a lot of the sample tilesets encode longitude, latitude, and height properties which can be converted to Cartesian coordinates pretty easily for distance checks. Check out the code in https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=3D%20Tiles%20Interactivity.html&label=3D%20Tiles.

If you have these properties in the batch table it is also a lot easier to write a style that colors by distance rather than looping over the feature’s yourself. Check out the Color By Distance mode in https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=3D%20Tiles%20Feature%20Styling.html&label=3D%20Tiles. Alternatively, you can style with a custom function. Check out the second example here: https://cesiumjs.org/Cesium/Build/Documentation/Cesium3DTileStyle.html?classFilter=cesium3dtilestyle#color. This way probably makes more sense since it is based on the camera’s position.

If you are writing your own tileset generation tool it shouldn’t be too hard to add those properties. But if not, I’m afraid there isn’t a great way of getting feature bounding volume information.