Skip to content

Commit

Permalink
TilesRenderer: Don't modify tiles fields to clean up implicit tiling (#…
Browse files Browse the repository at this point in the history
…691)

* Handle uri preprocessing

* Move uri preprocessing

* Update implicit tiling handling

* Handle parsing of parameters in the url in GoogleCloudAuthPlugin

* Fix implicit tiling url

* Fix up implicit tiling
  • Loading branch information
gkjohnson authored Aug 16, 2024
1 parent 24a43b6 commit ac952bc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 47 deletions.
50 changes: 24 additions & 26 deletions src/base/TilesRendererBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ export class TilesRendererBase {

}

set preprocessURL( v ) {

console.warn( 'TilesRendererBase: The "preprocessURL" callback has been deprecated. Use a plugin, instead.' );
this._preprocessURL = v;

}

get preprocessURL() {

return this._preprocessURL;

}

constructor( url = null ) {

// state
Expand All @@ -112,7 +125,7 @@ export class TilesRendererBase {
this.fetchOptions = {};
this.plugins = [];

this.preprocessURL = null;
this._preprocessURL = null;

const lruCache = new LRUCache();
lruCache.unloadPriorityCallback = lruPriorityCallback;
Expand Down Expand Up @@ -292,9 +305,6 @@ export class TilesRendererBase {

preprocessNode( tile, tileSetDir, parentTile = null ) {

// Store the original content uri
const uri = tile.content?.uri;

if ( tile.content ) {

// Fix old file formats
Expand All @@ -305,13 +315,6 @@ export class TilesRendererBase {

}

if ( tile.content.uri ) {

// tile content uri has to be interpreted relative to the tileset.json
tile.content.uri = new URL( tile.content.uri, tileSetDir + '/' ).toString();

}

// NOTE: fix for some cases where tilesets provide the bounding volume
// but volumes are not present.
if (
Expand All @@ -332,7 +335,7 @@ export class TilesRendererBase {
tile.parent = parentTile;
tile.children = tile.children || [];

if ( uri ) {
if ( tile.content?.uri ) {

// "content" should only indicate loadable meshes, not external tile sets
const extension = getUrlExtension( tile.content.uri );
Expand Down Expand Up @@ -394,7 +397,7 @@ export class TilesRendererBase {

this.invokeAllPlugins( plugin => {

plugin !== this && plugin.preprocessNode && plugin.preprocessNode( tile, uri, parentTile );
plugin !== this && plugin.preprocessNode && plugin.preprocessNode( tile, tileSetDir, parentTile );

} );

Expand Down Expand Up @@ -487,7 +490,7 @@ export class TilesRendererBase {
if ( ! ( url in tileSets ) ) {

let processedUrl = url;
this.invokeAllPlugins( plugin => processedUrl = plugin.preprocessURL ? plugin.preprocessURL( processedUrl ) : processedUrl );
this.invokeAllPlugins( plugin => processedUrl = plugin.preprocessURL ? plugin.preprocessURL( processedUrl, null ) : processedUrl );

const pr = this
.fetchTileSet( processedUrl, this.fetchOptions )
Expand Down Expand Up @@ -530,11 +533,14 @@ export class TilesRendererBase {

}

let uri = new URL( tile.content.uri, tile.__basePath + '/' ).toString();
this.invokeAllPlugins( plugin => uri = plugin.preprocessURL ? plugin.preprocessURL( uri, tile ) : uri );

const stats = this.stats;
const lruCache = this.lruCache;
const downloadQueue = this.downloadQueue;
const parseQueue = this.parseQueue;
const uriExtension = getUrlExtension( tile.content.uri );
const uriExtension = getUrlExtension( uri );
const isExternalTileSet = Boolean( uriExtension && /json$/.test( uriExtension ) );
const addedSuccessfully = lruCache.add( tile, t => {

Expand Down Expand Up @@ -644,10 +650,7 @@ export class TilesRendererBase {

}

let processedUrl = tileCb.content.uri;
this.invokeAllPlugins( plugin => processedUrl = plugin.preprocessURL ? plugin.preprocessURL( processedUrl ) : processedUrl );

return this.fetchTileSet( processedUrl, Object.assign( { signal }, this.fetchOptions ), tileCb );
return this.fetchTileSet( uri, Object.assign( { signal }, this.fetchOptions ), tileCb );

} )
.then( json => {
Expand Down Expand Up @@ -678,10 +681,7 @@ export class TilesRendererBase {

}

let processedUrl = downloadTile.content.uri;
this.invokeAllPlugins( plugin => processedUrl = plugin.preprocessURL ? plugin.preprocessURL( processedUrl ) : processedUrl );

return fetch( processedUrl, Object.assign( { signal }, this.fetchOptions ) );
return fetch( uri, Object.assign( { signal }, this.fetchOptions ) );

} )
.then( res => {
Expand Down Expand Up @@ -726,10 +726,8 @@ export class TilesRendererBase {

}

const uri = parseTile.content.uri;
const extension = getUrlExtension( uri );

return this.invokeOnePlugin( plugin => plugin.parseTile && plugin.parseTile( buffer, parseTile, extension ) );
return this.invokeOnePlugin( plugin => plugin.parseTile && plugin.parseTile( buffer, parseTile, extension, uri ) );

} );

Expand Down
3 changes: 1 addition & 2 deletions src/three/TilesRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,11 @@ export class TilesRenderer extends TilesRendererBase {

}

async parseTile( buffer, tile, extension ) {
async parseTile( buffer, tile, extension, uri ) {

const cached = tile.cached;
cached._loadIndex ++;

const uri = tile.content.uri;
const uriSplits = uri.split( /[\\/]/g );
uriSplits.pop();
const workingPath = uriSplits.join( '/' );
Expand Down
2 changes: 1 addition & 1 deletion src/three/plugins/GoogleCloudAuthPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class GoogleCloudAuthPlugin {

if ( tile.content && tile.content.uri ) {

this.sessionToken = new URL( tile.content.uri ).searchParams.get( 'session' );
this.sessionToken = new URL( tile.content.uri, tile.__basePath ).searchParams.get( 'session' );
return true;

}
Expand Down
37 changes: 21 additions & 16 deletions src/three/plugins/ImplicitTilingPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ export class ImplicitTilingPlugin {

}

preprocessNode( tile, uri, parentTile ) {
preprocessNode( tile, tileSetDir, parentTile ) {

if ( tile.implicitTiling ) { //Check if the tile is an Implicit Root Tile
if ( tile.implicitTiling ) {

tile.__hasUnrenderableContent = true;
tile.__hasRenderableContent = false;

// Keep the original content uri
tile.__contentUri = uri ?? tile.content?.uri;

// Declare some properties
tile.__subtreeIdx = 0; // Idx of the tile in its subtree
tile.__implicitRoot = tile; // Keep this tile as an Implicit Root Tile
Expand All @@ -34,15 +31,6 @@ export class ImplicitTilingPlugin {
tile.__z = 0;
tile.__level = 0;

// Replace the original content uri to the subtree uri
const implicitUri = tile.implicitTiling.subtrees.uri
.replace( '{level}', tile.__level )
.replace( '{x}', tile.__x )
.replace( '{y}', tile.__y )
.replace( '{z}', tile.__z );

tile.content.uri = new URL( implicitUri, tile.__basePath + '/' ).toString();

} else if ( /.subtree$/i.test( tile.content?.uri ) ) {

// Handling content uri pointing to a subtree file
Expand All @@ -55,8 +43,7 @@ export class ImplicitTilingPlugin {

parseTile( buffer, parseTile, extension ) {

//todo use extension instead ?
if ( /.subtree$/i.test( parseTile.content.uri ) ) {
if ( /^subtree$/i.test( extension ) ) {

const loader = new SUBTREELoader( parseTile );
loader.parse( buffer );
Expand All @@ -66,6 +53,24 @@ export class ImplicitTilingPlugin {

}

preprocessURL( url, tile ) {

if ( tile && tile.implicitTiling ) {

const implicitUri = tile.implicitTiling.subtrees.uri
.replace( '{level}', tile.__level )
.replace( '{x}', tile.__x )
.replace( '{y}', tile.__y )
.replace( '{z}', tile.__z );

return new URL( implicitUri, tile.__basePath + '/' ).toString();

}

return url;

}

disposeTile( tile ) {

if ( /.subtree$/i.test( tile.content?.uri ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/three/plugins/SUBTREELoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export class SUBTREELoader extends LoaderBase {
if ( subtree && this.getBit( subtree._contentAvailabilityBitstreams[ i ], 0 ) ) {

// Create a child holding the content uri, this child is similar to its parent and doesn't have any children
contentTile.content = { uri: this.parseImplicitURI( subtreeRoot, this.rootTile.__contentUri ) };
contentTile.content = { uri: this.parseImplicitURI( subtreeRoot, this.rootTile.content.uri ) };
break;

}
Expand Down Expand Up @@ -615,7 +615,7 @@ export class SUBTREELoader extends LoaderBase {

if ( subtree && this.getBit( subtree._contentAvailabilityBitstreams[ i ], childBitIndex ) ) {

subtreeTile.content = { uri: this.parseImplicitURI( subtreeTile, this.rootTile.__contentUri ) };
subtreeTile.content = { uri: this.parseImplicitURI( subtreeTile, this.rootTile.content.uri ) };
break;

}
Expand Down

0 comments on commit ac952bc

Please sign in to comment.