Bootstrap

cesium 3dtiles地形遮挡、设置离地高度

问题描述

在开启 viewer.scene.globe.depthTestAgainstTerrain = true //开启地形深度检测 后加载3dtiles数据会导致被地形遮挡,导致3d tiles数据看不见

解决办法

使用矩阵将模型高度提升

 const tilesets = viewer.scene.primitives.add(
    new Cesium.Cesium3DTileset({
      url: `${BASE_URL}/3DTiles/building/tileset.json`,
    }),
  )
  tilesets.readyPromise.then(function (tileset) {
    const offsetHeight = 100 
    const boundingSphere = tileset.boundingSphere 
    const cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center) 
    const surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0) 
    const offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, offsetHeight)
    const translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3())
    tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation)
    viewer.flyTo(tileset)
  })
;