Skip to content

ravanova/glb-slim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

glb-slim

Make a heavy GLB (the kind AI generators like Tripo produce) lean enough to drop into a real-time engine or a web build, using only plain glTF features that every loader understands.

  • optimize-glb.sh welds, decimates the mesh, and resizes embedded textures.
  • fix-glb-mime.py repairs a GLB whose embedded texture declares the wrong mimeType, which is a frequent cause of a model that loads geometry but silently fails to texture (or fails to load at all).

The problem

AI-generated meshes are often around 300k triangles with 2K textures. That is far too heavy to ship to a browser or a mobile build. The usual fix is Draco or KTX2 compression, but plenty of importers do not support those extensions out of the box. A notable example is glTFast in its default mode, which reads plain glTF but not Draco, webp, or KTX2. So the mesh has to be slimmed with plain features only: fewer triangles and smaller JPEG or PNG textures.

There is also a sharp edge that costs people hours: if a texture is re-encoded as JPEG but its mimeType still says image/png (or vice versa), strict loaders refuse to decode it and the whole model load fails. fix-glb-mime.py rewrites the declared type from the actual magic bytes.

Requirements

  • bash and Node.js (the optimize step uses @gltf-transform/cli via npx, no global install needed)
  • Python 3 with Pillow for the texture resize (pip install pillow)

Usage

# weld + decimate to 8% of triangles + textures capped at 1024px
./optimize-glb.sh heavy.glb slim.glb

# tune it: keep 15% of triangles, cap textures at 2048px
./optimize-glb.sh heavy.glb slim.glb 0.15 2048

# repair a wrong-mimeType GLB (safe to run on any GLB; a no-op if already correct)
./fix-glb-mime.py slim.glb

optimize-glb.sh arguments: <in.glb> <out.glb> [tri-ratio] [tex-size]. tri-ratio is the fraction of triangles to keep (0.08 keeps 8%). tex-size is the maximum texture edge in pixels.

A typical pipeline is: generate, then slim, then fix the mimeType.

./optimize-glb.sh raw.glb game/ship.glb && ./fix-glb-mime.py game/ship.glb

Related

Pairs naturally with tripo-cli, which generates the raw GLB in the first place.

License

MIT. See LICENSE.

About

Slim heavy AI-generated GLBs (decimate mesh, resize textures) into plain-glTF assets that glTFast and other loaders read natively; plus a fix for wrong-mimeType embedded textures.

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors