RUST · LIBRARY + CLI
Make game assets small.
smasher packs sprites into atlases, turns textures into KTX2, compresses models with Draco or meshopt and cuts each one to what a phone, a desktop or a big screen can draw. The codecs are compiled in: no Node, no external tools to install.
cargo install --git https://github.com/joydle/smasher smasher-cliNeeds a C++ compiler, or take a binary from Releases.
Use it · Compare it · Source · MIT or Apache-2.0
See it
The original from Khronos against what smasher mesh wrote. Loaded live, measured in your browser.
Drag to turn, scroll or pinch to zoom, right-drag to pan, double-click to reset.
Damaged Helmet by ctxwing (CC BY 4.0), after theblueturtle_ (CC BY-NC 4.0). Lantern by sbtron and Frank Galligan, BoomBox by Microsoft (CC0). All from the Khronos glTF Sample Assets; licenses in site/models. The smashed files cap textures at 1024 px as well as keeping them compressed, and the GPU figure counts both: an uncompressed texture is RGBA8 with its mip chain.
Numbers
Against the two open-source tools people reach for: same models, same 1024 px texture cap.
| model | original | smasher | gltfpack, UASTC data | gltfpack default | gltf-transform |
|---|---|---|---|---|---|
| DamagedHelmet | 3.77 MB | 2.26 MB 39.6 dB | 2.65 MB 39.7 dB | 0.81 MB 27.1 dB | 0.87 MB 34.6 dB |
| Lantern | 9.56 MB | 1.18 MB 41.2 dB | 1.29 MB 41.2 dB | 0.42 MB 28.4 dB | 2.96 MB 58.4 dB |
| BoomBox | 10.6 MB | 0.97 MB 41.7 dB | 1.11 MB 41.5 dB | 0.26 MB 21.9 dB | 2.14 MB 52.3 dB |
| rigged character, 35 clips, Draco | 4.08 MB | 2.65 MB | cannot read Draco | 2.74 MB | |
Textures capped at 1024 px everywhere. dB is the worst data map (normal, roughness, occlusion): PSNR against the source map resized without compression; higher is closer. smasher and the first gltfpack column both write UASTC for data maps and ETC1S for colour (gltfpack -c -tc -tu normal -tu attrib -tl 1024); at the same quality smasher's files are 9–15% smaller, in the same range of time. gltfpack's default (-c -tc -tl 1024) puts every map in ETC1S: the smallest files, at 22–28 dB. gltf-transform (optimize --compress meshopt --texture-size 1024) keeps JPEG: sharp, but every texture is full RGBA on the GPU, and its KTX2 needs KTX-Software. gltf-transform 4.4, gltfpack 1.3. The first three are Khronos sample models; the last is in crates/smasher-glb/tests/fixtures.
| what it does | smasher | gltf-transform | gltfpack |
|---|---|---|---|
| Runs as | Rust library + CLI | Node.js library + CLI | C++ CLI, also on npm |
| meshopt geometry | yes | yes | yes |
| Draco geometry | yes | yes | no, and refuses Draco input |
| Picks the codec per model | Draco static, meshopt animated | you choose | meshopt only |
| KTX2 / Basis textures | built in | needs KTX-Software | native builds |
| Levels per device and asset class | phone · desktop · high | a simplify ratio | a simplify ratio |
| Sprite atlases and strips | yes, TexturePacker JSON | no | no |
When bytes are all that count and softer maps are fine, gltfpack's defaults go smallest. smasher keeps data maps sharp and also does the sprites, atlases and images a game ships.
What it does
Built while shipping our own games.
- Sprite atlases
- MaxRects packing with trim, padding and power-of-two, a TexturePacker JSON-hash manifest that loads straight into Pixi, animations named, and unpack to get the frames back. Fixed-grid strips too.
- Images
- Cap the longest edge with Lanczos3, re-encode as PNG (a lossless palette when it has 256 colours or fewer, quantized on request) or JPEG. A result is written only if it is smaller.
- Geometry
- meshopt for animated models, Draco for static ones, chosen per file. Quantize, deduplicate, join meshes, prune constant animation channels. Draco input passes through untouched.
- Textures
- KTX2 with Basis Universal: UASTC for normal, metallic-roughness and occlusion maps, ETC1S for colour, full mip chain, colour resized in linear light. Fills UV gutters so mips do not bleed dark seams.
- Levels
- One source model cut once per device class, to a triangle budget for what it is: a pickup, a prop, a set piece, a character. A manifest names every level.
- Fail-open
- An error or a panic returns your original bytes. A heavier asset that works beats a missing one. Inputs are never overwritten.
Levels
How hard to smash. Phone is the most aggressive; high keeps the detail a big screen shows.
| asset class | phone | desktop | high |
|---|---|---|---|
| food, pickups | 1,500 | 6,000 | 24,000 |
| props | 2,500 | 10,000 | 40,000 |
| characters (rigged) | 6,000 | 24,000 | 96,000 |
| thin-walled: cups, bowls, rims | 7,000 | 28,000 | 112,000 |
| set pieces, buildings, backdrops | 9,000 | 36,000 | 144,000 |
Triangles for the whole model. The phone column is the top of what our games shipped on an iPhone 11-class phone; desktop and high step ×4 each, with texture detail rising alongside. The simplifier stops at the error bound even if the budget is not met.
Use
From the shell, from Rust, or from any tool over JSON.
shell — results go to ./smashed, inputs untouched
$ smasher mesh hero.glb --levels phone,desktop,high optimize_mesh 372 KB source → 3 level(s) smashed/hero.phone.glb 106 KB smashed/hero.desktop.glb 116 KB smashed/hero.high.glb 116 KB smashed/hero.levels.json 525 B phone 5998 triangles (of 7185), textures ≤ 1024 px desktop 7185 triangles (of 7185), textures ≤ 2048 px high 7185 triangles (of 7185), textures ≤ 4096 px $ smasher atlas sprites/coin_*.png --max-size 2048 $ smasher compress art/*.png --max-size 1024 --format png --quantize $ smasher gutters hero.glb # audit UV gutters; `dilate` fills them
Rust — crates/smasher/examples/quickstart.rs
use smasher_glb::{optimize, Options, TextureMode}; let glb = std::fs::read("hero.glb")?; let (small, report) = optimize(&glb, Options { textures: TextureMode::Clamp(1024), ktx2: true, ..Options::default() })?; std::fs::write("hero.small.glb", small)?;
JSON — one request on stdin, one answer on stdout
$ echo '{"root":".","op":"pack_atlas","paths":["a.png","b.png"],"out_dir":"out"}' | smasher {"protocol":1,"op":"pack_atlas","adopted":true,"before_bytes":8735,"after_bytes":4642,…}
Three crates: smasher (images, atlases, the GLB front end, levels), smasher-glb (the in-process GLB optimizer with Draco, meshoptimizer and Basis Universal compiled in) and smasher-cli. Building needs a C++ compiler for the codecs; smasher-glb also builds without them (--no-default-features), keeping textures PNG/JPEG and static meshes on meshopt.