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

注意:在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();
});

最新文章

  1. 萌新笔记——C++里将string类字符串(utf-8编码)分解成单个字(可中英混输)
  2. jquery 里面对数组去重操作-unique
  3. Skype无法收发组消息
  4. python 播放 wav 文件
  5. MVC公开课 &ndash; 1.基础 (2013-3-15广州传智MVC公开课)
  6. ASCIIHexDecode,RunLengthDecode
  7. XML 解析器
  8. sqlyog使用注意事项
  9. violin 结构介绍
  10. Adriod与HTML+JS的交互
  11. 数据库查询优化——Mysql索引
  12. smack4中文文档
  13. Flask 三方组件 WTForms
  14. hugepage优势
  15. iptable用法
  16. 报错解决——Failed to load resource: the server responded with a status of 404 (Not Found) favicon.ico文件找不到
  17. 【sping揭秘】11、Java 平台上的AOP实现机制
  18. android studio 使用总结
  19. 06Vue.js快速入门-Vue组件化开发
  20. Extjs4.x treepanel,treegrid 节点选择,选中某个节点

热门文章

  1. 49.react中使用less
  2. Java 面向对象(八) 权限修饰符 和 final、native 关键字
  3. Java深入学习(5):锁
  4. 安装socketio出现module &#39;importlib._bootstrap&#39; has no attribute &#39;SourceFileLoader&#39; 错误
  5. pandas 之 数据合并
  6. Hive安装部署与配置
  7. MySQL Config--参数innodb_flush_method
  8. Httpd服务进阶知识-LAMP源码编译安装
  9. Go基本运行编译命令解释
  10. iodine dig A