C2——cesium流动特效

描述:cesium里面的道路什么的加个流动的效果。

原理:通过创建自定义材质来实现。

效果:可以自己定义流动样式颜色,可以调整流动速度的快慢,。

代码有点乱没时间整理就这样吧:在其他地方已经把自定义材质封装成了一个对象,但是版本更新太多次没时间去找了。奔来也是参考网上其他人的但现在原文找不到了。

// 自定义材质的
if (Cesium.PolylineTrailLinkMaterialPropertyRoad1 == undefined) {
    function PolylineTrailLinkMaterialPropertyRoad1(color, duration) {
        this._definitionChanged = new Cesium.Event();
        this._color = undefined;
        this._colorSubscription = undefined;
        this.color = color;
        this.duration = duration;
        this._time = new Date().getTime();
    }
    Object.defineProperties(
        PolylineTrailLinkMaterialPropertyRoad1.prototype,
        {
            isConstant: {
                get: function () {
                    return false;
                }
            },
            definitionChanged: {
                get: function () {
                    return this._definitionChanged;
                }
            },
            color: Cesium.createPropertyDescriptor("color")
        }
    );
    PolylineTrailLinkMaterialPropertyRoad1.prototype.getType = function (time) {
        return "PolylineTrailLink";
    };
    PolylineTrailLinkMaterialPropertyRoad1.prototype.getValue = function (time,result) {
        if (!Cesium.defined(result)) {
            result = {};
        }
        result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
        result.time =((new Date().getTime() - this._time) % this.duration) / this.duration;
        return result;
    };
    PolylineTrailLinkMaterialPropertyRoad1.prototype.equals = function ( other ) {
        return ( this === other || (other instanceof PolylineTrailLinkMaterialPropertyRoad1 && Property.equals(this._color, other._color)) ); 
    };
    Cesium.PolylineTrailLinkMaterialPropertyRoad1 = PolylineTrailLinkMaterialPropertyRoad1;
    Cesium.Material.PolylineTrailLinkType = "PolylineTrailLink";
    Cesium.Material.PolylineTrailLinkImage = require("./blue6.png");//道路样式的png
    Cesium.Material.PolylineTrailLinkSource = "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
                                                {\n\
                                                    czm_material material = czm_getDefaultMaterial(materialInput);\n\
                                                    vec2 st = materialInput.st;\n\
                                                    vec4 colorImage = texture2D(image, vec2(fract(st.s - time), st.t));\n\
                                                    material.alpha = colorImage.a * color.a;\n\
                                                    material.diffuse = (colorImage.rgb+color.rgb)/2.0;\n\
                                                    return material;\n\
                                                }";
    Cesium.Material._materialCache.addMaterial(
        Cesium.Material.PolylineTrailLinkType,
        {
            fabric: {
                type: Cesium.Material.PolylineTrailLinkType,
                uniforms: {
                    color: new Cesium.Color(1.0, 0.0, 0.0, 0.5),
                    image: Cesium.Material.PolylineTrailLinkImage,
                    time: 0,
                    constantSpeed: 300,
                    depthFailMaterial: true
                },
                source: Cesium.Material.PolylineTrailLinkSource
            },
            translucent: function (material) {
                return true;
            }
        }
    );
}

// new来生成材质实体
if (!window.roadMaterialRoad1) {
    let roadColor = new Cesium.Color.fromCssColorString("#0cfd11");
    window.roadMaterialRoad1 = new Cesium.PolylineTrailLinkMaterialPropertyRoad1( roadColor, 20000 );
}

// 创建流动线对象
viewer.entities.add({
    polyline: new Cesium.PolylineGraphics({
        material: roadMaterial,
        width: new Cesium.ConstantProperty(25),// 线宽
        arcType: Cesium.ArcType.GEODESIC,
        positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions)//positions道路经过的坐标点集合
    })
});

 

  • 7
    点赞
  • 55
    收藏
    觉得还不错? 一键收藏
  • 21
    评论
Cesium瀑布特效是一种通过使用Cesium地理信息系统平台来实现的特效效果。Cesium是一种开源的JavaScript库,用于开发3D WebGIS应用程序。它可以为用户提供高质量、高性能的地理可视化效果。瀑布特效是其中的一种特效,用于模拟瀑布的流动效果。 在实现Cesium瀑布特效时,首先需要创建一个3D场景,并在场景中添加一条瀑布的模型。可以使用Cesium的3D模型库,或者通过自定义模型来实现这个效果。模型可以包含瀑布的流动水流和瀑布周围的环境。然后,通过设置Cesium瀑布特效的参数,例如水流的流动速度、水流的颜色和流动方向等,来控制瀑布的外观和行为。 实现瀑布特效还可以利用Cesium的shader编程功能。使用shader编程,可以对瀑布的渲染过程进行自定义,例如对水流的纹理进行处理,以增强瀑布的真实感和细节效果。还可以通过调整瀑布的反射和折射效果,使得瀑布在光线照射下呈现出更加逼真的效果。 Cesium瀑布特效的实现可应用在各种领域,例如游戏、虚拟旅游、建筑可视化等。通过将瀑布特效应用于这些领域中,可以为用户提供更加生动和沉浸式的体验。此外,Cesium还提供了丰富的交互和动画效果,可以进一步增加瀑布特效的互动性和视觉效果。总之,Cesium瀑布特效是一种通过Cesium平台实现的3D地理信息可视化效果,可以为用户带来更加逼真和令人惊叹的瀑布场景。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值