美文网首页
Cesium爆炸粒子

Cesium爆炸粒子

作者: zhuyx0304 | 来源:发表于2024-06-02 11:27 被阅读0次
//爆炸特效
export  class explotEffect{
  constructor(viewer) {
    this.viewer=viewer
    this.viewModel={
      emissionRate: 5,
      gravity: 0.0,//设置重力参数
      minimumParticleLife: 1,
      maximumParticleLife: 6,
      minimumSpeed: 1.0,//粒子发射的最小速度
      maximumSpeed: 4.0,//粒子发射的最大速度
      startScale: 0.0,
      endScale: 10.0,
      particleSize: 25.0,
    }
    this.emitterModelMatrix = new Cesium.Matrix4()
    this.translation = new Cesium.Cartesian3()
    this.rotation = new Cesium.Quaternion()
    this.hpr = new Cesium.HeadingPitchRoll()
    this.trs = new Cesium.TranslationRotationScale()
    this.scene = this.viewer.scene
    this.particleSystem=''
    this.entity = this.viewer.entities.add({
      //选择粒子放置的坐标
      position: Cesium.Cartesian3.fromDegrees(
        116.34485552299206,
        39.99754814959118
      ),
    });
    this.init();
  }

  init(){
    const _this=this
    this.viewer.clock.shouldAnimate = true;
    this.viewer.scene.globe.depthTestAgainstTerrain = false;
    this.viewer.trackedEntity = this.entity;
    var particleSystem = this.scene.primitives.add(
      new Cesium.ParticleSystem({
        image: require('../assets/explot.png'),//生成所需粒子的图片路径
        //粒子在生命周期开始时的颜色
        startColor: Cesium.Color.RED.withAlpha(0.7),
        //粒子在生命周期结束时的颜色
        endColor: Cesium.Color.YELLOW.withAlpha(0.3),
        //粒子在生命周期开始时初始比例
        startScale: _this.viewModel.startScale,
        //粒子在生命周期结束时比例
        endScale: _this.viewModel.endScale,
        //粒子发射的最小速度
        minimumParticleLife: _this.viewModel.minimumParticleLife,
        //粒子发射的最大速度
        maximumParticleLife: _this.viewModel.maximumParticleLife,
        //粒子质量的最小界限
        minimumSpeed: _this.viewModel.minimumSpeed,
        //粒子质量的最大界限
        maximumSpeed: _this.viewModel.maximumSpeed,
        //以像素为单位缩放粒子图像尺寸
        imageSize: new Cesium.Cartesian2(
          _this.viewModel.particleSize,
          _this.viewModel.particleSize
        ),
        //每秒发射的粒子数
        emissionRate: _this.viewModel.emissionRate,
        //粒子系统发射粒子的时间(秒)
        lifetime: 16.0,
        //设置粒子的大小是否以米或像素为单位
        sizeInMeters: true,
        //系统的粒子发射器
        emitter: new Cesium.CircleEmitter(5.0),//BoxEmitter 盒形发射器,ConeEmitter 锥形发射器,SphereEmitter 球形发射器,CircleEmitter圆形发射器

      })
    );
    this.particleSystem=particleSystem;
    this.preUpdateEvent()
  }

  //场景渲染事件
  preUpdateEvent() {
    let _this=this;
    this.viewer.scene.preUpdate.addEventListener(function (scene, time) {
      //发射器地理位置
      _this.particleSystem.modelMatrix = _this.computeModelMatrix(_this.entity, time);
      //发射器局部位置
      _this.particleSystem.emitterModelMatrix = _this.computeEmitterModelMatrix();
      // 将发射器旋转
      if (_this.viewModel.spin) {
        _this.viewModel.heading += 1.0;
        _this.viewModel.pitch += 1.0;
        _this.viewModel.roll += 1.0;
      }
    });
  }

  computeModelMatrix(entity, time) {
    return entity.computeModelMatrix(time, new Cesium.Matrix4());
  }

  computeEmitterModelMatrix() {
    this.hpr = Cesium.HeadingPitchRoll.fromDegrees(0.0, 0.0, 0.0, this.hpr);
    this.trs.translation = Cesium.Cartesian3.fromElements(
      -4.0,
      0.0,
      1.4,
      this.translation
    );
    this.trs.rotation = Cesium.Quaternion.fromHeadingPitchRoll(this.hpr, this.rotation);

    return Cesium.Matrix4.fromTranslationRotationScale(
      this.trs,
      this.emitterModelMatrix
    );
  }


  removeEvent(){
    this.viewer.scene.preUpdate.removeEventListener(this.preUpdateEvent, this);
    this.emitterModelMatrix = undefined;
    this.translation = undefined;
    this.rotation = undefined;
    this.hpr = undefined;
    this.trs = undefined;
  }

  //移除粒子特效
  remove() {
    ()=>{return this.removeEvent()}; //清除事件
    this.viewer.scene.primitives.remove(this.particleSystem); //删除粒子对象
    this.viewer.entities.remove(this.entity); //删除entity
  }

}

相关文章

  • Cesium 粒子系统学习

    Cesium中粒子系统被用来模拟飞机爆炸、雨雪天气等场景。根据官网对其定义 ,粒子系统是由小图像组成的集合,当他们...

  • 粒子效果-烟花

    //分为3种粒子,子弹粒子,爆炸粒子,散开粒子 CAEmitterLayer *fireworksEmitter ...

  • 粒子系统发射器

    粒子发射器是用来限定粒子活动范围的,并给定随机产生的粒子一个初始位移和速度。cesium默认提供了4种粒子发射器。...

  • cesium粒子着火特效

    import "cesium/Widgets/widgets.cs...

  • cesium粒子系统

    1,粒子系统的作用。cesium粒子系统可以用来模拟汽车尾气,烟花,火焰,雨雪,落叶等。例如下面 2,我们看下生成...

  • Cesium绘制轨迹线与轨迹点

    介绍使用primitives创建线条轨迹以及轨迹点以及entities大概介绍 Cesium上建立风场动态粒子效果...

  • Cesium粒子系统--参数介绍

    最近因为工作原因,对于Cesium的粒子系统进行了研究(除了雨雪效果)。发现新手想要用好粒子效果还是有一定的难度的...

  • Cesium粒子系统--Particle System Fire

    Cesium为我们提供了非常棒的烟花的粒子特效,我们可以在沙盒中的Particle System FireWork...

  • Cesium 粒子系统 ParticleSystem

    雪花示例

  • 一个酷炫的 android 粒子动画库

    一、灵感 做这个粒子动画库的灵感来自于 MIUI 卸载应用时的动画: 这个爆炸的粒子效果看起来很酷炫,而且粒子颜色...

网友评论

      本文标题:Cesium爆炸粒子

      本文链接:https://www.haomeiwen.com/subject/lijmfjtx.html