cesium 多彩圆效果

/*
 * @Description: 多彩圆效果(参考开源代码)
 * @Version: 1.0
 * @Author: Julian
 * @Date: 2022-03-03 18:09:33
 * @LastEditors: Julian
 * @LastEditTime: 2022-03-03 18:32:18
 */

class CircleColorfulMaterialProperty {
    constructor(options) {
        this._definitionChanged = new Cesium.Event();
        this._color = undefined;
        this._speed = undefined;
        this.color = options.color;
        this.speed = options.speed;
    };

    get isConstant() {
        return false;
    }

    get definitionChanged() {
        return this._definitionChanged;
    }

    getType(time) {
        return Cesium.Material.CircleColorfulMaterialType;
    }

    getValue(time, result) {
        if (!Cesium.defined(result)) {
            result = {};
        }

        result.color = Cesium.Property.getValueOrDefault(this._color, time, Cesium.Color.RED, result.color);
        result.speed = Cesium.Property.getValueOrDefault(this._speed, time, 10, result.speed);
        return result
    }

    equals(other) {
        return (this === other ||
            (other instanceof CircleColorfulMaterialProperty &&
                Cesium.Property.equals(this._color, other._color) &&
                Cesium.Property.equals(this._speed, other._speed))
        )
    }
}

Object.defineProperties(CircleColorfulMaterialProperty.prototype, {
    color: Cesium.createPropertyDescriptor('color'),
    speed: Cesium.createPropertyDescriptor('speed')
})

Cesium.CircleColorfulMaterialProperty = CircleColorfulMaterialProperty;
Cesium.Material.CircleColorfulMaterialProperty = 'CircleColorfulMaterialProperty';
Cesium.Material.CircleColorfulMaterialType = 'CircleColorfulMaterialType';
Cesium.Material.CircleColorfulMaterialSource = `
                                                uniform vec4 color;
                                                uniform float speed;

                                                czm_material czm_getMaterial(czm_materialInput materialInput){
                                                czm_material material = czm_getDefaultMaterial(materialInput);
                                                vec2 st = materialInput.st  * 2.0 - 1.0;
                                                float time =czm_frameNumber * speed / 1000.0;
                                                float radius = length(st);
                                                float angle = atan(st.y/st.x);
                                                float radius1 = sin(time * 2.0) + sin(40.0*angle+time)*0.01;
                                                float radius2 = cos(time * 3.0);
                                                vec3 fragColor = 0.2 + 0.5 * cos( time + color.rgb + vec3(0,2,4));
                                                float inten1 = 1.0 - sqrt(abs(radius1 - radius));
                                                float inten2 = 1.0 - sqrt(abs(radius2 - radius));
                                                material.alpha = pow(inten1 + inten2 , 5.0) ;
                                                material.diffuse = fragColor * (inten1 + inten2);
                                                return material;
                                                }`

Cesium.Material._materialCache.addMaterial(Cesium.Material.CircleColorfulMaterialType, {
    fabric: {
        type: Cesium.Material.CircleColorfulMaterialType,
        uniforms: {
            color: new Cesium.Color(1.0, 0.0, 0.0, 1.0),
            speed: 10.0
        },
        source: Cesium.Material.CircleColorfulMaterialSource
    },
    translucent: function (material) {
        return true;
    }
})

// 这个方法的使用方法
// 多彩圆特效
// this.viewer.entities.add({
//     position: Cesium.Cartesian3.fromDegrees(120.277754, 31.533728),
//     name: "多彩圆",
//     ellipse: {
//       semiMinorAxis: 1000.0,
//       semiMajorAxis: 1000.0,
//       material: new Cesium.CircleColorfulMaterialProperty({
//         color: new Cesium.Color(1, 1, 0, 0.7),
//         speed: 12.0,
//       }),
//     },
//   });

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值