ktx-parse is a JavaScript/TypeScript library designed for parsing and serializing KTX 2.0 (`.ktx2`) container files. It provides programmatic access to the structure and metadata within KTX 2.0 files, including mipmap levels, data format descriptors, and key/value data. Crucially, this library focuses solely on the KTX 2.0 container format and does not include functionality for decompressing or compressing the actual texture data (e.g., Basis Universal, ETC1S, UASTC). Users must integrate separate transcoding libraries (like those from BinomialLLC or KhronosGroup) to handle the compressed GPU texture formats found inside the KTX 2.0 containers. The package is currently at version 1.1.0 and is actively maintained by Don McCurdy, known for his work on glTF-Transform. It offers robust type definitions for TypeScript users and is frequently adopted in 3D graphics and web applications that require efficient GPU texture streaming.
npm install ktx-parseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to fetch a KTX 2.0 file, parse its binary data using `ktx-parse`, access key properties like dimensions and mipmap levels, and then serialize the container back into a byte array. It highlights that the raw texture data from `container.levels` requires external transcoders for decoding.
Integrate an appropriate texture transcoder (e.g., KhronosGroup/Universal-Texture-Transcoders) alongside ktx-parse to handle the compressed texture data. First, parse the KTX2 container, then pass the relevant mip level data to your chosen transcoder.
If modifications to the original source buffer are necessary, ensure that a deep copy of the `KTX2Container` data (especially mip levels and other binary fields) is made before performing any write operations on the source buffer.
Verify that the input data is a valid KTX 2.0 file. Check the file extension (`.ktx2`) and ensure the file is not corrupted during transfer or loading. If it's a KTX 1.x file, `ktx-parse` is not the correct library.
Always check `container.levels.length` before attempting to access individual mip levels. Ensure the KTX2 file is well-formed and contains the expected number of mip levels.
No dependency data recorded yet.