Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return Promise.all(pending).then(() => {
const buffer = (canvas as any).toBuffer() as Buffer;
const arrayBuffer = GLTFUtil.trimBuffer(buffer);
GLTFUtil.addImage(container, 'atlas', arrayBuffer, atlasIsPNG ? 'image/png': 'image/jpeg');
const atlasImageIndex = container.json.images.length - 1;
// Reassign textures to atlas.
const imageMap = new Map();
images.forEach((i) => imageMap.set(i.index, i));
container.json.materials.forEach((material) => {
if (!material.pbrMetallicRoughness) return;
if (!material.pbrMetallicRoughness.baseColorTexture) return;
const baseColorTexture = material.pbrMetallicRoughness.baseColorTexture;
const textureIndex = baseColorTexture.index;
const textureDef = container.json.textures[textureIndex];
if (!imageMap.has(textureDef.source)) return;
const image = imageMap.get(textureDef.source);
baseColorTexture['extensions'] = baseColorTexture['extensions'] || {};