function Cesium3DTileset(options)
利用when.js 实现的promise 异步调用
Resource.createIfNeeded(url) //判断是url中是否有资源
Cesium3DTileset.loadJson(resource).then(function(value){ return JSON.parse(value);}//返回一个promise (实现方式,是通过url的的response获取文本内容)
json的格式
{
“assets”:{
“gltfUpAxis”:,
“version”:,
},
“root”:{
“geometricError”:,
“boundingVolume”:{
“box”:[0,0,0,0,0,0,0,0,0,0,0,0]
},
“content”
.
.
.
.
}
.
.
.
}
当获取完成JSON对象后调用回调
then(function(tilesetJson)
第一步:
Cesium3DTileset.prototype.loadTileset = function(resource, tilesetJson, parentTile)
var rootTile = new Cesium3DTile(this, resource, tilesetJson.root, parentTile);//创建一个新的3dtile根节点,并返回这个根节点
if (defined(parentTile)) {//是否有父节点
parentTile.children.push(rootTile);
rootTile._depth = parentTile._depth + 1;
}
//以栈的形式将节点保存入缓存中
var stack = [];
stack.push(rootTile);
while (stack.length > 0) {
var tile = stack.pop();
++statistics.numberOfTilesTotal;
this._allTilesAdditive = this._allTilesAdditive && (tile.refine === Cesium3DTileRefine.ADD);
var children = tile._header.children;
if (defined(children)) {
var length = children.length;
for (var i = 0; i < length; ++i) {
var childHeader = children[i];
var childTile = new Cesium3DTile(this, resource, childHeader, tile);
tile.children.push(childTile);
childTile._depth = tile._depth + 1;
stack.push(childTile);
}
}
if (this._cullWithChildrenBounds) {
Cesium3DTileOptimizations.checkChildrenWithinParent(tile);
}
}
Cesium3DTile(this, resource, tilesetJson.root, parentTile)
/**
* The time in seconds after the tile’s content is ready when the content expires and new content is requested.当内容过期并请求新内容时,以秒为单位的时间。
*
* @type {Number}
*/
this.expireDuration = expireDuration;
/**
* The date when the content expires and new content is requested.
*
* @type {JulianDate}
*/
this.expireDate = expireDate;
/**
* The time when a style was last applied to this tile.内容过期并请求新内容的日期。
*
* @type {Number}
*
* @private
*/
this.lastStyleTime = 0;
/**
* Marks whether the tile's children bounds are fully contained within the tile's bounds标记tile的子边界是否完全包含在tile的边界中
*
* @type {Cesium3DTileOptimizationHint}
*
* @private
*/
this._optimChildrenWithinParent = Cesium3DTileOptimizationHint.NOT_COMPUTED;
/**
* Tracks if the tile's relationship with a ClippingPlaneCollection has changed with regards 跟踪与剪贴平面集合的关系是否随着剪贴平面收集的状态发生了变化
* to the ClippingPlaneCollection's state.
*
* @type {Boolean}
*
* @private
*/
this.clippingPlanesDirty = false;
// Members that are updated every frame for tree traversal and rendering optimizations:更新每帧树遍历和渲染优化的成员
this._distanceToCamera = 0;
this._centerZDepth = 0;
this._screenSpaceError = 0;
this._visibilityPlaneMask = 0;
this._visible = false;
this._inRequestVolume = false;
this._finalResolution = true;
this._depth = 0;
this._stackLength = 0;
this._selectionDepth = 0;
this._updatedVisibilityFrame = 0;
this._touchedFrame = 0;
this._visitedFrame = 0;
this._selectedFrame = 0;
this._requestedFrame = 0;
this._ancestorWithContent = undefined;
this._ancestorWithContentAvailable = undefined;
this._refines = false;
this._shouldSelect = false;
this._priority = 0.0;
this._isClipped = true;
this._clippingPlanesState = 0; // encapsulates (_isClipped, clippingPlanes.enabled) and number/function
this._debugBoundingVolume = undefined;
this._debugContentBoundingVolume = undefined;
this._debugViewerRequestVolume = undefined;
this._debugColor = Color.fromRandom({ alpha : 1.0 });
this._debugColorizeTiles = false;
this._commandsLength = 0;
this._color = undefined;
this._colorDirty = false;