cesium 动态线效果

56 篇文章 2 订阅

一、扩展材质

function PolylineTrailMaterial(options) {
            options = Cesium.defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT);
            this._definitionChanged = new Cesium.Event();
            // 变量初始化
            this.color = Cesium.defaultValue(options.color && new Cesium.Color.fromCssColorString(options.color), Cesium.Color.RED);
            this.image = options.image || '';
            this.duration = options.duration || 1000;
            this.time = (new Date()).getTime();
        }
        // 材质类型
        PolylineTrailMaterial.prototype.getType = function (time) {
            return "PolylineTrail";
        };
        // 这个方法在每次渲染时被调用,result的参数会传入glsl中。
        PolylineTrailMaterial.prototype.getValue = function (time, result) {
            if (!Cesium.defined(result)) {
                result = {};
            }
            result.color = Cesium.Property.getValueOrClonedDefault(this.color, time, Cesium.Color.WHITE, result.color);
            result.image = Cesium.Property.getValueOrClonedDefault(this.image);
            result.time = (((new Date()).getTime() - this.time) % this.duration) / this.duration;
            return result;
        };

        PolylineTrailMaterial.prototype.equals = function (other) {
            return this === other ||
                other instanceof PolylineTrailMaterial && Cesium.Property.equals(this.color, other.color) && Cesium.Property.equals(this.image, other.image) && Cesium.Property.equals(this.duration, other.duration);
        };

        Object.defineProperties(PolylineTrailMaterial.prototype, {
            isConstant: {
                get: function get() {
                    return false;
                }
            },
            definitionChanged: {
                get: function get() {
                    return this._definitionChanged;
                }
            },
            color: Cesium.createPropertyDescriptor('color'),
            image: Cesium.createPropertyDescriptor('image'),
            duration: Cesium.createPropertyDescriptor('duration'),
        });

        Cesium.Material._materialCache.addMaterial("PolylineTrail", {
            fabric: {
                type: "PolylineTrail",
                uniforms: {
                    color: new Cesium.Color(1, 1, 0, 1.0),
                    image: '',
                    duration: 1,
                    time: 0
                },
                source:
                    `
                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 = color.rgb;\n\
                        return material;\n\
                    }
                `
            },
            translucent: function translucent() {
                return true;
            }
        });
        // 写到Cesium对象上,就可以像其他MaterialProperty一样使用了
        Cesium.Material.PolylineTrailType = 'PolylineTrail'
        Cesium.PolylineTrailMaterialProperty = PolylineTrailMaterial

二、调用

viewer.entities.add({
                name: 'polyline',
                polyline: {
                    positions: Cesium.Cartesian3.fromDegreesArray([
                        113.394743, 38.090979,
                        113.395422, 38.091654,
                    ]),
                    width: 10,
                    material: new Cesium.PolylineTrailMaterialProperty({
                        color: '#f00',
                        image: './image/trailLinkBlue.png'
                    })
                }
            });

 

  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Cesium是一个用于创建和显示地球上地理数据的JavaScript库。在Cesium中,可以使用纹理来创建动态线流动线效果。首先,你可以使用CesiumLab将你的数据转换为Cesium可用的3dtiles数据格式。然后,你可以向Cesium.Material中添加你刚刚新建的纹理,以创建动态线流动线效果。你可以使用Cesium.Material._materialCache.addMaterial方法来添加材质,参数中包括纹理的颜色、图像和时间等属性。最后,你可以使用纹理来绘制线或面,实现动态线流动线效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Cesium实现流动线/动态纹理](https://blog.csdn.net/weixin_42066016/article/details/105426932)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [济南建筑数据模型可直接使用cesiumlab转换为cesium可用的3dtiles数据](https://download.csdn.net/download/zslsh44/88278569)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值