Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | 1x 1x 1x 1x 1x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 51x 81x 81x 81x 81x 96x 96x 96x 96x 20x 20x 20x 5x 5x 5x 15x 15x 309x 309x 228x 81x 573x 573x 573x 573x 111x 462x 462x 462x 7x 7x 264x 264x 264x 525x 264x 264x 264x 525x 525x 462x 462x 63x 21x 21x 264x 389x 389x 14x 375x 97x 278x 278x 111x 111x 111x 111x 111x 111x 573x 573x 573x 573x 573x 573x 573x 573x 160x 160x 160x 413x 24x 24x 389x 389x 375x 375x 278x 14x 7x 7x 7x 573x 573x 111x 111x 111x 111x 611x 611x 611x 257x 257x 38x 38x 18x 38x 38x 573x 573x 573x 573x 145x 2x 143x 143x 22x 143x 143x 105x 105x 38x 38x 468x 264x 264x 525x 525x 462x | import defined from "../Core/defined.js"; import ManagedArray from "../Core/ManagedArray.js"; import Cesium3DTileRefine from "./Cesium3DTileRefine.js"; import Cesium3DTilesetTraversal from "./Cesium3DTilesetTraversal.js"; /** * Depth-first traversal that traverses all visible tiles and marks tiles for selection. * Allows for skipping levels of the tree and rendering children and parent tiles simultaneously. * * @alias Cesium3DTilesetSkipTraversal * @constructor * * @private */ function Cesium3DTilesetSkipTraversal() {} const traversal = { stack: new ManagedArray(), stackMaximumLength: 0, }; const descendantTraversal = { stack: new ManagedArray(), stackMaximumLength: 0, }; const selectionTraversal = { stack: new ManagedArray(), stackMaximumLength: 0, ancestorStack: new ManagedArray(), ancestorStackMaximumLength: 0, }; const descendantSelectionDepth = 2; /** * Traverses a {@link Cesium3DTileset} to determine which tiles to load and render. * * @private * @param {Cesium3DTileset} tileset * @param {FrameState} frameState */ Cesium3DTilesetSkipTraversal.selectTiles = function (tileset, frameState) { tileset._requestedTiles.length = 0; Iif (tileset.debugFreezeFrame) { return; } tileset._selectedTiles.length = 0; tileset._selectedTilesToStyle.length = 0; tileset._emptyTiles.length = 0; tileset.hasMixedContent = false; const root = tileset.root; Cesium3DTilesetTraversal.updateTile(root, frameState); Iif (!root.isVisible) { return; } Iif ( root.getScreenSpaceError(frameState, true) <= tileset.memoryAdjustedScreenSpaceError ) { return; } executeTraversal(root, frameState); traverseAndSelect(root, frameState); traversal.stack.trim(traversal.stackMaximumLength); descendantTraversal.stack.trim(descendantTraversal.stackMaximumLength); selectionTraversal.stack.trim(selectionTraversal.stackMaximumLength); selectionTraversal.ancestorStack.trim( selectionTraversal.ancestorStackMaximumLength, ); // Update the priority for any requests found during traversal // Update after traversal so that min and max values can be used to normalize priority values const requestedTiles = tileset._requestedTiles; for (let i = 0; i < requestedTiles.length; ++i) { requestedTiles[i].updatePriority(); } }; /** * Mark descendant tiles for rendering, and update as needed * * @private * @param {Cesium3DTile} root * @param {FrameState} frameState */ function selectDescendants(root, frameState) { const { updateTile, touchTile, selectTile } = Cesium3DTilesetTraversal; const stack = descendantTraversal.stack; stack.push(root); while (stack.length > 0) { descendantTraversal.stackMaximumLength = Math.max( descendantTraversal.stackMaximumLength, stack.length, ); const tile = stack.pop(); const children = tile.children; for (let i = 0; i < children.length; ++i) { const child = children[i]; Eif (child.isVisible) { if (child.contentAvailable) { updateTile(child, frameState); touchTile(child, frameState); selectTile(child, frameState); } else Eif (child._depth - root._depth < descendantSelectionDepth) { // Continue traversing, but not too far stack.push(child); } } } } } /** * Mark a tile as selected if it has content available. * If its content is not available, and we are skipping levels of detail, * select an ancestor or descendant tile instead * * @private * @param {Cesium3DTile} tile * @param {FrameState} frameState */ function selectDesiredTile(tile, frameState) { // If this tile is not loaded attempt to select its ancestor instead const loadedTile = tile.contentAvailable ? tile : tile._ancestorWithContentAvailable; if (defined(loadedTile)) { // Tiles will actually be selected in traverseAndSelect loadedTile._shouldSelect = true; } else { // If no ancestors are ready traverse down and select tiles to minimize empty regions. // This happens often for immediatelyLoadDesiredLevelOfDetail where parent tiles are not necessarily loaded before zooming out. selectDescendants(tile, frameState); } } /** * Update links to the ancestor tiles that have content * * @private * @param {Cesium3DTile} tile * @param {FrameState} frameState */ function updateTileAncestorContentLinks(tile, frameState) { tile._ancestorWithContent = undefined; tile._ancestorWithContentAvailable = undefined; const { parent } = tile; if (!defined(parent)) { return; } const parentHasContent = !parent.hasUnloadedRenderableContent || parent._requestedFrame === frameState.frameNumber; // ancestorWithContent is an ancestor that has content or has the potential to have // content. Used in conjunction with tileset.skipLevels to know when to skip a tile. tile._ancestorWithContent = parentHasContent ? parent : parent._ancestorWithContent; // ancestorWithContentAvailable is an ancestor that is rendered if a desired tile is not loaded tile._ancestorWithContentAvailable = parent.contentAvailable ? parent : parent._ancestorWithContentAvailable; } /** * Determine if a tile has reached the limit of level of detail skipping. * If so, it should _not_ be skipped: it should be loaded and rendered * * @private * @param {Cesium3DTileset} tileset * @param {Cesium3DTile} tile * @returns {boolean} true if this tile should not be skipped */ function reachedSkippingThreshold(tileset, tile) { const ancestor = tile._ancestorWithContent; return ( !tileset.immediatelyLoadDesiredLevelOfDetail && (tile._priorityProgressiveResolutionScreenSpaceErrorLeaf || (defined(ancestor) && tile._screenSpaceError < ancestor._screenSpaceError / tileset.skipScreenSpaceErrorFactor && tile._depth > ancestor._depth + tileset.skipLevels)) ); } /** * @private * @param {Cesium3DTile} tile * @param {ManagedArray} stack * @param {FrameState} frameState * @returns {boolean} */ function updateAndPushChildren(tile, stack, frameState) { const { tileset, children } = tile; const { updateTile, loadTile, touchTile } = Cesium3DTilesetTraversal; for (let i = 0; i < children.length; ++i) { updateTile(children[i], frameState); } // Sort by distance to take advantage of early Z and reduce artifacts children.sort(Cesium3DTilesetTraversal.sortChildrenByDistanceToCamera); let anyChildrenVisible = false; for (let i = 0; i < children.length; ++i) { const child = children[i]; if (child.isVisible) { stack.push(child); anyChildrenVisible = true; } else if (tileset.loadSiblings) { loadTile(child, frameState); touchTile(child, frameState); } } return anyChildrenVisible; } /** * Determine if a tile is part of the base traversal. * If not, this tile could be considered for level of detail skipping * * @private * @param {Cesium3DTile} tile * @param {number} baseScreenSpaceError * @returns {boolean} */ function inBaseTraversal(tile, baseScreenSpaceError) { const { tileset } = tile; if (tileset.immediatelyLoadDesiredLevelOfDetail) { return false; } if (!defined(tile._ancestorWithContent)) { // Include root or near-root tiles in the base traversal so there is something to select up to return true; } Eif (tile._screenSpaceError === 0.0) { // If a leaf, use parent's SSE return tile.parent._screenSpaceError > baseScreenSpaceError; } return tile._screenSpaceError > baseScreenSpaceError; } /** * Depth-first traversal that traverses all visible tiles and marks tiles for selection. * Tiles that have a greater screen space error than the base screen space error are part of the base traversal, * all other tiles are part of the skip traversal. The skip traversal allows for skipping levels of the tree * and rendering children and parent tiles simultaneously. * * @private * @param {Cesium3DTile} root * @param {FrameState} frameState */ function executeTraversal(root, frameState) { const { tileset } = root; const baseScreenSpaceError = tileset.immediatelyLoadDesiredLevelOfDetail ? Number.MAX_VALUE : Math.max( tileset.baseScreenSpaceError, tileset.memoryAdjustedScreenSpaceError, ); const { canTraverse, loadTile, visitTile, touchTile } = Cesium3DTilesetTraversal; const stack = traversal.stack; stack.push(root); while (stack.length > 0) { traversal.stackMaximumLength = Math.max( traversal.stackMaximumLength, stack.length, ); const tile = stack.pop(); updateTileAncestorContentLinks(tile, frameState); const parent = tile.parent; const parentRefines = !defined(parent) || parent._refines; tile._refines = canTraverse(tile) ? updateAndPushChildren(tile, stack, frameState) && parentRefines : false; const stoppedRefining = !tile._refines && parentRefines; if (!tile.hasRenderableContent) { // Add empty tile just to show its debug bounding volume // If the tile has tileset content load the external tileset // If the tile cannot refine further select its nearest loaded ancestor tileset._emptyTiles.push(tile); loadTile(tile, frameState); Iif (stoppedRefining) { selectDesiredTile(tile, frameState); } } else if (tile.refine === Cesium3DTileRefine.ADD) { // Additive tiles are always loaded and selected selectDesiredTile(tile, frameState); loadTile(tile, frameState); } else Eif (tile.refine === Cesium3DTileRefine.REPLACE) { if (inBaseTraversal(tile, baseScreenSpaceError)) { // Always load tiles in the base traversal // Select tiles that can't refine further loadTile(tile, frameState); if (stoppedRefining) { selectDesiredTile(tile, frameState); } } else if (stoppedRefining) { // In skip traversal, load and select tiles that can't refine further selectDesiredTile(tile, frameState); loadTile(tile, frameState); } else Iif (reachedSkippingThreshold(tileset, tile)) { // In skip traversal, load tiles that aren't skipped loadTile(tile, frameState); } } visitTile(tile, frameState); touchTile(tile, frameState); } } /** * Traverse the tree and check if their selected frame is the current frame. If so, add it to a selection queue. * This is a preorder traversal so children tiles are selected before ancestor tiles. * * The reason for the preorder traversal is so that tiles can easily be marked with their * selection depth. A tile's _selectionDepth is its depth in the tree where all non-selected tiles are removed. * This property is important for use in the stencil test because we want to render deeper tiles on top of their * ancestors. If a tileset is very deep, the depth is unlikely to fit into the stencil buffer. * * We want to select children before their ancestors because there is no guarantee on the relationship between * the children's z-depth and the ancestor's z-depth. We cannot rely on Z because we want the child to appear on top * of ancestor regardless of true depth. The stencil tests used require children to be drawn first. * * NOTE: 3D Tiles uses 3 bits from the stencil buffer meaning this will not work when there is a chain of * selected tiles that is deeper than 7. This is not very likely. * * @private * @param {Cesium3DTile} root * @param {FrameState} frameState */ function traverseAndSelect(root, frameState) { const { selectTile, canTraverse } = Cesium3DTilesetTraversal; const { stack, ancestorStack } = selectionTraversal; let lastAncestor; stack.push(root); while (stack.length > 0 || ancestorStack.length > 0) { selectionTraversal.stackMaximumLength = Math.max( selectionTraversal.stackMaximumLength, stack.length, ); selectionTraversal.ancestorStackMaximumLength = Math.max( selectionTraversal.ancestorStackMaximumLength, ancestorStack.length, ); if (ancestorStack.length > 0) { const waitingTile = ancestorStack.peek(); if (waitingTile._stackLength === stack.length) { ancestorStack.pop(); if (waitingTile !== lastAncestor) { waitingTile._finalResolution = false; } selectTile(waitingTile, frameState); continue; } } const tile = stack.pop(); Iif (!defined(tile)) { // stack is empty but ancestorStack isn't continue; } const traverse = canTraverse(tile); if (tile._shouldSelect) { if (tile.refine === Cesium3DTileRefine.ADD) { selectTile(tile, frameState); } else { tile._selectionDepth = ancestorStack.length; if (tile._selectionDepth > 0) { tile.tileset.hasMixedContent = true; } lastAncestor = tile; if (!traverse) { selectTile(tile, frameState); continue; } ancestorStack.push(tile); tile._stackLength = stack.length; } } if (traverse) { const children = tile.children; for (let i = 0; i < children.length; ++i) { const child = children[i]; if (child.isVisible) { stack.push(child); } } } } } export default Cesium3DTilesetSkipTraversal; |