114 lines
3.3 KiB
JavaScript
114 lines
3.3 KiB
JavaScript
|
/*
|
|||
|
* @Description: 流动线
|
|||
|
*/
|
|||
|
function FlowLine() {
|
|||
|
class FlowLineMaterialProperty {
|
|||
|
constructor(options) {
|
|||
|
this._definitionChanged = new Cesium.Event();
|
|||
|
this._color = undefined;
|
|||
|
this._duration = undefined;
|
|||
|
this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)");
|
|||
|
this.duration = options.duration || 10.0;
|
|||
|
this.lineBackAlpha = options.lineBackAlpha || 0.05;
|
|||
|
}
|
|||
|
|
|||
|
get isConstant() {
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
get definitionChanged() {
|
|||
|
return this._definitionChanged;
|
|||
|
}
|
|||
|
|
|||
|
getType(time) {
|
|||
|
return Cesium.Material.FlowLineMaterialType;
|
|||
|
}
|
|||
|
|
|||
|
getValue(time, result) {
|
|||
|
if (!Cesium.defined(result)) {
|
|||
|
result = {};
|
|||
|
}
|
|||
|
|
|||
|
result.color = Cesium.Property.getValueOrDefault(
|
|||
|
this._color,
|
|||
|
time,
|
|||
|
Cesium.Color.RED,
|
|||
|
result.color
|
|||
|
);
|
|||
|
result.duration = Cesium.Property.getValueOrDefault(
|
|||
|
this._duration,
|
|||
|
time,
|
|||
|
10,
|
|||
|
result.duration
|
|||
|
);
|
|||
|
result.lineBackAlpha = this.lineBackAlpha;
|
|||
|
result.frameNumber = Cesium.getTimestamp();
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
equals(other) {
|
|||
|
return (
|
|||
|
this === other ||
|
|||
|
(other instanceof FlowLineMaterialProperty &&
|
|||
|
Cesium.Property.equals(this._color, other._color) &&
|
|||
|
Cesium.Property.equals(this._duration, other.duration) &&
|
|||
|
Cesium.Property.equals(this.lineBackAlpha, other.lineBackAlpha))
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Object.defineProperties(FlowLineMaterialProperty.prototype, {
|
|||
|
color: Cesium.createPropertyDescriptor("color"),
|
|||
|
duration: Cesium.createPropertyDescriptor("duration"),
|
|||
|
transparency: Cesium.createPropertyDescriptor("lineBackAlpha"),
|
|||
|
});
|
|||
|
|
|||
|
Cesium.FlowLineMaterialProperty = FlowLineMaterialProperty;
|
|||
|
Cesium.Material.FlowLineMaterialProperty = "FlowLineMaterialProperty";
|
|||
|
Cesium.Material.FlowLineMaterialType = "FlowLineMaterialType";
|
|||
|
Cesium.Material.FlowLineMaterialSource = `
|
|||
|
uniform vec4 color;
|
|||
|
uniform float duration;
|
|||
|
uniform float lineBackAlpha;
|
|||
|
|
|||
|
czm_material czm_getMaterial(czm_materialInput materialInput)
|
|||
|
{
|
|||
|
//生成默认的基础材质
|
|||
|
czm_material material = czm_getDefaultMaterial(materialInput);
|
|||
|
//获取st(uv)
|
|||
|
vec2 st = materialInput.st;
|
|||
|
//获取当前帧数,10秒内变化0-1
|
|||
|
float time = fract(czm_frameNumber / (60.0*duration));
|
|||
|
//长度1/10
|
|||
|
time = time * (1.0 + 0.1);
|
|||
|
//平滑过渡函数
|
|||
|
float alpha = smoothstep(time-0.1,time,st.s) * step(-time,-st.s);
|
|||
|
//光带轨迹(不会完全透明)
|
|||
|
alpha += lineBackAlpha;
|
|||
|
material.alpha = alpha;
|
|||
|
material.diffuse = color.rgb;
|
|||
|
return material;
|
|||
|
}
|
|||
|
`;
|
|||
|
|
|||
|
Cesium.Material._materialCache.addMaterial(
|
|||
|
Cesium.Material.FlowLineMaterialType,
|
|||
|
{
|
|||
|
fabric: {
|
|||
|
type: Cesium.Material.FlowLineMaterialType,
|
|||
|
uniforms: {
|
|||
|
color: new Cesium.Color(1.0, 1.0, 1.0, 1.0),
|
|||
|
duration: 10.0,
|
|||
|
lineBackAlpha: 0.05,
|
|||
|
},
|
|||
|
source: Cesium.Material.FlowLineMaterialSource,
|
|||
|
},
|
|||
|
translucent: function (material) {
|
|||
|
return true;
|
|||
|
},
|
|||
|
}
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
export { FlowLine }
|