接上一篇博客,这篇直接分析火星的源码,看它到底改了些什么。

注意:在cesium1.63.1版本改变了模块化方式,由AMD改为ES6模块化。注意引入文件加载模块时做出对应修改。

1.火星代码里修改了4处源码

1.1.GlobeSurfaceTileProvider.js

M代表引入的ExpandByMars.js文件

将

command.pass = Pass.GLOBE;

改为

command.pass = M.underEarth.enable?Pass.TRANSLUCENT:Pass.GLOBE;

1.2.RenderState.js

将

var enabled = cull.enabled;

改为

var enabled = defaultValue(M.undMerEarth.cullFace, cull.enabled);

1.3.Camera.js

将

                if (cartographic.height < height) {
cartographic.height = height;
if (mode === SceneMode.SCENE3D) {
ellipsoid.cartographicToCartesian(cartographic, this.position);
} else {
projection.project(cartographic, this.position);
}
heightUpdated = true;
}

改为(主要是监测到进入地下不自己弹出来的问题)

                if (cartographic.height < height) {
if (M.underEarth.enable && cartographic.height > (height - M.underEarth.enableDepth)){
return;
}
cartographic.height = height;
if (mode === SceneMode.SCENE3D) {
ellipsoid.cartographicToCartesian(cartographic, this.position);
} else {
projection.project(cartographic, this.position);
}
heightUpdated = true;
}

1.4.QuantizedMeshTerrainData.js(不知道有什么用,此处我没有改)

