From 2800fa4f32f3900509cb4d6eefaf2bfaf54efdd7 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Mon, 21 Apr 2025 18:29:09 +0800
Subject: [PATCH] fix: 天气显示

---
 src/utils/cesium/ImageTrailMaterial.js |  146 +++++++++++++++++++++++-------------------------
 1 files changed, 70 insertions(+), 76 deletions(-)

diff --git a/src/utils/cesium/ImageTrailMaterial.js b/src/utils/cesium/ImageTrailMaterial.js
index 1e1092c..ce96d8a 100644
--- a/src/utils/cesium/ImageTrailMaterial.js
+++ b/src/utils/cesium/ImageTrailMaterial.js
@@ -1,85 +1,80 @@
-import * as Cesium from 'cesium';
+import * as Cesium from 'cesium'
 /**
  * 定义Cesium材质对象
  */
 class ImageTrailMaterial {
-    constructor(options = {}) {
-        this._definitionChanged = new Cesium.Event();
-        this._color = void 0;
-        this._colorSubscription = void 0;
-        this._speed = void 0;
-        this._speedSubscription = void 0;
-        this._image = void 0;
-        this._imageSubscription = void 0;
-        this._repeat = void 0;
-        this._repeatSubscription = void 0;
-        this.color = options.color || Cesium.Color.fromBytes(0, 0, 255, 255);
-        this.speed = options.speed || 1;
-        this.image = options.image;
-        this.repeat = new Cesium.Cartesian2(
-            options.repeat?.x || 1,
-            options.repeat?.y || 1,
-        );
-    }
+	constructor(options = {}) {
+		this._definitionChanged = new Cesium.Event()
+		this._color = void 0
+		this._colorSubscription = void 0
+		this._speed = void 0
+		this._speedSubscription = void 0
+		this._image = void 0
+		this._imageSubscription = void 0
+		this._repeat = void 0
+		this._repeatSubscription = void 0
+		this.color = options.color || Cesium.Color.fromBytes(0, 0, 255, 255)
+		this.speed = options.speed || 1
+		this.image = options.image
+		this.repeat = new Cesium.Cartesian2(options.repeat?.x || 1, options.repeat?.y || 1)
+	}
 
-    get isConstant() {
-        return false;
-    }
+	get isConstant() {
+		return false
+	}
 
-    get definitionChanged() {
-        return this._definitionChanged;
-    }
+	get definitionChanged() {
+		return this._definitionChanged
+	}
 
-    getType() {
-        return Cesium.Material.ImageTrailMaterialType;
-    }
+	getType() {
+		return Cesium.Material.ImageTrailMaterialType
+	}
 
-    getValue(time, result) {
-        if (!result) {
-            result = {};
-        }
-        result.color = Cesium.Property.getValueOrUndefined(this._color, time);
-        result.image = Cesium.Property.getValueOrUndefined(this._image, time);
-        result.repeat = Cesium.Property.getValueOrUndefined(this._repeat, time);
-        result.speed = this._speed;
-        return result;
-    }
+	getValue(time, result) {
+		if (!result) {
+			result = {}
+		}
+		result.color = Cesium.Property.getValueOrUndefined(this._color, time)
+		result.image = Cesium.Property.getValueOrUndefined(this._image, time)
+		result.repeat = Cesium.Property.getValueOrUndefined(this._repeat, time)
+		result.speed = this._speed
+		return result
+	}
 
-    equals(other) {
-        return (
-            this === other ||
-            (other instanceof ImageTrailMaterial &&
-                Cesium.Property.equals(this._color, other._color) &&
-                Cesium.Property.equals(this._image, other._image) &&
-                Cesium.Property.equals(this._repeat, other._repeat) &&
-                Cesium.Property.equals(this._speed, other._speed))
-        );
-    }
+	equals(other) {
+		return (
+			this === other ||
+			(other instanceof ImageTrailMaterial &&
+				Cesium.Property.equals(this._color, other._color) &&
+				Cesium.Property.equals(this._image, other._image) &&
+				Cesium.Property.equals(this._repeat, other._repeat) &&
+				Cesium.Property.equals(this._speed, other._speed))
+		)
+	}
 }
 
 Object.defineProperties(ImageTrailMaterial.prototype, {
-    color: Cesium.createPropertyDescriptor('color'),
-    speed: Cesium.createPropertyDescriptor('speed'),
-    image: Cesium.createPropertyDescriptor('image'),
-    repeat: Cesium.createPropertyDescriptor('repeat'),
-});
+	color: Cesium.createPropertyDescriptor('color'),
+	speed: Cesium.createPropertyDescriptor('speed'),
+	image: Cesium.createPropertyDescriptor('image'),
+	repeat: Cesium.createPropertyDescriptor('repeat'),
+})
 //材质类型
-Cesium.Material.ImageTrailMaterialType = 'PolylineImageTrail';
+Cesium.Material.ImageTrailMaterialType = 'PolylineImageTrail'
 //添加材质到缓冲区中
-Cesium.Material._materialCache.addMaterial(
-    Cesium.Material.ImageTrailMaterialType,
-    {
-        fabric: {
-            type: Cesium.Material.ImageTrailMaterialType,
-            //uniform变量
-            uniforms: {
-                color: new Cesium.Color(1.0, 0.0, 0.0, 0.7),
-                image: Cesium.Material.DefaultImageId,
-                speed: 1,
-                repeat: new Cesium.Cartesian2(1, 1),
-            },
-            //
-            source: `
+Cesium.Material._materialCache.addMaterial(Cesium.Material.ImageTrailMaterialType, {
+	fabric: {
+		type: Cesium.Material.ImageTrailMaterialType,
+		//uniform变量
+		uniforms: {
+			color: new Cesium.Color(1.0, 0.0, 0.0, 0.7),
+			image: Cesium.Material.DefaultImageId,
+			speed: 1,
+			repeat: new Cesium.Cartesian2(1, 1),
+		},
+		//
+		source: `
                     uniform sampler2D image; 
                     uniform float speed;
                     uniform vec4 color;
@@ -89,19 +84,18 @@
                         czm_material material=czm_getDefaultMaterial(materialInput);
                         vec2 st=repeat * materialInput.st;
                         float time=fract(czm_frameNumber*speed/1000.);
-                        vec4 colorImage=texture2D(image,vec2(fract(st.s-time),st.t));
+                        vec4 colorImage=texture(image,vec2(fract(st.s-time),st.t)); // 修改 texture2D 为 texture
                         material.alpha = colorImage.a * color.a;
                         material.diffuse = (colorImage.rgb+color.rgb)/2.0;
                         return material;
                     }
                     `,
-        },
-        translucent: function () {
-            return true;
-        },
-    },
-);
-export default ImageTrailMaterial;
+	},
+	translucent: function () {
+		return true
+	},
+})
+export default ImageTrailMaterial
 
 //之前的航线材质编写
 // source: `

--
Gitblit v1.9.3