2025-07-03 16:28:48 +08:00
|
|
|
|
/*
|
|
|
|
|
* @Description: 流动线
|
|
|
|
|
*/
|
|
|
|
|
function LineTexture() {
|
|
|
|
|
class LineTextureMaterialProperty {
|
|
|
|
|
constructor(options) {
|
|
|
|
|
this._definitionChanged = new Cesium.Event();
|
|
|
|
|
this._image = undefined;
|
|
|
|
|
this._color = undefined;
|
2025-07-07 16:21:01 +08:00
|
|
|
|
this._speed = undefined;
|
|
|
|
|
this._repeat = undefined;
|
2025-07-03 16:28:48 +08:00
|
|
|
|
this.image = options.image || "";
|
|
|
|
|
this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)");
|
2025-07-07 16:21:01 +08:00
|
|
|
|
this.speed = options.speed != undefined ? options.speed : 1.0;
|
|
|
|
|
this.repeat = options.repeat || 1.0;
|
2025-07-03 16:28:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
);
|
2025-07-07 16:21:01 +08:00
|
|
|
|
result.speed = Cesium.Property.getValueOrDefault(
|
|
|
|
|
this._speed,
|
2025-07-03 16:28:48 +08:00
|
|
|
|
time,
|
2025-07-07 16:21:01 +08:00
|
|
|
|
1.0,
|
|
|
|
|
result.speed
|
|
|
|
|
);
|
|
|
|
|
result.repeat = Cesium.Property.getValueOrDefault(
|
|
|
|
|
this._repeat,
|
|
|
|
|
time,
|
|
|
|
|
1.0,
|
|
|
|
|
result.repeat
|
2025-07-03 16:28:48 +08:00
|
|
|
|
);
|
2025-07-09 11:26:33 +08:00
|
|
|
|
result.frameNumber = Cesium.getTimestamp();
|
2025-07-03 16:28:48 +08:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
equals(other) {
|
|
|
|
|
return (
|
|
|
|
|
this === other ||
|
|
|
|
|
(other instanceof LineTextureMaterialProperty &&
|
|
|
|
|
Cesium.Property.equals(this._image, other._image) &&
|
|
|
|
|
Cesium.Property.equals(this._color, other._color) &&
|
2025-07-07 16:21:01 +08:00
|
|
|
|
Cesium.Property.equals(this._imageW, other._imageW) &&
|
|
|
|
|
Cesium.Property.equals(this._speed, other._speed))
|
2025-07-03 16:28:48 +08:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object.defineProperties(LineTextureMaterialProperty.prototype, {
|
|
|
|
|
image: Cesium.createPropertyDescriptor("image"),
|
|
|
|
|
color: Cesium.createPropertyDescriptor("color"),
|
2025-07-07 16:21:01 +08:00
|
|
|
|
speed: Cesium.createPropertyDescriptor("speed"),
|
|
|
|
|
repeat: Cesium.createPropertyDescriptor("repeat"),
|
2025-07-03 16:28:48 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Cesium.LineTextureMaterialProperty = LineTextureMaterialProperty;
|
|
|
|
|
Cesium.Material.LineTextureMaterialProperty = "LineTextureMaterialProperty";
|
|
|
|
|
Cesium.Material.LineTextureMaterialType = "LineTextureMaterialType";
|
|
|
|
|
Cesium.Material.LineTextureMaterialSource = `
|
2025-07-07 16:21:01 +08:00
|
|
|
|
uniform vec4 color;
|
|
|
|
|
uniform sampler2D image;
|
|
|
|
|
uniform float speed;
|
|
|
|
|
uniform float repeat;
|
2025-07-03 16:28:48 +08:00
|
|
|
|
czm_material czm_getMaterial(czm_materialInput materialInput)
|
|
|
|
|
{
|
2025-07-07 16:21:01 +08:00
|
|
|
|
czm_material material = czm_getDefaultMaterial(materialInput);
|
|
|
|
|
vec2 st = materialInput.st;
|
|
|
|
|
st.s *= repeat; // 关键:通过repeat控制纹理密度
|
2025-07-09 11:26:33 +08:00
|
|
|
|
// vec4 colorImage = texture2D(image, vec2(fract(st.s + speed*czm_frameNumber* 0.01), st.t));
|
|
|
|
|
vec4 colorImage = speed==0.0?texture2D(image, vec2(fract(st.s), st.t)):texture2D(image, vec2(fract(st.s + frameNumber / 1000.0 / speed * repeat ), st.t));
|
2025-07-07 16:21:01 +08:00
|
|
|
|
material.alpha = colorImage.a * color.a;
|
|
|
|
|
material.diffuse = color.rgb;
|
|
|
|
|
return material;
|
2025-07-03 16:28:48 +08:00
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
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: '',
|
2025-07-07 16:21:01 +08:00
|
|
|
|
repeat: 1.0,
|
|
|
|
|
speed: 1.0,
|
2025-07-09 11:26:33 +08:00
|
|
|
|
frameNumber: Cesium.getTimestamp(),
|
2025-07-03 16:28:48 +08:00
|
|
|
|
uTime: 1
|
|
|
|
|
},
|
|
|
|
|
source: Cesium.Material.LineTextureMaterialSource,
|
|
|
|
|
},
|
|
|
|
|
translucent: function (material) {
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { LineTexture }
|