cesium实现水闸放水以及水面升降效果

Mars3d水闸放水水面升降效果

用mars3d实现了开闸 水闸放水,水面升降以及控制流速等效果

效果图

QQ录屏20231130132647

QQ录屏20231129144059

水闸水柱

// 添加水柱
function addWaterGate() {
  // 阀门位置
  const posArr = [
    [121.479861, 29.791326, 18],
    [121.479826, 29.791326, 18],
    [121.479789, 29.791336, 18]
  ]

  for (let i = 0, len = posArr.length; i < len; i++) {
    const pos = posArr[i]
    const particleSystem = new mars3d.graphic.ParticleSystem({
      id: i + 1,
      position: pos, // 位置
      style: {
        image: "./img/particle/waterdrink.png", // "./img/particle/waterfall.png",
        particleSize: 36, // 粒子大小(单位:像素)
        emissionRate: 100.0, // 发射速率 (单位:次/秒)
        heading: 105, // 方向角
        pitch: 90, // 俯仰角
        gravity: -11, // 重力因子,会修改速度矢量以改变方向或速度(基于物理的效果)
        transZ: 5, // 离地高度(单位:米)
        maxHeight: 300, // 超出该高度后不显示粒子效果

        startColor: Cesium.Color.LIGHTYELLOW.withAlpha(0.3), // 开始颜色
        endColor: Cesium.Color.LIGHTYELLOW.withAlpha(0.0), // 结束颜色
        minimumParticleLife: 1, // 最小寿命时间(秒)
        maximumParticleLife: 2, // 最大寿命时间(秒)
        minimumSpeed: 10.0, // 最小速度(米/秒)
        maximumSpeed: 14.0 // 最大速度(米/秒)
      }
    })
    map.graphicLayer.addGraphic(particleSystem)
  }
}

 阀门控制

 //闸门加载
  zmGraphic = new mars3d.graphic.ModelEntity({
    name: "闸门",
    position: [121.479813, 29.791278, 16],
    style: {
      url: "//data.mars3d.cn/gltf/mars/zhamen.glb",
      heading: 105
    }
  })
  map.graphicLayer.addGraphic(zmGraphic)


// 全部闸门的控制
function bindShowAll(val) {
  map.graphicLayer.eachGraphic((graphic) => {
    graphic.show = val
    if (graphic.name == "闸门") {
      graphic.show = !val
    }
  })
}
/**
 * 开启阀门
 *
 * @export
 * @param {number} height  阀门高度  单位: m
 * @param {number} time //时间 单位:s
 * @returns {void} 无
 */
export function openZm(height, time) {
  addWaterGate()
  let thisHeight = 0 // 当前高度
  const endHeight = height // 结束高度

  const step = time / 0.1 // 步长
  const stepHeight = (endHeight - thisHeight) / step // 每次阀门、水面上移高度

  // 再次点击"开启"时从当前位置开启
  updateHeight(thisHeight)

  clearInterval(timeInv)
  timeInv = setInterval(() => {
    thisHeight += stepHeight // 上移后的当前高度,相当于时实更新

    if (thisHeight >= endHeight) {
      thisHeight = endHeight
      clearInterval(timeInv) // 清除定时器,当前阀门的高度值等于结束时阀门的高度值时,停止上移,关闭定时器
    }
    updateHeight(thisHeight)
  }, 100)
}

/**
 * 关闭阀门
 *
 * @export
 * @param {number} height  阀门高度 单位: m
 * @param {number} time //时间 单位:s
 * @returns {void} 无
 */
export function closeZm(height, time) {
  let thisHeight = height
  const endHeight = 0

  const step = time / 0.1
  const stepHeight = (endHeight - thisHeight) / step

  updateHeight(thisHeight)

  clearInterval(timeInv)
  timeInv = setInterval(() => {
    thisHeight += stepHeight

    if (thisHeight <= endHeight) {
      thisHeight = endHeight
      clearInterval(timeInv)
    }
    updateHeight(thisHeight)
  }, 100)
  bindShowAll(false)
}

 水面升降

waterLayer = new mars3d.layer.GeoJsonLayer({
    name: "排污河流(面状)",
    url: "//data.mars3d.cn/file/geojson/hedao-wai.json",
    symbol: {
      type: "waterC",
      styleOptions: {
        height: 16, // 水面高度
        offsetHeight: 0,
        normalMap: "img/textures/waterNormals.jpg", // 水正常扰动的法线图
        frequency: 8000.0, // 控制波数的数字。
        animationSpeed: 0.02, // 控制水的动画速度的数字。
        amplitude: 2.0, // 控制水波振幅的数字。
        specularIntensity: 0.4, // 控制镜面反射强度的数字。
        baseWaterColor: "#998c62", // rgba颜色对象基础颜色的水。#00ffff,#00baff,#006ab4,#877658,#ac8113
        blendColor: "#877658", // 从水中混合到非水域时使用的rgba颜色对象。
        opacity: 0.6 // 透明度
      }
    }
  })
  map.addLayer(waterLayer)



