飞线,光照
This commit is contained in:
		
							
								
								
									
										124
									
								
								src/Obj/Materail/FlowDashedLineFlowMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								src/Obj/Materail/FlowDashedLineFlowMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,124 @@
 | 
			
		||||
/*
 | 
			
		||||
 * @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 }
 | 
			
		||||
							
								
								
									
										113
									
								
								src/Obj/Materail/FlowLineMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								src/Obj/Materail/FlowLineMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,113 @@
 | 
			
		||||
/*
 | 
			
		||||
 * @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 }
 | 
			
		||||
							
								
								
									
										110
									
								
								src/Obj/Materail/LineTextureMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								src/Obj/Materail/LineTextureMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,110 @@
 | 
			
		||||
/*
 | 
			
		||||
 * @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 }
 | 
			
		||||
							
								
								
									
										113
									
								
								src/Obj/Materail/PolylineFlowMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								src/Obj/Materail/PolylineFlowMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,113 @@
 | 
			
		||||
/*
 | 
			
		||||
 * @Description: 流动线
 | 
			
		||||
 */
 | 
			
		||||
function PolylineFlow() {
 | 
			
		||||
  class PolylineFlowMaterialProperty {
 | 
			
		||||
    constructor(options) {
 | 
			
		||||
      this._definitionChanged = new Cesium.Event();
 | 
			
		||||
      this._color = undefined;
 | 
			
		||||
      this._speed = undefined;
 | 
			
		||||
      this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)");
 | 
			
		||||
      this.speed = options.speed || 0.25;//速度
 | 
			
		||||
      this.lineBackAlpha = options.lineBackAlpha || 0.05;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    get isConstant() {
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    get definitionChanged() {
 | 
			
		||||
      return this._definitionChanged;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getType(time) {
 | 
			
		||||
      return Cesium.Material.PolylineFlowMaterialType;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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.lineBackAlpha = this.lineBackAlpha;
 | 
			
		||||
      result.frameNumber = Cesium.getTimestamp();
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    equals(other) {
 | 
			
		||||
      return (
 | 
			
		||||
        this === other ||
 | 
			
		||||
        (other instanceof PolylineFlowMaterialProperty &&
 | 
			
		||||
          Cesium.Property.equals(this._color, other._color) &&
 | 
			
		||||
          Cesium.Property.equals(this._speed, other.speed) &&
 | 
			
		||||
          Cesium.Property.equals(this.lineBackAlpha, other.lineBackAlpha))
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Object.defineProperties(PolylineFlowMaterialProperty.prototype, {
 | 
			
		||||
    color: Cesium.createPropertyDescriptor("color"),
 | 
			
		||||
    speed: Cesium.createPropertyDescriptor("speed"),
 | 
			
		||||
    transparency: Cesium.createPropertyDescriptor("lineBackAlpha"),
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  Cesium.PolylineFlowMaterialProperty = PolylineFlowMaterialProperty;
 | 
			
		||||
  Cesium.Material.PolylineFlowMaterialProperty = "PolylineFlowMaterialProperty";
 | 
			
		||||
  Cesium.Material.PolylineFlowMaterialType = "PolylineFlowMaterialType";
 | 
			
		||||
  Cesium.Material.PolylineFlowMaterialSource = `
 | 
			
		||||
      uniform vec4 color;
 | 
			
		||||
      uniform float speed;
 | 
			
		||||
      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 * speed / 60.0);
 | 
			
		||||
            //长度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.PolylineFlowMaterialType,
 | 
			
		||||
    {
 | 
			
		||||
      fabric: {
 | 
			
		||||
        type: Cesium.Material.PolylineFlowMaterialType,
 | 
			
		||||
        uniforms: {
 | 
			
		||||
          color: new Cesium.Color(1.0, 1.0, 1.0, 1.0),
 | 
			
		||||
          speed: 0.1,
 | 
			
		||||
          lineBackAlpha: 0.05,
 | 
			
		||||
        },
 | 
			
		||||
        source: Cesium.Material.PolylineFlowMaterialSource,
 | 
			
		||||
      },
 | 
			
		||||
      translucent: function (material) {
 | 
			
		||||
        return true;
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { PolylineFlow }
 | 
			
		||||
							
								
								
									
										134
									
								
								src/Obj/Materail/PolylineFlowMultMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								src/Obj/Materail/PolylineFlowMultMaterialProperty.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,134 @@
 | 
			
		||||
/*
 | 
			
		||||
 * @Description: 流动线
 | 
			
		||||
 */
 | 
			
		||||
function PolylineFlowMult() {
 | 
			
		||||
  class PolylineFlowMultMaterialProperty {
 | 
			
		||||
    constructor(options) {
 | 
			
		||||
      this._definitionChanged = new Cesium.Event();
 | 
			
		||||
      this._color = undefined;
 | 
			
		||||
      this._speed = undefined;
 | 
			
		||||
      this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)");
 | 
			
		||||
      this.speed = options.speed || 0.1;//速度
 | 
			
		||||
      this.lineBackAlpha = options.lineBackAlpha || 0.05;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    get isConstant() {
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    get definitionChanged() {
 | 
			
		||||
      return this._definitionChanged;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getType(time) {
 | 
			
		||||
      return Cesium.Material.PolylineFlowMultMaterialType;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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.lineBackAlpha = this.lineBackAlpha;
 | 
			
		||||
      result.frameNumber = Cesium.getTimestamp();
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    equals(other) {
 | 
			
		||||
      return (
 | 
			
		||||
        this === other ||
 | 
			
		||||
        (other instanceof PolylineFlowMultMaterialProperty &&
 | 
			
		||||
          Cesium.Property.equals(this._color, other._color) &&
 | 
			
		||||
          Cesium.Property.equals(this._speed, other.speed) &&
 | 
			
		||||
          Cesium.Property.equals(this.lineBackAlpha, other.lineBackAlpha))
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Object.defineProperties(PolylineFlowMultMaterialProperty.prototype, {
 | 
			
		||||
    color: Cesium.createPropertyDescriptor("color"),
 | 
			
		||||
    speed: Cesium.createPropertyDescriptor("speed"),
 | 
			
		||||
    transparency: Cesium.createPropertyDescriptor("lineBackAlpha"),
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  Cesium.PolylineFlowMultMaterialProperty = PolylineFlowMultMaterialProperty;
 | 
			
		||||
  Cesium.Material.PolylineFlowMultMaterialProperty = "PolylineFlowMultMaterialProperty";
 | 
			
		||||
  Cesium.Material.PolylineFlowMultMaterialType = "PolylineFlowMultMaterialType";
 | 
			
		||||
  Cesium.Material.PolylineFlowMaterialSource = `
 | 
			
		||||
      uniform vec4 color;
 | 
			
		||||
      uniform float speed;
 | 
			
		||||
      uniform float lineBackAlpha;
 | 
			
		||||
 | 
			
		||||
      czm_material czm_getMaterial(czm_materialInput materialInput)
 | 
			
		||||
        {
 | 
			
		||||
            czm_material material = czm_getDefaultMaterial(materialInput);
 | 
			
		||||
            vec2 st = materialInput.st;
 | 
			
		||||
 | 
			
		||||
            // 基础时间轴(控制主光带)
 | 
			
		||||
            float baseTime = fract(czm_frameNumber * speed / 60.0) * 1.1;
 | 
			
		||||
 | 
			
		||||
            // 高频时间轴(控制高光点)
 | 
			
		||||
            float highlightTime = fract(czm_frameNumber * speed * 3.0 / 60.0);
 | 
			
		||||
            float highlightSpacing = 0.3; // 高光点间隔
 | 
			
		||||
 | 
			
		||||
            // 主光带透明度计算
 | 
			
		||||
            float mainAlpha = smoothstep(baseTime-0.1, baseTime, st.s) * step(-baseTime, -st.s);
 | 
			
		||||
 | 
			
		||||
            // 多高光点计算(3个周期性光斑)
 | 
			
		||||
            float highlight1 = smoothstep(highlightTime-0.05, highlightTime, st.s) *
 | 
			
		||||
                              step(-highlightTime, -st.s) *
 | 
			
		||||
                              (1.0 - smoothstep(0.0, highlightSpacing, abs(st.s - highlightTime)));
 | 
			
		||||
 | 
			
		||||
            float highlight2 = smoothstep(highlightTime+highlightSpacing-0.05,
 | 
			
		||||
                                        highlightTime+highlightSpacing, st.s) *
 | 
			
		||||
                              step(-(highlightTime+highlightSpacing), -st.s) *
 | 
			
		||||
                              (1.0 - smoothstep(0.0, highlightSpacing, abs(st.s - (highlightTime+highlightSpacing))));
 | 
			
		||||
 | 
			
		||||
            float highlight3 = smoothstep(highlightTime+2.0*highlightSpacing-0.05,
 | 
			
		||||
                                        highlightTime+2.0*highlightSpacing, st.s) *
 | 
			
		||||
                              step(-(highlightTime+2.0*highlightSpacing), -st.s) *
 | 
			
		||||
                              (1.0 - smoothstep(0.0, highlightSpacing, abs(st.s - (highlightTime+2.0*highlightSpacing))));
 | 
			
		||||
 | 
			
		||||
            // 合并效果
 | 
			
		||||
            // material.alpha = mainAlpha * 0.7 +
 | 
			
		||||
            //                 (highlight1 + highlight2 + highlight3) * 0.5 +
 | 
			
		||||
            //                 lineBackAlpha;
 | 
			
		||||
            material.alpha = (highlight1 + highlight2 + highlight3) * 0.5 +
 | 
			
		||||
                            lineBackAlpha;
 | 
			
		||||
            material.diffuse = color.rgb; // 高光区变亮
 | 
			
		||||
            return material;
 | 
			
		||||
        }
 | 
			
		||||
       `;
 | 
			
		||||
 | 
			
		||||
  Cesium.Material._materialCache.addMaterial(
 | 
			
		||||
    Cesium.Material.PolylineFlowMultMaterialType,
 | 
			
		||||
    {
 | 
			
		||||
      fabric: {
 | 
			
		||||
        type: Cesium.Material.PolylineFlowMultMaterialType,
 | 
			
		||||
        uniforms: {
 | 
			
		||||
          color: new Cesium.Color(1.0, 1.0, 1.0, 1.0),
 | 
			
		||||
          speed: 0.1,
 | 
			
		||||
          lineBackAlpha: 0.05,
 | 
			
		||||
        },
 | 
			
		||||
        source: Cesium.Material.PolylineFlowMaterialSource,
 | 
			
		||||
      },
 | 
			
		||||
      translucent: function (material) {
 | 
			
		||||
        return true;
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { PolylineFlowMult }
 | 
			
		||||
@ -2,6 +2,11 @@ import { StreamWall1, StreamWall2 } from './WallMaterialProperty'
 | 
			
		||||
import { RadarScan } from './RadarScanMaterialProperty'
 | 
			
		||||
import { CustomColorMaterialSource } from './CustomColorMaterialSource'
 | 
			
		||||
import { CustomImageMaterialSource } from './CustomImageMaterialSource'
 | 
			
		||||
import { FlowLine } from './FlowLineMaterialProperty'
 | 
			
		||||
import { PolylineFlow } from './PolylineFlowMaterialProperty'
 | 
			
		||||
import { PolylineFlowMult } from './PolylineFlowMultMaterialProperty'
 | 
			
		||||
import { FlowDashedLine } from './FlowDashedLineFlowMaterialProperty'
 | 
			
		||||
import { LineTexture } from './LineTextureMaterialProperty'
 | 
			
		||||
 | 
			
		||||
function init_material() {
 | 
			
		||||
  StreamWall1()
 | 
			
		||||
@ -9,6 +14,11 @@ function init_material() {
 | 
			
		||||
  RadarScan()
 | 
			
		||||
  CustomColorMaterialSource()
 | 
			
		||||
  CustomImageMaterialSource()
 | 
			
		||||
  FlowLine()
 | 
			
		||||
  PolylineFlow()
 | 
			
		||||
  PolylineFlowMult()
 | 
			
		||||
  FlowDashedLine()
 | 
			
		||||
  LineTexture()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { init_material }
 | 
			
		||||
export { init_material }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user