gltf

Can I make the glb file smaller?


I have a large obj file of 306 mb. So I converted it into a glb file to reduce its size. The size of the file has decreased a lot to 82 mb, but it is still big. I want to make this file smaller. Is there a way? If there is, please let me know.

If you can't reduce the glb file further, let me know more effective ways to reduce the obj file. One of the things I've already done is change the obj file to json, compress, unwind and load it using pako.js. I didn't choose this method because it was too slow to decompress.


Solution

  • There might be, if it is the vertex-data that is causing the file to be that big. In that case you can use the DRACO compression-library to get the size down even further.

    First, to test the compressor, you can run

    npx gltf-pipeline -i original.glb -d --draco.compressionLevel 10 -o compressed.glb
    

    (you need to have a current version of node.js installed for this to work)

    If vertex-data was the reason for the file being that big, the compressed file should be considerably smaller than the original.

    Now you have to go through some extra-steps to load the file, as the regular GLTFLoader doesn't support DRACO-compressed meshes.

    Essentially, you need to import the THREE.DRACOLoader and the draco-decoder. Finally, you need to tell your GLTFLoader that you know how to handle DRACO-compression:

    DRACOLoader.setDecoderPath('path/to/draco-decoder');
    gltfLoader.setDRACOLoader(new DRACOLoader());
    

    After that, you can use the GLTFLoader as before.

    The only downside of this is that the decoder itself needs some resources: decoding isn't free and the decoder itself is another 320kB of data to be loaded by the browser. I think it's still worth it if it saves you megabytes of mesh-data.