Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make the glb file smaller?

Tags:

gltf

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.

like image 416
김태은 Avatar asked May 23 '19 08:05

김태은


People also ask

What can you do with GLB files?

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).

Is GLB or glTF better?

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.


2 Answers

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.

like image 81
Martin Schuhfuß Avatar answered Jan 02 '23 19:01

Martin Schuhfuß


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.

like image 35
Will Chen Avatar answered Jan 02 '23 21:01

Will Chen