Cesium 水波材质教程
水波材质 ·Water Material· ▶ 在线运行案例案例合集三维可视化功能案例threehub.cn开源仓库github地址https://github.com/z2586300277/three-cesium-examples400个案例代码网盘链接你将学到什么水面反射/镜像材质效果说明本案例演示水波材质效果基于 WebGL 实现「水波材质」可视化效果附完整可运行源码核心用到 水面反射/镜像材质。建议先打开文首在线案例查看动态画面再对照下方源码逐步理解。核心概念Viewer聚合 Scene、Camera、Clock 与渲染循环是 Cesium 应用入口。阅读下方完整源码时建议从init/load/animate三条主线入手再深入 shader 与工具函数。实现步骤创建 Viewer配置地形/影像若案例需要并设置初始相机在requestAnimationFrame循环中更新状态并 renderCesium 为viewer.render或自动渲染代码要点import * as Cesium from cesiumconst box document.getElementById(box)const viewer new Cesium.Viewer(box, {animation: false,//是否创建动画小器件左下角仪表baseLayerPicker: false,//是否显示图层选择器右上角图层选择按钮baseLayer: Cesium.ImageryLayer.fromProviderAsync(Cesium.ArcGisMapServerImageryProvider.fromUrl(https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer)),fullscreenButton: false,//是否显示全屏按钮右下角全屏选择按钮timeline: false,//是否显示时间轴infoBox: false,//是否显示信息框})// 添加水波纹效果 const positions [-109.080842, 45.002073, -105.91517, 45.002073 , -104.058488, 46.996596]; // 示例坐标数组 const index 1; // 示例索引const primitives new Cesium.Primitive({ geometryInstances: new Cesium.GeometryInstance({ id: waterRipple index, geometry: new Cesium.PolygonGeometry({ polygonHierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(positions)), height: 0, }), }), appearance: new Cesium.EllipsoidSurfaceAppearance({ material: new Cesium.Material({ fabric: { type: Water, uniforms: { baseWaterColor: Cesium.Color.fromCssColorString(rgba(64,157,253,0.5)), blendColor: Cesium.Color.fromCssColorString(rgba(64,157,253,0.3)), normalMap: FILE_HOST images/drei/normal.jpg, frequency: 500.0, animationSpeed: 0.1, amplitude: 20, specularIntensity: 5 } } }), }), })viewer.scene.primitives.add(primitives);// 定位到水波纹位置 viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(-106.0, 44.5, 120000), // 提升高度可以看清水面效果 orientation: { heading: Cesium.Math.toRadians(0), pitch: Cesium.Math.toRadians(-45), // 斜视角度更容易看出波纹 roll: 0 }, duration: 1 });完整源码GitHub小结本文提供水波材质完整 Cesium.js 源码与在线 Demo建议先运行案例再改 uniform/参数做二次实验更多 Cesium.js 实战案例见 three-cesium-examples 合集 与 GitHub 开源仓库