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

注意:在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. 【翻译】nginx初学者指南

    nginx初学者指南 本文翻译自nginx官方网站:http://nginx.org/en/docs/beginners_guide.html#control 该指南会对nginx做一个简要的介绍,同 ...

  2. 几何不变矩--Hu矩

    [图像算法]图像特征: ---------------------------------------------------------------------------------------- ...

  3. Ubuntu中的两套网络连接管理方式

     版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/haifeng_gu/article/details/78286895 Linux里面有两套管理网络 ...

  4. 我碰到的stackoverflow error

    出现这种问题,首先需要检查自己的代码: 要么代码小错误:或者逻辑错误: 如果出现循环调用更要仔细检查: 我的问题: 循环调用:一个实体他有自己的父栏目,含有子栏目的list集合:两者结果映射resul ...

  5. vue自定义指令VNode详解(转)

    1.自定义指令钩子函数 Vue.directive('my-directive', {bind: function () {// 做绑定的准备工作// 比如添加事件监听器,或是其他只需要执行一次的复杂 ...

  6. Jest单元测试进阶

    Jest 命令行窗口中的指令 在学习Jest单元测试入门的时候,给Jest命令提供了一个参数 --watchAll, 让它监听测试文件或测试文件引入的文件的变化,从而时时进行测试.但这样做也带来一个问 ...

  7. vue学习整理

    1.webpack+vue自定义路径别名 vue-cli 用的是webpack,也可以使用webpack自定义别名这个功能,自定义别名这个功能当你在多层文件夹嵌套的时候不必一层一层找路径,直接使用自定 ...

  8. 30、filter数组去重

    eg: let arr=[1,0,0,9,7,7,5,2] let data=arr.filter((item,index,self)=> self.indexOf(item)===index ...

  9. psexec与wmi在内网渗透的使用

    psexec是一个很好的管理工具,在内网渗透中也被广泛使用. 但太“出名”也往往会遭来各种麻烦. 在有安全监听.防护的内网中使用psexec会容易触发告警. 1.psexec用法(前提:对方要开启ad ...

  10. Python 操作 MySQL 数据库

    使用示例: import pymysql #python3 conn=pymysql.connect(host="localhost",port=3306,user="r ...