// 高度更新
function updateHeight(height) {
  zmGraphic.height = 16 + height // 阀门高度

  waterLayer.eachGraphic((graphic) => {
    graphic.offsetHeight = height// 水域高度变化
  })
}

水面流速控制

//添加水面效果
function addDemoGraphic1() {
  debugger
  dynamicRiver = new mars3d.graphic.DynamicRiver({
    positions: [
      [121.487538, 29.803229, 16],
      [121.485562, 29.801082, 16],
      [121.484083, 29.79374, 16],
      [121.483607, 29.792796, 16],
      [121.482538, 29.792148, 16],
      [121.4811, 29.791998, 16],
      [121.479441, 29.792376, 16],
      [121.475508, 29.795565, 16],
      [121.474042, 29.795589, 16],
      [121.473272, 29.795118, 16],
      [121.473111, 29.790095, 16],
      [121.471644, 29.789939, 16]
    ],
    style: {
      image: "img/textures/poly-soil.jpg", // "img/textures/poly-rivers.png",
      width: 150,
      height: 0,
      speed: 2
    }
  })
  map.graphicLayer.addGraphic(dynamicRiver)
}

/**
 * 改变流速
 *
 * @export
 * @param {number} speed
 * @returns {void} 无
 */
export function changeSpeed(speed) {
  // debugger
  // const frequency = 8000 / speed
  speed = speed === 0 ? 1 : speed
  // const animationSpeed = 0.04 * speed
  // const amplitude = 2 * speed
  // waterLayer.eachGraphic((graphic) => {
  //   graphic.setStyle({
  //     animationSpeed: animationSpeed, // 控制水的动画速度的数字。
  //     amplitude: amplitude // 控制水波振幅的数字。
  //   })
  // })

  const riverSpeed = 2 * speed
  dynamicRiver.setStyle({
    speed: riverSpeed
  })
}

cesium的写的效果太一般了,草草放个乱码吧cesium实现

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
要使用Cesium实现水闸放水效果,可以使用Cesium的ParticleSystem对象和WaterMaterial材质,结合场景中的水面模型来实现。以下是示例代码: ```javascript // 加载水面模型 var waterSurface = viewer.scene.primitives.add(Cesium.Model.fromGltf({ url: 'path/to/water-surface.gltf', modelMatrix: Cesium.Matrix4.multiply( Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(lon, lat)), Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0, 0, 0)), new Cesium.Matrix4() ), scale: 100 })); // 定义水闸放水效果的粒子系统 var particleSystem = new Cesium.ParticleSystem({ image: 'path/to/particle.png', startColor: new Cesium.Color(1.0, 1.0, 1.0, 1.0), endColor: new Cesium.Color(1.0, 1.0, 1.0, 0.0), particleLife: 5.0, speed: 20.0, emissionRate: 1000.0, startScale: 1.0, endScale: 0.0, imageSize: new Cesium.Cartesian2(10, 10), emitter: new Cesium.CircleEmitter(0.2), emitterModelMatrix: Cesium.Matrix4.IDENTITY }); // 添加水闸放水效果的材质 waterSurface.readyPromise.then(function(model) { var node = model.getNode('WaterSurface'); if (Cesium.defined(node)) { var waterMaterial = new Cesium.WaterMaterial({ baseWaterColor: new Cesium.Color.fromCssColorString('#003366'), normalMap: 'path/to/normal-map.png', frequency: 100.0, animationSpeed: 0.01, amplitude: 0.1, specularIntensity: 0.5 }); node.material = waterMaterial; } }); // 将水闸放水效果的粒子系统添加到场景中 viewer.scene.primitives.add(particleSystem); // 绑定水闸放水效果的粒子系统到水面模型上 particleSystem.emitter = new Cesium.MeshEmitter(waterSurface, 'WaterSurface'); particleSystem.emitter.particleRadius = 0.05; particleSystem.emitter.minEmitTime = 0.1; particleSystem.emitter.maxEmitTime = 0.2; particleSystem.emitter.minInitialSpeed = -2.0; particleSystem.emitter.maxInitialSpeed = -5.0; particleSystem.emitter.minLife = 1.0; particleSystem.emitter.maxLife = 2.0; particleSystem.emitter.emitRate = 50.0; ``` 在上面的示例代码中,我们首先加载水面模型,并定义了一个粒子系统,用于模拟水闸放水效果。接着,我们添加了WaterMaterial材质,将其绑定到水面模型上,并设置了一些参数,用于调整材质的效果。最后,我们将粒子系统添加到场景中,并通过MeshEmitter将其绑定到水面模型上,设置了一些参数,用于调整粒子系统的效果。 需要注意的是,上述代码中的水面模型、粒子图片、法线贴图等资源需要根据实际情况进行替换或调整,并且水面模型需要包含一个名为“WaterSurface”的节点,用于绑定WaterMaterial材质。另外,上述代码只是一个简单示例,实际应用中还需要考虑一些细节问题,如水闸放水的位置、方向、流速等参数的调整。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

姗姗的鱼尾喵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值