Files
sdk4.0/src/Obj/Materail/FlowDashedLineFlowMaterialProperty.js

147 lines
4.5 KiB
JavaScript
Raw Normal View History

2025-07-03 16:28:48 +08:00
/*
* @Description: 流动线
*/
function FlowDashedLine() {
class FlowDashedLineFlowMaterialProperty {
constructor(options) {
this._definitionChanged = new Cesium.Event();
this._color = undefined;
this._speed = undefined;
this._uType = undefined;
2025-07-07 16:21:01 +08:00
this._space = undefined;
this._dashSize = undefined;
2025-07-03 16:28:48 +08:00
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.space = options.space || 0.01;//速度
this.dashSize = options.dashSize || 0.03;//速度
2025-07-03 16:28:48 +08:00
this.uType = options.uType === undefined ? 1 : options.uType;//类型0普通流动线 1虚化虚线
this.lineBackAlpha = options.lineBackAlpha || 0.05;
}
get isConstant() {
return false;
}
get definitionChanged() {
return this._definitionChanged;
}
getType(time) {
return Cesium.Material.FlowDashedLineMaterialType;
}
getValue(time, result) {
if (!Cesium.defined(result)) {
result = {};
}
result.color = Cesium.Property.getValueOrDefault(
this._color,
time,
Cesium.Color.RED,
result.color
);
result.speed = Cesium.Property.getValueOrDefault(
this._speed,
time,
10,
result.speed
);
2025-07-07 16:21:01 +08:00
result.space = Cesium.Property.getValueOrDefault(
this._space,
time,
10,
result.space
);
result.dashSize = Cesium.Property.getValueOrDefault(
this._dashSize,
time,
10,
result.dashSize
);
2025-07-03 16:28:48 +08:00
result.uType = Cesium.Property.getValueOrDefault(
this._uType,
time,
1,
result.uType
);
result.lineBackAlpha = this.lineBackAlpha;
result.frameNumber = Cesium.getTimestamp();
return result;
}
equals(other) {
return (
this === other ||
(other instanceof FlowDashedLineFlowMaterialProperty &&
Cesium.Property.equals(this._color, other._color) &&
Cesium.Property.equals(this._speed, other.speed) &&
Cesium.Property.equals(this._uType, other.uType) &&
Cesium.Property.equals(this.lineBackAlpha, other.lineBackAlpha))
);
}
}
Object.defineProperties(FlowDashedLineFlowMaterialProperty.prototype, {
color: Cesium.createPropertyDescriptor("color"),
speed: Cesium.createPropertyDescriptor("speed"),
2025-07-07 16:21:01 +08:00
space: Cesium.createPropertyDescriptor("space"),
dashSize: Cesium.createPropertyDescriptor("dashSize"),
2025-07-03 16:28:48 +08:00
uType: Cesium.createPropertyDescriptor("uType"),
transparency: Cesium.createPropertyDescriptor("lineBackAlpha"),
});
Cesium.FlowDashedLineFlowMaterialProperty = FlowDashedLineFlowMaterialProperty;
Cesium.Material.FlowDashedLineFlowMaterialProperty = "FlowDashedLineFlowMaterialProperty";
Cesium.Material.FlowDashedLineMaterialType = "FlowDashedLineMaterialType";
Cesium.Material.FlowDashedLineMaterialSource = `
uniform vec4 color;
uniform float speed;
// uniform int uType;
uniform float lineBackAlpha;
czm_material czm_getMaterial(czm_materialInput materialInput)
{
czm_material material = czm_getDefaultMaterial(materialInput);
vec2 st = materialInput.st;
// 计算流动虚线
float dashSize = 0.03;
2025-07-07 16:21:01 +08:00
// float gapSize = 0.01;
// float dashSize = dashSize;
float gapSize = space;
float progress = fract(speed * czm_frameNumber * 0.01); // 时间控制流动
2025-07-03 16:28:48 +08:00
float pattern = fract(st.x / (dashSize + gapSize) + progress);
float dash1 = step(0.1, pattern) - step(0.9, pattern);
2025-07-07 16:21:01 +08:00
float dash2 = smoothstep(0.0, 0.4, pattern) - smoothstep(0.6, 1.0, pattern);
2025-07-03 16:28:48 +08:00
float dash = (float(uType) != 1.0)?dash1:dash2;
material.alpha = dash;
material.diffuse = color.rgb;
return material;
}
`;
Cesium.Material._materialCache.addMaterial(
Cesium.Material.FlowDashedLineMaterialType,
{
fabric: {
type: Cesium.Material.FlowDashedLineMaterialType,
uniforms: {
color: new Cesium.Color(1.0, 1.0, 1.0, 1.0),
2025-07-07 16:21:01 +08:00
speed: 1,
space: 0.01,
dashSize: 0.03,
2025-07-03 16:28:48 +08:00
uType: 1,
lineBackAlpha: 0.05,
},
source: Cesium.Material.FlowDashedLineMaterialSource,
},
translucent: function (material) {
return true;
},
}
);
}
export { FlowDashedLine }