将

        return when(upsamplePromise).then(function(result) {
var quantizedVertices = new Uint16Array(result.vertices);
var indicesTypedArray = IndexDatatype.createTypedArray(quantizedVertices.length / , result.indices);
var encodedNormals;
if (defined(result.encodedNormals)) {
encodedNormals = new Uint8Array(result.encodedNormals);
}

改为

        return M.underEarth.enableSkirt &&(westSkirtHeight = ,
southSkirtHeight = ,
eastSkirtHeight = ,
northSkirtHeight = ),when(upsamplePromise).then(function(result) {
var quantizedVertices = new Uint16Array(result.vertices);
var indicesTypedArray = IndexDatatype.createTypedArray(quantizedVertices.length / , result.indices);
var encodedNormals;
if (defined(result.encodedNormals)) {
encodedNormals = new Uint8Array(result.encodedNormals);
}

2.火星新增了两个js文件

2.1.ExpandByMars.js

define(["../Core/clone"], function (e) {
"use strict";
return {
trustGenerator: ["fanfan"],
_defaultFloodAnalysis: {
floodVar: [, , , ],
ym_pos_x: [, , , , , , , , , , , , , , , ],
ym_pos_y: [, , , , , , , , , , , , , , , ],
ym_pos_z: [, , , , , , , , , , , , , , , ],
rect_flood: [, , , , , , , , ],
floodSpeed: ,
ym_max_index: ,
globe: !,
showElseArea: !
},
floodAnalysis: {
floodVar: [, , , ],
ym_pos_x: [, , , , , , , , , , , , , , , ],
ym_pos_y: [, , , , , , , , , , , , , , , ],
ym_pos_z: [, , , , , , , , , , , , , , , ],
rect_flood: [, , , , , , , , ],
floodSpeed: ,
ym_max_index: ,
globe: !,
showElseArea: !
},
resetFloodAnalysis: function () {
this.floodAnalysis = e(this._defaultFloodAnalysis)
},
_defaultExcavateAnalysis: {
splitNum: ,
showSelfOnly: !,
dig_pos_x: [, , , , , , , , , , , , , , , ],
dig_pos_y: [, , , , , , , , , , , , , , , ],
dig_pos_z: [, , , , , , , , , , , , , , , ],
rect_dig: [, , , , , , , , ],
dig_max_index: ,
excavateHeight: ,
excavateMinHeight: ,
excavatePerPoint: !
},
excavateAnalysis: {
splitNum: ,
showSelfOnly: !,
dig_pos_x: [, , , , , , , , , , , , , , , ],
dig_pos_y: [, , , , , , , , , , , , , , , ],
dig_pos_z: [, , , , , , , , , , , , , , , ],
rect_dig: [, , , , , , , , ],
dig_max_index: ,
excavateHeight: ,
excavateMinHeight: ,
excavatePerPoint: !
},
resetExcavateAnalysis: function () {
this.excavateAnalysis = e(this._defaultExcavateAnalysis)
},
_defaultTilesEditor: {
floodVar: [, , , ],
flatRect: [, , , , , , , , ],
yp_mat_x: [, , , , , , , , , , , , , , , ],
yp_mat_y: [, , , , , , , , , , , , , , , ],
yp_mat_z: [, , , , , , , , , , , , , , , ],
yp_max_index: ,
model_min_height: ,
IsYaPing: [!, !, !, !],
yp_show_InOrOut: [!, !, !, !],
yp_black_texture: null,
hm_dh_attr: [, , ],
modelLight: 2.2,
times: (new Date).getTime(),
floodColor: [, , , .]
},
tilesEditor: {
floodVar: [, , , ],
flatRect: [, , , , , , , , ],
yp_mat_x: [, , , , , , , , , , , , , , , ],
yp_mat_y: [, , , , , , , , , , , , , , , ],
yp_mat_z: [, , , , , , , , , , , , , , , ],
yp_max_index: ,
model_min_height: ,
IsYaPing: [!, !, !, !],
yp_show_InOrOut: [!, !, !, !],
yp_black_texture: null,
hm_dh_attr: [, , ],
modelLight: 2.2,
times: (new Date).getTime(),
floodColor: [, , , .]
},
resetTilesEditor: function () {
this.tilesEditor = e(this._defaultTilesEditor)
},
underEarth: {
cullFace: void ,
enable: void ,
enableDepth: ,
enableSkirt: !
},
occlusionOpen: !
}
})

2.2.underground.js

文件做了修改了,大概的意思如下面代码

function underground(t, i) {
this._viewer = t;
var n = Cesium.defaultValue(i, {});
this._depth = Cesium.defaultValue(n.depth, ),
this._alpha = Cesium.defaultValue(n.alpha, .),
this.enable = Cesium.defaultValue(n.enable, !)
}
underground.prototype._updateImageryLayersAlpha=function(e) {
for (var t = this._viewer.imageryLayers._layers, i = , a = t.length; i < a; i++)
t[i].alpha = e
}
underground.prototype._historyOpts =function() {
var e = {};
e.alpha = Cesium.clone(this._viewer.imageryLayers._layers[] && this._viewer.imageryLayers._layers[].alpha),
e.highDynamicRange = Cesium.clone(this._viewer.scene.highDynamicRange),
e.skyShow = Cesium.clone(this._viewer.scene.skyAtmosphere.show),
e.skyBoxShow = Cesium.clone(this._viewer.scene.skyBox.show),
e.depthTest = Cesium.clone(this._viewer.scene.globe.depthTestAgainstTerrain),
this._viewer.scene.globe._surface && this._viewer.scene.globe._surface._tileProvider && this._viewer.scene.globe._surface._tileProvider._renderState && (e.blending = Cesium.clone(this._viewer.scene.globe._surface._tileProvider._renderState.blending)),
this._oldViewOpts = e
}
underground.prototype.activate =function() {
if (!this._enable) {
this._enable = !,
this._historyOpts(),
this._updateImageryLayersAlpha(this._alpha);
var e = this._viewer;
Cesium.ExpandByMars.underEarth.cullFace = !,
Cesium.ExpandByMars.underEarth.enable = !,
Cesium.ExpandByMars.underEarth.enableDepth = this._depth,
Cesium.ExpandByMars.underEarth.enableSkirt = !,
e.scene.globe.depthTestAgainstTerrain = !,
e.scene.highDynamicRange = !,
e.scene.skyAtmosphere.show = !,
e.scene.skyBox.show = !,
e.scene.globe._surface._tileProvider && e.scene.globe._surface._tileProvider._renderState && e.scene.globe._surface._tileProvider._renderState.blending /*&& (e.scene.globe._surface._tileProvider._renderState.blending.enabled = !0,
e.scene.globe._surface._tileProvider._renderState.blending.equationRgb = Cesium.BlendEquation.ADD,
e.scene.globe._surface._tileProvider._renderState.blending.equationAlpha = Cesium.BlendEquation.ADD,
e.scene.globe._surface._tileProvider._renderState.blending.functionSourceAlpha = Cesium.BlendFunction.ONE,
e.scene.globe._surface._tileProvider._renderState.blending.functionSourceRgb = Cesium.BlendFunction.ONE,
e.scene.globe._surface._tileProvider._renderState.blending.functionDestinationAlpha = Cesium.BlendFunction.ZERO,
e.scene.globe._surface._tileProvider._renderState.blending.functionDestinationRgb = Cesium.BlendFunction.ZERO)*/
}
}
underground.prototype.disable=function() {
if (this._enable) {
this._enable = !,
this._updateImageryLayersAlpha(this._oldViewOpts.alpha);
var e = this._viewer;
Cesium.ExpandByMars.underEarth.cullFace = void ,
Cesium.ExpandByMars.underEarth.enable = !,
Cesium.ExpandByMars.underEarth.enableDepth = ,
Cesium.ExpandByMars.underEarth.enableSkirt = !,
e.scene.globe.depthTestAgainstTerrain = this._oldViewOpts.depthTest,
e.scene.skyBox.show = this._oldViewOpts.skyBoxShow,
e.scene.highDynamicRange = this._oldViewOpts.highDynamicRange,
e.scene.skyAtmosphere.show = this._oldViewOpts.skyShow/*,
void 0 != this._oldViewOpts.blending && (e.scene.globe._surface._tileProvider._renderState.blending = this._oldViewOpts.blending)*/
}
}
underground.prototype.destroy=function(){
delete this._viewer,
delete this._alpha,
delete this._depth,
delete this._enable,
delete this._oldViewOpts
}

3.测试

3.1.修改3处源码

3.2.增加1个文件,ExpandByMars.js

3.3.重新打包

npm run minifyRelease

3.4.沙盒里测试

function underground(t, i) {
this._viewer = t;
var n = Cesium.defaultValue(i, {});
this._depth = Cesium.defaultValue(n.depth, ),
this._alpha = Cesium.defaultValue(n.alpha, .),
this.enable = Cesium.defaultValue(n.enable, !)
}
underground.prototype._updateImageryLayersAlpha=function(e) {
for (var t = this._viewer.imageryLayers._layers, i = , a = t.length; i < a; i++)
t[i].alpha = e
}
underground.prototype._historyOpts =function() {
var e = {};
e.alpha = Cesium.clone(this._viewer.imageryLayers._layers[] && this._viewer.imageryLayers._layers[].alpha),
e.highDynamicRange = Cesium.clone(this._viewer.scene.highDynamicRange),
e.skyShow = Cesium.clone(this._viewer.scene.skyAtmosphere.show),
e.skyBoxShow = Cesium.clone(this._viewer.scene.skyBox.show),
e.depthTest = Cesium.clone(this._viewer.scene.globe.depthTestAgainstTerrain),
this._viewer.scene.globe._surface && this._viewer.scene.globe._surface._tileProvider && this._viewer.scene.globe._surface._tileProvider._renderState && (e.blending = Cesium.clone(this._viewer.scene.globe._surface._tileProvider._renderState.blending)),
this._oldViewOpts = e
}
underground.prototype.activate =function() {
if (!this._enable) {
this._enable = !,
this._historyOpts(),
this._updateImageryLayersAlpha(this._alpha);
var e = this._viewer;
Cesium.ExpandByMars.underEarth.cullFace = !,
Cesium.ExpandByMars.underEarth.enable = !,
Cesium.ExpandByMars.underEarth.enableDepth = this._depth,
Cesium.ExpandByMars.underEarth.enableSkirt = !,
e.scene.globe.depthTestAgainstTerrain = !,
e.scene.highDynamicRange = !,
e.scene.skyAtmosphere.show = !,
e.scene.skyBox.show = !,
e.scene.globe._surface._tileProvider && e.scene.globe._surface._tileProvider._renderState && e.scene.globe._surface._tileProvider._renderState.blending /*&& (e.scene.globe._surface._tileProvider._renderState.blending.enabled = !0,
e.scene.globe._surface._tileProvider._renderState.blending.equationRgb = Cesium.BlendEquation.ADD,
e.scene.globe._surface._tileProvider._renderState.blending.equationAlpha = Cesium.BlendEquation.ADD,
e.scene.globe._surface._tileProvider._renderState.blending.functionSourceAlpha = Cesium.BlendFunction.ONE,
e.scene.globe._surface._tileProvider._renderState.blending.functionSourceRgb = Cesium.BlendFunction.ONE,
e.scene.globe._surface._tileProvider._renderState.blending.functionDestinationAlpha = Cesium.BlendFunction.ZERO,
e.scene.globe._surface._tileProvider._renderState.blending.functionDestinationRgb = Cesium.BlendFunction.ZERO)*/
}
}
underground.prototype.disable=function() {
if (this._enable) {
this._enable = !,
this._updateImageryLayersAlpha(this._oldViewOpts.alpha);
var e = this._viewer;
Cesium.ExpandByMars.underEarth.cullFace = void ,
Cesium.ExpandByMars.underEarth.enable = !,
Cesium.ExpandByMars.underEarth.enableDepth = ,
Cesium.ExpandByMars.underEarth.enableSkirt = !,
e.scene.globe.depthTestAgainstTerrain = this._oldViewOpts.depthTest,
e.scene.skyBox.show = this._oldViewOpts.skyBoxShow,
e.scene.highDynamicRange = this._oldViewOpts.highDynamicRange,
e.scene.skyAtmosphere.show = this._oldViewOpts.skyShow/*,
void 0 != this._oldViewOpts.blending && (e.scene.globe._surface._tileProvider._renderState.blending = this._oldViewOpts.blending)*/
}
}
underground.prototype.destroy=function(){
delete this._viewer,
delete this._alpha,
delete this._depth,
delete this._enable,
delete this._oldViewOpts
} var viewer = new Cesium.Viewer('cesiumContainer');
viewer.scene.globe.baseColor = new Cesium.Color(, , , );
var blueBox = viewer.entities.add({
name: 'Blue box',
position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, ),
box: {
dimensions: new Cesium.Cartesian3(100.0, 100.0, 5000.0),
material: Cesium.Color.RED
}
});
viewer.zoomTo(blueBox);
var ug = new underground(viewer, {
depth: ,
alpha: 0.6
})
ug.activate(); Sandcastle.addToggleButton('地下模式', true, function(checked) {
checked?ug.activate():ug.disable();
});

cesium地下模式(地表透明)2的更多相关文章

  1. cesium地下模式(地表透明)4

    这篇博客主要罗列一下解决地下模式(地表透明)的相关资源 1.Cesium的Github仓库地下模式issue 有人提了这个问题,但是cesium官方没有解决这个问题,持续跟踪一下问题说不定哪天官方就解 ...

  2. cesium地下模式(地表透明)1

    cesium没有提供地下功能,实现地下模式需要以下三步. 1.修改cesium源码,在GlobeSurfaceTileProvider.js文件里修改一行代码 command.pass = Pass. ...

  3. cesium地下模式(地表透明)3

    这篇博客主要解决“瓦片的白色网格”问题 设置skirt=0可以解决这个问题,需要设置3个地方 1.HeightmapTerrainData.js createMesh方法 this._skirtHei ...

  4. 对端边缘云网络计算模式:透明计算、移动边缘计算、雾计算和Cloudlet

    对端边缘云网络计算模式:透明计算.移动边缘计算.雾计算和Cloudlet 概要 将数据发送到云端进行分析是过去几十年的一个突出趋势,推动了云计算成为主流计算范式.然而,物联网时代设备数量和数据流量的急 ...

  5. 七个结构模式之装饰者模式(Decorator Pattern)

    定义: 使用组合的方法,动态给一个类增加一些额外的功能,避免因为使用子类继承而导致类继承结构复杂.并且可以保持和被装饰者同一个抽象接口,从而使客户端透明. 结构图: Component:抽象构件类,定 ...

  6. <代码整洁之道>、<java与模式>、<head first设计模式>读书笔记集合

    一.前言                                                                                       几个月前的看书笔记 ...

  7. (十七)迭代器模式详解(foreach的精髓)

    作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 各位好,很久没以LZ的身份和 ...

  8. JavaScript高级---装饰者模式设计

    一.设计模式 javascript里面给我们提供了很多种设计模式: 工厂.桥.组合.门面.适配器.装饰者.享元.代理.观察者.命令.责任链 在前面我们实现了工厂模式和桥模式 工厂模式 : 核心:为了生 ...

  9. 24种设计模式--组合模式【Composite Pattern】

    大家在上学的时候应该都学过“数据结构”这门课程吧,还记得其中有一节叫“二叉树”吧,我们上学那会儿这一章节是必考内容,左子树,右子树,什么先序遍历后序遍历什么,重点就是二叉树的的遍历,我还记得当时老师就 ...

随机推荐

  1. .net core使用ocelot---第二篇 身份验证

    简介原文链接      .net core使用ocelot---第一篇 简单使用 接上文,我将继续介绍使用asp.net core 创建API网关,主要介绍身份验证(authentication )相 ...

  2. scarpy设置日志打印级别和存储位置

    在settings.py中配置 日志级别设置 LOG_LEVEL = 'ERROR' # 当LOG_LEVEL设置为ERROR时,在进行日志打印时,只是打印ERROR级别的日志 日志存储设置 LOG_ ...

  3. VIM编辑器使用的小技巧

    在命令中输入 vi –t 类型名.结构体名或者函数名 系统就会寻找相应的对象,默认是在当前目录的 tags 中搜索,例如我们想寻找 stat 结构体, 则输入 vi –t  stat 然后按 q 退出 ...

  4. Vue学习之动画小结(六)

    一.Vue中实现动画的方式:https://cn.vuejs.org/v2/guide/transitions.html Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括 ...

  5. [转] Cache 和 Buffer的区别

    程序员开发过程中经常会遇到“缓存”.“缓冲”等相似概念,之前没有特别关注,现在停下来做一下总结,才能更好地前行. 先来下枯燥的概念: 1.Cache:缓存区,是高速缓存,是位于CPU和主内存之间的容量 ...

  6. java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib/libjni_i

    出错log:java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib/libskytvjni.so" ...

  7. 12306 抢票项目霸榜 GitHub,标星即将破万

    十一将至,你买到回家的火车票了吗?如果没有,你可以试着打开 GitHub,在搜索栏键入 12306 的关键词,我相信你会发现一个新大陆.没错,这里有 1572 个抢票项目.它们大多用 Python.J ...

  8. TP5日志打印方法封装

    需求:在开发及测试过程中需要打印日志,并且可以将日志内容打印到指定文件,这样方便查看. 过程: 1. 打开think\Log文件,在该文件中添加一个静态方法,代码如下: /** * @param $m ...

  9. 浅谈布隆过滤器Bloom Filter

    先从一道面试题开始: 给A,B两个文件,各存放50亿条URL,每条URL占用64字节,内存限制是4G,让你找出A,B文件共同的URL. 这个问题的本质在于判断一个元素是否在一个集合中.哈希表以O(1) ...

  10. JMETER 使用BeanShell 配合 if 控制器实现逻辑控制

    业务场景 在登录后,我们根据登录的响应,判断是否执行下一步的操作. 实现步骤 1.在登录采样器树中增加BeanShell 监听器. 作用是在线程上下文变量中增加一个变量,表示登录是否成功. beans ...