quantize

  • Quantizes vertex attributes with KHR_mesh_quantization, reducing the size and memory footprint of the file. Conceptually, quantization refers to snapping values to regular intervals; vertex positions are snapped to a 3D grid, UVs to a 2D grid, and so on. When quantized to <= 16 bits, larger component types may be more compactly stored as 16-bit or 8-bit attributes.

    Often, it can be useful to quantize to precision lower than the maximum allowed by the component type. Positions quantized to 14 bits in a 16-bit accessor will occupy 16 bits in VRAM, but they can be compressed further for network compression with lossless encodings such as ZSTD.

    Vertex positions are shifted into [-1,1] or [0,1] range before quantization. Compensating for that shift, a transform is applied to the parent Node, or inverse bind matrices for a Skin if applicable. Materials using KHRMaterialsVolume are adjusted to maintain appearance. In future releases, UVs may also be transformed with KHRTextureTransform. Currently UVs outside of [0,1] range are not quantized.

    In most cases, quantization requires KHRMeshQuantization; the extension will be added automatically when quantize() is applied. When applying meshopt compression with EXTMeshoptCompression, quantization is usually applied before compression.

    Example:

    import { quantize } from '@gltf-transform/functions';
    
    await document.transform(
      quantize({
        quantizePosition: 14,
        quantizeNormal: 10,
      }),
    );
    

    For the inverse operation, see dequantize.

Function symbol, where the argument and output are a box labeled 'glTF'.

Made by Don McCurdy. Documentation built with greendoc and published under Creative Commons Attribution 3.0.