Skip to content

Commit 789954e

Browse files
authored
Unify overlay level calculation for planar and ellipsoid projections (#1543)
* Unify overlay level calculation for planar and ellipsoid projections * Update gitignore * Properly handle tilesets not defining all levels * Remove outdated comment
1 parent 95b3958 commit 789954e

2 files changed

Lines changed: 44 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ typings/
6666

6767
example/local-data
6868
example/dev-bundle
69+
example/bundle
6970
build
7071

7172
pnpm-lock.yaml

src/three/plugins/images/ImageOverlayPlugin.js

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export class ImageOverlayPlugin {
290290

291291
if ( range !== null ) {
292292

293-
overlay.releaseTexture( range, tile );
293+
overlay.releaseTexture( range );
294294

295295
}
296296

@@ -511,7 +511,7 @@ export class ImageOverlayPlugin {
511511
// if the tile has a render target associated with the overlay and the last level of detail
512512
// is not being displayed, yet, then we need to split
513513
const info = tileInfo.get( tile );
514-
if ( info && info.target && overlay.shouldSplit( info.range, tile ) ) {
514+
if ( info && info.target && overlay.shouldSplit( info.range ) ) {
515515

516516
// get the vector representing the projection direction
517517
if ( overlay.frame ) {
@@ -857,7 +857,7 @@ export class ImageOverlayPlugin {
857857
// release the ranges
858858
if ( range !== null ) {
859859

860-
overlay.releaseTexture( range, tile );
860+
overlay.releaseTexture( range );
861861

862862
}
863863

@@ -1012,7 +1012,7 @@ export class ImageOverlayPlugin {
10121012
range = overlay.projection.toNormalizedRange( range );
10131013

10141014
info.range = range;
1015-
overlay.lockTexture( range, tile );
1015+
overlay.lockTexture( range );
10161016

10171017
}
10181018

@@ -1104,14 +1104,14 @@ export class ImageOverlayPlugin {
11041104
if ( info.range === null ) {
11051105

11061106
info.range = range;
1107-
overlay.lockTexture( range, tile );
1107+
overlay.lockTexture( range );
11081108

11091109
}
11101110

11111111
// if the image projection is outside the 0, 1 uvw range or there are no textures to draw in
11121112
// the tiled image set the don't allocate a texture for it.
11131113
let target = null;
1114-
if ( heightInRange && overlay.hasContent( range, tile ) ) {
1114+
if ( heightInRange && overlay.hasContent( range ) ) {
11151115

11161116
target = await processQueue
11171117
.add( { tile, overlay }, async () => {
@@ -1124,7 +1124,7 @@ export class ImageOverlayPlugin {
11241124
}
11251125

11261126
// Get the texture from the overlay
1127-
const regionTarget = await overlay.getTexture( range, tile );
1127+
const regionTarget = await overlay.getTexture( range );
11281128

11291129
// check if the overlay has been disposed since starting this function
11301130
if ( controller.signal.aborted || tileController.signal.aborted ) {
@@ -1349,33 +1349,33 @@ class ImageOverlay {
13491349

13501350
}
13511351

1352-
hasContent( range, tile ) {
1352+
hasContent( range ) {
13531353

13541354
return false;
13551355

13561356
}
13571357

1358-
async getTexture( range, tile ) {
1358+
async getTexture( range ) {
13591359

13601360
return null;
13611361

13621362
}
13631363

1364-
async lockTexture( range, tile ) {
1364+
async lockTexture( range ) {
13651365

13661366
return null;
13671367

13681368
}
13691369

1370-
releaseTexture( range, tile ) {
1370+
releaseTexture( range ) {
13711371

13721372
}
13731373

13741374
setResolution( resolution ) {
13751375

13761376
}
13771377

1378-
shouldSplit( range, tile ) {
1378+
shouldSplit( range ) {
13791379

13801380
return false;
13811381

@@ -1450,64 +1450,62 @@ class TiledImageOverlay extends ImageOverlay {
14501450
}
14511451

14521452
// Texture acquisition API implementations
1453-
calculateLevel( range, tile ) {
1454-
1455-
if ( this.isPlanarProjection ) {
1453+
calculateLevel( range ) {
14561454

1457-
const [ minX, minY, maxX, maxY ] = range;
1458-
const w = maxX - minX;
1459-
const h = maxY - minY;
1455+
const [ minX, minY, maxX, maxY ] = range;
1456+
const w = maxX - minX;
1457+
const h = maxY - minY;
14601458

1461-
let level = 0;
1462-
const resolution = this.regionImageSource.resolution;
1463-
const maxLevel = this.tiling.maxLevel;
1464-
for ( ; level < maxLevel; level ++ ) {
1459+
let level = 0;
1460+
const resolution = this.regionImageSource.resolution;
1461+
const maxLevel = this.tiling.maxLevel;
1462+
for ( ; level < maxLevel; level ++ ) {
14651463

1466-
// the number of pixels per image on each axis
1467-
const wProj = resolution / w;
1468-
const hProj = resolution / h;
1464+
// the number of pixels per image on each axis
1465+
const wProj = resolution / w;
1466+
const hProj = resolution / h;
14691467

1470-
const { pixelWidth, pixelHeight } = this.tiling.getLevel( level );
1471-
if ( pixelWidth >= wProj || pixelHeight >= hProj ) {
1468+
const levelData = this.tiling.getLevel( level );
1469+
if ( levelData === null || levelData === undefined ) {
14721470

1473-
break;
1474-
1475-
}
1471+
continue;
14761472

14771473
}
14781474

1479-
// TODO: should this be one layer higher LoD?
1480-
return level;
1475+
const { pixelWidth, pixelHeight } = levelData;
1476+
if ( pixelWidth >= wProj || pixelHeight >= hProj ) {
14811477

1482-
} else {
1478+
break;
14831479

1484-
return tile.internal.depthFromRenderedParent - 1;
1480+
}
14851481

14861482
}
14871483

1484+
return level;
1485+
14881486
}
14891487

1490-
hasContent( range, tile ) {
1488+
hasContent( range ) {
14911489

1492-
return this.regionImageSource.hasContent( ...range, this.calculateLevel( range, tile ) );
1490+
return this.regionImageSource.hasContent( ...range, this.calculateLevel( range ) );
14931491

14941492
}
14951493

1496-
getTexture( range, tile ) {
1494+
getTexture( range ) {
14971495

1498-
return this.regionImageSource.get( ...range, this.calculateLevel( range, tile ) );
1496+
return this.regionImageSource.get( ...range, this.calculateLevel( range ) );
14991497

15001498
}
15011499

1502-
lockTexture( range, tile ) {
1500+
lockTexture( range ) {
15031501

1504-
return this.regionImageSource.lock( ...range, this.calculateLevel( range, tile ) );
1502+
return this.regionImageSource.lock( ...range, this.calculateLevel( range ) );
15051503

15061504
}
15071505

1508-
releaseTexture( range, tile ) {
1506+
releaseTexture( range ) {
15091507

1510-
this.regionImageSource.release( ...range, this.calculateLevel( range, tile ) );
1508+
this.regionImageSource.release( ...range, this.calculateLevel( range ) );
15111509

15121510
}
15131511

@@ -1517,10 +1515,10 @@ class TiledImageOverlay extends ImageOverlay {
15171515

15181516
}
15191517

1520-
shouldSplit( range, tile ) {
1518+
shouldSplit( range ) {
15211519

15221520
// if we haven't reached the max level yet then continue splitting
1523-
return this.tiling.maxLevel > this.calculateLevel( range, tile );
1521+
return this.tiling.maxLevel > this.calculateLevel( range );
15241522

15251523
}
15261524

@@ -1693,7 +1691,7 @@ export class GeoJSONOverlay extends ImageOverlay {
16931691

16941692
}
16951693

1696-
shouldSplit( range, tile ) {
1694+
shouldSplit( range ) {
16971695

16981696
// geojson can always split
16991697
return true;

0 commit comments

Comments
 (0)