水面流动效果


import movingRiver from "@/assets/img/waterNormals.jpg";
export class WaterPrimitive {
    constructor(options) {
        this._positions = options.positions;
        this._height =   options.height;
        this._extrudedHeight = options.extrudedHeight;
        this._targetHeight = Cesium.defaultValue(options.targetHeight, options.extrudedHeight);
        this._grow = Cesium.defaultValue(options.grow, false);
        this._upGrow = Cesium.defaultValue(options.upGrow, true);
        this.init();
    }
}
Object.defineProperties(WaterPrimitive.prototype, {
    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;
            }
        }
    }
});
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.update = function (frameState) {
    if (this._primitive) {
        let primitive = this._primitive;
        primitive.update(frameState);
    }
};

WaterPrimitive.prototype.destroy = function () {
    let primitive = this._primitive;
    primitive.destroy()
}

WaterPrimitive.prototype.init = function () {
    let geometry = this.getGeometry();
    if (!geometry) return;
    this._primitive = new Cesium.Primitive({
        releaseGeometryInstances: false,
        geometryInstances: new Cesium.GeometryInstance({
            geometry
        }),
        asynchronous: false,
        appearance: new Cesium.EllipsoidSurfaceAppearance({
            material: new Cesium.Material({
                fabric: {
                    type: "Water",
                    uniforms: {
                        baseWaterColor: new Cesium.Color(0 / 255.0, 255 / 255.0, 237 / 255.0, 0.1),
                        normalMap: movingRiver,
                        frequency: 1000.0,
                        animationSpeed: 0.1,
                        amplitude: 10,
                        specularIntensity: 10
                    }
                }
            }),

        })
    });
    if (this._grow) {
        this.grow();
    }

};
WaterPrimitive.prototype.grow = function () {
    if (this._upGrow) {
        if (this.extrudedHeight < this._targetHeight) {
            this.extrudedHeight += 0.01;
            Cesium.requestAnimationFrame(() => this.grow());
        }
    } else {
        if (this.extrudedHeight > this._targetHeight) {
            this.extrudedHeight -= 0.01;
            Cesium.requestAnimationFrame(() => this.grow());
        }
    }
}
Cesium.WaterPrimitive = WaterPrimitive;

调用方法:

position Cartesian3 世界坐标系 x,y,z

import { WaterPrimitive } from './Water'


this.viewer.scene.primitives.add(new WaterPrimitive({
                positions,
                height,
                extrudedHeight:height,
                targetHeight:750,
                grow:true,
                upGrow:true,

            }))

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值