ceisum实现绘制线段实现动画效果

需求:

在cesium中,要实现类似于风场动画的效果.由于数据的问题,以及要避开三维建筑等因素,我们退而求其次,根据绘制区域,由数据分析出风向流动发方向,我们负责绘制,
1.绘制两点.

    geometryInstances: new GeometryInstance({
        geometry: new PolylineGeometry({
          positions: positions,
          width: 2,
          vertexFormat: PolylineMaterialAppearance.VERTEX_FORMAT, //可以不设置,一般会根据 appearance的类型自动默认对应的类型
        }),
        attributes: {
          
        },
      }),

2 appearance

 appearance: new PolylineMaterialAppearance({
        material: Material.fromType(Material.FadeType, {
          repeat: false,
          fadeInColor: Color.fromCssColorString('#00ffff').withAlpha(0.85),
          fadeOutColor: Color.fromCssColorString('#00ffff').withAlpha(0),
          time: new Cartesian2(100.0, 1.0),
          maximumDistance: 0.75 / 2.5,
          fadeDirection: {
            x: true,
            y: false,
          },
        }),
      }),

3.加载
cesiumview.scene.primitives.add(primitive);
4.设置动画

    let max = 30;
    let min = 20;
    let zhengshu = Math.floor(Math.random() * (max - min + 1) + min);
    let step = zhengshu / 1000;
    console.log('step', step);
    //0.01-0.5
    var timex = 0;
    function render() {
      timex += step;
      if (timex >= 1) {
        timex = 0; // 控制在0.0到1.0之间
      }

      primitive.appearance.material.uniforms.time.x = timex - 0.003;
      requestAnimationFrame(render);
    }
    requestAnimationFrame(render);

总结:整体代码

  var primitive = new Primitive({
      geometryInstances: new GeometryInstance({
        geometry: new PolylineGeometry({
          positions: positions,
          width: 2,
          vertexFormat: PolylineMaterialAppearance.VERTEX_FORMAT, //可以不设置,一般会根据 appearance的类型自动默认对应的类型
        }),
        attributes: {
          
        },
      }),
      appearance: new PolylineMaterialAppearance({
        material: Material.fromType(Material.FadeType, {
          repeat: false,
          fadeInColor: Color.fromCssColorString('#00ffff').withAlpha(0.85),
          fadeOutColor: Color.fromCssColorString('#00ffff').withAlpha(0),
          time: new Cartesian2(100.0, 1.0),
          maximumDistance: 0.75 / 2.5,
          fadeDirection: {
            x: true,
            y: false,
          },
        }),
      }),
    });
    cesiumview.scene.primitives.add(primitive);
    let max = 30;
    let min = 20;
    let zhengshu = Math.floor(Math.random() * (max - min + 1) + min);
    let step = zhengshu / 1000;
    console.log('step', step);
    //0.01-0.5
    var timex = 0;
    function render() {
      timex += step;
      if (timex >= 1) {
        timex = 0; // 控制在0.0到1.0之间
      }

      primitive.appearance.material.uniforms.time.x = timex - 0.003;
      requestAnimationFrame(render);
    }
    requestAnimationFrame(render);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值