utils/weather/Snow.js

/*
 * @Author: jianlei wang
 * @Date: 2024-02-22 17:29:08
 * @Last Modified by: jianlei wang
 * @Last Modified time: 2024-03-28 15:16:29
 */
import { Cesium } from '../../../namespace'
import snowShader from '../shaders/weather/snow.glsl'
/**
 * 雪天气效果
 * @class
 */
class SnowEffect {
  /**
   * 构造函数
   * @param {Object} viewer - 地图场景对象
   */
  constructor(viewer) {
    this._viewer = viewer
    this._snowSize = 0.02 //最好小于0.02
    this._snowSpeed = 60.0
  }
  _init() {
    this._clear()
    this._snowStage = new Cesium.PostProcessStage({
      name: 'weather_snow',
      fragmentShader: snowShader,
      uniforms: {
        snowSize: () => this._snowSize,
        snowSpeed: () => this._snowSpeed,
      },
    })
    this._viewer.scene.postProcessStages.add(this._snowStage)
  }
  /**
   * 销毁对象
   */
  destroy() {
    this._clear()
    this._snowStage.destroy()
  }

  _clear() {
    if (!this._viewer || !this._snowStage) return
    this._viewer.scene.postProcessStages.remove(this._snowStage)
  }
  /**
   * 控制雪天气显示
   * @type {Boolean}
   */
  set show(bool) {
    bool ? this._init() : this._clear()
  }
}
export default SnowEffect