Amazing tool to reduce the size of gltf files

А. Change NodeIO to WebIO, otherwise it will not work in browser (sharp is also useless here).
B. Don’t use draco for the first time. It requires additional complicated setup with wasm files.
C. If there are no animations in your scene you don’t need resample.
D. Dedup should go before prune.
E. After this line const doc = await io.readBinary(arr) you may use

await doc.transform(
        dedup(),
        prune(),
       textureCompress({
        targetFormat: 'webp',
        resize: [1024, 2024],
    })
);

const glb = await io.writeBinary(doc);
// Then one may convert it to the URL
        const assetBlob = new Blob([glb]);
        const assetUrl = URL.createObjectURL(assetBlob);
        const link = document.createElement("a");
        link.href = assetUrl;
        link.download = "SomeName" + ".glb";
        link.click();

Let me know if you’ll have any questions.

1 Like