cesium水面特效代码
来个水面特效吧
代码部分
export default class WaterPolygon {
waterColor
alpha
positions
primitive
speed
choppy
height
freq
geoJson
constructor(options) {
this.waterColor = options.waterColor
this.alpha = options.alpha
this.speed = options.speed
this.positions = options.positions
this.choppy = options.choppy
this.height = options.height
this.freq = options.freq
this.geoJson = options.geoJson
this.primitive = null
if (options.geoJson) {
this.initJson()
} else {
this.initPoint()
}
}
initPoint() {
let appearance = this.initAppearance()
var rectangleInstance = new Cesium.GeometryInstance({
geometry: new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy(
this.positions
)
}),
id: 'rectangle',
attributes: {
color: new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)
}
})
let primitive = new Cesium.Primitive({
geometryInstances: [rectangleInstance],
appearance: appearance
})
this.primitive = primitive
}
initJson() {
let appearance = this.initAppearance()
var geometryInstances = [];
const entities = this.geoJson?.entities.values;
if (Array.isArray(entities)) {
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var hierarchy = entity.polygon.hierarchy.getValue();
var geometryInstance = new Cesium.GeometryInstance({
geometry:new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy(hierarchy.positions)
}),
attributes: {
color: new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)
}
});
geometryInstances.push(geometryInstance);
}
}
let primitive = new Cesium.Primitive({
geometryInstances: geometryInstances,
appearance: appearance
})
this.primitive = primitive
}
initAppearance() {
let color
if (this.waterColor) {
let t_Color = Cesium.Color.fromCssColorString(this.waterColor);
color = new Cesium.Cartesian3(t_Color.red, t_Color.green, t_Color.blue)
} else {
}
let appearance = new Cesium.MaterialAppearance({
material: new Cesium.Material({
...
});
function renderLoop(timestamp) {
appearance.material.uniforms.u_time = timestamp / 1000;
requestAnimationFrame(renderLoop);
}
renderLoop(10000);
return appearance
}
}
效果图片