4x/irrigation-monitoring-platf.../public/Cesium/dynamicWallMaterial.js

120 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2024-12-26 19:24:07 +08:00
/**
* color颜色颜色
* speed速度越低越快
* count条数分隔条数
* freely纵横vertical纵cross横
* direction方向
* '-'由下到上'+'由上到下
* '-'顺时针'+'逆时针
*/
function DynamicWallMaterialProperty(
color,
speed,
count,
freely,
direction,
img
) {
this._definitionChanged = new Cesium.Event();
this.color = color;
this.speed = speed;
this.count = count;
this.freely = freely;
this.direction = direction;
this.img = img;
DynamicWallMaterialProperty.prototype.init(
color,
speed,
count,
freely,
direction,
img
);
}
Object.defineProperties(DynamicWallMaterialProperty.prototype, {
isConstant: {
get: function () {
return false;
},
},
definitionChanged: {
get: function () {
return this._definitionChanged;
},
},
});
DynamicWallMaterialProperty.prototype.getType = function (time) {
return "DynamicWall";
};
DynamicWallMaterialProperty.prototype.getValue = function (time, result) {
if (!Cesium.defined(result)) {
result = {};
}
//console.log(" this.color1", this.color);
result.color = this.color;
result.speed = this.speed;
result.count = this.count;
result.freely = this.freely;
result.direction = this.direction;
result.img = this.img;
return result;
};
DynamicWallMaterialProperty.prototype.equals = function (other) {
return false;
//return this === other || (other instanceof DynamicWallMaterialProperty && Cesium.Property.equals(this._color, other._color));
};
DynamicWallMaterialProperty.prototype.init = function (
color,
speed,
count,
freely,
direction,
img
) {
var sourceStr =
"czm_material czm_getMaterial(czm_materialInput materialInput)\n";
sourceStr += "{\n";
sourceStr += "float time = czm_frameNumber / " + speed + ";\n";
sourceStr +=
"czm_material material = czm_getDefaultMaterial(materialInput);\n";
sourceStr += "vec2 st = materialInput.st;\n";
if (freely == "vertical") {
//(由下到上)
sourceStr =
sourceStr +
"vec4 colorImage = texture2D(image, vec2(fract( " +
count +
"*st.t " +
direction +
" time), fract(st.s)));\n ";
} else {
//(逆时针)
sourceStr =
sourceStr +
"vec4 colorImage = texture2D(image, vec2(fract( " +
count +
"*st.s " +
direction +
" time), fract(st.t)));\n ";
}
sourceStr += "material.diffuse = color.rgb;\n ";
sourceStr += "material.alpha = (colorImage.a * color.a);\n ";
sourceStr += "return material;\n";
sourceStr += "}\n";
var uniforms = {
color: color,
image: img,
};
Cesium.Material._materialCache.addMaterial("DynamicWall", {
fabric: {
type: "DynamicWall",
uniforms: uniforms,
source: sourceStr,
},
translucent: true,
});
};