111 lines
3.1 KiB
JavaScript
111 lines
3.1 KiB
JavaScript
|
/*
|
||
|
* @Description: 流动线
|
||
|
*/
|
||
|
function LineTexture() {
|
||
|
class LineTextureMaterialProperty {
|
||
|
constructor(options) {
|
||
|
this._definitionChanged = new Cesium.Event();
|
||
|
this._image = undefined;
|
||
|
this._color = undefined;
|
||
|
this._imageW = undefined;
|
||
|
this.image = options.image || "";
|
||
|
this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)");
|
||
|
this.imageW = options.imageW || 1;
|
||
|
}
|
||
|
|
||
|
get isConstant() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
get definitionChanged() {
|
||
|
return this._definitionChanged;
|
||
|
}
|
||
|
|
||
|
getType(time) {
|
||
|
return Cesium.Material.LineTextureMaterialType;
|
||
|
}
|
||
|
|
||
|
getValue(time, result) {
|
||
|
if (!Cesium.defined(result)) {
|
||
|
result = {};
|
||
|
}
|
||
|
result.image = Cesium.Property.getValueOrDefault(
|
||
|
this._image,
|
||
|
time,
|
||
|
"",
|
||
|
result.image
|
||
|
);
|
||
|
result.color = Cesium.Property.getValueOrDefault(
|
||
|
this._color,
|
||
|
time,
|
||
|
Cesium.Color.RED,
|
||
|
result.color
|
||
|
);
|
||
|
result.imageW = Cesium.Property.getValueOrDefault(
|
||
|
this._imageW,
|
||
|
time,
|
||
|
1,
|
||
|
result.imageW
|
||
|
);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
equals(other) {
|
||
|
return (
|
||
|
this === other ||
|
||
|
(other instanceof LineTextureMaterialProperty &&
|
||
|
Cesium.Property.equals(this._image, other._image) &&
|
||
|
Cesium.Property.equals(this._color, other._color) &&
|
||
|
Cesium.Property.equals(this._imageW, other._imageW))
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Object.defineProperties(LineTextureMaterialProperty.prototype, {
|
||
|
image: Cesium.createPropertyDescriptor("image"),
|
||
|
color: Cesium.createPropertyDescriptor("color"),
|
||
|
imageW: Cesium.createPropertyDescriptor("imageW"),
|
||
|
});
|
||
|
|
||
|
Cesium.LineTextureMaterialProperty = LineTextureMaterialProperty;
|
||
|
Cesium.Material.LineTextureMaterialProperty = "LineTextureMaterialProperty";
|
||
|
Cesium.Material.LineTextureMaterialType = "LineTextureMaterialType";
|
||
|
Cesium.Material.LineTextureMaterialSource = `
|
||
|
#extension GL_OES_standard_derivatives : enable
|
||
|
czm_material czm_getMaterial(czm_materialInput materialInput)
|
||
|
{
|
||
|
czm_material m = czm_getDefaultMaterial(materialInput);
|
||
|
|
||
|
|
||
|
vec2 st = materialInput.st * vec2(494/172, 1.0); // 横向重复两次
|
||
|
vec2 uv = vec2(fract(st.s + uTime*0.1), st.t);
|
||
|
// uv.y = mix(uv.y, 1.0-uv.y, step(0.5, fract(uTime))); // 周期性反转Y轴
|
||
|
vec4 tex = texture(image, uv);
|
||
|
m.diffuse =(tex.rgb+color.rgb)/2.0;
|
||
|
m.alpha = tex.a * (1.0 - fract(st.t)) * color.a; // 顶部渐隐
|
||
|
|
||
|
return m;
|
||
|
}
|
||
|
`;
|
||
|
Cesium.Material._materialCache.addMaterial(
|
||
|
Cesium.Material.LineTextureMaterialType,
|
||
|
{
|
||
|
fabric: {
|
||
|
type: Cesium.Material.LineTextureMaterialType,
|
||
|
uniforms: {
|
||
|
color: new Cesium.Color(1.0, 1.0, 1.0, 1.0),
|
||
|
image: '',
|
||
|
imageW: 1,
|
||
|
uTime: 1
|
||
|
},
|
||
|
source: Cesium.Material.LineTextureMaterialSource,
|
||
|
},
|
||
|
translucent: function (material) {
|
||
|
return true;
|
||
|
},
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
export { LineTexture }
|