How to use the @gltf-transform/core.GLTFUtil.trimBuffer function in @gltf-transform/core

To help you get started, we’ve selected a few @gltf-transform/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github donmccurdy / glTF-Transform / packages / atlas / src / atlas.ts View on Github external
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'] || {};