diff --git a/src/core/plugins/CesiumIonAuthPlugin.d.ts b/src/core/plugins/CesiumIonAuthPlugin.d.ts new file mode 100644 index 000000000..adaeb0e54 --- /dev/null +++ b/src/core/plugins/CesiumIonAuthPlugin.d.ts @@ -0,0 +1,12 @@ +import { TilesRendererBase } from '3d-tiles-renderer/core'; + +export class CesiumIonAuthPlugin { + + constructor( options : { + apiToken: string, + assetId?: string | null, + autoRefreshToken?: boolean, + assetTypeHandler?: ( type: string, tiles: TilesRendererBase, asset: object ) => void, + } ); + +} diff --git a/src/core/plugins/CesiumIonAuthPlugin.js b/src/core/plugins/CesiumIonAuthPlugin.js new file mode 100644 index 000000000..d427d9493 --- /dev/null +++ b/src/core/plugins/CesiumIonAuthPlugin.js @@ -0,0 +1,193 @@ +import { CesiumIonAuth } from './auth/CesiumIonAuth.js'; +import { GoogleCloudAuthPlugin } from './GoogleCloudAuthPlugin.js'; + +export class CesiumIonAuthPlugin { + + get apiToken() { + + return this.auth.apiToken; + + } + + set apiToken( v ) { + + this.auth.apiToken = v; + + } + + get autoRefreshToken() { + + return this.auth.autoRefreshToken; + + } + + set autoRefreshToken( v ) { + + this.auth.autoRefreshToken = v; + + } + + constructor( options = {} ) { + + const { + apiToken, + assetId = null, + autoRefreshToken = false, + useRecommendedSettings = true, + assetTypeHandler = ( type, tiles, asset ) => { + + console.warn( `CesiumIonAuthPlugin: Cesium Ion asset type "${ type }" unhandled.` ); + + }, + } = options; + + this.name = 'CESIUM_ION_AUTH_PLUGIN'; + this.auth = new CesiumIonAuth( { apiToken, autoRefreshToken } ); + + this.assetId = assetId; + this.autoRefreshToken = autoRefreshToken; + this.useRecommendedSettings = useRecommendedSettings; + this.assetTypeHandler = assetTypeHandler; + this.tiles = null; + + this._tileSetVersion = - 1; + this._attributions = []; + + } + + init( tiles ) { + + if ( this.assetId !== null ) { + + tiles.rootURL = `https://api.cesium.com/v1/assets/${ this.assetId }/endpoint`; + + } + + this.tiles = tiles; + this.auth.authURL = tiles.rootURL; + + // reset the tiles in case this plugin was removed and re-added + tiles.resetFailedTiles(); + + } + + loadRootTileSet() { + + // ensure we have an up-to-date token and root url, then trigger the internal + // root tile set load function + return this + .auth + .refreshToken() + .then( json => { + + this._initializeFromAsset( json ); + return this.tiles.invokeOnePlugin( plugin => plugin !== this && plugin.loadRootTileSet && plugin.loadRootTileSet() ); + + } ) + .catch( error => { + + this.tiles.dispatchEvent( { + type: 'load-error', + tile: null, + error, + url: this.auth.authURL, + } ); + + } ); + + } + + preprocessURL( uri ) { + + uri = new URL( uri ); + if ( /^http/.test( uri.protocol ) && this._tileSetVersion != - 1 ) { + + uri.searchParams.set( 'v', this._tileSetVersion ); + + } + return uri.toString(); + + } + + fetchData( uri, options ) { + + const tiles = this.tiles; + if ( tiles.getPluginByName( 'GOOGLE_CLOUD_AUTH_PLUGIN' ) !== null ) { + + return null; + + } else { + + return this.auth.fetch( uri, options ); + + } + + } + + getAttributions( target ) { + + if ( this.tiles.visibleTiles.size > 0 ) { + + target.push( ...this._attributions ); + + } + + } + + _initializeFromAsset( json ) { + + const tiles = this.tiles; + if ( 'externalType' in json ) { + + const url = new URL( json.options.url ); + tiles.rootURL = json.options.url; + + // if the tile set is "external" then assume it's a google API tile set + tiles.registerPlugin( new GoogleCloudAuthPlugin( { + apiToken: url.searchParams.get( 'key' ), + autoRefreshToken: this.autoRefreshToken, + useRecommendedSettings: this.useRecommendedSettings, + } ) ); + + } else { + + // fire callback for unhandled asset types + if ( json.type !== '3DTILES' ) { + + // Other types include: + // - GLTF + // - CZML + // - KML + // - GEOJSON + // - TERRAIN (QuantizedMesh) + // - IMAGERY (TSM Tiles) + + this.assetTypeHandler( json.type, tiles, json ); + + } + + tiles.rootURL = json.url; + + // save the version key if present + const url = new URL( json.url ); + if ( url.searchParams.has( 'v' ) && this._tileSetVersion === - 1 ) { + + this._tileSetVersion = url.searchParams.get( 'v' ); + + } + + if ( json.attributions ) { + + this._attributions = json.attributions.map( att => ( { + value: att.html, + type: 'html', + collapsible: att.collapsible, + } ) ); + + } + + } + + } + +} diff --git a/src/three/plugins/GoogleAttributionsManager.js b/src/core/plugins/GoogleAttributionsManager.js similarity index 100% rename from src/three/plugins/GoogleAttributionsManager.js rename to src/core/plugins/GoogleAttributionsManager.js diff --git a/src/core/plugins/GoogleCloudAuthPlugin.d.ts b/src/core/plugins/GoogleCloudAuthPlugin.d.ts new file mode 100644 index 000000000..803f8bb4a --- /dev/null +++ b/src/core/plugins/GoogleCloudAuthPlugin.d.ts @@ -0,0 +1,11 @@ +export class GoogleCloudAuthPlugin { + + constructor( options: { + apiToken: string, + autoRefreshToken?: boolean, + logoUrl?: string, + useRecommendedSettings?: boolean; + sessionOptions?: null | { mapType: string, language: string, region: string, [key: string]: any }, + } ); + +} diff --git a/src/core/plugins/GoogleCloudAuthPlugin.js b/src/core/plugins/GoogleCloudAuthPlugin.js new file mode 100644 index 000000000..4feba5213 --- /dev/null +++ b/src/core/plugins/GoogleCloudAuthPlugin.js @@ -0,0 +1,117 @@ +import { GoogleCloudAuth } from '3d-tiles-renderer/core/plugins'; +import { GoogleAttributionsManager } from './GoogleAttributionsManager.js'; + +const TILES_3D_API = 'https://tile.googleapis.com/v1/3dtiles/root.json'; + +export class GoogleCloudAuthPlugin { + + constructor( { + apiToken, + sessionOptions = null, + autoRefreshToken = false, + logoUrl = null, + useRecommendedSettings = true, + } ) { + + this.name = 'GOOGLE_CLOUD_AUTH_PLUGIN'; + + this.apiToken = apiToken; + this.useRecommendedSettings = useRecommendedSettings; + this.logoUrl = logoUrl; + + this.auth = new GoogleCloudAuth( { apiToken, autoRefreshToken, sessionOptions } ); + this.tiles = null; + + this._visibilityChangeCallback = null; + this._attributionsManager = new GoogleAttributionsManager(); + this._logoAttribution = { + value: '', + type: 'image', + collapsible: false, + }; + this._attribution = { + value: '', + type: 'string', + collapsible: true, + }; + + } + + init( tiles ) { + + const { useRecommendedSettings, auth } = this; + + // reset the tiles in case this plugin was removed and re-added + tiles.resetFailedTiles(); + + if ( tiles.rootURL == null ) { + + tiles.rootURL = TILES_3D_API; + + } + + if ( ! auth.sessionOptions ) { + + auth.authURL = tiles.rootURL; + + } + + if ( useRecommendedSettings && ! auth.isMapTilesSession ) { + + // This plugin changes below values to be more efficient for the photorealistic tiles + tiles.errorTarget = 20; + + } + + this.tiles = tiles; + + this._visibilityChangeCallback = ( { tile, visible } ) => { + + const copyright = tile.cached.metadata?.asset?.copyright || ''; + if ( visible ) { + + this._attributionsManager.addAttributions( copyright ); + + } else { + + this._attributionsManager.removeAttributions( copyright ); + + } + + }; + + tiles.addEventListener( 'tile-visibility-change', this._visibilityChangeCallback ); + + } + + getAttributions( target ) { + + if ( this.tiles.visibleTiles.size > 0 ) { + + if ( this.logoUrl ) { + + this._logoAttribution.value = this.logoUrl; + target.push( this._logoAttribution ); + + } + + this._attribution.value = this._attributionsManager.toString(); + target.push( this._attribution ); + + } + + } + + dispose() { + + this.tiles.removeEventListener( 'tile-visibility-change', this._visibilityChangeCallback ); + + } + + async fetchData( uri, options ) { + + return this.auth.fetch( uri, options ); + + } + +} diff --git a/src/core/plugins/index.d.ts b/src/core/plugins/index.d.ts index 90534f5ff..84c01d3f2 100644 --- a/src/core/plugins/index.d.ts +++ b/src/core/plugins/index.d.ts @@ -1,2 +1,4 @@ +export * from './CesiumIonAuthPlugin.js'; +export * from './GoogleCloudAuthPlugin.js'; export * from './ImplicitTilingPlugin.js'; export * from './EnforceNonZeroErrorPlugin.js'; diff --git a/src/core/plugins/index.js b/src/core/plugins/index.js index ab84f246a..736bb7f49 100644 --- a/src/core/plugins/index.js +++ b/src/core/plugins/index.js @@ -1,3 +1,5 @@ +export * from './CesiumIonAuthPlugin.js'; +export * from './GoogleCloudAuthPlugin.js'; export * from './ImplicitTilingPlugin.js'; export * from './EnforceNonZeroErrorPlugin.js'; export * from './auth/GoogleCloudAuth.js'; diff --git a/src/core/renderer/tiles/TilesRendererBase.js b/src/core/renderer/tiles/TilesRendererBase.js index 67623ffd3..e9dae5920 100644 --- a/src/core/renderer/tiles/TilesRendererBase.js +++ b/src/core/renderer/tiles/TilesRendererBase.js @@ -250,46 +250,69 @@ export class TilesRendererBase { } - traverse( beforecb, aftercb, ensureFullyProcessed = true ) { - - if ( ! this.root ) return; + invokeOnePlugin( func ) { - traverseSet( this.root, ( tile, ...args ) => { + const plugins = [ ...this.plugins, this ]; + for ( let i = 0; i < plugins.length; i ++ ) { - if ( ensureFullyProcessed ) { + const result = func( plugins[ i ] ); + if ( result ) { - this.ensureChildrenArePreprocessed( tile, true ); + return result; } - return beforecb ? beforecb( tile, ...args ) : false; + } - }, aftercb ); + return null; } - queueTileForDownload( tile ) { + invokeAllPlugins( func ) { - if ( tile.__loadingState !== UNLOADED || this.lruCache.isFull() ) { + const plugins = [ ...this.plugins, this ]; + const pending = []; + for ( let i = 0; i < plugins.length; i ++ ) { - return; + const result = func( plugins[ i ] ); + if ( result ) { + + pending.push( result ); + + } } - this.queuedTiles.push( tile ); + return pending.length === 0 ? null : Promise.all( pending ); } - markTileUsed( tile ) { + // Public API + traverse( beforecb, aftercb, ensureFullyProcessed = true ) { - // save the tile in a separate "used set" so we can mark it as unused - // before the next tile set traversal - this.usedSet.add( tile ); - this.lruCache.markUsed( tile ); + if ( ! this.root ) return; + + traverseSet( this.root, ( tile, ...args ) => { + + if ( ensureFullyProcessed ) { + + this.ensureChildrenArePreprocessed( tile, true ); + + } + + return beforecb ? beforecb( tile, ...args ) : false; + + }, aftercb ); + + } + + getAttributions( target = [] ) { + + this.invokeAllPlugins( plugin => plugin !== this && plugin.getAttributions && plugin.getAttributions( target ) ); + return target; } - // Public API update() { const { lruCache, usedSet, stats, root, downloadQueue, parseQueue, processNodeQueue } = this; @@ -460,17 +483,11 @@ export class TilesRendererBase { } - dispatchEvent( e ) { - - // event to be overriden for dispatching via an event system + dispatchEvent( e ) {} - } + addEventListener( name, callback ) {} - fetchData( url, options ) { - - return fetch( url, options ); - - } + removeEventListener( name, callback ) {} parseTile( buffer, tile, extension ) { @@ -622,6 +639,34 @@ export class TilesRendererBase { } + // Private Functions + queueTileForDownload( tile ) { + + if ( tile.__loadingState !== UNLOADED || this.lruCache.isFull() ) { + + return; + + } + + this.queuedTiles.push( tile ); + + } + + markTileUsed( tile ) { + + // save the tile in a separate "used set" so we can mark it as unused + // before the next tile set traversal + this.usedSet.add( tile ); + this.lruCache.markUsed( tile ); + + } + + fetchData( url, options ) { + + return fetch( url, options ); + + } + ensureChildrenArePreprocessed( tile, immediate = false ) { const children = tile.children; @@ -659,7 +704,6 @@ export class TilesRendererBase { } - // Private Functions // returns the total bytes used for by the given tile as reported by all plugins getBytesUsed( tile ) { @@ -1030,48 +1074,4 @@ export class TilesRendererBase { } - getAttributions( target = [] ) { - - this.invokeAllPlugins( plugin => plugin !== this && plugin.getAttributions && plugin.getAttributions( target ) ); - return target; - - } - - invokeOnePlugin( func ) { - - const plugins = [ ...this.plugins, this ]; - for ( let i = 0; i < plugins.length; i ++ ) { - - const result = func( plugins[ i ] ); - if ( result ) { - - return result; - - } - - } - - return null; - - } - - invokeAllPlugins( func ) { - - const plugins = [ ...this.plugins, this ]; - const pending = []; - for ( let i = 0; i < plugins.length; i ++ ) { - - const result = func( plugins[ i ] ); - if ( result ) { - - pending.push( result ); - - } - - } - - return pending.length === 0 ? null : Promise.all( pending ); - - } - } diff --git a/src/plugins.js b/src/plugins.js index d702ec74f..2cc4c22ba 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -1,2 +1,20 @@ +// Export all core plugins export * from '3d-tiles-renderer/core/plugins'; + +// Export all three.js plugins export * from '3d-tiles-renderer/three/plugins'; + +// Override with backward compatible version (no constructor warning) +import { CesiumIonAuthPlugin as CesiumIonAuthPluginDeprecated } from '3d-tiles-renderer/three/plugins'; +export class CesiumIonAuthPlugin extends CesiumIonAuthPluginDeprecated { + + constructor( options ) { + + super( { + ...options, + __suppress_warning__: true, + } ); + + } + +} diff --git a/src/three/plugins/CesiumIonAuthPlugin.d.ts b/src/three/plugins/CesiumIonAuthPlugin.d.ts index 42669fa13..1ad5a77df 100644 --- a/src/three/plugins/CesiumIonAuthPlugin.d.ts +++ b/src/three/plugins/CesiumIonAuthPlugin.d.ts @@ -1,9 +1,2 @@ -export class CesiumIonAuthPlugin { +export { CesiumIonAuthPlugin } from '3d-tiles-renderer/core/plugins'; - constructor( options : { - apiToken: string, - assetId?: string | null, - autoRefreshToken?: boolean - } ); - -} diff --git a/src/three/plugins/CesiumIonAuthPlugin.js b/src/three/plugins/CesiumIonAuthPlugin.js index cd3bc7005..981d2347f 100644 --- a/src/three/plugins/CesiumIonAuthPlugin.js +++ b/src/three/plugins/CesiumIonAuthPlugin.js @@ -1,183 +1,50 @@ -import { CesiumIonAuth } from '3d-tiles-renderer/core/plugins'; -import { GoogleCloudAuthPlugin } from './GoogleCloudAuthPlugin.js'; +import { CesiumIonAuthPlugin as CesiumIonAuthPluginImpl } from '3d-tiles-renderer/core/plugins'; import { TMSTilesPlugin } from './images/EPSGTilesPlugin.js'; import { QuantizedMeshPlugin } from './QuantizedMeshPlugin.js'; -export class CesiumIonAuthPlugin { +export class CesiumIonAuthPlugin extends CesiumIonAuthPluginImpl { - get apiToken() { + constructor( options = {} ) { - return this.auth.apiToken; + super( { + assetTypeHandler: ( type, tiles, asset ) => { - } - - set apiToken( v ) { - - this.auth.apiToken = v; - - } - - get autoRefreshToken() { - - return this.auth.autoRefreshToken; - - } - - set autoRefreshToken( v ) { - - this.auth.autoRefreshToken = v; - - } - - constructor( { apiToken, assetId = null, autoRefreshToken = false, useRecommendedSettings = true } ) { - - this.name = 'CESIUM_ION_AUTH_PLUGIN'; - this.auth = new CesiumIonAuth( { apiToken, autoRefreshToken } ); - - this.assetId = assetId; - this.autoRefreshToken = autoRefreshToken; - this.useRecommendedSettings = useRecommendedSettings; - this.tiles = null; - - this._tileSetVersion = - 1; - this._attributions = []; - - } - - init( tiles ) { - - if ( this.assetId !== null ) { - - tiles.rootURL = `https://api.cesium.com/v1/assets/${ this.assetId }/endpoint`; - - } - - this.tiles = tiles; - this.auth.authURL = tiles.rootURL; - - // reset the tiles in case this plugin was removed and re-added - tiles.resetFailedTiles(); - - } - - loadRootTileSet() { - - // ensure we have an up-to-date token and root url, then trigger the internal - // root tile set load function - return this - .auth - .refreshToken() - .then( json => { - - this._initializeFromAsset( json ); - return this.tiles.invokeOnePlugin( plugin => plugin !== this && plugin.loadRootTileSet && plugin.loadRootTileSet() ); - - } ) - .catch( error => { - - this.tiles.dispatchEvent( { - type: 'load-error', - tile: null, - error, - url: this.auth.authURL, - } ); - - } ); - - } - - preprocessURL( uri ) { - - uri = new URL( uri ); - if ( /^http/.test( uri.protocol ) && this._tileSetVersion != - 1 ) { - - uri.searchParams.set( 'v', this._tileSetVersion ); - - } - return uri.toString(); - - } - - fetchData( uri, options ) { - - const tiles = this.tiles; - if ( tiles.getPluginByName( 'GOOGLE_CLOUD_AUTH_PLUGIN' ) !== null ) { - - return null; - - } else { - - return this.auth.fetch( uri, options ); - - } - - } - - getAttributions( target ) { - - if ( this.tiles.visibleTiles.size > 0 ) { - - target.push( ...this._attributions ); - - } - - } - - _initializeFromAsset( json ) { - - const tiles = this.tiles; - if ( 'externalType' in json ) { - - const url = new URL( json.options.url ); - tiles.rootURL = json.options.url; - - // if the tile set is "external" then assume it's a google API tile set - tiles.registerPlugin( new GoogleCloudAuthPlugin( { - apiToken: url.searchParams.get( 'key' ), - autoRefreshToken: this.autoRefreshToken, - useRecommendedSettings: this.useRecommendedSettings, - } ) ); - - } else { - - // GLTF - // CZML - // KML - // GEOJSON - if ( json.type === 'TERRAIN' && tiles.getPluginByName( 'QUANTIZED_MESH_PLUGIN' ) === null ) { - - tiles.registerPlugin( new QuantizedMeshPlugin( { - useRecommendedSettings: this.useRecommendedSettings, - } ) ); - - } else if ( json.type === 'IMAGERY' && tiles.getPluginByName( 'TMS_TILES_PLUGIN' ) === null ) { + if ( type === 'TERRAIN' && tiles.getPluginByName( 'QUANTIZED_MESH_PLUGIN' ) === null ) { - tiles.registerPlugin( new TMSTilesPlugin( { - useRecommendedSettings: this.useRecommendedSettings, - shape: 'ellipsoid', - } ) ); + console.warn( + 'CesiumIonAuthPlugin: CesiumIonAuthPlugin plugin auto-registration has been deprecated. ' + + 'Please implement a custom "assetTypeHandler" for "TERRAIN" using "QuantizedMeshPlugin", instead.' + ); + tiles.registerPlugin( new QuantizedMeshPlugin( { + useRecommendedSettings: this.useRecommendedSettings, + } ) ); - } + } else if ( type === 'IMAGERY' && tiles.getPluginByName( 'TMS_TILES_PLUGIN' ) === null ) { - tiles.rootURL = json.url; + console.warn( + 'CesiumIonAuthPlugin: CesiumIonAuthPlugin plugin auto-registration has been deprecated. ' + + 'Please implement a custom "assetTypeHandler" for "IMAGERY" using "TMSTilesPlugin", instead.' + ); + tiles.registerPlugin( new TMSTilesPlugin( { + useRecommendedSettings: this.useRecommendedSettings, + shape: 'ellipsoid', + } ) ); - // save the version key if present - const url = new URL( json.url ); - if ( url.searchParams.has( 'v' ) && this._tileSetVersion === - 1 ) { + } else { - this._tileSetVersion = url.searchParams.get( 'v' ); + console.warn( `CesiumIonAuthPlugin: Cesium Ion asset type "${ type }" unhandled.` ); - } + } - if ( json.attributions ) { + }, + ...options, + } ); - this._attributions = json.attributions.map( att => ( { - value: att.html, - type: 'html', - collapsible: att.collapsible, - } ) ); + if ( options.__suppress_warning__ ) { - } + console.warn( + 'CesiumIonAuthPlugin: Plugin has been moved to "3d-tiles-renderer/core/plugins".' + ); } diff --git a/src/three/plugins/GoogleCloudAuthPlugin.d.ts b/src/three/plugins/GoogleCloudAuthPlugin.d.ts index 803f8bb4a..bed79ce34 100644 --- a/src/three/plugins/GoogleCloudAuthPlugin.d.ts +++ b/src/three/plugins/GoogleCloudAuthPlugin.d.ts @@ -1,11 +1 @@ -export class GoogleCloudAuthPlugin { - - constructor( options: { - apiToken: string, - autoRefreshToken?: boolean, - logoUrl?: string, - useRecommendedSettings?: boolean; - sessionOptions?: null | { mapType: string, language: string, region: string, [key: string]: any }, - } ); - -} +export { GoogleCloudAuthPlugin } from '3d-tiles-renderer/core/plugins'; diff --git a/src/three/plugins/GoogleCloudAuthPlugin.js b/src/three/plugins/GoogleCloudAuthPlugin.js index 4feba5213..15496d36b 100644 --- a/src/three/plugins/GoogleCloudAuthPlugin.js +++ b/src/three/plugins/GoogleCloudAuthPlugin.js @@ -1,116 +1,11 @@ -import { GoogleCloudAuth } from '3d-tiles-renderer/core/plugins'; -import { GoogleAttributionsManager } from './GoogleAttributionsManager.js'; +import { GoogleCloudAuthPlugin as GoogleCloudAuthPluginImpl } from '3d-tiles-renderer/core/plugins'; -const TILES_3D_API = 'https://tile.googleapis.com/v1/3dtiles/root.json'; +export class GoogleCloudAuthPlugin extends GoogleCloudAuthPluginImpl { -export class GoogleCloudAuthPlugin { + constructor( ...args ) { - constructor( { - apiToken, - sessionOptions = null, - autoRefreshToken = false, - logoUrl = null, - useRecommendedSettings = true, - } ) { - - this.name = 'GOOGLE_CLOUD_AUTH_PLUGIN'; - - this.apiToken = apiToken; - this.useRecommendedSettings = useRecommendedSettings; - this.logoUrl = logoUrl; - - this.auth = new GoogleCloudAuth( { apiToken, autoRefreshToken, sessionOptions } ); - this.tiles = null; - - this._visibilityChangeCallback = null; - this._attributionsManager = new GoogleAttributionsManager(); - this._logoAttribution = { - value: '', - type: 'image', - collapsible: false, - }; - this._attribution = { - value: '', - type: 'string', - collapsible: true, - }; - - } - - init( tiles ) { - - const { useRecommendedSettings, auth } = this; - - // reset the tiles in case this plugin was removed and re-added - tiles.resetFailedTiles(); - - if ( tiles.rootURL == null ) { - - tiles.rootURL = TILES_3D_API; - - } - - if ( ! auth.sessionOptions ) { - - auth.authURL = tiles.rootURL; - - } - - if ( useRecommendedSettings && ! auth.isMapTilesSession ) { - - // This plugin changes below values to be more efficient for the photorealistic tiles - tiles.errorTarget = 20; - - } - - this.tiles = tiles; - - this._visibilityChangeCallback = ( { tile, visible } ) => { - - const copyright = tile.cached.metadata?.asset?.copyright || ''; - if ( visible ) { - - this._attributionsManager.addAttributions( copyright ); - - } else { - - this._attributionsManager.removeAttributions( copyright ); - - } - - }; - - tiles.addEventListener( 'tile-visibility-change', this._visibilityChangeCallback ); - - } - - getAttributions( target ) { - - if ( this.tiles.visibleTiles.size > 0 ) { - - if ( this.logoUrl ) { - - this._logoAttribution.value = this.logoUrl; - target.push( this._logoAttribution ); - - } - - this._attribution.value = this._attributionsManager.toString(); - target.push( this._attribution ); - - } - - } - - dispose() { - - this.tiles.removeEventListener( 'tile-visibility-change', this._visibilityChangeCallback ); - - } - - async fetchData( uri, options ) { - - return this.auth.fetch( uri, options ); + super( ...args ); + console.warn( 'GoogleCloudAuthPlugin: Plugin has been moved to "3d-tiles-renderer/core/plugins".' ); } diff --git a/src/three/plugins/README.md b/src/three/plugins/README.md index d36f72870..cee4fed93 100644 --- a/src/three/plugins/README.md +++ b/src/three/plugins/README.md @@ -369,11 +369,39 @@ tiles.errorTarget = 20; ### constructor ```js -constructor( { apiToken : String, assetId = null : String | null, autoRefreshToken = false : Boolean } ) +constructor( { + apiToken : String, + assetId = null : String | null, + autoRefreshToken = false : Boolean, + assetTypeHandler? : ( type: string, tiles: TilesRenderer, asset: Object ) => void, +} ) ``` Takes the CesiumIon access token and optionally the asset id. If the asset id is not provided then the Cesium Ion URL is expected to have been passed into the `TilesRenderer` constructor. If `autoRefreshToken` is set to true then the plugin will automatically perform a new root tile request once the existing token has expired after an hour. +### .assetTypeHandler + +```js +assetTypeHandler: ( type: string, tiles: TilesRenderer, asset: Object ) => void +``` + +Callback fired when an asset type other than 3DTiles is encountered. A warning is logged by default but a provided callback can add a plugin to add support for the loaded asset type. If "TERRAIN" is encountered then the handler can add "QuantizedMeshPlugin", for example. + +```js +tilesRenderer.registerPlugin( { + // ... + assetTypeHandler: ( type, tilesRenderer ) => { + + if ( type === '' ) { + + tilesRenderer.registerPlugin( new QuantizedMeshPlugin() ); + + } + + }, +} ); +``` + ## TextureOverlayPlugin _available in the examples directory_ diff --git a/src/three/plugins/index.d.ts b/src/three/plugins/index.d.ts index 8fa1773ee..efb4ce02c 100644 --- a/src/three/plugins/index.d.ts +++ b/src/three/plugins/index.d.ts @@ -1,15 +1,15 @@ // three.js plugins -export { CesiumIonAuthPlugin } from './CesiumIonAuthPlugin.js'; -export { GoogleCloudAuthPlugin } from './GoogleCloudAuthPlugin.js'; -export { UpdateOnChangePlugin } from './UpdateOnChangePlugin.js'; -export { TileCompressionPlugin } from './TileCompressionPlugin.js'; -export { GLTFExtensionsPlugin } from './GLTFExtensionsPlugin.js'; -export { ReorientationPlugin } from './ReorientationPlugin.js'; -export { UnloadTilesPlugin } from './UnloadTilesPlugin.js'; -export { TilesFadePlugin } from './fade/TilesFadePlugin.js'; -export { BatchedTilesPlugin } from './batched/BatchedTilesPlugin.js'; -export { TileFlatteningPlugin } from './TileFlatteningPlugin.js'; -export { QuantizedMeshPlugin } from './QuantizedMeshPlugin.js'; +export * from './CesiumIonAuthPlugin.js'; +export * from '../../core/plugins/GoogleCloudAuthPlugin.js'; +export * from './UpdateOnChangePlugin.js'; +export * from './TileCompressionPlugin.js'; +export * from './GLTFExtensionsPlugin.js'; +export * from './ReorientationPlugin.js'; +export * from './UnloadTilesPlugin.js'; +export * from './fade/TilesFadePlugin.js'; +export * from './batched/BatchedTilesPlugin.js'; +export * from './TileFlatteningPlugin.js'; +export * from './QuantizedMeshPlugin.js'; export * from './images/ImageOverlayPlugin.js'; export * from './LoadRegionPlugin.js'; export * from './DebugTilesPlugin.js'; @@ -19,9 +19,9 @@ export * from './images/DeepZoomImagePlugin.js'; export * from './images/EPSGTilesPlugin.js'; // gltf extensions -export { GLTFCesiumRTCExtension } from './gltf/GLTFCesiumRTCExtension.js'; -export { GLTFStructuralMetadataExtension } from './gltf/GLTFStructuralMetadataExtension.js'; -export { GLTFMeshFeaturesExtension } from './gltf/GLTFMeshFeaturesExtension.js'; +export * from './gltf/GLTFCesiumRTCExtension.js'; +export * from './gltf/GLTFStructuralMetadataExtension.js'; +export * from './gltf/GLTFMeshFeaturesExtension.js'; // loaders export * from './loaders/WMTSCapabilitiesLoader.js'; diff --git a/src/three/plugins/index.js b/src/three/plugins/index.js index 8fa1773ee..329725c6f 100644 --- a/src/three/plugins/index.js +++ b/src/three/plugins/index.js @@ -1,15 +1,14 @@ // three.js plugins -export { CesiumIonAuthPlugin } from './CesiumIonAuthPlugin.js'; -export { GoogleCloudAuthPlugin } from './GoogleCloudAuthPlugin.js'; -export { UpdateOnChangePlugin } from './UpdateOnChangePlugin.js'; -export { TileCompressionPlugin } from './TileCompressionPlugin.js'; -export { GLTFExtensionsPlugin } from './GLTFExtensionsPlugin.js'; -export { ReorientationPlugin } from './ReorientationPlugin.js'; -export { UnloadTilesPlugin } from './UnloadTilesPlugin.js'; -export { TilesFadePlugin } from './fade/TilesFadePlugin.js'; -export { BatchedTilesPlugin } from './batched/BatchedTilesPlugin.js'; -export { TileFlatteningPlugin } from './TileFlatteningPlugin.js'; -export { QuantizedMeshPlugin } from './QuantizedMeshPlugin.js'; +export * from './CesiumIonAuthPlugin.js'; +export * from './UpdateOnChangePlugin.js'; +export * from './TileCompressionPlugin.js'; +export * from './GLTFExtensionsPlugin.js'; +export * from './ReorientationPlugin.js'; +export * from './UnloadTilesPlugin.js'; +export * from './fade/TilesFadePlugin.js'; +export * from './batched/BatchedTilesPlugin.js'; +export * from './TileFlatteningPlugin.js'; +export * from './QuantizedMeshPlugin.js'; export * from './images/ImageOverlayPlugin.js'; export * from './LoadRegionPlugin.js'; export * from './DebugTilesPlugin.js'; @@ -19,9 +18,9 @@ export * from './images/DeepZoomImagePlugin.js'; export * from './images/EPSGTilesPlugin.js'; // gltf extensions -export { GLTFCesiumRTCExtension } from './gltf/GLTFCesiumRTCExtension.js'; -export { GLTFStructuralMetadataExtension } from './gltf/GLTFStructuralMetadataExtension.js'; -export { GLTFMeshFeaturesExtension } from './gltf/GLTFMeshFeaturesExtension.js'; +export * from './gltf/GLTFCesiumRTCExtension.js'; +export * from './gltf/GLTFStructuralMetadataExtension.js'; +export * from './gltf/GLTFMeshFeaturesExtension.js'; // loaders export * from './loaders/WMTSCapabilitiesLoader.js';