Files
sdk4.0/src/Obj/Materail/RadarScanMaterialProperty.js

122 lines
3.4 KiB
JavaScript
Raw Normal View History

2025-07-03 13:54:01 +08:00
/*
* @Description: 雷达扫描效果
*/
function RadarScan() {
class RadarScanMaterialProperty {
constructor(options) {
this._definitionChanged = new Cesium.Event();
this._color = undefined;
this._speed = undefined;
this.color = options.color;
this.speed = options.speed;
this.transparency = options.transparency;
}
get isConstant() {
return false;
}
get definitionChanged() {
return this._definitionChanged;
}
getType(time) {
return Cesium.Material.RadarScanMaterialType;
}
getValue(time, result) {
if (!Cesium.defined(result)) {
result = {};
}
result.color = Cesium.Property.getValueOrDefault(
this._color,
time,
Cesium.Color.RED,
result.color
);
result.speed = Cesium.Property.getValueOrDefault(
this._speed,
time,
10,
result.speed
);
result.transparency = this.transparency;
result.frameNumber = Cesium.getTimestamp();
return result;
}
equals(other) {
return (
this === other ||
(other instanceof RadarScanMaterialProperty &&
Cesium.Property.equals(this._color, other._color) &&
Cesium.Property.equals(this._speed, other._speed) &&
Cesium.Property.equals(this.transparency, other.transparency))
);
}
}
Object.defineProperties(RadarScanMaterialProperty.prototype, {
color: Cesium.createPropertyDescriptor("color"),
speed: Cesium.createPropertyDescriptor("speed"),
transparency: Cesium.createPropertyDescriptor("transparency"),
});
Cesium.RadarScanMaterialProperty = RadarScanMaterialProperty;
Cesium.Material.RadarScanMaterialProperty = "RadarScanMaterialProperty";
Cesium.Material.RadarScanMaterialType = "RadarScanMaterialType";
Cesium.Material.RadarScanMaterialSource = `
uniform vec4 color;
uniform float speed;
uniform float transparency;
uniform float frameNumber;
#define PI 3.14159265359
czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);
vec2 st = materialInput.st;
vec2 scrPt = st * 2.0 - 1.0;
float time = frameNumber * speed / 30000.0 ;
vec3 col = vec3(0.0);
mat2 rot;
float theta = -time * 1.0 * PI - 2.2;
float cosTheta, sinTheta;
cosTheta = cos(theta);
sinTheta = sin(theta);
rot[0][0] = cosTheta;
rot[0][1] = -sinTheta;
rot[1][0] = sinTheta;
rot[1][1] = cosTheta;
vec2 scrPtRot = rot * scrPt;
float angle = 1.0 - (atan(scrPtRot.y, scrPtRot.x) / 6.2831 + 0.5);
float falloff = length(scrPtRot);
material.alpha = pow(length(col + vec3(.5)),5.0) * transparency * 0.6;
material.diffuse = (0.5 + pow(angle, 2.0) * falloff ) * color.rgb ;
return material;
}
`;
Cesium.Material._materialCache.addMaterial(
Cesium.Material.RadarScanMaterialType,
{
fabric: {
type: Cesium.Material.RadarScanMaterialType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 1.0),
speed: 10.0,
transparency: 1,
frameNumber: Cesium.getTimestamp(),
},
source: Cesium.Material.RadarScanMaterialSource,
},
translucent: function (material) {
return true;
},
}
);
}
export { RadarScan }