@@ -19,12 +19,14 @@ function isUsedThisFrame( tile, frameCount ) {
1919
2020}
2121
22+ // Checks whether all children have been processed and are ready to traverse
2223function areChildrenProcessed ( tile ) {
2324
2425 return tile . __childrenProcessed === tile . children . length && ( ! tile . __hasUnrenderableContent || isDownloadFinished ( tile . __loadingState ) ) ;
2526
2627}
2728
29+ // Checks whether we can stop at this tile for rendering or not
2830function canUnconditionallyRefine ( tile ) {
2931
3032 return tile . __hasUnrenderableContent || ( tile . parent && tile . parent . geometricError < tile . geometricError ) ;
@@ -104,14 +106,18 @@ function recursivelyMarkPreviouslyUsed( tile, renderer ) {
104106
105107 }
106108
107- // don't traverse if the children have not been processed, yet but tileset content
108- // should be considered to be "replaced" by the loaded children so await that here.
109- if ( areChildrenProcessed ( tile ) ) {
109+ if ( ! tile . __active || canUnconditionallyRefine ( tile ) ) {
110110
111- const children = tile . children ;
112- for ( let i = 0 , l = children . length ; i < l ; i ++ ) {
111+ // don't traverse if the children have not been processed, yet but tileset content
112+ // should be considered to be "replaced" by the loaded children so await that here.
113+ if ( areChildrenProcessed ( tile ) ) {
113114
114- recursivelyMarkPreviouslyUsed ( children [ i ] , renderer ) ;
115+ const children = tile . children ;
116+ for ( let i = 0 , l = children . length ; i < l ; i ++ ) {
117+
118+ recursivelyMarkPreviouslyUsed ( children [ i ] , renderer ) ;
119+
120+ }
115121
116122 }
117123
@@ -157,6 +163,7 @@ function canTraverse( tile, renderer ) {
157163
158164}
159165
166+ // Marks "active" children as "kicked" so they are still loaded but not rendered yet
160167function kickActiveChildren ( tile , renderer ) {
161168
162169 const { frameCount } = renderer ;
@@ -182,6 +189,13 @@ function kickActiveChildren( tile, renderer ) {
182189
183190}
184191
192+ // Checks whether this tile is ready to be stopped at for rendering
193+ function isChildReady ( tile ) {
194+
195+ return ! canUnconditionallyRefine ( tile ) && ( ! tile . __hasContent || isDownloadFinished ( tile . __loadingState ) ) ;
196+
197+ }
198+
185199// Determine which tiles are used by the renderer given the current camera configuration
186200function markUsedTiles ( tile , renderer ) {
187201
@@ -267,6 +281,7 @@ function markUsedSetLeaves( tile, renderer ) {
267281
268282 }
269283
284+ // Traversal
270285 if ( ! anyChildrenUsed ) {
271286
272287 tile . __isLeaf = true ;
@@ -313,13 +328,12 @@ function markVisibleTiles( tile, renderer ) {
313328 const children = tile . children ;
314329 if ( tile . __isLeaf ) {
315330
331+ // if we're allowed to stop at this tile then mark it as active and allow any previously active tiles to
332+ // continue to be displayed
316333 if ( ! canUnconditionallyRefine ( tile ) ) {
317334
318335 tile . __active = true ;
319336
320- // TODO: tiles should never end at an "unconditionally refine-able tiles" so we can guard this
321- // behind checking if this tile should be "visible" and loaded and if if it's not then we can
322- // continue to load previously active tiles
323337 if ( areChildrenProcessed ( tile ) && ( ! tile . __hasContent || ! isDownloadFinished ( tile . __loadingState ) ) ) {
324338
325339 for ( let i = 0 , l = children . length ; i < l ; i ++ ) {
@@ -346,8 +360,8 @@ function markVisibleTiles( tile, renderer ) {
346360
347361 if ( isUsedThisFrame ( c , renderer . frameCount ) ) {
348362
349- const childIsVisible = c . __active && ! canUnconditionallyRefine ( c ) && ( ! c . __hasContent || isDownloadFinished ( c . __loadingState ) ) ;
350- if ( ! childIsVisible && ! c . __allChildrenReady ) {
363+ const childIsReady = c . __active && isChildReady ( c ) ;
364+ if ( ! childIsReady && ! c . __allChildrenReady ) {
351365
352366 allChildrenReady = false ;
353367
@@ -359,7 +373,9 @@ function markVisibleTiles( tile, renderer ) {
359373
360374 tile . __allChildrenReady = allChildrenReady ;
361375
362- const thisTileIsVisible = tile . __active && ! canUnconditionallyRefine ( tile ) && ( ! tile . __hasContent || isDownloadFinished ( tile . __loadingState ) ) ;
376+ // If we find that the subsequent children are not ready such that this tile gap can be filled then
377+ // mark all lower tiles as non active and prepare this one to be displayed if possible
378+ const thisTileIsVisible = tile . __active && isChildReady ( tile ) ;
363379 if ( ! canUnconditionallyRefine ( tile ) && ! allChildrenReady && ! thisTileIsVisible ) {
364380
365381 if ( tile . __wasSetActive && ( loadedContent || ! tile . __hasContent ) ) {
@@ -379,16 +395,15 @@ function toggleTiles( tile, renderer ) {
379395 const isUsed = isUsedThisFrame ( tile , renderer . frameCount ) ;
380396 if ( isUsed ) {
381397
382- // any internal tileset must be marked as active and loaded
398+ // any internal tileset and additive tile must be marked as active and loaded
383399 if ( tile . __hasUnrenderableContent || tile . __hasRenderableContent && tile . refine === 'ADD' ) {
384400
385401 tile . __active = true ;
386402
387403 }
388404
389- // queue any tiles to load that we need to
390- // TODO: we'll need to ensure any lower level children that were "unmarked" also need to be queued for load. We can mark them as
391- // "kicked" so they can be accounted for later
405+ // queue any tiles to load that we need to, and unmark any unloaded or non visible tiles as "active"
406+ // TODO: it may be more simple to track a separate variable than "active" here
392407 if ( ( tile . __active || tile . __kicked ) && tile . __hasContent ) {
393408
394409 renderer . markTileUsed ( tile ) ;
@@ -421,10 +436,6 @@ function toggleTiles( tile, renderer ) {
421436
422437 }
423438
424- // TODO: if isLeaf and we can't load any tiles then we need to continue to traverse if
425- // a tile was loaded or was rendered. We can keep track of whether a parent tile is
426- // loaded so we can know whether to traverse or not
427-
428439 }
429440
430441 if ( isUsed || tile . __usedLastFrame ) {
0 commit comments