From 43c467fe49aa2d5a249e0e1e3b0bbf445c26e0a8 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 24 Nov 2025 11:46:05 +0900 Subject: [PATCH 01/10] Add callback overrides --- src/core/renderer/tiles/TilesRendererBase.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/renderer/tiles/TilesRendererBase.js b/src/core/renderer/tiles/TilesRendererBase.js index 67623ffd3..56c92f163 100644 --- a/src/core/renderer/tiles/TilesRendererBase.js +++ b/src/core/renderer/tiles/TilesRendererBase.js @@ -466,6 +466,14 @@ export class TilesRendererBase { } + addEventListener( name, callback ) { + + } + + removeEventListener( name, callback ) { + + } + fetchData( url, options ) { return fetch( url, options ); From 6c6e3fa326939268a592684ae3021933b37c0e1c Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 24 Nov 2025 11:50:32 +0900 Subject: [PATCH 02/10] Move GooglePhotorealisticTiles Plugin to core plugins --- .../plugins/GoogleAttributionsManager.js | 0 .../plugins/GoogleCloudAuthPlugin.d.ts | 0 .../plugins/GoogleCloudAuthPlugin.js | 0 src/core/plugins/index.js | 1 + src/three/plugins/index.d.ts | 28 +++++++++---------- src/three/plugins/index.js | 27 +++++++++--------- 6 files changed, 28 insertions(+), 28 deletions(-) rename src/{three => core}/plugins/GoogleAttributionsManager.js (100%) rename src/{three => core}/plugins/GoogleCloudAuthPlugin.d.ts (100%) rename src/{three => core}/plugins/GoogleCloudAuthPlugin.js (100%) 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/three/plugins/GoogleCloudAuthPlugin.d.ts b/src/core/plugins/GoogleCloudAuthPlugin.d.ts similarity index 100% rename from src/three/plugins/GoogleCloudAuthPlugin.d.ts rename to src/core/plugins/GoogleCloudAuthPlugin.d.ts diff --git a/src/three/plugins/GoogleCloudAuthPlugin.js b/src/core/plugins/GoogleCloudAuthPlugin.js similarity index 100% rename from src/three/plugins/GoogleCloudAuthPlugin.js rename to src/core/plugins/GoogleCloudAuthPlugin.js diff --git a/src/core/plugins/index.js b/src/core/plugins/index.js index ab84f246a..16161cc46 100644 --- a/src/core/plugins/index.js +++ b/src/core/plugins/index.js @@ -1,3 +1,4 @@ +export * from './GoogleCloudAuthPlugin.js'; export * from './ImplicitTilingPlugin.js'; export * from './EnforceNonZeroErrorPlugin.js'; export * from './auth/GoogleCloudAuth.js'; 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'; From 129cc12bc7e6a5846f5512e97044142c13abedf3 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 24 Nov 2025 11:53:31 +0900 Subject: [PATCH 03/10] Add deprecation warning --- src/three/plugins/GoogleCloudAuthPlugin.d.ts | 1 + src/three/plugins/GoogleCloudAuthPlugin.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/three/plugins/GoogleCloudAuthPlugin.d.ts create mode 100644 src/three/plugins/GoogleCloudAuthPlugin.js diff --git a/src/three/plugins/GoogleCloudAuthPlugin.d.ts b/src/three/plugins/GoogleCloudAuthPlugin.d.ts new file mode 100644 index 000000000..bed79ce34 --- /dev/null +++ b/src/three/plugins/GoogleCloudAuthPlugin.d.ts @@ -0,0 +1 @@ +export { GoogleCloudAuthPlugin } from '3d-tiles-renderer/core/plugins'; diff --git a/src/three/plugins/GoogleCloudAuthPlugin.js b/src/three/plugins/GoogleCloudAuthPlugin.js new file mode 100644 index 000000000..15496d36b --- /dev/null +++ b/src/three/plugins/GoogleCloudAuthPlugin.js @@ -0,0 +1,12 @@ +import { GoogleCloudAuthPlugin as GoogleCloudAuthPluginImpl } from '3d-tiles-renderer/core/plugins'; + +export class GoogleCloudAuthPlugin extends GoogleCloudAuthPluginImpl { + + constructor( ...args ) { + + super( ...args ); + console.warn( 'GoogleCloudAuthPlugin: Plugin has been moved to "3d-tiles-renderer/core/plugins".' ); + + } + +} From 7284196ffc45ee737f22a18f464a78dd12584871 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 24 Nov 2025 12:07:57 +0900 Subject: [PATCH 04/10] Reorganization --- src/core/renderer/tiles/TilesRendererBase.js | 152 +++++++++---------- 1 file changed, 72 insertions(+), 80 deletions(-) diff --git a/src/core/renderer/tiles/TilesRendererBase.js b/src/core/renderer/tiles/TilesRendererBase.js index 56c92f163..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,25 +483,11 @@ export class TilesRendererBase { } - dispatchEvent( e ) { - - // event to be overriden for dispatching via an event system - - } - - addEventListener( name, callback ) { - - } - - removeEventListener( name, callback ) { + dispatchEvent( e ) {} - } + addEventListener( name, callback ) {} - fetchData( url, options ) { - - return fetch( url, options ); - - } + removeEventListener( name, callback ) {} parseTile( buffer, tile, extension ) { @@ -630,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; @@ -667,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 ) { @@ -1038,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 ); - - } - } From 98377a8c10e95b59fa91a6d74439f4b4eb8b4bbf Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 24 Nov 2025 12:41:50 +0900 Subject: [PATCH 05/10] Add handler for asset types --- src/three/plugins/CesiumIonAuthPlugin.js | 56 +++++++++++++++++------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/three/plugins/CesiumIonAuthPlugin.js b/src/three/plugins/CesiumIonAuthPlugin.js index cd3bc7005..7bd4bcabe 100644 --- a/src/three/plugins/CesiumIonAuthPlugin.js +++ b/src/three/plugins/CesiumIonAuthPlugin.js @@ -29,7 +29,36 @@ export class CesiumIonAuthPlugin { } - constructor( { apiToken, assetId = null, autoRefreshToken = false, useRecommendedSettings = true } ) { + constructor( options = {} ) { + + const { + apiToken, + assetId = null, + autoRefreshToken = false, + useRecommendedSettings = true, + assetTypeHandler = ( type, tiles, info ) => { + + if ( type === 'TERRAIN' && tiles.getPluginByName( 'QUANTIZED_MESH_PLUGIN' ) === null ) { + + tiles.registerPlugin( new QuantizedMeshPlugin( { + useRecommendedSettings: this.useRecommendedSettings, + } ) ); + + } else if ( type === 'IMAGERY' && tiles.getPluginByName( 'TMS_TILES_PLUGIN' ) === null ) { + + tiles.registerPlugin( new TMSTilesPlugin( { + useRecommendedSettings: this.useRecommendedSettings, + shape: 'ellipsoid', + } ) ); + + } else { + + console.warn( `CesiumIonAuth: Cesium Ion asset type "${ type }" unhandled.` ); + + } + + }, + } = options; this.name = 'CESIUM_ION_AUTH_PLUGIN'; this.auth = new CesiumIonAuth( { apiToken, autoRefreshToken } ); @@ -37,6 +66,7 @@ export class CesiumIonAuthPlugin { this.assetId = assetId; this.autoRefreshToken = autoRefreshToken; this.useRecommendedSettings = useRecommendedSettings; + this.assetTypeHandler = assetTypeHandler; this.tiles = null; this._tileSetVersion = - 1; @@ -140,22 +170,18 @@ export class CesiumIonAuthPlugin { } else { - // GLTF - // CZML - // KML - // GEOJSON - if ( json.type === 'TERRAIN' && tiles.getPluginByName( 'QUANTIZED_MESH_PLUGIN' ) === null ) { + // fire callback for unhandled asset types + if ( json.type !== '3DTILES' ) { - tiles.registerPlugin( new QuantizedMeshPlugin( { - useRecommendedSettings: this.useRecommendedSettings, - } ) ); - - } else if ( json.type === 'IMAGERY' && tiles.getPluginByName( 'TMS_TILES_PLUGIN' ) === null ) { + // Other types include: + // - GLTF + // - CZML + // - KML + // - GEOJSON + // - TERRAIN (QuantizedMesh) + // - IMAGERY (TSM Tiles) - tiles.registerPlugin( new TMSTilesPlugin( { - useRecommendedSettings: this.useRecommendedSettings, - shape: 'ellipsoid', - } ) ); + this.assetTypeHandler( json.type, tiles, json ); } From 8c9bc33765903c2a5d9686d6c15ce8a25a85b95d Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 24 Nov 2025 12:44:27 +0900 Subject: [PATCH 06/10] Types update --- src/three/plugins/CesiumIonAuthPlugin.d.ts | 5 ++++- src/three/plugins/CesiumIonAuthPlugin.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/three/plugins/CesiumIonAuthPlugin.d.ts b/src/three/plugins/CesiumIonAuthPlugin.d.ts index 42669fa13..adaeb0e54 100644 --- a/src/three/plugins/CesiumIonAuthPlugin.d.ts +++ b/src/three/plugins/CesiumIonAuthPlugin.d.ts @@ -1,9 +1,12 @@ +import { TilesRendererBase } from '3d-tiles-renderer/core'; + export class CesiumIonAuthPlugin { constructor( options : { apiToken: string, assetId?: string | null, - autoRefreshToken?: boolean + autoRefreshToken?: boolean, + assetTypeHandler?: ( type: string, tiles: TilesRendererBase, asset: object ) => void, } ); } diff --git a/src/three/plugins/CesiumIonAuthPlugin.js b/src/three/plugins/CesiumIonAuthPlugin.js index 7bd4bcabe..5c13d5bfb 100644 --- a/src/three/plugins/CesiumIonAuthPlugin.js +++ b/src/three/plugins/CesiumIonAuthPlugin.js @@ -36,7 +36,7 @@ export class CesiumIonAuthPlugin { assetId = null, autoRefreshToken = false, useRecommendedSettings = true, - assetTypeHandler = ( type, tiles, info ) => { + assetTypeHandler = ( type, tiles, asset ) => { if ( type === 'TERRAIN' && tiles.getPluginByName( 'QUANTIZED_MESH_PLUGIN' ) === null ) { From 57502040a4cc66e21e9e79f5b65d64c2cfcae77b Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 24 Nov 2025 12:58:17 +0900 Subject: [PATCH 07/10] Move CesiumIonAuthPlugin plugin to core --- src/core/plugins/CesiumIonAuthPlugin.d.ts | 12 ++ src/core/plugins/CesiumIonAuthPlugin.js | 193 ++++++++++++++++++++ src/core/plugins/index.d.ts | 2 + src/core/plugins/index.js | 1 + src/three/plugins/CesiumIonAuthPlugin.d.ts | 12 +- src/three/plugins/CesiumIonAuthPlugin.js | 199 ++------------------- 6 files changed, 227 insertions(+), 192 deletions(-) create mode 100644 src/core/plugins/CesiumIonAuthPlugin.d.ts create mode 100644 src/core/plugins/CesiumIonAuthPlugin.js 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/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 16161cc46..736bb7f49 100644 --- a/src/core/plugins/index.js +++ b/src/core/plugins/index.js @@ -1,3 +1,4 @@ +export * from './CesiumIonAuthPlugin.js'; export * from './GoogleCloudAuthPlugin.js'; export * from './ImplicitTilingPlugin.js'; export * from './EnforceNonZeroErrorPlugin.js'; diff --git a/src/three/plugins/CesiumIonAuthPlugin.d.ts b/src/three/plugins/CesiumIonAuthPlugin.d.ts index adaeb0e54..1ad5a77df 100644 --- a/src/three/plugins/CesiumIonAuthPlugin.d.ts +++ b/src/three/plugins/CesiumIonAuthPlugin.d.ts @@ -1,12 +1,2 @@ -import { TilesRendererBase } from '3d-tiles-renderer/core'; +export { CesiumIonAuthPlugin } from '3d-tiles-renderer/core/plugins'; -export class CesiumIonAuthPlugin { - - constructor( options : { - apiToken: string, - assetId?: string | null, - autoRefreshToken?: boolean, - assetTypeHandler?: ( type: string, tiles: TilesRendererBase, asset: object ) => void, - } ); - -} diff --git a/src/three/plugins/CesiumIonAuthPlugin.js b/src/three/plugins/CesiumIonAuthPlugin.js index 5c13d5bfb..9449d7ed2 100644 --- a/src/three/plugins/CesiumIonAuthPlugin.js +++ b/src/three/plugins/CesiumIonAuthPlugin.js @@ -1,51 +1,30 @@ -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 { - - 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; - - } +export class CesiumIonAuthPlugin extends CesiumIonAuthPluginImpl { constructor( options = {} ) { - const { - apiToken, - assetId = null, - autoRefreshToken = false, - useRecommendedSettings = true, - assetTypeHandler = ( type, tiles, asset ) => { + super( { + assetTypeHandler: ( type, tiles, asset ) => { if ( type === 'TERRAIN' && tiles.getPluginByName( 'QUANTIZED_MESH_PLUGIN' ) === null ) { + 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 ) { + 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', @@ -53,159 +32,17 @@ export class CesiumIonAuthPlugin { } else { - console.warn( `CesiumIonAuth: Cesium Ion asset type "${ type }" unhandled.` ); + 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, - } ) ); - - } + ...options, + } ); - } + console.warn( + 'CesiumIonAuthPlugin: Plugin has been moved to "3d-tiles-renderer/core/plugins".' + ); } From 17f09f62fb59593f9436b21800dfaafbb70be42d Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Mon, 24 Nov 2025 17:14:13 +0900 Subject: [PATCH 08/10] README update --- src/plugins.js | 11 ++++++++++- src/three/plugins/README.md | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/plugins.js b/src/plugins.js index d702ec74f..003c237b1 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -1,2 +1,11 @@ -export * from '3d-tiles-renderer/core/plugins'; +export { + // excluded to avoid conflicts. Remove once the deprecated three.js versions are removed + // CesiumIonAuthPlugin, + // GoogleCloudAuthPlugin, + ImplicitTilingPlugin, + EnforceNonZeroErrorPlugin, + GoogleCloudAuth, + CesiumIonAuth, + QuantizedMeshLoaderBase, +} from '3d-tiles-renderer/core/plugins'; export * from '3d-tiles-renderer/three/plugins'; diff --git a/src/three/plugins/README.md b/src/three/plugins/README.md index d36f72870..e70527e7a 100644 --- a/src/three/plugins/README.md +++ b/src/three/plugins/README.md @@ -369,11 +369,24 @@ 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. + ## TextureOverlayPlugin _available in the examples directory_ From 39fc677dff79b3ccc390d63cd050c3a25cf077fc Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 25 Nov 2025 12:10:09 +0900 Subject: [PATCH 09/10] Log only as necessary --- src/plugins.js | 29 ++++++++++++++++-------- src/three/plugins/CesiumIonAuthPlugin.js | 10 +++++--- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/plugins.js b/src/plugins.js index 003c237b1..2cc4c22ba 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -1,11 +1,20 @@ -export { - // excluded to avoid conflicts. Remove once the deprecated three.js versions are removed - // CesiumIonAuthPlugin, - // GoogleCloudAuthPlugin, - ImplicitTilingPlugin, - EnforceNonZeroErrorPlugin, - GoogleCloudAuth, - CesiumIonAuth, - QuantizedMeshLoaderBase, -} from '3d-tiles-renderer/core/plugins'; +// 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.js b/src/three/plugins/CesiumIonAuthPlugin.js index 9449d7ed2..981d2347f 100644 --- a/src/three/plugins/CesiumIonAuthPlugin.js +++ b/src/three/plugins/CesiumIonAuthPlugin.js @@ -40,9 +40,13 @@ export class CesiumIonAuthPlugin extends CesiumIonAuthPluginImpl { ...options, } ); - console.warn( - 'CesiumIonAuthPlugin: Plugin has been moved to "3d-tiles-renderer/core/plugins".' - ); + if ( options.__suppress_warning__ ) { + + console.warn( + 'CesiumIonAuthPlugin: Plugin has been moved to "3d-tiles-renderer/core/plugins".' + ); + + } } From 28335a6f24c5b385269a999281752b7462b59847 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Tue, 25 Nov 2025 12:11:51 +0900 Subject: [PATCH 10/10] README update --- src/three/plugins/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/three/plugins/README.md b/src/three/plugins/README.md index e70527e7a..cee4fed93 100644 --- a/src/three/plugins/README.md +++ b/src/three/plugins/README.md @@ -387,6 +387,21 @@ 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_