radarScanMaterialProperty copy.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * @Description: 雷达扫描效果(参考开源代码)
  3. * @Version: 1.0
  4. * @Author: Julian
  5. * @Date: 2022-03-04 20:02:48
  6. * @LastEditors: Julian
  7. * @LastEditTime: 2022-03-05 15:26:47
  8. */
  9. class RadarScanMaterialProperty {
  10. constructor(options) {
  11. this._definitionChanged = new Cesium.Event();
  12. this._color = undefined;
  13. this._speed = undefined;
  14. this.color = options.color;
  15. this.speed = options.speed;
  16. };
  17. get isConstant() {
  18. return false;
  19. }
  20. get definitionChanged() {
  21. return this._definitionChanged;
  22. }
  23. getType(time) {
  24. return Cesium.Material.RadarScanMaterialType;
  25. }
  26. getValue(time, result) {
  27. if (!Cesium.defined(result)) {
  28. result = {};
  29. }
  30. result.color = Cesium.Property.getValueOrDefault(this._color, time, Cesium.Color.RED, result.color);
  31. result.speed = Cesium.Property.getValueOrDefault(this._speed, time, 10, result.speed);
  32. return result
  33. }
  34. equals(other) {
  35. return (this === other ||
  36. (other instanceof RadarScanMaterialProperty &&
  37. Cesium.Property.equals(this._color, other._color) &&
  38. Cesium.Property.equals(this._speed, other._speed))
  39. )
  40. }
  41. }
  42. Object.defineProperties(RadarScanMaterialProperty.prototype, {
  43. color: Cesium.createPropertyDescriptor('color'),
  44. speed: Cesium.createPropertyDescriptor('speed')
  45. })
  46. Cesium.RadarScanMaterialProperty = RadarScanMaterialProperty;
  47. Cesium.Material.RadarScanMaterialProperty = 'RadarScanMaterialProperty';
  48. Cesium.Material.RadarScanMaterialType = 'RadarScanMaterialType';
  49. Cesium.Material.RadarScanMaterialSource =
  50. `
  51. uniform vec4 color;
  52. uniform float speed;
  53. #define PI 3.14159265359
  54. czm_material czm_getMaterial(czm_materialInput materialInput){
  55. czm_material material = czm_getDefaultMaterial(materialInput);
  56. vec2 st = materialInput.st;
  57. vec2 scrPt = st * 2.0 - 1.0;
  58. float time = czm_frameNumber * speed / 1000.0 ;
  59. vec3 col = vec3(0.0);
  60. mat2 rot;
  61. float theta = -time * 1.0 * PI - 2.2;
  62. float cosTheta, sinTheta;
  63. cosTheta = cos(theta);
  64. sinTheta = sin(theta);
  65. rot[0][0] = cosTheta;
  66. rot[0][1] = -sinTheta;
  67. rot[1][0] = sinTheta;
  68. rot[1][1] = cosTheta;
  69. vec2 scrPtRot = rot * scrPt;
  70. float angle = 1.0 - (atan(scrPtRot.y, scrPtRot.x) / 6.2831 + 0.5);
  71. float falloff = length(scrPtRot);
  72. material.alpha = pow(length(col + vec3(.5)),5.0);
  73. material.diffuse = (0.5 + pow(angle, 2.0) * falloff ) * color.rgb ;
  74. return material;
  75. }
  76. `
  77. Cesium.Material._materialCache.addMaterial(Cesium.Material.RadarScanMaterialType, {
  78. fabric: {
  79. type: Cesium.Material.RadarScanMaterialType,
  80. uniforms: {
  81. color: new Cesium.Color(1.0, 0.0, 0.0, 1.0),
  82. speed: 10.0
  83. },
  84. source: Cesium.Material.RadarScanMaterialSource
  85. },
  86. translucent: function (material) {
  87. return true;
  88. }
  89. })