KHR_mesh_quantization expands allowed component types for vertex attributes to include 16- and 8-bit storage.

Quantization provides a memory/precision tradeoff — depending on the application needs, 16-bit or 8-bit storage can be sufficient for mesh geometry, at 1/2 or 1/4 the size. For example, a 10x10 mesh might be written to a uint16 Accessor, with values 0–65536, normalized to be interpreted as 0–1. With an additional 10x scale on any node Node instantiating the quantized Mesh, the model retains its original scale with a minimal quality loss and up to 50% file size reduction.

Defining no ExtensionProperty types, this Extension is simply attached to the Document, and affects the entire Document by allowing more flexible use of Accessor types for vertex attributes. Without the Extension, the same use of these data types would yield an invalid glTF document, under the stricter core glTF specification.

Properties:

  • N/A

Example

import { MeshQuantization } from '@gltf-transform/extensions';
import { quantize } from '@gltf-transform/functions';

// Create an Extension attached to the Document.
const quantizationExtension = document.createExtension(MeshQuantization).setRequired(true);

// Use Uint16Array, Uint8Array, Int16Array, and Int8Array in vertex accessors manually,
// or apply the provided quantize() function to compute quantized accessors automatically:
await document.transform(quantize({
    quantizePosition: 16,
    quantizeNormal: 12,
    quantizeTexcoord: 14
}));

For more documentation about automatic quantization, see the quantize function.

Hierarchy

  • Extension
    • MeshQuantization

Properties

extensionName: "KHR_mesh_quantization" = ...
prereadTypes: PropertyType[]

Before reading, extension should be called for these Property types. Most extensions don't need to implement this.

prewriteTypes: PropertyType[]

Before writing, extension should be called for these Property types. Most extensions don't need to implement this.

readDependencies: string[]

Dependency IDs needed by this extension, to be installed before I/O.

Methods

  • dispose(): void
  • Disables and removes the extension from the Document.

  • Installs dependencies required by the extension.

  • isRequired(): boolean
  • Indicates to the client whether it is OK to load the asset when this extension is not recognized. Optional extensions are generally preferred, if there is not a good reason to require a client to completely fail when an extension isn't known.

  • preread(_readerContext: ReaderContext, _propertyType: PropertyType): MeshQuantization
  • Used by the PlatformIO utilities when reading a glTF asset. This method may optionally be implemented by an extension, and should then support any property type declared by the Extension's Extension.prereadTypes list. The Extension will be given a ReaderContext instance, and is expected to update either the context or its JSONDocument with resources known to the Extension. Most extensions don't need to implement this.

  • prewrite(_writerContext: WriterContext, _propertyType: PropertyType): MeshQuantization
  • Used by the PlatformIO utilities when writing a glTF asset. This method may optionally be implemented by an extension, and should then support any property type declared by the Extension's Extension.prewriteTypes list. The Extension will be given a WriterContext instance, and is expected to update either the context or its JSONDocument with resources known to the Extension. Most extensions don't need to implement this.

  • Indicates to the client whether it is OK to load the asset when this extension is not recognized. Optional extensions are generally preferred, if there is not a good reason to require a client to completely fail when an extension isn't known.

  • register(): void
  • Performs first-time setup for the extension. Must be idempotent.

Function symbol, f(📦) → 📦, where the argument and output are a box labeled 'glTF'.

Made by Don McCurdy TypeDoc documentation Copyright 2021 under MIT license