@loaders.gl/gltf
Version:
Framework-independent loader for the glTF format
33 lines • 1.42 kB
JavaScript
// GLTF EXTENSION: EXT_TEXTURE_WEBP
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
/* eslint-disable camelcase */
import { isImageFormatSupported } from '@loaders.gl/images';
import { GLTFScenegraph } from "../api/gltf-scenegraph.js";
const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
/** Extension name */
export const name = EXT_TEXTURE_WEBP;
/**
* Replaces a texture source reference with the extension texture
* Done in preprocess() to prevent load of default image
*/
export function preprocess(gltfData, options) {
const scenegraph = new GLTFScenegraph(gltfData);
if (!isImageFormatSupported('image/webp')) {
if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
}
return;
}
const { json } = scenegraph;
for (const texture of json.textures || []) {
const extension = scenegraph.getObjectExtension(texture, EXT_TEXTURE_WEBP);
if (extension) {
// TODO - if multiple texture extensions are present which one wins?
texture.source = extension.source;
}
scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
}
// Remove the top-level extension
scenegraph.removeExtension(EXT_TEXTURE_WEBP);
}
//# sourceMappingURL=EXT_texture_webp.js.map