EXT_texture_webp enables WebP images for any material texture.

NOTICE: Multi-vendor extensions (EXT_*) should be considered last-mile optimizations for an application known to support their use. Files using these extensions may not be widely portable in other software, and are not officially endorsed by the Khronos Group.

WebP typically provides the minimal transmission size, but requires browser support. Like PNG and JPEG, a WebP image is fully decompressed when uploaded to the GPU, which increases upload time and GPU memory cost. For seamless uploads and minimal GPU memory cost, it is necessary to use a GPU texture format like Basis Universal, with the KHR_texture_basisu extension.

Defining no ExtensionProperty types, this Extension is simply attached to the Document, and affects the entire Document by allowing use of the image/webp MIME type and passing WebP image data to the Texture.setImage method. Without the Extension, the same MIME types and image data would yield an invalid glTF document, under the stricter core glTF specification.

Properties:

  • N/A

Example

import { TextureWebP } from '@gltf-transform/extensions';

// Create an Extension attached to the Document.
const webpExtension = document.createExtension(TextureWebP)
    .setRequired(true);
document.createTexture('MyWebPTexture')
    .setMimeType('image/webp')
    .setImage(fs.readFileSync('my-texture.webp'));

WebP conversion is not done automatically when adding the extension as shown above — you must convert the image data first, then pass the .webp payload to Texture.setImage.

When the EXT_texture_webp extension is added to a file by glTF-Transform, the extension should always be required. This tool does not support writing assets that "fall back" to optional PNG or JPEG image data.

Hierarchy

  • Extension
    • TextureWebP

Properties

extensionName: "EXT_texture_webp" = ...
prereadTypes: PropertyType[] = ...
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.

  • install(key: string, dependency: unknown): TextureWebP
  • 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.

  • prewrite(_writerContext: WriterContext, _propertyType: PropertyType): TextureWebP
  • 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.

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

Made by Don McCurdy TypeDoc documentation Copyright 2020 under MIT license