/** * @description:动态立体墙材质 * @date: 2022-02-11 */ //动态墙材质 function DynamicWallMaterialProperty(options) { // 默认参数设置 this._definitionChanged = new Cesium.Event(); this._color = undefined; this._colorSubscription = undefined; this.color = options.color; this.duration = options.duration; this.trailImage = options.trailImage; this._time = (new Date()).getTime(); } Object.defineProperties(DynamicWallMaterialProperty.prototype, { isConstant: { get: function() { return false; } }, definitionChanged: { get: function() { return this._definitionChanged; } }, color: Cesium.createPropertyDescriptor('color') }); DynamicWallMaterialProperty.prototype.getType = function(time) { return 'DynamicWall'; }; DynamicWallMaterialProperty.prototype.getValue = function(time, result) { if (!Cesium.defined(result)) { result = {}; } result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color); if (this.trailImage) { result.image = this.trailImage; } else { result.image = Cesium.Material.DynamicWallImage } if (this.duration) { result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration; } viewer.scene.requestRender(); return result; }; DynamicWallMaterialProperty.prototype.equals = function(other) { return this === other || (other instanceof DynamicWallMaterialProperty && Cesium.Property.equals(this._color, other._color)) }; Cesium.DynamicWallMaterialProperty = DynamicWallMaterialProperty; Cesium.Material.DynamicWallType = 'DynamicWall'; // Cesium.Material.DynamicWallImage = "../images/overview/colors.png"; Cesium.Material.DynamicWallImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAAgCAYAAABkS8DlAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAADSSURBVHja7NYxEoUgDEDBYM39z2qHtZViwMFxt1FJnF/98ZXWWkRE7LWWOOt5Lsm9q/vsbu9Zdtazs/J19O5bs1XPZrwze/6V31zxbOZs1n905Wt2p3f25GzE7ohv6q3nLQCA3xEAACAAAAABAAAIAABAAAAAAgAAEAAAgAAAAAQAACAAAAABAAAIAABAAAAAAgAAEAAAgAAAAAQAACAAAEAAAAACAAAQAACAAAAABAAAIAAAAAEAAAgAAEAAAAACAAAQAACAAAAA8g4AAAD//wMA4WEFTJOT5UIAAAAASUVORK5CYII="; Cesium.Material.DynamicWallSource = "czm_material czm_getMaterial(czm_materialInput materialInput)\n\ {\n\ czm_material material = czm_getDefaultMaterial(materialInput);\n\ vec2 st = materialInput.st;\n\ vec4 colorImage = texture2D(image, vec2(fract(st.t - time), st.t));\n\ vec4 fragColor;\n\ fragColor.rgb = color.rgb / 1.0;\n\ fragColor = czm_gammaCorrect(fragColor);\n\ material.alpha = colorImage.a * color.a;\n\ material.diffuse = color.rgb;\n\ material.emission = fragColor.rgb;\n\ return material;\n\ }"; Cesium.Material._materialCache.addMaterial(Cesium.Material.DynamicWallType, { fabric: { type: Cesium.Material.DynamicWallType, uniforms: { color: new Cesium.Color(1.0, 1.0, 1.0, 1), image: Cesium.Material.DynamicWallImage, time: 0 }, source: Cesium.Material.DynamicWallSource }, translucent: function(material) { return true; } });