UNPKG

@loaders.gl/gltf

Version:

Framework-independent loader for the glTF format

40 lines 1.65 kB
// GLTF EXTENSION: KHR_materials_unlit // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit import { GLTFScenegraph } from "../../api/gltf-scenegraph.js"; const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit'; export const name = KHR_MATERIALS_UNLIT; export async function decode(gltfData) { const gltfScenegraph = new GLTFScenegraph(gltfData); const { json } = gltfScenegraph; // Any nodes that have the extension, add lights field pointing to light object // and remove the extension for (const material of json.materials || []) { const extension = material.extensions && material.extensions.KHR_materials_unlit; if (extension) { // @ts-ignore TODO material.unlit = true; } gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT); } // Remove the top-level extension gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT); } export function encode(gltfData) { const gltfScenegraph = new GLTFScenegraph(gltfData); const { json } = gltfScenegraph; // Any nodes that have lights field pointing to light object // add the extension // @ts-ignore if (gltfScenegraph.materials) { for (const material of json.materials || []) { // @ts-ignore if (material.unlit) { // @ts-ignore delete material.unlit; gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {}); gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT); } } } } //# sourceMappingURL=KHR_materials_unlit.js.map