forked from drone/command-center-dashboard

罗广辉
2025-04-21 2800fa4f32f3900509cb4d6eefaf2bfaf54efdd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as Cesium from 'cesium'
 
let pM = "PolyGradientMaterial"
Cesium.Material._materialCache.addMaterial(pM, {
  strict: true,
  fabric: {
    type: pM,
    uniforms: {
      color: new Cesium.Color(1.0, 1.0, 0.0, 0.5),
      diffusePower: 1.6,
      alphaPower: 1.5,
      center: new Cesium.Cartesian2(0.5, 0.5),
      isInner: false,
      globalAlpha: 1.0,
    },
    source: `
            uniform vec4 color;
            uniform float diffusePower;
            uniform float alphaPower;
            uniform float globalAlpha;
            uniform vec2 center;
            uniform bool isInner;
 
            czm_material czm_getMaterial(czm_materialInput materialInput) {
                czm_material material = czm_getDefaultMaterial(materialInput);
                vec2 st = materialInput.st;
                float alphaMars3D = distance(st, center);
 
                if(isInner) {
                    material.alpha = (1.0 - (color.a * alphaMars3D * alphaPower)) * globalAlpha;
                    if(material.alpha < 0.0) material.alpha = 0.0;
                } else {
                    material.alpha = color.a * alphaMars3D * alphaPower * globalAlpha;
                }
 
                material.diffuse = color.rgb * diffusePower;
                return material;
            }
        `,
  },
  translucent: true,
})
 
class MaterialProperty {
  constructor(options = {}) {
    this._definitionChanged = new Cesium.Event()
    this._color = undefined
    this._opacity = undefined
    this._alphaPower = undefined
 
    this.color = options.color || Cesium.Color.fromBytes(0, 255, 255, 255)
 
    this.opacity = options.opacity || 0.5
    this.alphaPower = options.alphaPower || 1.5
  }
 
  get isConstant () {
    return false
  }
 
  get definitionChanged () {
    return this._definitionChanged
  }
 
  getType (time) {
    return null
  }
 
  getValue (time, result) {
    result = Cesium.defaultValue(result, {})
    return result
  }
 
  equals (other) {
    return this === other
  }
}
 
class PolyGradientMaterial extends MaterialProperty {
  constructor(options = {}) {
    super(options)
  }
 
  getType (time) {
    return pM
  }
 
  getValue (time, result) {
    if (!result) {
      result = {}
    }
 
    result.color = Cesium.Property.getValueOrUndefined(this._color, time)
    result.globalAlpha = Cesium.Property.getValueOrUndefined(this._opacity, time)
    result.alphaPower = Cesium.Property.getValueOrUndefined(this._alphaPower, time)
    return result
  }
 
  equals (other) {
    return (
      this === other ||
      (other instanceof PolyGradientMaterial &&
        Cesium.Property.equals(this._color, other._color) &&
        Cesium.Property.equals(this._opacity, other._opacity) &&
        Cesium.Property.equals(this._alphaPower, other._alphaPower))
    )
  }
}
 
Object.defineProperties(PolyGradientMaterial.prototype, {
  color: Cesium.createPropertyDescriptor('color'),
  opacity: Cesium.createPropertyDescriptor('opacity'),
  alphaPower: Cesium.createPropertyDescriptor('alphaPower'),
})
 
export {
  PolyGradientMaterial
}