/* * @Descripttion: * @version: 1.0.0 * @Author: glc * @Date: 2022-04-29 16:13:29 * @LastEditors: Andy * @LastEditTime: 2022-09-16 20:55:05 */ //自定义水体primitive export function WaterPrimitive(options) { //debugger; this._positions = options.positions; this._height = options.height; this._extrudedHeight = options.extrudedHeight; this._primitive = null; this._waterImg = options.waterimg; Object.defineProperty(this, "extrudedHeight", { get() { return this._extrudedHeight; }, set(newVal) { if (Object.prototype.toString.call(newVal) !== "[object Number]") return; if (this._primitive) { this._primitive._state = 3; // 关键 this._primitive._appearance = undefined; // 关键 this._primitive.geometryInstances.geometry = this.getGeometry(); this._extrudedHeight = newVal; } }, }); this.init(); // 调用init函数 } WaterPrimitive.prototype.getGeometry = function () { return new Cesium.PolygonGeometry({ polygonHierarchy: new Cesium.PolygonHierarchy(this._positions), height: this._height, // 底部高度 extrudedHeight: this._extrudedHeight, // 水面高度 vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT, }); }; WaterPrimitive.prototype.init = function () { this._primitive = new Cesium.Primitive({ show: true, // 默认隐藏 geometryInstances: new Cesium.GeometryInstance({ geometry: new Cesium.PolygonGeometry({ polygonHierarchy: new Cesium.PolygonHierarchy(this._positions), extrudedHeight: this._extrudedHeight, //注释掉此属性可以只显示水面 //perPositionHeight: true, //注释掉此属性水面就贴地了 }), }), // 可以设置内置的水面shader appearance: new Cesium.EllipsoidSurfaceAppearance({ translucent: true, material: new Cesium.Material({ fabric: { type: "Water", uniforms: { baseWaterColor: new Cesium.Color(0.0, 0.0, 1.0, 0.5), blendColor: new Cesium.Color(0.0, 0.0, 1.0, 0.5), normalMap: this._waterImg, frequency: 1000.0, animationSpeed: 0.01, amplitude: 10.0, }, }, }), }), }); }; WaterPrimitive.prototype.update = function (frameState) { if (this._primitive) { let primitive = this._primitive; primitive.update(frameState); } };