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
|
}
|