/** * @description 测试 */ import MaterialProperty from "./MaterialProperty"; class PolylineImageTrailMaterialProperty extends MaterialProperty { constructor(options = {}) { super(options); /** * 定义Cesium材质对象 */ Cesium.Material.PolylineImageTrailType = "PolylineImageTrail"; Cesium.Material._materialCache.addMaterial( Cesium.Material.PolylineImageTrailType, { fabric: { type: Cesium.Material.PolylineImageTrailType, uniforms: { color: new Cesium.Color(1.0, 0.0, 0.0, 0.1), image: Cesium.Material.DefaultImageId, speed: 1, repeat: new Cesium.Cartesian2(1, 1), rotate: 0 }, source: `uniform sampler2D image; uniform float speed; uniform vec4 color; uniform vec2 repeat; czm_material czm_getMaterial(czm_materialInput materialInput){ czm_material material=czm_getDefaultMaterial(materialInput); mat2 rotationMatrix = mat2(cos(radians(-rotate)), sin(radians(-rotate)), -sin(radians(-rotate)), cos(radians(-rotate))); vec2 st=repeat*materialInput.st*rotationMatrix; float time=fract(czm_frameNumber); vec4 colorImage=texture2D(image,vec2(fract(st.s-time),st.t)); material.alpha=colorImage.a; material.diffuse=colorImage.rgb; return material; }`, }, isTranslucent: function () { return true; }, } ); // Object.defineProperties(PolylineImageTrailMaterialProperty.prototype, { // color: Cesium.createPropertyDescriptor("color"), // speed: Cesium.createPropertyDescriptor("speed"), // image: Cesium.createPropertyDescriptor("image"), // repeat: Cesium.createPropertyDescriptor("repeat"), // }); this._image = undefined; this._imageSubscription = undefined; this._repeat = undefined; this._repeatSubscription = undefined; this.image = options.image; this.repeat = new Cesium.Cartesian2( options.repeat?.x || 1, options.repeat?.y || 1 ); this.rotate = options.rotate let i=1 // setInterval(() => { // this.repeat = new Cesium.Cartesian2( // i++, // options.repeat?.y || 1 // ); // console.log(this.repeat) // }, 1000); // setInterval(() => { // this.rotate ++ // }, 100); } getType() { return Cesium.Material.PolylineImageTrailType; } getValue(time, result) { if (!result) { result = {}; } result.color = this.color; result.image = this.image; result.repeat = this.repeat; result.speed = this.speed; result.rotate = this.rotate // console.log(result.repeat) return result; } equals(other) { return ( this === other || (other instanceof PolylineImageTrailMaterialProperty && 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) && Cesium.Property.equals(this.rotate, other._rotate)) ); } } export default PolylineImageTrailMaterialProperty;