Cesium 白膜半透明渐变效果-LMLPHP

export default class Tilesets {
  constructor(val) {
    this.viewer = val.viewer;
    this.tilesets = null;
    this.addtilesets();
  }

  // 添加3d模型
  addtilesets() {
    let _this = this;
    var tilesets = this.viewer.scene.primitives.add(
      new Cesium.Cesium3DTileset({
        url: 'http://58.48.30.30:29701/06hzmx/surroundingBuildings/tileset.json',
        maximumMemoryUsage: 100, 
        maximumScreenSpaceError: 50,
        shadows: false, 
      })
    );
    tilesets.readyPromise.then(function (tileset) {
      let r = tileset.boundingSphere.radius;
      if (tileset.boundingSphere.radius > 1000) {
        r = tileset.boundingSphere.radius / 10;
      }
      tileset.style = new Cesium.Cesium3DTileStyle({
        color: 'vec4(0.207, 0.588, 1.0,0.5)',
      });
      // 注入 shader
      tileset.tileVisible.addEventListener((tile) => {
        var content = tile.content;
        var featuresLength = content.featuresLength;
        for (var i = 0; i < featuresLength; i += 2) {
          const feature = content.getFeature(i);
          const model = feature.content._model;
          if (model && model._sourcePrograms && model._rendererResources) {
            Object.keys(model._sourcePrograms).forEach((key) => {
              const program = model._sourcePrograms[key];
              const fragmentShader =
                model._rendererResources.sourceShaders[program.fragmentShader];
              let vPosition = '';
              if (fragmentShader.indexOf(' v_positionEC;') !== -1) {
                vPosition = 'v_positionEC';
              } else if (fragmentShader.indexOf(' v_pos;') !== -1) {
                vPosition = 'v_pos';
              }
              const color = `vec4(${feature.color.toString()})`;
              // 自定义着色器
              model._rendererResources.sourceShaders[program.fragmentShader] = `
          varying vec3 ${vPosition};
          void main(void){
          vec4 v_helsing_position = czm_inverseModelView * vec4(${vPosition},1);
          float stc_pl = fract(czm_frameNumber /80.0) * 3.14159265 ;
          float stc_sd = v_helsing_position.z / 150.0 + sin(stc_pl) * 0.09;
          gl_FragColor = ${color};// 
          gl_FragColor += vec4(stc_sd, stc_sd, stc_sd, 0.5);// 高度渐变
          }
        `;
            });
            // 让系统重新编译着色器
            model._shouldRegenerateShaders = true;
          }
        }
      });
      _this.viewer.flyTo(tileset);
    });
    this.tilesets = tilesets;
  }

  // 删除实体
  deleteEntity() {
    this.viewer.scene.primitives.remove(this.tilesets);
  }
}

03-13 12:46