diff --git a/examples/jsm/loaders/KTX2Loader.js b/examples/jsm/loaders/KTX2Loader.js index 3a2c1ca3727631..b44d81b2d85ef4 100644 --- a/examples/jsm/loaders/KTX2Loader.js +++ b/examples/jsm/loaders/KTX2Loader.js @@ -16,6 +16,8 @@ import { CompressedArrayTexture, CompressedCubeTexture, Data3DTexture, + DataArrayTexture, + DataCubeTexture, DataTexture, DisplayP3ColorSpace, FileLoader, @@ -796,7 +798,6 @@ async function createRawTexture( container ) { const mipmaps = []; - for ( let levelIndex = 0; levelIndex < container.levels.length; levelIndex ++ ) { const levelWidth = Math.max( 1, container.pixelWidth >> levelIndex ); @@ -864,19 +865,55 @@ async function createRawTexture( container ) { if ( UNCOMPRESSED_FORMATS.has( FORMAT_MAP[ vkFormat ] ) ) { - texture = container.pixelDepth === 0 - ? new DataTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight ) - : new Data3DTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight, container.pixelDepth ); + if ( container.faceCount === 6 ) { + + texture = new DataCubeTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight ); + + } else if ( container.layerCount > 1 ) { + + texture = new DataArrayTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight, container.layerCount ); + + } else if ( container.pixelDepth === 0 ) { + + texture = new DataTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight ); + + } else { + + texture = new Data3DTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight, container.pixelDepth ); + + } } else { - if ( container.pixelDepth > 0 ) throw new Error( 'THREE.KTX2Loader: Unsupported pixelDepth.' ); + if ( container.faceCount === 6 ) { + + texture = new CompressedCubeTexture( mipmaps ); - texture = new CompressedTexture( mipmaps, container.pixelWidth, container.pixelHeight ); + } else if ( container.layerCount > 1 ) { + + texture = new CompressedArrayTexture( mipmaps, container.pixelWidth, container.pixelHeight, container.layerCount ); + + } else if ( container.pixelDepth === 0 ) { + + texture = new CompressedTexture( mipmaps, container.pixelWidth, container.pixelHeight ); + + } else { + + throw new Error( 'THREE.KTX2Loader: Unsupported pixelDepth.' ); + + } } - texture.mipmaps = mipmaps; + if ( texture.isDataCubeTexture ) { + + texture.mipmaps = mipmaps.map( ( mip ) => new DataCubeTexture( mip.data, mip.width, mip.height ) ); + + } else { + + texture.mipmaps = mipmaps; + + } texture.type = TYPE_MAP[ vkFormat ]; texture.format = FORMAT_MAP[ vkFormat ]; diff --git a/examples/textures/compressed/2d_rgba16_linear.ktx2 b/examples/textures/compressed/2d_rgba16_linear.ktx2 index 07589e433365c9..0bba5a24106940 100644 Binary files a/examples/textures/compressed/2d_rgba16_linear.ktx2 and b/examples/textures/compressed/2d_rgba16_linear.ktx2 differ diff --git a/examples/textures/compressed/2d_rgba32_linear.ktx2 b/examples/textures/compressed/2d_rgba32_linear.ktx2 index 8b6d3a51ba4b76..8d8e615db566c2 100644 Binary files a/examples/textures/compressed/2d_rgba32_linear.ktx2 and b/examples/textures/compressed/2d_rgba32_linear.ktx2 differ diff --git a/examples/textures/compressed/3d_etc1s.ktx2 b/examples/textures/compressed/3d_etc1s.ktx2 new file mode 100644 index 00000000000000..3de94fc45c6f24 Binary files /dev/null and b/examples/textures/compressed/3d_etc1s.ktx2 differ diff --git a/examples/textures/compressed/3d_rgba16_linear.ktx2 b/examples/textures/compressed/3d_rgba16_linear.ktx2 new file mode 100644 index 00000000000000..e6b4035204315f Binary files /dev/null and b/examples/textures/compressed/3d_rgba16_linear.ktx2 differ diff --git a/examples/textures/compressed/3d_rgba32_linear.ktx2 b/examples/textures/compressed/3d_rgba32_linear.ktx2 new file mode 100644 index 00000000000000..c258565df526fd Binary files /dev/null and b/examples/textures/compressed/3d_rgba32_linear.ktx2 differ diff --git a/examples/textures/compressed/3d_rgba32_lut.ktx2 b/examples/textures/compressed/3d_rgba32_lut.ktx2 new file mode 100644 index 00000000000000..a9e82826e80af5 Binary files /dev/null and b/examples/textures/compressed/3d_rgba32_lut.ktx2 differ diff --git a/examples/textures/compressed/3d_rgba8.ktx2 b/examples/textures/compressed/3d_rgba8.ktx2 new file mode 100644 index 00000000000000..5ec1d3bed7b892 Binary files /dev/null and b/examples/textures/compressed/3d_rgba8.ktx2 differ diff --git a/examples/textures/compressed/3d_rgba8_linear.ktx2 b/examples/textures/compressed/3d_rgba8_linear.ktx2 new file mode 100644 index 00000000000000..e674eac8c1660a Binary files /dev/null and b/examples/textures/compressed/3d_rgba8_linear.ktx2 differ diff --git a/examples/textures/compressed/3d_uastc.ktx2 b/examples/textures/compressed/3d_uastc.ktx2 new file mode 100644 index 00000000000000..f05db3c2090628 Binary files /dev/null and b/examples/textures/compressed/3d_uastc.ktx2 differ diff --git a/examples/textures/compressed/array_etc1s.ktx2 b/examples/textures/compressed/array_etc1s.ktx2 new file mode 100644 index 00000000000000..3de94fc45c6f24 Binary files /dev/null and b/examples/textures/compressed/array_etc1s.ktx2 differ diff --git a/examples/textures/compressed/array_rgba16_linear.ktx2 b/examples/textures/compressed/array_rgba16_linear.ktx2 new file mode 100644 index 00000000000000..e6b4035204315f Binary files /dev/null and b/examples/textures/compressed/array_rgba16_linear.ktx2 differ diff --git a/examples/textures/compressed/array_rgba32_linear.ktx2 b/examples/textures/compressed/array_rgba32_linear.ktx2 new file mode 100644 index 00000000000000..c258565df526fd Binary files /dev/null and b/examples/textures/compressed/array_rgba32_linear.ktx2 differ diff --git a/examples/textures/compressed/array_rgba8.ktx2 b/examples/textures/compressed/array_rgba8.ktx2 new file mode 100644 index 00000000000000..5ec1d3bed7b892 Binary files /dev/null and b/examples/textures/compressed/array_rgba8.ktx2 differ diff --git a/examples/textures/compressed/array_rgba8_linear.ktx2 b/examples/textures/compressed/array_rgba8_linear.ktx2 new file mode 100644 index 00000000000000..e674eac8c1660a Binary files /dev/null and b/examples/textures/compressed/array_rgba8_linear.ktx2 differ diff --git a/examples/textures/compressed/array_uastc.ktx2 b/examples/textures/compressed/array_uastc.ktx2 new file mode 100644 index 00000000000000..f05db3c2090628 Binary files /dev/null and b/examples/textures/compressed/array_uastc.ktx2 differ diff --git a/examples/textures/compressed/cubemap_etc1s.ktx2 b/examples/textures/compressed/cubemap_etc1s.ktx2 new file mode 100644 index 00000000000000..9deb32b04c1ec4 Binary files /dev/null and b/examples/textures/compressed/cubemap_etc1s.ktx2 differ diff --git a/examples/textures/compressed/cubemap_rgba16_linear.ktx2 b/examples/textures/compressed/cubemap_rgba16_linear.ktx2 new file mode 100644 index 00000000000000..65830c5e261347 Binary files /dev/null and b/examples/textures/compressed/cubemap_rgba16_linear.ktx2 differ diff --git a/examples/textures/compressed/cubemap_rgba32_linear.ktx2 b/examples/textures/compressed/cubemap_rgba32_linear.ktx2 new file mode 100644 index 00000000000000..1764712a96343d Binary files /dev/null and b/examples/textures/compressed/cubemap_rgba32_linear.ktx2 differ diff --git a/examples/textures/compressed/cubemap_rgba8.ktx2 b/examples/textures/compressed/cubemap_rgba8.ktx2 new file mode 100644 index 00000000000000..996c3101bfdae9 Binary files /dev/null and b/examples/textures/compressed/cubemap_rgba8.ktx2 differ diff --git a/examples/textures/compressed/cubemap_rgba8_linear.ktx2 b/examples/textures/compressed/cubemap_rgba8_linear.ktx2 new file mode 100644 index 00000000000000..c7eea4c6e19dff Binary files /dev/null and b/examples/textures/compressed/cubemap_rgba8_linear.ktx2 differ diff --git a/examples/textures/compressed/cubemap_uastc.ktx2 b/examples/textures/compressed/cubemap_uastc.ktx2 new file mode 100644 index 00000000000000..35e40250862410 Binary files /dev/null and b/examples/textures/compressed/cubemap_uastc.ktx2 differ diff --git a/examples/webgl_loader_texture_ktx2.html b/examples/webgl_loader_texture_ktx2.html index 44878f8a7d8a84..007f16b06ff404 100644 --- a/examples/webgl_loader_texture_ktx2.html +++ b/examples/webgl_loader_texture_ktx2.html @@ -10,8 +10,8 @@