首页 > 其他分享 >Cesium地下模式

Cesium地下模式

时间:2022-12-14 14:44:08浏览次数:40  
标签:index const imageryLayers globe scene 模式 Cesium 地下 true

Cesium 地下模式

在一般的业务场景中,例如地下管线这些需要看地下模型的场景时候,需要开启地下模式。而开启地下模式也非常简单

开启地下模式

注释可见

const enterUnderGround = () => {
  const { scene } = viewer;
  const { globe } = viewer.scene;
  const { imageryLayers } = viewer;
  scene.globe.depthTestAgainstTerrain = false;
  scene.screenSpaceCameraController.inertiaZoom = 0.5;//调整相机惯性缩放时长
  scene.screenSpaceCameraController.enableCollisionDetection = false;//禁用相机与地形的碰撞检测
  scene.highDynamicRange = false;//关闭高动态范围渲染
  scene.skyAtmosphere.show = false;//关闭大气
  scene.skyBox.show = false;//关闭天空盒
  scene.fog.enabled = false;//关闭雾
  globe.baseColor = Color.BLACK;
  if (imageryLayers && imageryLayers.length > 0) {
    // 遍历所有的影像,把影像透明度调整为0.7
    for (let index = 0; index < imageryLayers.length; index++) {
      const layer = imageryLayers.get(index);
      layer.alpha = 0.2;
    }
  }
  //当相机在地下或地球是半透明时渲染地球背面的颜色,根据相机的距离与地球颜色混合。
  globe.undergroundColor = Color.BLACK;
  //获取或设置 Globe#undergroundColor 与地球颜色混合的近距离和远距离
  globe.undergroundColorAlphaByDistance.near = 1000;
  globe.undergroundColorAlphaByDistance.far = 1000000;
  globe.undergroundColorAlphaByDistance.nearValue = 0;
  globe.undergroundColorAlphaByDistance.farValue = 1;
};

关闭地下模式

const cancelUnderGround = () => {
  const { scene } = viewer;
  const { globe } = viewer.scene;
  const { imageryLayers } = viewer;
  scene.globe.depthTestAgainstTerrain = true;

  // 退出地下模式的参数---------------------------------------------------
  const originalOpts = {
    baseColor: globe.baseColor,
    alpha: 1.0,
    skyBox: true,
    skyAtmosphere: true,
    highDynamicRange: true,
    fog: true,
  };
  //启用或禁用相机与地形的碰撞检测
  scene.screenSpaceCameraController.enableCollisionDetection = true;
  scene.highDynamicRange = originalOpts.highDynamicRange;
  scene.skyAtmosphere.show = originalOpts.skyAtmosphere;
  scene.skyBox.show = originalOpts.skyBox;
  scene.fog.enabled = originalOpts.fog;
  globe.baseColor - originalOpts.baseColor;
  if (imageryLayers && imageryLayers.length > 0) {
    // 遍历所有的影像,把影像透明度调整回来
    for (let index = 0; index < imageryLayers.length; index++) {
      const layer = imageryLayers.get(index);
      layer.alpha = 1;
    }
  }
};

标签:index,const,imageryLayers,globe,scene,模式,Cesium,地下,true
From: https://www.cnblogs.com/webglblog/p/16982119.html

相关文章