Cesium 展示——动态洪水淹没效果

103 篇文章 55 订阅 ¥59.90 ¥99.00
  • 11
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要实现大量水面淹没效果,您可以使用Cesium中的ClippingPlaneCollection和Primitive组合来实现。以下是一个示例代码: ```javascript // 创建PrimitiveCollection和ClippingPlaneCollection对象 var primitives = new Cesium.PrimitiveCollection(); var clippingPlanes = new Cesium.ClippingPlaneCollection({ planes : [] }); // 将PrimitiveCollection添加到场景中 viewer.scene.primitives.add(primitives); // 加载GeoJSON数据 Cesium.GeoJsonDataSource.load('./data.geojson').then(function(dataSource) { var entities = dataSource.entities.values; var height = 0.0; // 循环遍历每个实体并设置面样式 for (var i = 0; i < entities.length; i++) { var entity = entities[i]; // 如果是水面实体,将其添加到ClippingPlaneCollection中 if (entity.properties.type == "water") { var plane = new Cesium.Plane(Cesium.Cartesian3.UNIT_Z, -entity.properties.height); clippingPlanes.add(plane); height = height + entity.properties.height; } // 如果是陆地实体,将其添加到PrimitiveCollection中 else { var primitive = new Cesium.Primitive({ geometryInstances : new Cesium.GeometryInstance({ geometry : new Cesium.PolygonGeometry({ polygonHierarchy : new Cesium.PolygonHierarchy(entity.polygon), height : entity.properties.height, extrudedHeight : entity.properties.extrudedHeight, vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL, stRotation: entity.properties.stRotation }), attributes : { color : Cesium.ColorGeometryInstanceAttribute.fromColor(entity.properties.color) } }), appearance : new Cesium.PerInstanceColorAppearance({ closed : true }) }); primitives.add(primitive); } } // 设置ClippingPlaneCollection viewer.scene.globe.clippingPlanes = clippingPlanes; viewer.scene.globe.depthTestAgainstTerrain = true; viewer.camera.setView({ destination : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883, height + 1000), orientation : { heading : 0.0, pitch : Cesium.Math.toRadians(-90.0), roll : 0.0 } }); }); ``` 其中,我们首先创建一个PrimitiveCollection和ClippingPlaneCollection对象来分别存储陆地和水面实体。然后,我们遍历每个实体,如果是水面实体,则将其高度作为一个ClippingPlane添加到ClippingPlaneCollection中。如果是陆地实体,则将其作为一个Primitive添加到PrimitiveCollection中。最后,我们将ClippingPlaneCollection设置到场景的globe中,这样就可以实现水面淹没效果了。 需要注意的是,由于大量水面的存在,可能会导致渲染性能下降。因此,建议使用WebGL调试工具来优化代码和性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

博客zhu虎康

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

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

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

打赏作者

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

抵扣说明:

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

余额充值