From 751baac5dd17e5bb11be51f4ead18890a2cb193e Mon Sep 17 00:00:00 2001 From: DIAMOND <276397553@qq.com> Date: Tue, 2 Jan 2024 16:26:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=9B=B7=E8=BE=BE=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E4=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/earthMap/radarEntity.ts | 106 +++++++++++++++++++++++++- src/views/earthMap/edit/EarthComp.vue | 27 ++++++- 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/src/utils/earthMap/radarEntity.ts b/src/utils/earthMap/radarEntity.ts index 7c03659..d78cccc 100644 --- a/src/utils/earthMap/radarEntity.ts +++ b/src/utils/earthMap/radarEntity.ts @@ -295,6 +295,110 @@ class CircleScan { } +/* + 方式二 + * @Description: 雷达扫描效果(参考开源代码) + * @Version: 1.0 + * @Author: Julian + * @Date: 2022-03-04 20:02:48 + * @LastEditors: Julian + * @LastEditTime: 2022-03-05 15:26:47 + */ +class RadarScanMaterialProperty { + constructor(options) { + this._definitionChanged = new Cesium.Event(); + this._color = undefined; + this._speed = undefined; + this.color = options.color; + this.speed = options.speed; + }; + + 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); + return result + } + + equals(other) { + return (this === other || + (other instanceof RadarScanMaterialProperty && + Cesium.Property.equals(this._color, other._color) && + Cesium.Property.equals(this._speed, other._speed)) + ) + } +} + +Object.defineProperties(RadarScanMaterialProperty.prototype, { + color: Cesium.createPropertyDescriptor('color'), + speed: Cesium.createPropertyDescriptor('speed') +}) + +Cesium.RadarScanMaterialProperty = RadarScanMaterialProperty; +Cesium.Material.RadarScanMaterialProperty = 'RadarScanMaterialProperty'; +Cesium.Material.RadarScanMaterialType = 'RadarScanMaterialType'; +Cesium.Material.RadarScanMaterialSource = + ` + uniform vec4 color; + uniform float speed; + + #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 = czm_frameNumber * speed / 1000.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 = color.a*pow(length(col + vec3(.5)),5.0); + material.diffuse = (0.5 + pow(angle, 2.0) * falloff ) * color.rgb ; + return material; + } + + ` +// material.alpha = pow(length(col + vec3(.5)),5.0); +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 + }, + source: Cesium.Material.RadarScanMaterialSource + }, + translucent: function (material) { + return true; + } +}) + + export { - CircleScan + CircleScan, RadarScanMaterialProperty } diff --git a/src/views/earthMap/edit/EarthComp.vue b/src/views/earthMap/edit/EarthComp.vue index 12ca715..6675c7b 100644 --- a/src/views/earthMap/edit/EarthComp.vue +++ b/src/views/earthMap/edit/EarthComp.vue @@ -2203,12 +2203,33 @@ let degreePosition = radianToDegreeInLngLatHeight( pickedFeature.id._xbsjOwner.position[0], pickedFeature.id._xbsjOwner.position[1], - pickedFeature.id._xbsjOwner.position[2] + 0.1 ) - //创建雷达扫描 + //创建雷达扫描 深度 + // this._viewer.scene.globe.depthTestAgainstTerrain = true; let rader = new CircleScan(this._viewer) - rader.add(degreePosition, null, radarRadius, 3000); + rader.add(degreePosition, null, radarRadius, 10000); pickedFeature.id._xbsjOwner.addViewShedReturn= rader + + // 雷达扫描2 + // let rader2 = this._viewer.entities.add({ + // position: Cesium.Cartesian3.fromDegrees(113.528333, 22.156109), + // name: '雷达扫描', + // ellipse: { + // semiMajorAxis: 5000.0, + // semiMinorAxis: 5000.0, + // material: new Cesium.RadarScanMaterialProperty({ + // color: new Cesium.Color(1.0, 1.0, 0.0, 0.7), + // speed: 20.0, + // }), + // height: 20.0, + // heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, + // outline: true, + // outlineColor: new Cesium.Color(1.0, 1.0, 0.0, 1.0) + // } + // }) + + // pickedFeature.id._xbsjOwner.addViewShedReturn= addViewShedRadar( // pickedFeature.id._xbsjOwner.position, // radarRadius,