Optimizes a single Texture, optionally resizing or converting to JPEG, PNG, WebP, or AVIF formats.
For best results use a Node.js environment, install the sharp module, and
provide an encoder. When the encoder is omitted — sharp works only in Node.js —
the implementation will use a platform-specific fallback encoder, and most
quality- and compression-related options are ignored.
Optimizes a single Texture, optionally resizing or converting to JPEG, PNG, WebP, or AVIF formats.
For best results use a Node.js environment, install the
sharp
module, and provide an encoder. When the encoder is omitted —sharp
works only in Node.js — the implementation will use a platform-specific fallback encoder, and most quality- and compression-related options are ignored.Example:
import { compressTexture } from '@gltf-transform/functions'; import sharp from 'sharp'; const texture = document.getRoot().listTextures() .find((texture) => texture.getName() === 'MyTexture'); // (A) Node.js. await compressTexture(texture, { encoder: sharp, targetFormat: 'webp', resize: [1024, 1024] }); // (B) Web. await compressTexture(texture, { targetFormat: 'webp', resize: [1024, 1024] });