125 lines
3.8 KiB
JavaScript
125 lines
3.8 KiB
JavaScript
|
/*
|
|||
|
* @Description: 流动线
|
|||
|
*/
|
|||
|
function FlowDashedLine() {
|
|||
|
class FlowDashedLineFlowMaterialProperty {
|
|||
|
constructor(options) {
|
|||
|
this._definitionChanged = new Cesium.Event();
|
|||
|
this._color = undefined;
|
|||
|
this._speed = undefined;
|
|||
|
this._uType = undefined;
|
|||
|
this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)");
|
|||
|
this.speed = options.speed || 0.25;//速度
|
|||
|
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
|
|||
|
);
|
|||
|
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"),
|
|||
|
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;
|
|||
|
float gapSize = 0.01;
|
|||
|
float progress = fract(czm_frameNumber * 0.01); // 时间控制流动
|
|||
|
float pattern = fract(st.x / (dashSize + gapSize) + progress);
|
|||
|
float dash1 = step(0.1, pattern) - step(0.9, pattern);
|
|||
|
float dash2 = smoothstep(0.1, 0.3, pattern) - smoothstep(0.7, 0.9, pattern);
|
|||
|
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),
|
|||
|
speed: 0.1,
|
|||
|
uType: 1,
|
|||
|
lineBackAlpha: 0.05,
|
|||
|
},
|
|||
|
source: Cesium.Material.FlowDashedLineMaterialSource,
|
|||
|
},
|
|||
|
translucent: function (material) {
|
|||
|
return true;
|
|||
|
},
|
|||
|
}
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
export { FlowDashedLine }
|