@loaders.gl/tiles 4.1.0-alpha.4 → 4.1.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.dev.js CHANGED
@@ -6572,24 +6572,23 @@ var __exports__ = (() => {
6572
6572
  let allDescendantsLoaded = true;
6573
6573
  const stack = this._emptyTraversalStack;
6574
6574
  stack.push(root);
6575
- while (stack.length > 0 && allDescendantsLoaded) {
6575
+ while (stack.length > 0) {
6576
6576
  const tile = stack.pop();
6577
+ const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, false);
6578
+ const emptyLeaf = !tile.hasRenderContent && tile.children.length === 0;
6579
+ if (!traverse && !tile.contentAvailable && !emptyLeaf) {
6580
+ allDescendantsLoaded = false;
6581
+ }
6577
6582
  this.updateTile(tile, frameState);
6578
6583
  if (!tile.isVisibleAndInRequestVolume) {
6579
6584
  this.loadTile(tile, frameState);
6585
+ this.touchTile(tile, frameState);
6580
6586
  }
6581
- this.touchTile(tile, frameState);
6582
- const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true);
6583
6587
  if (traverse) {
6584
6588
  const children = tile.children;
6585
6589
  for (const child of children) {
6586
- if (stack.find(child)) {
6587
- stack.delete(child);
6588
- }
6589
6590
  stack.push(child);
6590
6591
  }
6591
- } else if (!tile.contentAvailable && !tile.hasEmptyContent) {
6592
- allDescendantsLoaded = false;
6593
6592
  }
6594
6593
  }
6595
6594
  return allDescendantsLoaded;
package/dist/index.cjs CHANGED
@@ -1123,24 +1123,23 @@ var TilesetTraverser = class {
1123
1123
  let allDescendantsLoaded = true;
1124
1124
  const stack = this._emptyTraversalStack;
1125
1125
  stack.push(root);
1126
- while (stack.length > 0 && allDescendantsLoaded) {
1126
+ while (stack.length > 0) {
1127
1127
  const tile = stack.pop();
1128
+ const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, false);
1129
+ const emptyLeaf = !tile.hasRenderContent && tile.children.length === 0;
1130
+ if (!traverse && !tile.contentAvailable && !emptyLeaf) {
1131
+ allDescendantsLoaded = false;
1132
+ }
1128
1133
  this.updateTile(tile, frameState);
1129
1134
  if (!tile.isVisibleAndInRequestVolume) {
1130
1135
  this.loadTile(tile, frameState);
1136
+ this.touchTile(tile, frameState);
1131
1137
  }
1132
- this.touchTile(tile, frameState);
1133
- const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true);
1134
1138
  if (traverse) {
1135
1139
  const children = tile.children;
1136
1140
  for (const child of children) {
1137
- if (stack.find(child)) {
1138
- stack.delete(child);
1139
- }
1140
1141
  stack.push(child);
1141
1142
  }
1142
- } else if (!tile.contentAvailable && !tile.hasEmptyContent) {
1143
- allDescendantsLoaded = false;
1144
1143
  }
1145
1144
  }
1146
1145
  return allDescendantsLoaded;
@@ -1 +1 @@
1
- {"version":3,"file":"tileset-traverser.d.ts","sourceRoot":"","sources":["../../src/tileset/tileset-traverser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,cAAc,CAAC,EAAE,CAAC,UAAU,KAAA,KAAK,GAAG,CAAC;IACrC,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAQzD,CAAC;AAEF,qBAAa,gBAAgB;IAC3B,OAAO,EA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I;IAStD,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI;IASpD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI;IAQrD,WAAW,CACT,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,UAAU,EACtB,eAAe,GAAE,OAAe,EAChC,gBAAgB,GAAE,OAAe,GAChC,OAAO;IAmBV,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAMrC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAMvC,oFAAoF;IACpF,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,GAAE,OAAe,GAAG,OAAO;IAS7F,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI;IAiBhE,uBAAuB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;IAIrD,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO;IAajE,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO;CAkCrE"}
@@ -210,24 +210,23 @@ export class TilesetTraverser {
210
210
  let allDescendantsLoaded = true;
211
211
  const stack = this._emptyTraversalStack;
212
212
  stack.push(root);
213
- while (stack.length > 0 && allDescendantsLoaded) {
213
+ while (stack.length > 0) {
214
214
  const tile = stack.pop();
215
+ const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, false);
216
+ const emptyLeaf = !tile.hasRenderContent && tile.children.length === 0;
217
+ if (!traverse && !tile.contentAvailable && !emptyLeaf) {
218
+ allDescendantsLoaded = false;
219
+ }
215
220
  this.updateTile(tile, frameState);
216
221
  if (!tile.isVisibleAndInRequestVolume) {
217
222
  this.loadTile(tile, frameState);
223
+ this.touchTile(tile, frameState);
218
224
  }
219
- this.touchTile(tile, frameState);
220
- const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true);
221
225
  if (traverse) {
222
226
  const children = tile.children;
223
227
  for (const child of children) {
224
- if (stack.find(child)) {
225
- stack.delete(child);
226
- }
227
228
  stack.push(child);
228
229
  }
229
- } else if (!tile.contentAvailable && !tile.hasEmptyContent) {
230
- allDescendantsLoaded = false;
231
230
  }
232
231
  }
233
232
  return allDescendantsLoaded;
@@ -1 +1 @@
1
- {"version":3,"file":"tileset-traverser.js","names":["ManagedArray","TILE_REFINEMENT","DEFAULT_PROPS","loadSiblings","skipLevelOfDetail","maximumScreenSpaceError","updateTransforms","onTraversalEnd","viewportTraversersMap","basePath","TilesetTraverser","traversalFinished","frameState","constructor","options","root","selectedTiles","requestedTiles","emptyTiles","lastUpdate","Date","getTime","updateDebounceTime","_traversalStack","_emptyTraversalStack","_frameNumber","traverse","reset","updateTile","frameNumber","executeTraversal","stack","_selectionDepth","push","length","tile","pop","shouldRefine","canTraverse","updateChildTiles","updateAndPushChildren","hasRenderContent","parent","parentRefines","Boolean","_shouldRefine","stoppedRefining","id","loadTile","selectTile","refine","ADD","REPLACE","touchTile","newTime","children","child","depth","sort","compareDistanceToCamera","bind","checkRefines","hasVisibleChild","refines","isVisibleAndInRequestVolume","find","delete","childRefines","_inRequestVolume","executeEmptyTraversal","contentAvailable","updateTileVisibility","shouldSelectTile","_selectedFrame","shouldLoadTile","_requestedFrame","_priority","_getPriority","tileset","_cache","touch","_touchedFrame","useParentMetric","arguments","undefined","ignoreVisibility","hasChildren","hasTilesetContent","contentExpired","hasUnloadedContent","screenSpaceError","_screenSpaceError","getScreenSpaceError","viewportIds","key","value","viewport","updateVisibility","b","a","_distanceToCamera","anyChildrenVisible","anyVisible","allDescendantsLoaded","hasEmptyContent"],"sources":["../../src/tileset/tileset-traverser.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Tile3D} from './tile-3d';\nimport {ManagedArray} from '../utils/managed-array';\nimport {TILE_REFINEMENT} from '../constants';\nimport {FrameState} from './helpers/frame-state';\n\nexport type TilesetTraverserProps = {\n loadSiblings?: boolean;\n skipLevelOfDetail?: boolean;\n updateTransforms?: boolean;\n maximumScreenSpaceError?: number;\n onTraversalEnd?: (frameState) => any;\n viewportTraversersMap?: Record<string, any>;\n basePath?: string;\n};\n\nexport const DEFAULT_PROPS: Required<TilesetTraverserProps> = {\n loadSiblings: false,\n skipLevelOfDetail: false,\n maximumScreenSpaceError: 2,\n updateTransforms: true,\n onTraversalEnd: () => {},\n viewportTraversersMap: {},\n basePath: ''\n};\n\nexport class TilesetTraverser {\n options: Required<TilesetTraverserProps>;\n\n // fulfill in traverse call\n root: any = null;\n\n // tiles should be rendered\n selectedTiles: Record<string, Tile3D> = {};\n // tiles should be loaded from server\n requestedTiles: Record<string, Tile3D> = {};\n // tiles does not have render content\n emptyTiles: Record<string, Tile3D> = {};\n\n protected lastUpdate: number = new Date().getTime();\n protected readonly updateDebounceTime = 1000;\n /** temporary storage to hold the traversed tiles during a traversal */\n protected _traversalStack = new ManagedArray();\n protected _emptyTraversalStack = new ManagedArray();\n /** set in every traverse cycle */\n protected _frameNumber: number | null = null;\n\n // RESULT\n protected traversalFinished(frameState: FrameState): boolean {\n return true;\n }\n\n // TODO nested props\n constructor(options: TilesetTraverserProps) {\n this.options = {...DEFAULT_PROPS, ...options};\n }\n\n // tiles should be visible\n traverse(root, frameState, options) {\n this.root = root; // for root screen space error\n this.options = {...this.options, ...options};\n\n // reset result\n this.reset();\n\n // update tile (visibility and expiration)\n this.updateTile(root, frameState);\n\n this._frameNumber = frameState.frameNumber;\n this.executeTraversal(root, frameState);\n }\n\n reset() {\n this.requestedTiles = {};\n this.selectedTiles = {};\n this.emptyTiles = {};\n this._traversalStack.reset();\n this._emptyTraversalStack.reset();\n }\n\n /**\n * Execute traverse\n * Depth-first traversal that traverses all visible tiles and marks tiles for selection.\n * If skipLevelOfDetail is off then a tile does not refine until all children are loaded.\n * This is the traditional replacement refinement approach and is called the base traversal.\n * Tiles that have a greater screen space error than the base screen space error are part of the base traversal,\n * all other tiles are part of the skip traversal. The skip traversal allows for skipping levels of the tree\n * and rendering children and parent tiles simultaneously.\n */\n /* eslint-disable-next-line complexity, max-statements */\n executeTraversal(root, frameState: FrameState): void {\n // stack to store traversed tiles, only visible tiles should be added to stack\n // visible: visible in the current view frustum\n const stack = this._traversalStack;\n root._selectionDepth = 1;\n\n stack.push(root);\n while (stack.length > 0) {\n // 1. pop tile\n const tile = stack.pop();\n\n // 2. check if tile needs to be refine, needs refine if a tile's LoD is not sufficient and tile has available children (available content)\n let shouldRefine = false;\n if (this.canTraverse(tile, frameState)) {\n this.updateChildTiles(tile, frameState);\n shouldRefine = this.updateAndPushChildren(\n tile,\n frameState,\n stack,\n tile.hasRenderContent ? tile._selectionDepth + 1 : tile._selectionDepth\n );\n }\n\n // 3. decide if should render (select) this tile\n // - tile does not have render content\n // - tile has render content and tile is `add` type (pointcloud)\n // - tile has render content and tile is `replace` type (photogrammetry) and can't refine any further\n const parent = tile.parent;\n const parentRefines = Boolean(!parent || parent._shouldRefine);\n const stoppedRefining = !shouldRefine;\n\n if (!tile.hasRenderContent) {\n this.emptyTiles[tile.id] = tile;\n this.loadTile(tile, frameState);\n if (stoppedRefining) {\n this.selectTile(tile, frameState);\n }\n // additive tiles\n } else if (tile.refine === TILE_REFINEMENT.ADD) {\n // Additive tiles are always loaded and selected\n this.loadTile(tile, frameState);\n this.selectTile(tile, frameState);\n\n // replace tiles\n } else if (tile.refine === TILE_REFINEMENT.REPLACE) {\n // Always load tiles in the base traversal\n // Select tiles that can't refine further\n this.loadTile(tile, frameState);\n if (stoppedRefining) {\n this.selectTile(tile, frameState);\n }\n }\n\n // 3. update cache, most recent touched tiles have higher priority to be fetched from server\n this.touchTile(tile, frameState);\n\n // 4. update tile refine prop and parent refinement status to trickle down to the descendants\n tile._shouldRefine = shouldRefine && parentRefines;\n }\n\n const newTime = new Date().getTime();\n if (this.traversalFinished(frameState) || newTime - this.lastUpdate > this.updateDebounceTime) {\n this.lastUpdate = newTime;\n this.options.onTraversalEnd(frameState);\n }\n }\n\n updateChildTiles(tile: Tile3D, frameState: FrameState): void {\n const children = tile.children;\n for (const child of children) {\n this.updateTile(child, frameState);\n }\n }\n\n /* eslint-disable complexity, max-statements */\n updateAndPushChildren(tile: Tile3D, frameState: FrameState, stack, depth): boolean {\n const {loadSiblings, skipLevelOfDetail} = this.options;\n\n const children = tile.children;\n\n // sort children tiles\n children.sort(this.compareDistanceToCamera.bind(this));\n\n // For traditional replacement refinement only refine if all children are loaded.\n // Empty tiles are exempt since it looks better if children stream in as they are loaded to fill the empty space.\n const checkRefines =\n tile.refine === TILE_REFINEMENT.REPLACE && tile.hasRenderContent && !skipLevelOfDetail;\n\n let hasVisibleChild = false;\n let refines = true;\n\n for (const child of children) {\n child._selectionDepth = depth;\n if (child.isVisibleAndInRequestVolume) {\n if (stack.find(child)) {\n stack.delete(child);\n }\n stack.push(child);\n hasVisibleChild = true;\n } else if (checkRefines || loadSiblings) {\n // Keep non-visible children loaded since they are still needed before the parent can refine.\n // Or loadSiblings is true so always load tiles regardless of visibility.\n this.loadTile(child, frameState);\n this.touchTile(child, frameState);\n }\n\n if (checkRefines) {\n let childRefines;\n if (!child._inRequestVolume) {\n childRefines = false;\n } else if (!child.hasRenderContent) {\n childRefines = this.executeEmptyTraversal(child, frameState);\n } else {\n childRefines = child.contentAvailable;\n }\n refines = refines && childRefines;\n\n if (!refines) {\n return false;\n }\n }\n }\n\n if (!hasVisibleChild) {\n refines = false;\n }\n return refines;\n }\n /* eslint-enable complexity, max-statements */\n\n updateTile(tile: Tile3D, frameState: FrameState): void {\n this.updateTileVisibility(tile, frameState);\n }\n\n // tile to render in the browser\n selectTile(tile: Tile3D, frameState: FrameState): void {\n if (this.shouldSelectTile(tile)) {\n // The tile can be selected right away and does not require traverseAndSelect\n tile._selectedFrame = frameState.frameNumber;\n this.selectedTiles[tile.id] = tile;\n }\n }\n\n // tile to load from server\n loadTile(tile: Tile3D, frameState: FrameState): void {\n if (this.shouldLoadTile(tile)) {\n tile._requestedFrame = frameState.frameNumber;\n tile._priority = tile._getPriority();\n this.requestedTiles[tile.id] = tile;\n }\n }\n\n // cache tile\n touchTile(tile: Tile3D, frameState: FrameState): void {\n tile.tileset._cache.touch(tile);\n tile._touchedFrame = frameState.frameNumber;\n }\n\n // tile should be visible\n // tile should have children\n // tile LoD (level of detail) is not sufficient under current viewport\n canTraverse(\n tile: Tile3D,\n frameState: FrameState,\n useParentMetric: boolean = false,\n ignoreVisibility: boolean = false\n ): boolean {\n if (!tile.hasChildren) {\n return false;\n }\n\n // cesium specific\n if (tile.hasTilesetContent) {\n // Traverse external this to visit its root tile\n // Don't traverse if the subtree is expired because it will be destroyed\n return !tile.contentExpired;\n }\n\n if (!ignoreVisibility && !tile.isVisibleAndInRequestVolume) {\n return false;\n }\n\n return this.shouldRefine(tile, frameState, useParentMetric);\n }\n\n shouldLoadTile(tile: Tile3D): boolean {\n // if request tile is in current frame\n // and has unexpired render content\n return tile.hasUnloadedContent || tile.contentExpired;\n }\n\n shouldSelectTile(tile: Tile3D): boolean {\n // if select tile is in current frame\n // and content available\n return tile.contentAvailable && !this.options.skipLevelOfDetail;\n }\n\n /** Decide if tile LoD (level of detail) is not sufficient under current viewport */\n shouldRefine(tile: Tile3D, frameState: FrameState, useParentMetric: boolean = false): boolean {\n let screenSpaceError = tile._screenSpaceError;\n if (useParentMetric) {\n screenSpaceError = tile.getScreenSpaceError(frameState, true);\n }\n\n return screenSpaceError > this.options.maximumScreenSpaceError;\n }\n\n updateTileVisibility(tile: Tile3D, frameState: FrameState): void {\n const viewportIds: string[] = [];\n if (this.options.viewportTraversersMap) {\n for (const key in this.options.viewportTraversersMap) {\n const value = this.options.viewportTraversersMap[key];\n if (value === frameState.viewport.id) {\n viewportIds.push(key);\n }\n }\n } else {\n viewportIds.push(frameState.viewport.id);\n }\n tile.updateVisibility(frameState, viewportIds);\n }\n\n // UTILITIES\n\n compareDistanceToCamera(b: Tile3D, a: Tile3D): number {\n return b._distanceToCamera - a._distanceToCamera;\n }\n\n anyChildrenVisible(tile: Tile3D, frameState: FrameState): boolean {\n let anyVisible = false;\n for (const child of tile.children) {\n // @ts-expect-error\n child.updateVisibility(frameState);\n // @ts-expect-error\n anyVisible = anyVisible || child.isVisibleAndInRequestVolume;\n }\n return anyVisible;\n }\n\n // Depth-first traversal that checks if all nearest descendants with content are loaded.\n // Ignores visibility.\n executeEmptyTraversal(root: Tile3D, frameState: FrameState): boolean {\n let allDescendantsLoaded = true;\n const stack = this._emptyTraversalStack;\n\n stack.push(root);\n\n while (stack.length > 0 && allDescendantsLoaded) {\n const tile = stack.pop();\n\n this.updateTile(tile, frameState);\n\n if (!tile.isVisibleAndInRequestVolume) {\n // Load tiles that aren't visible since they are still needed for the parent to refine\n this.loadTile(tile, frameState);\n }\n\n this.touchTile(tile, frameState);\n\n // Only traverse if the tile is empty - traversal stop at descendants with content\n const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true);\n\n if (traverse) {\n const children = tile.children;\n for (const child of children) {\n // eslint-disable-next-line max-depth\n if (stack.find(child)) {\n stack.delete(child);\n }\n stack.push(child);\n }\n } else if (!tile.contentAvailable && !tile.hasEmptyContent) {\n allDescendantsLoaded = false;\n }\n }\n\n return allDescendantsLoaded;\n }\n}\n"],"mappings":"SAKQA,YAAY;AAAA,SACZC,eAAe;AAavB,OAAO,MAAMC,aAA8C,GAAG;EAC5DC,YAAY,EAAE,KAAK;EACnBC,iBAAiB,EAAE,KAAK;EACxBC,uBAAuB,EAAE,CAAC;EAC1BC,gBAAgB,EAAE,IAAI;EACtBC,cAAc,EAAEA,CAAA,KAAM,CAAC,CAAC;EACxBC,qBAAqB,EAAE,CAAC,CAAC;EACzBC,QAAQ,EAAE;AACZ,CAAC;AAED,OAAO,MAAMC,gBAAgB,CAAC;EAsBlBC,iBAAi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M6B,QAAQ,GAAGpB,IAAI,CAACoB,QAAQ;QAC9B,KAAK,MAAMC,KAAK,IAAID,QAAQ,EAAE;UAE5B,IAAIxB,KAAK,CAACkC,IAAI,CAACT,KAAK,CAAC,EAAE;YACrBzB,KAAK,CAACmC,MAAM,CAACV,KAAK,CAAC;UACrB;UACAzB,KAAK,CAACE,IAAI,CAACuB,KAAK,CAAC;QACnB;MACF,CAAC,MAAM,IAAI,CAACrB,IAAI,CAACmC,gBAAgB,IAAI,CAACnC,IAAI,CAACqE,eAAe,EAAE;QAC1DD,oBAAoB,GAAG,KAAK;MAC9B;IACF;IAEA,OAAOA,oBAAoB;EAC7B;AACF"}
1
+ {"version":3,"file":"tileset-traverser.js","names":["ManagedArray","TILE_REFINEMENT","DEFAULT_PROPS","loadSiblings","skipLevelOfDetail","maximumScreenSpaceError","updateTransforms","onTraversalEnd","viewportTraversersMap","basePath","TilesetTraverser","traversalFinished","frameState","constructor","options","root","selectedTiles","requestedTiles","emptyTiles","lastUpdate","Date","getTime","updateDebounceTime","_traversalStack","_emptyTraversalStack","_frameNumber","traverse","reset","updateTile","frameNumber","executeTraversal","stack","_selectionDepth","push","length","tile","pop","shouldRefine","canTraverse","updateChildTiles","updateAndPushChildren","hasRenderContent","parent","parentRefines","Boolean","_shouldRefine","stoppedRefining","id","loadTile","selectTile","refine","ADD","REPLACE","touchTile","newTime","children","child","depth","sort","compareDistanceToCamera","bind","checkRefines","hasVisibleChild","refines","isVisibleAndInRequestVolume","find","delete","childRefines","_inRequestVolume","executeEmptyTraversal","contentAvailable","updateTileVisibility","shouldSelectTile","_selectedFrame","shouldLoadTile","_requestedFrame","_priority","_getPriority","tileset","_cache","touch","_touchedFrame","useParentMetric","arguments","undefined","ignoreVisibility","hasChildren","hasTilesetContent","contentExpired","hasUnloadedContent","screenSpaceError","_screenSpaceError","getScreenSpaceError","viewportIds","key","value","viewport","updateVisibility","b","a","_distanceToCamera","anyChildrenVisible","anyVisible","allDescendantsLoaded","emptyLeaf"],"sources":["../../src/tileset/tileset-traverser.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Tile3D} from './tile-3d';\nimport {ManagedArray} from '../utils/managed-array';\nimport {TILE_REFINEMENT} from '../constants';\nimport {FrameState} from './helpers/frame-state';\n\nexport type TilesetTraverserProps = {\n loadSiblings?: boolean;\n skipLevelOfDetail?: boolean;\n updateTransforms?: boolean;\n maximumScreenSpaceError?: number;\n onTraversalEnd?: (frameState) => any;\n viewportTraversersMap?: Record<string, any>;\n basePath?: string;\n};\n\nexport const DEFAULT_PROPS: Required<TilesetTraverserProps> = {\n loadSiblings: false,\n skipLevelOfDetail: false,\n maximumScreenSpaceError: 2,\n updateTransforms: true,\n onTraversalEnd: () => {},\n viewportTraversersMap: {},\n basePath: ''\n};\n\nexport class TilesetTraverser {\n options: Required<TilesetTraverserProps>;\n\n // fulfill in traverse call\n root: any = null;\n\n // tiles should be rendered\n selectedTiles: Record<string, Tile3D> = {};\n // tiles should be loaded from server\n requestedTiles: Record<string, Tile3D> = {};\n // tiles does not have render content\n emptyTiles: Record<string, Tile3D> = {};\n\n protected lastUpdate: number = new Date().getTime();\n protected readonly updateDebounceTime = 1000;\n /** temporary storage to hold the traversed tiles during a traversal */\n protected _traversalStack = new ManagedArray();\n protected _emptyTraversalStack = new ManagedArray();\n /** set in every traverse cycle */\n protected _frameNumber: number | null = null;\n\n // RESULT\n protected traversalFinished(frameState: FrameState): boolean {\n return true;\n }\n\n // TODO nested props\n constructor(options: TilesetTraverserProps) {\n this.options = {...DEFAULT_PROPS, ...options};\n }\n\n // tiles should be visible\n traverse(root, frameState, options) {\n this.root = root; // for root screen space error\n this.options = {...this.options, ...options};\n\n // reset result\n this.reset();\n\n // update tile (visibility and expiration)\n this.updateTile(root, frameState);\n\n this._frameNumber = frameState.frameNumber;\n this.executeTraversal(root, frameState);\n }\n\n reset() {\n this.requestedTiles = {};\n this.selectedTiles = {};\n this.emptyTiles = {};\n this._traversalStack.reset();\n this._emptyTraversalStack.reset();\n }\n\n /**\n * Execute traverse\n * Depth-first traversal that traverses all visible tiles and marks tiles for selection.\n * If skipLevelOfDetail is off then a tile does not refine until all children are loaded.\n * This is the traditional replacement refinement approach and is called the base traversal.\n * Tiles that have a greater screen space error than the base screen space error are part of the base traversal,\n * all other tiles are part of the skip traversal. The skip traversal allows for skipping levels of the tree\n * and rendering children and parent tiles simultaneously.\n */\n /* eslint-disable-next-line complexity, max-statements */\n executeTraversal(root, frameState: FrameState): void {\n // stack to store traversed tiles, only visible tiles should be added to stack\n // visible: visible in the current view frustum\n const stack = this._traversalStack;\n root._selectionDepth = 1;\n\n stack.push(root);\n while (stack.length > 0) {\n // 1. pop tile\n const tile = stack.pop();\n\n // 2. check if tile needs to be refine, needs refine if a tile's LoD is not sufficient and tile has available children (available content)\n let shouldRefine = false;\n if (this.canTraverse(tile, frameState)) {\n this.updateChildTiles(tile, frameState);\n shouldRefine = this.updateAndPushChildren(\n tile,\n frameState,\n stack,\n tile.hasRenderContent ? tile._selectionDepth + 1 : tile._selectionDepth\n );\n }\n\n // 3. decide if should render (select) this tile\n // - tile does not have render content\n // - tile has render content and tile is `add` type (pointcloud)\n // - tile has render content and tile is `replace` type (photogrammetry) and can't refine any further\n const parent = tile.parent;\n const parentRefines = Boolean(!parent || parent._shouldRefine);\n const stoppedRefining = !shouldRefine;\n\n if (!tile.hasRenderContent) {\n this.emptyTiles[tile.id] = tile;\n this.loadTile(tile, frameState);\n if (stoppedRefining) {\n this.selectTile(tile, frameState);\n }\n // additive tiles\n } else if (tile.refine === TILE_REFINEMENT.ADD) {\n // Additive tiles are always loaded and selected\n this.loadTile(tile, frameState);\n this.selectTile(tile, frameState);\n\n // replace tiles\n } else if (tile.refine === TILE_REFINEMENT.REPLACE) {\n // Always load tiles in the base traversal\n // Select tiles that can't refine further\n this.loadTile(tile, frameState);\n if (stoppedRefining) {\n this.selectTile(tile, frameState);\n }\n }\n\n // 3. update cache, most recent touched tiles have higher priority to be fetched from server\n this.touchTile(tile, frameState);\n\n // 4. update tile refine prop and parent refinement status to trickle down to the descendants\n tile._shouldRefine = shouldRefine && parentRefines;\n }\n\n const newTime = new Date().getTime();\n if (this.traversalFinished(frameState) || newTime - this.lastUpdate > this.updateDebounceTime) {\n this.lastUpdate = newTime;\n this.options.onTraversalEnd(frameState);\n }\n }\n\n updateChildTiles(tile: Tile3D, frameState: FrameState): void {\n const children = tile.children;\n for (const child of children) {\n this.updateTile(child, frameState);\n }\n }\n\n /* eslint-disable complexity, max-statements */\n updateAndPushChildren(tile: Tile3D, frameState: FrameState, stack, depth): boolean {\n const {loadSiblings, skipLevelOfDetail} = this.options;\n\n const children = tile.children;\n\n // sort children tiles\n children.sort(this.compareDistanceToCamera.bind(this));\n\n // For traditional replacement refinement only refine if all children are loaded.\n // Empty tiles are exempt since it looks better if children stream in as they are loaded to fill the empty space.\n const checkRefines =\n tile.refine === TILE_REFINEMENT.REPLACE && tile.hasRenderContent && !skipLevelOfDetail;\n\n let hasVisibleChild = false;\n let refines = true;\n\n for (const child of children) {\n child._selectionDepth = depth;\n if (child.isVisibleAndInRequestVolume) {\n if (stack.find(child)) {\n stack.delete(child);\n }\n stack.push(child);\n hasVisibleChild = true;\n } else if (checkRefines || loadSiblings) {\n // Keep non-visible children loaded since they are still needed before the parent can refine.\n // Or loadSiblings is true so always load tiles regardless of visibility.\n this.loadTile(child, frameState);\n this.touchTile(child, frameState);\n }\n\n if (checkRefines) {\n let childRefines;\n if (!child._inRequestVolume) {\n childRefines = false;\n } else if (!child.hasRenderContent) {\n childRefines = this.executeEmptyTraversal(child, frameState);\n } else {\n childRefines = child.contentAvailable;\n }\n refines = refines && childRefines;\n\n if (!refines) {\n return false;\n }\n }\n }\n\n if (!hasVisibleChild) {\n refines = false;\n }\n return refines;\n }\n /* eslint-enable complexity, max-statements */\n\n updateTile(tile: Tile3D, frameState: FrameState): void {\n this.updateTileVisibility(tile, frameState);\n }\n\n // tile to render in the browser\n selectTile(tile: Tile3D, frameState: FrameState): void {\n if (this.shouldSelectTile(tile)) {\n // The tile can be selected right away and does not require traverseAndSelect\n tile._selectedFrame = frameState.frameNumber;\n this.selectedTiles[tile.id] = tile;\n }\n }\n\n // tile to load from server\n loadTile(tile: Tile3D, frameState: FrameState): void {\n if (this.shouldLoadTile(tile)) {\n tile._requestedFrame = frameState.frameNumber;\n tile._priority = tile._getPriority();\n this.requestedTiles[tile.id] = tile;\n }\n }\n\n // cache tile\n touchTile(tile: Tile3D, frameState: FrameState): void {\n tile.tileset._cache.touch(tile);\n tile._touchedFrame = frameState.frameNumber;\n }\n\n // tile should be visible\n // tile should have children\n // tile LoD (level of detail) is not sufficient under current viewport\n canTraverse(\n tile: Tile3D,\n frameState: FrameState,\n useParentMetric: boolean = false,\n ignoreVisibility: boolean = false\n ): boolean {\n if (!tile.hasChildren) {\n return false;\n }\n\n // cesium specific\n if (tile.hasTilesetContent) {\n // Traverse external this to visit its root tile\n // Don't traverse if the subtree is expired because it will be destroyed\n return !tile.contentExpired;\n }\n\n if (!ignoreVisibility && !tile.isVisibleAndInRequestVolume) {\n return false;\n }\n\n return this.shouldRefine(tile, frameState, useParentMetric);\n }\n\n shouldLoadTile(tile: Tile3D): boolean {\n // if request tile is in current frame\n // and has unexpired render content\n return tile.hasUnloadedContent || tile.contentExpired;\n }\n\n shouldSelectTile(tile: Tile3D): boolean {\n // if select tile is in current frame\n // and content available\n return tile.contentAvailable && !this.options.skipLevelOfDetail;\n }\n\n /** Decide if tile LoD (level of detail) is not sufficient under current viewport */\n shouldRefine(tile: Tile3D, frameState: FrameState, useParentMetric: boolean = false): boolean {\n let screenSpaceError = tile._screenSpaceError;\n if (useParentMetric) {\n screenSpaceError = tile.getScreenSpaceError(frameState, true);\n }\n\n return screenSpaceError > this.options.maximumScreenSpaceError;\n }\n\n updateTileVisibility(tile: Tile3D, frameState: FrameState): void {\n const viewportIds: string[] = [];\n if (this.options.viewportTraversersMap) {\n for (const key in this.options.viewportTraversersMap) {\n const value = this.options.viewportTraversersMap[key];\n if (value === frameState.viewport.id) {\n viewportIds.push(key);\n }\n }\n } else {\n viewportIds.push(frameState.viewport.id);\n }\n tile.updateVisibility(frameState, viewportIds);\n }\n\n // UTILITIES\n\n compareDistanceToCamera(b: Tile3D, a: Tile3D): number {\n return b._distanceToCamera - a._distanceToCamera;\n }\n\n anyChildrenVisible(tile: Tile3D, frameState: FrameState): boolean {\n let anyVisible = false;\n for (const child of tile.children) {\n // @ts-expect-error\n child.updateVisibility(frameState);\n // @ts-expect-error\n anyVisible = anyVisible || child.isVisibleAndInRequestVolume;\n }\n return anyVisible;\n }\n\n // Depth-first traversal that checks if all nearest descendants with content are loaded.\n // Ignores visibility.\n executeEmptyTraversal(root: Tile3D, frameState: FrameState): boolean {\n let allDescendantsLoaded = true;\n const stack = this._emptyTraversalStack;\n stack.push(root);\n\n while (stack.length > 0) {\n const tile = stack.pop();\n\n const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, false);\n const emptyLeaf = !tile.hasRenderContent && tile.children.length === 0;\n\n // Traversal stops but the tile does not have content yet\n // There will be holes if the parent tries to refine to its children, so don't refine\n // One exception: a parent may refine even if one of its descendants is an empty leaf\n if (!traverse && !tile.contentAvailable && !emptyLeaf) {\n allDescendantsLoaded = false;\n }\n\n this.updateTile(tile, frameState);\n\n if (!tile.isVisibleAndInRequestVolume) {\n this.loadTile(tile, frameState);\n this.touchTile(tile, frameState);\n }\n\n if (traverse) {\n const children = tile.children;\n for (const child of children) {\n stack.push(child);\n }\n }\n }\n return allDescendantsLoaded;\n }\n}\n"],"mappings":"SAKQA,YAAY;AAAA,SACZC,eAAe;AAavB,OAAO,MAAMC,aAA8C,GAAG;EAC5DC,YAAY,EAAE,KAAK;EACnBC,iBAAiB,EAAE,KAAK;EACxBC,uBAAuB,EAAE,CAAC;EAC1BC,gBAAgB,EAAE,IAAI;EACtBC,cAAc,EAAEA,CAAA,KAAM,CAAC,CAAC;EACxBC,qBA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S,EAAE;QACrDD,oBAAoB,GAAG,KAAK;MAC9B;MAEA,IAAI,CAAC3E,UAAU,CAACO,IAAI,EAAEvB,UAAU,CAAC;MAEjC,IAAI,CAACuB,IAAI,CAAC6B,2BAA2B,EAAE;QACrC,IAAI,CAAChB,QAAQ,CAACb,IAAI,EAAEvB,UAAU,CAAC;QAC/B,IAAI,CAACyC,SAAS,CAAClB,IAAI,EAAEvB,UAAU,CAAC;MAClC;MAEA,IAAIc,QAAQ,EAAE;QACZ,MAAM6B,QAAQ,GAAGpB,IAAI,CAACoB,QAAQ;QAC9B,KAAK,MAAMC,KAAK,IAAID,QAAQ,EAAE;UAC5BxB,KAAK,CAACE,IAAI,CAACuB,KAAK,CAAC;QACnB;MACF;IACF;IACA,OAAO+C,oBAAoB;EAC7B;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/tiles",
3
- "version": "4.1.0-alpha.4",
3
+ "version": "4.1.0-alpha.6",
4
4
  "description": "Common components for different tiles loaders.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -41,8 +41,8 @@
41
41
  "build-bundle": "ocular-bundle ./src/index.ts"
42
42
  },
43
43
  "dependencies": {
44
- "@loaders.gl/loader-utils": "4.1.0-alpha.4",
45
- "@loaders.gl/math": "4.1.0-alpha.4",
44
+ "@loaders.gl/loader-utils": "4.1.0-alpha.6",
45
+ "@loaders.gl/math": "4.1.0-alpha.6",
46
46
  "@math.gl/core": "^4.0.0",
47
47
  "@math.gl/culling": "^4.0.0",
48
48
  "@math.gl/geospatial": "^4.0.0",
@@ -55,5 +55,5 @@
55
55
  "devDependencies": {
56
56
  "@deck.gl/core": "^8.9.0"
57
57
  },
58
- "gitHead": "b18ba1d63be704fd021e4470e8ab84175621e62d"
58
+ "gitHead": "fd58d91e05ebfd89ab8998a87157bf07c43997a5"
59
59
  }
@@ -335,38 +335,35 @@ export class TilesetTraverser {
335
335
  executeEmptyTraversal(root: Tile3D, frameState: FrameState): boolean {
336
336
  let allDescendantsLoaded = true;
337
337
  const stack = this._emptyTraversalStack;
338
-
339
338
  stack.push(root);
340
339
 
341
- while (stack.length > 0 && allDescendantsLoaded) {
340
+ while (stack.length > 0) {
342
341
  const tile = stack.pop();
343
342
 
343
+ const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, false);
344
+ const emptyLeaf = !tile.hasRenderContent && tile.children.length === 0;
345
+
346
+ // Traversal stops but the tile does not have content yet
347
+ // There will be holes if the parent tries to refine to its children, so don't refine
348
+ // One exception: a parent may refine even if one of its descendants is an empty leaf
349
+ if (!traverse && !tile.contentAvailable && !emptyLeaf) {
350
+ allDescendantsLoaded = false;
351
+ }
352
+
344
353
  this.updateTile(tile, frameState);
345
354
 
346
355
  if (!tile.isVisibleAndInRequestVolume) {
347
- // Load tiles that aren't visible since they are still needed for the parent to refine
348
356
  this.loadTile(tile, frameState);
357
+ this.touchTile(tile, frameState);
349
358
  }
350
359
 
351
- this.touchTile(tile, frameState);
352
-
353
- // Only traverse if the tile is empty - traversal stop at descendants with content
354
- const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true);
355
-
356
360
  if (traverse) {
357
361
  const children = tile.children;
358
362
  for (const child of children) {
359
- // eslint-disable-next-line max-depth
360
- if (stack.find(child)) {
361
- stack.delete(child);
362
- }
363
363
  stack.push(child);
364
364
  }
365
- } else if (!tile.contentAvailable && !tile.hasEmptyContent) {
366
- allDescendantsLoaded = false;
367
365
  }
368
366
  }
369
-
370
367
  return allDescendantsLoaded;
371
368
  }
372
369
  }