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.
The information contained in GLB files not only includes 3D scenes, but models, lighting, materials, node hierarchy, and animations. In layman's terms, it's a file format that supports motion and animation, which is why it is commonly used in web applications, games, virtual reality (VR), and augmented reality (AR).
The main advantage of using a file extension glb is that it is much more lightweight in terms of size than its similar gltf version. This means that the GLB is easy to transfer (great email file format) and takes up less processing space.
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.
I'm surprised that no one has mentioned the obvious, simple way of lossily reducing the size of a .glb
file that's just a container for separate mesh and texture data:
Reduce your vertex count by collapsing adjacent vertices that are close together or coplanar, and reduce your image data by trimming out, scaling down, or using a lower bit depth for unnecessary details.
Every 2X decrease in surface polygon/pixel density should yield roughly a 4X decrease in file size.
And then, once you've removed unneeded detail, start looking at things like DRACO
, basis
, fewer JPEG
chroma samples, and optipng
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With