Minimize the size of glb file exported from GLTFExporter

Hi
I have an fbx file which after using FBXLoader.parse I converted the resultant Object/Group using GLTFExporter to a glb file.
Now there is a huge difference between the size of these two files
The size of fbx file is around 40MB and the size of glb is more than three times the size of fbx which is 144MB.

Is there any way I can decrease the size of glb file?

Here is the piece of code that I am using to convert the file:-

const loader = new FBXLoader()
const object: any = loader.parse(response.target.result,
// An array buffer of fbx file got from reader.readAsArrayBuffer(fbxFile)
'')
const exporter = new GLTFExporter();
exporter.parse(object, (gltf: any) => {
    this.saveArrayBuffer(gltf, this.fileName.replace('.fbx', '.glb'));
}, {
 binary: true,
// embedImages: false
});

You’ll need to share the model to get help on this one, I think. It’s hard to guess what part of the model has been changed in the FBX -> three.js -> glTF process. You may also want to try converting with FBX2GLTF or with Blender.

1 Like

@donmccurdy Well It can be any fbx model, For instance here is the link of fbx model:-

After FBX -> three.js -> glTF process, Here is the glb file:-

Fbx model is less than 4MB but glb is 23.6MB (approx 6 times)

I’d recommend filing a bug on three.js — either FBXLoader or GLTFExporter is increasing the vertex count by quite a lot, basically de-indexing the mesh, and there could be good reasons for it but I’m not sure why. Both FBX2GLTF and Blender do a better job of converting the model, it looks like. It’ll still be a bit bigger initially, but then you can compress it to just 700kb with glTF-Pipeline:

iphone_draco.glb (743.3 KB)

Hey Don,

I’m also using GLTFExporter to convert FBX to glTF but it’s consistently creating a much larger file. Is there any way to losslessly optimize it? The zipped file is still smaller even though the unzipped is much larger. Here are the relevant files. WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free

@dwang3142 you should try your files in some existing viewers just to see what errors they have.

If you drop your GLB file int Don’s GLTF Viewer it will show you the error.

If you try manually loading your FBX file in my FBX Viewer the console will show that it could not load images (which you could try providing during the manual load).

And for any future readers, my viewers already include exporting to GLB with DRACO and / or MESHOPT as well as WEBP compression from Don’s glTF-transform. In order to be any successful in exporting the model has to be fully and properly loaded.

Even FBX2GLTF converter is stating that it could not find couple of images.

Sorry about that, I do some custom stuff with the buffers so the exported GLB file wont load in public viewers.

Generally though I’ve found OBJ and FBX models that I convert to GLB using GLTFExporter turn out much larger (with and without textures initially). I already use MESHOPT and GLTF Transform but since I need the files to remain visually the same, the 2 don’t do that much so I’m left with a larger GLB file than I started with (granted the zip file is smaller).

Both the FBX and GLB files have 850K triangles, but there’s a big difference too — the FBX has 425,000 vertices, and the GLB has 2,500,000 vertices. That increase can happen during the load+render+export cycle, it’s not a bug in and of itself … but it’s definitely something you’ll want to fix to have an optimized glTF file.

This doesn’t seem to be a valid glTF file given the custom buffers, so I’m not sure how to advise on optimizing it intact… I did test import+export from Blender, which “fixes” the buffers, but probably is losing whatever custom thing you were doing. With the now-valid file, simply welding vertices brings it back to the size of the FBX original, 100% losslessly:

npm install --global @gltf-transform/cli@next

gltf-transform weld input.glb output.glb

If you don’t mind including some slightly lossy compression (which shouldn’t affect the visual quality) you can get it closer to 1/8th the size of the FBX original:

gltf-transform optimize input.glb output.glb --no-instance --compress meshopt --no-simplify

This assumes you are using Meshopt+Gzip, or using Draco alone. If there are textures then consider WebP or KTX2 compression on those by adding --texture-compress webp.

1 Like

use compressed ZIP
need this:
https://didisoftwares.ddns.net/build/jszip.min.js
https://didisoftwares.ddns.net/build/jszip-utils.js


function unZipGlb(zip) {
    zip.filter(function (path, file) {
        var manager = new THREE.LoadingManager();
        manager.setURLModifier(function (url) {            
            var file = zip.files[url];
            console.log(zip.files[url]);
            if (file) {
                var blob = new Blob([file.asArrayBuffer()], { type: 'application/octet-stream' });
                return URL.createObjectURL(blob);
            }
            return url;
        });
        var extension = file.name.split('.').pop().toLowerCase();
        switch (extension) {
            case 'glb':
                LOADER.glbloader.parse(file.asArrayBuffer(), '', function (result) {
                    //your GLB uncopressed here
                });
                break;
        }
    });
}

JSZipUtils.getBinaryContent(COMPRESSED_GLB_HERE, async function (err, data) {
    if (err) { throw err; }
    var myzip = new JSZip();
    unZipGlb(myzip.load(data));
});