Skip to content

Commit eaf53cf

Browse files
authored
Reconsider error calculations for ImageFormatPlugin (#1410)
1 parent 1c05895 commit eaf53cf

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/three/plugins/images/ImageFormatPlugin.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ export class ImageFormatPlugin {
255255

256256
}
257257

258-
259258
// return bounding box
260259
return {
261260
box: [
@@ -280,13 +279,16 @@ export class ImageFormatPlugin {
280279

281280
}
282281

283-
// the scale ration of the image at this level
284-
const { pixelWidth, pixelHeight } = tiling.getLevel( tiling.maxLevel );
285-
const { pixelWidth: levelWidth, pixelHeight: levelHeight } = tiling.getLevel( level );
286-
let geometricError = Math.max( 1 / levelWidth, 1 / levelHeight );
282+
// Calculate geometric error: size of one pixel in world space.
283+
// The tile contents span [0, 1] along Y and [0, aspectRatio] along X.
284+
const { pixelWidth, pixelHeight } = tiling.getLevel( level );
285+
let geometricError = Math.max( tiling.aspectRatio / pixelWidth, 1 / pixelHeight );
286+
287+
// apply deprecated pixelSize scaling if specified
287288
if ( pixelSize ) {
288289

289-
geometricError *= pixelSize * Math.max( pixelWidth, pixelHeight );
290+
const maxLevelInfo = tiling.getLevel( tiling.maxLevel );
291+
geometricError *= pixelSize * Math.max( maxLevelInfo.pixelWidth, maxLevelInfo.pixelHeight );
290292

291293
}
292294

0 commit comments

Comments
 (0)