cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Bounding volume issues until tileset.boundingSphere is accessed

Open mramato opened this issue 2 years ago • 1 comments

Start with the following Sandcastle. It will create a 3D Tiles tileset floating high above the earth.

It also creates a debug bounding volume around the tileset. However, the debug bounding volume does not show up if you generate it before access tileset.boundingSphere. I have no idea why but it looks like accessing tileset.BoundingSphere might actually compute some data.

To see this, modify the code to uncomment out //const fixDebugVolume = tileset.boundingSphere; and the debug volume will suddenly show up.

const viewer = new Cesium.Viewer("cesiumContainer");

try {
  const scene = viewer.scene;
  
  const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(40866);
  tileset.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
    Cesium.Cartesian3.fromDegrees(0, 0)
  );
  scene.primitives.add(tileset);

  //const fixDebugVolume = tileset.boundingSphere;
  const tileBv = tileset.root.boundingVolume;
  scene.primitives.add(tileBv.createDebugVolume(Cesium.Color.WHITE));

  scene.camera.flyToBoundingSphere(tileset.boundingSphere, {
    endTransform: Cesium.Matrix4.IDENTITY,
    duration: 0,
  });
  
} catch (error) {
  console.log(`Error loading tileset: ${error}`);
} 

I also realized that leaving the line commented (i.e. broken) and then commenting out the tileset.ModelMatrix = line also fixes it (but the tileset is now in the wrong place) so clearly this has something to do with when the tileset modelMatrix gets applied to the bounding sphere,.

mramato avatar May 16 '23 01:05 mramato

Also reported in https://github.com/CesiumGS/cesium/issues/11893 when setting modelMatrix to the identity.

ggetz avatar Mar 26 '24 12:03 ggetz