From 74658baf3d2085139787652c8bddc36365b55e70 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Sun, 13 Dec 2020 20:56:37 -0800 Subject: [PATCH 1/2] KTX2Loader: Fix calculation of level dimensions for NPOT textures. --- examples/jsm/loaders/KTX2Loader.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/jsm/loaders/KTX2Loader.js b/examples/jsm/loaders/KTX2Loader.js index 8c8659c527a78d..f743cd400e54fb 100644 --- a/examples/jsm/loaders/KTX2Loader.js +++ b/examples/jsm/loaders/KTX2Loader.js @@ -524,8 +524,8 @@ class KTX2Container { for ( var level = 0; level < this.header.levelCount; level ++ ) { - var levelWidth = Math.ceil( width / Math.pow( 2, level ) ); - var levelHeight = Math.ceil( height / Math.pow( 2, level ) ); + var levelWidth = Math.floor( width / ( 1 << level ) ) || 1; + var levelHeight = Math.floor( height / ( 1 << level ) ) || 1; var numImagesInLevel = 1; // TODO(donmccurdy): Support cubemaps, arrays and 3D. var imageOffsetInLevel = 0; From c21e5a97335a482027c81e9e703f94e1d173eb33 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Fri, 8 Jan 2021 17:01:47 -0800 Subject: [PATCH 2/2] KTX2Loader: Improve readability of level size calculation. --- examples/jsm/loaders/KTX2Loader.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/jsm/loaders/KTX2Loader.js b/examples/jsm/loaders/KTX2Loader.js index f743cd400e54fb..1e0cd3650147e3 100644 --- a/examples/jsm/loaders/KTX2Loader.js +++ b/examples/jsm/loaders/KTX2Loader.js @@ -524,8 +524,8 @@ class KTX2Container { for ( var level = 0; level < this.header.levelCount; level ++ ) { - var levelWidth = Math.floor( width / ( 1 << level ) ) || 1; - var levelHeight = Math.floor( height / ( 1 << level ) ) || 1; + var levelWidth = Math.max( 1, Math.floor( width / Math.pow( 2, level ) ) ); + var levelHeight = Math.max( 1, Math.floor( height / Math.pow( 2, level ) ) ); var numImagesInLevel = 1; // TODO(donmccurdy): Support cubemaps, arrays and 3D. var imageOffsetInLevel = 0;