Skip to content

Commit 31c65bb

Browse files
authored
TilesRenderer: Change "cached" to "engineData" (#1429)
* Move "cached" initialization in base class * Migrate "cached" to "engineData" * variable renames * Update variables * Add warning
1 parent 8e327ef commit 31c65bb

13 files changed

Lines changed: 107 additions & 96 deletions

src/core/plugins/GoogleCloudAuthPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class GoogleCloudAuthPlugin {
6767

6868
this._visibilityChangeCallback = ( { tile, visible } ) => {
6969

70-
const copyright = tile.cached.metadata?.asset?.copyright || '';
70+
const copyright = tile.engineData.metadata?.asset?.copyright || '';
7171
if ( visible ) {
7272

7373
this._attributionsManager.addAttributions( copyright );

src/core/renderer/tiles/TilesRendererBase.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,25 @@ export class TilesRendererBase {
726726

727727
tile.__lastFrameVisited = - 1;
728728

729+
// Initialize engineData data structure with engine-agnostic fields
730+
tile.engineData = {
731+
scene: null,
732+
metadata: null,
733+
boundingVolume: null,
734+
};
735+
736+
// Backwards compatibility: cached is an alias for engineData
737+
Object.defineProperty( tile, 'cached', {
738+
get() {
739+
740+
console.warn( 'TilesRenderer: "tile.cached" field has been renamed to "tile.engineData".' );
741+
return this.engineData;
742+
743+
},
744+
enumerable: false,
745+
configurable: true,
746+
} );
747+
729748
this.invokeAllPlugins( plugin => {
730749

731750
plugin !== this && plugin.preprocessNode && plugin.preprocessNode( tile, tilesetDir, parentTile );
@@ -858,7 +877,7 @@ export class TilesRendererBase {
858877

859878
if ( plugin.calculateBytesUsed ) {
860879

861-
bytes += plugin.calculateBytesUsed( tile, tile.cached.scene ) || 0;
880+
bytes += plugin.calculateBytesUsed( tile, tile.engineData.scene ) || 0;
862881

863882
}
864883

@@ -1209,11 +1228,11 @@ export class TilesRendererBase {
12091228

12101229
}
12111230

1212-
if ( tile.cached.scene ) {
1231+
if ( tile.engineData.scene ) {
12131232

12141233
this.dispatchEvent( {
12151234
type: 'load-model',
1216-
scene: tile.cached.scene,
1235+
scene: tile.engineData.scene,
12171236
tile,
12181237
url: uri,
12191238
} );

src/three/plugins/DebugTilesPlugin.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ export class DebugTilesPlugin {
288288
// initialize an already-loaded tiles
289289
tiles.traverse( tile => {
290290

291-
if ( tile.cached.scene ) {
291+
if ( tile.engineData.scene ) {
292292

293-
this._onLoadModel( tile.cached.scene, tile );
293+
this._onLoadModel( tile.engineData.scene, tile );
294294

295295
}
296296

@@ -318,7 +318,7 @@ export class DebugTilesPlugin {
318318

319319
}
320320

321-
const scene = tile.cached.scene;
321+
const scene = tile.engineData.scene;
322322
if ( scene ) {
323323

324324
scene.traverse( c => {
@@ -457,7 +457,7 @@ export class DebugTilesPlugin {
457457
// update plugins
458458
visibleTiles.forEach( tile => {
459459

460-
const scene = tile.cached.scene;
460+
const scene = tile.engineData.scene;
461461

462462
// create a random color per-tile
463463
let h, s, l;
@@ -662,8 +662,8 @@ export class DebugTilesPlugin {
662662
_createBoundHelper( tile ) {
663663

664664
const tiles = this.tiles;
665-
const cached = tile.cached;
666-
const { sphere, obb, region } = cached.boundingVolume;
665+
const engineData = tile.engineData;
666+
const { sphere, obb, region } = engineData.boundingVolume;
667667
if ( obb ) {
668668

669669
// Create debug bounding box
@@ -678,7 +678,7 @@ export class DebugTilesPlugin {
678678
boxHelper.raycast = emptyRaycast;
679679
boxHelperGroup.add( boxHelper );
680680

681-
cached.boxHelperGroup = boxHelperGroup;
681+
engineData.boxHelperGroup = boxHelperGroup;
682682

683683
if ( tiles.visibleTiles.has( tile ) && this.displayBoxBounds ) {
684684

@@ -694,7 +694,7 @@ export class DebugTilesPlugin {
694694
// Create debug bounding sphere
695695
const sphereHelper = new SphereHelper( sphere, getIndexedRandomColor( tile.__depth ) );
696696
sphereHelper.raycast = emptyRaycast;
697-
cached.sphereHelper = sphereHelper;
697+
engineData.sphereHelper = sphereHelper;
698698

699699
if ( tiles.visibleTiles.has( tile ) && this.displaySphereBounds ) {
700700

@@ -719,7 +719,7 @@ export class DebugTilesPlugin {
719719
sphere.center.multiplyScalar( - 1 );
720720
regionHelper.geometry.translate( ...sphere.center );
721721

722-
cached.regionHelper = regionHelper;
722+
engineData.regionHelper = regionHelper;
723723

724724
if ( tiles.visibleTiles.has( tile ) && this.displayRegionBounds ) {
725725

@@ -756,9 +756,9 @@ export class DebugTilesPlugin {
756756

757757
_updateBoundHelper( tile, visible ) {
758758

759-
const cached = tile.cached;
759+
const engineData = tile.engineData;
760760

761-
if ( ! cached ) {
761+
if ( ! engineData ) {
762762

763763
return;
764764

@@ -768,15 +768,15 @@ export class DebugTilesPlugin {
768768
const boxGroup = this.boxGroup;
769769
const regionGroup = this.regionGroup;
770770

771-
if ( visible && ( cached.boxHelperGroup == null && cached.sphereHelper == null && cached.regionHelper == null ) ) {
771+
if ( visible && ( engineData.boxHelperGroup == null && engineData.sphereHelper == null && engineData.regionHelper == null ) ) {
772772

773773
this._createBoundHelper( tile );
774774

775775
}
776776

777-
const boxHelperGroup = cached.boxHelperGroup;
778-
const sphereHelper = cached.sphereHelper;
779-
const regionHelper = cached.regionHelper;
777+
const boxHelperGroup = engineData.boxHelperGroup;
778+
const sphereHelper = engineData.sphereHelper;
779+
const regionHelper = engineData.regionHelper;
780780

781781
if ( ! visible ) {
782782

@@ -916,25 +916,25 @@ export class DebugTilesPlugin {
916916

917917
_onDisposeModel( tile ) {
918918

919-
const cached = tile.cached;
920-
if ( cached?.boxHelperGroup ) {
919+
const engineData = tile.engineData;
920+
if ( engineData?.boxHelperGroup ) {
921921

922-
cached.boxHelperGroup.children[ 0 ].geometry.dispose();
923-
delete cached.boxHelperGroup;
922+
engineData.boxHelperGroup.children[ 0 ].geometry.dispose();
923+
delete engineData.boxHelperGroup;
924924

925925
}
926926

927-
if ( cached?.sphereHelper ) {
927+
if ( engineData?.sphereHelper ) {
928928

929-
cached.sphereHelper.geometry.dispose();
930-
delete cached.sphereHelper;
929+
engineData.sphereHelper.geometry.dispose();
930+
delete engineData.sphereHelper;
931931

932932
}
933933

934-
if ( cached?.regionHelper ) {
934+
if ( engineData?.regionHelper ) {
935935

936-
cached.regionHelper.geometry.dispose();
937-
delete cached.regionHelper;
936+
engineData.regionHelper.geometry.dispose();
937+
delete engineData.regionHelper;
938938

939939
}
940940

src/three/plugins/LoadRegionPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class LoadRegionPlugin {
5454
// tiles are only loaded if they are within those shapes.
5555
calculateTileViewError( tile, target ) {
5656

57-
const boundingVolume = tile.cached.boundingVolume;
57+
const boundingVolume = tile.engineData.boundingVolume;
5858
const { regions, tiles } = this;
5959

6060
let inShape = false;

src/three/plugins/QuantizedMeshPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export class QuantizedMeshPlugin {
253253
clipper.minLon = west;
254254
clipper.maxLon = east;
255255

256-
result = clipper.clipToQuadrant( tile.parent.cached.scene, left, bottom );
256+
result = clipper.clipToQuadrant( tile.parent.engineData.scene, left, bottom );
257257

258258
} else if ( extension === 'terrain' ) {
259259

@@ -284,7 +284,7 @@ export class QuantizedMeshPlugin {
284284
const { minHeight, maxHeight, metadata } = result.userData;
285285
tile.boundingVolume.region[ 4 ] = minHeight;
286286
tile.boundingVolume.region[ 5 ] = maxHeight;
287-
tile.cached.boundingVolume.setRegionData( ellipsoid, ...tile.boundingVolume.region );
287+
tile.engineData.boundingVolume.setRegionData( ellipsoid, ...tile.boundingVolume.region );
288288

289289
// use the geometric error value if it's present
290290
if ( metadata ) {

src/three/plugins/TileFlatteningPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class TileFlatteningPlugin {
9494
const { positionsUpdated, positionsMap, shapes, tiles } = this;
9595
positionsUpdated.add( tile );
9696

97-
const scene = tile.cached.scene;
97+
const scene = tile.engineData.scene;
9898
if ( ! positionsMap.has( tile ) ) {
9999

100100
// save the geometry positions for resetting after

src/three/plugins/UnloadTilesPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class UnloadTilesPlugin {
6868

6969
const unloadCallback = tile => {
7070

71-
const scene = tile.cached.scene;
71+
const scene = tile.engineData.scene;
7272
const visible = tiles.visibleTiles.has( tile );
7373

7474
if ( ! visible ) {

src/three/plugins/batched/BatchedTilesPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class BatchedTilesPlugin {
145145

146146
setTileVisible( tile, visible ) {
147147

148-
const scene = tile.cached.scene;
148+
const scene = tile.engineData.scene;
149149
if ( visible ) {
150150

151151
// Add tileset to the batched mesh if it hasn't been added already
@@ -374,7 +374,7 @@ export class BatchedTilesPlugin {
374374
// TODO: this would be best done in a more general way
375375
if ( this.discardOriginalContent ) {
376376

377-
tile.cached.textures.forEach( tex => {
377+
tile.engineData.textures.forEach( tex => {
378378

379379
if ( tex.image instanceof ImageBitmap ) {
380380

@@ -384,10 +384,10 @@ export class BatchedTilesPlugin {
384384

385385
} );
386386

387-
tile.cached.scene = null;
388-
tile.cached.materials = [];
389-
tile.cached.geometries = [];
390-
tile.cached.textures = [];
387+
tile.engineData.scene = null;
388+
tile.engineData.materials = [];
389+
tile.engineData.geometries = [];
390+
tile.engineData.textures = [];
391391

392392
}
393393

src/three/plugins/fade/TilesFadePlugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function onUpdateAfter() {
5959

6060
// if a tile is fading out then it may not be traversed and thus will not have
6161
// the frustum flag set correctly.
62-
const scene = t.cached.scene;
62+
const scene = t.engineData.scene;
6363
if ( scene ) {
6464

6565
scene.visible = t.__inFrustum;
@@ -124,7 +124,7 @@ function onUpdateAfter() {
124124
fadeManager.forEachObject( ( tile, { fadeIn, fadeOut } ) => {
125125

126126
// prevent faded tiles from being unloaded
127-
const scene = tile.cached.scene;
127+
const scene = tile.engineData.scene;
128128
const isFadingOut = fadeManager.isFadingOut( tile );
129129
tiles.markTileUsed( tile );
130130
if ( scene ) {
@@ -252,7 +252,7 @@ export class TilesFadePlugin {
252252
// this function gets fired _after_ all set visible callbacks including the batched meshes
253253

254254
// revert the scene and fade to the initial state when toggling
255-
const scene = tile.cached.scene;
255+
const scene = tile.engineData.scene;
256256
if ( scene ) {
257257

258258
scene.visible = true;
@@ -308,7 +308,7 @@ export class TilesFadePlugin {
308308
fadeManager.onFadeComplete = ( tile, visible ) => {
309309

310310
// mark the fade as finished and reset the fade parameters
311-
this._fadeMaterialManager.setFade( tile.cached.scene, 0, 0 );
311+
this._fadeMaterialManager.setFade( tile.engineData.scene, 0, 0 );
312312

313313
this.forEachBatchIds( tile, ( id, batchedMesh, plugin ) => {
314314

src/three/plugins/images/EllipsoidProjectionTilesPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class EllipsoidProjectionTilesPlugin extends ImageFormatPlugin {
6363
// adjust the geometry to position it at the region
6464
const { position, normal, uv } = geometry.attributes;
6565
const vertCount = position.count;
66-
tile.cached.boundingVolume.getSphere( _sphere );
66+
tile.engineData.boundingVolume.getSphere( _sphere );
6767
for ( let i = 0; i < vertCount; i ++ ) {
6868

6969
// retrieve attributes

0 commit comments

Comments
 (0)